+trunc:
+ (void)printf("[|pim]");
+ return;
+}
+
+/*
+ * auto-RP is a cisco protocol, documented at
+ * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
+ *
+ * This implements version 1+, dated Sept 9, 1998.
+ */
+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;
+ }
+ if (bp[4] & 0xfc)
+ (void)printf(" [rsvd=0x%02x]", bp[4] & 0xfc);
+ 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]);
+ if (bp[0] & 0xfe)
+ (void)printf("[rsvd=0x%02x]", bp[0] & 0xfe);
+ s = ',';
+ bp += 6; len -= 6;
+ }
+ }
+ return;
+
+trunc:
+ (void)printf("[|autorp]");
+ return;
+}
+
+void
+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;
+
+ ep = (const u_char *)snapend;
+ if (bp >= ep)
+ return;
+#ifdef notyet /* currently we see only version and type */
+ TCHECK(pim->pim_rsv);
+#endif
+
+ switch (PIM_VER(pim->pim_typever)) {
+ case 2:
+ if (!vflag) {
+ 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",
+ PIM_VER(pim->pim_typever),
+ len,
+ tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim->pim_typever)));
+ pimv2_print(bp, len, cksum);
+ }
+ break;
+ default:
+ printf("PIMv%u, length %u",
+ PIM_VER(pim->pim_typever),
+ len);
+ break;
+ }
+ return;
+}
+
+/*
+ * PIMv2 uses encoded address representations.
+ *
+ * The last PIM-SM I-D before RFC2117 was published specified the
+ * following representation for unicast addresses. However, RFC2117
+ * specified no encoding for unicast addresses with the unicast
+ * address length specified in the header. Therefore, we have to
+ * guess which encoding is being used (Cisco's PIMv2 implementation
+ * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
+ * field into a 'unicast-address-length-in-bytes' field. We guess
+ * that it's the draft encoding if this reserved field is zero.
+ *
+ * RFC2362 goes back to the encoded format, and calls the addr length
+ * field "reserved" again.
+ *
+ * The first byte is the address family, from:
+ *
+ * 0 Reserved
+ * 1 IP (IP version 4)
+ * 2 IP6 (IP version 6)
+ * 3 NSAP
+ * 4 HDLC (8-bit multidrop)
+ * 5 BBN 1822
+ * 6 802 (includes all 802 media plus Ethernet "canonical format")
+ * 7 E.163
+ * 8 E.164 (SMDS, Frame Relay, ATM)
+ * 9 F.69 (Telex)
+ * 10 X.121 (X.25, Frame Relay)
+ * 11 IPX
+ * 12 Appletalk
+ * 13 Decnet IV
+ * 14 Banyan Vines
+ * 15 E.164 with NSAP format subaddress
+ *
+ * In addition, the second byte is an "Encoding". 0 is the default
+ * encoding for the address family, and no other encodings are currently
+ * specified.
+ *
+ */
+
+static int pimv2_addr_len;
+
+enum pimv2_addrtype {
+ pimv2_unicast, pimv2_group, pimv2_source
+};
+
+/* 0 1 2 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Addr Family | Encoding Type | Unicast Address |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
+ * 0 1 2 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Addr Family | Encoding Type | Reserved | Mask Len |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Group multicast Address |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * 0 1 2 3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Source Address |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+static int
+pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent)
+{
+ int af;
+ int len, hdrlen;
+
+ TCHECK(bp[0]);
+
+ if (pimv2_addr_len == 0) {
+ TCHECK(bp[1]);
+ switch (bp[0]) {
+ case 1:
+ 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;
+ }
+ if (bp[1] != 0)
+ return -1;
+ hdrlen = 2;
+ } else {
+ switch (pimv2_addr_len) {
+ 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;
+ }
+ len = pimv2_addr_len;
+ hdrlen = 0;
+ }
+
+ bp += hdrlen;
+ switch (at) {
+ case pimv2_unicast:
+ TCHECK2(bp[0], len);
+ if (af == AF_INET) {
+ if (!silent)
+ (void)printf("%s", ipaddr_string(bp));
+ }
+#ifdef INET6
+ else if (af == AF_INET6) {
+ if (!silent)
+ (void)printf("%s", ip6addr_string(bp));
+ }
+#endif
+ return hdrlen + len;
+ case pimv2_group:
+ case pimv2_source:
+ TCHECK2(bp[0], len + 2);
+ if (af == AF_INET) {
+ if (!silent) {
+ (void)printf("%s", ipaddr_string(bp + 2));
+ if (bp[1] != 32)
+ (void)printf("/%u", bp[1]);
+ }
+ }
+#ifdef INET6
+ else if (af == AF_INET6) {
+ if (!silent) {
+ (void)printf("%s", ip6addr_string(bp + 2));
+ if (bp[1] != 128)
+ (void)printf("/%u", bp[1]);
+ }
+ }
+#endif
+ if (bp[0] && !silent) {
+ if (at == pimv2_group) {
+ (void)printf("(0x%02x)", bp[0]);
+ } else {
+ (void)printf("(%s%s%s",
+ bp[0] & 0x04 ? "S" : "",
+ bp[0] & 0x02 ? "W" : "",
+ bp[0] & 0x01 ? "R" : "");
+ if (bp[0] & 0xf8) {
+ (void) printf("+0x%02x", bp[0] & 0xf8);
+ }
+ (void)printf(")");
+ }
+ }
+ return hdrlen + 2 + len;
+ default:
+ return -1;
+ }
+trunc:
+ return -1;
+}
+
+static void
+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;
+ int advance;
+
+ ep = (const u_char *)snapend;
+ if (bp >= ep)
+ return;
+ if (ep > bp + len)
+ ep = bp + len;
+ TCHECK(pim->pim_rsv);
+ pimv2_addr_len = pim->pim_rsv;
+ 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:
+ {
+ u_int16_t otype, olen;
+ bp += 4;
+ while (bp < ep) {
+ TCHECK2(bp[0], 4);
+ otype = EXTRACT_16BITS(&bp[0]);
+ olen = EXTRACT_16BITS(&bp[2]);
+ TCHECK2(bp[0], 4 + olen);
+
+ printf("\n\t %s Option (%u), length %u, Value: ",
+ tok2str( pimv2_hello_option_values,"Unknown",otype),
+ otype,
+ olen);
+ bp += 4;
+
+ switch (otype) {
+ case PIMV2_HELLO_OPTION_HOLDTIME:
+ relts_print(EXTRACT_16BITS(bp));
+ break;
+
+ case PIMV2_HELLO_OPTION_LANPRUNEDELAY:
+ if (olen != 4) {
+ (void)printf("ERROR: Option Lenght != 4 Bytes (%u)", olen);
+ } else {
+ char t_bit;
+ u_int16_t lan_delay, override_interval;
+ lan_delay = EXTRACT_16BITS(bp);
+ override_interval = EXTRACT_16BITS(bp+2);
+ t_bit = (lan_delay & 0x8000)? 1 : 0;
+ lan_delay &= ~0x8000;
+ (void)printf("\n\t T-bit=%d, LAN delay %dms, Override interval %dms",
+ t_bit, lan_delay, override_interval);
+ }
+ break;