Skip to contentSkip to conversation

BCP code ported to pppd 2.4.2

Bridge Ulrich Holeschak 1 participant 1 message May 1, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello,
i have ported the BCP (Bride Control Protocol) patch for pppd 2.4.1 mentioned in
http://lists.osdl.org/pipermail/bridge/2004-September/000619.html
to pppd 2.4.2. The kernel patch still works without problems with kernel 2.4.30. Perhaps someone else could use this patch ...

Here again some documentation i have found about the BCP patch somewere else:

When pppd negotiates BCP, it tells the kernel PPP driver to enable bridging. The kernel creates a device named "bcpX" where X matches the "pppX" device that would be used for IP communication (assuming I did not make a mistake). Pppd runs the script /etc/ppp/eth-up, which is a good place to add bcpX to your bridge and "ifconfig up" it. If the link goes down, the kernel should handle all cleanup, but pppd also calls /etc/ppp/eth-down in case you should find something you want to run at that time. Don't access the bcpX device from eth-down, as it is probably already gone.

It should be possible to run BCP and IPCP (and other protocols) simultaneously, although we haven't tested it much because it seems silly. The options "noip", "nobcp", etc. are helpful to restrict the behavior of pppd.

The pppd option "maclocal" will tell pppd what hardware address to assign
bcpX. Without this option, pppd will attempt to use an address assigned
by the peer. BCP negotiation will fail if it can not determine a hardware
address. Change the source code if that doesn't suit your application. I don't know how the bridge driver handles interfaces without hardware addresses, though. You might have to turn off STP in that case to avoid
unintended consequences.

Thanks,
Ulrich

------------------- BEGIN SNIP ----------------------

include/linux/ppp_defs.h Tue Apr 5 22:26:44 2005 renamed from include/linux/ppp_defs.h Fri Dec 6 10:49:15 2002 +0 -0
diff -Naur ppp-2.4.2/include/linux/ppp_defs.h ppp-2.4.2-bcp/include/linux/ppp_defs.h
@@ -78,13 +78,16 @@

#define PPP_IPX 0x2b /* IPX protocol */
#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
+#define PPP_BRIDGE 0x31 /* Bridged LAN traffic or BPDU */
#define PPP_MP 0x3d /* Multilink protocol */
#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */
#define PPP_COMPFRAG 0xfb /* fragment compressed below bundle */
#define PPP_COMP 0xfd /* compressed packet */
+#define PPP_BPDU_IEEE 0x0201 /* IEEE 802.1 (D or G) bridge PDU */

#define PPP_IPCP    0x8021    /* IP Control Protocol */
#define PPP_ATCP    0x8029    /* AppleTalk Control Protocol */
#define PPP_IPXCP    0x802b    /* IPX Control Protocol */
+#define PPP_BCP        0x8031    /* Bridging Control Protocol */
#define PPP_IPV6CP    0x8057    /* IPv6 Control Protocol */
#define PPP_CCPFRAG    0x80fb    /* CCP at link level (below MP bundle) */
#define PPP_CCP        0x80fd    /* Compression Control Protocol */
include/net/ppp_defs.h Tue Apr 5 22:26:44 2005 renamed from include/net/ppp_defs.h Fri Dec 6 10:49:15 2002 +0 -0
diff -Naur ppp-2.4.2/include/net/ppp_defs.h ppp-2.4.2-bcp/include/net/ppp_defs.h
@@ -80,11 +80,14 @@

#define PPP_IPX 0x2b /* IPX protocol */
#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
+#define PPP_BRIDGE 0x31 /* Bridged LAN traffic or BPDU */

#define PPP_IPV6    0x57    /* Internet Protocol Version 6 */
#define PPP_COMP    0xfd    /* compressed packet */
+#define PPP_BPDU_IEEE    0x0201    /* IEEE 802.1 (D or G) bridge PDU */
#define PPP_IPCP    0x8021    /* IP Control Protocol */
#define PPP_ATCP    0x8029    /* AppleTalk Control Protocol */
#define PPP_IPXCP    0x802b    /* IPX Control Protocol */
+#define PPP_BCP        0x8031    /* Bridging Control Protocol */
#define PPP_IPV6CP    0x8057    /* IPv6 Control Protocol */
#define PPP_CCP        0x80fd    /* Compression Control Protocol */
#define PPP_ECP        0x8053    /* Encryption Control Protocol */
pppd/Makefile.linux Tue Apr 5 22:29:39 2005 renamed from pppd/Makefile.linux Tue Dec 7 01:23:15 2004 +0 -0
diff -Naur ppp-2.4.2/pppd/Makefile.linux ppp-2.4.2-bcp/pppd/Makefile.linux
@@ -10,7 +10,7 @@
 

TARGETS = pppd

-PPPDSRCS = main.c magic.c fsm.c lcp.c ipcp.c upap.c chap-new.c md5.c ccp.c \
+PPPDSRCS = main.c magic.c fsm.c bcp.c lcp.c ipcp.c upap.c chap-new.c md5.c ccp.c \
ecp.c ipxcp.c auth.c options.c sys-linux.c md4.c chap_ms.c \
demand.c utils.c tty.c eap.c chap-md5.c

@@ -19,7 +19,7 @@
upap.h eap.h

MANPAGES = pppd.8
-PPPDOBJS = main.o magic.o fsm.o lcp.o ipcp.o upap.o chap-new.o md5.o ccp.o \

+PPPDOBJS = main.o magic.o fsm.o bcp.o lcp.o ipcp.o upap.o chap-new.o md5.o ccp.o \
       ecp.o auth.o options.o demand.o utils.o sys-linux.o ipxcp.o tty.o \
       eap.o chap-md5.o
pppd/auth.c Tue Apr 5 22:33:27 2005 renamed from pppd/auth.c Thu Jun 12 01:56:26 2003 +0 -0
diff -Naur ppp-2.4.2/pppd/auth.c ppp-2.4.2-bcp/pppd/auth.c
@@ -157,9 +157,31 @@

/* Extra options to apply, from the secrets file entry for the peer. */ static struct wordlist *extra_options;

+/* Bits 0, 8, 14, and 15 are the same in all network protocol numbers, so
+ * remove them to save space in np_running[][]. */
+#define NP_BRIEF(np) ((int)((((np) & 0x3E00) >> 2) | (((np) & 0x00FE) >> 1)))
+#define NP_ARRAY_BYTE(np) (NP_BRIEF(np) / 8)
+#define NP_ARRAY_BIT(np) ((unsigned char)(1 << (NP_BRIEF(np) % 8)))
+
+/* Flags for running protocols. One bit per protocol per PPP unit. */ +static unsigned char np_running[NP_ARRAY_BYTE(0xBEFF)+1][NUM_PPP]; +
/* Number of network protocols which we have opened. */
static int num_np_open;

+#define NP_RUNNING(unit, np) \
+ (np_running[unit][NP_ARRAY_BYTE(np)] & NP_ARRAY_BIT(np))
+
+#define MARK_NP_RUNNING(unit, np) do { \

+    np_running[unit][NP_ARRAY_BYTE(np)] |= NP_ARRAY_BIT(np);    \
+    ++num_np_open;    \
+    } while (0)
+
+#define MARK_NP_FINISHED(unit, np) do {    \
+    np_running[unit][NP_ARRAY_BYTE(np)] &= ~NP_ARRAY_BIT(np);    \
+    --num_np_open;    \
+    } while (0)

+
/* Number of network protocols which have come up. */ static int num_np_up;

@@ -583,6 +605,8 @@

        if (protp->protocol < 0xC000 && protp->close != NULL)
        (*protp->close)(unit, "LCP down");
    }
+
+    memset(np_running, 0, sizeof(np_running));
    num_np_open = 0;
    num_np_up = 0;
    if (phase != PHASE_DEAD)
@@ -769,7 +793,8 @@
        && protp->protocol != PPP_CCP && protp->protocol != PPP_ECP
        && protp->enabled_flag && protp->open != NULL) {
        (*protp->open)(0);
-        ++num_np_open;
+        /* [UH] ++num_np_open; */
+            MARK_NP_RUNNING(0, protp->protocol);
    }

    if (num_np_open == 0)

@@ -983,16 +1008,31 @@
}

/*
+ * np_start - a network protocol is starting to use the link.
+ */
+void
+np_start(unit, proto)
+ int unit, proto;
+{
+ if (!NP_RUNNING(unit, proto))
+ MARK_NP_RUNNING(unit, proto);
+}
+
+/*
* np_finished - a network protocol has finished using the link. */
void
np_finished(unit, proto)

    int unit, proto;

{
- if (--num_np_open <= 0) {
+ if (NP_RUNNING(unit, proto)) {
+ MARK_NP_FINISHED(unit, proto);
+

+        if (num_np_open <= 0) {
    /* no further use for the link: shut up shop. */
    lcp_close(0, "No network protocols running");
    }

+}
}

#ifdef MAXOCTETS

pppd/bcp.c Tue Apr 5 22:26:44 2005 renamed from pppd/bcp.c Thu Jan 1 01:00:00 1970 +1743 -0

1,743 lines not on this page · raw message

pppd/bcp.h Tue Apr 5 22:26:44 2005 renamed from pppd/bcp.h Thu Jan 1 01:00:00 1970 +73 -0

73 lines not on this page · raw message

pppd/fsm.c Tue Apr 5 22:26:44 2005 renamed from pppd/fsm.c Sun Jun 29 12:06:14 2003 +2 -0
diff -Naur ppp-2.4.2/pppd/fsm.c ppp-2.4.2-bcp/pppd/fsm.c
@@ -218,6 +218,8 @@
    switch( f->state ){
    case STARTING:
    f->state = INITIAL;
+        if( f->callbacks->finished )
+        (*f->callbacks->finished)(f);
    break;
    case STOPPED:
    f->state = CLOSED;
pppd/ipcp.c Tue Apr 5 22:26:44 2005 renamed from pppd/ipcp.c Tue Jan 13 04:59:06 2004 +0 -0
diff -Naur ppp-2.4.2/pppd/ipcp.c ppp-2.4.2-bcp/pppd/ipcp.c
@@ -108,6 +108,7 @@

static int ipcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
static void ipcp_up __P((fsm *)); /* We're UP */
static void ipcp_down __P((fsm *)); /* We're DOWN */
+static void ipcp_start __P((fsm *)); /* Need lower layer */
static void ipcp_finished __P((fsm *)); /* Don't need lower layer */

fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
@@ -122,7 +123,7 @@
ipcp_reqci, /* Request peer's Configuration Information */
ipcp_up, /* Called when fsm reaches OPENED state */
ipcp_down, /* Called when fsm leaves OPENED state */
- NULL, /* Called when we want the lower layer up */
+ ipcp_start, /* Called when we want the lower layer up */
ipcp_finished, /* Called when we want the lower layer down */
NULL, /* Called when Protocol-Reject received */
NULL, /* Retransmission is necessary */
@@ -1886,6 +1887,17 @@

    default_route_set[unit] = 0;
    }
    cifaddr(unit, ouraddr, hisaddr);

+}
+
+
+/*
+ * ipcp_start - called when we want the lower layer up.
+ */
+static void
+ipcp_start(f)
+ fsm *f;
+{
+ np_start(f->unit, PPP_IP);
}

pppd/ipv6cp.c Tue Apr 5 22:26:44 2005 renamed from pppd/ipv6cp.c Tue Jan 13 04:59:37 2004 +0 -0
diff -Naur ppp-2.4.2/pppd/ipv6cp.c ppp-2.4.2-bcp/pppd/ipv6cp.c
@@ -191,6 +191,7 @@

static int ipv6cp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
static void ipv6cp_up __P((fsm *)); /* We're UP */
static void ipv6cp_down __P((fsm *)); /* We're DOWN */
+static void ipv6cp_start __P((fsm *)); /* Need lower layer */
static void ipv6cp_finished __P((fsm *)); /* Don't need lower layer */

fsm ipv6cp_fsm[NUM_PPP]; /* IPV6CP fsm structure */
@@ -205,7 +206,7 @@
ipv6cp_reqci, /* Request peer's Configuration Information */
ipv6cp_up, /* Called when fsm reaches OPENED state */
ipv6cp_down, /* Called when fsm leaves OPENED state */
- NULL, /* Called when we want the lower layer up */
+ ipv6cp_start, /* Called when we want the lower layer up */
ipv6cp_finished, /* Called when we want the lower layer down */
NULL, /* Called when Protocol-Reject received */
NULL, /* Retransmission is necessary */
@@ -1352,6 +1353,17 @@

    eui64_t hisid;
{
    cif6addr(unit, ourid, hisid);

+}
+
+
+/*
+ * ipv6cp_start - called when we want the lower layer up.
+ */
+static void
+ipv6cp_start(f)
+ fsm *f;
+{
+ np_start(f->unit, PPP_IPV6);
}

pppd/ipxcp.c Tue Apr 5 22:26:44 2005 renamed from pppd/ipxcp.c Tue Nov 18 11:42:56 2003 +0 -0
diff -Naur ppp-2.4.2/pppd/ipxcp.c ppp-2.4.2-bcp/pppd/ipxcp.c
@@ -87,6 +87,7 @@

static int ipxcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
static void ipxcp_up __P((fsm *)); /* We're UP */
static void ipxcp_down __P((fsm *)); /* We're DOWN */
+static void ipxcp_start __P((fsm *)); /* Need lower layer */
static void ipxcp_finished __P((fsm *)); /* Don't need lower layer */
static void ipxcp_script __P((fsm *, char *)); /* Run an up/down script */

@@ -102,7 +103,7 @@
ipxcp_reqci, /* Request peer's Configuration Information */
ipxcp_up, /* Called when fsm reaches OPENED state */
ipxcp_down, /* Called when fsm leaves OPENED state */
- NULL, /* Called when we want the lower layer up */
+ ipxcp_start, /* Called when we want the lower layer up */
ipxcp_finished, /* Called when we want the lower layer down */
NULL, /* Called when Protocol-Reject received */
NULL, /* Retransmission is necessary */
@@ -1377,6 +1378,17 @@

    sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);
    sifdown(f->unit);
    ipxcp_script (f, _PATH_IPXDOWN);

+}
+
+
+/*
+ * ipxcp_start - called when we want the lower layer up.
+ */
+static void
+ipxcp_start(f)
+ fsm *f;
+{
+ np_start(f->unit, PPP_IPX);
}

pppd/main.c Fri Apr 8 01:52:48 2005 renamed from pppd/main.c Tue Jan 13 05:00:34 2004 +0 -0
diff -Naur ppp-2.4.2/pppd/main.c ppp-2.4.2-bcp/pppd/main.c
@@ -68,6 +68,7 @@

#include "pppd.h"
#include "magic.h"
#include "fsm.h"
+#include "bcp.h"
#include "lcp.h"
#include "ipcp.h"
#ifdef INET6
@@ -258,6 +259,7 @@
&atcp_protent,
#endif
&eap_protent,
+ &bcp_protent,
NULL
};

pppd/pathnames.h Tue Apr 5 22:26:44 2005 renamed from pppd/pathnames.h Sat Nov 9 12:24:42 2002 +0 -0
diff -Naur ppp-2.4.2/pppd/pathnames.h ppp-2.4.2-bcp/pppd/pathnames.h
@@ -30,6 +30,8 @@

#define _PATH_CONNERRS _ROOT_PATH "/etc/ppp/connect-errors"
#define _PATH_PEERFILES _ROOT_PATH "/etc/ppp/peers/"
#define _PATH_RESOLV _ROOT_PATH "/etc/ppp/resolv.conf"
+#define _PATH_ETHUP _ROOT_PATH "/etc/ppp/eth-up"
+#define _PATH_ETHDOWN _ROOT_PATH "/etc/ppp/eth-down"

#define _PATH_USEROPT ".ppprc"
#define _PATH_PSEUDONYM ".ppp_pseudonym"

pppd/pppd.h Wed Apr 6 23:52:28 2005 renamed from pppd/pppd.h Mon Apr 7 02:01:46 2003 +0 -0
diff -Naur ppp-2.4.2/pppd/pppd.h ppp-2.4.2-bcp/pppd/pppd.h
@@ -518,6 +518,7 @@

void continue_networks __P((int)); /* start network [ip, etc] control protos */
void np_up __P((int, int)); /* a network protocol has come up */
void np_down __P((int, int)); /* a network protocol has gone down */
+void np_start __P((int, int)); /* a network protocol needs link */
void np_finished __P((int, int)); /* a network protocol no longer needs link */

void auth_peer_fail __P((int, int));
                /* peer failed to authenticate itself */

@@ -640,6 +641,7 @@
int sipxfaddr __P((int, unsigned long, unsigned char *)); int cipxfaddr __P((int));
#endif
+int set_if_hwaddr __P((const u_char *addr, const char *name)); int get_if_hwaddr __P((u_char *addr, char *name)); char *get_first_ethernet __P((void));

@@ -788,6 +790,7 @@
#ifdef DEBUGALL
#define DEBUGMAIN 1
#define DEBUGFSM 1
+#define DEBUGBCP 1
#define DEBUGLCP 1
#define DEBUGIPCP 1
#define DEBUGIPV6CP 1
@@ -821,6 +824,12 @@
#define FSMDEBUG(x) if (debug) dbglog x
#else
#define FSMDEBUG(x)
+#endif
+
+#ifdef DEBUGBCP
+#define BCPDEBUG(x) if (debug) dbglog x
+#else
+#define BCPDEBUG(x)
#endif

#ifdef DEBUGLCP

pppd/sys-linux.c Thu Apr 7 00:02:12 2005 renamed from pppd/sys-linux.c Tue Jan 13 05:05:20 2004 +0 -0
diff -Naur ppp-2.4.2/pppd/sys-linux.c ppp-2.4.2-bcp/pppd/sys-linux.c
@@ -1840,6 +1840,30 @@

}

/*
+ * set_if_hwaddr - set the hardware address for the specified
+ * network interface device.
+ */
+int
+set_if_hwaddr(const u_char *addr, const char *name) +{
+ struct ifreq ifreq;
+ int ret, sock_fd;
+
+ sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock_fd < 0)
+ return 0;

+    memset(&ifreq.ifr_hwaddr, 0, sizeof(struct sockaddr));
+    strlcpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name));
+    ret = ioctl(sock_fd, SIOCGIFHWADDR, &ifreq);

+ if (ret >= 0) {
+ memcpy(ifreq.ifr_hwaddr.sa_data, addr, 6);
+ ret = ioctl(sock_fd, SIOCSIFHWADDR, &ifreq);
+ }
+ close(sock_fd);
+ return ret;
+}
+
+/*
* get_if_hwaddr - get the hardware address for the specified
* network interface device.
*/
------------------- END SNIP ----------------------