X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/a580d11dca20afc35c17a6243baaad850738ea43..5287bffd3f4fa1fda9d7734b45f8cf02391d3855:/print-dhcp6.c diff --git a/print-dhcp6.c b/print-dhcp6.c index 20fd763d..cc2787a9 100644 --- a/print-dhcp6.c +++ b/print-dhcp6.c @@ -26,6 +26,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + +/* \summary: IPv6 DHCP printer */ + /* * RFC3315: DHCPv6 * supported DHCPv6 options: @@ -40,17 +43,16 @@ * RFC6334: Dual-Stack Lite option, */ -#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include #include -#include "interface.h" +#include "netdissect.h" #include "addrtoname.h" #include "extract.h" @@ -103,8 +105,8 @@ static const struct tok dh6_msgtype_str[] = { /* DHCP6 base packet format */ struct dhcp6 { union { - u_int8_t m; - u_int32_t x; + nd_uint8_t m; + nd_uint32_t x; } dh6_msgtypexid; /* options follow */ }; @@ -114,10 +116,10 @@ struct dhcp6 { /* DHCPv6 relay messages */ struct dhcp6_relay { - u_int8_t dh6relay_msgtype; - u_int8_t dh6relay_hcnt; - u_int8_t dh6relay_linkaddr[16]; /* XXX: badly aligned */ - u_int8_t dh6relay_peeraddr[16]; + nd_uint8_t dh6relay_msgtype; + nd_uint8_t dh6relay_hcnt; + nd_uint8_t dh6relay_linkaddr[16]; /* XXX: badly aligned */ + nd_uint8_t dh6relay_peeraddr[16]; /* options follow */ }; @@ -192,6 +194,7 @@ struct dhcp6_relay { # define DH6OPT_NTP_SUBOPTION_MC_ADDR 2 # define DH6OPT_NTP_SUBOPTION_SRV_FQDN 3 #define DH6OPT_AFTR_NAME 64 +#define DH6OPT_MUDURL 112 static const struct tok dh6opt_str[] = { { DH6OPT_CLIENTID, "client-ID" }, @@ -242,27 +245,28 @@ static const struct tok dh6opt_str[] = { { DH6OPT_LQ_CLIENT_LINK, "LQ-client-link" }, { DH6OPT_NTP_SERVER, "NTP-server" }, { DH6OPT_AFTR_NAME, "AFTR-Name" }, + { DH6OPT_MUDURL, "MUD-URL" }, { 0, NULL } }; static const struct tok dh6opt_stcode_str[] = { - { DH6OPT_STCODE_SUCCESS, "success" }, - { DH6OPT_STCODE_UNSPECFAIL, "unspec failure" }, - { DH6OPT_STCODE_NOADDRAVAIL, "no addresses" }, - { DH6OPT_STCODE_NOBINDING, "no binding" }, - { DH6OPT_STCODE_NOTONLINK, "not on-link" }, - { DH6OPT_STCODE_USEMULTICAST, "use multicast" }, - { DH6OPT_STCODE_NOPREFIXAVAIL, "no prefixes" }, - { DH6OPT_STCODE_UNKNOWNQUERYTYPE, "unknown query type" }, - { DH6OPT_STCODE_MALFORMEDQUERY, "malformed query" }, - { DH6OPT_STCODE_NOTCONFIGURED, "not configured" }, - { DH6OPT_STCODE_NOTALLOWED, "not allowed" }, + { DH6OPT_STCODE_SUCCESS, "Success" }, /* RFC3315 */ + { DH6OPT_STCODE_UNSPECFAIL, "UnspecFail" }, /* RFC3315 */ + { DH6OPT_STCODE_NOADDRAVAIL, "NoAddrsAvail" }, /* RFC3315 */ + { DH6OPT_STCODE_NOBINDING, "NoBinding" }, /* RFC3315 */ + { DH6OPT_STCODE_NOTONLINK, "NotOnLink" }, /* RFC3315 */ + { DH6OPT_STCODE_USEMULTICAST, "UseMulticast" }, /* RFC3315 */ + { DH6OPT_STCODE_NOPREFIXAVAIL, "NoPrefixAvail" }, /* RFC3633 */ + { DH6OPT_STCODE_UNKNOWNQUERYTYPE, "UnknownQueryType" }, /* RFC5007 */ + { DH6OPT_STCODE_MALFORMEDQUERY, "MalformedQuery" }, /* RFC5007 */ + { DH6OPT_STCODE_NOTCONFIGURED, "NotConfigured" }, /* RFC5007 */ + { DH6OPT_STCODE_NOTALLOWED, "NotAllowed" }, /* RFC5007 */ { 0, NULL } }; struct dhcp6opt { - u_int16_t dh6opt_type; - u_int16_t dh6opt_len; + nd_uint16_t dh6opt_type; + nd_uint16_t dh6opt_len; /* type-dependent data follows */ }; @@ -279,27 +283,28 @@ dhcp6opt_print(netdissect_options *ndo, const struct dhcp6opt *dh6o; const u_char *tp; size_t i; - u_int16_t opttype; + uint16_t opttype; size_t optlen; - u_int8_t auth_proto; + uint8_t auth_proto; u_int authinfolen, authrealmlen; int remain_len; /* Length of remaining options */ int label_len; /* Label length */ - u_int16_t subopt_code; - u_int16_t subopt_len; + uint16_t subopt_code; + uint16_t subopt_len; if (cp == ep) return; while (cp < ep) { if (ep < cp + sizeof(*dh6o)) goto trunc; - dh6o = (struct dhcp6opt *)cp; + dh6o = (const struct dhcp6opt *)cp; ND_TCHECK(*dh6o); - optlen = EXTRACT_16BITS(&dh6o->dh6opt_len); + optlen = EXTRACT_BE_16BITS(&dh6o->dh6opt_len); if (ep < cp + sizeof(*dh6o) + optlen) goto trunc; - opttype = EXTRACT_16BITS(&dh6o->dh6opt_type); + opttype = EXTRACT_BE_16BITS(&dh6o->dh6opt_type); ND_PRINT((ndo, " (%s", tok2str(dh6opt_str, "opt_%u", opttype))); + ND_TCHECK2(*(cp + sizeof(*dh6o)), optlen); switch (opttype) { case DH6OPT_CLIENTID: case DH6OPT_SERVERID: @@ -308,13 +313,13 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); - switch (EXTRACT_16BITS(tp)) { + tp = (const u_char *)(dh6o + 1); + switch (EXTRACT_BE_16BITS(tp)) { case 1: if (optlen >= 2 + 6) { ND_PRINT((ndo, " hwaddr/time type %u time %u ", - EXTRACT_16BITS(&tp[2]), - EXTRACT_32BITS(&tp[4]))); + EXTRACT_BE_16BITS(&tp[2]), + EXTRACT_BE_32BITS(&tp[4]))); for (i = 8; i < optlen; i++) ND_PRINT((ndo, "%02x", tp[i])); /*(*/ @@ -339,7 +344,7 @@ dhcp6opt_print(netdissect_options *ndo, case 3: if (optlen >= 2 + 2) { ND_PRINT((ndo, " hwaddr type %u ", - EXTRACT_16BITS(&tp[2]))); + EXTRACT_BE_16BITS(&tp[2]))); for (i = 4; i < optlen; i++) ND_PRINT((ndo, "%02x", tp[i])); /*(*/ @@ -350,7 +355,7 @@ dhcp6opt_print(netdissect_options *ndo, } break; default: - ND_PRINT((ndo, " type %d)", EXTRACT_16BITS(tp))); + ND_PRINT((ndo, " type %d)", EXTRACT_BE_16BITS(tp))); break; } break; @@ -360,11 +365,11 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[0]))); ND_PRINT((ndo, " pltime:%u vltime:%u", - EXTRACT_32BITS(&tp[16]), - EXTRACT_32BITS(&tp[20]))); + EXTRACT_BE_32BITS(&tp[16]), + EXTRACT_BE_32BITS(&tp[20]))); if (optlen > 24) { /* there are sub-options */ dhcp6opt_print(ndo, tp + 24, tp + optlen); @@ -377,10 +382,10 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); for (i = 0; i < optlen; i += 2) { ND_PRINT((ndo, " %s", - tok2str(dh6opt_str, "opt_%u", EXTRACT_16BITS(&tp[i])))); + tok2str(dh6opt_str, "opt_%u", EXTRACT_BE_16BITS(&tp[i])))); } ND_PRINT((ndo, ")")); break; @@ -389,7 +394,7 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); ND_PRINT((ndo, " %d)", *tp)); break; case DH6OPT_ELAPSED_TIME: @@ -397,12 +402,12 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); - ND_PRINT((ndo, " %d)", EXTRACT_16BITS(tp))); + tp = (const u_char *)(dh6o + 1); + ND_PRINT((ndo, " %d)", EXTRACT_BE_16BITS(tp))); break; case DH6OPT_RELAY_MSG: ND_PRINT((ndo, " (")); - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); dhcp6_print(ndo, tp, optlen); ND_PRINT((ndo, ")")); break; @@ -411,7 +416,7 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); auth_proto = *tp; switch (auth_proto) { case DH6OPT_AUTHPROTO_DELAYED: @@ -446,7 +451,7 @@ dhcp6opt_print(netdissect_options *ndo, tp++; ND_PRINT((ndo, ", RD:")); for (i = 0; i < 4; i++, tp += 2) - ND_PRINT((ndo, " %04x", EXTRACT_16BITS(tp))); + ND_PRINT((ndo, " %04x", EXTRACT_BE_16BITS(tp))); /* protocol dependent part */ authinfolen = optlen - 11; @@ -464,11 +469,11 @@ dhcp6opt_print(netdissect_options *ndo, } for (i = 0; i < authrealmlen; i++, tp++) ND_PRINT((ndo, "%02x", *tp)); - ND_PRINT((ndo, ", key ID: %08x", EXTRACT_32BITS(tp))); + ND_PRINT((ndo, ", key ID: %08x", EXTRACT_BE_32BITS(tp))); tp += 4; ND_PRINT((ndo, ", HMAC-MD5:")); for (i = 0; i < 4; i++, tp+= 4) - ND_PRINT((ndo, " %08x", EXTRACT_32BITS(tp))); + ND_PRINT((ndo, " %08x", EXTRACT_BE_32BITS(tp))); break; case DH6OPT_AUTHPROTO_RECONFIG: if (authinfolen != 17) { @@ -488,7 +493,7 @@ dhcp6opt_print(netdissect_options *ndo, } ND_PRINT((ndo, " value:")); for (i = 0; i < 4; i++, tp+= 4) - ND_PRINT((ndo, " %08x", EXTRACT_32BITS(tp))); + ND_PRINT((ndo, " %08x", EXTRACT_BE_32BITS(tp))); break; default: ND_PRINT((ndo, " ??")); @@ -506,14 +511,18 @@ dhcp6opt_print(netdissect_options *ndo, * Since we cannot predict the encoding, print hex dump * at most 10 characters. */ - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); ND_PRINT((ndo, " ")); for (i = 0; i < optlen && i < 10; i++) ND_PRINT((ndo, "%02x", tp[i])); ND_PRINT((ndo, "...)")); break; case DH6OPT_RECONF_MSG: - tp = (u_char *)(dh6o + 1); + if (optlen != 1) { + ND_PRINT((ndo, " ?)")); + break; + } + tp = (const u_char *)(dh6o + 1); switch (*tp) { case DH6_RENEW: ND_PRINT((ndo, " for renew)")); @@ -541,14 +550,14 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); for (i = 0; i < optlen; i += 16) ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[i]))); ND_PRINT((ndo, ")")); break; case DH6OPT_SIP_SERVER_D: case DH6OPT_DOMAIN_LIST: - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); while (tp < cp + sizeof(*dh6o) + optlen) { ND_PRINT((ndo, " ")); if ((tp = ns_nprint(ndo, tp, cp + sizeof(*dh6o) + optlen)) == NULL) @@ -561,8 +570,8 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); - ND_PRINT((ndo, " %s)", dhcp6stcode(EXTRACT_16BITS(&tp[0])))); + tp = (const u_char *)(dh6o + 1); + ND_PRINT((ndo, " %s)", dhcp6stcode(EXTRACT_BE_16BITS(&tp[0])))); break; case DH6OPT_IA_NA: case DH6OPT_IA_PD: @@ -570,11 +579,11 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); ND_PRINT((ndo, " IAID:%u T1:%u T2:%u", - EXTRACT_32BITS(&tp[0]), - EXTRACT_32BITS(&tp[4]), - EXTRACT_32BITS(&tp[8]))); + EXTRACT_BE_32BITS(&tp[0]), + EXTRACT_BE_32BITS(&tp[4]), + EXTRACT_BE_32BITS(&tp[8]))); if (optlen > 12) { /* there are sub-options */ dhcp6opt_print(ndo, tp + 12, tp + optlen); @@ -586,8 +595,8 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); - ND_PRINT((ndo, " IAID:%u", EXTRACT_32BITS(tp))); + tp = (const u_char *)(dh6o + 1); + ND_PRINT((ndo, " IAID:%u", EXTRACT_BE_32BITS(tp))); if (optlen > 4) { /* there are sub-options */ dhcp6opt_print(ndo, tp + 4, tp + optlen); @@ -599,11 +608,11 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); ND_PRINT((ndo, " %s/%d", ip6addr_string(ndo, &tp[9]), tp[8])); ND_PRINT((ndo, " pltime:%u vltime:%u", - EXTRACT_32BITS(&tp[0]), - EXTRACT_32BITS(&tp[4]))); + EXTRACT_BE_32BITS(&tp[0]), + EXTRACT_BE_32BITS(&tp[4]))); if (optlen > 25) { /* there are sub-options */ dhcp6opt_print(ndo, tp + 25, tp + optlen); @@ -616,16 +625,16 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); - ND_PRINT((ndo, " %d)", EXTRACT_32BITS(tp))); + tp = (const u_char *)(dh6o + 1); + ND_PRINT((ndo, " %d)", EXTRACT_BE_32BITS(tp))); break; case DH6OPT_REMOTE_ID: if (optlen < 4) { ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); - ND_PRINT((ndo, " %d ", EXTRACT_32BITS(tp))); + tp = (const u_char *)(dh6o + 1); + ND_PRINT((ndo, " %d ", EXTRACT_BE_32BITS(tp))); /* * Print hex dump first 10 characters. */ @@ -638,7 +647,7 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); switch (*tp) { case 1: ND_PRINT((ndo, " by-address")); @@ -658,7 +667,7 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, ")")); break; case DH6OPT_CLIENT_DATA: - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); if (optlen > 0) { /* there are encapsulated options */ dhcp6opt_print(ndo, tp, tp + optlen); @@ -670,7 +679,7 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); ND_PRINT((ndo, " %s ", ip6addr_string(ndo, &tp[0]))); /* * Print hex dump first 10 characters. @@ -684,11 +693,11 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); while (tp < cp + sizeof(*dh6o) + optlen - 4) { - subopt_code = EXTRACT_16BITS(tp); + subopt_code = EXTRACT_BE_16BITS(tp); tp += 2; - subopt_len = EXTRACT_16BITS(tp); + subopt_len = EXTRACT_BE_16BITS(tp); tp += 2; if (tp + subopt_len > cp + sizeof(*dh6o) + optlen) goto trunc; @@ -720,14 +729,14 @@ dhcp6opt_print(netdissect_options *ndo, ND_PRINT((ndo, " ?)")); break; } - tp = (u_char *)(dh6o + 1); + tp = (const u_char *)(dh6o + 1); remain_len = optlen; ND_PRINT((ndo, " ")); /* Encoding is described in section 3.1 of RFC 1035 */ while (remain_len && *tp) { label_len = *tp++; if (label_len < remain_len - 1) { - ND_PRINT((ndo, "%.*s", label_len, tp)); + (void)fn_printn(ndo, tp, label_len, NULL); tp += label_len; remain_len -= (label_len + 1); if(*tp) ND_PRINT((ndo, ".")); @@ -738,6 +747,19 @@ dhcp6opt_print(netdissect_options *ndo, } ND_PRINT((ndo, ")")); break; + case DH6OPT_NEW_POSIX_TIMEZONE: /* all three of these options */ + case DH6OPT_NEW_TZDB_TIMEZONE: /* are encoded similarly */ + case DH6OPT_MUDURL: /* although GMT might not work */ + if (optlen < 5) { + ND_PRINT((ndo, " ?)")); + break; + } + tp = (const u_char *)(dh6o + 1); + ND_PRINT((ndo, "=")); + (void)fn_printn(ndo, tp, (u_int)optlen, NULL); + ND_PRINT((ndo, ")")); + break; + default: ND_PRINT((ndo, ")")); break; @@ -758,20 +780,20 @@ void dhcp6_print(netdissect_options *ndo, const u_char *cp, u_int length) { - struct dhcp6 *dh6; - struct dhcp6_relay *dh6relay; + const struct dhcp6 *dh6; + const struct dhcp6_relay *dh6relay; const u_char *ep; - u_char *extp; + const u_char *extp; const char *name; ND_PRINT((ndo, "dhcp6")); - ep = (u_char *)ndo->ndo_snapend; + ep = (const u_char *)ndo->ndo_snapend; if (cp + length < ep) ep = cp + length; - dh6 = (struct dhcp6 *)cp; - dh6relay = (struct dhcp6_relay *)cp; + dh6 = (const struct dhcp6 *)cp; + dh6relay = (const struct dhcp6_relay *)cp; ND_TCHECK(dh6->dh6_xid); name = tok2str(dh6_msgtype_str, "msgtype-%u", dh6->dh6_msgtype); @@ -785,8 +807,8 @@ dhcp6_print(netdissect_options *ndo, ND_PRINT((ndo, " %s (", name)); /*)*/ if (dh6->dh6_msgtype != DH6_RELAY_FORW && dh6->dh6_msgtype != DH6_RELAY_REPLY) { - ND_PRINT((ndo, "xid=%x", EXTRACT_32BITS(&dh6->dh6_xid) & DH6_XIDMASK)); - extp = (u_char *)(dh6 + 1); + ND_PRINT((ndo, "xid=%x", EXTRACT_BE_32BITS(&dh6->dh6_xid) & DH6_XIDMASK)); + extp = (const u_char *)(dh6 + 1); dhcp6opt_print(ndo, extp, ep); } else { /* relay messages */ struct in6_addr addr6; @@ -799,7 +821,7 @@ dhcp6_print(netdissect_options *ndo, memcpy(&addr6, dh6relay->dh6relay_peeraddr, sizeof (addr6)); ND_PRINT((ndo, " peeraddr=%s", ip6addr_string(ndo, &addr6))); - dhcp6opt_print(ndo, (u_char *)(dh6relay + 1), ep); + dhcp6opt_print(ndo, (const u_char *)(dh6relay + 1), ep); } /*(*/ ND_PRINT((ndo, ")"));