]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/pppol2tp/pppol2tp.c
Fixing CLang warning: format specifies type 'unsigned short' but the argument has...
[ppp.git] / pppd / plugins / pppol2tp / pppol2tp.c
index a7e3400e72faed5ac0fac7991910af704f7920bf..f22568df5a0eea48ed64ef1e9bb75e38d21dcca5 100644 (file)
  *  as published by the Free Software Foundation; either version
  *  2 of the License, or (at your option) any later version.
  */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
@@ -74,8 +78,6 @@ struct channel pppol2tp_channel;
 
 static void (*old_snoop_recv_hook)(unsigned char *p, int len) = NULL;
 static void (*old_snoop_send_hook)(unsigned char *p, int len) = NULL;
-static void (*old_ip_up_hook)(void) = NULL;
-static void (*old_ip_down_hook)(void) = NULL;
 
 /* Hook provided to allow other plugins to handle ACCM changes */
 void (*pppol2tp_send_accm_hook)(int tunnel_id, int session_id,
@@ -123,10 +125,10 @@ static int setdevname_pppol2tp(char **argv)
                char buffer[128];
                struct sockaddr pppol2tp;
        } s;
-       int len = sizeof(s);
+       socklen_t len = sizeof(s);
        char **a;
        int tmp;
-       int tmp_len = sizeof(tmp);
+       socklen_t tmp_len = sizeof(tmp);
 
        if (device_got_set)
                return 0;
@@ -150,6 +152,10 @@ static int setdevname_pppol2tp(char **argv)
                fatal("PPPoL2TP kernel driver not installed");
        }
 
+       pppol2tp_fd_str = strdup(*argv);
+       if (pppol2tp_fd_str == NULL)
+               novm("PPPoL2TP FD");
+
        /* Setup option defaults. Compression options are disabled! */
 
        modem = 0;
@@ -235,10 +241,10 @@ static void send_config_pppol2tp(int mtu,
                sprintf(&reorderto[0], "%d ", pppol2tp_reorder_timeout);
        tid[0] = '\0';
        if (pppol2tp_tunnel_id > 0)
-               sprintf(&tid[0], "%hu ", pppol2tp_tunnel_id);
+               sprintf(&tid[0], "%u ", pppol2tp_tunnel_id);
        sid[0] = '\0';
        if (pppol2tp_session_id > 0)
-               sprintf(&sid[0], "%hu ", pppol2tp_session_id);
+               sprintf(&sid[0], "%u ", pppol2tp_session_id);
 
        dbglog("PPPoL2TP options: %s%s%s%s%s%s%s%s%sdebugmask %d",
               pppol2tp_recv_seq ? "recvseq " : "",
@@ -436,22 +442,18 @@ static void pppol2tp_lcp_snoop_send(unsigned char *p, int len)
  * Interface up/down events
  *****************************************************************************/
 
-static void pppol2tp_ip_up_hook(void)
+static void pppol2tp_ip_up(void *opaque, int arg)
 {
-       if (old_ip_up_hook != NULL)
-               (*old_ip_up_hook)();
-
+       /* may get called twice (for IPv4 and IPv6) but the hook handles that well */
        if (pppol2tp_ip_updown_hook != NULL) {
                (*pppol2tp_ip_updown_hook)(pppol2tp_tunnel_id,
                                           pppol2tp_session_id, 1);
        }
 }
 
-static void pppol2tp_ip_down_hook(void)
+static void pppol2tp_ip_down(void *opaque, int arg)
 {
-       if (old_ip_down_hook != NULL)
-               (*old_ip_down_hook)();
-
+       /* may get called twice (for IPv4 and IPv6) but the hook handles that well */
        if (pppol2tp_ip_updown_hook != NULL) {
                (*pppol2tp_ip_updown_hook)(pppol2tp_tunnel_id,
                                           pppol2tp_session_id, 0);
@@ -478,14 +480,6 @@ static void pppol2tp_check_options(void)
                snoop_recv_hook = pppol2tp_lcp_snoop_recv;
                snoop_send_hook = pppol2tp_lcp_snoop_send;
        }
-
-       /* Hook up ip up/down hooks to send indicator to openl2tpd
-        * that the link is up
-        */
-       old_ip_up_hook = ip_up_hook;
-       ip_up_hook = pppol2tp_ip_up_hook;
-       old_ip_down_hook = ip_down_hook;
-       ip_down_hook = pppol2tp_ip_down_hook;
 }
 
 /* Called just before pppd exits.
@@ -509,18 +503,26 @@ void plugin_init(void)
        fatal("No PPPoL2TP support on this OS");
 #endif
        add_options(pppol2tp_options);
+
+       /* Hook up ip up/down notifiers to send indicator to openl2tpd
+        * that the link is up
+        */
+       add_notifier(&ip_up_notifier, pppol2tp_ip_up, NULL);
+       add_notifier(&ip_down_notifier, pppol2tp_ip_down, NULL);
+       add_notifier(&ipv6_up_notifier, pppol2tp_ip_up, NULL);
+       add_notifier(&ipv6_down_notifier, pppol2tp_ip_down, NULL);
 }
 
 struct channel pppol2tp_channel = {
-    options: pppol2tp_options,
-    process_extra_options: NULL,
-    check_options: &pppol2tp_check_options,
-    connect: &connect_pppol2tp,
-    disconnect: &disconnect_pppol2tp,
-    establish_ppp: &generic_establish_ppp,
-    disestablish_ppp: &generic_disestablish_ppp,
-    send_config: &send_config_pppol2tp,
-    recv_config: &recv_config_pppol2tp,
-    close: NULL,
-    cleanup: NULL
+    .options = pppol2tp_options,
+    .process_extra_options = NULL,
+    .check_options = &pppol2tp_check_options,
+    .connect = &connect_pppol2tp,
+    .disconnect = &disconnect_pppol2tp,
+    .establish_ppp = &generic_establish_ppp,
+    .disestablish_ppp = &generic_disestablish_ppp,
+    .send_config = &send_config_pppol2tp,
+    .recv_config = &recv_config_pppol2tp,
+    .close = NULL,
+    .cleanup = NULL
 };