X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fplugins%2Frp-pppoe%2Fplugin.c;h=a4784107e8755861bafb15a98ad8cd4f34077e97;hb=aefcf5ac90dee434d605167b6a719c58c0ffcf03;hp=e97d06a8a5aeb9c906426fb26313ac37f8e90952;hpb=de87fc02dd7cc8518d50edfd9f9dd4a32bb74703;p=ppp.git diff --git a/pppd/plugins/rp-pppoe/plugin.c b/pppd/plugins/rp-pppoe/plugin.c index e97d06a..a478410 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.4 2002/02/27 16:00:30 dfs Exp $"; +"$Id: plugin.c,v 1.7 2002/04/02 13:11:00 dfs Exp $"; #define _GNU_SOURCE 1 #include "pppoe.h" @@ -64,7 +64,7 @@ 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", @@ -80,7 +80,7 @@ static option_t Options[] = { "Be verbose about discovered access concentrators"}, { NULL } }; -int (*OldDevnameHook)(const char *name) = NULL; +int (*OldDevnameHook)(char *cmd, char **argv, int doit) = NULL; static PPPoEConnection *conn = NULL; /********************************************************************** @@ -259,7 +259,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 +269,23 @@ 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" 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)) { + if (OldDevnameHook) return OldDevnameHook(cmd, argv, doit); + return 0; + } + /* Open a socket */ if ((fd = socket(PF_PACKET, SOCK_RAW, 0)) < 0) { r = 0; @@ -280,7 +293,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,7 +301,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; } } @@ -298,7 +311,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; @@ -327,7 +340,7 @@ PPPoEDevnameHook(const char *name) return 1; } - if (OldDevnameHook) r = OldDevnameHook(name); + if (OldDevnameHook) r = OldDevnameHook(cmd, argv, doit); return r; }