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 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 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 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 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 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
, const u_char
*bp2
, u_int len
)
630 ip
= (const struct ip
*)bp2
;
632 struct cksum_vec vec
[1];
636 cksum
= in_cksum(vec
, 1);
637 return (cksum
? INCORRECT
: CORRECT
);
638 } else if (IP_V(ip
) == 6) {
639 const struct ip6_hdr
*ip6
;
641 ip6
= (const struct ip6_hdr
*)bp2
;
642 cksum
= nextproto6_cksum(ndo
, ip6
, bp
, len
, len
, IPPROTO_PIM
);
643 return (cksum
? INCORRECT
: CORRECT
);
650 pimv2_print(netdissect_options
*ndo
,
651 register const u_char
*bp
, register u_int len
, const u_char
*bp2
)
653 register const u_char
*ep
;
654 register const struct pim
*pim
= (const struct pim
*)bp
;
656 enum checksum_status cksum_status
;
658 ep
= (const u_char
*)ndo
->ndo_snapend
;
663 ND_TCHECK(pim
->pim_rsv
);
664 pimv2_addr_len
= pim
->pim_rsv
;
665 if (pimv2_addr_len
!= 0)
666 ND_PRINT((ndo
, ", RFC2117-encoding"));
668 ND_PRINT((ndo
, ", cksum 0x%04x ", EXTRACT_16BITS(&pim
->pim_cksum
)));
669 if (EXTRACT_16BITS(&pim
->pim_cksum
) == 0) {
670 ND_PRINT((ndo
, "(unverified)"));
672 if (PIM_TYPE(pim
->pim_typever
) == PIMV2_TYPE_REGISTER
) {
674 * The checksum only covers the packet header,
675 * not the encapsulated packet.
677 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, 8);
678 if (cksum_status
== INCORRECT
) {
680 * To quote RFC 4601, "For interoperability
681 * reasons, a message carrying a checksum
682 * calculated over the entire PIM Register
683 * message should also be accepted."
685 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, len
);
689 * The checksum covers the entire packet.
691 cksum_status
= pimv2_check_checksum(ndo
, bp
, bp2
, len
);
693 switch (cksum_status
) {
696 ND_PRINT((ndo
, "(correct)"));
700 ND_PRINT((ndo
, "(incorrect)"));
704 ND_PRINT((ndo
, "(unverified)"));
709 switch (PIM_TYPE(pim
->pim_typever
)) {
710 case PIMV2_TYPE_HELLO
:
712 uint16_t otype
, olen
;
715 ND_TCHECK2(bp
[0], 4);
716 otype
= EXTRACT_16BITS(&bp
[0]);
717 olen
= EXTRACT_16BITS(&bp
[2]);
718 ND_TCHECK2(bp
[0], 4 + olen
);
719 ND_PRINT((ndo
, "\n\t %s Option (%u), length %u, Value: ",
720 tok2str(pimv2_hello_option_values
, "Unknown", otype
),
726 case PIMV2_HELLO_OPTION_HOLDTIME
:
727 relts_print(ndo
, EXTRACT_16BITS(bp
));
730 case PIMV2_HELLO_OPTION_LANPRUNEDELAY
:
732 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
735 uint16_t lan_delay
, override_interval
;
736 lan_delay
= EXTRACT_16BITS(bp
);
737 override_interval
= EXTRACT_16BITS(bp
+2);
738 t_bit
= (lan_delay
& 0x8000)? 1 : 0;
739 lan_delay
&= ~0x8000;
740 ND_PRINT((ndo
, "\n\t T-bit=%d, LAN delay %dms, Override interval %dms",
741 t_bit
, lan_delay
, override_interval
));
745 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
:
746 case PIMV2_HELLO_OPTION_DR_PRIORITY
:
749 ND_PRINT((ndo
, "Bi-Directional Capability (Old)"));
752 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(bp
)));
755 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
760 case PIMV2_HELLO_OPTION_GENID
:
761 ND_PRINT((ndo
, "0x%08x", EXTRACT_32BITS(bp
)));
764 case PIMV2_HELLO_OPTION_REFRESH_CAP
:
765 ND_PRINT((ndo
, "v%d", *bp
));
767 ND_PRINT((ndo
, ", interval "));
768 relts_print(ndo
, *(bp
+1));
770 if (EXTRACT_16BITS(bp
+2) != 0) {
771 ND_PRINT((ndo
, " ?0x%04x?", EXTRACT_16BITS(bp
+2)));
775 case PIMV2_HELLO_OPTION_BIDIR_CAP
:
778 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
:
779 case PIMV2_HELLO_OPTION_ADDRESS_LIST
:
780 if (ndo
->ndo_vflag
> 1) {
781 const u_char
*ptr
= bp
;
782 while (ptr
< (bp
+olen
)) {
783 ND_PRINT((ndo
, "\n\t "));
784 advance
= pimv2_addr_print(ndo
, ptr
, pimv2_unicast
, 0);
786 ND_PRINT((ndo
, "..."));
794 if (ndo
->ndo_vflag
<= 1)
795 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
798 /* do we want to see an additionally hexdump ? */
799 if (ndo
->ndo_vflag
> 1)
800 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
806 case PIMV2_TYPE_REGISTER
:
810 ND_TCHECK2(*(bp
+ 4), PIMV2_REGISTER_FLAG_LEN
);
812 ND_PRINT((ndo
, ", Flags [ %s ]\n\t",
813 tok2str(pimv2_register_flag_values
,
815 EXTRACT_32BITS(bp
+4))));
818 /* encapsulated multicast packet */
819 ip
= (const struct ip
*)bp
;
821 case 0: /* Null header */
822 ND_PRINT((ndo
, "IP-Null-header %s > %s",
823 ipaddr_string(ndo
, &ip
->ip_src
),
824 ipaddr_string(ndo
, &ip
->ip_dst
)));
828 ip_print(ndo
, bp
, len
);
832 ip6_print(ndo
, bp
, len
);
836 ND_PRINT((ndo
, "IP ver %d", IP_V(ip
)));
842 case PIMV2_TYPE_REGISTER_STOP
:
846 ND_PRINT((ndo
, " group="));
847 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
848 ND_PRINT((ndo
, "..."));
851 bp
+= advance
; len
-= advance
;
854 ND_PRINT((ndo
, " source="));
855 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
856 ND_PRINT((ndo
, "..."));
859 bp
+= advance
; len
-= advance
;
862 case PIMV2_TYPE_JOIN_PRUNE
:
863 case PIMV2_TYPE_GRAFT
:
864 case PIMV2_TYPE_GRAFT_ACK
:
869 * 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
870 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
871 * |PIM Ver| Type | Addr length | Checksum |
872 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
873 * | Unicast-Upstream Neighbor Address |
874 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
875 * | Reserved | Num groups | Holdtime |
876 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
877 * | Encoded-Multicast Group Address-1 |
878 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
879 * | Number of Joined Sources | Number of Pruned Sources |
880 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
881 * | Encoded-Joined Source Address-1 |
882 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
885 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
886 * | Encoded-Joined Source Address-n |
887 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
888 * | Encoded-Pruned Source Address-1 |
889 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
892 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
893 * | Encoded-Pruned Source Address-n |
894 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
897 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
898 * | Encoded-Multicast Group Address-n |
899 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
910 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
913 ND_PRINT((ndo
, ", upstream-neighbor: "));
914 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
915 ND_PRINT((ndo
, "..."));
918 bp
+= advance
; len
-= advance
;
923 holdtime
= EXTRACT_16BITS(&bp
[2]);
924 ND_PRINT((ndo
, "\n\t %u group(s)", ngroup
));
925 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
926 ND_PRINT((ndo
, ", holdtime: "));
927 if (holdtime
== 0xffff)
928 ND_PRINT((ndo
, "infinite"));
930 relts_print(ndo
, holdtime
);
933 for (i
= 0; i
< ngroup
; i
++) {
936 ND_PRINT((ndo
, "\n\t group #%u: ", i
+1));
937 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
938 ND_PRINT((ndo
, "...)"));
941 bp
+= advance
; len
-= advance
;
943 ND_PRINT((ndo
, "...)"));
946 njoin
= EXTRACT_16BITS(&bp
[0]);
947 nprune
= EXTRACT_16BITS(&bp
[2]);
948 ND_PRINT((ndo
, ", joined sources: %u, pruned sources: %u", njoin
, nprune
));
950 for (j
= 0; j
< njoin
; j
++) {
951 ND_PRINT((ndo
, "\n\t joined source #%u: ", j
+1));
952 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
953 ND_PRINT((ndo
, "...)"));
956 bp
+= advance
; len
-= advance
;
958 for (j
= 0; j
< nprune
; j
++) {
959 ND_PRINT((ndo
, "\n\t pruned source #%u: ", j
+1));
960 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
961 ND_PRINT((ndo
, "...)"));
964 bp
+= advance
; len
-= advance
;
971 case PIMV2_TYPE_BOOTSTRAP
:
976 /* Fragment Tag, Hash Mask len, and BSR-priority */
977 if (bp
+ sizeof(uint16_t) >= ep
) break;
978 ND_PRINT((ndo
, " tag=%x", EXTRACT_16BITS(bp
)));
979 bp
+= sizeof(uint16_t);
981 ND_PRINT((ndo
, " hashmlen=%d", bp
[0]));
982 if (bp
+ 1 >= ep
) break;
983 ND_PRINT((ndo
, " BSRprio=%d", bp
[1]));
986 /* Encoded-Unicast-BSR-Address */
988 ND_PRINT((ndo
, " BSR="));
989 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
990 ND_PRINT((ndo
, "..."));
995 for (i
= 0; bp
< ep
; i
++) {
996 /* Encoded-Group Address */
997 ND_PRINT((ndo
, " (group%d: ", i
));
998 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
1000 ND_PRINT((ndo
, "...)"));
1005 /* RP-Count, Frag RP-Cnt, and rsvd */
1007 ND_PRINT((ndo
, "...)"));
1010 ND_PRINT((ndo
, " RPcnt=%d", bp
[0]));
1012 ND_PRINT((ndo
, "...)"));
1015 ND_PRINT((ndo
, " FRPcnt=%d", frpcnt
= bp
[1]));
1018 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
1020 ND_PRINT((ndo
, " RP%d=", j
));
1021 if ((advance
= pimv2_addr_print(ndo
, bp
,
1024 ND_PRINT((ndo
, "...)"));
1030 ND_PRINT((ndo
, "...)"));
1033 ND_PRINT((ndo
, ",holdtime="));
1034 relts_print(ndo
, EXTRACT_16BITS(bp
));
1036 ND_PRINT((ndo
, "...)"));
1039 ND_PRINT((ndo
, ",prio=%d", bp
[2]));
1042 ND_PRINT((ndo
, ")"));
1047 case PIMV2_TYPE_ASSERT
:
1051 ND_PRINT((ndo
, " group="));
1052 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1053 ND_PRINT((ndo
, "..."));
1056 bp
+= advance
; len
-= advance
;
1059 ND_PRINT((ndo
, " src="));
1060 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1061 ND_PRINT((ndo
, "..."));
1064 bp
+= advance
; len
-= advance
;
1068 ND_PRINT((ndo
, " RPT"));
1069 ND_PRINT((ndo
, " pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff));
1070 ND_PRINT((ndo
, " metric=%u", EXTRACT_32BITS(&bp
[4])));
1073 case PIMV2_TYPE_CANDIDATE_RP
:
1078 /* Prefix-Cnt, Priority, and Holdtime */
1079 if (bp
>= ep
) break;
1080 ND_PRINT((ndo
, " prefix-cnt=%d", bp
[0]));
1082 if (bp
+ 1 >= ep
) break;
1083 ND_PRINT((ndo
, " prio=%d", bp
[1]));
1084 if (bp
+ 3 >= ep
) break;
1085 ND_PRINT((ndo
, " holdtime="));
1086 relts_print(ndo
, EXTRACT_16BITS(&bp
[2]));
1089 /* Encoded-Unicast-RP-Address */
1090 if (bp
>= ep
) break;
1091 ND_PRINT((ndo
, " RP="));
1092 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1093 ND_PRINT((ndo
, "..."));
1098 /* Encoded-Group Addresses */
1099 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
1100 ND_PRINT((ndo
, " Group%d=", i
));
1101 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
1103 ND_PRINT((ndo
, "..."));
1111 case PIMV2_TYPE_PRUNE_REFRESH
:
1112 ND_PRINT((ndo
, " src="));
1113 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1114 ND_PRINT((ndo
, "..."));
1118 ND_PRINT((ndo
, " grp="));
1119 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1120 ND_PRINT((ndo
, "..."));
1124 ND_PRINT((ndo
, " forwarder="));
1125 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1126 ND_PRINT((ndo
, "..."));
1130 ND_TCHECK2(bp
[0], 2);
1131 ND_PRINT((ndo
, " TUNR "));
1132 relts_print(ndo
, EXTRACT_16BITS(bp
));
1137 ND_PRINT((ndo
, " [type %d]", PIM_TYPE(pim
->pim_typever
)));
1144 ND_PRINT((ndo
, "[|pim]"));
1149 * c-style: whitesmith