From c30d204fe82b18fb9668a05afb587a37f981696c Mon Sep 17 00:00:00 2001 From: "David F. Skoll" Date: Tue, 12 Feb 2002 20:07:10 +0000 Subject: [PATCH] Added new hooks: snoop_send_hook and snoop_recv_hook allow plugins to watch the flow of frames (typically we're interested in LCP frames). This is useful for implementing L2TP, because the L2TP access concentrator would like to collect some information from LCP and perhaps authentication protocols and forward the information to the LNS. --- PLUGINS | 9 ++++++++- pppd/main.c | 5 ++++- pppd/pppd.h | 6 +++++- pppd/sys-linux.c | 5 ++++- pppd/sys-solaris.c | 3 ++- pppd/sys-sunos4.c | 3 ++- pppd/sys-svr4.c | 3 ++- 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/PLUGINS b/PLUGINS index 206f8fc..e3e6718 100644 --- a/PLUGINS +++ b/PLUGINS @@ -211,6 +211,13 @@ address. If the hook returns 1, the address is accepted. If it returns in the normal away against the appropriate options and secrets files. +void (*snoop_recv_hook)(unsigned char *p, int len) +void (*snoop_send_hook)(unsigned char *p, int len) + +These hooks are called whenever pppd receives or sends a packet. The +packet is in p; its length is len. This allows plugins to "snoop in" +on the pppd conversation. The hooks may prove useful in implmenting +L2TP. A plugin registers itself with a notifier by declaring a procedure of the form: @@ -258,4 +265,4 @@ Here is a list of the currently-implemented notifiers in pppd. -## $Id: PLUGINS,v 1.4 2002/01/22 16:02:55 dfs Exp $ ## +## $Id: PLUGINS,v 1.5 2002/02/12 20:07:09 dfs Exp $ ## diff --git a/pppd/main.c b/pppd/main.c index 124f640..16231db 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -17,7 +17,7 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define RCSID "$Id: main.c,v 1.111 2002/01/22 16:02:58 dfs Exp $" +#define RCSID "$Id: main.c,v 1.112 2002/02/12 20:07:09 dfs Exp $" #include #include @@ -108,6 +108,8 @@ char db_key[32]; int (*holdoff_hook) __P((void)) = NULL; int (*new_phase_hook) __P((int)) = NULL; +void (*snoop_recv_hook) __P((unsigned char *p, int len)) = NULL; +void (*snoop_send_hook) __P((unsigned char *p, int len)) = NULL; static int conn_running; /* we have a [dis]connector running */ static int devfd; /* fd of underlying device */ @@ -968,6 +970,7 @@ get_input() } dump_packet("rcvd", p, len); + if (snoop_recv_hook) snoop_recv_hook(p, len); p += 2; /* Skip address and control */ GETSHORT(protocol, p); diff --git a/pppd/pppd.h b/pppd/pppd.h index 9e9f87b..5d287d6 100644 --- a/pppd/pppd.h +++ b/pppd/pppd.h @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: pppd.h,v 1.64 2002/01/22 16:02:58 dfs Exp $ + * $Id: pppd.h,v 1.65 2002/02/12 20:07:09 dfs Exp $ */ /* @@ -628,6 +628,10 @@ extern void (*ip_choose_hook) __P((u_int32_t *)); extern int (*chap_check_hook) __P((void)); extern int (*chap_passwd_hook) __P((char *user, char *passwd)); +/* Let a plugin snoop sent and received packets. Useful for L2TP */ +extern void (*snoop_recv_hook) __P((unsigned char *p, int len)); +extern void (*snoop_send_hook) __P((unsigned char *p, int len)); + /* * Inline versions of get/put char/short/long. * Pointer is advanced; we assume that both arguments diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c index f391dac..76fda67 100644 --- a/pppd/sys-linux.c +++ b/pppd/sys-linux.c @@ -127,7 +127,7 @@ static int master_fd = -1; #ifdef INET6 static int sock6_fd = -1; #endif /* INET6 */ -static int ppp_dev_fd = -1; /* fd for /dev/ppp (new style driver) */ +int ppp_dev_fd = -1; /* fd for /dev/ppp (new style driver) */ static int chindex; /* channel index (new style driver) */ static fd_set in_fds; /* set of fds that wait_input waits for */ @@ -946,6 +946,7 @@ void output (int unit, unsigned char *p, int len) int proto; dump_packet("sent", p, len); + if (snoop_send_hook) snoop_send_hook(p, len); if (len < PPP_HDRLEN) return; @@ -1512,6 +1513,8 @@ int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway) SET_SA_FAMILY (rt.rt_dst, AF_INET); SET_SA_FAMILY (rt.rt_gateway, AF_INET); + rt.rt_dev = ifname; + if (kernel_version > KVERSION(2,1,0)) { SET_SA_FAMILY (rt.rt_genmask, AF_INET); SIN_ADDR(rt.rt_genmask) = 0L; diff --git a/pppd/sys-solaris.c b/pppd/sys-solaris.c index fed68f5..dc2fe2b 100644 --- a/pppd/sys-solaris.c +++ b/pppd/sys-solaris.c @@ -42,7 +42,7 @@ * OR MODIFICATIONS. */ -#define RCSID "$Id: sys-solaris.c,v 1.6 2001/05/23 03:39:13 paulus Exp $" +#define RCSID "$Id: sys-solaris.c,v 1.7 2002/02/12 20:07:09 dfs Exp $" #include #include @@ -1293,6 +1293,7 @@ output(unit, p, len) struct pollfd pfd; dump_packet("sent", p, len); + if (snoop_send_hook) snoop_send_hook(p, len); data.len = len; data.buf = (caddr_t) p; diff --git a/pppd/sys-sunos4.c b/pppd/sys-sunos4.c index 75e2120..89eebf9 100644 --- a/pppd/sys-sunos4.c +++ b/pppd/sys-sunos4.c @@ -25,7 +25,7 @@ * OR MODIFICATIONS. */ -#define RCSID "$Id: sys-sunos4.c,v 1.28 2001/05/23 03:39:13 paulus Exp $" +#define RCSID "$Id: sys-sunos4.c,v 1.29 2002/02/12 20:07:09 dfs Exp $" #include #include @@ -575,6 +575,7 @@ output(unit, p, len) struct pollfd pfd; dump_packet("sent", p, len); + if (snoop_send_hook) snoop_send_hook(p, len); data.len = len; data.buf = (caddr_t) p; diff --git a/pppd/sys-svr4.c b/pppd/sys-svr4.c index c9969bd..b731e8f 100644 --- a/pppd/sys-svr4.c +++ b/pppd/sys-svr4.c @@ -42,7 +42,7 @@ * OR MODIFICATIONS. */ -#define RCSID "$Id: sys-svr4.c,v 1.43 2001/05/23 03:39:14 paulus Exp $" +#define RCSID "$Id: sys-svr4.c,v 1.44 2002/02/12 20:07:10 dfs Exp $" #include #include @@ -1298,6 +1298,7 @@ output(unit, p, len) struct pollfd pfd; dump_packet("sent", p, len); + if (snoop_send_hook) snoop_send_hook(p, len); data.len = len; data.buf = (caddr_t) p; -- 2.39.2