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.
26 #include <netdissect-stdinc.h>
28 #include "netdissect.h"
29 #include "addrtoname.h"
36 #define PIMV1_TYPE_QUERY 0
37 #define PIMV1_TYPE_REGISTER 1
38 #define PIMV1_TYPE_REGISTER_STOP 2
39 #define PIMV1_TYPE_JOIN_PRUNE 3
40 #define PIMV1_TYPE_RP_REACHABILITY 4
41 #define PIMV1_TYPE_ASSERT 5
42 #define PIMV1_TYPE_GRAFT 6
43 #define PIMV1_TYPE_GRAFT_ACK 7
45 static const struct tok pimv1_type_str
[] = {
46 { PIMV1_TYPE_QUERY
, "Query" },
47 { PIMV1_TYPE_REGISTER
, "Register" },
48 { PIMV1_TYPE_REGISTER_STOP
, "Register-Stop" },
49 { PIMV1_TYPE_JOIN_PRUNE
, "Join/Prune" },
50 { PIMV1_TYPE_RP_REACHABILITY
, "RP-reachable" },
51 { PIMV1_TYPE_ASSERT
, "Assert" },
52 { PIMV1_TYPE_GRAFT
, "Graft" },
53 { PIMV1_TYPE_GRAFT_ACK
, "Graft-ACK" },
57 #define PIMV2_TYPE_HELLO 0
58 #define PIMV2_TYPE_REGISTER 1
59 #define PIMV2_TYPE_REGISTER_STOP 2
60 #define PIMV2_TYPE_JOIN_PRUNE 3
61 #define PIMV2_TYPE_BOOTSTRAP 4
62 #define PIMV2_TYPE_ASSERT 5
63 #define PIMV2_TYPE_GRAFT 6
64 #define PIMV2_TYPE_GRAFT_ACK 7
65 #define PIMV2_TYPE_CANDIDATE_RP 8
66 #define PIMV2_TYPE_PRUNE_REFRESH 9
67 #define PIMV2_TYPE_DF_ELECTION 10
68 #define PIMV2_TYPE_ECMP_REDIRECT 11
70 static const struct tok pimv2_type_values
[] = {
71 { PIMV2_TYPE_HELLO
, "Hello" },
72 { PIMV2_TYPE_REGISTER
, "Register" },
73 { PIMV2_TYPE_REGISTER_STOP
, "Register Stop" },
74 { PIMV2_TYPE_JOIN_PRUNE
, "Join / Prune" },
75 { PIMV2_TYPE_BOOTSTRAP
, "Bootstrap" },
76 { PIMV2_TYPE_ASSERT
, "Assert" },
77 { PIMV2_TYPE_GRAFT
, "Graft" },
78 { PIMV2_TYPE_GRAFT_ACK
, "Graft Acknowledgement" },
79 { PIMV2_TYPE_CANDIDATE_RP
, "Candidate RP Advertisement" },
80 { PIMV2_TYPE_PRUNE_REFRESH
, "Prune Refresh" },
81 { PIMV2_TYPE_DF_ELECTION
, "DF Election" },
82 { PIMV2_TYPE_ECMP_REDIRECT
, "ECMP Redirect" },
86 #define PIMV2_HELLO_OPTION_HOLDTIME 1
87 #define PIMV2_HELLO_OPTION_LANPRUNEDELAY 2
88 #define PIMV2_HELLO_OPTION_DR_PRIORITY_OLD 18
89 #define PIMV2_HELLO_OPTION_DR_PRIORITY 19
90 #define PIMV2_HELLO_OPTION_GENID 20
91 #define PIMV2_HELLO_OPTION_REFRESH_CAP 21
92 #define PIMV2_HELLO_OPTION_BIDIR_CAP 22
93 #define PIMV2_HELLO_OPTION_ADDRESS_LIST 24
94 #define PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD 65001
96 static const struct tok pimv2_hello_option_values
[] = {
97 { PIMV2_HELLO_OPTION_HOLDTIME
, "Hold Time" },
98 { PIMV2_HELLO_OPTION_LANPRUNEDELAY
, "LAN Prune Delay" },
99 { PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
, "DR Priority (Old)" },
100 { PIMV2_HELLO_OPTION_DR_PRIORITY
, "DR Priority" },
101 { PIMV2_HELLO_OPTION_GENID
, "Generation ID" },
102 { PIMV2_HELLO_OPTION_REFRESH_CAP
, "State Refresh Capability" },
103 { PIMV2_HELLO_OPTION_BIDIR_CAP
, "Bi-Directional Capability" },
104 { PIMV2_HELLO_OPTION_ADDRESS_LIST
, "Address List" },
105 { PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
, "Address List (Old)" },
109 #define PIMV2_REGISTER_FLAG_LEN 4
110 #define PIMV2_REGISTER_FLAG_BORDER 0x80000000
111 #define PIMV2_REGISTER_FLAG_NULL 0x40000000
113 static const struct tok pimv2_register_flag_values
[] = {
114 { PIMV2_REGISTER_FLAG_BORDER
, "Border" },
115 { PIMV2_REGISTER_FLAG_NULL
, "Null" },
120 * XXX: We consider a case where IPv6 is not ready yet for portability,
121 * but PIM dependent defintions should be independent of IPv6...
126 /* upper 4bit: PIM version number; 2 for PIMv2 */
127 /* lower 4bit: the PIM message type, currently they are:
128 * Hello, Register, Register-Stop, Join/Prune,
129 * Bootstrap, Assert, Graft (PIM-DM only),
130 * Graft-Ack (PIM-DM only), C-RP-Adv
132 #define PIM_VER(x) (((x) & 0xf0) >> 4)
133 #define PIM_TYPE(x) ((x) & 0x0f)
134 u_char pim_rsv
; /* Reserved */
135 u_short pim_cksum
; /* IP style check sum */
138 static void pimv2_print(netdissect_options
*, register const u_char
*bp
, register u_int len
, const u_char
*);
141 pimv1_join_prune_print(netdissect_options
*ndo
,
142 register const u_char
*bp
, register u_int len
)
144 int ngroups
, njoin
, nprune
;
147 /* If it's a single group and a single source, use 1-line output. */
148 if (ND_TTEST2(bp
[0], 30) && bp
[11] == 1 &&
149 ((njoin
= EXTRACT_16BITS(&bp
[20])) + EXTRACT_16BITS(&bp
[22])) == 1) {
152 ND_PRINT((ndo
, " RPF %s ", ipaddr_string(ndo
, bp
)));
153 hold
= EXTRACT_16BITS(&bp
[6]);
155 ND_PRINT((ndo
, "Hold "));
156 relts_print(ndo
, hold
);
158 ND_PRINT((ndo
, "%s (%s/%d, %s", njoin
? "Join" : "Prune",
159 ipaddr_string(ndo
, &bp
[26]), bp
[25] & 0x3f,
160 ipaddr_string(ndo
, &bp
[12])));
161 if (EXTRACT_32BITS(&bp
[16]) != 0xffffffff)
162 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[16])));
163 ND_PRINT((ndo
, ") %s%s %s",
164 (bp
[24] & 0x01) ? "Sparse" : "Dense",
165 (bp
[25] & 0x80) ? " WC" : "",
166 (bp
[25] & 0x40) ? "RP" : "SPT"));
170 ND_TCHECK2(bp
[0], sizeof(struct in_addr
));
171 if (ndo
->ndo_vflag
> 1)
172 ND_PRINT((ndo
, "\n"));
173 ND_PRINT((ndo
, " Upstream Nbr: %s", ipaddr_string(ndo
, bp
)));
174 ND_TCHECK2(bp
[6], 2);
175 if (ndo
->ndo_vflag
> 1)
176 ND_PRINT((ndo
, "\n"));
177 ND_PRINT((ndo
, " Hold time: "));
178 relts_print(ndo
, EXTRACT_16BITS(&bp
[6]));
179 if (ndo
->ndo_vflag
< 2)
184 ND_TCHECK2(bp
[0], 4);
190 * XXX - does the address have length "addrlen" and the
191 * mask length "maddrlen"?
193 ND_TCHECK2(bp
[0], sizeof(struct in_addr
));
194 ND_PRINT((ndo
, "\n\tGroup: %s", ipaddr_string(ndo
, bp
)));
195 ND_TCHECK2(bp
[4], sizeof(struct in_addr
));
196 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
197 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[4])));
198 ND_TCHECK2(bp
[8], 4);
199 njoin
= EXTRACT_16BITS(&bp
[8]);
200 nprune
= EXTRACT_16BITS(&bp
[10]);
201 ND_PRINT((ndo
, " joined: %d pruned: %d", njoin
, nprune
));
204 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
211 ND_TCHECK2(bp
[0], 6);
212 ND_PRINT((ndo
, "\n\t%s %s%s%s%s/%d", type
,
213 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
214 (bp
[1] & 0x80) ? "WC " : "",
215 (bp
[1] & 0x40) ? "RP " : "SPT ",
216 ipaddr_string(ndo
, &bp
[2]), bp
[1] & 0x3f));
223 ND_PRINT((ndo
, "[|pim]"));
228 pimv1_print(netdissect_options
*ndo
,
229 register const u_char
*bp
, register u_int len
)
231 register const u_char
*ep
;
232 register u_char type
;
234 ep
= (const u_char
*)ndo
->ndo_snapend
;
241 ND_PRINT((ndo
, " %s", tok2str(pimv1_type_str
, "[type %u]", type
)));
243 case PIMV1_TYPE_QUERY
:
244 if (ND_TTEST(bp
[8])) {
245 switch (bp
[8] >> 4) {
247 ND_PRINT((ndo
, " Dense-mode"));
250 ND_PRINT((ndo
, " Sparse-mode"));
253 ND_PRINT((ndo
, " Sparse-Dense-mode"));
256 ND_PRINT((ndo
, " mode-%d", bp
[8] >> 4));
260 if (ndo
->ndo_vflag
) {
261 ND_TCHECK2(bp
[10],2);
262 ND_PRINT((ndo
, " (Hold-time "));
263 relts_print(ndo
, EXTRACT_16BITS(&bp
[10]));
264 ND_PRINT((ndo
, ")"));
268 case PIMV1_TYPE_REGISTER
:
269 ND_TCHECK2(bp
[8], 20); /* ip header */
270 ND_PRINT((ndo
, " for %s > %s", ipaddr_string(ndo
, &bp
[20]),
271 ipaddr_string(ndo
, &bp
[24])));
273 case PIMV1_TYPE_REGISTER_STOP
:
274 ND_TCHECK2(bp
[12], sizeof(struct in_addr
));
275 ND_PRINT((ndo
, " for %s > %s", ipaddr_string(ndo
, &bp
[8]),
276 ipaddr_string(ndo
, &bp
[12])));
278 case PIMV1_TYPE_RP_REACHABILITY
:
279 if (ndo
->ndo_vflag
) {
280 ND_TCHECK2(bp
[22], 2);
281 ND_PRINT((ndo
, " group %s", ipaddr_string(ndo
, &bp
[8])));
282 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
283 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[12])));
284 ND_PRINT((ndo
, " RP %s hold ", ipaddr_string(ndo
, &bp
[16])));
285 relts_print(ndo
, EXTRACT_16BITS(&bp
[22]));
288 case PIMV1_TYPE_ASSERT
:
289 ND_TCHECK2(bp
[16], sizeof(struct in_addr
));
290 ND_PRINT((ndo
, " for %s > %s", ipaddr_string(ndo
, &bp
[16]),
291 ipaddr_string(ndo
, &bp
[8])));
292 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
293 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[12])));
294 ND_TCHECK2(bp
[24], 4);
295 ND_PRINT((ndo
, " %s pref %d metric %d",
296 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
297 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
298 EXTRACT_32BITS(&bp
[24])));
300 case PIMV1_TYPE_JOIN_PRUNE
:
301 case PIMV1_TYPE_GRAFT
:
302 case PIMV1_TYPE_GRAFT_ACK
:
304 pimv1_join_prune_print(ndo
, &bp
[8], len
- 8);
307 if ((bp
[4] >> 4) != 1)
308 ND_PRINT((ndo
, " [v%d]", bp
[4] >> 4));
312 ND_PRINT((ndo
, "[|pim]"));
317 * auto-RP is a cisco protocol, documented at
318 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
320 * This implements version 1+, dated Sept 9, 1998.
323 cisco_autorp_print(netdissect_options
*ndo
,
324 register const u_char
*bp
, register u_int len
)
331 ND_PRINT((ndo
, " auto-rp "));
335 ND_PRINT((ndo
, "candidate-advert"));
338 ND_PRINT((ndo
, "mapping"));
341 ND_PRINT((ndo
, "type-0x%02x", type
));
348 ND_TCHECK2(bp
[2], 2);
349 ND_PRINT((ndo
, " Hold "));
350 hold
= EXTRACT_16BITS(&bp
[2]);
352 relts_print(ndo
, EXTRACT_16BITS(&bp
[2]));
354 ND_PRINT((ndo
, "FOREVER"));
356 /* Next 4 bytes are reserved. */
360 /*XXX skip unless -v? */
364 * numrps entries of the form:
367 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
368 * 8 bits: # of entries for this RP
369 * each entry: 7 bits: reserved, 1 bit: negative,
370 * 8 bits: mask 32 bits: source
371 * lather, rinse, repeat.
377 ND_TCHECK2(bp
[0], 4);
378 ND_PRINT((ndo
, " RP %s", ipaddr_string(ndo
, bp
)));
380 switch (bp
[4] & 0x3) {
381 case 0: ND_PRINT((ndo
, " PIMv?"));
383 case 1: ND_PRINT((ndo
, " PIMv1"));
385 case 2: ND_PRINT((ndo
, " PIMv2"));
387 case 3: ND_PRINT((ndo
, " PIMv1+2"));
391 ND_PRINT((ndo
, " [rsvd=0x%02x]", bp
[4] & 0xfc));
396 for (; nentries
; nentries
--) {
397 ND_TCHECK2(bp
[0], 6);
398 ND_PRINT((ndo
, "%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
399 ipaddr_string(ndo
, &bp
[2]), bp
[1]));
401 ND_PRINT((ndo
, " bidir"));
404 ND_PRINT((ndo
, "[rsvd=0x%02x]", bp
[0] & 0xfc));
413 ND_PRINT((ndo
, "[|autorp]"));
418 pim_print(netdissect_options
*ndo
,
419 register const u_char
*bp
, register u_int len
, const u_char
*bp2
)
421 register const u_char
*ep
;
422 register const struct pim
*pim
= (const struct pim
*)bp
;
424 ep
= (const u_char
*)ndo
->ndo_snapend
;
427 #ifdef notyet /* currently we see only version and type */
428 ND_TCHECK(pim
->pim_rsv
);
431 switch (PIM_VER(pim
->pim_typever
)) {
433 if (!ndo
->ndo_vflag
) {
434 ND_PRINT((ndo
, "PIMv%u, %s, length %u",
435 PIM_VER(pim
->pim_typever
),
436 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim
->pim_typever
)),
440 ND_PRINT((ndo
, "PIMv%u, length %u\n\t%s",
441 PIM_VER(pim
->pim_typever
),
443 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim
->pim_typever
))));
444 pimv2_print(ndo
, bp
, len
, bp2
);
448 ND_PRINT((ndo
, "PIMv%u, length %u",
449 PIM_VER(pim
->pim_typever
),
457 * PIMv2 uses encoded address representations.
459 * The last PIM-SM I-D before RFC2117 was published specified the
460 * following representation for unicast addresses. However, RFC2117
461 * specified no encoding for unicast addresses with the unicast
462 * address length specified in the header. Therefore, we have to
463 * guess which encoding is being used (Cisco's PIMv2 implementation
464 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
465 * field into a 'unicast-address-length-in-bytes' field. We guess
466 * that it's the draft encoding if this reserved field is zero.
468 * RFC2362 goes back to the encoded format, and calls the addr length
469 * field "reserved" again.
471 * The first byte is the address family, from:
474 * 1 IP (IP version 4)
475 * 2 IP6 (IP version 6)
477 * 4 HDLC (8-bit multidrop)
479 * 6 802 (includes all 802 media plus Ethernet "canonical format")
481 * 8 E.164 (SMDS, Frame Relay, ATM)
483 * 10 X.121 (X.25, Frame Relay)
488 * 15 E.164 with NSAP format subaddress
490 * In addition, the second byte is an "Encoding". 0 is the default
491 * encoding for the address family, and no other encodings are currently
496 static int pimv2_addr_len
;
498 enum pimv2_addrtype
{
499 pimv2_unicast
, pimv2_group
, pimv2_source
503 * 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
504 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
505 * | Addr Family | Encoding Type | Unicast Address |
506 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
508 * 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
509 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
510 * | Addr Family | Encoding Type | Reserved | Mask Len |
511 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
512 * | Group multicast Address |
513 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
515 * 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
516 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
517 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
518 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
520 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
523 pimv2_addr_print(netdissect_options
*ndo
,
524 const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
531 if (pimv2_addr_len
== 0) {
536 len
= sizeof(struct in_addr
);
540 len
= sizeof(struct in6_addr
);
549 switch (pimv2_addr_len
) {
550 case sizeof(struct in_addr
):
553 case sizeof(struct in6_addr
):
560 len
= pimv2_addr_len
;
567 ND_TCHECK2(bp
[0], len
);
570 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, bp
)));
572 else if (af
== AF_INET6
) {
574 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, bp
)));
579 ND_TCHECK2(bp
[0], len
+ 2);
582 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, bp
+ 2)));
584 ND_PRINT((ndo
, "/%u", bp
[1]));
587 else if (af
== AF_INET6
) {
589 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, bp
+ 2)));
591 ND_PRINT((ndo
, "/%u", bp
[1]));
594 if (bp
[0] && !silent
) {
595 if (at
== pimv2_group
) {
596 ND_PRINT((ndo
, "(0x%02x)", bp
[0]));
598 ND_PRINT((ndo
, "(%s%s%s",
599 bp
[0] & 0x04 ? "S" : "",
600 bp
[0] & 0x02 ? "W" : "",
601 bp
[0] & 0x01 ? "R" : ""));
603 ND_PRINT((ndo
, "+0x%02x", bp
[0] & 0xf8));
605 ND_PRINT((ndo
, ")"));
608 return hdrlen
+ 2 + len
;
616 enum checksum_status
{
622 static enum checksum_status
623 pimv2_check_checksum(const u_char
*bp
, const u_char
*bp2
, u_int len
)
628 ip
= (const struct ip
*)bp2
;
630 struct cksum_vec vec
[1];
634 cksum
= in_cksum(vec
, 1);
635 return (cksum
? INCORRECT
: CORRECT
);
636 } else if (IP_V(ip
) == 6) {
637 const struct ip6_hdr
*ip6
;
639 ip6
= (const struct ip6_hdr
*)bp2
;
640 cksum
= nextproto6_cksum(ip6
, bp
, len
, len
, IPPROTO_PIM
);
641 return (cksum
? INCORRECT
: CORRECT
);
648 pimv2_print(netdissect_options
*ndo
,
649 register const u_char
*bp
, register u_int len
, const u_char
*bp2
)
651 register const u_char
*ep
;
652 register const struct pim
*pim
= (const struct pim
*)bp
;
654 enum checksum_status cksum_status
;
656 ep
= (const u_char
*)ndo
->ndo_snapend
;
661 ND_TCHECK(pim
->pim_rsv
);
662 pimv2_addr_len
= pim
->pim_rsv
;
663 if (pimv2_addr_len
!= 0)
664 ND_PRINT((ndo
, ", RFC2117-encoding"));
666 ND_PRINT((ndo
, ", cksum 0x%04x ", EXTRACT_16BITS(&pim
->pim_cksum
)));
667 if (EXTRACT_16BITS(&pim
->pim_cksum
) == 0) {
668 ND_PRINT((ndo
, "(unverified)"));
670 if (PIM_TYPE(pim
->pim_typever
) == PIMV2_TYPE_REGISTER
) {
672 * The checksum only covers the packet header,
673 * not the encapsulated packet.
675 cksum_status
= pimv2_check_checksum(bp
, bp2
, 8);
676 if (cksum_status
== INCORRECT
) {
678 * To quote RFC 4601, "For interoperability
679 * reasons, a message carrying a checksum
680 * calculated over the entire PIM Register
681 * message should also be accepted."
683 cksum_status
= pimv2_check_checksum(bp
, bp2
, len
);
687 * The checksum covers the entire packet.
689 cksum_status
= pimv2_check_checksum(bp
, bp2
, len
);
691 switch (cksum_status
) {
694 ND_PRINT((ndo
, "(correct)"));
698 ND_PRINT((ndo
, "(incorrect)"));
702 ND_PRINT((ndo
, "(unverified)"));
707 switch (PIM_TYPE(pim
->pim_typever
)) {
708 case PIMV2_TYPE_HELLO
:
710 uint16_t otype
, olen
;
713 ND_TCHECK2(bp
[0], 4);
714 otype
= EXTRACT_16BITS(&bp
[0]);
715 olen
= EXTRACT_16BITS(&bp
[2]);
716 ND_TCHECK2(bp
[0], 4 + olen
);
717 ND_PRINT((ndo
, "\n\t %s Option (%u), length %u, Value: ",
718 tok2str(pimv2_hello_option_values
, "Unknown", otype
),
724 case PIMV2_HELLO_OPTION_HOLDTIME
:
725 relts_print(ndo
, EXTRACT_16BITS(bp
));
728 case PIMV2_HELLO_OPTION_LANPRUNEDELAY
:
730 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
733 uint16_t lan_delay
, override_interval
;
734 lan_delay
= EXTRACT_16BITS(bp
);
735 override_interval
= EXTRACT_16BITS(bp
+2);
736 t_bit
= (lan_delay
& 0x8000)? 1 : 0;
737 lan_delay
&= ~0x8000;
738 ND_PRINT((ndo
, "\n\t T-bit=%d, LAN delay %dms, Override interval %dms",
739 t_bit
, lan_delay
, override_interval
));
743 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
:
744 case PIMV2_HELLO_OPTION_DR_PRIORITY
:
747 ND_PRINT((ndo
, "Bi-Directional Capability (Old)"));
750 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(bp
)));
753 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
758 case PIMV2_HELLO_OPTION_GENID
:
759 ND_PRINT((ndo
, "0x%08x", EXTRACT_32BITS(bp
)));
762 case PIMV2_HELLO_OPTION_REFRESH_CAP
:
763 ND_PRINT((ndo
, "v%d", *bp
));
765 ND_PRINT((ndo
, ", interval "));
766 relts_print(ndo
, *(bp
+1));
768 if (EXTRACT_16BITS(bp
+2) != 0) {
769 ND_PRINT((ndo
, " ?0x%04x?", EXTRACT_16BITS(bp
+2)));
773 case PIMV2_HELLO_OPTION_BIDIR_CAP
:
776 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
:
777 case PIMV2_HELLO_OPTION_ADDRESS_LIST
:
778 if (ndo
->ndo_vflag
> 1) {
779 const u_char
*ptr
= bp
;
780 while (ptr
< (bp
+olen
)) {
781 ND_PRINT((ndo
, "\n\t "));
782 advance
= pimv2_addr_print(ndo
, ptr
, pimv2_unicast
, 0);
784 ND_PRINT((ndo
, "..."));
792 if (ndo
->ndo_vflag
<= 1)
793 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
796 /* do we want to see an additionally hexdump ? */
797 if (ndo
->ndo_vflag
> 1)
798 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
804 case PIMV2_TYPE_REGISTER
:
808 ND_TCHECK2(*(bp
+ 4), PIMV2_REGISTER_FLAG_LEN
);
810 ND_PRINT((ndo
, ", Flags [ %s ]\n\t",
811 tok2str(pimv2_register_flag_values
,
813 EXTRACT_32BITS(bp
+4))));
816 /* encapsulated multicast packet */
817 ip
= (const struct ip
*)bp
;
819 case 0: /* Null header */
820 ND_PRINT((ndo
, "IP-Null-header %s > %s",
821 ipaddr_string(ndo
, &ip
->ip_src
),
822 ipaddr_string(ndo
, &ip
->ip_dst
)));
826 ip_print(ndo
, bp
, len
);
830 ip6_print(ndo
, bp
, len
);
834 ND_PRINT((ndo
, "IP ver %d", IP_V(ip
)));
840 case PIMV2_TYPE_REGISTER_STOP
:
844 ND_PRINT((ndo
, " group="));
845 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
846 ND_PRINT((ndo
, "..."));
849 bp
+= advance
; len
-= advance
;
852 ND_PRINT((ndo
, " source="));
853 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
854 ND_PRINT((ndo
, "..."));
857 bp
+= advance
; len
-= advance
;
860 case PIMV2_TYPE_JOIN_PRUNE
:
861 case PIMV2_TYPE_GRAFT
:
862 case PIMV2_TYPE_GRAFT_ACK
:
867 * 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
868 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
869 * |PIM Ver| Type | Addr length | Checksum |
870 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
871 * | Unicast-Upstream Neighbor Address |
872 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
873 * | Reserved | Num groups | Holdtime |
874 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
875 * | Encoded-Multicast Group Address-1 |
876 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
877 * | Number of Joined Sources | Number of Pruned Sources |
878 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
879 * | Encoded-Joined Source Address-1 |
880 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
883 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
884 * | Encoded-Joined Source Address-n |
885 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
886 * | Encoded-Pruned Source Address-1 |
887 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
890 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
891 * | Encoded-Pruned Source Address-n |
892 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
895 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
896 * | Encoded-Multicast Group Address-n |
897 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
908 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
911 ND_PRINT((ndo
, ", upstream-neighbor: "));
912 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
913 ND_PRINT((ndo
, "..."));
916 bp
+= advance
; len
-= advance
;
921 holdtime
= EXTRACT_16BITS(&bp
[2]);
922 ND_PRINT((ndo
, "\n\t %u group(s)", ngroup
));
923 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
924 ND_PRINT((ndo
, ", holdtime: "));
925 if (holdtime
== 0xffff)
926 ND_PRINT((ndo
, "infinite"));
928 relts_print(ndo
, holdtime
);
931 for (i
= 0; i
< ngroup
; i
++) {
934 ND_PRINT((ndo
, "\n\t group #%u: ", i
+1));
935 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
936 ND_PRINT((ndo
, "...)"));
939 bp
+= advance
; len
-= advance
;
941 ND_PRINT((ndo
, "...)"));
944 njoin
= EXTRACT_16BITS(&bp
[0]);
945 nprune
= EXTRACT_16BITS(&bp
[2]);
946 ND_PRINT((ndo
, ", joined sources: %u, pruned sources: %u", njoin
, nprune
));
948 for (j
= 0; j
< njoin
; j
++) {
949 ND_PRINT((ndo
, "\n\t joined source #%u: ", j
+1));
950 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
951 ND_PRINT((ndo
, "...)"));
954 bp
+= advance
; len
-= advance
;
956 for (j
= 0; j
< nprune
; j
++) {
957 ND_PRINT((ndo
, "\n\t pruned source #%u: ", j
+1));
958 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
959 ND_PRINT((ndo
, "...)"));
962 bp
+= advance
; len
-= advance
;
969 case PIMV2_TYPE_BOOTSTRAP
:
974 /* Fragment Tag, Hash Mask len, and BSR-priority */
975 if (bp
+ sizeof(uint16_t) >= ep
) break;
976 ND_PRINT((ndo
, " tag=%x", EXTRACT_16BITS(bp
)));
977 bp
+= sizeof(uint16_t);
979 ND_PRINT((ndo
, " hashmlen=%d", bp
[0]));
980 if (bp
+ 1 >= ep
) break;
981 ND_PRINT((ndo
, " BSRprio=%d", bp
[1]));
984 /* Encoded-Unicast-BSR-Address */
986 ND_PRINT((ndo
, " BSR="));
987 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
988 ND_PRINT((ndo
, "..."));
993 for (i
= 0; bp
< ep
; i
++) {
994 /* Encoded-Group Address */
995 ND_PRINT((ndo
, " (group%d: ", i
));
996 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
998 ND_PRINT((ndo
, "...)"));
1003 /* RP-Count, Frag RP-Cnt, and rsvd */
1005 ND_PRINT((ndo
, "...)"));
1008 ND_PRINT((ndo
, " RPcnt=%d", bp
[0]));
1010 ND_PRINT((ndo
, "...)"));
1013 ND_PRINT((ndo
, " FRPcnt=%d", frpcnt
= bp
[1]));
1016 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
1018 ND_PRINT((ndo
, " RP%d=", j
));
1019 if ((advance
= pimv2_addr_print(ndo
, bp
,
1022 ND_PRINT((ndo
, "...)"));
1028 ND_PRINT((ndo
, "...)"));
1031 ND_PRINT((ndo
, ",holdtime="));
1032 relts_print(ndo
, EXTRACT_16BITS(bp
));
1034 ND_PRINT((ndo
, "...)"));
1037 ND_PRINT((ndo
, ",prio=%d", bp
[2]));
1040 ND_PRINT((ndo
, ")"));
1045 case PIMV2_TYPE_ASSERT
:
1049 ND_PRINT((ndo
, " group="));
1050 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1051 ND_PRINT((ndo
, "..."));
1054 bp
+= advance
; len
-= advance
;
1057 ND_PRINT((ndo
, " src="));
1058 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1059 ND_PRINT((ndo
, "..."));
1062 bp
+= advance
; len
-= advance
;
1066 ND_PRINT((ndo
, " RPT"));
1067 ND_PRINT((ndo
, " pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff));
1068 ND_PRINT((ndo
, " metric=%u", EXTRACT_32BITS(&bp
[4])));
1071 case PIMV2_TYPE_CANDIDATE_RP
:
1076 /* Prefix-Cnt, Priority, and Holdtime */
1077 if (bp
>= ep
) break;
1078 ND_PRINT((ndo
, " prefix-cnt=%d", bp
[0]));
1080 if (bp
+ 1 >= ep
) break;
1081 ND_PRINT((ndo
, " prio=%d", bp
[1]));
1082 if (bp
+ 3 >= ep
) break;
1083 ND_PRINT((ndo
, " holdtime="));
1084 relts_print(ndo
, EXTRACT_16BITS(&bp
[2]));
1087 /* Encoded-Unicast-RP-Address */
1088 if (bp
>= ep
) break;
1089 ND_PRINT((ndo
, " RP="));
1090 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1091 ND_PRINT((ndo
, "..."));
1096 /* Encoded-Group Addresses */
1097 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
1098 ND_PRINT((ndo
, " Group%d=", i
));
1099 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
1101 ND_PRINT((ndo
, "..."));
1109 case PIMV2_TYPE_PRUNE_REFRESH
:
1110 ND_PRINT((ndo
, " src="));
1111 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1112 ND_PRINT((ndo
, "..."));
1116 ND_PRINT((ndo
, " grp="));
1117 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1118 ND_PRINT((ndo
, "..."));
1122 ND_PRINT((ndo
, " forwarder="));
1123 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1124 ND_PRINT((ndo
, "..."));
1128 ND_TCHECK2(bp
[0], 2);
1129 ND_PRINT((ndo
, " TUNR "));
1130 relts_print(ndo
, EXTRACT_16BITS(bp
));
1135 ND_PRINT((ndo
, " [type %d]", PIM_TYPE(pim
->pim_typever
)));
1142 ND_PRINT((ndo
, "[|pim]"));
1147 * c-style: whitesmith