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 <tcpdump-stdinc.h>
28 #include "netdissect.h"
29 #include "addrtoname.h"
35 #define PIMV1_TYPE_QUERY 0
36 #define PIMV1_TYPE_REGISTER 1
37 #define PIMV1_TYPE_REGISTER_STOP 2
38 #define PIMV1_TYPE_JOIN_PRUNE 3
39 #define PIMV1_TYPE_RP_REACHABILITY 4
40 #define PIMV1_TYPE_ASSERT 5
41 #define PIMV1_TYPE_GRAFT 6
42 #define PIMV1_TYPE_GRAFT_ACK 7
44 static const struct tok pimv1_type_str
[] = {
45 { PIMV1_TYPE_QUERY
, "Query" },
46 { PIMV1_TYPE_REGISTER
, "Register" },
47 { PIMV1_TYPE_REGISTER_STOP
, "Register-Stop" },
48 { PIMV1_TYPE_JOIN_PRUNE
, "Join/Prune" },
49 { PIMV1_TYPE_RP_REACHABILITY
, "RP-reachable" },
50 { PIMV1_TYPE_ASSERT
, "Assert" },
51 { PIMV1_TYPE_GRAFT
, "Graft" },
52 { PIMV1_TYPE_GRAFT_ACK
, "Graft-ACK" },
56 #define PIMV2_TYPE_HELLO 0
57 #define PIMV2_TYPE_REGISTER 1
58 #define PIMV2_TYPE_REGISTER_STOP 2
59 #define PIMV2_TYPE_JOIN_PRUNE 3
60 #define PIMV2_TYPE_BOOTSTRAP 4
61 #define PIMV2_TYPE_ASSERT 5
62 #define PIMV2_TYPE_GRAFT 6
63 #define PIMV2_TYPE_GRAFT_ACK 7
64 #define PIMV2_TYPE_CANDIDATE_RP 8
65 #define PIMV2_TYPE_PRUNE_REFRESH 9
66 #define PIMV2_TYPE_DF_ELECTION 10
67 #define PIMV2_TYPE_ECMP_REDIRECT 11
69 static const struct tok pimv2_type_values
[] = {
70 { PIMV2_TYPE_HELLO
, "Hello" },
71 { PIMV2_TYPE_REGISTER
, "Register" },
72 { PIMV2_TYPE_REGISTER_STOP
, "Register Stop" },
73 { PIMV2_TYPE_JOIN_PRUNE
, "Join / Prune" },
74 { PIMV2_TYPE_BOOTSTRAP
, "Bootstrap" },
75 { PIMV2_TYPE_ASSERT
, "Assert" },
76 { PIMV2_TYPE_GRAFT
, "Graft" },
77 { PIMV2_TYPE_GRAFT_ACK
, "Graft Acknowledgement" },
78 { PIMV2_TYPE_CANDIDATE_RP
, "Candidate RP Advertisement" },
79 { PIMV2_TYPE_PRUNE_REFRESH
, "Prune Refresh" },
80 { PIMV2_TYPE_DF_ELECTION
, "DF Election" },
81 { PIMV2_TYPE_ECMP_REDIRECT
, "ECMP Redirect" },
85 #define PIMV2_HELLO_OPTION_HOLDTIME 1
86 #define PIMV2_HELLO_OPTION_LANPRUNEDELAY 2
87 #define PIMV2_HELLO_OPTION_DR_PRIORITY_OLD 18
88 #define PIMV2_HELLO_OPTION_DR_PRIORITY 19
89 #define PIMV2_HELLO_OPTION_GENID 20
90 #define PIMV2_HELLO_OPTION_REFRESH_CAP 21
91 #define PIMV2_HELLO_OPTION_BIDIR_CAP 22
92 #define PIMV2_HELLO_OPTION_ADDRESS_LIST 24
93 #define PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD 65001
95 static const struct tok pimv2_hello_option_values
[] = {
96 { PIMV2_HELLO_OPTION_HOLDTIME
, "Hold Time" },
97 { PIMV2_HELLO_OPTION_LANPRUNEDELAY
, "LAN Prune Delay" },
98 { PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
, "DR Priority (Old)" },
99 { PIMV2_HELLO_OPTION_DR_PRIORITY
, "DR Priority" },
100 { PIMV2_HELLO_OPTION_GENID
, "Generation ID" },
101 { PIMV2_HELLO_OPTION_REFRESH_CAP
, "State Refresh Capability" },
102 { PIMV2_HELLO_OPTION_BIDIR_CAP
, "Bi-Directional Capability" },
103 { PIMV2_HELLO_OPTION_ADDRESS_LIST
, "Address List" },
104 { PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
, "Address List (Old)" },
108 #define PIMV2_REGISTER_FLAG_LEN 4
109 #define PIMV2_REGISTER_FLAG_BORDER 0x80000000
110 #define PIMV2_REGISTER_FLAG_NULL 0x40000000
112 static const struct tok pimv2_register_flag_values
[] = {
113 { PIMV2_REGISTER_FLAG_BORDER
, "Border" },
114 { PIMV2_REGISTER_FLAG_NULL
, "Null" },
119 * XXX: We consider a case where IPv6 is not ready yet for portability,
120 * but PIM dependent defintions should be independent of IPv6...
125 /* upper 4bit: PIM version number; 2 for PIMv2 */
126 /* lower 4bit: the PIM message type, currently they are:
127 * Hello, Register, Register-Stop, Join/Prune,
128 * Bootstrap, Assert, Graft (PIM-DM only),
129 * Graft-Ack (PIM-DM only), C-RP-Adv
131 #define PIM_VER(x) (((x) & 0xf0) >> 4)
132 #define PIM_TYPE(x) ((x) & 0x0f)
133 u_char pim_rsv
; /* Reserved */
134 u_short pim_cksum
; /* IP style check sum */
137 static void pimv2_print(netdissect_options
*, register const u_char
*bp
, register u_int len
, const u_char
*);
140 pimv1_join_prune_print(netdissect_options
*ndo
,
141 register const u_char
*bp
, register u_int len
)
143 int ngroups
, njoin
, nprune
;
146 /* If it's a single group and a single source, use 1-line output. */
147 if (ND_TTEST2(bp
[0], 30) && bp
[11] == 1 &&
148 ((njoin
= EXTRACT_16BITS(&bp
[20])) + EXTRACT_16BITS(&bp
[22])) == 1) {
151 ND_PRINT((ndo
, " RPF %s ", ipaddr_string(ndo
, bp
)));
152 hold
= EXTRACT_16BITS(&bp
[6]);
154 ND_PRINT((ndo
, "Hold "));
155 relts_print(ndo
, hold
);
157 ND_PRINT((ndo
, "%s (%s/%d, %s", njoin
? "Join" : "Prune",
158 ipaddr_string(ndo
, &bp
[26]), bp
[25] & 0x3f,
159 ipaddr_string(ndo
, &bp
[12])));
160 if (EXTRACT_32BITS(&bp
[16]) != 0xffffffff)
161 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[16])));
162 ND_PRINT((ndo
, ") %s%s %s",
163 (bp
[24] & 0x01) ? "Sparse" : "Dense",
164 (bp
[25] & 0x80) ? " WC" : "",
165 (bp
[25] & 0x40) ? "RP" : "SPT"));
169 ND_TCHECK2(bp
[0], sizeof(struct in_addr
));
170 if (ndo
->ndo_vflag
> 1)
171 ND_PRINT((ndo
, "\n"));
172 ND_PRINT((ndo
, " Upstream Nbr: %s", ipaddr_string(ndo
, bp
)));
173 ND_TCHECK2(bp
[6], 2);
174 if (ndo
->ndo_vflag
> 1)
175 ND_PRINT((ndo
, "\n"));
176 ND_PRINT((ndo
, " Hold time: "));
177 relts_print(ndo
, EXTRACT_16BITS(&bp
[6]));
178 if (ndo
->ndo_vflag
< 2)
183 ND_TCHECK2(bp
[0], 4);
189 * XXX - does the address have length "addrlen" and the
190 * mask length "maddrlen"?
192 ND_TCHECK2(bp
[0], sizeof(struct in_addr
));
193 ND_PRINT((ndo
, "\n\tGroup: %s", ipaddr_string(ndo
, bp
)));
194 ND_TCHECK2(bp
[4], sizeof(struct in_addr
));
195 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
196 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[4])));
197 ND_TCHECK2(bp
[8], 4);
198 njoin
= EXTRACT_16BITS(&bp
[8]);
199 nprune
= EXTRACT_16BITS(&bp
[10]);
200 ND_PRINT((ndo
, " joined: %d pruned: %d", njoin
, nprune
));
203 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
210 ND_TCHECK2(bp
[0], 6);
211 ND_PRINT((ndo
, "\n\t%s %s%s%s%s/%d", type
,
212 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
213 (bp
[1] & 0x80) ? "WC " : "",
214 (bp
[1] & 0x40) ? "RP " : "SPT ",
215 ipaddr_string(ndo
, &bp
[2]), bp
[1] & 0x3f));
222 ND_PRINT((ndo
, "[|pim]"));
227 pimv1_print(netdissect_options
*ndo
,
228 register const u_char
*bp
, register u_int len
)
230 register const u_char
*ep
;
231 register u_char type
;
233 ep
= (const u_char
*)ndo
->ndo_snapend
;
240 ND_PRINT((ndo
, " %s", tok2str(pimv1_type_str
, "[type %u]", type
)));
242 case PIMV1_TYPE_QUERY
:
243 if (ND_TTEST(bp
[8])) {
244 switch (bp
[8] >> 4) {
246 ND_PRINT((ndo
, " Dense-mode"));
249 ND_PRINT((ndo
, " Sparse-mode"));
252 ND_PRINT((ndo
, " Sparse-Dense-mode"));
255 ND_PRINT((ndo
, " mode-%d", bp
[8] >> 4));
259 if (ndo
->ndo_vflag
) {
260 ND_TCHECK2(bp
[10],2);
261 ND_PRINT((ndo
, " (Hold-time "));
262 relts_print(ndo
, EXTRACT_16BITS(&bp
[10]));
263 ND_PRINT((ndo
, ")"));
267 case PIMV1_TYPE_REGISTER
:
268 ND_TCHECK2(bp
[8], 20); /* ip header */
269 ND_PRINT((ndo
, " for %s > %s", ipaddr_string(ndo
, &bp
[20]),
270 ipaddr_string(ndo
, &bp
[24])));
272 case PIMV1_TYPE_REGISTER_STOP
:
273 ND_TCHECK2(bp
[12], sizeof(struct in_addr
));
274 ND_PRINT((ndo
, " for %s > %s", ipaddr_string(ndo
, &bp
[8]),
275 ipaddr_string(ndo
, &bp
[12])));
277 case PIMV1_TYPE_RP_REACHABILITY
:
278 if (ndo
->ndo_vflag
) {
279 ND_TCHECK2(bp
[22], 2);
280 ND_PRINT((ndo
, " group %s", ipaddr_string(ndo
, &bp
[8])));
281 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
282 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[12])));
283 ND_PRINT((ndo
, " RP %s hold ", ipaddr_string(ndo
, &bp
[16])));
284 relts_print(ndo
, EXTRACT_16BITS(&bp
[22]));
287 case PIMV1_TYPE_ASSERT
:
288 ND_TCHECK2(bp
[16], sizeof(struct in_addr
));
289 ND_PRINT((ndo
, " for %s > %s", ipaddr_string(ndo
, &bp
[16]),
290 ipaddr_string(ndo
, &bp
[8])));
291 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
292 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[12])));
293 ND_TCHECK2(bp
[24], 4);
294 ND_PRINT((ndo
, " %s pref %d metric %d",
295 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
296 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
297 EXTRACT_32BITS(&bp
[24])));
299 case PIMV1_TYPE_JOIN_PRUNE
:
300 case PIMV1_TYPE_GRAFT
:
301 case PIMV1_TYPE_GRAFT_ACK
:
303 pimv1_join_prune_print(ndo
, &bp
[8], len
- 8);
306 if ((bp
[4] >> 4) != 1)
307 ND_PRINT((ndo
, " [v%d]", bp
[4] >> 4));
311 ND_PRINT((ndo
, "[|pim]"));
316 * auto-RP is a cisco protocol, documented at
317 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
319 * This implements version 1+, dated Sept 9, 1998.
322 cisco_autorp_print(netdissect_options
*ndo
,
323 register const u_char
*bp
, register u_int len
)
330 ND_PRINT((ndo
, " auto-rp "));
334 ND_PRINT((ndo
, "candidate-advert"));
337 ND_PRINT((ndo
, "mapping"));
340 ND_PRINT((ndo
, "type-0x%02x", type
));
347 ND_TCHECK2(bp
[2], 2);
348 ND_PRINT((ndo
, " Hold "));
349 hold
= EXTRACT_16BITS(&bp
[2]);
351 relts_print(ndo
, EXTRACT_16BITS(&bp
[2]));
353 ND_PRINT((ndo
, "FOREVER"));
355 /* Next 4 bytes are reserved. */
359 /*XXX skip unless -v? */
363 * numrps entries of the form:
366 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
367 * 8 bits: # of entries for this RP
368 * each entry: 7 bits: reserved, 1 bit: negative,
369 * 8 bits: mask 32 bits: source
370 * lather, rinse, repeat.
376 ND_TCHECK2(bp
[0], 4);
377 ND_PRINT((ndo
, " RP %s", ipaddr_string(ndo
, bp
)));
379 switch (bp
[4] & 0x3) {
380 case 0: ND_PRINT((ndo
, " PIMv?"));
382 case 1: ND_PRINT((ndo
, " PIMv1"));
384 case 2: ND_PRINT((ndo
, " PIMv2"));
386 case 3: ND_PRINT((ndo
, " PIMv1+2"));
390 ND_PRINT((ndo
, " [rsvd=0x%02x]", bp
[4] & 0xfc));
395 for (; nentries
; nentries
--) {
396 ND_TCHECK2(bp
[0], 6);
397 ND_PRINT((ndo
, "%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
398 ipaddr_string(ndo
, &bp
[2]), bp
[1]));
400 ND_PRINT((ndo
, " bidir"));
403 ND_PRINT((ndo
, "[rsvd=0x%02x]", bp
[0] & 0xfc));
412 ND_PRINT((ndo
, "[|autorp]"));
417 pim_print(netdissect_options
*ndo
,
418 register const u_char
*bp
, register u_int len
, const u_char
*bp2
)
420 register const u_char
*ep
;
421 register const struct pim
*pim
= (const struct pim
*)bp
;
423 ep
= (const u_char
*)ndo
->ndo_snapend
;
426 #ifdef notyet /* currently we see only version and type */
427 ND_TCHECK(pim
->pim_rsv
);
430 switch (PIM_VER(pim
->pim_typever
)) {
432 if (!ndo
->ndo_vflag
) {
433 ND_PRINT((ndo
, "PIMv%u, %s, length %u",
434 PIM_VER(pim
->pim_typever
),
435 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim
->pim_typever
)),
439 ND_PRINT((ndo
, "PIMv%u, length %u\n\t%s",
440 PIM_VER(pim
->pim_typever
),
442 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim
->pim_typever
))));
443 pimv2_print(ndo
, bp
, len
, bp2
);
447 ND_PRINT((ndo
, "PIMv%u, length %u",
448 PIM_VER(pim
->pim_typever
),
456 * PIMv2 uses encoded address representations.
458 * The last PIM-SM I-D before RFC2117 was published specified the
459 * following representation for unicast addresses. However, RFC2117
460 * specified no encoding for unicast addresses with the unicast
461 * address length specified in the header. Therefore, we have to
462 * guess which encoding is being used (Cisco's PIMv2 implementation
463 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
464 * field into a 'unicast-address-length-in-bytes' field. We guess
465 * that it's the draft encoding if this reserved field is zero.
467 * RFC2362 goes back to the encoded format, and calls the addr length
468 * field "reserved" again.
470 * The first byte is the address family, from:
473 * 1 IP (IP version 4)
474 * 2 IP6 (IP version 6)
476 * 4 HDLC (8-bit multidrop)
478 * 6 802 (includes all 802 media plus Ethernet "canonical format")
480 * 8 E.164 (SMDS, Frame Relay, ATM)
482 * 10 X.121 (X.25, Frame Relay)
487 * 15 E.164 with NSAP format subaddress
489 * In addition, the second byte is an "Encoding". 0 is the default
490 * encoding for the address family, and no other encodings are currently
495 static int pimv2_addr_len
;
497 enum pimv2_addrtype
{
498 pimv2_unicast
, pimv2_group
, pimv2_source
502 * 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
503 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
504 * | Addr Family | Encoding Type | Unicast Address |
505 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
507 * 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
508 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
509 * | Addr Family | Encoding Type | Reserved | Mask Len |
510 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
511 * | Group multicast Address |
512 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
514 * 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
515 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
516 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
517 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
519 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
522 pimv2_addr_print(netdissect_options
*ndo
,
523 const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
530 if (pimv2_addr_len
== 0) {
535 len
= sizeof(struct in_addr
);
540 len
= sizeof(struct in6_addr
);
550 switch (pimv2_addr_len
) {
551 case sizeof(struct in_addr
):
555 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
)));
576 else if (af
== AF_INET6
) {
578 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, bp
)));
584 ND_TCHECK2(bp
[0], len
+ 2);
587 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, bp
+ 2)));
589 ND_PRINT((ndo
, "/%u", bp
[1]));
593 else if (af
== AF_INET6
) {
595 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, bp
+ 2)));
597 ND_PRINT((ndo
, "/%u", bp
[1]));
601 if (bp
[0] && !silent
) {
602 if (at
== pimv2_group
) {
603 ND_PRINT((ndo
, "(0x%02x)", bp
[0]));
605 ND_PRINT((ndo
, "(%s%s%s",
606 bp
[0] & 0x04 ? "S" : "",
607 bp
[0] & 0x02 ? "W" : "",
608 bp
[0] & 0x01 ? "R" : ""));
610 ND_PRINT((ndo
, "+0x%02x", bp
[0] & 0xf8));
612 ND_PRINT((ndo
, ")"));
615 return hdrlen
+ 2 + len
;
623 enum checksum_status
{
629 static enum checksum_status
630 pimv2_check_checksum(const u_char
*bp
, const u_char
*bp2
, u_int len
)
635 ip
= (const struct ip
*)bp2
;
637 struct cksum_vec vec
[1];
641 cksum
= in_cksum(vec
, 1);
642 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(ip6
, bp
, len
, len
, IPPROTO_PIM
);
649 return (cksum
? INCORRECT
: CORRECT
);
657 pimv2_print(netdissect_options
*ndo
,
658 register const u_char
*bp
, register u_int len
, const u_char
*bp2
)
660 register const u_char
*ep
;
661 register const struct pim
*pim
= (const struct pim
*)bp
;
663 enum checksum_status cksum_status
;
665 ep
= (const u_char
*)ndo
->ndo_snapend
;
670 ND_TCHECK(pim
->pim_rsv
);
671 pimv2_addr_len
= pim
->pim_rsv
;
672 if (pimv2_addr_len
!= 0)
673 ND_PRINT((ndo
, ", RFC2117-encoding"));
675 ND_PRINT((ndo
, ", cksum 0x%04x ", EXTRACT_16BITS(&pim
->pim_cksum
)));
676 if (EXTRACT_16BITS(&pim
->pim_cksum
) == 0) {
677 ND_PRINT((ndo
, "(unverified)"));
679 if (PIM_TYPE(pim
->pim_typever
) == PIMV2_TYPE_REGISTER
) {
681 * The checksum only covers the packet header,
682 * not the encapsulated packet.
684 cksum_status
= pimv2_check_checksum(bp
, bp2
, 8);
685 if (cksum_status
== INCORRECT
) {
687 * To quote RFC 4601, "For interoperability
688 * reasons, a message carrying a checksum
689 * calculated over the entire PIM Register
690 * message should also be accepted."
692 cksum_status
= pimv2_check_checksum(bp
, bp2
, len
);
696 * The checksum covers the entire packet.
698 cksum_status
= pimv2_check_checksum(bp
, bp2
, len
);
700 switch (cksum_status
) {
703 ND_PRINT((ndo
, "(correct)"));
707 ND_PRINT((ndo
, "(incorrect)"));
711 ND_PRINT((ndo
, "(unverified)"));
716 switch (PIM_TYPE(pim
->pim_typever
)) {
717 case PIMV2_TYPE_HELLO
:
719 uint16_t otype
, olen
;
722 ND_TCHECK2(bp
[0], 4);
723 otype
= EXTRACT_16BITS(&bp
[0]);
724 olen
= EXTRACT_16BITS(&bp
[2]);
725 ND_TCHECK2(bp
[0], 4 + olen
);
726 ND_PRINT((ndo
, "\n\t %s Option (%u), length %u, Value: ",
727 tok2str(pimv2_hello_option_values
, "Unknown", otype
),
733 case PIMV2_HELLO_OPTION_HOLDTIME
:
734 relts_print(ndo
, EXTRACT_16BITS(bp
));
737 case PIMV2_HELLO_OPTION_LANPRUNEDELAY
:
739 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
742 uint16_t lan_delay
, override_interval
;
743 lan_delay
= EXTRACT_16BITS(bp
);
744 override_interval
= EXTRACT_16BITS(bp
+2);
745 t_bit
= (lan_delay
& 0x8000)? 1 : 0;
746 lan_delay
&= ~0x8000;
747 ND_PRINT((ndo
, "\n\t T-bit=%d, LAN delay %dms, Override interval %dms",
748 t_bit
, lan_delay
, override_interval
));
752 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
:
753 case PIMV2_HELLO_OPTION_DR_PRIORITY
:
756 ND_PRINT((ndo
, "Bi-Directional Capability (Old)"));
759 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(bp
)));
762 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
767 case PIMV2_HELLO_OPTION_GENID
:
768 ND_PRINT((ndo
, "0x%08x", EXTRACT_32BITS(bp
)));
771 case PIMV2_HELLO_OPTION_REFRESH_CAP
:
772 ND_PRINT((ndo
, "v%d", *bp
));
774 ND_PRINT((ndo
, ", interval "));
775 relts_print(ndo
, *(bp
+1));
777 if (EXTRACT_16BITS(bp
+2) != 0) {
778 ND_PRINT((ndo
, " ?0x%04x?", EXTRACT_16BITS(bp
+2)));
782 case PIMV2_HELLO_OPTION_BIDIR_CAP
:
785 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
:
786 case PIMV2_HELLO_OPTION_ADDRESS_LIST
:
787 if (ndo
->ndo_vflag
> 1) {
788 const u_char
*ptr
= bp
;
789 while (ptr
< (bp
+olen
)) {
790 ND_PRINT((ndo
, "\n\t "));
791 advance
= pimv2_addr_print(ndo
, ptr
, pimv2_unicast
, 0);
793 ND_PRINT((ndo
, "..."));
801 if (ndo
->ndo_vflag
<= 1)
802 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
805 /* do we want to see an additionally hexdump ? */
806 if (ndo
->ndo_vflag
> 1)
807 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
813 case PIMV2_TYPE_REGISTER
:
817 ND_TCHECK2(*(bp
+ 4), PIMV2_REGISTER_FLAG_LEN
);
819 ND_PRINT((ndo
, ", Flags [ %s ]\n\t",
820 tok2str(pimv2_register_flag_values
,
822 EXTRACT_32BITS(bp
+4))));
825 /* encapsulated multicast packet */
826 ip
= (const struct ip
*)bp
;
828 case 0: /* Null header */
829 ND_PRINT((ndo
, "IP-Null-header %s > %s",
830 ipaddr_string(ndo
, &ip
->ip_src
),
831 ipaddr_string(ndo
, &ip
->ip_dst
)));
835 ip_print(ndo
, bp
, len
);
839 ip6_print(ndo
, bp
, len
);
843 ND_PRINT((ndo
, "IP ver %d", IP_V(ip
)));
849 case PIMV2_TYPE_REGISTER_STOP
:
853 ND_PRINT((ndo
, " group="));
854 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
855 ND_PRINT((ndo
, "..."));
858 bp
+= advance
; len
-= advance
;
861 ND_PRINT((ndo
, " source="));
862 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
863 ND_PRINT((ndo
, "..."));
866 bp
+= advance
; len
-= advance
;
869 case PIMV2_TYPE_JOIN_PRUNE
:
870 case PIMV2_TYPE_GRAFT
:
871 case PIMV2_TYPE_GRAFT_ACK
:
876 * 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
877 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
878 * |PIM Ver| Type | Addr length | Checksum |
879 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
880 * | Unicast-Upstream Neighbor Address |
881 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
882 * | Reserved | Num groups | Holdtime |
883 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
884 * | Encoded-Multicast Group Address-1 |
885 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
886 * | Number of Joined Sources | Number of Pruned Sources |
887 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
888 * | Encoded-Joined Source Address-1 |
889 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
892 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
893 * | Encoded-Joined Source Address-n |
894 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
895 * | Encoded-Pruned Source Address-1 |
896 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
899 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
900 * | Encoded-Pruned Source Address-n |
901 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
904 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
905 * | Encoded-Multicast Group Address-n |
906 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
917 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
920 ND_PRINT((ndo
, ", upstream-neighbor: "));
921 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
922 ND_PRINT((ndo
, "..."));
925 bp
+= advance
; len
-= advance
;
930 holdtime
= EXTRACT_16BITS(&bp
[2]);
931 ND_PRINT((ndo
, "\n\t %u group(s)", ngroup
));
932 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
933 ND_PRINT((ndo
, ", holdtime: "));
934 if (holdtime
== 0xffff)
935 ND_PRINT((ndo
, "infinite"));
937 relts_print(ndo
, holdtime
);
940 for (i
= 0; i
< ngroup
; i
++) {
943 ND_PRINT((ndo
, "\n\t group #%u: ", i
+1));
944 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
945 ND_PRINT((ndo
, "...)"));
948 bp
+= advance
; len
-= advance
;
950 ND_PRINT((ndo
, "...)"));
953 njoin
= EXTRACT_16BITS(&bp
[0]);
954 nprune
= EXTRACT_16BITS(&bp
[2]);
955 ND_PRINT((ndo
, ", joined sources: %u, pruned sources: %u", njoin
, nprune
));
957 for (j
= 0; j
< njoin
; j
++) {
958 ND_PRINT((ndo
, "\n\t joined source #%u: ", j
+1));
959 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
960 ND_PRINT((ndo
, "...)"));
963 bp
+= advance
; len
-= advance
;
965 for (j
= 0; j
< nprune
; j
++) {
966 ND_PRINT((ndo
, "\n\t pruned source #%u: ", j
+1));
967 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
968 ND_PRINT((ndo
, "...)"));
971 bp
+= advance
; len
-= advance
;
978 case PIMV2_TYPE_BOOTSTRAP
:
983 /* Fragment Tag, Hash Mask len, and BSR-priority */
984 if (bp
+ sizeof(uint16_t) >= ep
) break;
985 ND_PRINT((ndo
, " tag=%x", EXTRACT_16BITS(bp
)));
986 bp
+= sizeof(uint16_t);
988 ND_PRINT((ndo
, " hashmlen=%d", bp
[0]));
989 if (bp
+ 1 >= ep
) break;
990 ND_PRINT((ndo
, " BSRprio=%d", bp
[1]));
993 /* Encoded-Unicast-BSR-Address */
995 ND_PRINT((ndo
, " BSR="));
996 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
997 ND_PRINT((ndo
, "..."));
1002 for (i
= 0; bp
< ep
; i
++) {
1003 /* Encoded-Group Address */
1004 ND_PRINT((ndo
, " (group%d: ", i
));
1005 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
1007 ND_PRINT((ndo
, "...)"));
1012 /* RP-Count, Frag RP-Cnt, and rsvd */
1014 ND_PRINT((ndo
, "...)"));
1017 ND_PRINT((ndo
, " RPcnt=%d", bp
[0]));
1019 ND_PRINT((ndo
, "...)"));
1022 ND_PRINT((ndo
, " FRPcnt=%d", frpcnt
= bp
[1]));
1025 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
1027 ND_PRINT((ndo
, " RP%d=", j
));
1028 if ((advance
= pimv2_addr_print(ndo
, bp
,
1031 ND_PRINT((ndo
, "...)"));
1037 ND_PRINT((ndo
, "...)"));
1040 ND_PRINT((ndo
, ",holdtime="));
1041 relts_print(ndo
, EXTRACT_16BITS(bp
));
1043 ND_PRINT((ndo
, "...)"));
1046 ND_PRINT((ndo
, ",prio=%d", bp
[2]));
1049 ND_PRINT((ndo
, ")"));
1054 case PIMV2_TYPE_ASSERT
:
1058 ND_PRINT((ndo
, " group="));
1059 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1060 ND_PRINT((ndo
, "..."));
1063 bp
+= advance
; len
-= advance
;
1066 ND_PRINT((ndo
, " src="));
1067 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1068 ND_PRINT((ndo
, "..."));
1071 bp
+= advance
; len
-= advance
;
1075 ND_PRINT((ndo
, " RPT"));
1076 ND_PRINT((ndo
, " pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff));
1077 ND_PRINT((ndo
, " metric=%u", EXTRACT_32BITS(&bp
[4])));
1080 case PIMV2_TYPE_CANDIDATE_RP
:
1085 /* Prefix-Cnt, Priority, and Holdtime */
1086 if (bp
>= ep
) break;
1087 ND_PRINT((ndo
, " prefix-cnt=%d", bp
[0]));
1089 if (bp
+ 1 >= ep
) break;
1090 ND_PRINT((ndo
, " prio=%d", bp
[1]));
1091 if (bp
+ 3 >= ep
) break;
1092 ND_PRINT((ndo
, " holdtime="));
1093 relts_print(ndo
, EXTRACT_16BITS(&bp
[2]));
1096 /* Encoded-Unicast-RP-Address */
1097 if (bp
>= ep
) break;
1098 ND_PRINT((ndo
, " RP="));
1099 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1100 ND_PRINT((ndo
, "..."));
1105 /* Encoded-Group Addresses */
1106 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
1107 ND_PRINT((ndo
, " Group%d=", i
));
1108 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
1110 ND_PRINT((ndo
, "..."));
1118 case PIMV2_TYPE_PRUNE_REFRESH
:
1119 ND_PRINT((ndo
, " src="));
1120 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1121 ND_PRINT((ndo
, "..."));
1125 ND_PRINT((ndo
, " grp="));
1126 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1127 ND_PRINT((ndo
, "..."));
1131 ND_PRINT((ndo
, " forwarder="));
1132 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1133 ND_PRINT((ndo
, "..."));
1137 ND_TCHECK2(bp
[0], 2);
1138 ND_PRINT((ndo
, " TUNR "));
1139 relts_print(ndo
, EXTRACT_16BITS(bp
));
1144 ND_PRINT((ndo
, " [type %d]", PIM_TYPE(pim
->pim_typever
)));
1151 ND_PRINT((ndo
, "[|pim]"));
1156 * c-style: whitesmith