From cc593def97b4f6f271fad15805b61c4773c4e30a Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Wed, 23 May 2001 03:39:14 +0000 Subject: [PATCH] add dump_packet, don't log lcp echo request/reply messages once the link is up unless debug >= 2 --- pppd/main.c | 14 ++++++++------ pppd/pppd.h | 4 +++- pppd/sys-linux.c | 3 +-- pppd/sys-solaris.c | 5 ++--- pppd/sys-sunos4.c | 5 ++--- pppd/sys-svr4.c | 5 ++--- pppd/utils.c | 34 +++++++++++++++++++++++++++++++++- 7 files changed, 51 insertions(+), 19 deletions(-) diff --git a/pppd/main.c b/pppd/main.c index 498f856..a09590e 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.106 2001/04/27 23:16:13 paulus Exp $" +#define RCSID "$Id: main.c,v 1.107 2001/05/23 03:39:13 paulus Exp $" #include #include @@ -468,7 +468,10 @@ main(argc, argv) * Start opening the connection and wait for * incoming events (reply, timeout, etc.). */ - notice("Connect: %s <--> %s", ifname, ppp_devnam); + if (ifunit >= 0) + notice("Connect: %s <--> %s", ifname, ppp_devnam); + else + notice("Starting negotiation on %s", ppp_devnam); gettimeofday(&start_time, NULL); link_stats_valid = 0; script_unsetenv("CONNECT_TIME"); @@ -942,14 +945,13 @@ get_input() return; } - if (debug /*&& (debugflags & DBG_INPACKET)*/) - dbglog("rcvd %P", p, len); - if (len < PPP_HDRLEN) { - MAINDEBUG(("io(): Received short packet.")); + dbglog("received short packet:%.*B", len, p); return; } + dump_packet("rcvd", p, len); + p += 2; /* Skip address and control */ GETSHORT(protocol, p); len -= PPP_HDRLEN; diff --git a/pppd/pppd.h b/pppd/pppd.h index 0437e7b..9e03a12 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.61 2001/05/23 02:28:14 paulus Exp $ + * $Id: pppd.h,v 1.62 2001/05/23 03:39:13 paulus Exp $ */ /* @@ -447,6 +447,8 @@ void fatal __P((char *, ...)); /* log an error message and die(1) */ void init_pr_log __P((char *, int)); /* initialize for using pr_log */ void pr_log __P((void *, char *, ...)); /* printer fn, output to syslog */ void end_pr_log __P((void)); /* finish up after using pr_log */ +void dump_packet __P((const char *, u_char *, int)); + /* dump packet to debug log if interesting */ /* Procedures exported from auth.c */ void link_required __P((int)); /* we are starting to use the link */ diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c index 252262e..918fa72 100644 --- a/pppd/sys-linux.c +++ b/pppd/sys-linux.c @@ -945,8 +945,7 @@ void output (int unit, unsigned char *p, int len) int fd = ppp_fd; int proto; - if (debug) - dbglog("sent %P", p, len); + dump_packet("sent", p, len); if (len < PPP_HDRLEN) return; diff --git a/pppd/sys-solaris.c b/pppd/sys-solaris.c index ff9c7de..fed68f5 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.5 2001/04/27 23:16:13 paulus Exp $" +#define RCSID "$Id: sys-solaris.c,v 1.6 2001/05/23 03:39:13 paulus Exp $" #include #include @@ -1292,8 +1292,7 @@ output(unit, p, len) int retries; struct pollfd pfd; - if (debug) - dbglog("sent %P", p, len); + dump_packet("sent", p, len); data.len = len; data.buf = (caddr_t) p; diff --git a/pppd/sys-sunos4.c b/pppd/sys-sunos4.c index 9159b4c..75e2120 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.27 2001/04/27 23:16:13 paulus Exp $" +#define RCSID "$Id: sys-sunos4.c,v 1.28 2001/05/23 03:39:13 paulus Exp $" #include #include @@ -574,8 +574,7 @@ output(unit, p, len) int retries; struct pollfd pfd; - if (debug) - dbglog("sent %P", p, len); + dump_packet("sent", p, len); data.len = len; data.buf = (caddr_t) p; diff --git a/pppd/sys-svr4.c b/pppd/sys-svr4.c index c64a78a..c9969bd 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.42 2000/04/06 23:11:05 masputra Exp $" +#define RCSID "$Id: sys-svr4.c,v 1.43 2001/05/23 03:39:14 paulus Exp $" #include #include @@ -1297,8 +1297,7 @@ output(unit, p, len) int retries; struct pollfd pfd; - if (debug) - dbglog("sent %P", p, len); + dump_packet("sent", p, len); data.len = len; data.buf = (caddr_t) p; diff --git a/pppd/utils.c b/pppd/utils.c index f305ea3..580363a 100644 --- a/pppd/utils.c +++ b/pppd/utils.c @@ -17,7 +17,7 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define RCSID "$Id: utils.c,v 1.13 2001/03/16 02:08:13 paulus Exp $" +#define RCSID "$Id: utils.c,v 1.14 2001/05/23 03:39:14 paulus Exp $" #include #include @@ -44,6 +44,8 @@ #endif #include "pppd.h" +#include "fsm.h" +#include "lcp.h" static const char rcsid[] = RCSID; @@ -761,6 +763,36 @@ dbglog __V((char *fmt, ...)) va_end(pvar); } +/* + * dump_packet - print out a packet in readable form if it is interesting. + * Assumes len >= PPP_HDRLEN. + */ +void +dump_packet(const char *tag, unsigned char *p, int len) +{ + int proto; + + if (!debug) + return; + + /* + * don't print LCP echo request/reply packets if debug <= 1 + * and the link is up. + */ + proto = (p[2] << 8) + p[3]; + if (debug <= 1 && unsuccess == 0 && proto == PPP_LCP + && len >= PPP_HDRLEN + HEADERLEN) { + unsigned char *lcp = p + PPP_HDRLEN; + int l = (lcp[2] << 8) + lcp[3]; + + if ((lcp[0] == ECHOREQ || lcp[0] == ECHOREP) + && l >= HEADERLEN && l <= len - PPP_HDRLEN) + return; + } + + dbglog("%s %P", tag, p - PPP_HDRLEN, len + PPP_HDRLEN); +} + /* Procedures for locking the serial device using a lock file. */ #ifndef LOCK_DIR #ifdef _linux_ -- 2.39.2