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
));
200 if (ndo
->ndo_vflag
> 1)
202 ND_PRINT(" Hold time: ");
203 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 2));
204 if (ndo
->ndo_vflag
< 2)
211 ngroups
= GET_U_1(bp
+ 3);
214 while (ngroups
!= 0) {
216 * XXX - does the address have length "addrlen" and the
217 * mask length "maddrlen"?
221 ND_TCHECK_LEN(bp
, sizeof(nd_ipv4
));
222 ND_PRINT("\n\tGroup: %s", GET_IPADDR_STRING(bp
));
227 ND_TCHECK_LEN(bp
, sizeof(nd_ipv4
));
228 if (GET_BE_U_4(bp
) != 0xffffffff)
229 ND_PRINT("/%s", GET_IPADDR_STRING(bp
));
234 njoin
= GET_BE_U_2(bp
);
235 nprune
= GET_BE_U_2(bp
+ 2);
236 ND_PRINT(" joined: %u pruned: %u", njoin
, nprune
);
239 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
248 ND_PRINT("\n\t%s %s%s%s%s/%u", type
,
249 (GET_U_1(bp
) & 0x01) ? "Sparse " : "Dense ",
250 (GET_U_1(bp
+ 1) & 0x80) ? "WC " : "",
251 (GET_U_1(bp
+ 1) & 0x40) ? "RP " : "SPT ",
252 GET_IPADDR_STRING(bp
+ 2),
253 GET_U_1(bp
+ 1) & 0x3f);
266 pimv1_print(netdissect_options
*ndo
,
267 const u_char
*bp
, u_int len
)
271 ndo
->ndo_protocol
= "pimv1";
272 type
= GET_U_1(bp
+ 1);
274 ND_PRINT(" %s", tok2str(pimv1_type_str
, "[type %u]", type
));
276 case PIMV1_TYPE_QUERY
:
277 if (ND_TTEST_1(bp
+ 8)) {
278 switch (GET_U_1(bp
+ 8) >> 4) {
280 ND_PRINT(" Dense-mode");
283 ND_PRINT(" Sparse-mode");
286 ND_PRINT(" Sparse-Dense-mode");
289 ND_PRINT(" mode-%u", GET_U_1(bp
+ 8) >> 4);
293 if (ndo
->ndo_vflag
) {
294 ND_PRINT(" (Hold-time ");
295 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 10));
300 case PIMV1_TYPE_REGISTER
:
301 ND_TCHECK_LEN(bp
+ 8, 20); /* ip header */
302 ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp
+ 20),
303 GET_IPADDR_STRING(bp
+ 24));
305 case PIMV1_TYPE_REGISTER_STOP
:
306 ND_TCHECK_LEN(bp
+ 12, sizeof(nd_ipv4
));
307 ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp
+ 8),
308 GET_IPADDR_STRING(bp
+ 12));
310 case PIMV1_TYPE_RP_REACHABILITY
:
311 if (ndo
->ndo_vflag
) {
312 ND_TCHECK_2(bp
+ 22);
313 ND_PRINT(" group %s", GET_IPADDR_STRING(bp
+ 8));
314 if (GET_BE_U_4(bp
+ 12) != 0xffffffff)
315 ND_PRINT("/%s", GET_IPADDR_STRING(bp
+ 12));
316 ND_PRINT(" RP %s hold ", GET_IPADDR_STRING(bp
+ 16));
317 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 22));
320 case PIMV1_TYPE_ASSERT
:
321 ND_TCHECK_LEN(bp
+ 16, sizeof(nd_ipv4
));
322 ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp
+ 16),
323 GET_IPADDR_STRING(bp
+ 8));
324 if (GET_BE_U_4(bp
+ 12) != 0xffffffff)
325 ND_PRINT("/%s", GET_IPADDR_STRING(bp
+ 12));
326 ND_PRINT(" %s pref %u metric %u",
327 (GET_U_1(bp
+ 20) & 0x80) ? "RP-tree" : "SPT",
328 GET_BE_U_4(bp
+ 20) & 0x7fffffff,
329 GET_BE_U_4(bp
+ 24));
331 case PIMV1_TYPE_JOIN_PRUNE
:
332 case PIMV1_TYPE_GRAFT
:
333 case PIMV1_TYPE_GRAFT_ACK
:
334 if (ndo
->ndo_vflag
) {
337 pimv1_join_prune_print(ndo
, bp
+ 8, len
- 8);
341 if ((GET_U_1(bp
+ 4) >> 4) != 1)
342 ND_PRINT(" [v%u]", GET_U_1(bp
+ 4) >> 4);
351 * auto-RP is a cisco protocol, documented at
352 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
354 * This implements version 1+, dated Sept 9, 1998.
357 cisco_autorp_print(netdissect_options
*ndo
,
358 const u_char
*bp
, u_int len
)
364 ndo
->ndo_protocol
= "cisco_autorp";
367 ND_PRINT(" auto-rp ");
371 ND_PRINT("candidate-advert");
377 ND_PRINT("type-0x%02x", type
);
381 numrps
= GET_U_1(bp
+ 1);
384 hold
= GET_BE_U_2(bp
+ 2);
386 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 2));
390 /* Next 4 bytes are reserved. */
394 /*XXX skip unless -v? */
398 * numrps entries of the form:
401 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
402 * 8 bits: # of entries for this RP
403 * each entry: 7 bits: reserved, 1 bit: negative,
404 * 8 bits: mask 32 bits: source
405 * lather, rinse, repeat.
407 while (numrps
!= 0) {
413 ND_PRINT(" RP %s", GET_IPADDR_STRING(bp
));
418 switch (GET_U_1(bp
) & 0x3) {
419 case 0: ND_PRINT(" PIMv?");
421 case 1: ND_PRINT(" PIMv1");
423 case 2: ND_PRINT(" PIMv2");
425 case 3: ND_PRINT(" PIMv1+2");
428 if (GET_U_1(bp
) & 0xfc)
429 ND_PRINT(" [rsvd=0x%02x]", GET_U_1(bp
) & 0xfc);
434 nentries
= GET_U_1(bp
);
438 while (nentries
!= 0) {
441 ND_PRINT("%c%s%s/%u", s
, GET_U_1(bp
) & 1 ? "!" : "",
442 GET_IPADDR_STRING(bp
+ 2), GET_U_1(bp
+ 1));
443 if (GET_U_1(bp
) & 0x02) {
446 if (GET_U_1(bp
) & 0xfc) {
447 ND_PRINT("[rsvd=0x%02x]", GET_U_1(bp
) & 0xfc);
463 pim_print(netdissect_options
*ndo
,
464 const u_char
*bp
, u_int len
, const u_char
*bp2
)
466 const struct pim
*pim
= (const struct pim
*)bp
;
469 ndo
->ndo_protocol
= "pim";
470 #ifdef notyet /* currently we see only version and type */
471 ND_TCHECK_1(pim
->pim_rsv
);
474 pim_typever
= GET_U_1(pim
->pim_typever
);
475 switch (PIM_VER(pim_typever
)) {
477 if (!ndo
->ndo_vflag
) {
478 ND_PRINT("PIMv%u, %s, length %u",
479 PIM_VER(pim_typever
),
480 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim_typever
)),
484 ND_PRINT("PIMv%u, length %u\n\t%s",
485 PIM_VER(pim_typever
),
487 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim_typever
)));
488 pimv2_print(ndo
, bp
, len
, bp2
);
492 ND_PRINT("PIMv%u, length %u",
493 PIM_VER(pim_typever
),
500 * PIMv2 uses encoded address representations.
502 * The last PIM-SM I-D before RFC2117 was published specified the
503 * following representation for unicast addresses. However, RFC2117
504 * specified no encoding for unicast addresses with the unicast
505 * address length specified in the header. Therefore, we have to
506 * guess which encoding is being used (Cisco's PIMv2 implementation
507 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
508 * field into a 'unicast-address-length-in-bytes' field. We guess
509 * that it's the draft encoding if this reserved field is zero.
511 * RFC2362 goes back to the encoded format, and calls the addr length
512 * field "reserved" again.
514 * The first byte is the address family, from:
517 * 1 IP (IP version 4)
518 * 2 IP6 (IP version 6)
520 * 4 HDLC (8-bit multidrop)
522 * 6 802 (includes all 802 media plus Ethernet "canonical format")
524 * 8 E.164 (SMDS, Frame Relay, ATM)
526 * 10 X.121 (X.25, Frame Relay)
531 * 15 E.164 with NSAP format subaddress
533 * In addition, the second byte is an "Encoding". 0 is the default
534 * encoding for the address family, and no other encodings are currently
539 enum pimv2_addrtype
{
540 pimv2_unicast
, pimv2_group
, pimv2_source
544 * 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
545 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
546 * | Addr Family | Encoding Type | Unicast Address |
547 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
549 * 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
550 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
551 * | Addr Family | Encoding Type | Reserved | Mask Len |
552 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
553 * | Group multicast Address |
554 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
556 * 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
557 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
558 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
559 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
561 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
564 pimv2_addr_print(netdissect_options
*ndo
,
565 const u_char
*bp
, u_int len
, enum pimv2_addrtype at
,
566 u_int addr_len
, int silent
)
574 switch (GET_U_1(bp
)) {
577 addr_len
= (u_int
)sizeof(nd_ipv4
);
581 addr_len
= (u_int
)sizeof(nd_ipv6
);
586 if (GET_U_1(bp
+ 1) != 0)
591 case sizeof(nd_ipv4
):
594 case sizeof(nd_ipv6
):
610 ND_TCHECK_LEN(bp
, addr_len
);
613 ND_PRINT("%s", GET_IPADDR_STRING(bp
));
615 else if (af
== AF_INET6
) {
617 ND_PRINT("%s", GET_IP6ADDR_STRING(bp
));
619 return hdrlen
+ addr_len
;
622 if (len
< addr_len
+ 2)
624 ND_TCHECK_LEN(bp
, addr_len
+ 2);
627 ND_PRINT("%s", GET_IPADDR_STRING(bp
+ 2));
628 if (GET_U_1(bp
+ 1) != 32)
629 ND_PRINT("/%u", GET_U_1(bp
+ 1));
632 else if (af
== AF_INET6
) {
634 ND_PRINT("%s", GET_IP6ADDR_STRING(bp
+ 2));
635 if (GET_U_1(bp
+ 1) != 128)
636 ND_PRINT("/%u", GET_U_1(bp
+ 1));
639 if (GET_U_1(bp
) && !silent
) {
640 if (at
== pimv2_group
) {
641 ND_PRINT("(0x%02x)", GET_U_1(bp
));
644 GET_U_1(bp
) & 0x04 ? "S" : "",
645 GET_U_1(bp
) & 0x02 ? "W" : "",
646 GET_U_1(bp
) & 0x01 ? "R" : "");
647 if (GET_U_1(bp
) & 0xf8) {
654 return hdrlen
+ 2 + addr_len
;
662 enum checksum_status
{
668 static enum checksum_status
669 pimv2_check_checksum(netdissect_options
*ndo
, const u_char
*bp
,
670 const u_char
*bp2
, u_int len
)
675 if (!ND_TTEST_LEN(bp
, len
)) {
676 /* We don't have all the data. */
679 ip
= (const struct ip
*)bp2
;
681 struct cksum_vec vec
[1];
685 cksum
= in_cksum(vec
, 1);
686 return (cksum
? INCORRECT
: CORRECT
);
687 } else if (IP_V(ip
) == 6) {
688 const struct ip6_hdr
*ip6
;
690 ip6
= (const struct ip6_hdr
*)bp2
;
691 cksum
= nextproto6_cksum(ndo
, ip6
, bp
, len
, len
, IPPROTO_PIM
);
692 return (cksum
? INCORRECT
: CORRECT
);
699 pimv2_print(netdissect_options
*ndo
,
700 const u_char
*bp
, u_int len
, const u_char
*bp2
)
702 const struct pim
*pim
= (const struct pim
*)bp
;
705 enum checksum_status cksum_status
;
707 u_int pimv2_addr_len
;
709 ndo
->ndo_protocol
= "pimv2";
711 ND_PRINT("[length %u < 2]", len
);
712 nd_print_invalid(ndo
);
715 pim_typever
= GET_U_1(pim
->pim_typever
);
716 /* RFC5015 allocates the high 4 bits of pim_rsv for "subtype". */
717 pimv2_addr_len
= GET_U_1(pim
->pim_rsv
) & 0x0f;
718 if (pimv2_addr_len
!= 0)
719 ND_PRINT(", RFC2117-encoding");
722 ND_PRINT("[length %u < 4]", len
);
723 nd_print_invalid(ndo
);
726 ND_PRINT(", cksum 0x%04x ", GET_BE_U_2(pim
->pim_cksum
));
727 if (GET_BE_U_2(pim
->pim_cksum
) == 0) {
728 ND_PRINT("(unverified)");
730 if (PIM_TYPE(pim_typever
) == PIMV2_TYPE_REGISTER
) {
732 * The checksum only covers the packet header,
733 * not the encapsulated packet.
735 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, 8);
736 if (cksum_status
== INCORRECT
) {
738 * To quote RFC 4601, "For interoperability
739 * reasons, a message carrying a checksum
740 * calculated over the entire PIM Register
741 * message should also be accepted."
743 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, len
);
747 * The checksum covers the entire packet.
749 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, len
);
751 switch (cksum_status
) {
754 ND_PRINT("(correct)");
758 ND_PRINT("(incorrect)");
762 ND_PRINT("(unverified)");
769 switch (PIM_TYPE(pim_typever
)) {
770 case PIMV2_TYPE_HELLO
:
772 uint16_t otype
, olen
;
776 otype
= GET_BE_U_2(bp
);
777 olen
= GET_BE_U_2(bp
+ 2);
778 ND_PRINT("\n\t %s Option (%u), length %u, Value: ",
779 tok2str(pimv2_hello_option_values
, "Unknown", otype
),
787 ND_TCHECK_LEN(bp
, olen
);
789 case PIMV2_HELLO_OPTION_HOLDTIME
:
791 ND_PRINT("[option length %u != 2]", olen
);
792 nd_print_invalid(ndo
);
795 unsigned_relts_print(ndo
,
800 case PIMV2_HELLO_OPTION_LANPRUNEDELAY
:
802 ND_PRINT("[option length %u != 4]", olen
);
803 nd_print_invalid(ndo
);
807 uint16_t lan_delay
, override_interval
;
808 lan_delay
= GET_BE_U_2(bp
);
809 override_interval
= GET_BE_U_2(bp
+ 2);
810 t_bit
= (lan_delay
& 0x8000)? 1 : 0;
811 lan_delay
&= ~0x8000;
812 ND_PRINT("\n\t T-bit=%u, LAN delay %ums, Override interval %ums",
813 t_bit
, lan_delay
, override_interval
);
817 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
:
818 case PIMV2_HELLO_OPTION_DR_PRIORITY
:
821 ND_PRINT("Bi-Directional Capability (Old)");
824 ND_PRINT("%u", GET_BE_U_4(bp
));
827 ND_PRINT("[option length %u != 4]", olen
);
828 nd_print_invalid(ndo
);
834 case PIMV2_HELLO_OPTION_GENID
:
836 ND_PRINT("[option length %u != 4]", olen
);
837 nd_print_invalid(ndo
);
840 ND_PRINT("0x%08x", GET_BE_U_4(bp
));
844 case PIMV2_HELLO_OPTION_REFRESH_CAP
:
846 ND_PRINT("[option length %u != 4]", olen
);
847 nd_print_invalid(ndo
);
850 ND_PRINT("v%u", GET_U_1(bp
));
851 if (GET_U_1(bp
+ 1) != 0) {
852 ND_PRINT(", interval ");
853 unsigned_relts_print(ndo
,
856 if (GET_BE_U_2(bp
+ 2) != 0) {
857 ND_PRINT(" ?0x%04x?",
863 case PIMV2_HELLO_OPTION_BIDIR_CAP
:
866 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
:
867 case PIMV2_HELLO_OPTION_ADDRESS_LIST
:
868 if (ndo
->ndo_vflag
> 1) {
869 const u_char
*ptr
= bp
;
871 while (ptr
< (bp
+olen
)) {
873 advance
= pimv2_addr_print(ndo
, ptr
, plen
, pimv2_unicast
, pimv2_addr_len
, 0);
882 if (ndo
->ndo_vflag
<= 1)
883 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
886 /* do we want to see an additionally hexdump ? */
887 if (ndo
->ndo_vflag
> 1)
888 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
895 case PIMV2_TYPE_REGISTER
:
901 ND_TCHECK_LEN(bp
, PIMV2_REGISTER_FLAG_LEN
);
903 ND_PRINT(", Flags [ %s ]\n\t",
904 tok2str(pimv2_register_flag_values
,
909 /* encapsulated multicast packet */
912 ip
= (const struct ip
*)bp
;
914 case 0: /* Null header */
915 ND_PRINT("IP-Null-header %s > %s",
916 GET_IPADDR_STRING(ip
->ip_src
),
917 GET_IPADDR_STRING(ip
->ip_dst
));
921 ip_print(ndo
, bp
, len
);
925 ip6_print(ndo
, bp
, len
);
929 ND_PRINT("IP ver %u", IP_V(ip
));
935 case PIMV2_TYPE_REGISTER_STOP
:
937 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
939 bp
+= advance
; len
-= advance
;
940 ND_PRINT(" source=");
941 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
943 bp
+= advance
; len
-= advance
;
946 case PIMV2_TYPE_JOIN_PRUNE
:
947 case PIMV2_TYPE_GRAFT
:
948 case PIMV2_TYPE_GRAFT_ACK
:
953 * 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
954 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
955 * |PIM Ver| Type | Addr length | Checksum |
956 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
957 * | Unicast-Upstream Neighbor Address |
958 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
959 * | Reserved | Num groups | Holdtime |
960 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
961 * | Encoded-Multicast Group Address-1 |
962 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
963 * | Number of Joined Sources | Number of Pruned Sources |
964 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
965 * | Encoded-Joined Source Address-1 |
966 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
969 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
970 * | Encoded-Joined Source Address-n |
971 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
972 * | Encoded-Pruned Source Address-1 |
973 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
976 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
977 * | Encoded-Pruned Source Address-n |
978 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
981 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
982 * | Encoded-Multicast Group Address-n |
983 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
993 if (PIM_TYPE(pim_typever
) != 7) { /*not for Graft-ACK*/
994 ND_PRINT(", upstream-neighbor: ");
995 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
997 bp
+= advance
; len
-= advance
;
1002 ngroup
= GET_U_1(bp
+ 1);
1003 holdtime
= GET_BE_U_2(bp
+ 2);
1004 ND_PRINT("\n\t %u group(s)", ngroup
);
1005 if (PIM_TYPE(pim_typever
) != 7) { /*not for Graft-ACK*/
1006 ND_PRINT(", holdtime: ");
1007 if (holdtime
== 0xffff)
1008 ND_PRINT("infinite");
1010 unsigned_relts_print(ndo
, holdtime
);
1013 for (i
= 0; i
< ngroup
; i
++) {
1014 ND_PRINT("\n\t group #%u: ", i
+1);
1015 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1017 bp
+= advance
; len
-= advance
;
1021 njoin
= GET_BE_U_2(bp
);
1022 nprune
= GET_BE_U_2(bp
+ 2);
1023 ND_PRINT(", joined sources: %u, pruned sources: %u", njoin
, nprune
);
1025 for (j
= 0; j
< njoin
; j
++) {
1026 ND_PRINT("\n\t joined source #%u: ", j
+1);
1027 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_source
, pimv2_addr_len
, 0)) < 0)
1029 bp
+= advance
; len
-= advance
;
1031 for (j
= 0; j
< nprune
; j
++) {
1032 ND_PRINT("\n\t pruned source #%u: ", j
+1);
1033 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_source
, pimv2_addr_len
, 0)) < 0)
1035 bp
+= advance
; len
-= advance
;
1041 case PIMV2_TYPE_BOOTSTRAP
:
1045 /* Fragment Tag, Hash Mask len, and BSR-priority */
1048 ND_PRINT(" tag=%x", GET_BE_U_2(bp
));
1053 ND_PRINT(" hashmlen=%u", GET_U_1(bp
));
1056 ND_TCHECK_1(bp
+ 2);
1057 ND_PRINT(" BSRprio=%u", GET_U_1(bp
+ 1));
1061 /* Encoded-Unicast-BSR-Address */
1063 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1068 for (i
= 0; len
> 0; i
++) {
1069 /* Encoded-Group Address */
1070 ND_PRINT(" (group%u: ", i
);
1071 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1076 /* RP-Count, Frag RP-Cnt, and rsvd */
1079 ND_PRINT(" RPcnt=%u", GET_U_1(bp
));
1082 frpcnt
= GET_U_1(bp
+ 1);
1083 ND_PRINT(" FRPcnt=%u", frpcnt
);
1089 for (j
= 0; j
< frpcnt
&& len
> 0; j
++) {
1091 ND_PRINT(" RP%u=", j
);
1092 if ((advance
= pimv2_addr_print(ndo
, bp
, len
,
1103 ND_PRINT(",holdtime=");
1104 unsigned_relts_print(ndo
,
1108 ND_PRINT(",prio=%u", GET_U_1(bp
+ 2));
1118 case PIMV2_TYPE_ASSERT
:
1119 ND_PRINT(" group=");
1120 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1122 bp
+= advance
; len
-= advance
;
1124 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1126 bp
+= advance
; len
-= advance
;
1130 if (GET_U_1(bp
) & 0x80)
1132 ND_PRINT(" pref=%u", GET_BE_U_4(bp
) & 0x7fffffff);
1133 ND_PRINT(" metric=%u", GET_BE_U_4(bp
+ 4));
1136 case PIMV2_TYPE_CANDIDATE_RP
:
1140 /* Prefix-Cnt, Priority, and Holdtime */
1143 ND_PRINT(" prefix-cnt=%u", GET_U_1(bp
));
1144 pfxcnt
= GET_U_1(bp
);
1147 ND_PRINT(" prio=%u", GET_U_1(bp
+ 1));
1150 ND_PRINT(" holdtime=");
1151 unsigned_relts_print(ndo
, GET_BE_U_2(bp
+ 2));
1155 /* Encoded-Unicast-RP-Address */
1157 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1162 /* Encoded-Group Addresses */
1163 for (i
= 0; i
< pfxcnt
&& len
> 0; i
++) {
1164 ND_PRINT(" Group%u=", i
);
1165 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1173 case PIMV2_TYPE_PRUNE_REFRESH
:
1175 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1180 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_group
, pimv2_addr_len
, 0)) < 0)
1184 ND_PRINT(" forwarder=");
1185 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0)
1192 unsigned_relts_print(ndo
, GET_BE_U_2(bp
));
1195 case PIMV2_TYPE_DF_ELECTION
:
1196 subtype
= PIM_SUBTYPE(GET_U_1(pim
->pim_rsv
));
1197 ND_PRINT("\n\t %s,", tok2str( pimv2_df_election_flag_values
,
1198 "Unknown", subtype
) );
1201 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0) {
1206 ND_PRINT(" sender pref=%u", GET_BE_U_4(bp
) );
1207 ND_PRINT(" sender metric=%u", GET_BE_U_4(bp
+ 4));
1213 case PIMV2_DF_ELECTION_BACKOFF
:
1214 case PIMV2_DF_ELECTION_PASS
:
1215 ND_PRINT("\n\t %s addr=", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype
));
1216 if ((advance
= pimv2_addr_print(ndo
, bp
, len
, pimv2_unicast
, pimv2_addr_len
, 0)) < 0) {
1222 ND_PRINT(" %s pref=%u", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype
), GET_BE_U_4(bp
) );
1223 ND_PRINT(" %s metric=%u", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype
), GET_BE_U_4(bp
+ 4));
1228 if (subtype
== PIMV2_DF_ELECTION_BACKOFF
) {
1229 ND_PRINT(" interval %dms", GET_BE_U_2(bp
));
1239 ND_PRINT(" [type %u]", PIM_TYPE(pim_typever
));
1246 nd_print_trunc(ndo
);