]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/rp-pppoe/plugin.c
PPPoE updates: don't exit if discovery fails, cope with both
[ppp.git] / pppd / plugins / rp-pppoe / plugin.c
index afb6b09108667ca2a8ba031dabb92a28b995d118..00316ae5050979482e2c8f2925ec8d354f0c2f63 100644 (file)
@@ -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.10 2004/01/13 04:03:58 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;
+int (*OldDevnameHook)(char *cmd, char **argv, int doit) = 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;
        }
     }
 
@@ -195,12 +196,14 @@ PPPOESendConfig(int mtu,
     }
     sock = socket(AF_INET, SOCK_DGRAM, 0);
     if (sock < 0) {
-       fatal("Couldn't create IP socket: %m");
+       error("Couldn't create IP socket: %m");
+       return;
     }
     strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
     ifr.ifr_mtu = mtu;
     if (ioctl(sock, SIOCSIFMTU, &ifr) < 0) {
-       fatal("ioctl(SIOCSIFMTU): %m");
+       error("Couldn't set interface MTU to %d: %m", mtu);
+       return;
     }
     (void) close (sock);
 }
@@ -212,9 +215,8 @@ PPPOERecvConfig(int mru,
                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);
 }
 
 /**********************************************************************
@@ -259,7 +261,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 +271,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))) {
+       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 +296,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 +304,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 +314,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 +343,7 @@ PPPoEDevnameHook(const char *name)
        return 1;
     }
 
-    if (OldDevnameHook) r = OldDevnameHook(name);
+    if (OldDevnameHook) r = OldDevnameHook(cmd, argv, doit);
     return r;
 }