X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fplugins%2Frp-pppoe%2Fplugin.c;h=1ea46a65efdedcca71b2aecda3b6e2177bf953ba;hb=71373d6f2d74ebb13d6697cb1cc1112033a71fc9;hp=ceef0512eb8d80893a1b1bf4f424fd7c7668daa0;hpb=d95598c16f6a3feb4846db669601856bad15bb74;p=ppp.git diff --git a/pppd/plugins/rp-pppoe/plugin.c b/pppd/plugins/rp-pppoe/plugin.c index ceef051..1ea46a6 100644 --- a/pppd/plugins/rp-pppoe/plugin.c +++ b/pppd/plugins/rp-pppoe/plugin.c @@ -22,7 +22,7 @@ ***********************************************************************/ static char const RCSID[] = -"$Id: plugin.c,v 1.2 2002/01/22 16:03:05 dfs Exp $"; +"$Id: plugin.c,v 1.13 2005/07/09 09:12:48 paulus Exp $"; #define _GNU_SOURCE 1 #include "pppoe.h" @@ -59,25 +59,28 @@ char pppd_version[] = VERSION; /* From sys-linux.c in pppd -- MUST FIX THIS! */ extern int new_style_driver; -static char *service = NULL; +char *pppd_pppoe_service = NULL; static char *acName = NULL; static char *existingSession = NULL; +static int printACNames = 0; -static int PPPoEDevnameHook(const char *name); +static int PPPoEDevnameHook(char *cmd, char **argv, int doit); static option_t Options[] = { { "device name", o_wild, (void *) &PPPoEDevnameHook, "PPPoE device name", OPT_DEVNAM | OPT_PRIVFIX | OPT_NOARG | OPT_A2STRVAL | OPT_STATIC, devnam}, - { "rp_pppoe_service", o_string, &service, + { "rp_pppoe_service", o_string, &pppd_pppoe_service, "Desired PPPoE service name" }, { "rp_pppoe_ac", o_string, &acName, "Desired PPPoE access concentrator name" }, { "rp_pppoe_sess", o_string, &existingSession, "Attach to existing session (sessid:macaddr)" }, + { "rp_pppoe_verbose", o_int, &printACNames, + "Be verbose about discovered access concentrators"}, { NULL } }; -int (*OldDevnameHook)(const char *name) = NULL; + static PPPoEConnection *conn = NULL; /********************************************************************** @@ -100,13 +103,14 @@ PPPOEInitDevice(void) if (acName) { SET_STRING(conn->acName, acName); } - if (service) { - SET_STRING(conn->serviceName, acName); + if (pppd_pppoe_service) { + SET_STRING(conn->serviceName, pppd_pppoe_service); } SET_STRING(conn->ifName, devnam); conn->discoverySocket = -1; conn->sessionSocket = -1; conn->useHostUniq = 1; + conn->printACNames = printACNames; return 1; } @@ -140,7 +144,8 @@ PPPOEConnectDevice(void) } else { discovery(conn); if (conn->discoveryState != STATE_SESSION) { - fatal("Unable to complete PPPoE Discovery"); + error("Unable to complete PPPoE Discovery"); + return -1; } } @@ -176,41 +181,14 @@ PPPOEConnectDevice(void) return conn->sessionSocket; } -static void -PPPOESendConfig(int mtu, - u_int32_t asyncmap, - int pcomp, - int accomp) -{ - int sock; - struct ifreq ifr; - - if (mtu > MAX_PPPOE_MTU) { - warn("Couldn't increase MTU to %d", mtu); - mtu = MAX_PPPOE_MTU; - } - sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock < 0) { - fatal("Couldn't create IP socket: %m"); - } - strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); - ifr.ifr_mtu = mtu; - if (ioctl(sock, SIOCSIFMTU, &ifr) < 0) { - fatal("ioctl(SIOCSIFMTU): %m"); - } - (void) close (sock); -} - - static void PPPOERecvConfig(int mru, u_int32_t asyncmap, int pcomp, int accomp) { - if (mru > MAX_PPPOE_MTU) { - error("Couldn't increase MRU to %d", mru); - } + if (mru > MAX_PPPOE_MTU) + warn("Couldn't increase MRU to %d", mru); } /********************************************************************** @@ -238,6 +216,8 @@ PPPOEDisconnectDevice(void) return; } close(conn->sessionSocket); + /* don't send PADT?? */ + close(conn->discoverySocket); } static void @@ -255,7 +235,9 @@ struct channel pppoe_channel; /********************************************************************** * %FUNCTION: PPPoEDevnameHook * %ARGUMENTS: - * name -- name of device + * cmd -- the command (actually, the device name + * argv -- argument vector + * doit -- if non-zero, set device name. Otherwise, just check if possible * %RETURNS: * 1 if we will handle this device; 0 otherwise. * %DESCRIPTION: @@ -263,12 +245,24 @@ struct channel pppoe_channel; * sets up devnam (string representation of device). ***********************************************************************/ static int -PPPoEDevnameHook(const char *name) +PPPoEDevnameHook(char *cmd, char **argv, int doit) { int r = 1; int fd; struct ifreq ifr; + /* Only do it if name is "ethXXX", "nasXXX", "tapXXX" or "nic-XXXX. + In latter case strip off the "nic-" */ + /* Thanks to Russ Couturier for this fix */ + if (strlen(cmd) > 4 && !strncmp(cmd, "nic-", 4)) { + /* Strip off "nic-" */ + cmd += 4; + } else if (strlen(cmd) < 4 + || (strncmp(cmd, "eth", 3) && strncmp(cmd, "nas", 3) + && strncmp(cmd, "tap", 3) && strncmp(cmd, "br", 2))) { + return 0; + } + /* Open a socket */ if ((fd = socket(PF_PACKET, SOCK_RAW, 0)) < 0) { r = 0; @@ -276,7 +270,7 @@ PPPoEDevnameHook(const char *name) /* Try getting interface index */ if (r) { - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strncpy(ifr.ifr_name, cmd, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) { r = 0; } else { @@ -284,7 +278,7 @@ PPPoEDevnameHook(const char *name) r = 0; } else { if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) { - error("Interface %s not Ethernet", name); + error("Interface %s not Ethernet", cmd); r=0; } } @@ -294,7 +288,7 @@ PPPoEDevnameHook(const char *name) /* Close socket */ close(fd); if (r) { - strncpy(devnam, name, sizeof(devnam)); + strncpy(devnam, cmd, sizeof(devnam)); if (the_channel != &pppoe_channel) { the_channel = &pppoe_channel; @@ -309,6 +303,9 @@ PPPoEDevnameHook(const char *name) lcp_allowoptions[0].neg_pcompression = 0; lcp_wantoptions[0].neg_pcompression = 0; + lcp_allowoptions[0].mru = MAX_PPPOE_MTU; + lcp_wantoptions[0].mru = MAX_PPPOE_MTU; + ccp_allowoptions[0].deflate = 0 ; ccp_wantoptions[0].deflate = 0 ; @@ -323,7 +320,6 @@ PPPoEDevnameHook(const char *name) return 1; } - if (OldDevnameHook) r = OldDevnameHook(name); return r; } @@ -412,7 +408,7 @@ struct channel pppoe_channel = { disconnect: &PPPOEDisconnectDevice, establish_ppp: &generic_establish_ppp, disestablish_ppp: &generic_disestablish_ppp, - send_config: &PPPOESendConfig, + send_config: NULL, recv_config: &PPPOERecvConfig, close: NULL, cleanup: NULL