X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/315fe447eadb6e03484cd534d21b3936ea903752..refs/heads/master:/print-pim.c diff --git a/print-pim.c b/print-pim.c index f089205d..9241db32 100644 --- a/print-pim.c +++ b/print-pim.c @@ -21,9 +21,7 @@ /* \summary: Protocol Independent Multicast (PIM) printer */ -#ifdef HAVE_CONFIG_H #include -#endif #include "netdissect-stdinc.h" @@ -34,6 +32,7 @@ #include "ip.h" #include "ip6.h" #include "ipproto.h" +#include "af.h" #define PIMV1_TYPE_QUERY 0 #define PIMV1_TYPE_REGISTER 1 @@ -123,7 +122,7 @@ static const struct tok pimv2_register_flag_values[] = { #define PIMV2_DF_ELECTION_BACKOFF 3 #define PIMV2_DF_ELECTION_PASS 4 -static struct tok pimv2_df_election_flag_values[] = { +static const struct tok pimv2_df_election_flag_values[] = { { PIMV2_DF_ELECTION_OFFER, "Offer" }, { PIMV2_DF_ELECTION_WINNER, "Winner" }, { PIMV2_DF_ELECTION_BACKOFF, "Backoff" }, @@ -137,7 +136,7 @@ static struct tok pimv2_df_election_flag_values[] = { /* * XXX: We consider a case where IPv6 is not ready yet for portability, - * but PIM dependent defintions should be independent of IPv6... + * but PIM dependent definitions should be independent of IPv6... */ struct pim { @@ -169,17 +168,17 @@ pimv1_join_prune_print(netdissect_options *ndo, ((njoin = GET_BE_U_2(bp + 20)) + GET_BE_U_2(bp + 22)) == 1) { u_int hold; - ND_PRINT(" RPF %s ", ipaddr_string(ndo, bp)); + ND_PRINT(" RPF %s ", GET_IPADDR_STRING(bp)); hold = GET_BE_U_2(bp + 6); if (hold != 180) { ND_PRINT("Hold "); unsigned_relts_print(ndo, hold); } ND_PRINT("%s (%s/%u, %s", njoin ? "Join" : "Prune", - ipaddr_string(ndo, bp + 26), GET_U_1(bp + 25) & 0x3f, - ipaddr_string(ndo, bp + 12)); + GET_IPADDR_STRING(bp + 26), GET_U_1(bp + 25) & 0x3f, + GET_IPADDR_STRING(bp + 12)); if (GET_BE_U_4(bp + 16) != 0xffffffff) - ND_PRINT("/%s", ipaddr_string(ndo, bp + 16)); + ND_PRINT("/%s", GET_IPADDR_STRING(bp + 16)); ND_PRINT(") %s%s %s", (GET_U_1(bp + 24) & 0x01) ? "Sparse" : "Dense", (GET_U_1(bp + 25) & 0x80) ? " WC" : "", @@ -189,15 +188,13 @@ pimv1_join_prune_print(netdissect_options *ndo, if (len < sizeof(nd_ipv4)) goto trunc; - ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); if (ndo->ndo_vflag > 1) ND_PRINT("\n"); - ND_PRINT(" Upstream Nbr: %s", ipaddr_string(ndo, bp)); + ND_PRINT(" Upstream Nbr: %s", GET_IPADDR_STRING(bp)); bp += 4; len -= 4; if (len < 4) goto trunc; - ND_TCHECK_2(bp + 2); if (ndo->ndo_vflag > 1) ND_PRINT("\n"); ND_PRINT(" Hold time: "); @@ -209,7 +206,6 @@ pimv1_join_prune_print(netdissect_options *ndo, if (len < 4) goto trunc; - ND_TCHECK_4(bp); ngroups = GET_U_1(bp + 3); bp += 4; len -= 4; @@ -220,20 +216,17 @@ pimv1_join_prune_print(netdissect_options *ndo, */ if (len < 4) goto trunc; - ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); - ND_PRINT("\n\tGroup: %s", ipaddr_string(ndo, bp)); + ND_PRINT("\n\tGroup: %s", GET_IPADDR_STRING(bp)); bp += 4; len -= 4; if (len < 4) goto trunc; - ND_TCHECK_LEN(bp, sizeof(nd_ipv4)); if (GET_BE_U_4(bp) != 0xffffffff) - ND_PRINT("/%s", ipaddr_string(ndo, bp)); + ND_PRINT("/%s", GET_IPADDR_STRING(bp)); bp += 4; len -= 4; if (len < 4) goto trunc; - ND_TCHECK_4(bp); njoin = GET_BE_U_2(bp); nprune = GET_BE_U_2(bp + 2); ND_PRINT(" joined: %u pruned: %u", njoin, nprune); @@ -248,12 +241,11 @@ pimv1_join_prune_print(netdissect_options *ndo, type = "Prune"; if (len < 6) goto trunc; - ND_TCHECK_6(bp); ND_PRINT("\n\t%s %s%s%s%s/%u", type, (GET_U_1(bp) & 0x01) ? "Sparse " : "Dense ", (GET_U_1(bp + 1) & 0x80) ? "WC " : "", (GET_U_1(bp + 1) & 0x40) ? "RP " : "SPT ", - ipaddr_string(ndo, bp + 2), + GET_IPADDR_STRING(bp + 2), GET_U_1(bp + 1) & 0x3f); bp += 6; len -= 6; @@ -263,7 +255,6 @@ pimv1_join_prune_print(netdissect_options *ndo, return; trunc: nd_print_trunc(ndo); - return; } void @@ -273,7 +264,6 @@ pimv1_print(netdissect_options *ndo, u_char type; ndo->ndo_protocol = "pimv1"; - ND_TCHECK_1(bp + 1); type = GET_U_1(bp + 1); ND_PRINT(" %s", tok2str(pimv1_type_str, "[type %u]", type)); @@ -296,7 +286,6 @@ pimv1_print(netdissect_options *ndo, } } if (ndo->ndo_vflag) { - ND_TCHECK_2(bp + 10); ND_PRINT(" (Hold-time "); unsigned_relts_print(ndo, GET_BE_U_2(bp + 10)); ND_PRINT(")"); @@ -305,31 +294,27 @@ pimv1_print(netdissect_options *ndo, case PIMV1_TYPE_REGISTER: ND_TCHECK_LEN(bp + 8, 20); /* ip header */ - ND_PRINT(" for %s > %s", ipaddr_string(ndo, bp + 20), - ipaddr_string(ndo, bp + 24)); + ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 20), + GET_IPADDR_STRING(bp + 24)); break; case PIMV1_TYPE_REGISTER_STOP: - ND_TCHECK_LEN(bp + 12, sizeof(nd_ipv4)); - ND_PRINT(" for %s > %s", ipaddr_string(ndo, bp + 8), - ipaddr_string(ndo, bp + 12)); + ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 8), + GET_IPADDR_STRING(bp + 12)); break; case PIMV1_TYPE_RP_REACHABILITY: if (ndo->ndo_vflag) { - ND_TCHECK_2(bp + 22); - ND_PRINT(" group %s", ipaddr_string(ndo, bp + 8)); + ND_PRINT(" group %s", GET_IPADDR_STRING(bp + 8)); if (GET_BE_U_4(bp + 12) != 0xffffffff) - ND_PRINT("/%s", ipaddr_string(ndo, bp + 12)); - ND_PRINT(" RP %s hold ", ipaddr_string(ndo, bp + 16)); + ND_PRINT("/%s", GET_IPADDR_STRING(bp + 12)); + ND_PRINT(" RP %s hold ", GET_IPADDR_STRING(bp + 16)); unsigned_relts_print(ndo, GET_BE_U_2(bp + 22)); } break; case PIMV1_TYPE_ASSERT: - ND_TCHECK_LEN(bp + 16, sizeof(nd_ipv4)); - ND_PRINT(" for %s > %s", ipaddr_string(ndo, bp + 16), - ipaddr_string(ndo, bp + 8)); + ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 16), + GET_IPADDR_STRING(bp + 8)); if (GET_BE_U_4(bp + 12) != 0xffffffff) - ND_PRINT("/%s", ipaddr_string(ndo, bp + 12)); - ND_TCHECK_4(bp + 24); + ND_PRINT("/%s", GET_IPADDR_STRING(bp + 12)); ND_PRINT(" %s pref %u metric %u", (GET_U_1(bp + 20) & 0x80) ? "RP-tree" : "SPT", GET_BE_U_4(bp + 20) & 0x7fffffff, @@ -345,14 +330,12 @@ pimv1_print(netdissect_options *ndo, } break; } - ND_TCHECK_1(bp + 4); if ((GET_U_1(bp + 4) >> 4) != 1) ND_PRINT(" [v%u]", GET_U_1(bp + 4) >> 4); return; trunc: nd_print_trunc(ndo); - return; } /* @@ -372,7 +355,6 @@ cisco_autorp_print(netdissect_options *ndo, ndo->ndo_protocol = "cisco_autorp"; if (len < 8) goto trunc; - ND_TCHECK_1(bp); ND_PRINT(" auto-rp "); type = GET_U_1(bp); switch (type) { @@ -387,10 +369,8 @@ cisco_autorp_print(netdissect_options *ndo, break; } - ND_TCHECK_1(bp + 1); numrps = GET_U_1(bp + 1); - ND_TCHECK_2(bp + 2); ND_PRINT(" Hold "); hold = GET_BE_U_2(bp + 2); if (hold) @@ -421,13 +401,11 @@ cisco_autorp_print(netdissect_options *ndo, if (len < 4) goto trunc; - ND_TCHECK_4(bp); - ND_PRINT(" RP %s", ipaddr_string(ndo, bp)); + ND_PRINT(" RP %s", GET_IPADDR_STRING(bp)); bp += 4; len -= 4; if (len < 1) goto trunc; - ND_TCHECK_1(bp); switch (GET_U_1(bp) & 0x3) { case 0: ND_PRINT(" PIMv?"); break; @@ -444,7 +422,6 @@ cisco_autorp_print(netdissect_options *ndo, len -= 1; if (len < 1) goto trunc; - ND_TCHECK_1(bp); nentries = GET_U_1(bp); bp += 1; len -= 1; @@ -452,9 +429,8 @@ cisco_autorp_print(netdissect_options *ndo, while (nentries != 0) { if (len < 6) goto trunc; - ND_TCHECK_6(bp); ND_PRINT("%c%s%s/%u", s, GET_U_1(bp) & 1 ? "!" : "", - ipaddr_string(ndo, bp + 2), GET_U_1(bp + 1)); + GET_IPADDR_STRING(bp + 2), GET_U_1(bp + 1)); if (GET_U_1(bp) & 0x02) { ND_PRINT(" bidir"); } @@ -471,7 +447,6 @@ cisco_autorp_print(netdissect_options *ndo, trunc: nd_print_trunc(ndo); - return; } void @@ -482,11 +457,7 @@ pim_print(netdissect_options *ndo, uint8_t pim_typever; ndo->ndo_protocol = "pim"; -#ifdef notyet /* currently we see only version and type */ - ND_TCHECK_1(pim->pim_rsv); -#endif - ND_TCHECK_1(pim->pim_typever); pim_typever = GET_U_1(pim->pim_typever); switch (PIM_VER(pim_typever)) { case 2: @@ -510,11 +481,6 @@ pim_print(netdissect_options *ndo, len); break; } - return; - -trunc: - nd_print_trunc(ndo); - return; } /* @@ -592,14 +558,12 @@ pimv2_addr_print(netdissect_options *ndo, if (addr_len == 0) { if (len < 2) goto trunc; - ND_TCHECK_1(bp + 1); - switch (GET_U_1(bp)) { - case 1: - af = AF_INET; + af = GET_U_1(bp); + switch (af) { + case AFNUM_IP: addr_len = (u_int)sizeof(nd_ipv4); break; - case 2: - af = AF_INET6; + case AFNUM_IP6: addr_len = (u_int)sizeof(nd_ipv6); break; default: @@ -611,14 +575,13 @@ pimv2_addr_print(netdissect_options *ndo, } else { switch (addr_len) { case sizeof(nd_ipv4): - af = AF_INET; + af = AFNUM_IP; break; case sizeof(nd_ipv6): - af = AF_INET6; + af = AFNUM_IP6; break; default: return -1; - break; } hdrlen = 0; } @@ -630,13 +593,12 @@ pimv2_addr_print(netdissect_options *ndo, if (len < addr_len) goto trunc; ND_TCHECK_LEN(bp, addr_len); - if (af == AF_INET) { + if (af == AFNUM_IP) { if (!silent) - ND_PRINT("%s", ipaddr_string(ndo, bp)); - } - else if (af == AF_INET6) { + ND_PRINT("%s", GET_IPADDR_STRING(bp)); + } else if (af == AFNUM_IP6) { if (!silent) - ND_PRINT("%s", ip6addr_string(ndo, bp)); + ND_PRINT("%s", GET_IP6ADDR_STRING(bp)); } return hdrlen + addr_len; case pimv2_group: @@ -644,16 +606,15 @@ pimv2_addr_print(netdissect_options *ndo, if (len < addr_len + 2) goto trunc; ND_TCHECK_LEN(bp, addr_len + 2); - if (af == AF_INET) { + if (af == AFNUM_IP) { if (!silent) { - ND_PRINT("%s", ipaddr_string(ndo, bp + 2)); + ND_PRINT("%s", GET_IPADDR_STRING(bp + 2)); if (GET_U_1(bp + 1) != 32) ND_PRINT("/%u", GET_U_1(bp + 1)); } - } - else if (af == AF_INET6) { + } else if (af == AFNUM_IP6) { if (!silent) { - ND_PRINT("%s", ip6addr_string(ndo, bp + 2)); + ND_PRINT("%s", GET_IP6ADDR_STRING(bp + 2)); if (GET_U_1(bp + 1) != 128) ND_PRINT("/%u", GET_U_1(bp + 1)); } @@ -734,7 +695,6 @@ pimv2_print(netdissect_options *ndo, nd_print_invalid(ndo); return; } - ND_TCHECK_1(pim->pim_rsv); pim_typever = GET_U_1(pim->pim_typever); /* RFC5015 allocates the high 4 bits of pim_rsv for "subtype". */ pimv2_addr_len = GET_U_1(pim->pim_rsv) & 0x0f; @@ -746,7 +706,6 @@ pimv2_print(netdissect_options *ndo, nd_print_invalid(ndo); return; } - ND_TCHECK_2(pim->pim_cksum); ND_PRINT(", cksum 0x%04x ", GET_BE_U_2(pim->pim_cksum)); if (GET_BE_U_2(pim->pim_cksum) == 0) { ND_PRINT("(unverified)"); @@ -794,10 +753,9 @@ pimv2_print(netdissect_options *ndo, case PIMV2_TYPE_HELLO: { uint16_t otype, olen; - while (len > 0) { + while (len != 0) { if (len < 4) goto trunc; - ND_TCHECK_4(bp); otype = GET_BE_U_2(bp); olen = GET_BE_U_2(bp + 2); ND_PRINT("\n\t %s Option (%u), length %u, Value: ", @@ -813,7 +771,9 @@ pimv2_print(netdissect_options *ndo, switch (otype) { case PIMV2_HELLO_OPTION_HOLDTIME: if (olen != 2) { - ND_PRINT("ERROR: Option Length != 2 Bytes (%u)", olen); + ND_PRINT("[option length %u != 2]", olen); + nd_print_invalid(ndo); + return; } else { unsigned_relts_print(ndo, GET_BE_U_2(bp)); @@ -822,7 +782,9 @@ pimv2_print(netdissect_options *ndo, case PIMV2_HELLO_OPTION_LANPRUNEDELAY: if (olen != 4) { - ND_PRINT("ERROR: Option Length != 4 Bytes (%u)", olen); + ND_PRINT("[option length %u != 4]", olen); + nd_print_invalid(ndo); + return; } else { char t_bit; uint16_t lan_delay, override_interval; @@ -845,14 +807,17 @@ pimv2_print(netdissect_options *ndo, ND_PRINT("%u", GET_BE_U_4(bp)); break; default: - ND_PRINT("ERROR: Option Length != 4 Bytes (%u)", olen); - break; + ND_PRINT("[option length %u != 4]", olen); + nd_print_invalid(ndo); + return; } break; case PIMV2_HELLO_OPTION_GENID: if (olen != 4) { - ND_PRINT("ERROR: Option Length != 4 Bytes (%u)", olen); + ND_PRINT("[option length %u != 4]", olen); + nd_print_invalid(ndo); + return; } else { ND_PRINT("0x%08x", GET_BE_U_4(bp)); } @@ -860,7 +825,9 @@ pimv2_print(netdissect_options *ndo, case PIMV2_HELLO_OPTION_REFRESH_CAP: if (olen != 4) { - ND_PRINT("ERROR: Option Length != 4 Bytes (%u)", olen); + ND_PRINT("[option length %u != 4]", olen); + nd_print_invalid(ndo); + return; } else { ND_PRINT("v%u", GET_U_1(bp)); if (GET_U_1(bp + 1) != 0) { @@ -925,13 +892,11 @@ pimv2_print(netdissect_options *ndo, if (len == 0) goto trunc; ip = (const struct ip *)bp; - ND_TCHECK_1(ip->ip_vhl); switch (IP_V(ip)) { case 0: /* Null header */ - ND_TCHECK_4(ip->ip_dst); ND_PRINT("IP-Null-header %s > %s", - ipaddr_string(ndo, ip->ip_src), - ipaddr_string(ndo, ip->ip_dst)); + GET_IPADDR_STRING(ip->ip_src), + GET_IPADDR_STRING(ip->ip_dst)); break; case 4: /* IPv4 */ @@ -1062,13 +1027,11 @@ pimv2_print(netdissect_options *ndo, /* Fragment Tag, Hash Mask len, and BSR-priority */ if (len < 2) goto trunc; - ND_TCHECK_2(bp); ND_PRINT(" tag=%x", GET_BE_U_2(bp)); bp += 2; len -= 2; if (len < 1) goto trunc; - ND_TCHECK_1(bp); ND_PRINT(" hashmlen=%u", GET_U_1(bp)); if (len < 2) goto trunc; @@ -1095,11 +1058,9 @@ pimv2_print(netdissect_options *ndo, /* RP-Count, Frag RP-Cnt, and rsvd */ if (len < 1) goto trunc; - ND_TCHECK_1(bp); ND_PRINT(" RPcnt=%u", GET_U_1(bp)); if (len < 2) goto trunc; - ND_TCHECK_1(bp + 1); frpcnt = GET_U_1(bp + 1); ND_PRINT(" FRPcnt=%u", frpcnt); if (len < 4) @@ -1120,13 +1081,11 @@ pimv2_print(netdissect_options *ndo, if (len < 2) goto trunc; - ND_TCHECK_2(bp); ND_PRINT(",holdtime="); unsigned_relts_print(ndo, GET_BE_U_2(bp)); if (len < 3) goto trunc; - ND_TCHECK_1(bp + 2); ND_PRINT(",prio=%u", GET_U_1(bp + 2)); if (len < 4) goto trunc; @@ -1162,16 +1121,13 @@ pimv2_print(netdissect_options *ndo, /* Prefix-Cnt, Priority, and Holdtime */ if (len < 1) goto trunc; - ND_TCHECK_1(bp); ND_PRINT(" prefix-cnt=%u", GET_U_1(bp)); pfxcnt = GET_U_1(bp); if (len < 2) goto trunc; - ND_TCHECK_1(bp + 1); ND_PRINT(" prio=%u", GET_U_1(bp + 1)); if (len < 4) goto trunc; - ND_TCHECK_2(bp + 2); ND_PRINT(" holdtime="); unsigned_relts_print(ndo, GET_BE_U_2(bp + 2)); bp += 4; @@ -1213,7 +1169,6 @@ pimv2_print(netdissect_options *ndo, len -= advance; if (len < 2) goto trunc; - ND_TCHECK_2(bp); ND_PRINT(" TUNR "); unsigned_relts_print(ndo, GET_BE_U_2(bp)); break;