From: fenner Date: Mon, 22 Nov 1999 07:25:26 +0000 (+0000) Subject: Enhanced PIMv1 support. X-Git-Tag: tcpdump-3.5.1~474 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/814765d31c7cf9bf8753cdb2c908f516608c72ee Enhanced PIMv1 support. Cisco Auto-RP support. --- diff --git a/interface.h b/interface.h index bb47b16d..7befb734 100644 --- a/interface.h +++ b/interface.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.111 1999-11-21 03:43:23 assar Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.112 1999-11-22 07:25:26 fenner Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -140,6 +140,7 @@ struct timeval; #endif extern void ts_print(const struct timeval *); +extern void relts_print(int); extern int fn_print(const u_char *, const u_char *); extern int fn_printn(const u_char *, u_int, const u_char *); @@ -200,7 +201,8 @@ extern void ns_print(const u_char *, u_int); extern void ntp_print(const u_char *, u_int); extern void null_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void ospf_print(const u_char *, u_int, const u_char *); -extern void igmp_pim_print(const u_char *, u_int); +extern void pimv1_print(const u_char *, u_int); +extern void cisco_autorp_print(const u_char *, u_int); extern void mobile_print(const u_char *, u_int); extern void pim_print(const u_char *, u_int); extern void ppp_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); diff --git a/print-ip.c b/print-ip.c index 9b66d520..bc167745 100644 --- a/print-ip.c +++ b/print-ip.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.75 1999-11-21 16:26:59 assar Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.76 1999-11-22 07:25:27 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -187,7 +187,7 @@ igmp_print(register const u_char *bp, register u_int len, break; case 0x14: (void)printf("igmp pim"); - igmp_pim_print(bp, len); + pimv1_print(bp, len); break; case 0x1e: print_mresp(bp, len); diff --git a/print-pim.c b/print-pim.c index 709d48d1..3adfcbd4 100644 --- a/print-pim.c +++ b/print-pim.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.13 1999-11-21 09:36:59 fenner Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.14 1999-11-22 07:25:27 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -71,11 +71,86 @@ struct pim { #include "interface.h" #include "addrtoname.h" +#include "extract.h" static void pimv2_print(register const u_char *bp, register u_int len); +static void +pimv1_join_prune_print(register const u_char *bp, register u_int len) +{ + int maddrlen, addrlen, ngroups, njoin, nprune; + int njp; + + /* If it's a single group and a single source, use 1-line output. */ + if (TTEST2(bp[0], 30) && bp[11] == 1 && + ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) { + int hold; + + (void)printf(" RPF %s ", ipaddr_string(bp)); + hold = EXTRACT_16BITS(&bp[6]); + if (hold != 180) { + (void)printf("Hold "); + relts_print(hold); + } + (void)printf("%s (%s/%d, %s", njoin ? "Join" : "Prune", + ipaddr_string(&bp[26]), bp[25] & 0x3f, + ipaddr_string(&bp[12])); + if (EXTRACT_32BITS(&bp[16]) != 0xffffffff) + (void)printf("/%s", ipaddr_string(&bp[16])); + (void)printf(") %s%s %s", + (bp[24] & 0x01) ? "Sparse" : "Dense", + (bp[25] & 0x80) ? " WC" : "", + (bp[25] & 0x40) ? "RP" : "SPT"); + return; + } + + TCHECK2(bp[0], 4); + (void)printf("\n Upstream Nbr: %s", ipaddr_string(bp)); + TCHECK2(bp[6], 2); + (void)printf("\n Hold time: "); + relts_print(EXTRACT_16BITS(&bp[6])); + bp += 8; len -= 8; + + TCHECK2(bp[0], 4); + maddrlen = bp[1]; + addrlen = bp[2]; + ngroups = bp[3]; + bp += 4; len -= 4; + while (ngroups--) { + TCHECK2(bp[0], 4); + (void)printf("\n\tGroup: %s", ipaddr_string(bp)); + if (EXTRACT_32BITS(&bp[4]) != 0xffffffff) + (void)printf("/%s", ipaddr_string(&bp[4])); + TCHECK2(bp[8], 4); + njoin = EXTRACT_16BITS(&bp[8]); + nprune = EXTRACT_16BITS(&bp[10]); + (void)printf(" joined: %d pruned: %d", njoin, nprune); + bp += 12; len -= 12; + for (njp = 0; njp < (njoin + nprune); njp++) { + char *type; + + if (njp < njoin) { + type = "Join "; + } else { + type = "Prune"; + } + TCHECK2(bp[0], 6); + (void)printf("\n\t%s %s%s%s%s/%d", type, + (bp[0] & 0x01) ? "Sparse " : "Dense ", + (bp[1] & 0x80) ? "WC " : "", + (bp[1] & 0x40) ? "RP " : "SPT ", + ipaddr_string(&bp[2]), bp[1] & 0x3f); + bp += 6; len -= 6; + } + } + return; +trunc: + (void)printf("[|pim]"); + return; +} + void -igmp_pim_print(register const u_char *bp, register u_int len) +pimv1_print(register const u_char *bp, register u_int len) { register const u_char *ep; register u_char type; @@ -89,34 +164,87 @@ igmp_pim_print(register const u_char *bp, register u_int len) switch (type) { case 0: (void)printf(" Query"); + if (TTEST(bp[8])) { + switch (bp[8] >> 4) { + case 0: (void)printf(" Dense-mode"); + break; + case 1: (void)printf(" Sparse-mode"); + break; + case 2: (void)printf(" Sparse-Dense-mode"); + break; + default: (void)printf(" mode-%d", bp[8] >> 4); + break; + } + } + if (vflag) { + TCHECK2(bp[10],2); + (void)printf(" (Hold-time "); + relts_print(EXTRACT_16BITS(&bp[10])); + (void)printf(")"); + } break; case 1: (void)printf(" Register"); + TCHECK2(bp[8], 20); /* ip header */ + (void)printf(" for %s > %s", ipaddr_string(&bp[20]), + ipaddr_string(&bp[24])); break; case 2: (void)printf(" Register-Stop"); + TCHECK2(bp[12], 4); + (void)printf(" for %s > %s", ipaddr_string(&bp[8]), + ipaddr_string(&bp[12])); break; case 3: (void)printf(" Join/Prune"); + if (vflag) { + pimv1_join_prune_print(&bp[8], len - 8); + } break; case 4: (void)printf(" RP-reachable"); + if (vflag) { + TCHECK2(bp[22], 2); + (void)printf(" group %s", + ipaddr_string(&bp[8])); + if (EXTRACT_32BITS(&bp[12]) != 0xffffffff) + (void)printf("/%s", ipaddr_string(&bp[12])); + (void)printf(" RP %s hold ", + ipaddr_string(&bp[16])); + relts_print(EXTRACT_16BITS(&bp[22])); + } break; case 5: (void)printf(" Assert"); + TCHECK2(bp[16], 4); + (void)printf(" for %s > %s", ipaddr_string(&bp[16]), + ipaddr_string(&bp[8])); + if (EXTRACT_32BITS(&bp[12]) != 0xffffffff) + (void)printf("/%s", ipaddr_string(&bp[12])); + TCHECK2(bp[24], 4); + (void)printf(" %s pref %d metric %d", + (bp[20] & 0x80) ? "RP-tree" : "SPT", + EXTRACT_32BITS(&bp[20]) & 0x7fffffff, + EXTRACT_32BITS(&bp[24])); break; case 6: (void)printf(" Graft"); + if (vflag) { + pimv1_join_prune_print(&bp[8], len - 8); + } break; case 7: (void)printf(" Graft-ACK"); + if (vflag) { + pimv1_join_prune_print(&bp[8], len - 8); + } break; case 8: @@ -127,6 +255,103 @@ igmp_pim_print(register const u_char *bp, register u_int len) (void)printf(" [type %d]", type); break; } + if ((bp[4] >> 4) != 1) + (void)printf(" [v%d]", bp[4] >> 4); + return; + +trunc: + (void)printf("[|pim]"); + return; +} + +/* + * auto-RP is a cisco protocol, documented at + * ftp://ftpeng.cisco.com/ipmulticast/pim-autorp-spec01.txt + */ +void +cisco_autorp_print(register const u_char *bp, register u_int len) +{ + int type; + int numrps; + int hold; + + TCHECK(bp[0]); + (void)printf(" auto-rp "); + type = bp[0]; + switch (type) { + case 0x11: + (void)printf("candidate-advert"); + break; + case 0x12: + (void)printf("mapping"); + break; + default: + (void)printf("type-0x%02x", type); + break; + } + + TCHECK(bp[1]); + numrps = bp[1]; + + TCHECK2(bp[2], 2); + (void)printf(" Hold "); + hold = EXTRACT_16BITS(&bp[2]); + if (hold) + relts_print(EXTRACT_16BITS(&bp[2])); + else + printf("FOREVER"); + + /* Next 4 bytes are reserved. */ + + bp += 8; len -= 8; + + /*XXX skip unless -v? */ + + /* + * Rest of packet: + * numrps entries of the form: + * 32 bits: RP + * 6 bits: reserved + * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2". + * 8 bits: # of entries for this RP + * each entry: 7 bits: reserved, 1 bit: negative, + * 8 bits: mask 32 bits: source + * lather, rinse, repeat. + */ + while (numrps--) { + int nentries; + char s; + + TCHECK2(bp[0], 4); + (void)printf(" RP %s", ipaddr_string(bp)); + TCHECK(bp[4]); + switch(bp[4] & 0x3) { + case 0: printf(" PIMv?"); + break; + case 1: printf(" PIMv1"); + break; + case 2: printf(" PIMv2"); + break; + case 3: printf(" PIMv1+2"); + break; + } + TCHECK(bp[5]); + nentries = bp[5]; + bp += 6; len -= 6; + s = ' '; + for (; nentries; nentries--) { + TCHECK2(bp[0], 6); + (void)printf("%c%s%s/%d", s, bp[0] & 1 ? "!" : "", + ipaddr_string(&bp[2]), bp[1]); + s = ','; + bp += 6; len -= 6; + } + } + return; + +trunc: + (void)printf("[|autorp]"); + return; } void diff --git a/print-udp.c b/print-udp.c index 74662ebd..6b98fe72 100644 --- a/print-udp.c +++ b/print-udp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.67 1999-11-21 15:57:51 assar Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.68 1999-11-22 07:25:27 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -309,6 +309,7 @@ rtcp_print(const u_char *hdr, const u_char *ep) #define RX_PORT_HIGH 7009 /*XXX*/ #define NETBIOS_NS_PORT 137 #define NETBIOS_DGRAM_PORT 138 +#define CISCO_AUTORP_PORT 496 /*XXX*/ #ifdef INET6 #define RIPNG_PORT 521 /*XXX*/ @@ -538,6 +539,8 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) */ else if (dport == 4567) wb_print((const void *)(up + 1), length); + else if (ISPORT(CISCO_AUTORP_PORT)) + cisco_autorp_print((const void *)(up + 1), length); else (void)printf(" udp %u", (u_int32_t)(ulen - sizeof(*up))); diff --git a/util.c b/util.c index e830a084..326eae49 100644 --- a/util.c +++ b/util.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.60 1999-11-21 09:37:05 fenner Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.61 1999-11-22 07:25:27 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -163,6 +163,34 @@ ts_print(register const struct timeval *tvp) } } +/* + * Print a relative number of seconds (e.g. hold time, prune timer) + * in the form 5m1s. This does no truncation, so 32230861 seconds + * is represented as 1y1w1d1h1m1s. + */ +void +relts_print(int secs) +{ + static char *lengths[]={"y","w","d","h","m","s"}; + static int seconds[]={31536000,604800,86400,3600,60,1}; + char **l = lengths; + int *s = seconds; + int len; + int i; + + if (secs == 0) { + (void)printf("0s"); + return; + } + while (secs) { + if (secs >= *s) { + (void)printf("%d%s", secs / *s, *l); + secs -= (secs / *s) * *s; + } + s++; l++; + } +} + /* * Convert a token value to a string; use "fmt" if not found. */