]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/pppoe/plugin.c
Let ./configure control the paths for pppd
[ppp.git] / pppd / plugins / pppoe / plugin.c
index de9b8166ce7bb1e982aaaacdf5f1049c3d225471..70205657202f90dd9cbe4f2b4087ca19cdb10ac8 100644 (file)
 static char const RCSID[] =
 "$Id: plugin.c,v 1.17 2008/06/15 04:35:50 paulus Exp $";
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #define _GNU_SOURCE 1
 #include "pppoe.h"
 
-#include "pppd/pppd.h"
-#include "pppd/fsm.h"
-#include "pppd/lcp.h"
-#include "pppd/ipcp.h"
-#include "pppd/ccp.h"
-/* #include "pppd/pathnames.h" */
-
 #include <linux/types.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -50,13 +48,15 @@ static char const RCSID[] =
 #include <linux/ppp_defs.h>
 #include <linux/if_pppox.h>
 
-#ifndef _ROOT_PATH
-#define _ROOT_PATH ""
-#endif
+#include <pppd/pppd.h>
+#include <pppd/fsm.h>
+#include <pppd/lcp.h>
+#include <pppd/ipcp.h>
+#include <pppd/ccp.h>
 
-#define _PATH_ETHOPT         _ROOT_PATH "/etc/ppp/options."
+#define PPP_PATH_ETHOPT         SYSCONFDIR "/ppp/options."
 
-char pppd_version[] = VERSION;
+char pppd_version[] = PPPD_VERSION;
 
 /* From sys-linux.c in pppd -- MUST FIX THIS! */
 extern int new_style_driver;
@@ -64,7 +64,7 @@ extern int new_style_driver;
 char *pppd_pppoe_service = NULL;
 static char *acName = NULL;
 static char *existingSession = NULL;
-static int printACNames = 0;
+int pppoe_verbose = 0;
 static char *pppoe_reqd_mac = NULL;
 unsigned char pppoe_reqd_mac_addr[6];
 static char *pppoe_host_uniq;
@@ -89,9 +89,9 @@ static option_t Options[] = {
       "Attach to existing session (sessid:macaddr)" },
     { "rp_pppoe_sess",    o_string, &existingSession,
       "Legacy alias for pppoe-sess", OPT_ALIAS },
-    { "pppoe-verbose", o_int, &printACNames,
+    { "pppoe-verbose", o_int, &pppoe_verbose,
       "Be verbose about discovered access concentrators" },
-    { "rp_pppoe_verbose", o_int, &printACNames,
+    { "rp_pppoe_verbose", o_int, &pppoe_verbose,
       "Legacy alias for pppoe-verbose", OPT_ALIAS },
     { "pppoe-mac", o_string, &pppoe_reqd_mac,
       "Only connect to specified MAC address" },
@@ -128,7 +128,6 @@ PPPOEInitDevice(void)
     conn->ifName = devnam;
     conn->discoverySocket = -1;
     conn->sessionSocket = -1;
-    conn->printACNames = printACNames;
     conn->discoveryTimeout = pppoe_padi_timeout;
     conn->discoveryAttempts = pppoe_padi_attempts;
     return 1;
@@ -162,8 +161,8 @@ PPPOEConnectDevice(void)
     }
 
     /* Restore configuration */
-    lcp_allowoptions[0].mru = conn->mtu;
-    lcp_wantoptions[0].mru = conn->mru;
+    lcp_allowoptions[0].mru = conn->mtu = conn->storedmtu;
+    lcp_wantoptions[0].mru = conn->mru = conn->storedmru;
 
     /* Update maximum MRU */
     s = socket(AF_INET, SOCK_DGRAM, 0);
@@ -180,9 +179,9 @@ PPPOEConnectDevice(void)
     close(s);
 
     if (lcp_allowoptions[0].mru > ifr.ifr_mtu - TOTAL_OVERHEAD)
-       lcp_allowoptions[0].mru = ifr.ifr_mtu - TOTAL_OVERHEAD;
+       lcp_allowoptions[0].mru = conn->mtu = ifr.ifr_mtu - TOTAL_OVERHEAD;
     if (lcp_wantoptions[0].mru > ifr.ifr_mtu - TOTAL_OVERHEAD)
-       lcp_wantoptions[0].mru = ifr.ifr_mtu - TOTAL_OVERHEAD;
+       lcp_wantoptions[0].mru = conn->mru = ifr.ifr_mtu - TOTAL_OVERHEAD;
 
     if (pppoe_host_uniq) {
        if (!parseHostUniq(pppoe_host_uniq, &conn->hostUniq))
@@ -197,7 +196,7 @@ PPPOEConnectDevice(void)
 
     conn->acName = acName;
     conn->serviceName = pppd_pppoe_service;
-    strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam));
+    strlcpy(ppp_devnam, devnam, MAXPATHLEN);
     if (existingSession) {
        unsigned int mac[ETH_ALEN];
        int i, ses;
@@ -217,9 +216,20 @@ PPPOEConnectDevice(void)
            error("Failed to create PPPoE discovery socket: %m");
            goto errout;
        }
-       discovery(conn);
+       discovery1(conn);
+       /* discovery1() may update conn->mtu and conn->mru */
+       lcp_allowoptions[0].mru = conn->mtu;
+       lcp_wantoptions[0].mru = conn->mru;
+       if (conn->discoveryState != STATE_RECEIVED_PADO) {
+           error("Unable to complete PPPoE Discovery phase 1");
+           goto errout;
+       }
+       discovery2(conn);
+       /* discovery2() may update conn->mtu and conn->mru */
+       lcp_allowoptions[0].mru = conn->mtu;
+       lcp_wantoptions[0].mru = conn->mru;
        if (conn->discoveryState != STATE_SESSION) {
-           error("Unable to complete PPPoE Discovery");
+           error("Unable to complete PPPoE Discovery phase 2");
            goto errout;
        }
     }
@@ -317,7 +327,7 @@ PPPOEDeviceOptions(void)
 {
     char buf[MAXPATHLEN];
 
-    strlcpy(buf, _PATH_ETHOPT, MAXPATHLEN);
+    strlcpy(buf, PPP_PATH_ETHOPT, MAXPATHLEN);
     strlcat(buf, devnam, MAXPATHLEN);
     if (!options_from_file(buf, 0, 0, 1))
        exit(EXIT_OPTION_ERROR);
@@ -381,7 +391,7 @@ PPPoEDevnameHook(char *cmd, char **argv, int doit)
     /* Close socket */
     close(fd);
     if (r && doit) {
-       strlcpy(devnam, cmd, sizeof(devnam));
+       strlcpy(devnam, cmd, MAXPATHLEN);
        if (the_channel != &pppoe_channel) {
 
            the_channel = &pppoe_channel;
@@ -413,7 +423,7 @@ plugin_init(void)
 
     add_options(Options);
 
-    info("PPPoE plugin from pppd %s", VERSION);
+    info("PPPoE plugin from pppd %s", PPPD_VERSION);
 }
 
 void pppoe_check_options(void)
@@ -448,8 +458,8 @@ void pppoe_check_options(void)
        lcp_wantoptions[0].mru = MAX_PPPOE_MTU;
 
     /* Save configuration */
-    conn->mtu = lcp_allowoptions[0].mru;
-    conn->mru = lcp_wantoptions[0].mru;
+    conn->storedmtu = lcp_allowoptions[0].mru;
+    conn->storedmru = lcp_wantoptions[0].mru;
 
     ccp_allowoptions[0].deflate = 0;
     ccp_wantoptions[0].deflate = 0;