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);
310 if ((bp
[4] >> 4) != 1)
311 ND_PRINT((ndo
, " [v%d]", bp
[4] >> 4));
315 ND_PRINT((ndo
, "[|pim]"));
320 * auto-RP is a cisco protocol, documented at
321 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
323 * This implements version 1+, dated Sept 9, 1998.
326 cisco_autorp_print(netdissect_options
*ndo
,
327 register const u_char
*bp
, register u_int len
)
334 ND_PRINT((ndo
, " auto-rp "));
338 ND_PRINT((ndo
, "candidate-advert"));
341 ND_PRINT((ndo
, "mapping"));
344 ND_PRINT((ndo
, "type-0x%02x", type
));
351 ND_TCHECK2(bp
[2], 2);
352 ND_PRINT((ndo
, " Hold "));
353 hold
= EXTRACT_16BITS(&bp
[2]);
355 unsigned_relts_print(ndo
, EXTRACT_16BITS(&bp
[2]));
357 ND_PRINT((ndo
, "FOREVER"));
359 /* Next 4 bytes are reserved. */
363 /*XXX skip unless -v? */
367 * numrps entries of the form:
370 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
371 * 8 bits: # of entries for this RP
372 * each entry: 7 bits: reserved, 1 bit: negative,
373 * 8 bits: mask 32 bits: source
374 * lather, rinse, repeat.
380 ND_TCHECK2(bp
[0], 4);
381 ND_PRINT((ndo
, " RP %s", ipaddr_string(ndo
, bp
)));
383 switch (bp
[4] & 0x3) {
384 case 0: ND_PRINT((ndo
, " PIMv?"));
386 case 1: ND_PRINT((ndo
, " PIMv1"));
388 case 2: ND_PRINT((ndo
, " PIMv2"));
390 case 3: ND_PRINT((ndo
, " PIMv1+2"));
394 ND_PRINT((ndo
, " [rsvd=0x%02x]", bp
[4] & 0xfc));
399 for (; nentries
; nentries
--) {
400 ND_TCHECK2(bp
[0], 6);
401 ND_PRINT((ndo
, "%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
402 ipaddr_string(ndo
, &bp
[2]), bp
[1]));
404 ND_PRINT((ndo
, " bidir"));
407 ND_PRINT((ndo
, "[rsvd=0x%02x]", bp
[0] & 0xfc));
416 ND_PRINT((ndo
, "[|autorp]"));
421 pim_print(netdissect_options
*ndo
,
422 register const u_char
*bp
, register u_int len
, const u_char
*bp2
)
424 register const u_char
*ep
;
425 register const struct pim
*pim
= (const struct pim
*)bp
;
427 ep
= (const u_char
*)ndo
->ndo_snapend
;
430 #ifdef notyet /* currently we see only version and type */
431 ND_TCHECK(pim
->pim_rsv
);
434 switch (PIM_VER(pim
->pim_typever
)) {
436 if (!ndo
->ndo_vflag
) {
437 ND_PRINT((ndo
, "PIMv%u, %s, length %u",
438 PIM_VER(pim
->pim_typever
),
439 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim
->pim_typever
)),
443 ND_PRINT((ndo
, "PIMv%u, length %u\n\t%s",
444 PIM_VER(pim
->pim_typever
),
446 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim
->pim_typever
))));
447 pimv2_print(ndo
, bp
, len
, bp2
);
451 ND_PRINT((ndo
, "PIMv%u, length %u",
452 PIM_VER(pim
->pim_typever
),
460 * PIMv2 uses encoded address representations.
462 * The last PIM-SM I-D before RFC2117 was published specified the
463 * following representation for unicast addresses. However, RFC2117
464 * specified no encoding for unicast addresses with the unicast
465 * address length specified in the header. Therefore, we have to
466 * guess which encoding is being used (Cisco's PIMv2 implementation
467 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
468 * field into a 'unicast-address-length-in-bytes' field. We guess
469 * that it's the draft encoding if this reserved field is zero.
471 * RFC2362 goes back to the encoded format, and calls the addr length
472 * field "reserved" again.
474 * The first byte is the address family, from:
477 * 1 IP (IP version 4)
478 * 2 IP6 (IP version 6)
480 * 4 HDLC (8-bit multidrop)
482 * 6 802 (includes all 802 media plus Ethernet "canonical format")
484 * 8 E.164 (SMDS, Frame Relay, ATM)
486 * 10 X.121 (X.25, Frame Relay)
491 * 15 E.164 with NSAP format subaddress
493 * In addition, the second byte is an "Encoding". 0 is the default
494 * encoding for the address family, and no other encodings are currently
499 static int pimv2_addr_len
;
501 enum pimv2_addrtype
{
502 pimv2_unicast
, pimv2_group
, pimv2_source
506 * 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
507 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
508 * | Addr Family | Encoding Type | Unicast Address |
509 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
511 * 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
512 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
513 * | Addr Family | Encoding Type | Reserved | Mask Len |
514 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
515 * | Group multicast Address |
516 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
518 * 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
519 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
520 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
521 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
523 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
526 pimv2_addr_print(netdissect_options
*ndo
,
527 const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
534 if (pimv2_addr_len
== 0) {
539 len
= sizeof(struct in_addr
);
543 len
= sizeof(struct in6_addr
);
552 switch (pimv2_addr_len
) {
553 case sizeof(struct in_addr
):
556 case sizeof(struct in6_addr
):
563 len
= pimv2_addr_len
;
570 ND_TCHECK2(bp
[0], len
);
573 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, bp
)));
575 else if (af
== AF_INET6
) {
577 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, bp
)));
582 ND_TCHECK2(bp
[0], len
+ 2);
585 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, bp
+ 2)));
587 ND_PRINT((ndo
, "/%u", bp
[1]));
590 else if (af
== AF_INET6
) {
592 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, bp
+ 2)));
594 ND_PRINT((ndo
, "/%u", bp
[1]));
597 if (bp
[0] && !silent
) {
598 if (at
== pimv2_group
) {
599 ND_PRINT((ndo
, "(0x%02x)", bp
[0]));
601 ND_PRINT((ndo
, "(%s%s%s",
602 bp
[0] & 0x04 ? "S" : "",
603 bp
[0] & 0x02 ? "W" : "",
604 bp
[0] & 0x01 ? "R" : ""));
606 ND_PRINT((ndo
, "+0x%02x", bp
[0] & 0xf8));
608 ND_PRINT((ndo
, ")"));
611 return hdrlen
+ 2 + len
;
619 enum checksum_status
{
625 static enum checksum_status
626 pimv2_check_checksum(netdissect_options
*ndo
, const u_char
*bp
,
627 const u_char
*bp2
, u_int len
)
632 if (!ND_TTEST2(bp
[0], len
)) {
633 /* We don't have all the data. */
636 ip
= (const struct ip
*)bp2
;
638 struct cksum_vec vec
[1];
642 cksum
= in_cksum(vec
, 1);
643 return (cksum
? INCORRECT
: CORRECT
);
644 } else if (IP_V(ip
) == 6) {
645 const struct ip6_hdr
*ip6
;
647 ip6
= (const struct ip6_hdr
*)bp2
;
648 cksum
= nextproto6_cksum(ndo
, ip6
, bp
, len
, len
, IPPROTO_PIM
);
649 return (cksum
? INCORRECT
: CORRECT
);
656 pimv2_print(netdissect_options
*ndo
,
657 register const u_char
*bp
, register u_int len
, const u_char
*bp2
)
659 register const u_char
*ep
;
660 register const struct pim
*pim
= (const struct pim
*)bp
;
662 enum checksum_status cksum_status
;
664 ep
= (const u_char
*)ndo
->ndo_snapend
;
669 ND_TCHECK(pim
->pim_rsv
);
670 pimv2_addr_len
= pim
->pim_rsv
;
671 if (pimv2_addr_len
!= 0)
672 ND_PRINT((ndo
, ", RFC2117-encoding"));
674 ND_PRINT((ndo
, ", cksum 0x%04x ", EXTRACT_16BITS(&pim
->pim_cksum
)));
675 if (EXTRACT_16BITS(&pim
->pim_cksum
) == 0) {
676 ND_PRINT((ndo
, "(unverified)"));
678 if (PIM_TYPE(pim
->pim_typever
) == PIMV2_TYPE_REGISTER
) {
680 * The checksum only covers the packet header,
681 * not the encapsulated packet.
683 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, 8);
684 if (cksum_status
== INCORRECT
) {
686 * To quote RFC 4601, "For interoperability
687 * reasons, a message carrying a checksum
688 * calculated over the entire PIM Register
689 * message should also be accepted."
691 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, len
);
695 * The checksum covers the entire packet.
697 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, len
);
699 switch (cksum_status
) {
702 ND_PRINT((ndo
, "(correct)"));
706 ND_PRINT((ndo
, "(incorrect)"));
710 ND_PRINT((ndo
, "(unverified)"));
715 switch (PIM_TYPE(pim
->pim_typever
)) {
716 case PIMV2_TYPE_HELLO
:
718 uint16_t otype
, olen
;
721 ND_TCHECK2(bp
[0], 4);
722 otype
= EXTRACT_16BITS(&bp
[0]);
723 olen
= EXTRACT_16BITS(&bp
[2]);
724 ND_TCHECK2(bp
[0], 4 + olen
);
725 ND_PRINT((ndo
, "\n\t %s Option (%u), length %u, Value: ",
726 tok2str(pimv2_hello_option_values
, "Unknown", otype
),
732 case PIMV2_HELLO_OPTION_HOLDTIME
:
734 ND_PRINT((ndo
, "ERROR: Option Length != 2 Bytes (%u)", olen
));
736 unsigned_relts_print(ndo
, EXTRACT_16BITS(bp
));
740 case PIMV2_HELLO_OPTION_LANPRUNEDELAY
:
742 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
745 uint16_t lan_delay
, override_interval
;
746 lan_delay
= EXTRACT_16BITS(bp
);
747 override_interval
= EXTRACT_16BITS(bp
+2);
748 t_bit
= (lan_delay
& 0x8000)? 1 : 0;
749 lan_delay
&= ~0x8000;
750 ND_PRINT((ndo
, "\n\t T-bit=%d, LAN delay %dms, Override interval %dms",
751 t_bit
, lan_delay
, override_interval
));
755 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
:
756 case PIMV2_HELLO_OPTION_DR_PRIORITY
:
759 ND_PRINT((ndo
, "Bi-Directional Capability (Old)"));
762 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(bp
)));
765 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
770 case PIMV2_HELLO_OPTION_GENID
:
772 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
774 ND_PRINT((ndo
, "0x%08x", EXTRACT_32BITS(bp
)));
778 case PIMV2_HELLO_OPTION_REFRESH_CAP
:
780 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
782 ND_PRINT((ndo
, "v%d", *bp
));
784 ND_PRINT((ndo
, ", interval "));
785 unsigned_relts_print(ndo
, *(bp
+1));
787 if (EXTRACT_16BITS(bp
+2) != 0) {
788 ND_PRINT((ndo
, " ?0x%04x?", EXTRACT_16BITS(bp
+2)));
793 case PIMV2_HELLO_OPTION_BIDIR_CAP
:
796 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
:
797 case PIMV2_HELLO_OPTION_ADDRESS_LIST
:
798 if (ndo
->ndo_vflag
> 1) {
799 const u_char
*ptr
= bp
;
800 while (ptr
< (bp
+olen
)) {
801 ND_PRINT((ndo
, "\n\t "));
802 advance
= pimv2_addr_print(ndo
, ptr
, pimv2_unicast
, 0);
804 ND_PRINT((ndo
, "..."));
812 if (ndo
->ndo_vflag
<= 1)
813 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
816 /* do we want to see an additionally hexdump ? */
817 if (ndo
->ndo_vflag
> 1)
818 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
824 case PIMV2_TYPE_REGISTER
:
828 ND_TCHECK2(*(bp
+ 4), PIMV2_REGISTER_FLAG_LEN
);
830 ND_PRINT((ndo
, ", Flags [ %s ]\n\t",
831 tok2str(pimv2_register_flag_values
,
833 EXTRACT_32BITS(bp
+4))));
836 /* encapsulated multicast packet */
837 ip
= (const struct ip
*)bp
;
839 case 0: /* Null header */
840 ND_PRINT((ndo
, "IP-Null-header %s > %s",
841 ipaddr_string(ndo
, &ip
->ip_src
),
842 ipaddr_string(ndo
, &ip
->ip_dst
)));
846 ip_print(ndo
, bp
, len
);
850 ip6_print(ndo
, bp
, len
);
854 ND_PRINT((ndo
, "IP ver %d", IP_V(ip
)));
860 case PIMV2_TYPE_REGISTER_STOP
:
864 ND_PRINT((ndo
, " group="));
865 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
866 ND_PRINT((ndo
, "..."));
869 bp
+= advance
; len
-= advance
;
872 ND_PRINT((ndo
, " source="));
873 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
874 ND_PRINT((ndo
, "..."));
877 bp
+= advance
; len
-= advance
;
880 case PIMV2_TYPE_JOIN_PRUNE
:
881 case PIMV2_TYPE_GRAFT
:
882 case PIMV2_TYPE_GRAFT_ACK
:
887 * 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
888 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
889 * |PIM Ver| Type | Addr length | Checksum |
890 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
891 * | Unicast-Upstream Neighbor Address |
892 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
893 * | Reserved | Num groups | Holdtime |
894 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
895 * | Encoded-Multicast Group Address-1 |
896 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
897 * | Number of Joined Sources | Number of Pruned Sources |
898 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
899 * | Encoded-Joined Source Address-1 |
900 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
903 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
904 * | Encoded-Joined Source Address-n |
905 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
906 * | Encoded-Pruned Source Address-1 |
907 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
910 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
911 * | Encoded-Pruned Source Address-n |
912 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
915 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
916 * | Encoded-Multicast Group Address-n |
917 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
928 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
931 ND_PRINT((ndo
, ", upstream-neighbor: "));
932 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
933 ND_PRINT((ndo
, "..."));
936 bp
+= advance
; len
-= advance
;
941 holdtime
= EXTRACT_16BITS(&bp
[2]);
942 ND_PRINT((ndo
, "\n\t %u group(s)", ngroup
));
943 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
944 ND_PRINT((ndo
, ", holdtime: "));
945 if (holdtime
== 0xffff)
946 ND_PRINT((ndo
, "infinite"));
948 unsigned_relts_print(ndo
, holdtime
);
951 for (i
= 0; i
< ngroup
; i
++) {
954 ND_PRINT((ndo
, "\n\t group #%u: ", i
+1));
955 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
956 ND_PRINT((ndo
, "...)"));
959 bp
+= advance
; len
-= advance
;
961 ND_PRINT((ndo
, "...)"));
964 njoin
= EXTRACT_16BITS(&bp
[0]);
965 nprune
= EXTRACT_16BITS(&bp
[2]);
966 ND_PRINT((ndo
, ", joined sources: %u, pruned sources: %u", njoin
, nprune
));
968 for (j
= 0; j
< njoin
; j
++) {
969 ND_PRINT((ndo
, "\n\t joined source #%u: ", j
+1));
970 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
971 ND_PRINT((ndo
, "...)"));
974 bp
+= advance
; len
-= advance
;
976 for (j
= 0; j
< nprune
; j
++) {
977 ND_PRINT((ndo
, "\n\t pruned source #%u: ", j
+1));
978 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
979 ND_PRINT((ndo
, "...)"));
982 bp
+= advance
; len
-= advance
;
989 case PIMV2_TYPE_BOOTSTRAP
:
994 /* Fragment Tag, Hash Mask len, and BSR-priority */
995 if (bp
+ sizeof(uint16_t) >= ep
) break;
996 ND_PRINT((ndo
, " tag=%x", EXTRACT_16BITS(bp
)));
997 bp
+= sizeof(uint16_t);
999 ND_PRINT((ndo
, " hashmlen=%d", bp
[0]));
1000 if (bp
+ 1 >= ep
) break;
1001 ND_PRINT((ndo
, " BSRprio=%d", bp
[1]));
1004 /* Encoded-Unicast-BSR-Address */
1005 if (bp
>= ep
) break;
1006 ND_PRINT((ndo
, " BSR="));
1007 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1008 ND_PRINT((ndo
, "..."));
1013 for (i
= 0; bp
< ep
; i
++) {
1014 /* Encoded-Group Address */
1015 ND_PRINT((ndo
, " (group%d: ", i
));
1016 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
1018 ND_PRINT((ndo
, "...)"));
1023 /* RP-Count, Frag RP-Cnt, and rsvd */
1025 ND_PRINT((ndo
, "...)"));
1028 ND_PRINT((ndo
, " RPcnt=%d", bp
[0]));
1030 ND_PRINT((ndo
, "...)"));
1033 ND_PRINT((ndo
, " FRPcnt=%d", frpcnt
= bp
[1]));
1036 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
1038 ND_PRINT((ndo
, " RP%d=", j
));
1039 if ((advance
= pimv2_addr_print(ndo
, bp
,
1042 ND_PRINT((ndo
, "...)"));
1048 ND_PRINT((ndo
, "...)"));
1051 ND_PRINT((ndo
, ",holdtime="));
1052 unsigned_relts_print(ndo
, EXTRACT_16BITS(bp
));
1054 ND_PRINT((ndo
, "...)"));
1057 ND_PRINT((ndo
, ",prio=%d", bp
[2]));
1060 ND_PRINT((ndo
, ")"));
1065 case PIMV2_TYPE_ASSERT
:
1069 ND_PRINT((ndo
, " group="));
1070 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1071 ND_PRINT((ndo
, "..."));
1074 bp
+= advance
; len
-= advance
;
1077 ND_PRINT((ndo
, " src="));
1078 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1079 ND_PRINT((ndo
, "..."));
1082 bp
+= advance
; len
-= advance
;
1086 ND_PRINT((ndo
, " RPT"));
1087 ND_PRINT((ndo
, " pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff));
1088 ND_PRINT((ndo
, " metric=%u", EXTRACT_32BITS(&bp
[4])));
1091 case PIMV2_TYPE_CANDIDATE_RP
:
1096 /* Prefix-Cnt, Priority, and Holdtime */
1097 if (bp
>= ep
) break;
1098 ND_PRINT((ndo
, " prefix-cnt=%d", bp
[0]));
1100 if (bp
+ 1 >= ep
) break;
1101 ND_PRINT((ndo
, " prio=%d", bp
[1]));
1102 if (bp
+ 3 >= ep
) break;
1103 ND_PRINT((ndo
, " holdtime="));
1104 unsigned_relts_print(ndo
, EXTRACT_16BITS(&bp
[2]));
1107 /* Encoded-Unicast-RP-Address */
1108 if (bp
>= ep
) break;
1109 ND_PRINT((ndo
, " RP="));
1110 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1111 ND_PRINT((ndo
, "..."));
1116 /* Encoded-Group Addresses */
1117 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
1118 ND_PRINT((ndo
, " Group%d=", i
));
1119 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
1121 ND_PRINT((ndo
, "..."));
1129 case PIMV2_TYPE_PRUNE_REFRESH
:
1130 ND_PRINT((ndo
, " src="));
1131 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1132 ND_PRINT((ndo
, "..."));
1136 ND_PRINT((ndo
, " grp="));
1137 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1138 ND_PRINT((ndo
, "..."));
1142 ND_PRINT((ndo
, " forwarder="));
1143 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1144 ND_PRINT((ndo
, "..."));
1148 ND_TCHECK2(bp
[0], 2);
1149 ND_PRINT((ndo
, " TUNR "));
1150 unsigned_relts_print(ndo
, EXTRACT_16BITS(bp
));
1155 ND_PRINT((ndo
, " [type %d]", PIM_TYPE(pim
->pim_typever
)));
1162 ND_PRINT((ndo
, "[|pim]"));
1167 * c-style: whitesmith