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" },
121 #define PIMV2_DF_ELECTION_OFFER 1
122 #define PIMV2_DF_ELECTION_WINNER 2
123 #define PIMV2_DF_ELECTION_BACKOFF 3
124 #define PIMV2_DF_ELECTION_PASS 4
126 static const struct tok pimv2_df_election_flag_values
[] = {
127 { PIMV2_DF_ELECTION_OFFER
, "Offer" },
128 { PIMV2_DF_ELECTION_WINNER
, "Winner" },
129 { PIMV2_DF_ELECTION_BACKOFF
, "Backoff" },
130 { PIMV2_DF_ELECTION_PASS
, "Pass" },
134 #define PIMV2_DF_ELECTION_PASS_BACKOFF_STR(x) ( \
135 x == PIMV2_DF_ELECTION_BACKOFF ? "offer" : "new winner" )
139 * XXX: We consider a case where IPv6 is not ready yet for portability,
140 * but PIM dependent defintions should be independent of IPv6...
144 nd_uint8_t pim_typever
;
145 /* upper 4bit: PIM version number; 2 for PIMv2 */
146 /* lower 4bit: the PIM message type, currently they are:
147 * Hello, Register, Register-Stop, Join/Prune,
148 * Bootstrap, Assert, Graft (PIM-DM only),
149 * Graft-Ack (PIM-DM only), C-RP-Adv
151 #define PIM_VER(x) (((x) & 0xf0) >> 4)
152 #define PIM_TYPE(x) ((x) & 0x0f)
153 nd_uint8_t pim_rsv
; /* Reserved in v1, subtype+address length in v2 */
154 #define PIM_SUBTYPE(x) (((x) & 0xf0) >> 4)
155 nd_uint16_t pim_cksum
; /* IP style check sum */
158 static void pimv2_print(netdissect_options
*, const u_char
*bp
, u_int len
, const u_char
*);
161 pimv1_join_prune_print(netdissect_options
*ndo
,
162 const u_char
*bp
, u_int len
)
164 u_int ngroups
, njoin
, nprune
;
167 /* If it's a single group and a single source, use 1-line output. */
168 if (ND_TTEST_LEN(bp
, 30) && GET_U_1(bp
+ 11) == 1 &&
169 ((njoin
= GET_BE_U_2(bp
+ 20)) + GET_BE_U_2(bp
+ 22)) == 1) {
172 ND_PRINT(" RPF %s ", GET_IPADDR_STRING(bp
));
173 hold
= GET_BE_U_2(bp
+ 6);
176 unsigned_relts_print(ndo
, hold
);
178 ND_PRINT("%s (%s/%u, %s", njoin
? "Join" : "Prune",
179 GET_IPADDR_STRING(bp
+ 26), GET_U_1(bp
+ 25) & 0x3f,
180 GET_IPADDR_STRING(bp
+ 12));
181 if (GET_BE_U_4(bp
+ 16) != 0xffffffff)
182 ND_PRINT("/%s", GET_IPADDR_STRING(bp
+ 16));
183 ND_PRINT(") %s%s %s",
184 (GET_U_1(bp
+ 24) & 0x01) ? "Sparse" : "Dense",
185 (GET_U_1(bp
+ 25) & 0x80) ? " WC" : "",
186 (GET_U_1(bp
+ 25) & 0x40) ? "RP" : "SPT");
190 if (len
< sizeof(nd_ipv4
))
192 ND_TCHECK_LEN(bp
, sizeof(nd_ipv4
));
193 if (ndo
->ndo_vflag
> 1)
195 ND_PRINT(" Upstream Nbr: %s", GET_IPADDR_STRING(bp
));
201 if (ndo
->ndo_vflag
> 1)
203 ND_PRINT(" Hold time: ");
204 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 2));
205 if (ndo
->ndo_vflag
< 2)
213 ngroups
= GET_U_1(bp
+ 3);
216 while (ngroups
!= 0) {
218 * XXX - does the address have length "addrlen" and the
219 * mask length "maddrlen"?
223 ND_TCHECK_LEN(bp
, sizeof(nd_ipv4
));
224 ND_PRINT("\n\tGroup: %s", GET_IPADDR_STRING(bp
));
229 ND_TCHECK_LEN(bp
, sizeof(nd_ipv4
));
230 if (GET_BE_U_4(bp
) != 0xffffffff)
231 ND_PRINT("/%s", GET_IPADDR_STRING(bp
));
237 njoin
= GET_BE_U_2(bp
);
238 nprune
= GET_BE_U_2(bp
+ 2);
239 ND_PRINT(" joined: %u pruned: %u", njoin
, nprune
);
242 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
252 ND_PRINT("\n\t%s %s%s%s%s/%u", type
,
253 (GET_U_1(bp
) & 0x01) ? "Sparse " : "Dense ",
254 (GET_U_1(bp
+ 1) & 0x80) ? "WC " : "",
255 (GET_U_1(bp
+ 1) & 0x40) ? "RP " : "SPT ",
256 GET_IPADDR_STRING(bp
+ 2),
257 GET_U_1(bp
+ 1) & 0x3f);
270 pimv1_print(netdissect_options
*ndo
,
271 const u_char
*bp
, u_int len
)
275 ndo
->ndo_protocol
= "pimv1";
277 type
= GET_U_1(bp
+ 1);
279 ND_PRINT(" %s", tok2str(pimv1_type_str
, "[type %u]", type
));
281 case PIMV1_TYPE_QUERY
:
282 if (ND_TTEST_1(bp
+ 8)) {
283 switch (GET_U_1(bp
+ 8) >> 4) {
285 ND_PRINT(" Dense-mode");
288 ND_PRINT(" Sparse-mode");
291 ND_PRINT(" Sparse-Dense-mode");
294 ND_PRINT(" mode-%u", GET_U_1(bp
+ 8) >> 4);
298 if (ndo
->ndo_vflag
) {
299 ND_TCHECK_2(bp
+ 10);
300 ND_PRINT(" (Hold-time ");
301 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 10));
306 case PIMV1_TYPE_REGISTER
:
307 ND_TCHECK_LEN(bp
+ 8, 20); /* ip header */
308 ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp
+ 20),
309 GET_IPADDR_STRING(bp
+ 24));
311 case PIMV1_TYPE_REGISTER_STOP
:
312 ND_TCHECK_LEN(bp
+ 12, sizeof(nd_ipv4
));
313 ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp
+ 8),
314 GET_IPADDR_STRING(bp
+ 12));
316 case PIMV1_TYPE_RP_REACHABILITY
:
317 if (ndo
->ndo_vflag
) {
318 ND_TCHECK_2(bp
+ 22);
319 ND_PRINT(" group %s", GET_IPADDR_STRING(bp
+ 8));
320 if (GET_BE_U_4(bp
+ 12) != 0xffffffff)
321 ND_PRINT("/%s", GET_IPADDR_STRING(bp
+ 12));
322 ND_PRINT(" RP %s hold ", GET_IPADDR_STRING(bp
+ 16));
323 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 22));
326 case PIMV1_TYPE_ASSERT
:
327 ND_TCHECK_LEN(bp
+ 16, sizeof(nd_ipv4
));
328 ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp
+ 16),
329 GET_IPADDR_STRING(bp
+ 8));
330 if (GET_BE_U_4(bp
+ 12) != 0xffffffff)
331 ND_PRINT("/%s", GET_IPADDR_STRING(bp
+ 12));
332 ND_TCHECK_4(bp
+ 24);
333 ND_PRINT(" %s pref %u metric %u",
334 (GET_U_1(bp
+ 20) & 0x80) ? "RP-tree" : "SPT",
335 GET_BE_U_4(bp
+ 20) & 0x7fffffff,
336 GET_BE_U_4(bp
+ 24));
338 case PIMV1_TYPE_JOIN_PRUNE
:
339 case PIMV1_TYPE_GRAFT
:
340 case PIMV1_TYPE_GRAFT_ACK
:
341 if (ndo
->ndo_vflag
) {
344 pimv1_join_prune_print(ndo
, bp
+ 8, len
- 8);
349 if ((GET_U_1(bp
+ 4) >> 4) != 1)
350 ND_PRINT(" [v%u]", GET_U_1(bp
+ 4) >> 4);
359 * auto-RP is a cisco protocol, documented at
360 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
362 * This implements version 1+, dated Sept 9, 1998.
365 cisco_autorp_print(netdissect_options
*ndo
,
366 const u_char
*bp
, u_int len
)
372 ndo
->ndo_protocol
= "cisco_autorp";
376 ND_PRINT(" auto-rp ");
380 ND_PRINT("candidate-advert");
386 ND_PRINT("type-0x%02x", type
);
391 numrps
= GET_U_1(bp
+ 1);
395 hold
= GET_BE_U_2(bp
+ 2);
397 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 2));
401 /* Next 4 bytes are reserved. */
405 /*XXX skip unless -v? */
409 * numrps entries of the form:
412 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
413 * 8 bits: # of entries for this RP
414 * each entry: 7 bits: reserved, 1 bit: negative,
415 * 8 bits: mask 32 bits: source
416 * lather, rinse, repeat.
418 while (numrps
!= 0) {
425 ND_PRINT(" RP %s", GET_IPADDR_STRING(bp
));
431 switch (GET_U_1(bp
) & 0x3) {
432 case 0: ND_PRINT(" PIMv?");
434 case 1: ND_PRINT(" PIMv1");
436 case 2: ND_PRINT(" PIMv2");
438 case 3: ND_PRINT(" PIMv1+2");
441 if (GET_U_1(bp
) & 0xfc)
442 ND_PRINT(" [rsvd=0x%02x]", GET_U_1(bp
) & 0xfc);
448 nentries
= GET_U_1(bp
);
452 while (nentries
!= 0) {
456 ND_PRINT("%c%s%s/%u", s
, GET_U_1(bp
) & 1 ? "!" : "",
457 GET_IPADDR_STRING(bp
+ 2), GET_U_1(bp
+ 1));
458 if (GET_U_1(bp
) & 0x02) {
461 if (GET_U_1(bp
) & 0xfc) {
462 ND_PRINT("[rsvd=0x%02x]", GET_U_1(bp
) & 0xfc);
478 pim_print(netdissect_options
*ndo
,
479 const u_char
*bp
, u_int len
, const u_char
*bp2
)
481 const struct pim
*pim
= (const struct pim
*)bp
;
484 ndo
->ndo_protocol
= "pim";
485 #ifdef notyet /* currently we see only version and type */
486 ND_TCHECK_1(pim
->pim_rsv
);
489 ND_TCHECK_1(pim
->pim_typever
);
490 pim_typever
= GET_U_1(pim
->pim_typever
);
491 switch (PIM_VER(pim_typever
)) {
493 if (!ndo
->ndo_vflag
) {
494 ND_PRINT("PIMv%u, %s, length %u",
495 PIM_VER(pim_typever
),
496 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim_typever
)),
500 ND_PRINT("PIMv%u, length %u\n\t%s",
501 PIM_VER(pim_typever
),
503 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim_typever
)));
504 pimv2_print(ndo
, bp
, len
, bp2
);
508 ND_PRINT("PIMv%u, length %u",
509 PIM_VER(pim_typever
),
521 * PIMv2 uses encoded address representations.
523 * The last PIM-SM I-D before RFC2117 was published specified the
524 * following representation for unicast addresses. However, RFC2117
525 * specified no encoding for unicast addresses with the unicast
526 * address length specified in the header. Therefore, we have to
527 * guess which encoding is being used (Cisco's PIMv2 implementation
528 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
529 * field into a 'unicast-address-length-in-bytes' field. We guess
530 * that it's the draft encoding if this reserved field is zero.
532 * RFC2362 goes back to the encoded format, and calls the addr length
533 * field "reserved" again.
535 * The first byte is the address family, from:
538 * 1 IP (IP version 4)
539 * 2 IP6 (IP version 6)
541 * 4 HDLC (8-bit multidrop)
543 * 6 802 (includes all 802 media plus Ethernet "canonical format")
545 * 8 E.164 (SMDS, Frame Relay, ATM)
547 * 10 X.121 (X.25, Frame Relay)
552 * 15 E.164 with NSAP format subaddress
554 * In addition, the second byte is an "Encoding". 0 is the default
555 * encoding for the address family, and no other encodings are currently
560 enum pimv2_addrtype
{
561 pimv2_unicast
, pimv2_group
, pimv2_source
565 * 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
566 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
567 * | Addr Family | Encoding Type | Unicast Address |
568 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
570 * 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
571 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
572 * | Addr Family | Encoding Type | Reserved | Mask Len |
573 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
574 * | Group multicast Address |
575 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
577 * 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
578 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
579 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
580 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
582 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
585 pimv2_addr_print(netdissect_options
*ndo
,
586 const u_char
*bp
, u_int len
, enum pimv2_addrtype at
,
587 u_int addr_len
, int silent
)
596 switch (GET_U_1(bp
)) {
599 addr_len
= (u_int
)sizeof(nd_ipv4
);
603 addr_len
= (u_int
)sizeof(nd_ipv6
);
608 if (GET_U_1(bp
+ 1) != 0)
613 case sizeof(nd_ipv4
):
616 case sizeof(nd_ipv6
):
632 ND_TCHECK_LEN(bp
, addr_len
);
635 ND_PRINT("%s", GET_IPADDR_STRING(bp
));
637 else if (af
== AF_INET6
) {
639 ND_PRINT("%s", GET_IP6ADDR_STRING(bp
));
641 return hdrlen
+ addr_len
;
644 if (len
< addr_len
+ 2)
646 ND_TCHECK_LEN(bp
, addr_len
+ 2);
649 ND_PRINT("%s", GET_IPADDR_STRING(bp
+ 2));
650 if (GET_U_1(bp
+ 1) != 32)
651 ND_PRINT("/%u", GET_U_1(bp
+ 1));
654 else if (af
== AF_INET6
) {
656 ND_PRINT("%s", GET_IP6ADDR_STRING(bp
+ 2));
657 if (GET_U_1(bp
+ 1) != 128)
658 ND_PRINT("/%u", GET_U_1(bp
+ 1));
661 if (GET_U_1(bp
) && !silent
) {
662 if (at
== pimv2_group
) {
663 ND_PRINT("(0x%02x)", GET_U_1(bp
));
666 GET_U_1(bp
) & 0x04 ? "S" : "",
667 GET_U_1(bp
) & 0x02 ? "W" : "",
668 GET_U_1(bp
) & 0x01 ? "R" : "");
669 if (GET_U_1(bp
) & 0xf8) {
676 return hdrlen
+ 2 + addr_len
;
684 enum checksum_status
{
690 static enum checksum_status
691 pimv2_check_checksum(netdissect_options
*ndo
, const u_char
*bp
,
692 const u_char
*bp2
, u_int len
)
697 if (!ND_TTEST_LEN(bp
, len
)) {
698 /* We don't have all the data. */
701 ip
= (const struct ip
*)bp2
;
703 struct cksum_vec vec
[1];
707 cksum
= in_cksum(vec
, 1);
708 return (cksum
? INCORRECT
: CORRECT
);
709 } else if (IP_V(ip
) == 6) {
710 const struct ip6_hdr
*ip6
;
712 ip6
= (const struct ip6_hdr
*)bp2
;
713 cksum
= nextproto6_cksum(ndo
, ip6
, bp
, len
, len
, IPPROTO_PIM
);
714 return (cksum
? INCORRECT
: CORRECT
);
721 pimv2_print(netdissect_options
*ndo
,
722 const u_char
*bp
, u_int len
, const u_char
*bp2
)
724 const struct pim
*pim
= (const struct pim
*)bp
;
727 enum checksum_status cksum_status
;
729 u_int pimv2_addr_len
;
731 ndo
->ndo_protocol
= "pimv2";
733 ND_PRINT("[length %u < 2]", len
);
734 nd_print_invalid(ndo
);
737 ND_TCHECK_1(pim
->pim_rsv
);
738 pim_typever
= GET_U_1(pim
->pim_typever
);
739 /* RFC5015 allocates the high 4 bits of pim_rsv for "subtype". */
740 pimv2_addr_len
= GET_U_1(pim
->pim_rsv
) & 0x0f;
741 if (pimv2_addr_len
!= 0)
742 ND_PRINT(", RFC2117-encoding");
745 ND_PRINT("[length %u < 4]", len
);
746 nd_print_invalid(ndo
);
749 ND_TCHECK_2(pim
->pim_cksum
);
750 ND_PRINT(", cksum 0x%04x ", GET_BE_U_2(pim
->pim_cksum
));
751 if (GET_BE_U_2(pim
->pim_cksum
) == 0) {
752 ND_PRINT("(unverified)");
754 if (PIM_TYPE(pim_typever
) == PIMV2_TYPE_REGISTER
) {
756 * The checksum only covers the packet header,
757 * not the encapsulated packet.
759 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, 8);
760 if (cksum_status
== INCORRECT
) {
762 * To quote RFC 4601, "For interoperability
763 * reasons, a message carrying a checksum
764 * calculated over the entire PIM Register
765 * message should also be accepted."
767 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, len
);
771 * The checksum covers the entire packet.
773 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, len
);
775 switch (cksum_status
) {
778 ND_PRINT("(correct)");
782 ND_PRINT("(incorrect)");
786 ND_PRINT("(unverified)");
793 switch (PIM_TYPE(pim_typever
)) {
794 case PIMV2_TYPE_HELLO
:
796 uint16_t otype
, olen
;
801 otype
= GET_BE_U_2(bp
);
802 olen
= GET_BE_U_2(bp
+ 2);
803 ND_PRINT("\n\t %s Option (%u), length %u, Value: ",
804 tok2str(pimv2_hello_option_values
, "Unknown", otype
),
812 ND_TCHECK_LEN(bp
, olen
);
814 case PIMV2_HELLO_OPTION_HOLDTIME
:
816 ND_PRINT("[option length %u != 2]", olen
);
817 nd_print_invalid(ndo
);
820 unsigned_relts_print(ndo
,
825 case PIMV2_HELLO_OPTION_LANPRUNEDELAY
:
827 ND_PRINT("[option length %u != 4]", olen
);
828 nd_print_invalid(ndo
);
832 uint16_t lan_delay
, override_interval
;
833 lan_delay
= GET_BE_U_2(bp
);
834 override_interval
= GET_BE_U_2(bp
+ 2);
835 t_bit
= (lan_delay
& 0x8000)? 1 : 0;
836 lan_delay
&= ~0x8000;
837 ND_PRINT("\n\t T-bit=%u, LAN delay %ums, Override interval %ums",
838 t_bit
, lan_delay
, override_interval
);
842 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
:
843 case PIMV2_HELLO_OPTION_DR_PRIORITY
:
846 ND_PRINT("Bi-Directional Capability (Old)");
849 ND_PRINT("%u", GET_BE_U_4(bp
));
852 ND_PRINT("[option length %u != 4]", olen
);
853 nd_print_invalid(ndo
);
859 case PIMV2_HELLO_OPTION_GENID
:
861 ND_PRINT("[option length %u != 4]", olen
);
862 nd_print_invalid(ndo
);
865 ND_PRINT("0x%08x", GET_BE_U_4(bp
));
869 case PIMV2_HELLO_OPTION_REFRESH_CAP
:
871 ND_PRINT("[option length %u != 4]", olen
);
872 nd_print_invalid(ndo
);
875 ND_PRINT("v%u", GET_U_1(bp
));
876 if (GET_U_1(bp
+ 1) != 0) {
877 ND_PRINT(", interval ");
878 unsigned_relts_print(ndo
,
881 if (GET_BE_U_2(bp
+ 2) != 0) {
882 ND_PRINT(" ?0x%04x?",
888 case PIMV2_HELLO_OPTION_BIDIR_CAP
:
891 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
:
892 case PIMV2_HELLO_OPTION_ADDRESS_LIST
:
893 if (ndo
->ndo_vflag
> 1) {
894 const u_char
*ptr
= bp
;
896 while (ptr
< (bp
+olen
)) {
898 advance
= pimv2_addr_print(ndo
, ptr
, plen
, pimv2_unicast
, pimv2_addr_len
, 0);
907 if (ndo
->ndo_vflag
<= 1)
908 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
911 /* do we want to see an additionally hexdump ? */
912 if (ndo
->ndo_vflag
> 1)
913 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
920 case PIMV2_TYPE_REGISTER
:
926 ND_TCHECK_LEN(bp
, PIMV2_REGISTER_FLAG_LEN
);
928 ND_PRINT(", Flags [ %s ]\n\t",
929 tok2str(pimv2_register_flag_values
,
934 /* encapsulated multicast packet */
937 ip
= (const struct ip
*)bp
;
938 ND_TCHECK_1(ip
->ip_vhl
);
940 case 0: /* Null header */
941 ND_TCHECK_4(ip
->ip_dst
);
942 ND_PRINT("IP-Null-header %s > %s",
943 GET_IPADDR_STRING(ip
->ip_src
),
944 GET_IPADDR_STRING(ip
->ip_dst
));
948 ip_print(ndo
, bp
, len
);
952 ip6_print(ndo
, bp
, len
);
956 ND_PRINT("IP ver %u", IP_V(ip
));
962 case PIMV2_TYPE_REGISTER_STOP
:
964 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
966 bp
+= advance
; len
-= advance
;
967 ND_PRINT(" source=");
968 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
970 bp
+= advance
; len
-= advance
;
973 case PIMV2_TYPE_JOIN_PRUNE
:
974 case PIMV2_TYPE_GRAFT
:
975 case PIMV2_TYPE_GRAFT_ACK
:
980 * 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
981 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
982 * |PIM Ver| Type | Addr length | Checksum |
983 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
984 * | Unicast-Upstream Neighbor Address |
985 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
986 * | Reserved | Num groups | Holdtime |
987 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
988 * | Encoded-Multicast Group Address-1 |
989 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
990 * | Number of Joined Sources | Number of Pruned Sources |
991 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
992 * | Encoded-Joined Source Address-1 |
993 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
996 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
997 * | Encoded-Joined Source Address-n |
998 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
999 * | Encoded-Pruned Source Address-1 |
1000 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1003 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1004 * | Encoded-Pruned Source Address-n |
1005 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1008 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1009 * | Encoded-Multicast Group Address-n |
1010 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1020 if (PIM_TYPE(pim_typever
) != 7) { /*not for Graft-ACK*/
1021 ND_PRINT(", upstream-neighbor: ");
1022 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1024 bp
+= advance
; len
-= advance
;
1029 ngroup
= GET_U_1(bp
+ 1);
1030 holdtime
= GET_BE_U_2(bp
+ 2);
1031 ND_PRINT("\n\t %u group(s)", ngroup
);
1032 if (PIM_TYPE(pim_typever
) != 7) { /*not for Graft-ACK*/
1033 ND_PRINT(", holdtime: ");
1034 if (holdtime
== 0xffff)
1035 ND_PRINT("infinite");
1037 unsigned_relts_print(ndo
, holdtime
);
1040 for (i
= 0; i
< ngroup
; i
++) {
1041 ND_PRINT("\n\t group #%u: ", i
+1);
1042 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1044 bp
+= advance
; len
-= advance
;
1048 njoin
= GET_BE_U_2(bp
);
1049 nprune
= GET_BE_U_2(bp
+ 2);
1050 ND_PRINT(", joined sources: %u, pruned sources: %u", njoin
, nprune
);
1052 for (j
= 0; j
< njoin
; j
++) {
1053 ND_PRINT("\n\t joined source #%u: ", j
+1);
1054 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_source
, pimv2_addr_len
, 0)) < 0)
1056 bp
+= advance
; len
-= advance
;
1058 for (j
= 0; j
< nprune
; j
++) {
1059 ND_PRINT("\n\t pruned source #%u: ", j
+1);
1060 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_source
, pimv2_addr_len
, 0)) < 0)
1062 bp
+= advance
; len
-= advance
;
1068 case PIMV2_TYPE_BOOTSTRAP
:
1072 /* Fragment Tag, Hash Mask len, and BSR-priority */
1076 ND_PRINT(" tag=%x", GET_BE_U_2(bp
));
1082 ND_PRINT(" hashmlen=%u", GET_U_1(bp
));
1085 ND_TCHECK_1(bp
+ 2);
1086 ND_PRINT(" BSRprio=%u", GET_U_1(bp
+ 1));
1090 /* Encoded-Unicast-BSR-Address */
1092 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1097 for (i
= 0; len
> 0; i
++) {
1098 /* Encoded-Group Address */
1099 ND_PRINT(" (group%u: ", i
);
1100 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1105 /* RP-Count, Frag RP-Cnt, and rsvd */
1109 ND_PRINT(" RPcnt=%u", GET_U_1(bp
));
1112 ND_TCHECK_1(bp
+ 1);
1113 frpcnt
= GET_U_1(bp
+ 1);
1114 ND_PRINT(" FRPcnt=%u", frpcnt
);
1120 for (j
= 0; j
< frpcnt
&& len
> 0; j
++) {
1122 ND_PRINT(" RP%u=", j
);
1123 if ((advance
= pimv2_addr_print(ndo
, bp
, len
,
1134 ND_PRINT(",holdtime=");
1135 unsigned_relts_print(ndo
,
1139 ND_TCHECK_1(bp
+ 2);
1140 ND_PRINT(",prio=%u", GET_U_1(bp
+ 2));
1150 case PIMV2_TYPE_ASSERT
:
1151 ND_PRINT(" group=");
1152 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1154 bp
+= advance
; len
-= advance
;
1156 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1158 bp
+= advance
; len
-= advance
;
1162 if (GET_U_1(bp
) & 0x80)
1164 ND_PRINT(" pref=%u", GET_BE_U_4(bp
) & 0x7fffffff);
1165 ND_PRINT(" metric=%u", GET_BE_U_4(bp
+ 4));
1168 case PIMV2_TYPE_CANDIDATE_RP
:
1172 /* Prefix-Cnt, Priority, and Holdtime */
1176 ND_PRINT(" prefix-cnt=%u", GET_U_1(bp
));
1177 pfxcnt
= GET_U_1(bp
);
1180 ND_TCHECK_1(bp
+ 1);
1181 ND_PRINT(" prio=%u", GET_U_1(bp
+ 1));
1184 ND_TCHECK_2(bp
+ 2);
1185 ND_PRINT(" holdtime=");
1186 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 2));
1190 /* Encoded-Unicast-RP-Address */
1192 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1197 /* Encoded-Group Addresses */
1198 for (i
= 0; i
< pfxcnt
&& len
> 0; i
++) {
1199 ND_PRINT(" Group%u=", i
);
1200 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1208 case PIMV2_TYPE_PRUNE_REFRESH
:
1210 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1215 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1219 ND_PRINT(" forwarder=");
1220 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1228 unsigned_relts_print(ndo
, GET_BE_U_2(bp
));
1231 case PIMV2_TYPE_DF_ELECTION
:
1232 subtype
= PIM_SUBTYPE(GET_U_1(pim
->pim_rsv
));
1233 ND_PRINT("\n\t %s,", tok2str( pimv2_df_election_flag_values
,
1234 "Unknown", subtype
) );
1237 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0) {
1242 ND_PRINT(" sender pref=%u", GET_BE_U_4(bp
) );
1243 ND_PRINT(" sender metric=%u", GET_BE_U_4(bp
+ 4));
1249 case PIMV2_DF_ELECTION_BACKOFF
:
1250 case PIMV2_DF_ELECTION_PASS
:
1251 ND_PRINT("\n\t %s addr=", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype
));
1252 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0) {
1258 ND_PRINT(" %s pref=%u", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype
), GET_BE_U_4(bp
) );
1259 ND_PRINT(" %s metric=%u", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype
), GET_BE_U_4(bp
+ 4));
1264 if (subtype
== PIMV2_DF_ELECTION_BACKOFF
) {
1265 ND_PRINT(" interval %dms", GET_BE_U_2(bp
));
1275 ND_PRINT(" [type %u]", PIM_TYPE(pim_typever
));
1282 nd_print_trunc(ndo
);