X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/6288c273b66fa124b58af66026151fff1d5931c2..a63600a1fc28dbc7ae7ce9f996829c49a25fb33c:/print-icmp6.c diff --git a/print-icmp6.c b/print-icmp6.c index c535d3b7..ae2596ac 100644 --- a/print-icmp6.c +++ b/print-icmp6.c @@ -41,7 +41,7 @@ #include "udp.h" #include "ah.h" -/* NetBSD: icmp6.h,v 1.13 2000/08/03 16:30:37 itojun Exp */ +/* NetBSD: icmp6.h,v 1.13 2000/08/03 16:30:37 itojun Exp */ /* $KAME: icmp6.h,v 1.22 2000/08/03 15:25:16 jinmei Exp $ */ /* @@ -103,7 +103,7 @@ struct icmp6_hdr { #define ICMP6_ECHO_REQUEST 128 /* echo service */ #define ICMP6_ECHO_REPLY 129 /* echo reply */ #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */ -#define MLD6_LISTENER_QUERY 130 /* multicast listener query */ +#define MLD6_LISTENER_QUERY 130 /* multicast listener query */ #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */ #define MLD6_LISTENER_REPORT 131 /* multicast listener report */ #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */ @@ -145,10 +145,10 @@ struct icmp6_hdr { #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */ #define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */ -#define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */ +#define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */ #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */ -#define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */ +#define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */ #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */ #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */ #define ICMP6_PARAMPROB_FRAGHDRCHAIN 3 /* incomplete header chain */ @@ -193,7 +193,7 @@ struct mld6_hdr { */ struct nd_router_solicit { /* router solicitation */ - struct icmp6_hdr nd_rs_hdr; + struct icmp6_hdr nd_rs_hdr; /* could be followed by options */ }; @@ -394,18 +394,13 @@ struct icmp6_nodeinfo { #define NI_QTYPE_NODEADDR 3 /* Node Addresses */ #define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */ -/* network endian */ -#define NI_SUPTYPE_FLAG_COMPRESS ((uint16_t)htons(0x1)) -#define NI_FQDN_FLAG_VALIDTTL ((uint16_t)htons(0x1)) - -/* network endian */ -#define NI_NODEADDR_FLAG_TRUNCATE ((uint16_t)htons(0x1)) -#define NI_NODEADDR_FLAG_ALL ((uint16_t)htons(0x2)) -#define NI_NODEADDR_FLAG_COMPAT ((uint16_t)htons(0x4)) -#define NI_NODEADDR_FLAG_LINKLOCAL ((uint16_t)htons(0x8)) -#define NI_NODEADDR_FLAG_SITELOCAL ((uint16_t)htons(0x10)) -#define NI_NODEADDR_FLAG_GLOBAL ((uint16_t)htons(0x20)) -#define NI_NODEADDR_FLAG_ANYCAST ((uint16_t)htons(0x40)) /* just experimental. not in spec */ +#define NI_NODEADDR_FLAG_TRUNCATE 0x0001 +#define NI_NODEADDR_FLAG_ALL 0x0002 +#define NI_NODEADDR_FLAG_COMPAT 0x0004 +#define NI_NODEADDR_FLAG_LINKLOCAL 0x0008 +#define NI_NODEADDR_FLAG_SITELOCAL 0x0010 +#define NI_NODEADDR_FLAG_GLOBAL 0x0020 +#define NI_NODEADDR_FLAG_ANYCAST 0x0040 /* just experimental. not in spec */ struct ni_reply_fqdn { nd_uint32_t ni_fqdn_ttl; /* TTL */ @@ -432,7 +427,7 @@ struct icmp6_router_renum { /* router renumbering header */ #define rr_type rr_hdr.icmp6_type #define rr_code rr_hdr.icmp6_code #define rr_cksum rr_hdr.icmp6_cksum -#define rr_seqnum rr_hdr.icmp6_data32[0] +#define rr_seqnum rr_hdr.icmp6_data32[0] struct rr_pco_match { /* match prefix part */ nd_uint8_t rpm_code; @@ -490,10 +485,6 @@ static void dnsname_print(netdissect_options *ndo, const u_char *, const u_char static void icmp6_nodeinfo_print(netdissect_options *ndo, u_int, const u_char *, const u_char *); static void icmp6_rrenum_print(netdissect_options *ndo, const u_char *, const u_char *); -#ifndef abs -#define abs(a) ((0 < (a)) ? (a) : -(a)) -#endif - /* * DIO: Updated to RFC6550, as published in 2012: section 6. (page 30) */ @@ -711,7 +702,6 @@ static const struct tok icmp6_nd_na_flag_values[] = { { 0, NULL } }; - static const struct tok icmp6_opt_values[] = { { ND_OPT_SOURCE_LINKADDR, "source link-address"}, { ND_OPT_TARGET_LINKADDR, "destination link-address"}, @@ -821,15 +811,15 @@ rpl_printopts(netdissect_options *ndo, const uint8_t *opts, u_int length) optlen = 1; ND_PRINT(" opt:pad1"); } else { - if (length < RPL_GENOPTION_LEN) - goto trunc; + if (length < RPL_GENOPTION_LEN) + goto trunc; optlen = GET_U_1(opt->rpl_dio_len)+RPL_GENOPTION_LEN; ND_PRINT(" opt:%s len:%u ", tok2str(rpl_subopt_values, "subopt:%u", dio_type), optlen); ND_TCHECK_LEN(opt, optlen); if (length < optlen) - goto trunc; + goto trunc; if (ndo->ndo_vflag > 2) { hex_print(ndo, " ", @@ -850,27 +840,25 @@ rpl_dio_print(netdissect_options *ndo, const u_char *bp, u_int length) { const struct nd_rpl_dio *dio = (const struct nd_rpl_dio *)bp; - const char *dagid_str; - - ND_TCHECK_SIZE(dio); - dagid_str = ip6addr_string (ndo, dio->rpl_dagid); + ND_ICHECK_ZU(length, <, sizeof(struct nd_rpl_dio)); ND_PRINT(" [dagid:%s,seq:%u,instance:%u,rank:%u,%smop:%s,prf:%u]", - dagid_str, + GET_IP6ADDR_STRING(dio->rpl_dagid), GET_U_1(dio->rpl_dtsn), GET_U_1(dio->rpl_instanceid), GET_BE_U_2(dio->rpl_dagrank), RPL_DIO_GROUNDED(GET_U_1(dio->rpl_mopprf)) ? "grounded,":"", - tok2str(rpl_mop_values, "mop%u", RPL_DIO_MOP(GET_U_1(dio->rpl_mopprf))), + tok2str(rpl_mop_values, "mop%u", + RPL_DIO_MOP(GET_U_1(dio->rpl_mopprf))), RPL_DIO_PRF(GET_U_1(dio->rpl_mopprf))); if(ndo->ndo_vflag > 1) { rpl_printopts(ndo, bp + sizeof(struct nd_rpl_dio), length - sizeof(struct nd_rpl_dio)); } - return; -trunc: - nd_print_trunc(ndo); + return; +invalid: + nd_print_invalid(ndo); } static void @@ -881,23 +869,19 @@ rpl_dao_print(netdissect_options *ndo, const char *dagid_str = ""; uint8_t rpl_flags; - ND_TCHECK_SIZE(dao); - if (length < ND_RPL_DAO_MIN_LEN) - goto tooshort; + ND_ICHECK_U(length, <, ND_RPL_DAO_MIN_LEN); bp += ND_RPL_DAO_MIN_LEN; length -= ND_RPL_DAO_MIN_LEN; rpl_flags = GET_U_1(dao->rpl_flags); if(RPL_DAO_D(rpl_flags)) { - ND_TCHECK_LEN(dao->rpl_dagid, DAGID_LEN); - if (length < DAGID_LEN) - goto tooshort; - dagid_str = ip6addr_string (ndo, dao->rpl_dagid); + ND_ICHECK_U(length, <, DAGID_LEN); + dagid_str = GET_IP6ADDR_STRING(dao->rpl_dagid); bp += DAGID_LEN; length -= DAGID_LEN; } - ND_PRINT(" [dagid:%s,seq:%u,instance:%u%s%s,%02x]", + ND_PRINT(" [dagid:%s,seq:%u,instance:%u%s%s,flags:%02x]", dagid_str, GET_U_1(dao->rpl_daoseq), GET_U_1(dao->rpl_instanceid), @@ -908,14 +892,9 @@ rpl_dao_print(netdissect_options *ndo, if(ndo->ndo_vflag > 1) { rpl_printopts(ndo, bp, length); } - return; - -trunc: - nd_print_trunc(ndo); - return; - -tooshort: - ND_PRINT(" [|length too short]"); + return; +invalid: + nd_print_invalid(ndo); } static void @@ -925,17 +904,13 @@ rpl_daoack_print(netdissect_options *ndo, const struct nd_rpl_daoack *daoack = (const struct nd_rpl_daoack *)bp; const char *dagid_str = ""; - ND_TCHECK_LEN(daoack, ND_RPL_DAOACK_MIN_LEN); - if (length < ND_RPL_DAOACK_MIN_LEN) - goto tooshort; + ND_ICHECK_U(length, <, ND_RPL_DAOACK_MIN_LEN); bp += ND_RPL_DAOACK_MIN_LEN; length -= ND_RPL_DAOACK_MIN_LEN; if(RPL_DAOACK_D(GET_U_1(daoack->rpl_flags))) { - ND_TCHECK_LEN(daoack->rpl_dagid, DAGID_LEN); - if (length < DAGID_LEN) - goto tooshort; - dagid_str = ip6addr_string (ndo, daoack->rpl_dagid); + ND_ICHECK_U(length, <, DAGID_LEN); + dagid_str = GET_IP6ADDR_STRING(daoack->rpl_dagid); bp += DAGID_LEN; length -= DAGID_LEN; } @@ -950,14 +925,9 @@ rpl_daoack_print(netdissect_options *ndo, if(ndo->ndo_vflag > 1) { rpl_printopts(ndo, bp, length); } - return; - -trunc: - nd_print_trunc(ndo); - return; - -tooshort: - ND_PRINT(" [|dao-length too short]"); + return; +invalid: + nd_print_invalid(ndo); } static void @@ -1017,7 +987,6 @@ trunc: } - void icmp6_print(netdissect_options *ndo, const u_char *bp, u_int length, const u_char *bp2, int fragmented) @@ -1164,7 +1133,6 @@ icmp6_print(netdissect_options *ndo, break; case ICMP6_ECHO_REQUEST: case ICMP6_ECHO_REPLY: - /* The check below covers both icmp6_id and icmp6_seq. */ ND_PRINT(", id %u, seq %u", GET_BE_U_2(dp->icmp6_id), GET_BE_U_2(dp->icmp6_seq)); break; @@ -1360,8 +1328,7 @@ get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot) if (ND_TTEST_2(uh->uh_dport)) { *prot = nh; return(uh); - } - else + } else return(NULL); /* NOTREACHED */ @@ -1489,8 +1456,7 @@ icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid) ND_PRINT(" lifetime %us, domain(s):", GET_BE_U_4(opds->nd_opt_dnssl_lifetime)); domp = cp + 8; /* domain names, variable-sized, RFC1035-encoded */ - while (domp < cp + (opt_len << 3) && GET_U_1(domp) != '\0') - { + while (domp < cp + (opt_len << 3) && GET_U_1(domp) != '\0') { ND_PRINT(" "); if ((domp = fqdn_print(ndo, domp, bp)) == NULL) goto trunc; @@ -1515,17 +1481,15 @@ icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid) case 1: break; case 2: - ND_TCHECK_8(opri + 1); - memcpy(&in6, opri + 1, 8); + GET_CPY_BYTES(&in6, opri + 1, 8); break; case 3: - ND_TCHECK_16(opri + 1); - memcpy(&in6, opri + 1, 16); + GET_CPY_BYTES(&in6, opri + 1, 16); break; default: goto trunc; } - ND_PRINT(" %s/%u", ip6addr_string(ndo, (const u_char *)&in6), + ND_PRINT(" %s/%u", ip6addr_string(ndo, (const u_char *)&in6), /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */ GET_U_1(opri->nd_opt_rti_prefixlen)); ND_PRINT(", pref=%s", get_rtpref(GET_U_1(opri->nd_opt_rti_flags))); @@ -1781,7 +1745,6 @@ icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, break; } - /* XXX backward compat, icmp-name-lookup-03 */ if (siz == sizeof(*ni6)) { ND_PRINT(", 03 draft"); @@ -1976,16 +1939,16 @@ icmp6_rrenum_print(netdissect_options *ndo, const u_char *bp, const u_char *ep) ND_TCHECK_4(rr6->rr_reserved); switch (GET_U_1(rr6->rr_code)) { case ICMP6_ROUTER_RENUMBERING_COMMAND: - ND_PRINT("router renum: command"); + ND_PRINT(", command"); break; case ICMP6_ROUTER_RENUMBERING_RESULT: - ND_PRINT("router renum: result"); + ND_PRINT(", result"); break; case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET: - ND_PRINT("router renum: sequence number reset"); + ND_PRINT(", sequence number reset"); break; default: - ND_PRINT("router renum: code-#%u", GET_U_1(rr6->rr_code)); + ND_PRINT(", code-#%u", GET_U_1(rr6->rr_code)); break; }