X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/99c91c3aec40b691641374f58e798bd8d6b657bd..d9dbb118f2f9c09a8548a2b34a6573f611c0bcf7:/print-pim.c diff --git a/print-pim.c b/print-pim.c index f023207d..092c41fe 100644 --- a/print-pim.c +++ b/print-pim.c @@ -19,6 +19,8 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +/* \summary: Protocol Independent Multicast (PIM) printer */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -31,6 +33,7 @@ #include "ip.h" #include "ip6.h" +#include "ipproto.h" #define PIMV1_TYPE_QUERY 0 #define PIMV1_TYPE_REGISTER 1 @@ -534,12 +537,10 @@ pimv2_addr_print(netdissect_options *ndo, af = AF_INET; len = sizeof(struct in_addr); break; -#ifdef INET6 case 2: af = AF_INET6; len = sizeof(struct in6_addr); break; -#endif default: return -1; } @@ -551,11 +552,9 @@ pimv2_addr_print(netdissect_options *ndo, case sizeof(struct in_addr): af = AF_INET; break; -#ifdef INET6 case sizeof(struct in6_addr): af = AF_INET6; break; -#endif default: return -1; break; @@ -572,12 +571,10 @@ pimv2_addr_print(netdissect_options *ndo, if (!silent) ND_PRINT((ndo, "%s", ipaddr_string(ndo, bp))); } -#ifdef INET6 else if (af == AF_INET6) { if (!silent) ND_PRINT((ndo, "%s", ip6addr_string(ndo, bp))); } -#endif return hdrlen + len; case pimv2_group: case pimv2_source: @@ -589,7 +586,6 @@ pimv2_addr_print(netdissect_options *ndo, ND_PRINT((ndo, "/%u", bp[1])); } } -#ifdef INET6 else if (af == AF_INET6) { if (!silent) { ND_PRINT((ndo, "%s", ip6addr_string(ndo, bp + 2))); @@ -597,7 +593,6 @@ pimv2_addr_print(netdissect_options *ndo, ND_PRINT((ndo, "/%u", bp[1])); } } -#endif if (bp[0] && !silent) { if (at == pimv2_group) { ND_PRINT((ndo, "(0x%02x)", bp[0])); @@ -627,11 +622,16 @@ enum checksum_status { }; static enum checksum_status -pimv2_check_checksum(const u_char *bp, const u_char *bp2, u_int len) +pimv2_check_checksum(netdissect_options *ndo, const u_char *bp, + const u_char *bp2, u_int len) { const struct ip *ip; u_int cksum; + if (!ND_TTEST2(bp[0], len)) { + /* We don't have all the data. */ + return (UNVERIFIED); + } ip = (const struct ip *)bp2; if (IP_V(ip) == 4) { struct cksum_vec vec[1]; @@ -640,14 +640,12 @@ pimv2_check_checksum(const u_char *bp, const u_char *bp2, u_int len) vec[0].len = len; cksum = in_cksum(vec, 1); return (cksum ? INCORRECT : CORRECT); -#ifdef INET6 } else if (IP_V(ip) == 6) { const struct ip6_hdr *ip6; ip6 = (const struct ip6_hdr *)bp2; - cksum = nextproto6_cksum(ip6, bp, len, len, IPPROTO_PIM); + cksum = nextproto6_cksum(ndo, ip6, bp, len, len, IPPROTO_PIM); return (cksum ? INCORRECT : CORRECT); -#endif } else { return (UNVERIFIED); } @@ -681,7 +679,7 @@ pimv2_print(netdissect_options *ndo, * The checksum only covers the packet header, * not the encapsulated packet. */ - cksum_status = pimv2_check_checksum(bp, bp2, 8); + cksum_status = pimv2_check_checksum(ndo, bp, bp2, 8); if (cksum_status == INCORRECT) { /* * To quote RFC 4601, "For interoperability @@ -689,13 +687,13 @@ pimv2_print(netdissect_options *ndo, * calculated over the entire PIM Register * message should also be accepted." */ - cksum_status = pimv2_check_checksum(bp, bp2, len); + cksum_status = pimv2_check_checksum(ndo, bp, bp2, len); } } else { /* * The checksum covers the entire packet. */ - cksum_status = pimv2_check_checksum(bp, bp2, len); + cksum_status = pimv2_check_checksum(ndo, bp, bp2, len); } switch (cksum_status) {