X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/1095f1011a8bcdc6b4893d21ac4a423233e7f408..1bcd37991fa57d9e966a6f96e7cbff59b16c28bd:/print-icmp6.c diff --git a/print-icmp6.c b/print-icmp6.c index c5ce7ea5..c535d3b7 100644 --- a/print-icmp6.c +++ b/print-icmp6.c @@ -151,6 +151,7 @@ struct icmp6_hdr { #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 */ #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */ @@ -757,7 +758,7 @@ get_lifetime(uint32_t v) if (v == (uint32_t)~0UL) return "infinity"; else { - nd_snprintf(buf, sizeof(buf), "%us", v); + snprintf(buf, sizeof(buf), "%us", v); return buf; } } @@ -815,7 +816,6 @@ rpl_printopts(netdissect_options *ndo, const uint8_t *opts, u_int length) while (length != 0) { opt = (const struct rpl_genoption *)opts; - ND_TCHECK_1(opt->rpl_dio_type); dio_type = GET_U_1(opt->rpl_dio_type); if (dio_type == RPL_OPT_PAD1) { optlen = 1; @@ -843,7 +843,6 @@ rpl_printopts(netdissect_options *ndo, const uint8_t *opts, u_int length) return; trunc: nd_print_trunc(ndo); - return; } static void @@ -872,7 +871,6 @@ rpl_dio_print(netdissect_options *ndo, return; trunc: nd_print_trunc(ndo); - return; } static void @@ -918,7 +916,6 @@ trunc: tooshort: ND_PRINT(" [|length too short]"); - return; } static void @@ -961,7 +958,6 @@ trunc: tooshort: ND_PRINT(" [|dao-length too short]"); - return; } static void @@ -1031,7 +1027,7 @@ icmp6_print(netdissect_options *ndo, const struct ip6_hdr *ip; const struct ip6_hdr *oip; const struct udphdr *ouh; - u_int dport; + uint16_t dport; const u_char *ep; u_int prot; @@ -1051,7 +1047,6 @@ icmp6_print(netdissect_options *ndo, uint16_t sum, udp_sum; if (ND_TTEST_LEN(bp, length)) { - ND_TCHECK_2(dp->icmp6_cksum); udp_sum = GET_BE_U_2(dp->icmp6_cksum); sum = icmp6_cksum(ndo, ip, dp, length); if (sum != 0) @@ -1063,7 +1058,6 @@ icmp6_print(netdissect_options *ndo, } } - ND_TCHECK_1(dp->icmp6_type); icmp6_type = GET_U_1(dp->icmp6_type); ND_PRINT("ICMP6, %s", tok2str(icmp6_type_values,"unknown icmp6 type (%u)",icmp6_type)); @@ -1077,24 +1071,22 @@ icmp6_print(netdissect_options *ndo, icmp6_type == ICMP6_MOBILEPREFIX_ADVERT )) ND_PRINT(", length %u", length); - ND_TCHECK_1(dp->icmp6_code); icmp6_code = GET_U_1(dp->icmp6_code); switch (icmp6_type) { case ICMP6_DST_UNREACH: - ND_TCHECK_16(oip->ip6_dst); ND_PRINT(", %s", tok2str(icmp6_dst_unreach_code_values,"unknown unreach code (%u)",icmp6_code)); switch (icmp6_code) { case ICMP6_DST_UNREACH_NOROUTE: /* fall through */ case ICMP6_DST_UNREACH_ADMIN: case ICMP6_DST_UNREACH_ADDR: - ND_PRINT(" %s",ip6addr_string(ndo, oip->ip6_dst)); + ND_PRINT(" %s",GET_IP6ADDR_STRING(oip->ip6_dst)); break; case ICMP6_DST_UNREACH_BEYONDSCOPE: ND_PRINT(" %s, source address %s", - ip6addr_string(ndo, oip->ip6_dst), - ip6addr_string(ndo, oip->ip6_src)); + GET_IP6ADDR_STRING(oip->ip6_dst), + GET_IP6ADDR_STRING(oip->ip6_src)); break; case ICMP6_DST_UNREACH_NOPORT: if ((ouh = get_upperlayer(ndo, (const u_char *)oip, &prot)) @@ -1105,17 +1097,17 @@ icmp6_print(netdissect_options *ndo, switch (prot) { case IPPROTO_TCP: ND_PRINT(", %s tcp port %s", - ip6addr_string(ndo, oip->ip6_dst), + GET_IP6ADDR_STRING(oip->ip6_dst), tcpport_string(ndo, dport)); break; case IPPROTO_UDP: ND_PRINT(", %s udp port %s", - ip6addr_string(ndo, oip->ip6_dst), + GET_IP6ADDR_STRING(oip->ip6_dst), udpport_string(ndo, dport)); break; default: ND_PRINT(", %s protocol %u port %u unreachable", - ip6addr_string(ndo, oip->ip6_dst), + GET_IP6ADDR_STRING(oip->ip6_dst), prot, dport); break; } @@ -1129,15 +1121,13 @@ icmp6_print(netdissect_options *ndo, } break; case ICMP6_PACKET_TOO_BIG: - ND_TCHECK_4(dp->icmp6_mtu); ND_PRINT(", mtu %u", GET_BE_U_4(dp->icmp6_mtu)); break; case ICMP6_TIME_EXCEEDED: - ND_TCHECK_16(oip->ip6_dst); switch (icmp6_code) { case ICMP6_TIME_EXCEED_TRANSIT: ND_PRINT(" for %s", - ip6addr_string(ndo, oip->ip6_dst)); + GET_IP6ADDR_STRING(oip->ip6_dst)); break; case ICMP6_TIME_EXCEED_REASSEMBLY: ND_PRINT(" (reassembly)"); @@ -1162,6 +1152,10 @@ icmp6_print(netdissect_options *ndo, ND_PRINT(", option - octet %u", GET_BE_U_4(dp->icmp6_pptr)); break; + case ICMP6_PARAMPROB_FRAGHDRCHAIN: + ND_PRINT(", incomplete header chain - octet %u", + GET_BE_U_4(dp->icmp6_pptr)); + break; default: ND_PRINT(", code-#%u", icmp6_code); @@ -1171,7 +1165,6 @@ icmp6_print(netdissect_options *ndo, case ICMP6_ECHO_REQUEST: case ICMP6_ECHO_REPLY: /* The check below covers both icmp6_id and icmp6_seq. */ - ND_TCHECK_2(dp->icmp6_seq); ND_PRINT(", id %u, seq %u", GET_BE_U_2(dp->icmp6_id), GET_BE_U_2(dp->icmp6_seq)); break; @@ -1205,7 +1198,6 @@ icmp6_print(netdissect_options *ndo, const struct nd_router_advert *p; p = (const struct nd_router_advert *)dp; - ND_TCHECK_4(p->nd_ra_retransmit); ND_PRINT("\n\thop limit %u, Flags [%s]" ", pref %s, router lifetime %us, reachable time %ums, retrans timer %ums", GET_U_1(p->nd_ra_curhoplimit), @@ -1224,8 +1216,7 @@ icmp6_print(netdissect_options *ndo, { const struct nd_neighbor_solicit *p; p = (const struct nd_neighbor_solicit *)dp; - ND_TCHECK_16(p->nd_ns_target); - ND_PRINT(", who has %s", ip6addr_string(ndo, p->nd_ns_target)); + ND_PRINT(", who has %s", GET_IP6ADDR_STRING(p->nd_ns_target)); if (ndo->ndo_vflag) { #define NDSOLLEN 24 if (icmp6_opt_print(ndo, (const u_char *)dp + NDSOLLEN, @@ -1239,9 +1230,8 @@ icmp6_print(netdissect_options *ndo, const struct nd_neighbor_advert *p; p = (const struct nd_neighbor_advert *)dp; - ND_TCHECK_16(p->nd_na_target); ND_PRINT(", tgt is %s", - ip6addr_string(ndo, p->nd_na_target)); + GET_IP6ADDR_STRING(p->nd_na_target)); if (ndo->ndo_vflag) { ND_PRINT(", Flags [%s]", bittok2str(icmp6_nd_na_flag_values, @@ -1260,10 +1250,8 @@ icmp6_print(netdissect_options *ndo, const struct nd_redirect *p; p = (const struct nd_redirect *)dp; - ND_TCHECK_16(p->nd_rd_dst); - ND_PRINT(", %s", ip6addr_string(ndo, p->nd_rd_dst)); - ND_TCHECK_16(p->nd_rd_target); - ND_PRINT(" to %s", ip6addr_string(ndo, p->nd_rd_target)); + ND_PRINT(", %s", GET_IP6ADDR_STRING(p->nd_rd_dst)); + ND_PRINT(" to %s", GET_IP6ADDR_STRING(p->nd_rd_target)); #define REDIRECTLEN 40 if (ndo->ndo_vflag) { if (icmp6_opt_print(ndo, (const u_char *)dp + REDIRECTLEN, @@ -1288,7 +1276,6 @@ icmp6_print(netdissect_options *ndo, break; case ICMP6_MOBILEPREFIX_SOLICIT: /* fall through */ case ICMP6_HADISCOV_REQUEST: - ND_TCHECK_2(dp->icmp6_data16[0]); ND_PRINT(", id 0x%04x", GET_BE_U_2(dp->icmp6_data16[0])); break; case ICMP6_HADISCOV_REPLY: @@ -1296,14 +1283,12 @@ icmp6_print(netdissect_options *ndo, const u_char *cp; const u_char *p; - ND_TCHECK_2(dp->icmp6_data16[0]); ND_PRINT(", id 0x%04x", GET_BE_U_2(dp->icmp6_data16[0])); cp = (const u_char *)dp + length; p = (const u_char *)(dp + 1); while (p < cp) { - ND_TCHECK_16(p); - ND_PRINT(", %s", ip6addr_string(ndo, p)); + ND_PRINT(", %s", GET_IP6ADDR_STRING(p)); p += 16; } } @@ -1312,10 +1297,8 @@ icmp6_print(netdissect_options *ndo, if (ndo->ndo_vflag) { uint16_t flags; - ND_TCHECK_2(dp->icmp6_data16[0]); ND_PRINT(", id 0x%04x", GET_BE_U_2(dp->icmp6_data16[0])); - ND_TCHECK_2(dp->icmp6_data16[1]); flags = GET_BE_U_2(dp->icmp6_data16[1]); if (flags & 0xc000) ND_PRINT(" "); @@ -1424,7 +1407,8 @@ static int icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid) { const struct nd_opt_hdr *op; - uint8_t opt_type, opt_len; + uint8_t opt_type; + u_int opt_len; const struct nd_opt_prefix_info *opp; const struct nd_opt_mtu *opm; const struct nd_opt_rdnss *oprd; @@ -1433,7 +1417,7 @@ icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid) const struct nd_opt_homeagent_info *oph; const struct nd_opt_route_info *opri; const u_char *cp, *ep, *domp; - struct in6_addr in6; + nd_ipv6 in6; size_t l; u_int i; @@ -1471,9 +1455,8 @@ icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid) break; case ND_OPT_PREFIX_INFORMATION: opp = (const struct nd_opt_prefix_info *)op; - ND_TCHECK_16(opp->nd_opt_pi_prefix); ND_PRINT("%s/%u%s, Flags [%s], valid time %s", - ip6addr_string(ndo, opp->nd_opt_pi_prefix), + GET_IP6ADDR_STRING(opp->nd_opt_pi_prefix), GET_U_1(opp->nd_opt_pi_prefix_len), (opt_len != 4) ? "badlen" : "", bittok2str(icmp6_opt_pi_flag_values, "none", GET_U_1(opp->nd_opt_pi_flags_reserved)), @@ -1487,7 +1470,6 @@ icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid) break; case ND_OPT_MTU: opm = (const struct nd_opt_mtu *)op; - ND_TCHECK_4(opm->nd_opt_mtu_mtu); ND_PRINT(" %u%s", GET_BE_U_4(opm->nd_opt_mtu_mtu), (opt_len != 1) ? "bad option length" : "" ); @@ -1498,9 +1480,8 @@ icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid) ND_PRINT(" lifetime %us,", GET_BE_U_4(oprd->nd_opt_rdnss_lifetime)); for (i = 0; i < l; i++) { - ND_TCHECK_16(oprd->nd_opt_rdnss_addr[i]); ND_PRINT(" addr: %s", - ip6addr_string(ndo, oprd->nd_opt_rdnss_addr[i])); + GET_IP6ADDR_STRING(oprd->nd_opt_rdnss_addr[i])); } break; case ND_OPT_DNSSL: @@ -1517,13 +1498,11 @@ icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid) break; case ND_OPT_ADVINTERVAL: opa = (const struct nd_opt_advinterval *)op; - ND_TCHECK_4(opa->nd_opt_adv_interval); ND_PRINT(" %ums", GET_BE_U_4(opa->nd_opt_adv_interval)); break; case ND_OPT_HOMEAGENT_INFO: oph = (const struct nd_opt_homeagent_info *)op; - ND_TCHECK_2(oph->nd_opt_hai_lifetime); ND_PRINT(" preference %u, lifetime %u", GET_BE_U_2(oph->nd_opt_hai_preference), GET_BE_U_2(oph->nd_opt_hai_lifetime)); @@ -1586,7 +1565,7 @@ mld6_print(netdissect_options *ndo, const u_char *bp) return; ND_PRINT("max resp delay: %u ", GET_BE_U_2(mp->mld6_maxdelay)); - ND_PRINT("addr: %s", ip6addr_string(ndo, mp->mld6_addr)); + ND_PRINT("addr: %s", GET_IP6ADDR_STRING(mp->mld6_addr)); } static void @@ -1602,7 +1581,6 @@ mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len) return; } - ND_TCHECK_2(icp->icmp6_data16[1]); ngroups = GET_BE_U_2(icp->icmp6_data16[1]); ND_PRINT(", %u group record(s)", ngroups); if (ndo->ndo_vflag > 0) { @@ -1614,8 +1592,7 @@ mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len) ND_PRINT(" [invalid number of groups]"); return; } - ND_TCHECK_LEN(bp + 4 + group, sizeof(nd_ipv6)); - ND_PRINT(" [gaddr %s", ip6addr_string(ndo, bp + group + 4)); + ND_PRINT(" [gaddr %s", GET_IP6ADDR_STRING(bp + group + 4)); ND_PRINT(" %s", tok2str(mldv2report2str, " [v2-report-#%u]", GET_U_1(bp + group))); nsrcs = GET_BE_U_2(bp + group + 2); @@ -1630,9 +1607,7 @@ mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len) /* Print the sources */ ND_PRINT(" {"); for (j = 0; j < nsrcs; j++) { - ND_TCHECK_LEN(bp + group + 20 + (j * sizeof(nd_ipv6)), - sizeof(nd_ipv6)); - ND_PRINT(" %s", ip6addr_string(ndo, bp + group + 20 + (j * sizeof(nd_ipv6)))); + ND_PRINT(" %s", GET_IP6ADDR_STRING(bp + group + 20 + (j * sizeof(nd_ipv6)))); } ND_PRINT(" }"); } @@ -1641,10 +1616,6 @@ mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len) ND_PRINT("]"); } } - return; -trunc: - nd_print_trunc(ndo); - return; } static void @@ -1661,7 +1632,6 @@ mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len) ND_PRINT(" [invalid len %u]", len); return; } - ND_TCHECK_2(icp->icmp6_data16[0]); mrc = GET_BE_U_2(icp->icmp6_data16[0]); if (mrc < 32768) { mrt = mrc; @@ -1671,11 +1641,9 @@ mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len) if (ndo->ndo_vflag) { ND_PRINT(" [max resp delay=%u]", mrt); } - ND_TCHECK_LEN(bp + 8, sizeof(nd_ipv6)); - ND_PRINT(" [gaddr %s", ip6addr_string(ndo, bp + 8)); + ND_PRINT(" [gaddr %s", GET_IP6ADDR_STRING(bp + 8)); if (ndo->ndo_vflag) { - ND_TCHECK_1(bp + 25); if (GET_U_1(bp + 24) & 0x08) { ND_PRINT(" sflag"); } @@ -1691,7 +1659,6 @@ mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len) ND_PRINT(" qqi=%u", qqi); } - ND_TCHECK_2(bp + 26); nsrcs = GET_BE_U_2(bp + 26); if (nsrcs > 0) { if (len < 28 + nsrcs * sizeof(nd_ipv6)) @@ -1699,19 +1666,13 @@ mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len) else if (ndo->ndo_vflag > 1) { ND_PRINT(" {"); for (i = 0; i < nsrcs; i++) { - ND_TCHECK_LEN(bp + 28 + (i * sizeof(nd_ipv6)), - sizeof(nd_ipv6)); - ND_PRINT(" %s", ip6addr_string(ndo, bp + 28 + (i * sizeof(nd_ipv6)))); + ND_PRINT(" %s", GET_IP6ADDR_STRING(bp + 28 + (i * sizeof(nd_ipv6)))); } ND_PRINT(" }"); } else ND_PRINT(", %u source(s)", nsrcs); } ND_PRINT("]"); - return; -trunc: - nd_print_trunc(ndo); - return; } static void @@ -1840,7 +1801,7 @@ icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, break; } ND_PRINT(", subject=%s", - ip6addr_string(ndo, cp)); + GET_IP6ADDR_STRING(cp)); break; case ICMP6_NI_SUBJ_FQDN: ND_PRINT(", subject=DNS name"); @@ -1867,7 +1828,7 @@ icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, break; } ND_PRINT(", subject=%s", - ipaddr_string(ndo, cp)); + GET_IPADDR_STRING(cp)); break; default: ND_PRINT(", unknown subject"); @@ -1939,7 +1900,6 @@ icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, ND_PRINT(", "); ND_PRINT("DNS name"); cp = (const u_char *)(ni6 + 1) + 4; - ND_TCHECK_1(cp); if (GET_U_1(cp) == ep - cp - 1) { /* icmp-name-lookup-03, pascal string */ if (ndo->ndo_vflag) @@ -1965,7 +1925,7 @@ icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, if (i + sizeof(uint32_t) + sizeof(nd_ipv6) > siz) break; ND_PRINT(" %s(%u)", - ip6addr_string(ndo, bp + i + sizeof(uint32_t)), + GET_IP6ADDR_STRING(bp + i + sizeof(uint32_t)), GET_BE_U_4(bp + i)); i += sizeof(uint32_t) + sizeof(nd_ipv6); }