2 * Copyright (c) 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 /* \summary: Protocol Independent Multicast (PIM) printer */
28 #include <netdissect-stdinc.h>
30 #include "netdissect.h"
31 #include "addrtoname.h"
38 #define PIMV1_TYPE_QUERY 0
39 #define PIMV1_TYPE_REGISTER 1
40 #define PIMV1_TYPE_REGISTER_STOP 2
41 #define PIMV1_TYPE_JOIN_PRUNE 3
42 #define PIMV1_TYPE_RP_REACHABILITY 4
43 #define PIMV1_TYPE_ASSERT 5
44 #define PIMV1_TYPE_GRAFT 6
45 #define PIMV1_TYPE_GRAFT_ACK 7
47 static const struct tok pimv1_type_str[] = {
48 { PIMV1_TYPE_QUERY, "Query" },
49 { PIMV1_TYPE_REGISTER, "Register" },
50 { PIMV1_TYPE_REGISTER_STOP, "Register-Stop" },
51 { PIMV1_TYPE_JOIN_PRUNE, "Join/Prune" },
52 { PIMV1_TYPE_RP_REACHABILITY, "RP-reachable" },
53 { PIMV1_TYPE_ASSERT, "Assert" },
54 { PIMV1_TYPE_GRAFT, "Graft" },
55 { PIMV1_TYPE_GRAFT_ACK, "Graft-ACK" },
59 #define PIMV2_TYPE_HELLO 0
60 #define PIMV2_TYPE_REGISTER 1
61 #define PIMV2_TYPE_REGISTER_STOP 2
62 #define PIMV2_TYPE_JOIN_PRUNE 3
63 #define PIMV2_TYPE_BOOTSTRAP 4
64 #define PIMV2_TYPE_ASSERT 5
65 #define PIMV2_TYPE_GRAFT 6
66 #define PIMV2_TYPE_GRAFT_ACK 7
67 #define PIMV2_TYPE_CANDIDATE_RP 8
68 #define PIMV2_TYPE_PRUNE_REFRESH 9
69 #define PIMV2_TYPE_DF_ELECTION 10
70 #define PIMV2_TYPE_ECMP_REDIRECT 11
72 static const struct tok pimv2_type_values[] = {
73 { PIMV2_TYPE_HELLO, "Hello" },
74 { PIMV2_TYPE_REGISTER, "Register" },
75 { PIMV2_TYPE_REGISTER_STOP, "Register Stop" },
76 { PIMV2_TYPE_JOIN_PRUNE, "Join / Prune" },
77 { PIMV2_TYPE_BOOTSTRAP, "Bootstrap" },
78 { PIMV2_TYPE_ASSERT, "Assert" },
79 { PIMV2_TYPE_GRAFT, "Graft" },
80 { PIMV2_TYPE_GRAFT_ACK, "Graft Acknowledgement" },
81 { PIMV2_TYPE_CANDIDATE_RP, "Candidate RP Advertisement" },
82 { PIMV2_TYPE_PRUNE_REFRESH, "Prune Refresh" },
83 { PIMV2_TYPE_DF_ELECTION, "DF Election" },
84 { PIMV2_TYPE_ECMP_REDIRECT, "ECMP Redirect" },
88 #define PIMV2_HELLO_OPTION_HOLDTIME 1
89 #define PIMV2_HELLO_OPTION_LANPRUNEDELAY 2
90 #define PIMV2_HELLO_OPTION_DR_PRIORITY_OLD 18
91 #define PIMV2_HELLO_OPTION_DR_PRIORITY 19
92 #define PIMV2_HELLO_OPTION_GENID 20
93 #define PIMV2_HELLO_OPTION_REFRESH_CAP 21
94 #define PIMV2_HELLO_OPTION_BIDIR_CAP 22
95 #define PIMV2_HELLO_OPTION_ADDRESS_LIST 24
96 #define PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD 65001
98 static const struct tok pimv2_hello_option_values[] = {
99 { PIMV2_HELLO_OPTION_HOLDTIME, "Hold Time" },
100 { PIMV2_HELLO_OPTION_LANPRUNEDELAY, "LAN Prune Delay" },
101 { PIMV2_HELLO_OPTION_DR_PRIORITY_OLD, "DR Priority (Old)" },
102 { PIMV2_HELLO_OPTION_DR_PRIORITY, "DR Priority" },
103 { PIMV2_HELLO_OPTION_GENID, "Generation ID" },
104 { PIMV2_HELLO_OPTION_REFRESH_CAP, "State Refresh Capability" },
105 { PIMV2_HELLO_OPTION_BIDIR_CAP, "Bi-Directional Capability" },
106 { PIMV2_HELLO_OPTION_ADDRESS_LIST, "Address List" },
107 { PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD, "Address List (Old)" },
111 #define PIMV2_REGISTER_FLAG_LEN 4
112 #define PIMV2_REGISTER_FLAG_BORDER 0x80000000
113 #define PIMV2_REGISTER_FLAG_NULL 0x40000000
115 static const struct tok pimv2_register_flag_values[] = {
116 { PIMV2_REGISTER_FLAG_BORDER, "Border" },
117 { PIMV2_REGISTER_FLAG_NULL, "Null" },
122 * XXX: We consider a case where IPv6 is not ready yet for portability,
123 * but PIM dependent defintions should be independent of IPv6...
128 /* upper 4bit: PIM version number; 2 for PIMv2 */
129 /* lower 4bit: the PIM message type, currently they are:
130 * Hello, Register, Register-Stop, Join/Prune,
131 * Bootstrap, Assert, Graft (PIM-DM only),
132 * Graft-Ack (PIM-DM only), C-RP-Adv
134 #define PIM_VER(x) (((x) & 0xf0) >> 4)
135 #define PIM_TYPE(x) ((x) & 0x0f)
136 u_char pim_rsv; /* Reserved */
137 u_short pim_cksum; /* IP style check sum */
140 static void pimv2_print(netdissect_options *, register const u_char *bp, register u_int len, const u_char *);
143 pimv1_join_prune_print(netdissect_options *ndo,
144 register const u_char *bp, register u_int len)
146 int ngroups, njoin, nprune;
149 /* If it's a single group and a single source, use 1-line output. */
150 if (ND_TTEST2(bp[0], 30) && bp[11] == 1 &&
151 ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) {
154 ND_PRINT((ndo, " RPF %s ", ipaddr_string(ndo, bp)));
155 hold = EXTRACT_16BITS(&bp[6]);
157 ND_PRINT((ndo, "Hold "));
158 unsigned_relts_print(ndo, hold);
160 ND_PRINT((ndo, "%s (%s/%d, %s", njoin ? "Join" : "Prune",
161 ipaddr_string(ndo, &bp[26]), bp[25] & 0x3f,
162 ipaddr_string(ndo, &bp[12])));
163 if (EXTRACT_32BITS(&bp[16]) != 0xffffffff)
164 ND_PRINT((ndo, "/%s", ipaddr_string(ndo, &bp[16])));
165 ND_PRINT((ndo, ") %s%s %s",
166 (bp[24] & 0x01) ? "Sparse" : "Dense",
167 (bp[25] & 0x80) ? " WC" : "",
168 (bp[25] & 0x40) ? "RP" : "SPT"));
172 ND_TCHECK2(bp[0], sizeof(struct in_addr));
173 if (ndo->ndo_vflag > 1)
174 ND_PRINT((ndo, "\n"));
175 ND_PRINT((ndo, " Upstream Nbr: %s", ipaddr_string(ndo, bp)));
176 ND_TCHECK2(bp[6], 2);
177 if (ndo->ndo_vflag > 1)
178 ND_PRINT((ndo, "\n"));
179 ND_PRINT((ndo, " Hold time: "));
180 unsigned_relts_print(ndo, EXTRACT_16BITS(&bp[6]));
181 if (ndo->ndo_vflag < 2)
186 ND_TCHECK2(bp[0], 4);
192 * XXX - does the address have length "addrlen" and the
193 * mask length "maddrlen"?
195 ND_TCHECK2(bp[0], sizeof(struct in_addr));
196 ND_PRINT((ndo, "\n\tGroup: %s", ipaddr_string(ndo, bp)));
197 ND_TCHECK2(bp[4], sizeof(struct in_addr));
198 if (EXTRACT_32BITS(&bp[4]) != 0xffffffff)
199 ND_PRINT((ndo, "/%s", ipaddr_string(ndo, &bp[4])));
200 ND_TCHECK2(bp[8], 4);
201 njoin = EXTRACT_16BITS(&bp[8]);
202 nprune = EXTRACT_16BITS(&bp[10]);
203 ND_PRINT((ndo, " joined: %d pruned: %d", njoin, nprune));
206 for (njp = 0; njp < (njoin + nprune); njp++) {
213 ND_TCHECK2(bp[0], 6);
214 ND_PRINT((ndo, "\n\t%s %s%s%s%s/%d", type,
215 (bp[0] & 0x01) ? "Sparse " : "Dense ",
216 (bp[1] & 0x80) ? "WC " : "",
217 (bp[1] & 0x40) ? "RP " : "SPT ",
218 ipaddr_string(ndo, &bp[2]), bp[1] & 0x3f));
225 ND_PRINT((ndo, "[|pim]"));
230 pimv1_print(netdissect_options *ndo,
231 register const u_char *bp, register u_int len)
233 register const u_char *ep;
234 register u_char type;
236 ep = (const u_char *)ndo->ndo_snapend;
243 ND_PRINT((ndo, " %s", tok2str(pimv1_type_str, "[type %u]", type)));
245 case PIMV1_TYPE_QUERY:
246 if (ND_TTEST(bp[8])) {
247 switch (bp[8] >> 4) {
249 ND_PRINT((ndo, " Dense-mode"));
252 ND_PRINT((ndo, " Sparse-mode"));
255 ND_PRINT((ndo, " Sparse-Dense-mode"));
258 ND_PRINT((ndo, " mode-%d", bp[8] >> 4));
262 if (ndo->ndo_vflag) {
263 ND_TCHECK2(bp[10],2);
264 ND_PRINT((ndo, " (Hold-time "));
265 unsigned_relts_print(ndo, EXTRACT_16BITS(&bp[10]));
266 ND_PRINT((ndo, ")"));
270 case PIMV1_TYPE_REGISTER:
271 ND_TCHECK2(bp[8], 20); /* ip header */
272 ND_PRINT((ndo, " for %s > %s", ipaddr_string(ndo, &bp[20]),
273 ipaddr_string(ndo, &bp[24])));
275 case PIMV1_TYPE_REGISTER_STOP:
276 ND_TCHECK2(bp[12], sizeof(struct in_addr));
277 ND_PRINT((ndo, " for %s > %s", ipaddr_string(ndo, &bp[8]),
278 ipaddr_string(ndo, &bp[12])));
280 case PIMV1_TYPE_RP_REACHABILITY:
281 if (ndo->ndo_vflag) {
282 ND_TCHECK2(bp[22], 2);
283 ND_PRINT((ndo, " group %s", ipaddr_string(ndo, &bp[8])));
284 if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
285 ND_PRINT((ndo, "/%s", ipaddr_string(ndo, &bp[12])));
286 ND_PRINT((ndo, " RP %s hold ", ipaddr_string(ndo, &bp[16])));
287 unsigned_relts_print(ndo, EXTRACT_16BITS(&bp[22]));
290 case PIMV1_TYPE_ASSERT:
291 ND_TCHECK2(bp[16], sizeof(struct in_addr));
292 ND_PRINT((ndo, " for %s > %s", ipaddr_string(ndo, &bp[16]),
293 ipaddr_string(ndo, &bp[8])));
294 if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
295 ND_PRINT((ndo, "/%s", ipaddr_string(ndo, &bp[12])));
296 ND_TCHECK2(bp[24], 4);
297 ND_PRINT((ndo, " %s pref %d metric %d",
298 (bp[20] & 0x80) ? "RP-tree" : "SPT",
299 EXTRACT_32BITS(&bp[20]) & 0x7fffffff,
300 EXTRACT_32BITS(&bp[24])));
302 case PIMV1_TYPE_JOIN_PRUNE:
303 case PIMV1_TYPE_GRAFT:
304 case PIMV1_TYPE_GRAFT_ACK:
306 pimv1_join_prune_print(ndo, &bp[8], len - 8);
309 if ((bp[4] >> 4) != 1)
310 ND_PRINT((ndo, " [v%d]", bp[4] >> 4));
314 ND_PRINT((ndo, "[|pim]"));
319 * auto-RP is a cisco protocol, documented at
320 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
322 * This implements version 1+, dated Sept 9, 1998.
325 cisco_autorp_print(netdissect_options *ndo,
326 register const u_char *bp, register u_int len)
333 ND_PRINT((ndo, " auto-rp "));
337 ND_PRINT((ndo, "candidate-advert"));
340 ND_PRINT((ndo, "mapping"));
343 ND_PRINT((ndo, "type-0x%02x", type));
350 ND_TCHECK2(bp[2], 2);
351 ND_PRINT((ndo, " Hold "));
352 hold = EXTRACT_16BITS(&bp[2]);
354 unsigned_relts_print(ndo, EXTRACT_16BITS(&bp[2]));
356 ND_PRINT((ndo, "FOREVER"));
358 /* Next 4 bytes are reserved. */
362 /*XXX skip unless -v? */
366 * numrps entries of the form:
369 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
370 * 8 bits: # of entries for this RP
371 * each entry: 7 bits: reserved, 1 bit: negative,
372 * 8 bits: mask 32 bits: source
373 * lather, rinse, repeat.
379 ND_TCHECK2(bp[0], 4);
380 ND_PRINT((ndo, " RP %s", ipaddr_string(ndo, bp)));
382 switch (bp[4] & 0x3) {
383 case 0: ND_PRINT((ndo, " PIMv?"));
385 case 1: ND_PRINT((ndo, " PIMv1"));
387 case 2: ND_PRINT((ndo, " PIMv2"));
389 case 3: ND_PRINT((ndo, " PIMv1+2"));
393 ND_PRINT((ndo, " [rsvd=0x%02x]", bp[4] & 0xfc));
398 for (; nentries; nentries--) {
399 ND_TCHECK2(bp[0], 6);
400 ND_PRINT((ndo, "%c%s%s/%d", s, bp[0] & 1 ? "!" : "",
401 ipaddr_string(ndo, &bp[2]), bp[1]));
403 ND_PRINT((ndo, " bidir"));
406 ND_PRINT((ndo, "[rsvd=0x%02x]", bp[0] & 0xfc));
415 ND_PRINT((ndo, "[|autorp]"));
420 pim_print(netdissect_options *ndo,
421 register const u_char *bp, register u_int len, const u_char *bp2)
423 register const u_char *ep;
424 register const struct pim *pim = (const struct pim *)bp;
426 ep = (const u_char *)ndo->ndo_snapend;
429 #ifdef notyet /* currently we see only version and type */
430 ND_TCHECK(pim->pim_rsv);
433 switch (PIM_VER(pim->pim_typever)) {
435 if (!ndo->ndo_vflag) {
436 ND_PRINT((ndo, "PIMv%u, %s, length %u",
437 PIM_VER(pim->pim_typever),
438 tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim->pim_typever)),
442 ND_PRINT((ndo, "PIMv%u, length %u\n\t%s",
443 PIM_VER(pim->pim_typever),
445 tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim->pim_typever))));
446 pimv2_print(ndo, bp, len, bp2);
450 ND_PRINT((ndo, "PIMv%u, length %u",
451 PIM_VER(pim->pim_typever),
459 * PIMv2 uses encoded address representations.
461 * The last PIM-SM I-D before RFC2117 was published specified the
462 * following representation for unicast addresses. However, RFC2117
463 * specified no encoding for unicast addresses with the unicast
464 * address length specified in the header. Therefore, we have to
465 * guess which encoding is being used (Cisco's PIMv2 implementation
466 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
467 * field into a 'unicast-address-length-in-bytes' field. We guess
468 * that it's the draft encoding if this reserved field is zero.
470 * RFC2362 goes back to the encoded format, and calls the addr length
471 * field "reserved" again.
473 * The first byte is the address family, from:
476 * 1 IP (IP version 4)
477 * 2 IP6 (IP version 6)
479 * 4 HDLC (8-bit multidrop)
481 * 6 802 (includes all 802 media plus Ethernet "canonical format")
483 * 8 E.164 (SMDS, Frame Relay, ATM)
485 * 10 X.121 (X.25, Frame Relay)
490 * 15 E.164 with NSAP format subaddress
492 * In addition, the second byte is an "Encoding". 0 is the default
493 * encoding for the address family, and no other encodings are currently
498 static int pimv2_addr_len;
500 enum pimv2_addrtype {
501 pimv2_unicast, pimv2_group, pimv2_source
505 * 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
506 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
507 * | Addr Family | Encoding Type | Unicast Address |
508 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
510 * 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
511 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
512 * | Addr Family | Encoding Type | Reserved | Mask Len |
513 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
514 * | Group multicast Address |
515 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
517 * 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
518 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
519 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
520 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
522 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
525 pimv2_addr_print(netdissect_options *ndo,
526 const u_char *bp, enum pimv2_addrtype at, int silent)
533 if (pimv2_addr_len == 0) {
538 len = sizeof(struct in_addr);
542 len = sizeof(struct in6_addr);
551 switch (pimv2_addr_len) {
552 case sizeof(struct in_addr):
555 case sizeof(struct in6_addr):
562 len = pimv2_addr_len;
569 ND_TCHECK2(bp[0], len);
572 ND_PRINT((ndo, "%s", ipaddr_string(ndo, bp)));
574 else if (af == AF_INET6) {
576 ND_PRINT((ndo, "%s", ip6addr_string(ndo, bp)));
581 ND_TCHECK2(bp[0], len + 2);
584 ND_PRINT((ndo, "%s", ipaddr_string(ndo, bp + 2)));
586 ND_PRINT((ndo, "/%u", bp[1]));
589 else if (af == AF_INET6) {
591 ND_PRINT((ndo, "%s", ip6addr_string(ndo, bp + 2)));
593 ND_PRINT((ndo, "/%u", bp[1]));
596 if (bp[0] && !silent) {
597 if (at == pimv2_group) {
598 ND_PRINT((ndo, "(0x%02x)", bp[0]));
600 ND_PRINT((ndo, "(%s%s%s",
601 bp[0] & 0x04 ? "S" : "",
602 bp[0] & 0x02 ? "W" : "",
603 bp[0] & 0x01 ? "R" : ""));
605 ND_PRINT((ndo, "+0x%02x", bp[0] & 0xf8));
607 ND_PRINT((ndo, ")"));
610 return hdrlen + 2 + len;
618 enum checksum_status {
624 static enum checksum_status
625 pimv2_check_checksum(netdissect_options *ndo, const u_char *bp,
626 const u_char *bp2, u_int len)
631 if (!ND_TTEST2(bp[0], len)) {
632 /* We don't have all the data. */
635 ip = (const struct ip *)bp2;
637 struct cksum_vec vec[1];
641 cksum = in_cksum(vec, 1);
642 return (cksum ? INCORRECT : CORRECT);
643 } else if (IP_V(ip) == 6) {
644 const struct ip6_hdr *ip6;
646 ip6 = (const struct ip6_hdr *)bp2;
647 cksum = nextproto6_cksum(ndo, ip6, bp, len, len, IPPROTO_PIM);
648 return (cksum ? INCORRECT : CORRECT);
655 pimv2_print(netdissect_options *ndo,
656 register const u_char *bp, register u_int len, const u_char *bp2)
658 register const u_char *ep;
659 register const struct pim *pim = (const struct pim *)bp;
661 enum checksum_status cksum_status;
663 ep = (const u_char *)ndo->ndo_snapend;
668 ND_TCHECK(pim->pim_rsv);
669 pimv2_addr_len = pim->pim_rsv;
670 if (pimv2_addr_len != 0)
671 ND_PRINT((ndo, ", RFC2117-encoding"));
673 ND_PRINT((ndo, ", cksum 0x%04x ", EXTRACT_16BITS(&pim->pim_cksum)));
674 if (EXTRACT_16BITS(&pim->pim_cksum) == 0) {
675 ND_PRINT((ndo, "(unverified)"));
677 if (PIM_TYPE(pim->pim_typever) == PIMV2_TYPE_REGISTER) {
679 * The checksum only covers the packet header,
680 * not the encapsulated packet.
682 cksum_status = pimv2_check_checksum(ndo, bp, bp2, 8);
683 if (cksum_status == INCORRECT) {
685 * To quote RFC 4601, "For interoperability
686 * reasons, a message carrying a checksum
687 * calculated over the entire PIM Register
688 * message should also be accepted."
690 cksum_status = pimv2_check_checksum(ndo, bp, bp2, len);
694 * The checksum covers the entire packet.
696 cksum_status = pimv2_check_checksum(ndo, bp, bp2, len);
698 switch (cksum_status) {
701 ND_PRINT((ndo, "(correct)"));
705 ND_PRINT((ndo, "(incorrect)"));
709 ND_PRINT((ndo, "(unverified)"));
714 switch (PIM_TYPE(pim->pim_typever)) {
715 case PIMV2_TYPE_HELLO:
717 uint16_t otype, olen;
720 ND_TCHECK2(bp[0], 4);
721 otype = EXTRACT_16BITS(&bp[0]);
722 olen = EXTRACT_16BITS(&bp[2]);
723 ND_TCHECK2(bp[0], 4 + olen);
724 ND_PRINT((ndo, "\n\t %s Option (%u), length %u, Value: ",
725 tok2str(pimv2_hello_option_values, "Unknown", otype),
731 case PIMV2_HELLO_OPTION_HOLDTIME:
732 unsigned_relts_print(ndo, EXTRACT_16BITS(bp));
735 case PIMV2_HELLO_OPTION_LANPRUNEDELAY:
737 ND_PRINT((ndo, "ERROR: Option Length != 4 Bytes (%u)", olen));
740 uint16_t lan_delay, override_interval;
741 lan_delay = EXTRACT_16BITS(bp);
742 override_interval = EXTRACT_16BITS(bp+2);
743 t_bit = (lan_delay & 0x8000)? 1 : 0;
744 lan_delay &= ~0x8000;
745 ND_PRINT((ndo, "\n\t T-bit=%d, LAN delay %dms, Override interval %dms",
746 t_bit, lan_delay, override_interval));
750 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD:
751 case PIMV2_HELLO_OPTION_DR_PRIORITY:
754 ND_PRINT((ndo, "Bi-Directional Capability (Old)"));
757 ND_PRINT((ndo, "%u", EXTRACT_32BITS(bp)));
760 ND_PRINT((ndo, "ERROR: Option Length != 4 Bytes (%u)", olen));
765 case PIMV2_HELLO_OPTION_GENID:
766 ND_PRINT((ndo, "0x%08x", EXTRACT_32BITS(bp)));
769 case PIMV2_HELLO_OPTION_REFRESH_CAP:
770 ND_PRINT((ndo, "v%d", *bp));
772 ND_PRINT((ndo, ", interval "));
773 unsigned_relts_print(ndo, *(bp+1));
775 if (EXTRACT_16BITS(bp+2) != 0) {
776 ND_PRINT((ndo, " ?0x%04x?", EXTRACT_16BITS(bp+2)));
780 case PIMV2_HELLO_OPTION_BIDIR_CAP:
783 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD:
784 case PIMV2_HELLO_OPTION_ADDRESS_LIST:
785 if (ndo->ndo_vflag > 1) {
786 const u_char *ptr = bp;
787 while (ptr < (bp+olen)) {
788 ND_PRINT((ndo, "\n\t "));
789 advance = pimv2_addr_print(ndo, ptr, pimv2_unicast, 0);
791 ND_PRINT((ndo, "..."));
799 if (ndo->ndo_vflag <= 1)
800 print_unknown_data(ndo, bp, "\n\t ", olen);
803 /* do we want to see an additionally hexdump ? */
804 if (ndo->ndo_vflag> 1)
805 print_unknown_data(ndo, bp, "\n\t ", olen);
811 case PIMV2_TYPE_REGISTER:
815 ND_TCHECK2(*(bp + 4), PIMV2_REGISTER_FLAG_LEN);
817 ND_PRINT((ndo, ", Flags [ %s ]\n\t",
818 tok2str(pimv2_register_flag_values,
820 EXTRACT_32BITS(bp+4))));
823 /* encapsulated multicast packet */
824 ip = (const struct ip *)bp;
826 case 0: /* Null header */
827 ND_PRINT((ndo, "IP-Null-header %s > %s",
828 ipaddr_string(ndo, &ip->ip_src),
829 ipaddr_string(ndo, &ip->ip_dst)));
833 ip_print(ndo, bp, len);
837 ip6_print(ndo, bp, len);
841 ND_PRINT((ndo, "IP ver %d", IP_V(ip)));
847 case PIMV2_TYPE_REGISTER_STOP:
851 ND_PRINT((ndo, " group="));
852 if ((advance = pimv2_addr_print(ndo, bp, pimv2_group, 0)) < 0) {
853 ND_PRINT((ndo, "..."));
856 bp += advance; len -= advance;
859 ND_PRINT((ndo, " source="));
860 if ((advance = pimv2_addr_print(ndo, bp, pimv2_unicast, 0)) < 0) {
861 ND_PRINT((ndo, "..."));
864 bp += advance; len -= advance;
867 case PIMV2_TYPE_JOIN_PRUNE:
868 case PIMV2_TYPE_GRAFT:
869 case PIMV2_TYPE_GRAFT_ACK:
874 * 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
875 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
876 * |PIM Ver| Type | Addr length | Checksum |
877 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
878 * | Unicast-Upstream Neighbor Address |
879 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
880 * | Reserved | Num groups | Holdtime |
881 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
882 * | Encoded-Multicast Group Address-1 |
883 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
884 * | Number of Joined Sources | Number of Pruned Sources |
885 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
886 * | Encoded-Joined Source Address-1 |
887 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
890 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
891 * | Encoded-Joined Source Address-n |
892 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
893 * | Encoded-Pruned Source Address-1 |
894 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
897 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
898 * | Encoded-Pruned Source Address-n |
899 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
902 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
903 * | Encoded-Multicast Group Address-n |
904 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
915 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
918 ND_PRINT((ndo, ", upstream-neighbor: "));
919 if ((advance = pimv2_addr_print(ndo, bp, pimv2_unicast, 0)) < 0) {
920 ND_PRINT((ndo, "..."));
923 bp += advance; len -= advance;
928 holdtime = EXTRACT_16BITS(&bp[2]);
929 ND_PRINT((ndo, "\n\t %u group(s)", ngroup));
930 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
931 ND_PRINT((ndo, ", holdtime: "));
932 if (holdtime == 0xffff)
933 ND_PRINT((ndo, "infinite"));
935 unsigned_relts_print(ndo, holdtime);
938 for (i = 0; i < ngroup; i++) {
941 ND_PRINT((ndo, "\n\t group #%u: ", i+1));
942 if ((advance = pimv2_addr_print(ndo, bp, pimv2_group, 0)) < 0) {
943 ND_PRINT((ndo, "...)"));
946 bp += advance; len -= advance;
948 ND_PRINT((ndo, "...)"));
951 njoin = EXTRACT_16BITS(&bp[0]);
952 nprune = EXTRACT_16BITS(&bp[2]);
953 ND_PRINT((ndo, ", joined sources: %u, pruned sources: %u", njoin, nprune));
955 for (j = 0; j < njoin; j++) {
956 ND_PRINT((ndo, "\n\t joined source #%u: ", j+1));
957 if ((advance = pimv2_addr_print(ndo, bp, pimv2_source, 0)) < 0) {
958 ND_PRINT((ndo, "...)"));
961 bp += advance; len -= advance;
963 for (j = 0; j < nprune; j++) {
964 ND_PRINT((ndo, "\n\t pruned source #%u: ", j+1));
965 if ((advance = pimv2_addr_print(ndo, bp, pimv2_source, 0)) < 0) {
966 ND_PRINT((ndo, "...)"));
969 bp += advance; len -= advance;
976 case PIMV2_TYPE_BOOTSTRAP:
981 /* Fragment Tag, Hash Mask len, and BSR-priority */
982 if (bp + sizeof(uint16_t) >= ep) break;
983 ND_PRINT((ndo, " tag=%x", EXTRACT_16BITS(bp)));
984 bp += sizeof(uint16_t);
986 ND_PRINT((ndo, " hashmlen=%d", bp[0]));
987 if (bp + 1 >= ep) break;
988 ND_PRINT((ndo, " BSRprio=%d", bp[1]));
991 /* Encoded-Unicast-BSR-Address */
993 ND_PRINT((ndo, " BSR="));
994 if ((advance = pimv2_addr_print(ndo, bp, pimv2_unicast, 0)) < 0) {
995 ND_PRINT((ndo, "..."));
1000 for (i = 0; bp < ep; i++) {
1001 /* Encoded-Group Address */
1002 ND_PRINT((ndo, " (group%d: ", i));
1003 if ((advance = pimv2_addr_print(ndo, bp, pimv2_group, 0))
1005 ND_PRINT((ndo, "...)"));
1010 /* RP-Count, Frag RP-Cnt, and rsvd */
1012 ND_PRINT((ndo, "...)"));
1015 ND_PRINT((ndo, " RPcnt=%d", bp[0]));
1017 ND_PRINT((ndo, "...)"));
1020 ND_PRINT((ndo, " FRPcnt=%d", frpcnt = bp[1]));
1023 for (j = 0; j < frpcnt && bp < ep; j++) {
1025 ND_PRINT((ndo, " RP%d=", j));
1026 if ((advance = pimv2_addr_print(ndo, bp,
1029 ND_PRINT((ndo, "...)"));
1035 ND_PRINT((ndo, "...)"));
1038 ND_PRINT((ndo, ",holdtime="));
1039 unsigned_relts_print(ndo, EXTRACT_16BITS(bp));
1041 ND_PRINT((ndo, "...)"));
1044 ND_PRINT((ndo, ",prio=%d", bp[2]));
1047 ND_PRINT((ndo, ")"));
1052 case PIMV2_TYPE_ASSERT:
1056 ND_PRINT((ndo, " group="));
1057 if ((advance = pimv2_addr_print(ndo, bp, pimv2_group, 0)) < 0) {
1058 ND_PRINT((ndo, "..."));
1061 bp += advance; len -= advance;
1064 ND_PRINT((ndo, " src="));
1065 if ((advance = pimv2_addr_print(ndo, bp, pimv2_unicast, 0)) < 0) {
1066 ND_PRINT((ndo, "..."));
1069 bp += advance; len -= advance;
1073 ND_PRINT((ndo, " RPT"));
1074 ND_PRINT((ndo, " pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff));
1075 ND_PRINT((ndo, " metric=%u", EXTRACT_32BITS(&bp[4])));
1078 case PIMV2_TYPE_CANDIDATE_RP:
1083 /* Prefix-Cnt, Priority, and Holdtime */
1084 if (bp >= ep) break;
1085 ND_PRINT((ndo, " prefix-cnt=%d", bp[0]));
1087 if (bp + 1 >= ep) break;
1088 ND_PRINT((ndo, " prio=%d", bp[1]));
1089 if (bp + 3 >= ep) break;
1090 ND_PRINT((ndo, " holdtime="));
1091 unsigned_relts_print(ndo, EXTRACT_16BITS(&bp[2]));
1094 /* Encoded-Unicast-RP-Address */
1095 if (bp >= ep) break;
1096 ND_PRINT((ndo, " RP="));
1097 if ((advance = pimv2_addr_print(ndo, bp, pimv2_unicast, 0)) < 0) {
1098 ND_PRINT((ndo, "..."));
1103 /* Encoded-Group Addresses */
1104 for (i = 0; i < pfxcnt && bp < ep; i++) {
1105 ND_PRINT((ndo, " Group%d=", i));
1106 if ((advance = pimv2_addr_print(ndo, bp, pimv2_group, 0))
1108 ND_PRINT((ndo, "..."));
1116 case PIMV2_TYPE_PRUNE_REFRESH:
1117 ND_PRINT((ndo, " src="));
1118 if ((advance = pimv2_addr_print(ndo, bp, pimv2_unicast, 0)) < 0) {
1119 ND_PRINT((ndo, "..."));
1123 ND_PRINT((ndo, " grp="));
1124 if ((advance = pimv2_addr_print(ndo, bp, pimv2_group, 0)) < 0) {
1125 ND_PRINT((ndo, "..."));
1129 ND_PRINT((ndo, " forwarder="));
1130 if ((advance = pimv2_addr_print(ndo, bp, pimv2_unicast, 0)) < 0) {
1131 ND_PRINT((ndo, "..."));
1135 ND_TCHECK2(bp[0], 2);
1136 ND_PRINT((ndo, " TUNR "));
1137 unsigned_relts_print(ndo, EXTRACT_16BITS(bp));
1142 ND_PRINT((ndo, " [type %d]", PIM_TYPE(pim->pim_typever)));
1149 ND_PRINT((ndo, "[|pim]"));
1154 * c-style: whitesmith