]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/pppoe/plugin.c
Header file reorganization and cleaning up the public API for pppd version 2.5.0...
[ppp.git] / pppd / plugins / pppoe / plugin.c
index 70205657202f90dd9cbe4f2b4087ca19cdb10ac8..ee9d343835b8a83995d15648f9ba10e2d8483f45 100644 (file)
@@ -49,13 +49,12 @@ static char const RCSID[] =
 #include <linux/if_pppox.h>
 
 #include <pppd/pppd.h>
+#include <pppd/options.h>
 #include <pppd/fsm.h>
 #include <pppd/lcp.h>
 #include <pppd/ipcp.h>
 #include <pppd/ccp.h>
 
-#define PPP_PATH_ETHOPT         SYSCONFDIR "/ppp/options."
-
 char pppd_version[] = PPPD_VERSION;
 
 /* From sys-linux.c in pppd -- MUST FIX THIS! */
@@ -70,9 +69,10 @@ unsigned char pppoe_reqd_mac_addr[6];
 static char *pppoe_host_uniq;
 static int pppoe_padi_timeout = PADI_TIMEOUT;
 static int pppoe_padi_attempts = MAX_PADI_ATTEMPTS;
+static char devnam[MAXNAMELEN];
 
 static int PPPoEDevnameHook(char *cmd, char **argv, int doit);
-static option_t Options[] = {
+static struct option Options[] = {
     { "device name", o_wild, (void *) &PPPoEDevnameHook,
       "PPPoE device name",
       OPT_DEVNAM | OPT_PRIVFIX | OPT_NOARG  | OPT_A2STRVAL | OPT_STATIC,
@@ -148,6 +148,7 @@ PPPOEConnectDevice(void)
     struct sockaddr_pppox sp;
     struct ifreq ifr;
     int s;
+    char remote_number[MAXNAMELEN];
 
     /* Open session socket before discovery phase, to avoid losing session */
     /* packets sent by peer just after PADS packet (noted on some Cisco    */
@@ -196,7 +197,7 @@ PPPOEConnectDevice(void)
 
     conn->acName = acName;
     conn->serviceName = pppd_pppoe_service;
-    strlcpy(ppp_devnam, devnam, MAXPATHLEN);
+    ppp_set_pppdevnam(devnam);
     if (existingSession) {
        unsigned int mac[ETH_ALEN];
        int i, ses;
@@ -235,7 +236,7 @@ PPPOEConnectDevice(void)
     }
 
     /* Set PPPoE session-number for further consumption */
-    ppp_session_number = ntohs(conn->session);
+    ppp_set_session_number(ntohs(conn->session));
 
     sp.sa_family = AF_PPPOX;
     sp.sa_protocol = PX_PROTO_OE;
@@ -251,17 +252,10 @@ PPPOEConnectDevice(void)
            (unsigned) conn->peerEth[3],
            (unsigned) conn->peerEth[4],
            (unsigned) conn->peerEth[5]);
+    warn("Connected to %s via interface %s", remote_number, conn->ifName);
+    ppp_set_remote_number(remote_number);
 
-    warn("Connected to %02X:%02X:%02X:%02X:%02X:%02X via interface %s",
-        (unsigned) conn->peerEth[0],
-        (unsigned) conn->peerEth[1],
-        (unsigned) conn->peerEth[2],
-        (unsigned) conn->peerEth[3],
-        (unsigned) conn->peerEth[4],
-        (unsigned) conn->peerEth[5],
-        conn->ifName);
-
-    script_setenv("MACREMOTE", remote_number, 0);
+    ppp_script_setenv("MACREMOTE", remote_number, 0);
 
     if (connect(conn->sessionSocket, (struct sockaddr *) &sp,
                sizeof(struct sockaddr_pppox)) < 0) {
@@ -325,13 +319,17 @@ PPPOEDisconnectDevice(void)
 static void
 PPPOEDeviceOptions(void)
 {
+    char name[MAXPATHLEN];
     char buf[MAXPATHLEN];
 
-    strlcpy(buf, PPP_PATH_ETHOPT, MAXPATHLEN);
-    strlcat(buf, devnam, MAXPATHLEN);
-    if (!options_from_file(buf, 0, 0, 1))
-       exit(EXIT_OPTION_ERROR);
-
+    slprintf(name, sizeof(name), "options.%s", devnam);
+       if (ppp_get_filepath(PPP_DIR_CONF, name, buf, sizeof(buf)) < sizeof(buf)) {
+               if (!ppp_options_from_file(buf, 0, 0, 1)) {
+                       exit(EXIT_OPTION_ERROR);
+               }
+       } else {
+               exit(EXIT_OPTION_ERROR);
+       }
 }
 
 struct channel pppoe_channel;
@@ -395,10 +393,11 @@ PPPoEDevnameHook(char *cmd, char **argv, int doit)
        if (the_channel != &pppoe_channel) {
 
            the_channel = &pppoe_channel;
-           modem = 0;
+           ppp_set_modem(0);
 
            PPPOEInitDevice();
        }
+       ppp_set_devnam(devnam);
        return 1;
     }
 
@@ -417,11 +416,11 @@ PPPoEDevnameHook(char *cmd, char **argv, int doit)
 void
 plugin_init(void)
 {
-    if (!ppp_available() && !new_style_driver) {
+    if (!ppp_check_kernel_support() && !new_style_driver) {
        fatal("Linux kernel does not support PPPoE -- are you running 2.4.x?");
     }
 
-    add_options(Options);
+    ppp_add_options(Options);
 
     info("PPPoE plugin from pppd %s", PPPD_VERSION);
 }
@@ -435,7 +434,7 @@ void pppoe_check_options(void)
        if (sscanf(pppoe_reqd_mac, "%x:%x:%x:%x:%x:%x",
                   &mac[0], &mac[1], &mac[2], &mac[3],
                   &mac[4], &mac[5]) != 6) {
-           option_error("cannot parse pppoe-mac option value");
+           ppp_option_error("cannot parse pppoe-mac option value");
            exit(EXIT_OPTION_ERROR);
        }
        for (i = 0; i < 6; ++i)
@@ -477,8 +476,8 @@ struct channel pppoe_channel = {
     .check_options = pppoe_check_options,
     .connect = &PPPOEConnectDevice,
     .disconnect = &PPPOEDisconnectDevice,
-    .establish_ppp = &generic_establish_ppp,
-    .disestablish_ppp = &generic_disestablish_ppp,
+    .establish_ppp = &ppp_generic_establish,
+    .disestablish_ppp = &ppp_generic_disestablish,
     .send_config = NULL,
     .recv_config = &PPPOERecvConfig,
     .close = NULL,