Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/tcpdump some merge from tcpdump.org code.



details:   https://anonhg.NetBSD.org/src/rev/3746020e9655
branches:  trunk
changeset: 495608:3746020e9655
user:      itojun <itojun%NetBSD.org@localhost>
date:      Tue Aug 01 17:29:47 2000 +0000

description:
some merge from tcpdump.org code.
- print-telnet.c: do not print control character
- print-icmp6.c: improve icmp6 node information printing
  (we need to at least meet our kernel code!)
- update dhcp6 printing to 15 draft (14 and 15 are totally incompatible)
- add safeputc() and safeputs() into util.c

diffstat:

 usr.sbin/tcpdump/dhcp6.h        |   36 ++-
 usr.sbin/tcpdump/interface.h    |    5 +-
 usr.sbin/tcpdump/print-dhcp6.c  |  161 ++++++++------
 usr.sbin/tcpdump/print-icmp6.c  |  433 ++++++++++++++++++++++++++++++---------
 usr.sbin/tcpdump/print-telnet.c |   26 +-
 usr.sbin/tcpdump/util.c         |   25 ++-
 6 files changed, 478 insertions(+), 208 deletions(-)

diffs (truncated from 1089 to 300 lines):

diff -r 58ead8e1649e -r 3746020e9655 usr.sbin/tcpdump/dhcp6.h
--- a/usr.sbin/tcpdump/dhcp6.h  Tue Aug 01 17:24:40 2000 +0000
+++ b/usr.sbin/tcpdump/dhcp6.h  Tue Aug 01 17:29:47 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dhcp6.h,v 1.1 1999/12/10 05:45:07 itojun Exp $ */
+/*     $NetBSD: dhcp6.h,v 1.2 2000/08/01 17:29:47 itojun Exp $ */
 
 /*
  * Copyright (C) 1998 and 1999 WIDE Project.
@@ -29,7 +29,7 @@
  * SUCH DAMAGE.
  */
 /*
- * draft-ietf-dhc-dhcpv6-14
+ * draft-ietf-dhc-dhcpv6-15
  */
 
 #ifndef __DHCP6_H_DEFINED
@@ -81,20 +81,27 @@
        u_int8_t dh6sol_msgtype;                /* DH6_SOLICIT */
        u_int8_t dh6sol_flags;
 #define DH6SOL_CLOSE   0x80
-       u_int8_t dh6sol_pad;
-       u_int8_t dh6sol_prefixsiz;      /* prefix-size */
+#define DH6SOL_PREFIX  0x40
+       /* XXX: solicit-ID is a 9-bit field...ugly! */
+#define DH6SOL_SOLICIT_ID_MASK 0x01ff
+#define DH6SOL_SOLICIT_ID_SHIFT 0
+#define DH6SOL_SOLICIT_ID(x) \
+    (((x) & DH6SOL_SOLICIT_ID_MASK) >> DH6SOL_SOLICIT_ID_SHIFT)
+#define DH6SOL_SOLICIT_PLEN_MASK 0xfe00
+#define DH6SOL_SOLICIT_PLEN_SHIFT 9
+#define DH6SOL_SOLICIT_PLEN(x) \
+    (((x) & DH6SOL_SOLICIT_PLEN_MASK) >> DH6SOL_SOLICIT_PLEN_SHIFT)
+       u_int16_t dh6sol_plen_id; /* prefix-len and solict-ID */
        struct in6_addr dh6sol_cliaddr; /* client's lladdr */
        struct in6_addr dh6sol_relayaddr; /* relay agent's lladdr */
 };
 
-/* NOTE: dhcpv6-12 and dhcpv6-13+n are not compatible at all */
 struct dhcp6_advert {
        u_int8_t dh6adv_msgtype;                /* DH6_ADVERT */
-       u_int8_t dh6adv_flags;
-#define DH6ADV_SERVPRESENT     0x80
-       u_int8_t dh6adv_pad;
+       u_int8_t dh6adv_rsv_id; /* reserved and uppermost bit of ID */
+       u_int8_t dh6adv_solcit_id; /* lower 8 bits of solicit-ID */
        u_int8_t dh6adv_pref;
-       struct in6_addr dh6adv_cliaddr; /* client's lladdr */
+       struct in6_addr dh6adv_cliaddr; /* client's link-local addr */
        struct in6_addr dh6adv_relayaddr; /* relay agent's (non-ll) addr */
        struct in6_addr dh6adv_serveraddr; /* server's addr */
        /* extensions */
@@ -104,25 +111,26 @@
        u_int8_t dh6req_msgtype;                /* DH6_REQUEST */
        u_int8_t dh6req_flags;
 #define DH6REQ_CLOSE           0x80
-#define DH6REQ_SERVPRESENT     0x40
-#define DH6REQ_REBOOT          0x20
+#define DH6REQ_REBOOT          0x40
        u_int16_t dh6req_xid;           /* transaction-ID */
        struct in6_addr dh6req_cliaddr; /* client's lladdr */
        struct in6_addr dh6req_relayaddr; /* relay agent's (non-ll) addr */
-       /* struct in6_addr dh6req_serveraddr; optional: server's addr */
+       struct in6_addr dh6req_serveraddr; /* server's addr */
        /* extensions */
 };
 
 struct dhcp6_reply {
        u_int8_t dh6rep_msgtype;                /* DH6_REPLY */
        u_int8_t dh6rep_flagandstat;
-#define DH6REP_CLIPRESENT      0x80
+#define DH6REP_RELAYPRESENT    0x80
 #define DH6REP_STATMASK                0x7f
        u_int16_t dh6rep_xid;           /* transaction-ID */
-       /* struct in6_addr dh6rep_cliaddr;      optional: client's lladdr */
+       struct in6_addr dh6rep_cliaddr; /* client's lladdr */
+       /* struct in6_addr dh6rep_relayaddr; optional: relay address */
        /* extensions */
 };
 
+/* XXX: followings are based on older drafts */
 struct dhcp6_release {
        u_int8_t dh6rel_msgtype;                /* DH6_RELEASE */
        u_int8_t dh6rel_flags;
diff -r 58ead8e1649e -r 3746020e9655 usr.sbin/tcpdump/interface.h
--- a/usr.sbin/tcpdump/interface.h      Tue Aug 01 17:24:40 2000 +0000
+++ b/usr.sbin/tcpdump/interface.h      Tue Aug 01 17:29:47 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: interface.h,v 1.13 2000/07/23 23:07:39 mycroft Exp $   */
+/*     $NetBSD: interface.h,v 1.14 2000/08/01 17:29:48 itojun Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -185,6 +185,9 @@
 extern char *read_infile(char *);
 extern char *copy_argv(char **);
 
+extern void safeputchar(int);
+extern void safeputs(const char *);
+
 extern char *isonsap_string(const u_char *);
 extern char *llcsap_string(u_char);
 extern char *protoid_string(const u_char *);
diff -r 58ead8e1649e -r 3746020e9655 usr.sbin/tcpdump/print-dhcp6.c
--- a/usr.sbin/tcpdump/print-dhcp6.c    Tue Aug 01 17:24:40 2000 +0000
+++ b/usr.sbin/tcpdump/print-dhcp6.c    Tue Aug 01 17:29:47 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: print-dhcp6.c,v 1.1 1999/12/10 05:45:08 itojun Exp $   */
+/*     $NetBSD: print-dhcp6.c,v 1.2 2000/08/01 17:29:48 itojun Exp $   */
 
 /*
  * Copyright (C) 1998 and 1999 WIDE Project.
@@ -35,7 +35,7 @@
 static const char rcsid[] =
     "@(#) KAME Header: /cvsroot/kame/kame/kame/kame/tcpdump/print-dhcp6.c,v 1.5 1999/11/02 14:55:01 itojun Exp";
 #else
-__RCSID("$NetBSD: print-dhcp6.c,v 1.1 1999/12/10 05:45:08 itojun Exp $");
+__RCSID("$NetBSD: print-dhcp6.c,v 1.2 2000/08/01 17:29:48 itojun Exp $");
 #endif
 #endif
 
@@ -77,36 +77,35 @@
        { 1, OL6_N,     "IP Address",                   OT6_NONE, },
 
        /* General Extension */
-       { 2, 4,         "Time Offset",                  OT6_NUM, },
-       { 3, OL6_N,     "IEEE 1003.1 POSIX Timezone",   OT6_STR, },
-       { 6, OL6_16N,   "Domain Name Server",           OT6_V6, },
-       { 10, OL6_N,    "Domain Name",                  OT6_STR, },
+       { 8193, OL6_N,  "IEEE 1003.1 POSIX Timezone",   OT6_STR, },
+       { 8194, OL6_16N, "Domain Name Server",          OT6_V6, },
+       { 8195, OL6_N,  "Domain Name",                  OT6_STR, },
 
-       /* Application and Service Parameters */
-       { 16, OL6_N,    "Directory Agent",              OT6_NONE, },
-       { 17, OL6_N,    "Service Scope" ,               OT6_NONE, },
-       { 18, OL6_16N,  "Network Time Protocol Servers", OT6_V6, },
-       { 19, OL6_N,    "NIS Domain",                   OT6_STR, },
-       { 20, OL6_16N,  "NIS Servers",                  OT6_V6, },
-       { 21, OL6_N,    "NIS+ Domain",                  OT6_STR, },
-       { 22, OL6_16N,  "NIS+ Servers",                 OT6_V6, },
+       { 8196, OL6_N,  "SLP Agent",                    OT6_NONE, },
+       { 8197, OL6_N,  "SLP Scope"     ,               OT6_NONE, },
+       { 8198, OL6_16N, "Network Time Protocol Servers", OT6_V6, },
+       { 8199, OL6_N,  "NIS Domain",                   OT6_STR, },
+       { 8200, OL6_16N, "NIS Servers",                 OT6_V6, },
+       { 8201, OL6_N,  "NIS+ Domain",                  OT6_STR, },
+       { 8202, OL6_16N, "NIS+ Servers",                OT6_V6, },
 
        /* TCP Parameters */
-       { 32, 4,        "TCP Keepalive Interval",       OT6_NUM, },
+       { 8203, 4,      "TCP Keepalive Interval",       OT6_NUM, },
 
        /* DHCPv6 Extensions */
-       { 40, 4,        "Maximum DHCPv6 Message Size",  OT6_NUM, },
-       { 41, OL6_N,    "DHCP Retransmission and Configuration Parameter",
+       { 8204, 4,      "Maximum DHCPv6 Message Size",  OT6_NUM, },
+       { 8205, OL6_N,  "DHCP Retransmission and Configuration Parameter",
                                                        OT6_NONE, },
-       { 48, OL6_N,    "Platform Specific Information", OT6_NONE, },
-       { 49, OL6_N,    "Platform Class Identifier",    OT6_STR, },
-       { 64, OL6_N,    "Class Identifier",             OT6_STR, },
-       { 66, 16,       "Reconfigure Multicast Address", OT6_V6, },
-       { 67, 16,       "Renumber DHCPv6 Server Address",
+       { 8206, OL6_N,  "Extension Request",            OT6_NONE, },
+       { 8207, OL6_N,  "Subnet Prefix",                OT6_NONE, },
+       { 8208, OL6_N,  "Platform Specific Information", OT6_NONE, },
+       { 8209, OL6_N,  "Platform Class Identifier",    OT6_STR, },
+       { 8210, OL6_N,  "Class Identifier",             OT6_STR, },
+       { 8211, 16,     "Reconfigure Multicast Address", OT6_V6, },
+       { 8212, 16,     "Renumber DHCPv6 Server Address",
                                                        OT6_V6, },
-       { 68, OL6_N,    "DHCP Relay ICMP Error Message", OT6_NONE, },
-       { 84, OL6_N,    "Client-Server Authentication", OT6_NONE, },
-       { 85, 4,        "Client Key Selection",         OT6_NUM, },
+       { 8213, OL6_N,  "Client-Server Authentication", OT6_NONE, },
+       { 8214, 4,      "Client Key Selection",         OT6_NUM, },
 
        /* End Extension */
        { 65536, OL6_Z, "End",                          OT6_NONE, },
@@ -162,13 +161,18 @@
 
        if (cp == ep)
                return;
-       printf(" ");
        while (cp < ep) {
+               if (ep - cp < sizeof(u_int16_t))
+                       break;
                code = ntohs(*(u_int16_t *)&cp[0]);
+               if (ep - cp < sizeof(u_int16_t) * 2)
+                       break;
                if (code != 65535)
                        len = ntohs(*(u_int16_t *)&cp[2]);
                else
                        len = 0;
+               if (ep - cp < len + 4)
+                       break;
                p = dhcp6opttab_bycode(code);
                if (p == NULL) {
                        printf("(unknown, len=%d)", len);
@@ -194,11 +198,11 @@
                        break;
                }
                if (cp + 4 + len > ep) {
-                       printf("[|%s]", p->name);
+                       printf(" [|%s]", p->name);
                        return;
                }
 
-               printf("(%s, ", p->name);
+               printf(" (%s, ", p->name);
                switch (p->type) {
                case OT6_V6:
                        for (i = 0; i < len; i += 16) {
@@ -235,11 +239,12 @@
  */
 void
 dhcp6_print(register const u_char *cp, u_int length,
-           u_short sport, u_short dport)
+           u_int16_t sport, u_int16_t dport)
 {
        union dhcp6 *dh6;
        u_char *ep;
        u_char *extp;
+       u_int16_t field16;
 
        printf("dhcp6");
 
@@ -249,31 +254,43 @@
        TCHECK(dh6->dh6_msgtype);
        switch (dh6->dh6_msgtype) {
        case DH6_SOLICIT:
-               if (vflag && TTEST(dh6->dh6_sol.dh6sol_relayaddr)) {
-                       printf(" solicit(");
-                       if ((dh6->dh6_sol.dh6sol_flags & DH6SOL_CLOSE) != 0)
-                               printf("C");
-                       if (dh6->dh6_sol.dh6sol_flags != 0)
-                               printf(" ");
-                       printf("cliaddr=%s",
-                               ip6addr_string(&dh6->dh6_sol.dh6sol_cliaddr));
-                       printf(" relayaddr=%s", 
-                               ip6addr_string(&dh6->dh6_sol.dh6sol_relayaddr));
-                       printf(")");
-               } else
+               if (!(vflag && TTEST(dh6->dh6_sol.dh6sol_relayaddr))) {
                        printf(" solicit");
+                       break;
+               }
+
+               printf(" solicit (");   /*)*/
+               if (dh6->dh6_sol.dh6sol_flags != 0) {
+                       u_int8_t f = dh6->dh6_sol.dh6sol_flags;
+                       printf("%s%s ",
+                          (f & DH6SOL_PREFIX) ? "P" : "",
+                          (f & DH6SOL_CLOSE) ? "C" : "");
+               }
+
+               memcpy(&field16, &dh6->dh6_sol.dh6sol_plen_id,
+                      sizeof(field16));
+               field16 = ntohs(field16);
+               if (field16 & ~DH6SOL_SOLICIT_PLEN_MASK)
+                       printf("plen=%d ", DH6SOL_SOLICIT_PLEN(field16));
+               printf("solicit-ID=%d", DH6SOL_SOLICIT_ID(field16));
+               
+               printf(" cliaddr=%s",
+                       ip6addr_string(&dh6->dh6_sol.dh6sol_cliaddr));
+               printf(" relayaddr=%s", 
+                       ip6addr_string(&dh6->dh6_sol.dh6sol_relayaddr));
+               /*(*/
+               printf(")");
                break;
        case DH6_ADVERT:
                if (!(vflag && TTEST(dh6->dh6_adv.dh6adv_serveraddr))) {
                        printf(" advert");
                        break;
                }
-               printf(" advert(");
-               if ((dh6->dh6_adv.dh6adv_flags & DH6ADV_SERVPRESENT) != 0)
-                       printf("S");
-               if (dh6->dh6_adv.dh6adv_flags != 0)
-                       printf(" ");
-               printf("pref=%u", dh6->dh6_adv.dh6adv_pref);
+               printf(" advert (");    /*)*/
+               memcpy(&field16, &dh6->dh6_adv.dh6adv_rsv_id, sizeof(field16));
+               printf("solicit-ID=%d",
+                      ntohs(field16) & DH6SOL_SOLICIT_ID_MASK); 
+               printf(" pref=%u", dh6->dh6_adv.dh6adv_pref);
                printf(" cliaddr=%s",
                        ip6addr_string(&dh6->dh6_adv.dh6adv_cliaddr));
                printf(" relayaddr=%s", 
@@ -282,6 +299,7 @@
                        ip6addr_string(&dh6->dh6_adv.dh6adv_serveraddr));
                extp = (u_char *)((&dh6->dh6_adv) + 1);
                dhcp6ext_print(extp, ep);
+               /*(*/
                printf(")");
                break;
        case DH6_REQUEST:
@@ -289,26 +307,22 @@



Home | Main Index | Thread Index | Old Index