]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/pppoatm/pppoatm.c
pppd.8: Document netmask option
[ppp.git] / pppd / plugins / pppoatm / pppoatm.c
index 6621cba8d384c234da55086ebbc5de6b5c67aa5a..39d3dbdf4cab33c45434464413fe8c7a6ebfe926 100644 (file)
  *  as published by the Free Software Foundation; either version
  *  2 of the License, or (at your option) any later version.
  */
+
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
-#include "pppd.h"
-#include "pathnames.h"
-#include "fsm.h" /* Needed for lcp.h to include cleanly */
-#include "lcp.h"
 #include <atm.h>
 #include <linux/atmdev.h>
 #include <linux/atmppp.h>
 #include <sys/stat.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
+#include <sys/param.h>
+#include <stdbool.h>
+#include <stdarg.h>
+
+#include <pppd/pppd.h>
+#include <pppd/options.h>
+#include <pppd/fsm.h> /* Needed for lcp.h to include cleanly */
+#include <pppd/lcp.h>
+
 
-const char pppd_version[] = VERSION;
+const char pppd_version[] = PPPD_VERSION;
 
 static struct sockaddr_atmpvc pvcaddr;
 static char *qosstr = NULL;
@@ -38,8 +44,9 @@ static int pppoatm_max_mtu, pppoatm_max_mru;
 static int setdevname_pppoatm(const char *cp, const char **argv, int doit);
 struct channel pppoa_channel;
 static int pppoa_fd = -1;
+static char devnam[MAXNAMELEN];
 
-static option_t pppoa_options[] = {
+static struct option pppoa_options[] = {
        { "device name", o_wild, (void *) &setdevname_pppoatm,
          "ATM service provider IDs: VPI.VCI",
          OPT_DEVNAM | OPT_PRIVFIX | OPT_NOARG  | OPT_A2STRVAL | OPT_STATIC,
@@ -70,20 +77,23 @@ static int setdevname_pppoatm(const char *cp, const char **argv, int doit)
 {
        struct sockaddr_atmpvc addr;
        extern struct stat devstat;
+
        if (device_got_set)
                return 0;
-       //info("PPPoATM setdevname_pppoatm: '%s'", cp);
+
        memset(&addr, 0, sizeof addr);
        if (text2atm(cp, (struct sockaddr *) &addr, sizeof(addr),
-           T2A_PVC | T2A_NAME) < 0) {
-               if(doit)
-                   info("atm does not recognize: %s", cp);
+           T2A_PVC | T2A_NAME | T2A_WILDCARD) < 0) {
+               if (doit)
+                       info("cannot parse the ATM address: %s", cp);
                return 0;
-           }
-       if (!doit) return 1;
-       //if (!dev_set_ok()) return -1;
+       }
+       if (!doit)
+               return 1;
+
        memcpy(&pvcaddr, &addr, sizeof pvcaddr);
-       strlcpy(devnam, cp, sizeof devnam);
+       strlcpy(devnam, cp, sizeof(devnam));
+       ppp_set_devnam(devnam);
        devstat.st_mode = S_IFSOCK;
        if (the_channel != &pppoa_channel) {
                the_channel = &pppoa_channel;
@@ -93,7 +103,6 @@ static int setdevname_pppoatm(const char *cp, const char **argv, int doit)
                lcp_allowoptions[0].neg_asyncmap = 0;
                lcp_wantoptions[0].neg_pcompression = 0;
        }
-       info("PPPoATM setdevname_pppoatm - SUCCESS:%s", cp);
        device_got_set = 1;
        return 1;
 }
@@ -108,6 +117,7 @@ static void no_device_given_pppoatm(void)
 static void set_line_discipline_pppoatm(int fd)
 {
        struct atm_backend_ppp be;
+
        be.backend_num = ATM_BACKEND_PPP;
        if (!llc_encaps)
                be.encaps = PPPOATM_ENCAPS_VC;
@@ -115,6 +125,7 @@ static void set_line_discipline_pppoatm(int fd)
                be.encaps = PPPOATM_ENCAPS_LLC;
        else
                be.encaps = PPPOATM_ENCAPS_AUTODETECT;
+
        if (ioctl(fd, ATM_SETBACKEND, &be) < 0)
                fatal("ioctl(ATM_SETBACKEND): %m");
 }
@@ -133,8 +144,6 @@ static int connect_pppoatm(void)
        int fd;
        struct atm_qos qos;
 
-       system ("/sbin/modprobe -q pppoatm");
-
        if (!device_got_set)
                no_device_given_pppoatm();
        fd = socket(AF_ATMPVC, SOCK_DGRAM, 0);
@@ -158,7 +167,7 @@ static int connect_pppoatm(void)
        pppoatm_max_mtu = lcp_allowoptions[0].mru;
        pppoatm_max_mru = lcp_wantoptions[0].mru;
        set_line_discipline_pppoatm(fd);
-       strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam));
+       ppp_set_pppdevnam(devnam);
        pppoa_fd = fd;
        return fd;
 }
@@ -168,57 +177,29 @@ static void disconnect_pppoatm(void)
        close(pppoa_fd);
 }
 
-static void send_config_pppoa(int mtu,
-                             u_int32_t asyncmap,
-                             int pcomp,
-                             int accomp)
-{
-       int sock;
-       struct ifreq ifr;
-       if (mtu > pppoatm_max_mtu)
-               error("Couldn't increase MTU to %d", 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, (caddr_t) &ifr) < 0)
-               fatal("ioctl(SIOCSIFMTU): %m");
-       (void) close (sock);
-}
-
-static void recv_config_pppoa(int mru,
-                             u_int32_t asyncmap,
-                             int pcomp,
-                             int accomp)
-{
-       if (mru > pppoatm_max_mru)
-               error("Couldn't increase MRU to %d", mru);
-}
-
 void plugin_init(void)
 {
-#if defined(__linux__)
+#ifdef linux
        extern int new_style_driver;    /* From sys-linux.c */
-       if (!ppp_available() && !new_style_driver)
+       if (!ppp_check_kernel_support() && !new_style_driver)
                fatal("Kernel doesn't support ppp_generic - "
                    "needed for PPPoATM");
 #else
        fatal("No PPPoATM support on this OS");
 #endif
-       info("PPPoATM plugin_init");
-       add_options(pppoa_options);
+       ppp_add_options(pppoa_options);
 }
+
 struct channel pppoa_channel = {
-    options: pppoa_options,
-    process_extra_options: NULL,
-    check_options: NULL,
-    connect: &connect_pppoatm,
-    disconnect: &disconnect_pppoatm,
-    establish_ppp: &generic_establish_ppp,
-    disestablish_ppp: &generic_disestablish_ppp,
-    send_config: &send_config_pppoa,
-    recv_config: &recv_config_pppoa,
-    close: NULL,
-    cleanup: NULL
+    .options = pppoa_options,
+    .process_extra_options = NULL,
+    .check_options = NULL,
+    .connect = &connect_pppoatm,
+    .disconnect = &disconnect_pppoatm,
+    .establish_ppp = &ppp_generic_establish,
+    .disestablish_ppp = &ppp_generic_disestablish,
+    .send_config = NULL,
+    .recv_config = NULL,
+    .close = NULL,
+    .cleanup = NULL
 };