X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/99c91c3aec40b691641374f58e798bd8d6b657bd..6c8ef0eb86a39c277d1a43802dd8ea01b51cfb2a:/print-mobility.c?ds=inline diff --git a/print-mobility.c b/print-mobility.c index 37410373..feb4c98f 100644 --- a/print-mobility.c +++ b/print-mobility.c @@ -27,18 +27,23 @@ * SUCH DAMAGE. */ +/* \summary: IPv6 mobility printer */ +/* RFC 3775 */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#ifdef INET6 #include -#include "ip6.h" #include "netdissect.h" #include "addrtoname.h" #include "extract.h" +#include "ip6.h" + +static const char tstr[] = "[|MOBILITY]"; + /* Mobility header */ struct ip6_mobility { uint8_t ip6m_pproto; /* following payload protocol (for PG) */ @@ -106,7 +111,7 @@ static const unsigned ip6m_hdrlen[IP6M_MAX + 1] = { #define IP6MOPT_AUTH 0x5 /* Binding Authorization Data */ #define IP6MOPT_AUTH_MINLEN 12 -static void +static int mobility_opt_print(netdissect_options *ndo, const u_char *bp, const unsigned len) { @@ -145,6 +150,7 @@ mobility_opt_print(netdissect_options *ndo, goto trunc; } /* units of 4 secs */ + ND_TCHECK_16BITS(&bp[i+2]); ND_PRINT((ndo, "(refresh: %u)", EXTRACT_16BITS(&bp[i+2]) << 2)); break; @@ -153,6 +159,7 @@ mobility_opt_print(netdissect_options *ndo, ND_PRINT((ndo, "(altcoa: trunc)")); goto trunc; } + ND_TCHECK_128BITS(&bp[i+2]); ND_PRINT((ndo, "(alt-CoA: %s)", ip6addr_string(ndo, &bp[i+2]))); break; case IP6MOPT_NONCEID: @@ -160,6 +167,8 @@ mobility_opt_print(netdissect_options *ndo, ND_PRINT((ndo, "(ni: trunc)")); goto trunc; } + ND_TCHECK_16BITS(&bp[i+2]); + ND_TCHECK_16BITS(&bp[i+4]); ND_PRINT((ndo, "(ni: ho=0x%04x co=0x%04x)", EXTRACT_16BITS(&bp[i+2]), EXTRACT_16BITS(&bp[i+4]))); @@ -180,10 +189,10 @@ mobility_opt_print(netdissect_options *ndo, break; } } - return; + return 0; trunc: - ND_PRINT((ndo, "[trunc] ")); + return 1; } /* @@ -237,8 +246,8 @@ mobility_print(netdissect_options *ndo, case IP6M_HOME_TEST_INIT: case IP6M_CAREOF_TEST_INIT: hlen = IP6M_MINLEN; - if (ndo->ndo_vflag) { - ND_TCHECK2(*mh, hlen + 8); + if (ndo->ndo_vflag) { + ND_TCHECK_32BITS(&bp[hlen + 4]); ND_PRINT((ndo, " %s Init Cookie=%08x:%08x", type == IP6M_HOME_TEST_INIT ? "Home" : "Care-of", EXTRACT_32BITS(&bp[hlen]), @@ -251,16 +260,16 @@ mobility_print(netdissect_options *ndo, ND_TCHECK(mh->ip6m_data16[0]); ND_PRINT((ndo, " nonce id=0x%x", EXTRACT_16BITS(&mh->ip6m_data16[0]))); hlen = IP6M_MINLEN; - if (ndo->ndo_vflag) { - ND_TCHECK2(*mh, hlen + 8); + if (ndo->ndo_vflag) { + ND_TCHECK_32BITS(&bp[hlen + 4]); ND_PRINT((ndo, " %s Init Cookie=%08x:%08x", type == IP6M_HOME_TEST ? "Home" : "Care-of", EXTRACT_32BITS(&bp[hlen]), EXTRACT_32BITS(&bp[hlen + 4]))); } hlen += 8; - if (ndo->ndo_vflag) { - ND_TCHECK2(*mh, hlen + 8); + if (ndo->ndo_vflag) { + ND_TCHECK_32BITS(&bp[hlen + 4]); ND_PRINT((ndo, " %s Keygen Token=%08x:%08x", type == IP6M_HOME_TEST ? "Home" : "Care-of", EXTRACT_32BITS(&bp[hlen]), @@ -272,22 +281,23 @@ mobility_print(netdissect_options *ndo, ND_TCHECK(mh->ip6m_data16[0]); ND_PRINT((ndo, " seq#=%u", EXTRACT_16BITS(&mh->ip6m_data16[0]))); hlen = IP6M_MINLEN; - ND_TCHECK2(*mh, hlen + 1); - if (bp[hlen] & 0xf0) + ND_TCHECK_16BITS(&bp[hlen]); + if (bp[hlen] & 0xf0) { ND_PRINT((ndo, " ")); - if (bp[hlen] & 0x80) - ND_PRINT((ndo, "A")); - if (bp[hlen] & 0x40) - ND_PRINT((ndo, "H")); - if (bp[hlen] & 0x20) - ND_PRINT((ndo, "L")); - if (bp[hlen] & 0x10) - ND_PRINT((ndo, "K")); + if (bp[hlen] & 0x80) + ND_PRINT((ndo, "A")); + if (bp[hlen] & 0x40) + ND_PRINT((ndo, "H")); + if (bp[hlen] & 0x20) + ND_PRINT((ndo, "L")); + if (bp[hlen] & 0x10) + ND_PRINT((ndo, "K")); + } /* Reserved (4bits) */ hlen += 1; /* Reserved (8bits) */ hlen += 1; - ND_TCHECK2(*mh, hlen + 2); + ND_TCHECK_16BITS(&bp[hlen]); /* units of 4 secs */ ND_PRINT((ndo, " lifetime=%u", EXTRACT_16BITS(&bp[hlen]) << 2)); hlen += 2; @@ -295,14 +305,15 @@ mobility_print(netdissect_options *ndo, case IP6M_BINDING_ACK: ND_TCHECK(mh->ip6m_data8[0]); ND_PRINT((ndo, " status=%u", mh->ip6m_data8[0])); + ND_TCHECK(mh->ip6m_data8[1]); if (mh->ip6m_data8[1] & 0x80) ND_PRINT((ndo, " K")); /* Reserved (7bits) */ hlen = IP6M_MINLEN; - ND_TCHECK2(*mh, hlen + 2); + ND_TCHECK_16BITS(&bp[hlen]); ND_PRINT((ndo, " seq#=%u", EXTRACT_16BITS(&bp[hlen]))); hlen += 2; - ND_TCHECK2(*mh, hlen + 2); + ND_TCHECK_16BITS(&bp[hlen]); /* units of 4 secs */ ND_PRINT((ndo, " lifetime=%u", EXTRACT_16BITS(&bp[hlen]) << 2)); hlen += 2; @@ -312,7 +323,7 @@ mobility_print(netdissect_options *ndo, ND_PRINT((ndo, " status=%u", mh->ip6m_data8[0])); /* Reserved */ hlen = IP6M_MINLEN; - ND_TCHECK2(*mh, hlen + 16); + ND_TCHECK2(bp[hlen], 16); ND_PRINT((ndo, " homeaddr %s", ip6addr_string(ndo, &bp[hlen]))); hlen += 16; break; @@ -321,13 +332,13 @@ mobility_print(netdissect_options *ndo, return(mhlen); break; } - if (ndo->ndo_vflag) - mobility_opt_print(ndo, &bp[hlen], mhlen - hlen); + if (ndo->ndo_vflag) + if (mobility_opt_print(ndo, &bp[hlen], mhlen - hlen)) + goto trunc;; return(mhlen); trunc: - ND_PRINT((ndo, "[|MOBILITY]")); - return(mhlen); + ND_PRINT((ndo, "%s", tstr)); + return(-1); } -#endif /* INET6 */