Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/tcpdump Add support for the new NetBSD PPP data lin...



details:   https://anonhg.NetBSD.org/src/rev/92398ac9fa33
branches:  trunk
changeset: 472876:92398ac9fa33
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue May 11 02:54:29 1999 +0000

description:
Add support for the new NetBSD PPP data link types, add some more
PPP definitions, and handle Cisco-format frames that come in off
of sync PPP interfaces.

diffstat:

 usr.sbin/tcpdump/interface.h |    4 +-
 usr.sbin/tcpdump/ppp.h       |   35 +++++++-
 usr.sbin/tcpdump/print-ppp.c |  208 ++++++++++++++++++++++++++++++++++++++++++-
 usr.sbin/tcpdump/tcpdump.c   |    5 +-
 4 files changed, 244 insertions(+), 8 deletions(-)

diffs (truncated from 358 to 300 lines):

diff -r f246aa0c40c8 -r 92398ac9fa33 usr.sbin/tcpdump/interface.h
--- a/usr.sbin/tcpdump/interface.h      Tue May 11 02:20:56 1999 +0000
+++ b/usr.sbin/tcpdump/interface.h      Tue May 11 02:54:29 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: interface.h,v 1.7 1999/03/23 00:02:24 bad Exp $        */
+/*     $NetBSD: interface.h,v 1.8 1999/05/11 02:54:29 thorpej Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -229,6 +229,8 @@
 extern void ppp_if_print(u_char *, const struct pcap_pkthdr *, const u_char *);
 extern void ppp_bsdos_if_print(u_char *, const struct pcap_pkthdr *,
        const u_char *);
+extern void ppp_netbsd_serial_if_print(u_char *, const struct pcap_pkthdr *,
+       const u_char *);
 extern void raw_if_print(u_char *, const struct pcap_pkthdr *, const u_char *);
 extern void rip_print(const u_char *, u_int);
 extern void sl_if_print(u_char *, const struct pcap_pkthdr *, const u_char *);
diff -r f246aa0c40c8 -r 92398ac9fa33 usr.sbin/tcpdump/ppp.h
--- a/usr.sbin/tcpdump/ppp.h    Tue May 11 02:20:56 1999 +0000
+++ b/usr.sbin/tcpdump/ppp.h    Tue May 11 02:54:29 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ppp.h,v 1.1.1.1 1997/10/03 17:25:18 christos Exp $     */
+/*     $NetBSD: ppp.h,v 1.2 1999/05/11 02:54:29 thorpej Exp $  */
 
 /* @(#) Header: ppp.h,v 1.7 95/05/04 17:52:46 mccanne Exp  (LBL) */
 /*
@@ -20,6 +20,14 @@
 #define PPP_ADDRESS    0xff    /* The address byte value */
 #define PPP_CONTROL    0x03    /* The control byte value */
 
+/* Actual address byte values */
+#define        PPP_ADDR_ALLSTATIONS    0xff    /* all stations broadcast addr */
+#define        PPP_ADDR_CISCO_MULTICAST 0x8f   /* Cisco multicast address */
+#define        PPP_ADDR_CISCO_UNICAST  0x0f    /* Cisco unicast address */
+
+/* Actual control byte values */
+#define        PPP_CTRL_UI             0x03    /* unnumbered information */
+
 /* Protocol numbers */
 #define PPP_IP         0x0021  /* Raw IP */
 #define PPP_OSI                0x0023  /* OSI Network Layer */
@@ -32,6 +40,7 @@
 #define PPP_BRPDU      0x0031  /* Bridging PDU */
 #define PPP_STII       0x0033  /* Stream Protocol (ST-II) */
 #define PPP_VINES      0x0035  /* Banyan Vines */
+#define        PPP_IPV6        0x0057  /* IPv6 */
 
 #define PPP_HELLO      0x0201  /* 802.1d Hello Packets */
 #define PPP_LUXCOM     0x0231  /* Luxcom */
@@ -46,7 +55,31 @@
 #define PPP_STIICP     0x8033  /* Strean Protocol Control Protocol */
 #define PPP_VINESCP    0x8035  /* Banyan Vines Control Protocol */
 
+/*
+ * XXX Note, this is overloaded with VINESCP, but we can tell based on
+ * XXX the address byte if we're using Cisco protocol numbers (i.e.
+ * XXX Ethertypes).
+ */
+#define        PPP_CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */
+
 #define PPP_LCP                0xc021  /* Link Control Protocol */
 #define PPP_PAP                0xc023  /* Password Authentication Protocol */
 #define PPP_LQM                0xc025  /* Link Quality Monitoring */
+#define        PPP_CBCP        0xc029  /* Callback Control Protocol */
 #define PPP_CHAP       0xc223  /* Challenge Handshake Authentication Protocol */
+
+/*
+ * Structure of a Cisco keepalive packet.
+ */
+#define        CISCO_KEEP_TYPE_OFF     0       /* 4 bytes */
+#define        CISCO_KEEP_PAR1_OFF     4       /* 4 bytes */
+#define        CISCO_KEEP_PAR2_OFF     8       /* 4 bytes */
+#define        CISCO_KEEP_REL_OFF      10      /* 2 bytes */
+#define        CISCO_KEEP_TIME0_OFF    12      /* 2 bytes */
+#define        CISCO_KEEP_TIME1_OFF    14      /* 2 bytes */
+
+#define        CISCO_KEEP_LEN          18
+
+#define        CISCO_KEEP_TYPE_ADDR_REQ        0
+#define        CISCO_KEEP_TYPE_ADDR_REPLY      1
+#define        CISCO_KEEP_TYPE_KEEP_REQ        2
diff -r f246aa0c40c8 -r 92398ac9fa33 usr.sbin/tcpdump/print-ppp.c
--- a/usr.sbin/tcpdump/print-ppp.c      Tue May 11 02:20:56 1999 +0000
+++ b/usr.sbin/tcpdump/print-ppp.c      Tue May 11 02:54:29 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: print-ppp.c,v 1.4 1997/10/03 19:55:36 christos Exp $   */
+/*     $NetBSD: print-ppp.c,v 1.5 1999/05/11 02:54:30 thorpej Exp $    */
 
 /*
  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
@@ -27,7 +27,7 @@
 static const char rcsid[] =
     "@(#) Header: print-ppp.c,v 1.26 97/06/12 14:21:29 leres Exp  (LBL)";
 #else
-__RCSID("$NetBSD: print-ppp.c,v 1.4 1997/10/03 19:55:36 christos Exp $");
+__RCSID("$NetBSD: print-ppp.c,v 1.5 1999/05/11 02:54:30 thorpej Exp $");
 #endif
 #endif
 
@@ -43,6 +43,12 @@
 #endif
 #include <net/if.h>
 
+#ifdef __NetBSD__
+#include <net/if_ether.h>
+#else
+#include <netinet/if_ether.h>
+#endif
+
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
 #include <netinet/ip.h>
@@ -54,6 +60,7 @@
 
 #include "interface.h"
 #include "addrtoname.h"
+#include "ethertype.h"
 #include "ppp.h"
 
 /* XXX This goes somewhere else. */
@@ -99,11 +106,38 @@
 
 /* proto type to string mapping */
 static struct tok ptype2str[] = {
+       { PPP_IP,       "IP" },
+       { PPP_OSI,      "OSI" },
+       { PPP_NS,       "NS" },
+       { PPP_DECNET,   "DEC" },
+       { PPP_APPLE,    "AT" },
+       { PPP_IPX,      "IPX" },
        { PPP_VJC,      "VJC" },
        { PPP_VJNC,     "VJNC" },
-       { PPP_OSI,      "OSI" },
+       { PPP_BRPDU,    "BRPDU" },
+       { PPP_STII,     "STII" },
+       { PPP_VINES,    "VINES" },
+       { PPP_IPV6,     "IPv6" },
+
+       { PPP_HELLO,    "HELLO" },
+       { PPP_LUXCOM,   "LUXCOM" },
+       { PPP_SNS,      "SNS" },
+
+       { PPP_IPCP,     "IPCP" },
+       { PPP_OSICP,    "OSICP" },
+       { PPP_NSCP,     "NSCP" },
+       { PPP_DECNETCP, "DECCP" },
+       { PPP_APPLECP,  "ATCP" },
+       { PPP_IPXCP,    "IPXCP" },
+       { PPP_STIICP,   "STIICP" },
+       { PPP_VINESCP,  "VINESCP" },
+
        { PPP_LCP,      "LCP" },
-       { PPP_IPCP,     "IPCP" },
+       { PPP_PAP,      "PAP" },
+       { PPP_LQM,      "LQM" },
+       { PPP_CBCP,     "CBCP" },
+       { PPP_CHAP,     "CHAP" },
+
        { 0,            NULL }
 };
 
@@ -173,3 +207,169 @@
 out:
        putchar('\n');
 }
+
+/*
+ * NetBSD-specific PPP printers.  Handles multiple PPP encaps, and
+ * Cisco frames.
+ */
+
+void   ppp_netbsd_common_print(const u_char *, u_int, u_int, u_short);
+
+#define        PPP_NETBSD_SERIAL_HDRLEN        4
+
+void
+ppp_netbsd_serial_if_print(u_char *user, const struct pcap_pkthdr *h,
+               register const u_char *p)
+{
+       register u_int length = h->len;
+       register u_int caplen = h->caplen;
+       u_short ptype;
+       u_char addr, ctrl;
+
+       ts_print(&h->ts);
+
+       if (caplen < PPP_NETBSD_SERIAL_HDRLEN) {
+               printf("[|ppp]");
+               goto out;
+       }
+
+       /*
+        * Some printers want to get back at the link level addresses,
+        * and/or check that they're not walking off the end of the packet.
+        * Rather than pass them all the way down, we set these globals.
+        */
+       packetp = p;
+       snapend = p + caplen;
+
+       addr = p[0];
+       ctrl = p[1];
+
+       switch (addr) {
+       case PPP_ADDR_ALLSTATIONS:
+               /*
+                * Regular serial PPP packet.
+                */
+               if (eflag)
+                       printf("%02x %02x %d ", p[0], p[1], length);
+
+               ptype = (p[2] << 8) | p[3];
+
+               p += PPP_NETBSD_SERIAL_HDRLEN;
+               length -= PPP_NETBSD_SERIAL_HDRLEN;
+               caplen -= PPP_NETBSD_SERIAL_HDRLEN;
+
+               ppp_netbsd_common_print(p, length, caplen, ptype);
+               break;
+
+       case PPP_ADDR_CISCO_MULTICAST:
+       case PPP_ADDR_CISCO_UNICAST:
+               if (eflag) {
+                       /* Control field not valid here. */
+                       printf("CISCO %02x %d ", p[0], length);
+               }
+
+               ptype = (p[2] << 8) | p[3];
+
+               p += PPP_NETBSD_SERIAL_HDRLEN;
+               length -= PPP_NETBSD_SERIAL_HDRLEN;
+               caplen -= PPP_NETBSD_SERIAL_HDRLEN;
+
+               switch (ptype) {
+               case PPP_CISCO_KEEPALIVE:
+                   {
+                       u_int type, par1, par2;
+                       u_short rel, time0, time1;
+
+                       if (caplen < CISCO_KEEP_LEN) {
+                               printf("[!cisco keepalive]");
+                               goto out;
+                       }
+
+#define        GET4(p, o) \
+       (p)[(o) + 0] << 24 | \
+       (p)[(o) + 1] << 16 | \
+       (p)[(o) + 2] << 8  | \
+       (p)[(o) + 3]
+
+                       type = GET4(p, CISCO_KEEP_TYPE_OFF);
+                       par1 = GET4(p, CISCO_KEEP_PAR1_OFF);
+                       par2 = GET4(p, CISCO_KEEP_PAR2_OFF);
+
+#undef GET4
+
+#define        GET2(p, o) \
+       (p)[(o) + 0] << 8 | \
+       (p)[(o) + 1]
+
+                       rel = GET2(p, CISCO_KEEP_REL_OFF);
+                       time0 = GET2(p, CISCO_KEEP_TIME0_OFF);
+                       time1 = GET2(p, CISCO_KEEP_TIME1_OFF);
+
+#undef GET2
+
+                       switch(type) {
+                       case CISCO_KEEP_TYPE_ADDR_REPLY:
+                               printf("CISCO ADDR REPLY ");
+                               break;
+
+                       case CISCO_KEEP_TYPE_KEEP_REQ:
+                               printf("CISCO KEEP REQ ");
+                               break;
+
+                       case CISCO_KEEP_TYPE_ADDR_REQ:
+                               printf("CISCO ADDR REQ ");
+                               break;
+
+                       default:
+                               printf("CISCO type %04x ", type);
+                       }
+
+                       printf("%08x %08x %08x %04x-%04x ",
+                           par1, par2, rel, time0, time1);
+
+                       p += CISCO_KEEP_LEN;
+                       length -= CISCO_KEEP_LEN;
+                       caplen -= CISCO_KEEP_LEN;
+                       break;
+                   }
+
+               default:
+                       if (ether_encap_print(ptype, p, length, caplen) == 0)
+                               printf("proto-#%d ", ptype);
+               }
+
+               if (xflag)
+                       default_print((const u_char *)p, caplen);
+               break;



Home | Main Index | Thread Index | Old Index