X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/59690cf6b7ffce3cc86936cbe658909c6ec3a687..refs/heads/tcpdump-4.6:/print-pim.c diff --git a/print-pim.c b/print-pim.c index 645a4901..567d3d99 100644 --- a/print-pim.c +++ b/print-pim.c @@ -32,6 +32,27 @@ #include "ip.h" +#define PIMV1_TYPE_QUERY 0 +#define PIMV1_TYPE_REGISTER 1 +#define PIMV1_TYPE_REGISTER_STOP 2 +#define PIMV1_TYPE_JOIN_PRUNE 3 +#define PIMV1_TYPE_RP_REACHABILITY 4 +#define PIMV1_TYPE_ASSERT 5 +#define PIMV1_TYPE_GRAFT 6 +#define PIMV1_TYPE_GRAFT_ACK 7 + +static const struct tok pimv1_type_str[] = { + { PIMV1_TYPE_QUERY, "Query" }, + { PIMV1_TYPE_REGISTER, "Register" }, + { PIMV1_TYPE_REGISTER_STOP, "Register-Stop" }, + { PIMV1_TYPE_JOIN_PRUNE, "Join/Prune" }, + { PIMV1_TYPE_RP_REACHABILITY, "RP-reachable" }, + { PIMV1_TYPE_ASSERT, "Assert" }, + { PIMV1_TYPE_GRAFT, "Graft" }, + { PIMV1_TYPE_GRAFT_ACK, "Graft-ACK" }, + { 0, NULL } +}; + #define PIMV2_TYPE_HELLO 0 #define PIMV2_TYPE_REGISTER 1 #define PIMV2_TYPE_REGISTER_STOP 2 @@ -42,6 +63,8 @@ #define PIMV2_TYPE_GRAFT_ACK 7 #define PIMV2_TYPE_CANDIDATE_RP 8 #define PIMV2_TYPE_PRUNE_REFRESH 9 +#define PIMV2_TYPE_DF_ELECTION 10 +#define PIMV2_TYPE_ECMP_REDIRECT 11 static const struct tok pimv2_type_values[] = { { PIMV2_TYPE_HELLO, "Hello" }, @@ -54,6 +77,8 @@ static const struct tok pimv2_type_values[] = { { PIMV2_TYPE_GRAFT_ACK, "Graft Acknowledgement" }, { PIMV2_TYPE_CANDIDATE_RP, "Candidate RP Advertisement" }, { PIMV2_TYPE_PRUNE_REFRESH, "Prune Refresh" }, + { PIMV2_TYPE_DF_ELECTION, "DF Election" }, + { PIMV2_TYPE_ECMP_REDIRECT, "ECMP Redirect" }, { 0, NULL} }; @@ -96,7 +121,7 @@ static const struct tok pimv2_register_flag_values[] = { */ struct pim { - u_int8_t pim_typever; + uint8_t pim_typever; /* upper 4bit: PIM version number; 2 for PIMv2 */ /* lower 4bit: the PIM message type, currently they are: * Hello, Register, Register-Stop, Join/Prune, @@ -123,17 +148,17 @@ pimv1_join_prune_print(netdissect_options *ndo, ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) { int hold; - ND_PRINT((ndo, " RPF %s ", ipaddr_string(bp))); + ND_PRINT((ndo, " RPF %s ", ipaddr_string(ndo, bp))); hold = EXTRACT_16BITS(&bp[6]); if (hold != 180) { ND_PRINT((ndo, "Hold ")); - relts_print(hold); + relts_print(ndo, hold); } ND_PRINT((ndo, "%s (%s/%d, %s", njoin ? "Join" : "Prune", - ipaddr_string(&bp[26]), bp[25] & 0x3f, - ipaddr_string(&bp[12]))); + ipaddr_string(ndo, &bp[26]), bp[25] & 0x3f, + ipaddr_string(ndo, &bp[12]))); if (EXTRACT_32BITS(&bp[16]) != 0xffffffff) - ND_PRINT((ndo, "/%s", ipaddr_string(&bp[16]))); + ND_PRINT((ndo, "/%s", ipaddr_string(ndo, &bp[16]))); ND_PRINT((ndo, ") %s%s %s", (bp[24] & 0x01) ? "Sparse" : "Dense", (bp[25] & 0x80) ? " WC" : "", @@ -144,12 +169,12 @@ pimv1_join_prune_print(netdissect_options *ndo, ND_TCHECK2(bp[0], sizeof(struct in_addr)); if (ndo->ndo_vflag > 1) ND_PRINT((ndo, "\n")); - ND_PRINT((ndo, " Upstream Nbr: %s", ipaddr_string(bp))); + ND_PRINT((ndo, " Upstream Nbr: %s", ipaddr_string(ndo, bp))); ND_TCHECK2(bp[6], 2); if (ndo->ndo_vflag > 1) ND_PRINT((ndo, "\n")); ND_PRINT((ndo, " Hold time: ")); - relts_print(EXTRACT_16BITS(&bp[6])); + relts_print(ndo, EXTRACT_16BITS(&bp[6])); if (ndo->ndo_vflag < 2) return; bp += 8; @@ -165,10 +190,10 @@ pimv1_join_prune_print(netdissect_options *ndo, * mask length "maddrlen"? */ ND_TCHECK2(bp[0], sizeof(struct in_addr)); - ND_PRINT((ndo, "\n\tGroup: %s", ipaddr_string(bp))); + ND_PRINT((ndo, "\n\tGroup: %s", ipaddr_string(ndo, bp))); ND_TCHECK2(bp[4], sizeof(struct in_addr)); if (EXTRACT_32BITS(&bp[4]) != 0xffffffff) - ND_PRINT((ndo, "/%s", ipaddr_string(&bp[4]))); + ND_PRINT((ndo, "/%s", ipaddr_string(ndo, &bp[4]))); ND_TCHECK2(bp[8], 4); njoin = EXTRACT_16BITS(&bp[8]); nprune = EXTRACT_16BITS(&bp[10]); @@ -187,7 +212,7 @@ pimv1_join_prune_print(netdissect_options *ndo, (bp[0] & 0x01) ? "Sparse " : "Dense ", (bp[1] & 0x80) ? "WC " : "", (bp[1] & 0x40) ? "RP " : "SPT ", - ipaddr_string(&bp[2]), bp[1] & 0x3f)); + ipaddr_string(ndo, &bp[2]), bp[1] & 0x3f)); bp += 6; len -= 6; } @@ -212,9 +237,9 @@ pimv1_print(netdissect_options *ndo, ND_TCHECK(bp[1]); type = bp[1]; + ND_PRINT((ndo, " %s", tok2str(pimv1_type_str, "[type %u]", type))); switch (type) { - case 0: - ND_PRINT((ndo, " Query")); + case PIMV1_TYPE_QUERY: if (ND_TTEST(bp[8])) { switch (bp[8] >> 4) { case 0: @@ -234,68 +259,49 @@ pimv1_print(netdissect_options *ndo, if (ndo->ndo_vflag) { ND_TCHECK2(bp[10],2); ND_PRINT((ndo, " (Hold-time ")); - relts_print(EXTRACT_16BITS(&bp[10])); + relts_print(ndo, EXTRACT_16BITS(&bp[10])); ND_PRINT((ndo, ")")); } break; - case 1: - ND_PRINT((ndo, " Register")); + case PIMV1_TYPE_REGISTER: ND_TCHECK2(bp[8], 20); /* ip header */ - ND_PRINT((ndo, " for %s > %s", ipaddr_string(&bp[20]), - ipaddr_string(&bp[24]))); + ND_PRINT((ndo, " for %s > %s", ipaddr_string(ndo, &bp[20]), + ipaddr_string(ndo, &bp[24]))); break; - case 2: - ND_PRINT((ndo, " Register-Stop")); + case PIMV1_TYPE_REGISTER_STOP: ND_TCHECK2(bp[12], sizeof(struct in_addr)); - ND_PRINT((ndo, " for %s > %s", ipaddr_string(&bp[8]), - ipaddr_string(&bp[12]))); - break; - case 3: - ND_PRINT((ndo, " Join/Prune")); - if (ndo->ndo_vflag) - pimv1_join_prune_print(ndo, &bp[8], len - 8); + ND_PRINT((ndo, " for %s > %s", ipaddr_string(ndo, &bp[8]), + ipaddr_string(ndo, &bp[12]))); break; - case 4: - ND_PRINT((ndo, " RP-reachable")); + case PIMV1_TYPE_RP_REACHABILITY: if (ndo->ndo_vflag) { ND_TCHECK2(bp[22], 2); - ND_PRINT((ndo, " group %s", ipaddr_string(&bp[8]))); + ND_PRINT((ndo, " group %s", ipaddr_string(ndo, &bp[8]))); if (EXTRACT_32BITS(&bp[12]) != 0xffffffff) - ND_PRINT((ndo, "/%s", ipaddr_string(&bp[12]))); - ND_PRINT((ndo, " RP %s hold ", ipaddr_string(&bp[16]))); - relts_print(EXTRACT_16BITS(&bp[22])); + ND_PRINT((ndo, "/%s", ipaddr_string(ndo, &bp[12]))); + ND_PRINT((ndo, " RP %s hold ", ipaddr_string(ndo, &bp[16]))); + relts_print(ndo, EXTRACT_16BITS(&bp[22])); } break; - case 5: - ND_PRINT((ndo, " Assert")); + case PIMV1_TYPE_ASSERT: ND_TCHECK2(bp[16], sizeof(struct in_addr)); - ND_PRINT((ndo, " for %s > %s", ipaddr_string(&bp[16]), - ipaddr_string(&bp[8]))); + ND_PRINT((ndo, " for %s > %s", ipaddr_string(ndo, &bp[16]), + ipaddr_string(ndo, &bp[8]))); if (EXTRACT_32BITS(&bp[12]) != 0xffffffff) - ND_PRINT((ndo, "/%s", ipaddr_string(&bp[12]))); + ND_PRINT((ndo, "/%s", ipaddr_string(ndo, &bp[12]))); ND_TCHECK2(bp[24], 4); ND_PRINT((ndo, " %s pref %d metric %d", (bp[20] & 0x80) ? "RP-tree" : "SPT", EXTRACT_32BITS(&bp[20]) & 0x7fffffff, EXTRACT_32BITS(&bp[24]))); break; - case 6: - ND_PRINT((ndo, " Graft")); + case PIMV1_TYPE_JOIN_PRUNE: + case PIMV1_TYPE_GRAFT: + case PIMV1_TYPE_GRAFT_ACK: if (ndo->ndo_vflag) pimv1_join_prune_print(ndo, &bp[8], len - 8); break; - case 7: - ND_PRINT((ndo, " Graft-ACK")); - if (ndo->ndo_vflag) - pimv1_join_prune_print(ndo, &bp[8], len - 8); - break; - case 8: - ND_PRINT((ndo, " Mode")); - break; - default: - ND_PRINT((ndo, " [type %d]", type)); - break; } if ((bp[4] >> 4) != 1) ND_PRINT((ndo, " [v%d]", bp[4] >> 4)); @@ -342,7 +348,7 @@ cisco_autorp_print(netdissect_options *ndo, ND_PRINT((ndo, " Hold ")); hold = EXTRACT_16BITS(&bp[2]); if (hold) - relts_print(EXTRACT_16BITS(&bp[2])); + relts_print(ndo, EXTRACT_16BITS(&bp[2])); else ND_PRINT((ndo, "FOREVER")); @@ -368,7 +374,7 @@ cisco_autorp_print(netdissect_options *ndo, char s; ND_TCHECK2(bp[0], 4); - ND_PRINT((ndo, " RP %s", ipaddr_string(bp))); + ND_PRINT((ndo, " RP %s", ipaddr_string(ndo, bp))); ND_TCHECK(bp[4]); switch (bp[4] & 0x3) { case 0: ND_PRINT((ndo, " PIMv?")); @@ -389,7 +395,7 @@ cisco_autorp_print(netdissect_options *ndo, for (; nentries; nentries--) { ND_TCHECK2(bp[0], 6); ND_PRINT((ndo, "%c%s%s/%d", s, bp[0] & 1 ? "!" : "", - ipaddr_string(&bp[2]), bp[1])); + ipaddr_string(ndo, &bp[2]), bp[1])); if (bp[0] & 0x02) { ND_PRINT((ndo, " bidir")); } @@ -564,12 +570,12 @@ pimv2_addr_print(netdissect_options *ndo, ND_TCHECK2(bp[0], len); if (af == AF_INET) { if (!silent) - ND_PRINT((ndo, "%s", ipaddr_string(bp))); + ND_PRINT((ndo, "%s", ipaddr_string(ndo, bp))); } #ifdef INET6 else if (af == AF_INET6) { if (!silent) - ND_PRINT((ndo, "%s", ip6addr_string(bp))); + ND_PRINT((ndo, "%s", ip6addr_string(ndo, bp))); } #endif return hdrlen + len; @@ -578,7 +584,7 @@ pimv2_addr_print(netdissect_options *ndo, ND_TCHECK2(bp[0], len + 2); if (af == AF_INET) { if (!silent) { - ND_PRINT((ndo, "%s", ipaddr_string(bp + 2))); + ND_PRINT((ndo, "%s", ipaddr_string(ndo, bp + 2))); if (bp[1] != 32) ND_PRINT((ndo, "/%u", bp[1])); } @@ -586,7 +592,7 @@ pimv2_addr_print(netdissect_options *ndo, #ifdef INET6 else if (af == AF_INET6) { if (!silent) { - ND_PRINT((ndo, "%s", ip6addr_string(bp + 2))); + ND_PRINT((ndo, "%s", ip6addr_string(ndo, bp + 2))); if (bp[1] != 128) ND_PRINT((ndo, "/%u", bp[1])); } @@ -642,7 +648,7 @@ pimv2_print(netdissect_options *ndo, switch (PIM_TYPE(pim->pim_typever)) { case PIMV2_TYPE_HELLO: { - u_int16_t otype, olen; + uint16_t otype, olen; bp += 4; while (bp < ep) { ND_TCHECK2(bp[0], 4); @@ -657,7 +663,7 @@ pimv2_print(netdissect_options *ndo, switch (otype) { case PIMV2_HELLO_OPTION_HOLDTIME: - relts_print(EXTRACT_16BITS(bp)); + relts_print(ndo, EXTRACT_16BITS(bp)); break; case PIMV2_HELLO_OPTION_LANPRUNEDELAY: @@ -665,7 +671,7 @@ pimv2_print(netdissect_options *ndo, ND_PRINT((ndo, "ERROR: Option Length != 4 Bytes (%u)", olen)); } else { char t_bit; - u_int16_t lan_delay, override_interval; + uint16_t lan_delay, override_interval; lan_delay = EXTRACT_16BITS(bp); override_interval = EXTRACT_16BITS(bp+2); t_bit = (lan_delay & 0x8000)? 1 : 0; @@ -698,7 +704,7 @@ pimv2_print(netdissect_options *ndo, ND_PRINT((ndo, "v%d", *bp)); if (*(bp+1) != 0) { ND_PRINT((ndo, ", interval ")); - relts_print(*(bp+1)); + relts_print(ndo, *(bp+1)); } if (EXTRACT_16BITS(bp+2) != 0) { ND_PRINT((ndo, " ?0x%04x?", EXTRACT_16BITS(bp+2))); @@ -742,8 +748,7 @@ pimv2_print(netdissect_options *ndo, { struct ip *ip; - if (!ND_TTEST2(*(bp+4), PIMV2_REGISTER_FLAG_LEN)) - goto trunc; + ND_TCHECK2(*(bp + 4), PIMV2_REGISTER_FLAG_LEN); ND_PRINT((ndo, ", Flags [ %s ]\n\t", tok2str(pimv2_register_flag_values, @@ -756,8 +761,8 @@ pimv2_print(netdissect_options *ndo, switch (IP_V(ip)) { case 0: /* Null header */ ND_PRINT((ndo, "IP-Null-header %s > %s", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst))); + ipaddr_string(ndo, &ip->ip_src), + ipaddr_string(ndo, &ip->ip_dst))); break; case 4: /* IPv4 */ @@ -836,10 +841,10 @@ pimv2_print(netdissect_options *ndo, */ { - u_int8_t ngroup; - u_int16_t holdtime; - u_int16_t njoin; - u_int16_t nprune; + uint8_t ngroup; + uint16_t holdtime; + uint16_t njoin; + uint16_t nprune; int i, j; bp += 4; len -= 4; @@ -863,7 +868,7 @@ pimv2_print(netdissect_options *ndo, if (holdtime == 0xffff) ND_PRINT((ndo, "infinite")); else - relts_print(holdtime); + relts_print(ndo, holdtime); } bp += 4; len -= 4; for (i = 0; i < ngroup; i++) { @@ -910,9 +915,9 @@ pimv2_print(netdissect_options *ndo, bp += 4; /* Fragment Tag, Hash Mask len, and BSR-priority */ - if (bp + sizeof(u_int16_t) >= ep) break; + if (bp + sizeof(uint16_t) >= ep) break; ND_PRINT((ndo, " tag=%x", EXTRACT_16BITS(bp))); - bp += sizeof(u_int16_t); + bp += sizeof(uint16_t); if (bp >= ep) break; ND_PRINT((ndo, " hashmlen=%d", bp[0])); if (bp + 1 >= ep) break; @@ -967,7 +972,7 @@ pimv2_print(netdissect_options *ndo, goto bs_done; } ND_PRINT((ndo, ",holdtime=")); - relts_print(EXTRACT_16BITS(bp)); + relts_print(ndo, EXTRACT_16BITS(bp)); if (bp + 2 >= ep) { ND_PRINT((ndo, "...)")); goto bs_done; @@ -1019,7 +1024,7 @@ pimv2_print(netdissect_options *ndo, ND_PRINT((ndo, " prio=%d", bp[1])); if (bp + 3 >= ep) break; ND_PRINT((ndo, " holdtime=")); - relts_print(EXTRACT_16BITS(&bp[2])); + relts_print(ndo, EXTRACT_16BITS(&bp[2])); bp += 4; /* Encoded-Unicast-RP-Address */ @@ -1065,7 +1070,7 @@ pimv2_print(netdissect_options *ndo, bp += advance; ND_TCHECK2(bp[0], 2); ND_PRINT((ndo, " TUNR ")); - relts_print(EXTRACT_16BITS(bp)); + relts_print(ndo, EXTRACT_16BITS(bp)); break;