]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-mobility.c
add tracefiles for infinite loop testing
[tcpdump] / print-mobility.c
index 8fec5044ef7842dbe1c3e627122bdfb39a632236..c682b0541193a10abdd623daee37cc27f298e126 100644 (file)
 #endif
 
 #ifndef lint
-static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-mobility.c,v 1.2 2002-07-08 08:58:37 fenner Exp $";
+static const char rcsid[] _U_ =
+     "@(#) $Header: /tcpdump/master/tcpdump/print-mobility.c,v 1.9.2.2 2003-11-16 08:51:33 guy Exp $";
 #endif
 
 #ifdef INET6
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <tcpdump-stdinc.h>
 
-#include <netinet/in.h>
 #include <stdio.h>
 
 #include "ip6.h"
@@ -53,10 +49,11 @@ static const char rcsid[] =
 
 /* Mobility header */
 struct ip6_mobility {
-        u_int8_t ip6m_pproto;   /* following payload protocol (for PG) */
-       u_int8_t ip6m_len;      /* length in units of 8 octets */
-       u_int16_t ip6m_type;    /* message type */
-       u_int16_t ip6m_cksum;   /* sum of IPv6 pseudo-header and MH */
+       u_int8_t ip6m_pproto;   /* following payload protocol (for PG) */
+       u_int8_t ip6m_len;      /* length in units of 8 octets */
+       u_int8_t ip6m_type;     /* message type */
+       u_int8_t reserved;      /* reserved */
+       u_int16_t ip6m_cksum;   /* sum of IPv6 pseudo-header and MH */
        union {
                u_int16_t       ip6m_un_data16[1]; /* type-specific field */
                u_int8_t        ip6m_un_data8[2];  /* type-specific fiedl */
@@ -69,29 +66,29 @@ struct ip6_mobility {
 #define IP6M_MINLEN    8
 
 /* message type */
-#define IP6M_BINDING_REQUEST   0x0000  /* Binding Refresh Request */
-#define IP6M_HOME_TEST_INIT    0x0001  /* Home Test Init */
-#define IP6M_CAREOF_TEST_INIT  0x0002  /* Care-of Test Init */
-#define IP6M_HOME_TEST         0x0003  /* Home Test */
-#define IP6M_CAREOF_TEST       0x0004  /* Care-of Test */
-#define IP6M_BINDING_UPDATE    0x0005  /* Binding Update */
-#define IP6M_BINDING_ACK       0x0006  /* Binding Acknowledgement */
-#define IP6M_BINDING_ERROR     0x0007  /* Binding Error */
+#define IP6M_BINDING_REQUEST   0       /* Binding Refresh Request */
+#define IP6M_HOME_TEST_INIT    1       /* Home Test Init */
+#define IP6M_CAREOF_TEST_INIT  2       /* Care-of Test Init */
+#define IP6M_HOME_TEST         3       /* Home Test */
+#define IP6M_CAREOF_TEST       4       /* Care-of Test */
+#define IP6M_BINDING_UPDATE    5       /* Binding Update */
+#define IP6M_BINDING_ACK       6       /* Binding Acknowledgement */
+#define IP6M_BINDING_ERROR     7       /* Binding Error */
 
 /* Mobility Header Options */
 #define IP6MOPT_MINLEN         2
-#define IP6MOPT_PAD1          0x0
-#define IP6MOPT_PADN          0x1
-#define IP6MOPT_UI            0x2
-#define IP6MOPT_UI_MINLEN       4
-#define IP6MOPT_ALTCOA        0x3
+#define IP6MOPT_PAD1          0x0      /* Pad1 */
+#define IP6MOPT_PADN          0x1      /* PadN */
+#define IP6MOPT_REFRESH              0x2       /* Binding Refresh Advice */
+#define IP6MOPT_REFRESH_MINLEN  4
+#define IP6MOPT_ALTCOA        0x3      /* Alternate Care-of Address */
 #define IP6MOPT_ALTCOA_MINLEN  18
-#define IP6MOPT_NONCEID       0x4
+#define IP6MOPT_NONCEID       0x4      /* Nonce Indices */
 #define IP6MOPT_NONCEID_MINLEN  6
-#define IP6MOPT_AUTH          0x5
-#define IP6MOPT_AUTH_MINLEN     2 /* 2+len */
+#define IP6MOPT_AUTH          0x5      /* Binding Authorization Data */
+#define IP6MOPT_AUTH_MINLEN    12
 
-void
+static void
 mobility_opt_print(const u_char *bp, int len)
 {
        int i;
@@ -102,11 +99,9 @@ mobility_opt_print(const u_char *bp, int len)
                        optlen = 1;
                else {
                        if (i + 1 < len)
-                               optlen = bp[i + 1];
+                               optlen = bp[i + 1] + 2;
                        else
                                goto trunc;
-                       if (optlen < IP6MOPT_MINLEN)
-                               optlen = IP6MOPT_MINLEN;        /* XXX */
                }
                if (i + optlen > len)
                        goto trunc;
@@ -122,12 +117,14 @@ mobility_opt_print(const u_char *bp, int len)
                        }
                        printf("(padn)");
                        break;
-               case IP6MOPT_UI:
-                       if (len - i < IP6MOPT_UI_MINLEN) {
-                               printf("(ui: trunc)");
+               case IP6MOPT_REFRESH:
+                       if (len - i < IP6MOPT_REFRESH_MINLEN) {
+                               printf("(refresh: trunc)");
                                goto trunc;
                        }
-                       printf("(ui: 0x%04x)", EXTRACT_16BITS(&bp[i+2]));
+                       /* units of 4 secs */
+                       printf("(refresh: %d)",
+                               EXTRACT_16BITS(&bp[i+2]) << 2);
                        break;
                case IP6MOPT_ALTCOA:
                        if (len - i < IP6MOPT_ALTCOA_MINLEN) {
@@ -141,7 +138,7 @@ mobility_opt_print(const u_char *bp, int len)
                                printf("(ni: trunc)");
                                goto trunc;
                        }
-                       printf("(ni: ho=0x%04x ci=0x%04x)",
+                       printf("(ni: ho=0x%04x co=0x%04x)",
                                EXTRACT_16BITS(&bp[i+2]),
                                EXTRACT_16BITS(&bp[i+4]));
                        break;
@@ -150,8 +147,7 @@ mobility_opt_print(const u_char *bp, int len)
                                printf("(auth: trunc)");
                                goto trunc;
                        }
-                       printf("(auth spi: 0x%08x)",
-                               EXTRACT_32BITS(&bp[i+2]));
+                       printf("(auth)");
                        break;
                default:
                        if (len - i < IP6MOPT_MINLEN) {
@@ -185,15 +181,28 @@ mobility_print(const u_char *bp, const u_char *bp2)
        /* 'ep' points to the end of available data. */
        ep = snapend;
 
-       TCHECK(mh->ip6m_len);
-       mhlen = (int)(mh->ip6m_len << 3);
-       if (mhlen < IP6M_MINLEN)
-               mhlen = IP6M_MINLEN;    /* XXX */
+       if (!TTEST(mh->ip6m_len)) {
+               /*
+                * There's not enough captured data to include the
+                * mobility header length.
+                *
+                * Our caller expects us to return the length, however,
+                * so return a value that will run to the end of the
+                * captured data.
+                *
+                * XXX - "ip6_print()" doesn't do anything with the
+                * returned length, however, as it breaks out of the
+                * header-processing loop.
+                */
+               mhlen = ep - bp;
+               goto trunc;
+       }
+       mhlen = (int)((mh->ip6m_len + 1) << 3);
 
        /* XXX ip6m_cksum */
 
        TCHECK(mh->ip6m_type);
-       type = ntohs(mh->ip6m_type);
+       type = mh->ip6m_type;
        switch (type) {
        case IP6M_BINDING_REQUEST:
                printf("mobility: BRR");
@@ -204,73 +213,85 @@ mobility_print(const u_char *bp, const u_char *bp2)
                printf("mobility: %soTI",
                        type == IP6M_HOME_TEST_INIT ? "H" : "C");
                hlen = IP6M_MINLEN;
-               TCHECK2(*mh, hlen + 4);
-               printf(" cookie=0x%x", EXTRACT_32BITS(&bp[hlen]));
-               hlen += 4;
+               if (vflag) {
+                       TCHECK2(*mh, hlen + 8);
+                       printf(" %s Init Cookie=%08x:%08x",
+                              type == IP6M_HOME_TEST_INIT ? "Home" : "Care-of",
+                              EXTRACT_32BITS(&bp[hlen]),
+                              EXTRACT_32BITS(&bp[hlen + 4]));
+               }
+               hlen += 8;
                break;
        case IP6M_HOME_TEST:
        case IP6M_CAREOF_TEST:
                printf("mobility: %soT",
                        type == IP6M_HOME_TEST ? "H" : "C");
+               TCHECK(mh->ip6m_data16[0]);
+               printf(" nonce id=0x%x", EXTRACT_16BITS(&mh->ip6m_data16[0]));
                hlen = IP6M_MINLEN;
-               TCHECK2(*mh, hlen + 2);
-               printf(" nonce id=0x%x", EXTRACT_16BITS(&bp[hlen]));
-               hlen += 2;
-               /* Reserved (16bits) */
-               hlen += 2;
-               TCHECK2(*mh, hlen + 4);
-               printf(" mobile cookie=0x%x", EXTRACT_32BITS(&bp[hlen]));
-               hlen += 4;
-               /* Home(Care-of) Cookie (128 bits) */
-               hlen += 16;
+               if (vflag) {
+                       TCHECK2(*mh, hlen + 8);
+                       printf(" %s Init Cookie=%08x:%08x",
+                              type == IP6M_HOME_TEST ? "Home" : "Care-of",
+                              EXTRACT_32BITS(&bp[hlen]),
+                              EXTRACT_32BITS(&bp[hlen + 4]));
+               }
+               hlen += 8;
+               if (vflag) {
+                       TCHECK2(*mh, hlen + 8);
+                       printf(" %s Keygen Token=%08x:%08x",
+                              type == IP6M_HOME_TEST ? "Home" : "Care-of",
+                              EXTRACT_32BITS(&bp[hlen]),
+                              EXTRACT_32BITS(&bp[hlen + 4]));
+               }
+               hlen += 8;
                break;
        case IP6M_BINDING_UPDATE:
                printf("mobility: BU");
-               TCHECK(mh->ip6m_data8[0]);
-               if (mh->ip6m_data8[0] & 0xf0)
+               TCHECK(mh->ip6m_data16[0]);
+               printf(" seq#=%d", EXTRACT_16BITS(&mh->ip6m_data16[0]));
+               hlen = IP6M_MINLEN;
+               TCHECK2(*mh, hlen + 1);
+               if (bp[hlen] & 0xf0)
                        printf(" ");
-               if (mh->ip6m_data8[0] & 0x80)
+               if (bp[hlen] & 0x80)
                        printf("A");
-               if (mh->ip6m_data8[0] & 0x40)
+               if (bp[hlen] & 0x40)
                        printf("H");
-               if (mh->ip6m_data8[0] & 0x20)
-                       printf("S");
-               if (mh->ip6m_data8[0] & 0x10)
-                       printf("D");
-               hlen = IP6M_MINLEN;
+               if (bp[hlen] & 0x20)
+                       printf("L");
+               if (bp[hlen] & 0x10)
+                       printf("K");
+               /* Reserved (4bits) */
+               hlen += 1;
+               /* Reserved (8bits) */
+               hlen += 1;
                TCHECK2(*mh, hlen + 2);
-               printf(" seq#=%d", EXTRACT_16BITS(&bp[hlen]));
-               hlen += 2;
-               /* Reserved (16bits) */
+               /* units of 4 secs */
+               printf(" lifetime=%d", EXTRACT_16BITS(&bp[hlen]) << 2);
                hlen += 2;
-               TCHECK2(*mh, hlen + 4);
-               printf(" lifetime=%d", EXTRACT_32BITS(&bp[hlen]));
-               hlen += 4;
-               TCHECK2(*mh, hlen + 16);
-               printf(" homeaddr %s", ip6addr_string(&bp[hlen]));
-               hlen += 16;
                break;
        case IP6M_BINDING_ACK:
                printf("mobility: BA");
                TCHECK(mh->ip6m_data8[0]);
                printf(" status=%d", mh->ip6m_data8[0]);
+               if (mh->ip6m_data8[1] & 0x80)
+                       printf(" K");
+               /* Reserved (7bits) */
                hlen = IP6M_MINLEN;
                TCHECK2(*mh, hlen + 2);
                printf(" seq#=%d", EXTRACT_16BITS(&bp[hlen]));
                hlen += 2;
-               /* Reserved (16bits) */
+               TCHECK2(*mh, hlen + 2);
+               /* units of 4 secs */
+               printf(" lifetime=%d", EXTRACT_16BITS(&bp[hlen]) << 2);
                hlen += 2;
-               TCHECK2(*mh, hlen + 4);
-               printf(" lifetime=%d", EXTRACT_32BITS(&bp[hlen]));
-               hlen += 4;
-               TCHECK2(*mh, hlen + 4);
-               printf(" refresh=%d", ntohl(*(u_int32_t *)&bp[hlen]));
-               hlen += 4;
                break;
        case IP6M_BINDING_ERROR:
                printf("mobility: BE");
                TCHECK(mh->ip6m_data8[0]);
                printf(" status=%d", mh->ip6m_data8[0]);
+               /* Reserved */
                hlen = IP6M_MINLEN;
                TCHECK2(*mh, hlen + 16);
                printf(" homeaddr %s", ip6addr_string(&bp[hlen]));