]> The Tcpdump Group git mirrors - tcpdump/commitdiff
add mobile-ip6 option handling. [email protected] #113
authoritojun <itojun>
Wed, 13 Dec 2000 07:57:04 +0000 (07:57 +0000)
committeritojun <itojun>
Wed, 13 Dec 2000 07:57:04 +0000 (07:57 +0000)
from Timo Koskiahde.

icmp6.h
ip6.h
print-icmp6.c
print-ip6opts.c
print-rt6.c

diff --git a/icmp6.h b/icmp6.h
index 87bf7d994ad1bc58bfa4ddb0806d1dfbbe4fb2b9..dd1d3aba8f4e532de89e6e95ca8e268706332807 100644 (file)
--- a/icmp6.h
+++ b/icmp6.h
@@ -248,6 +248,7 @@ struct nd_opt_hdr {         /* Neighbor discovery option header */
 #define ND_OPT_PREFIX_INFORMATION      3
 #define ND_OPT_REDIRECTED_HEADER       4
 #define ND_OPT_MTU                     5
 #define ND_OPT_PREFIX_INFORMATION      3
 #define ND_OPT_REDIRECTED_HEADER       4
 #define ND_OPT_MTU                     5
+#define ND_OPT_ADVINT                  7
 
 struct nd_opt_prefix_info {    /* prefix information */
        u_int8_t        nd_opt_pi_type;
 
 struct nd_opt_prefix_info {    /* prefix information */
        u_int8_t        nd_opt_pi_type;
@@ -262,6 +263,7 @@ struct nd_opt_prefix_info { /* prefix information */
 
 #define ND_OPT_PI_FLAG_ONLINK          0x80
 #define ND_OPT_PI_FLAG_AUTO            0x40
 
 #define ND_OPT_PI_FLAG_ONLINK          0x80
 #define ND_OPT_PI_FLAG_AUTO            0x40
+#define ND_OPT_PI_FLAG_ROUTER          0x20    /*2292bis*/
 
 struct nd_opt_rd_hdr {         /* redirected header */
        u_int8_t        nd_opt_rh_type;
 
 struct nd_opt_rd_hdr {         /* redirected header */
        u_int8_t        nd_opt_rh_type;
@@ -278,6 +280,13 @@ struct nd_opt_mtu {                /* MTU option */
        u_int32_t       nd_opt_mtu_mtu;
 };
 
        u_int32_t       nd_opt_mtu_mtu;
 };
 
+struct nd_opt_advint {         /* Advertisement interval option */
+       u_int8_t        nd_opt_advint_type;
+       u_int8_t        nd_opt_advint_len;
+       u_int16_t       nd_opt_advint_reserved;
+       u_int32_t       nd_opt_advint_advint;
+};
+
 /*
  * icmp6 namelookup
  */
 /*
  * icmp6 namelookup
  */
diff --git a/ip6.h b/ip6.h
index b00b41551ec528513525ec91d202ce56c907f8bc..61cb609ff11918b49c18fb8cf9f52b90a800f8b8 100644 (file)
--- a/ip6.h
+++ b/ip6.h
@@ -136,13 +136,20 @@ struct ip6_dest {
 #define IP6OPT_PADN            0x01    /* 00 0 00001 */
 #define IP6OPT_JUMBO           0xC2    /* 11 0 00010 = 194 */
 #define IP6OPT_JUMBO_LEN       6
 #define IP6OPT_PADN            0x01    /* 00 0 00001 */
 #define IP6OPT_JUMBO           0xC2    /* 11 0 00010 = 194 */
 #define IP6OPT_JUMBO_LEN       6
-#define IP6OPT_RTALERT         0x05    /* 00 0 00101 */
+#define IP6OPT_ROUTER_ALERT    0x05    /* 00 0 00101 */
+
 #define IP6OPT_RTALERT_LEN     4
 #define IP6OPT_RTALERT_MLD     0       /* Datagram contains an MLD message */
 #define IP6OPT_RTALERT_RSVP    1       /* Datagram contains an RSVP message */
 #define IP6OPT_RTALERT_ACTNET  2       /* contains an Active Networks msg */
 #define IP6OPT_MINLEN          2
 
 #define IP6OPT_RTALERT_LEN     4
 #define IP6OPT_RTALERT_MLD     0       /* Datagram contains an MLD message */
 #define IP6OPT_RTALERT_RSVP    1       /* Datagram contains an RSVP message */
 #define IP6OPT_RTALERT_ACTNET  2       /* contains an Active Networks msg */
 #define IP6OPT_MINLEN          2
 
+#define IP6OPT_BINDING_UPDATE  0xc6    /* 11 0 00110 */
+#define IP6OPT_BINDING_ACK     0x07    /* 00 0 00111 */
+#define IP6OPT_BINDING_REQ     0x08    /* 00 0 01000 */
+#define IP6OPT_HOME_ADDRESS    0xc9    /* 11 0 01001 */
+#define IP6OPT_EID             0x8a    /* 10 0 01010 */
+
 #define IP6OPT_TYPE(o)         ((o) & 0xC0)
 #define IP6OPT_TYPE_SKIP       0x00
 #define IP6OPT_TYPE_DISCARD    0x40
 #define IP6OPT_TYPE(o)         ((o) & 0xC0)
 #define IP6OPT_TYPE_SKIP       0x00
 #define IP6OPT_TYPE_DISCARD    0x40
@@ -168,7 +175,7 @@ struct ip6_rthdr0 {
        u_int8_t  ip6r0_segleft;        /* segments left */
        u_int8_t  ip6r0_reserved;       /* reserved field */
        u_int8_t  ip6r0_slmap[3];       /* strict/loose bit map */
        u_int8_t  ip6r0_segleft;        /* segments left */
        u_int8_t  ip6r0_reserved;       /* reserved field */
        u_int8_t  ip6r0_slmap[3];       /* strict/loose bit map */
-       struct in6_addr  ip6r0_addr[1]; /* up to 23 addresses */
+       struct in6_addr ip6r0_addr[1];  /* up to 23 addresses */
 };
 
 /* Fragment header */
 };
 
 /* Fragment header */
index 2283a161ea7814da3d8563fe10204459a0977283..b3d8ef97e718aab5f192d8fcbaacd0dc47f48a0b 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.41 2000-11-12 15:16:16 itojun Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.42 2000-12-13 07:57:05 itojun Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -411,6 +411,7 @@ icmp6_opt_print(register const u_char *bp, int resid)
        register const struct nd_opt_prefix_info *opp;
        register const struct icmp6_opts_redirect *opr;
        register const struct nd_opt_mtu *opm;
        register const struct nd_opt_prefix_info *opp;
        register const struct icmp6_opts_redirect *opr;
        register const struct nd_opt_mtu *opm;
+       register const struct nd_opt_advint *opa;
        register const u_char *ep;
        int     opts_len;
 #if 0
        register const u_char *ep;
        int     opts_len;
 #if 0
@@ -476,9 +477,11 @@ icmp6_opt_print(register const u_char *bp, int resid)
                TCHECK(opp->nd_opt_pi_prefix);
                printf("(prefix info: ");       /*)*/
                if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
                TCHECK(opp->nd_opt_pi_prefix);
                printf("(prefix info: ");       /*)*/
                if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
-                      printf("L");
+                       printf("L");
                if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO)
                if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO)
-                      printf("A");
+                       printf("A");
+               if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ROUTER)
+                       printf("R");
                if (opp->nd_opt_pi_flags_reserved)
                        printf(" ");
                printf("valid_ltime=");
                if (opp->nd_opt_pi_flags_reserved)
                        printf(" ");
                printf("valid_ltime=");
@@ -522,6 +525,17 @@ icmp6_opt_print(register const u_char *bp, int resid)
                icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
                                resid - (op->nd_opt_len << 3));
                break;
                icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
                                resid - (op->nd_opt_len << 3));
                break;
+        case ND_OPT_ADVINT:
+               opa = (struct nd_opt_advint *)op;
+               TCHECK(opa->nd_opt_advint_advint);
+               printf("(advint: ");    /*)*/
+               printf("advint=%u",
+                   (u_int32_t)ntohl(opa->nd_opt_advint_advint));
+               /*(*/
+               printf(")");
+               icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3),
+                               resid - (op->nd_opt_len << 3));
+               break;                
        default:
                opts_len = op->nd_opt_len;
                printf("(unknwon opt_type=%d, opt_len=%d)",
        default:
                opts_len = op->nd_opt_len;
                printf("(unknwon opt_type=%d, opt_len=%d)",
index 7fab41c3b86440dc764a383a08936d0f8c0469e3..163b70f4ff46c14eb953c69f75888f2e4c590eb9 100644 (file)
@@ -33,7 +33,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.7 2000-10-07 05:53:11 itojun Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.8 2000-12-13 07:57:05 itojun Exp $";
 #endif
 
 #ifdef INET6
 #endif
 
 #ifdef INET6
@@ -50,6 +50,79 @@ static const char rcsid[] =
 #include "interface.h"
 #include "addrtoname.h"
 
 #include "interface.h"
 #include "addrtoname.h"
 
+/* items outside of rfc2292bis */
+#ifndef IP6OPT_MINLEN
+#define IP6OPT_MINLEN  2
+#endif
+#ifndef IP6OPT_RTALERT_LEN
+#define IP6OPT_RTALERT_LEN     4
+#endif
+#ifndef IP6OPT_JUMBO_LEN
+#define IP6OPT_JUMBO_LEN       6
+#endif
+#define IP6OPT_HOMEADDR_MINLEN 18
+#define IP6OPT_BU_MINLEN       10
+#define IP6OPT_BA_MINLEN       13
+#define IP6OPT_BR_MINLEN        2
+#define IP6SOPT_ALTCOA        0x4
+#define IP6SOPT_ALTCOA_MINLEN  18
+#define IP6SOPT_UI            0x2
+#define IP6SOPT_UI_MINLEN       4
+
+static void ip6_sopt_print(const u_char *, int);
+
+static void
+ip6_sopt_print(const u_char *bp, int len)
+{
+    int i;
+    int optlen;
+
+    for (i = 0; i < len; i += optlen) {
+       switch (bp[i]) {
+       case IP6OPT_PAD1:
+            printf(", pad1");
+           optlen = 1;
+           break;
+       case IP6OPT_PADN:
+           if (len - i < IP6OPT_MINLEN) {
+               printf(", padn: trunc");
+               goto trunc;
+           }
+            printf(", padn");
+           optlen = bp[i + 1] + 2;
+           break;
+        case IP6SOPT_ALTCOA:
+             if (len - i < IP6SOPT_ALTCOA_MINLEN) {
+               printf(", altcoa: trunc");
+               goto trunc;
+           }
+            printf(", alt-CoA: %s", ip6addr_string(&bp[i+2]));
+           optlen = bp[i + 1] + 2;
+           break;
+        case IP6SOPT_UI:
+             if (len - i < IP6SOPT_UI_MINLEN) {
+               printf(", ui: trunc");
+               goto trunc;
+           }
+            printf("(ui: 0x%04x) ", ntohs(*(u_int16_t *)&bp[i + 2]));
+           optlen = bp[i + 1] + 2;
+           break;
+       default:
+           if (len - i < IP6OPT_MINLEN) {
+               printf(", sopt_type %d: trunc)", bp[i]);
+               goto trunc;
+           }
+           printf(", sopt_type 0x%02x: len=%d", bp[i], bp[i + 1]);
+           optlen = bp[i + 1] + 2;
+           break;
+       }
+    }
+    return;
+
+trunc:
+    printf("[trunc] ");
+}
+
 void
 ip6_opt_print(const u_char *bp, int len)
 {
 void
 ip6_opt_print(const u_char *bp, int len)
 {
@@ -58,32 +131,19 @@ ip6_opt_print(const u_char *bp, int len)
 
     for (i = 0; i < len; i += optlen) {
        switch (bp[i]) {
 
     for (i = 0; i < len; i += optlen) {
        switch (bp[i]) {
-#ifndef IP6OPT_PAD1
-#define IP6OPT_PAD1    0x00
-#endif
        case IP6OPT_PAD1:
        case IP6OPT_PAD1:
+            printf("(pad1)");
            optlen = 1;
            break;
            optlen = 1;
            break;
-#ifndef IP6OPT_PADN
-#define IP6OPT_PADN    0x01
-#endif
        case IP6OPT_PADN:
        case IP6OPT_PADN:
-#ifndef IP6OPT_MINLEN
-#define IP6OPT_MINLEN  2
-#endif
            if (len - i < IP6OPT_MINLEN) {
                printf("(padn: trunc)");
                goto trunc;
            }
            if (len - i < IP6OPT_MINLEN) {
                printf("(padn: trunc)");
                goto trunc;
            }
+            printf("(padn)");
            optlen = bp[i + 1] + 2;
            break;
            optlen = bp[i + 1] + 2;
            break;
-#ifndef IP6OPT_RTALERT
-#define IP6OPT_RTALERT 0x05
-#endif
-       case IP6OPT_RTALERT:
-#ifndef IP6OPT_RTALERT_LEN
-#define IP6OPT_RTALERT_LEN     4
-#endif
+       case IP6OPT_ROUTER_ALERT:
            if (len - i < IP6OPT_RTALERT_LEN) {
                printf("(rtalert: trunc)");
                goto trunc;
            if (len - i < IP6OPT_RTALERT_LEN) {
                printf("(rtalert: trunc)");
                goto trunc;
@@ -95,13 +155,7 @@ ip6_opt_print(const u_char *bp, int len)
            printf("(rtalert: 0x%04x) ", ntohs(*(u_int16_t *)&bp[i + 2]));
            optlen = IP6OPT_RTALERT_LEN;
            break;
            printf("(rtalert: 0x%04x) ", ntohs(*(u_int16_t *)&bp[i + 2]));
            optlen = IP6OPT_RTALERT_LEN;
            break;
-#ifndef IP6OPT_JUMBO
-#define IP6OPT_JUMBO   0xC2
-#endif
        case IP6OPT_JUMBO:
        case IP6OPT_JUMBO:
-#ifndef IP6OPT_JUMBO_LEN
-#define IP6OPT_JUMBO_LEN       6
-#endif
            if (len - i < IP6OPT_JUMBO_LEN) {
                printf("(jumbo: trunc)");
                goto trunc;
            if (len - i < IP6OPT_JUMBO_LEN) {
                printf("(jumbo: trunc)");
                goto trunc;
@@ -113,12 +167,100 @@ ip6_opt_print(const u_char *bp, int len)
            printf("(jumbo: %u) ", (u_int32_t)ntohl(*(u_int32_t *)&bp[i + 2]));
            optlen = IP6OPT_JUMBO_LEN;
            break;
            printf("(jumbo: %u) ", (u_int32_t)ntohl(*(u_int32_t *)&bp[i + 2]));
            optlen = IP6OPT_JUMBO_LEN;
            break;
+        case IP6OPT_HOME_ADDRESS:
+           if (len - i < IP6OPT_HOMEADDR_MINLEN) {
+               printf("(homeaddr: trunc)");
+               goto trunc;
+           }
+           if (bp[i + 1] < IP6OPT_HOMEADDR_MINLEN - 2) {
+               printf("(homeaddr: invalid len %d)", bp[i + 1]);
+               goto trunc;
+           }
+           printf("(homeaddr: %s", ip6addr_string(&bp[i + 2]));
+            if (bp[i + 1] > IP6OPT_HOMEADDR_MINLEN - 2) {
+               ip6_sopt_print(&bp[i + IP6OPT_HOMEADDR_MINLEN],
+                   (optlen-IP6OPT_HOMEADDR_MINLEN));
+           }
+            printf(")");
+           optlen = bp[i + 1] + 2;
+           break;
+        case IP6OPT_BINDING_UPDATE:
+           if (len - i < IP6OPT_BU_MINLEN) {
+               printf("(bu: trunc)");
+               goto trunc;
+           }
+           if (bp[i + 1] < IP6OPT_BU_MINLEN - 2) {
+               printf("(bu: invalid len %d)", bp[i + 1]);
+               goto trunc;
+           }
+           printf("(bu: ");
+           if (bp[i + 2] & 0x80)
+                   printf("A");
+           if (bp[i + 2] & 0x40)
+                   printf("H");
+           if (bp[i + 2] & 0x20)
+                   printf("R");
+           if (bp[i + 2] & 0x10)
+                   printf("D");
+           if (bp[i + 2] & 0x0f)
+                   printf("res");
+           printf(", prefixlen: %u", bp[i + 3]);
+           printf(", sequence: %u",
+               (u_int16_t)ntohs(*(u_int16_t *)&bp[i + 4]));
+           printf(", lifetime: %u",
+               (u_int32_t)ntohs(*(u_int32_t *)&bp[i + 8]));
+
+           optlen = bp[i + 1] + 2;
+           if (bp[i + 1] > IP6OPT_BU_MINLEN - 2) {
+               ip6_sopt_print(&bp[i + IP6OPT_BU_MINLEN],
+                   (optlen - IP6OPT_BU_MINLEN));
+           }
+           printf(")");
+           break;
+       case IP6OPT_BINDING_ACK:
+           if (len - i < IP6OPT_BA_MINLEN) {
+               printf("(ba: trunc)");
+               goto trunc;
+           }
+           if (bp[i + 1] < IP6OPT_BA_MINLEN - 2) {
+               printf("(ba: invalid len %d)", bp[i + 1]);
+               goto trunc;
+           }
+           printf("(ba: ");
+           printf("status: %u", bp[i + 2]);
+           printf(", sequence: %u",
+               (u_int16_t)ntohs(*(u_int16_t *)&bp[i + 3]));
+           printf(", lifetime: %u",
+               (u_int32_t)ntohs(*(u_int32_t *)&bp[i + 7]));
+           printf(", refresh: %u",
+               (u_int32_t)ntohs(*(u_int32_t *)&bp[i + 11]));
+
+           if (bp[i + 1] > IP6OPT_BA_MINLEN - 2) {
+               ip6_sopt_print(&bp[i + IP6OPT_BA_MINLEN],
+                   (optlen-IP6OPT_BA_MINLEN));
+           }
+            printf(")");
+           optlen = bp[i + 1] + 2;
+           break;
+        case IP6OPT_BINDING_REQ:
+           if (len - i < IP6OPT_BR_MINLEN) {
+               printf("(br: trunc)");
+               goto trunc;
+           }
+            printf("(br");
+            if (bp[i + 1] > IP6OPT_BR_MINLEN - 2) {
+               ip6_sopt_print(&bp[i + IP6OPT_BR_MINLEN],
+                   (optlen-IP6OPT_BR_MINLEN));
+           }
+            printf(")");
+           optlen = bp[i + 1] + 2;
+           break;
        default:
            if (len - i < IP6OPT_MINLEN) {
                printf("(type %d: trunc)", bp[i]);
                goto trunc;
            }
        default:
            if (len - i < IP6OPT_MINLEN) {
                printf("(type %d: trunc)", bp[i]);
                goto trunc;
            }
-           printf("(type 0x%02x: len=%d) ", bp[i], bp[i + 1]);
+           printf("(opt_type 0x%02x: len=%d) ", bp[i], bp[i + 1]);
            optlen = bp[i + 1] + 2;
            break;
        }
            optlen = bp[i + 1] + 2;
            break;
        }
@@ -144,7 +286,7 @@ hbhopt_print(register const u_char *bp)
     ep = snapend;
     TCHECK(dp->ip6h_len);
     hbhlen = (int)((dp->ip6h_len + 1) << 3);
     ep = snapend;
     TCHECK(dp->ip6h_len);
     hbhlen = (int)((dp->ip6h_len + 1) << 3);
-    TCHECK2(dp, hbhlen);
+    TCHECK2(*dp, hbhlen);
     printf("HBH ");
     if (vflag)
        ip6_opt_print((const u_char *)dp + sizeof(*dp), hbhlen - sizeof(*dp));
     printf("HBH ");
     if (vflag)
        ip6_opt_print((const u_char *)dp + sizeof(*dp), hbhlen - sizeof(*dp));
@@ -167,7 +309,7 @@ dstopt_print(register const u_char *bp)
     ep = snapend;
     TCHECK(dp->ip6d_len);
     dstoptlen = (int)((dp->ip6d_len + 1) << 3);
     ep = snapend;
     TCHECK(dp->ip6d_len);
     dstoptlen = (int)((dp->ip6d_len + 1) << 3);
-    TCHECK2(dp, dstoptlen);
+    TCHECK2(*dp, dstoptlen);
     printf("DSTOPT ");
     if (vflag) {
        ip6_opt_print((const u_char *)dp + sizeof(*dp),
     printf("DSTOPT ");
     if (vflag) {
        ip6_opt_print((const u_char *)dp + sizeof(*dp),
index 122531374f5ef01c23eb288682438d2ecff1fca6..0bf78b81b60c36bad9e2b69bc82b69b80fec45af 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-rt6.c,v 1.16 2000-10-07 05:53:13 itojun Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-rt6.c,v 1.17 2000-12-13 07:57:05 itojun Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -53,6 +53,7 @@ rt6_print(register const u_char *bp, register const u_char *bp2)
        register const struct ip6_hdr *ip;
        register const u_char *ep;
        int i, len;
        register const struct ip6_hdr *ip;
        register const u_char *ep;
        int i, len;
+       register const struct in6_addr *addr;
 
        dp = (struct ip6_rthdr *)bp;
        ip = (struct ip6_hdr *)bp2;
 
        dp = (struct ip6_rthdr *)bp;
        ip = (struct ip6_hdr *)bp2;
@@ -89,14 +90,13 @@ rt6_print(register const u_char *bp, register const u_char *bp2)
                if (len % 2 == 1)
                        goto trunc;
                len >>= 1;
                if (len % 2 == 1)
                        goto trunc;
                len >>= 1;
+               addr = &dp0->ip6r0_addr[0];
                for (i = 0; i < len; i++) {
                for (i = 0; i < len; i++) {
-                       struct in6_addr *addr;
-
-                       addr = ((struct in6_addr *)(dp0 + 1)) + i;
-                       if ((u_char *)addr > ep - sizeof(*addr))
+                       if ((u_char *)(addr + 1) > ep)
                                goto trunc;
                                goto trunc;
-
-                       printf(", [%d]%s", i, ip6addr_string((u_char *)addr));
+               
+                       printf(", [%d]%s", i, ip6addr_string(addr));
+                       addr++;
                }
                /*(*/
                printf(") ");
                }
                /*(*/
                printf(") ");