X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fplugins%2Fpppol2tp%2Fpppol2tp.c;h=ed2d7c7942a11db2ac6eb8152d0ad87507bf2886;hb=eff574c871822c7e2788aa8a928f2480fa7a6cb3;hp=a7e3400e72faed5ac0fac7991910af704f7920bf;hpb=c3480c5c56919a12f7bd34f8a9e193922c154fe9;p=ppp.git diff --git a/pppd/plugins/pppol2tp/pppol2tp.c b/pppd/plugins/pppol2tp/pppol2tp.c index a7e3400..ed2d7c7 100644 --- a/pppd/plugins/pppol2tp/pppol2tp.c +++ b/pppd/plugins/pppol2tp/pppol2tp.c @@ -20,6 +20,10 @@ * 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 +#endif + #include #include #include @@ -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; @@ -201,8 +207,8 @@ static void send_config_pppol2tp(int mtu, int on = 1; int fd; char reorderto[16]; - char tid[8]; - char sid[8]; + char tid[12]; + char sid[12]; if (pppol2tp_ifname[0]) { struct ifreq ifr; @@ -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 };