X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fplugins%2Frp-pppoe%2Fplugin.c;h=b84a6af696d192448151ed84ac6b38fdaa929a9d;hp=afb6b09108667ca2a8ba031dabb92a28b995d118;hb=ccc4c4604dd9e7316fe734b41b7327aa5906de3e;hpb=5580a43ba47c96ff41046226a9409c31b5efc8d2 diff --git a/pppd/plugins/rp-pppoe/plugin.c b/pppd/plugins/rp-pppoe/plugin.c index afb6b09..b84a6af 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.3 2002/02/12 04:36:00 mostrows Exp $"; +"$Id: plugin.c,v 1.15 2006/05/29 23:29:16 paulus Exp $"; #define _GNU_SOURCE 1 #include "pppoe.h" @@ -59,18 +59,18 @@ 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" }, @@ -80,7 +80,7 @@ static option_t Options[] = { "Be verbose about discovered access concentrators"}, { NULL } }; -int (*OldDevnameHook)(const char *name) = NULL; + static PPPoEConnection *conn = NULL; /********************************************************************** @@ -103,8 +103,8 @@ 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; @@ -144,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; } } @@ -180,41 +181,16 @@ 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 0 /* broken protocol, but no point harrassing the users I guess... */ + if (mru > MAX_PPPOE_MTU) + warn("Couldn't increase MRU to %d", mru); +#endif } /********************************************************************** @@ -242,6 +218,8 @@ PPPOEDisconnectDevice(void) return; } close(conn->sessionSocket); + /* don't send PADT?? */ + close(conn->discoverySocket); } static void @@ -259,7 +237,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: @@ -267,12 +247,22 @@ 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; + /* + * Take any otherwise-unrecognized option as a possible device name, + * and test if it is the name of a network interface with a + * hardware address whose sa_family is ARPHRD_ETHER. + */ + if (strlen(cmd) > 4 && !strncmp(cmd, "nic-", 4)) { + /* Strip off "nic-" */ + cmd += 4; + } + /* Open a socket */ if ((fd = socket(PF_PACKET, SOCK_RAW, 0)) < 0) { r = 0; @@ -280,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 { @@ -288,8 +278,9 @@ PPPoEDevnameHook(const char *name) r = 0; } else { if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) { - error("Interface %s not Ethernet", name); - r=0; + if (doit) + error("Interface %s not Ethernet", cmd); + r = 0; } } } @@ -297,37 +288,18 @@ PPPoEDevnameHook(const char *name) /* Close socket */ close(fd); - if (r) { - strncpy(devnam, name, sizeof(devnam)); + if (r && doit) { + strncpy(devnam, cmd, sizeof(devnam)); if (the_channel != &pppoe_channel) { the_channel = &pppoe_channel; modem = 0; - lcp_allowoptions[0].neg_accompression = 0; - lcp_wantoptions[0].neg_accompression = 0; - - lcp_allowoptions[0].neg_asyncmap = 0; - lcp_wantoptions[0].neg_asyncmap = 0; - - lcp_allowoptions[0].neg_pcompression = 0; - lcp_wantoptions[0].neg_pcompression = 0; - - ccp_allowoptions[0].deflate = 0 ; - ccp_wantoptions[0].deflate = 0 ; - - ipcp_allowoptions[0].neg_vj=0; - ipcp_wantoptions[0].neg_vj=0; - - ccp_allowoptions[0].bsd_compress = 0; - ccp_wantoptions[0].bsd_compress = 0; - PPPOEInitDevice(); } return 1; } - if (OldDevnameHook) r = OldDevnameHook(name); return r; } @@ -407,16 +379,41 @@ sysErr(char const *str) rp_fatal(str); } +void pppoe_check_options(void) +{ + lcp_allowoptions[0].neg_accompression = 0; + lcp_wantoptions[0].neg_accompression = 0; + + lcp_allowoptions[0].neg_asyncmap = 0; + lcp_wantoptions[0].neg_asyncmap = 0; + + lcp_allowoptions[0].neg_pcompression = 0; + lcp_wantoptions[0].neg_pcompression = 0; + + if (lcp_allowoptions[0].mru > MAX_PPPOE_MTU) + lcp_allowoptions[0].mru = MAX_PPPOE_MTU; + if (lcp_wantoptions[0].mru > MAX_PPPOE_MTU) + lcp_wantoptions[0].mru = MAX_PPPOE_MTU; + + ccp_allowoptions[0].deflate = 0; + ccp_wantoptions[0].deflate = 0; + + ipcp_allowoptions[0].neg_vj = 0; + ipcp_wantoptions[0].neg_vj = 0; + + ccp_allowoptions[0].bsd_compress = 0; + ccp_wantoptions[0].bsd_compress = 0; +} struct channel pppoe_channel = { options: Options, process_extra_options: &PPPOEDeviceOptions, - check_options: NULL, + check_options: pppoe_check_options, connect: &PPPOEConnectDevice, 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