X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/67eb31b99460a5d3454b28d0cec118ef35bbeacd..ad7a38341c19e71e3595c17368ac18f08b71482d:/print-pim.c diff --git a/print-pim.c b/print-pim.c index ba7d22ce..157df46f 100644 --- a/print-pim.c +++ b/print-pim.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.48 2005-07-11 20:15:33 hannes Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.49 2006-02-13 01:31:35 hannes Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -29,7 +29,15 @@ static const char rcsid[] _U_ = #endif #include + +#include +#include + #include "interface.h" +#include "addrtoname.h" +#include "extract.h" + +#include "ip.h" #define PIMV2_TYPE_HELLO 0 #define PIMV2_TYPE_REGISTER 1 @@ -42,7 +50,7 @@ static const char rcsid[] _U_ = #define PIMV2_TYPE_CANDIDATE_RP 8 #define PIMV2_TYPE_PRUNE_REFRESH 9 -static struct tok pimv2_type_values[] = { +static const struct tok pimv2_type_values[] = { { PIMV2_TYPE_HELLO, "Hello" }, { PIMV2_TYPE_REGISTER, "Register" }, { PIMV2_TYPE_REGISTER_STOP, "Register Stop" }, @@ -66,7 +74,7 @@ static struct tok pimv2_type_values[] = { #define PIMV2_HELLO_OPTION_ADDRESS_LIST 24 #define PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD 65001 -static struct tok pimv2_hello_option_values[] = { +static const struct tok pimv2_hello_option_values[] = { { PIMV2_HELLO_OPTION_HOLDTIME, "Hold Time" }, { PIMV2_HELLO_OPTION_LANPRUNEDELAY, "LAN Prune Delay" }, { PIMV2_HELLO_OPTION_DR_PRIORITY_OLD, "DR Priority (Old)" }, @@ -79,6 +87,15 @@ static struct tok pimv2_hello_option_values[] = { { 0, NULL} }; +#define PIMV2_REGISTER_FLAG_LEN 4 +#define PIMV2_REGISTER_FLAG_BORDER 0x80000000 +#define PIMV2_REGISTER_FLAG_NULL 0x40000000 + +static const struct tok pimv2_register_flag_values[] = { + { PIMV2_REGISTER_FLAG_BORDER, "Border" }, + { PIMV2_REGISTER_FLAG_NULL, "Null" }, + { 0, NULL} +}; /* * XXX: We consider a case where IPv6 is not ready yet for portability, @@ -99,22 +116,12 @@ struct pim { u_short pim_cksum; /* IP style check sum */ }; - -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "extract.h" - -#include "ip.h" - -static void pimv2_print(register const u_char *bp, register u_int len); +static void pimv2_print(register const u_char *bp, register u_int len, u_int cksum); static void pimv1_join_prune_print(register const u_char *bp, register u_int len) { - int maddrlen, addrlen, ngroups, njoin, nprune; + int ngroups, njoin, nprune; int njp; /* If it's a single group and a single source, use 1-line output. */ @@ -155,8 +162,6 @@ pimv1_join_prune_print(register const u_char *bp, register u_int len) len -= 8; TCHECK2(bp[0], 4); - maddrlen = bp[1]; - addrlen = bp[2]; ngroups = bp[3]; bp += 4; len -= 4; @@ -390,8 +395,12 @@ cisco_autorp_print(register const u_char *bp, register u_int len) TCHECK2(bp[0], 6); (void)printf("%c%s%s/%d", s, bp[0] & 1 ? "!" : "", ipaddr_string(&bp[2]), bp[1]); - if (bp[0] & 0xfe) - (void)printf("[rsvd=0x%02x]", bp[0] & 0xfe); + if (bp[0] & 0x02) { + (void)printf(" bidir"); + } + if (bp[0] & 0xfc) { + (void)printf("[rsvd=0x%02x]", bp[0] & 0xfc); + } s = ','; bp += 6; len -= 6; } @@ -404,7 +413,7 @@ trunc: } void -pim_print(register const u_char *bp, register u_int len) +pim_print(register const u_char *bp, register u_int len, u_int cksum) { register const u_char *ep; register struct pim *pim = (struct pim *)bp; @@ -419,21 +428,21 @@ pim_print(register const u_char *bp, register u_int len) switch (PIM_VER(pim->pim_typever)) { case 2: if (!vflag) { - printf("PIMv%u, %s, length: %u", + printf("PIMv%u, %s, length %u", PIM_VER(pim->pim_typever), tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim->pim_typever)), len); return; } else { - printf("PIMv%u, length: %u\n\t%s", + printf("PIMv%u, length %u\n\t%s", PIM_VER(pim->pim_typever), len, tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim->pim_typever))); - pimv2_print(bp, len); + pimv2_print(bp, len, cksum); } break; default: - printf("PIMv%u, length: %u", + printf("PIMv%u, length %u", PIM_VER(pim->pim_typever), len); break; @@ -609,7 +618,7 @@ trunc: } static void -pimv2_print(register const u_char *bp, register u_int len) +pimv2_print(register const u_char *bp, register u_int len, u_int cksum) { register const u_char *ep; register struct pim *pim = (struct pim *)bp; @@ -625,6 +634,13 @@ pimv2_print(register const u_char *bp, register u_int len) if (pimv2_addr_len != 0) (void)printf(", RFC2117-encoding"); + printf(", cksum 0x%04x ", EXTRACT_16BITS(&pim->pim_cksum)); + if (EXTRACT_16BITS(&pim->pim_cksum) == 0) { + printf("(unverified)"); + } else { + printf("(%scorrect)", TTEST2(bp[0], len) && cksum ? "in" : "" ); + } + switch (PIM_TYPE(pim->pim_typever)) { case PIMV2_TYPE_HELLO: { @@ -636,7 +652,7 @@ pimv2_print(register const u_char *bp, register u_int len) olen = EXTRACT_16BITS(&bp[2]); TCHECK2(bp[0], 4 + olen); - printf("\n\t %s Option (%u), length: %u, Value: ", + printf("\n\t %s Option (%u), length %u, Value: ", tok2str( pimv2_hello_option_values,"Unknown",otype), otype, olen); @@ -649,7 +665,7 @@ pimv2_print(register const u_char *bp, register u_int len) case PIMV2_HELLO_OPTION_LANPRUNEDELAY: if (olen != 4) { - (void)printf("ERROR: Option Lenght != 4 Bytes (%u)", olen); + (void)printf("ERROR: Option Length != 4 Bytes (%u)", olen); } else { char t_bit; u_int16_t lan_delay, override_interval; @@ -672,7 +688,7 @@ pimv2_print(register const u_char *bp, register u_int len) printf("%u", EXTRACT_32BITS(bp)); break; default: - printf("ERROR: Option Lenght != 4 Bytes (%u)", olen); + printf("ERROR: Option Length != 4 Bytes (%u)", olen); break; } break; @@ -714,12 +730,12 @@ pimv2_print(register const u_char *bp, register u_int len) break; default: if (vflag <= 1) - print_unknown_data(bp,"\n\t ",olen); + print_unknown_data(gndo,bp,"\n\t ",olen); break; } /* do we want to see an additionally hexdump ? */ if (vflag> 1) - print_unknown_data(bp,"\n\t ",olen); + print_unknown_data(gndo,bp,"\n\t ",olen); bp += olen; } break; @@ -729,30 +745,35 @@ pimv2_print(register const u_char *bp, register u_int len) { struct ip *ip; - if (vflag && bp + 8 <= ep) { - (void)printf(" %s%s", bp[4] & 0x80 ? "B" : "", - bp[4] & 0x40 ? "N" : ""); - } - bp += 8; len -= 8; + if (!TTEST2(*(bp+4), PIMV2_REGISTER_FLAG_LEN)) + goto trunc; + printf(", Flags [ %s ]\n\t", + tok2str(pimv2_register_flag_values, + "none", + EXTRACT_32BITS(bp+4))); + + bp += 8; len -= 8; /* encapsulated multicast packet */ - if (bp >= ep) - break; ip = (struct ip *)bp; switch (IP_V(ip)) { + case 0: /* Null header */ + (void)printf("IP-Null-header %s > %s", + ipaddr_string(&ip->ip_src), + ipaddr_string(&ip->ip_dst)); + break; + case 4: /* IPv4 */ - printf(" "); ip_print(gndo, bp, len); break; #ifdef INET6 case 6: /* IPv6 */ - printf(" "); - ip6_print(bp, len); + ip6_print(gndo, bp, len); break; #endif - default: - (void)printf(" IP ver %d", IP_V(ip)); - break; + default: + (void)printf("IP ver %d", IP_V(ip)); + break; } break; }