]> The Tcpdump Group git mirrors - tcpdump/blob - print-pim.c
provide multiline output for PIM Joins/Grafts/Graft-Acks
[tcpdump] / print-pim.c
1 /*
2 * Copyright (c) 1995, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 */
21
22 #ifndef lint
23 static const char rcsid[] _U_ =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.42 2004-03-18 14:12:18 hannes Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <tcpdump-stdinc.h>
32 #include "interface.h"
33
34 #define PIMV2_TYPE_HELLO 0
35 #define PIMV2_TYPE_REGISTER 1
36 #define PIMV2_TYPE_REGISTER_STOP 2
37 #define PIMV2_TYPE_JOIN_PRUNE 3
38 #define PIMV2_TYPE_BOOTSTRAP 4
39 #define PIMV2_TYPE_ASSERT 5
40 #define PIMV2_TYPE_GRAFT 6
41 #define PIMV2_TYPE_GRAFT_ACK 7
42 #define PIMV2_TYPE_CANDIDATE_RP 8
43 #define PIMV2_TYPE_PRUNE_REFRESH 9
44
45 static struct tok pimv2_type_values[] = {
46 { PIMV2_TYPE_HELLO, "Hello" },
47 { PIMV2_TYPE_REGISTER, "Register" },
48 { PIMV2_TYPE_REGISTER_STOP, "Register Stop" },
49 { PIMV2_TYPE_JOIN_PRUNE, "Join / Prune" },
50 { PIMV2_TYPE_BOOTSTRAP, "Bootstrap" },
51 { PIMV2_TYPE_ASSERT, "Assert" },
52 { PIMV2_TYPE_GRAFT, "Graft" },
53 { PIMV2_TYPE_GRAFT_ACK, "Graft Acknowledgement" },
54 { PIMV2_TYPE_CANDIDATE_RP, "Candidate RP Advertisement" },
55 { PIMV2_TYPE_PRUNE_REFRESH, "Prune Refresh" },
56 { 0, NULL}
57 };
58
59 #define PIMV2_HELLO_OPTION_HOLDTIME 1
60 #define PIMV2_HELLO_OPTION_LANPRUNEDELAY 2
61 #define PIMV2_HELLO_OPTION_DR_PRIORITY_OLD 18
62 #define PIMV2_HELLO_OPTION_DR_PRIORITY 19
63 #define PIMV2_HELLO_OPTION_GENID 20
64 #define PIMV2_HELLO_OPTION_REFRESH_CAP 21
65 #define PIMV2_HELLO_OPTION_BIDIR_CAP 22
66 #define PIMV2_HELLO_OPTION_ADDRESS_LIST 24
67 #define PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD 65001
68
69 static struct tok pimv2_hello_option_values[] = {
70 { PIMV2_HELLO_OPTION_HOLDTIME, "Hold Time" },
71 { PIMV2_HELLO_OPTION_LANPRUNEDELAY, "LAN Prune Delay" },
72 { PIMV2_HELLO_OPTION_DR_PRIORITY_OLD, "DR Priority (Old)" },
73 { PIMV2_HELLO_OPTION_DR_PRIORITY, "DR Priority" },
74 { PIMV2_HELLO_OPTION_GENID, "Generation ID" },
75 { PIMV2_HELLO_OPTION_REFRESH_CAP, "State Refresh Capability" },
76 { PIMV2_HELLO_OPTION_BIDIR_CAP, "Bi-Directional Capability" },
77 { PIMV2_HELLO_OPTION_ADDRESS_LIST, "Address List" },
78 { PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD, "Address List (Old)" },
79 { 0, NULL}
80 };
81
82
83 /*
84 * XXX: We consider a case where IPv6 is not ready yet for portability,
85 * but PIM dependent defintions should be independent of IPv6...
86 */
87
88 struct pim {
89 u_int8_t pim_typever;
90 /* upper 4bit: PIM version number; 2 for PIMv2 */
91 /* lower 4bit: the PIM message type, currently they are:
92 * Hello, Register, Register-Stop, Join/Prune,
93 * Bootstrap, Assert, Graft (PIM-DM only),
94 * Graft-Ack (PIM-DM only), C-RP-Adv
95 */
96 #define PIM_VER(x) (((x) & 0xf0) >> 4)
97 #define PIM_TYPE(x) ((x) & 0x0f)
98 u_char pim_rsv; /* Reserved */
99 u_short pim_cksum; /* IP style check sum */
100 };
101
102
103 #include <stdio.h>
104 #include <stdlib.h>
105
106 #include "interface.h"
107 #include "addrtoname.h"
108 #include "extract.h"
109
110 #include "ip.h"
111
112 static void pimv2_print(register const u_char *bp, register u_int len);
113
114 static void
115 pimv1_join_prune_print(register const u_char *bp, register u_int len)
116 {
117 int maddrlen, addrlen, ngroups, njoin, nprune;
118 int njp;
119
120 /* If it's a single group and a single source, use 1-line output. */
121 if (TTEST2(bp[0], 30) && bp[11] == 1 &&
122 ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) {
123 int hold;
124
125 (void)printf(" RPF %s ", ipaddr_string(bp));
126 hold = EXTRACT_16BITS(&bp[6]);
127 if (hold != 180) {
128 (void)printf("Hold ");
129 relts_print(hold);
130 }
131 (void)printf("%s (%s/%d, %s", njoin ? "Join" : "Prune",
132 ipaddr_string(&bp[26]), bp[25] & 0x3f,
133 ipaddr_string(&bp[12]));
134 if (EXTRACT_32BITS(&bp[16]) != 0xffffffff)
135 (void)printf("/%s", ipaddr_string(&bp[16]));
136 (void)printf(") %s%s %s",
137 (bp[24] & 0x01) ? "Sparse" : "Dense",
138 (bp[25] & 0x80) ? " WC" : "",
139 (bp[25] & 0x40) ? "RP" : "SPT");
140 return;
141 }
142
143 TCHECK2(bp[0], 4);
144 if (vflag > 1)
145 (void)printf("\n");
146 (void)printf(" Upstream Nbr: %s", ipaddr_string(bp));
147 TCHECK2(bp[6], 2);
148 if (vflag > 1)
149 (void)printf("\n");
150 (void)printf(" Hold time: ");
151 relts_print(EXTRACT_16BITS(&bp[6]));
152 if (vflag < 2)
153 return;
154 bp += 8;
155 len -= 8;
156
157 TCHECK2(bp[0], 4);
158 maddrlen = bp[1];
159 addrlen = bp[2];
160 ngroups = bp[3];
161 bp += 4;
162 len -= 4;
163 while (ngroups--) {
164 TCHECK2(bp[0], 4);
165 (void)printf("\n\tGroup: %s", ipaddr_string(bp));
166 if (EXTRACT_32BITS(&bp[4]) != 0xffffffff)
167 (void)printf("/%s", ipaddr_string(&bp[4]));
168 TCHECK2(bp[8], 4);
169 njoin = EXTRACT_16BITS(&bp[8]);
170 nprune = EXTRACT_16BITS(&bp[10]);
171 (void)printf(" joined: %d pruned: %d", njoin, nprune);
172 bp += 12;
173 len -= 12;
174 for (njp = 0; njp < (njoin + nprune); njp++) {
175 const char *type;
176
177 if (njp < njoin)
178 type = "Join ";
179 else
180 type = "Prune";
181 TCHECK2(bp[0], 6);
182 (void)printf("\n\t%s %s%s%s%s/%d", type,
183 (bp[0] & 0x01) ? "Sparse " : "Dense ",
184 (bp[1] & 0x80) ? "WC " : "",
185 (bp[1] & 0x40) ? "RP " : "SPT ",
186 ipaddr_string(&bp[2]), bp[1] & 0x3f);
187 bp += 6;
188 len -= 6;
189 }
190 }
191 return;
192 trunc:
193 (void)printf("[|pim]");
194 return;
195 }
196
197 void
198 pimv1_print(register const u_char *bp, register u_int len)
199 {
200 register const u_char *ep;
201 register u_char type;
202
203 ep = (const u_char *)snapend;
204 if (bp >= ep)
205 return;
206
207 TCHECK(bp[1]);
208 type = bp[1];
209
210 switch (type) {
211 case 0:
212 (void)printf(" Query");
213 if (TTEST(bp[8])) {
214 switch (bp[8] >> 4) {
215 case 0:
216 (void)printf(" Dense-mode");
217 break;
218 case 1:
219 (void)printf(" Sparse-mode");
220 break;
221 case 2:
222 (void)printf(" Sparse-Dense-mode");
223 break;
224 default:
225 (void)printf(" mode-%d", bp[8] >> 4);
226 break;
227 }
228 }
229 if (vflag) {
230 TCHECK2(bp[10],2);
231 (void)printf(" (Hold-time ");
232 relts_print(EXTRACT_16BITS(&bp[10]));
233 (void)printf(")");
234 }
235 break;
236
237 case 1:
238 (void)printf(" Register");
239 TCHECK2(bp[8], 20); /* ip header */
240 (void)printf(" for %s > %s", ipaddr_string(&bp[20]),
241 ipaddr_string(&bp[24]));
242 break;
243 case 2:
244 (void)printf(" Register-Stop");
245 TCHECK2(bp[12], 4);
246 (void)printf(" for %s > %s", ipaddr_string(&bp[8]),
247 ipaddr_string(&bp[12]));
248 break;
249 case 3:
250 (void)printf(" Join/Prune");
251 if (vflag)
252 pimv1_join_prune_print(&bp[8], len - 8);
253 break;
254 case 4:
255 (void)printf(" RP-reachable");
256 if (vflag) {
257 TCHECK2(bp[22], 2);
258 (void)printf(" group %s",
259 ipaddr_string(&bp[8]));
260 if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
261 (void)printf("/%s", ipaddr_string(&bp[12]));
262 (void)printf(" RP %s hold ", ipaddr_string(&bp[16]));
263 relts_print(EXTRACT_16BITS(&bp[22]));
264 }
265 break;
266 case 5:
267 (void)printf(" Assert");
268 TCHECK2(bp[16], 4);
269 (void)printf(" for %s > %s", ipaddr_string(&bp[16]),
270 ipaddr_string(&bp[8]));
271 if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
272 (void)printf("/%s", ipaddr_string(&bp[12]));
273 TCHECK2(bp[24], 4);
274 (void)printf(" %s pref %d metric %d",
275 (bp[20] & 0x80) ? "RP-tree" : "SPT",
276 EXTRACT_32BITS(&bp[20]) & 0x7fffffff,
277 EXTRACT_32BITS(&bp[24]));
278 break;
279 case 6:
280 (void)printf(" Graft");
281 if (vflag)
282 pimv1_join_prune_print(&bp[8], len - 8);
283 break;
284 case 7:
285 (void)printf(" Graft-ACK");
286 if (vflag)
287 pimv1_join_prune_print(&bp[8], len - 8);
288 break;
289 case 8:
290 (void)printf(" Mode");
291 break;
292 default:
293 (void)printf(" [type %d]", type);
294 break;
295 }
296 if ((bp[4] >> 4) != 1)
297 (void)printf(" [v%d]", bp[4] >> 4);
298 return;
299
300 trunc:
301 (void)printf("[|pim]");
302 return;
303 }
304
305 /*
306 * auto-RP is a cisco protocol, documented at
307 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
308 *
309 * This implements version 1+, dated Sept 9, 1998.
310 */
311 void
312 cisco_autorp_print(register const u_char *bp, register u_int len)
313 {
314 int type;
315 int numrps;
316 int hold;
317
318 TCHECK(bp[0]);
319 (void)printf(" auto-rp ");
320 type = bp[0];
321 switch (type) {
322 case 0x11:
323 (void)printf("candidate-advert");
324 break;
325 case 0x12:
326 (void)printf("mapping");
327 break;
328 default:
329 (void)printf("type-0x%02x", type);
330 break;
331 }
332
333 TCHECK(bp[1]);
334 numrps = bp[1];
335
336 TCHECK2(bp[2], 2);
337 (void)printf(" Hold ");
338 hold = EXTRACT_16BITS(&bp[2]);
339 if (hold)
340 relts_print(EXTRACT_16BITS(&bp[2]));
341 else
342 printf("FOREVER");
343
344 /* Next 4 bytes are reserved. */
345
346 bp += 8; len -= 8;
347
348 /*XXX skip unless -v? */
349
350 /*
351 * Rest of packet:
352 * numrps entries of the form:
353 * 32 bits: RP
354 * 6 bits: reserved
355 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
356 * 8 bits: # of entries for this RP
357 * each entry: 7 bits: reserved, 1 bit: negative,
358 * 8 bits: mask 32 bits: source
359 * lather, rinse, repeat.
360 */
361 while (numrps--) {
362 int nentries;
363 char s;
364
365 TCHECK2(bp[0], 4);
366 (void)printf(" RP %s", ipaddr_string(bp));
367 TCHECK(bp[4]);
368 switch (bp[4] & 0x3) {
369 case 0: printf(" PIMv?");
370 break;
371 case 1: printf(" PIMv1");
372 break;
373 case 2: printf(" PIMv2");
374 break;
375 case 3: printf(" PIMv1+2");
376 break;
377 }
378 if (bp[4] & 0xfc)
379 (void)printf(" [rsvd=0x%02x]", bp[4] & 0xfc);
380 TCHECK(bp[5]);
381 nentries = bp[5];
382 bp += 6; len -= 6;
383 s = ' ';
384 for (; nentries; nentries--) {
385 TCHECK2(bp[0], 6);
386 (void)printf("%c%s%s/%d", s, bp[0] & 1 ? "!" : "",
387 ipaddr_string(&bp[2]), bp[1]);
388 if (bp[0] & 0xfe)
389 (void)printf("[rsvd=0x%02x]", bp[0] & 0xfe);
390 s = ',';
391 bp += 6; len -= 6;
392 }
393 }
394 return;
395
396 trunc:
397 (void)printf("[|autorp]");
398 return;
399 }
400
401 void
402 pim_print(register const u_char *bp, register u_int len)
403 {
404 register const u_char *ep;
405 register struct pim *pim = (struct pim *)bp;
406
407 ep = (const u_char *)snapend;
408 if (bp >= ep)
409 return;
410 #ifdef notyet /* currently we see only version and type */
411 TCHECK(pim->pim_rsv);
412 #endif
413
414 switch (PIM_VER(pim->pim_typever)) {
415 case 2:
416 if (!vflag) {
417 printf("PIMv%u, %s (%u), length: %u",
418 PIM_VER(pim->pim_typever),
419 tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim->pim_typever)),
420 PIM_TYPE(pim->pim_typever),
421 len);
422 return;
423 } else {
424 printf("PIMv%u, length: %u\n\t%s (%u)",
425 PIM_VER(pim->pim_typever),
426 len,
427 tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim->pim_typever)),
428 PIM_TYPE(pim->pim_typever));
429 pimv2_print(bp, len);
430 }
431 break;
432 default:
433 printf("PIMv%u, length: %u",
434 PIM_VER(pim->pim_typever),
435 len);
436 break;
437 }
438 return;
439 }
440
441 /*
442 * PIMv2 uses encoded address representations.
443 *
444 * The last PIM-SM I-D before RFC2117 was published specified the
445 * following representation for unicast addresses. However, RFC2117
446 * specified no encoding for unicast addresses with the unicast
447 * address length specified in the header. Therefore, we have to
448 * guess which encoding is being used (Cisco's PIMv2 implementation
449 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
450 * field into a 'unicast-address-length-in-bytes' field. We guess
451 * that it's the draft encoding if this reserved field is zero.
452 *
453 * RFC2362 goes back to the encoded format, and calls the addr length
454 * field "reserved" again.
455 *
456 * The first byte is the address family, from:
457 *
458 * 0 Reserved
459 * 1 IP (IP version 4)
460 * 2 IP6 (IP version 6)
461 * 3 NSAP
462 * 4 HDLC (8-bit multidrop)
463 * 5 BBN 1822
464 * 6 802 (includes all 802 media plus Ethernet "canonical format")
465 * 7 E.163
466 * 8 E.164 (SMDS, Frame Relay, ATM)
467 * 9 F.69 (Telex)
468 * 10 X.121 (X.25, Frame Relay)
469 * 11 IPX
470 * 12 Appletalk
471 * 13 Decnet IV
472 * 14 Banyan Vines
473 * 15 E.164 with NSAP format subaddress
474 *
475 * In addition, the second byte is an "Encoding". 0 is the default
476 * encoding for the address family, and no other encodings are currently
477 * specified.
478 *
479 */
480
481 static int pimv2_addr_len;
482
483 enum pimv2_addrtype {
484 pimv2_unicast, pimv2_group, pimv2_source
485 };
486
487 /* 0 1 2 3
488 * 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
489 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
490 * | Addr Family | Encoding Type | Unicast Address |
491 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
492 * 0 1 2 3
493 * 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
494 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
495 * | Addr Family | Encoding Type | Reserved | Mask Len |
496 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
497 * | Group multicast Address |
498 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
499 * 0 1 2 3
500 * 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
501 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
502 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
503 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
504 * | Source Address |
505 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
506 */
507 static int
508 pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent)
509 {
510 int af;
511 const char *afstr;
512 int len, hdrlen;
513
514 TCHECK(bp[0]);
515
516 if (pimv2_addr_len == 0) {
517 TCHECK(bp[1]);
518 switch (bp[0]) {
519 case 1:
520 af = AF_INET;
521 afstr = "IPv4";
522 len = 4;
523 break;
524 #ifdef INET6
525 case 2:
526 af = AF_INET6;
527 afstr = "IPv6";
528 len = 16;
529 break;
530 #endif
531 default:
532 return -1;
533 }
534 if (bp[1] != 0)
535 return -1;
536 hdrlen = 2;
537 } else {
538 switch (pimv2_addr_len) {
539 case 4:
540 af = AF_INET;
541 afstr = "IPv4";
542 break;
543 #ifdef INET6
544 case 16:
545 af = AF_INET6;
546 afstr = "IPv6";
547 break;
548 #endif
549 default:
550 return -1;
551 break;
552 }
553 len = pimv2_addr_len;
554 hdrlen = 0;
555 }
556
557 bp += hdrlen;
558 switch (at) {
559 case pimv2_unicast:
560 TCHECK2(bp[0], len);
561 if (af == AF_INET) {
562 if (!silent)
563 (void)printf("%s", ipaddr_string(bp));
564 }
565 #ifdef INET6
566 else if (af == AF_INET6) {
567 if (!silent)
568 (void)printf("%s", ip6addr_string(bp));
569 }
570 #endif
571 return hdrlen + len;
572 case pimv2_group:
573 case pimv2_source:
574 TCHECK2(bp[0], len + 2);
575 if (af == AF_INET) {
576 if (!silent) {
577 (void)printf("%s", ipaddr_string(bp + 2));
578 if (bp[1] != 32)
579 (void)printf("/%u", bp[1]);
580 }
581 }
582 #ifdef INET6
583 else if (af == AF_INET6) {
584 if (!silent) {
585 (void)printf("%s", ip6addr_string(bp + 2));
586 if (bp[1] != 128)
587 (void)printf("/%u", bp[1]);
588 }
589 }
590 #endif
591 if (bp[0] && !silent) {
592 if (at == pimv2_group) {
593 (void)printf("(0x%02x)", bp[0]);
594 } else {
595 (void)printf("(%s%s%s",
596 bp[0] & 0x04 ? "S" : "",
597 bp[0] & 0x02 ? "W" : "",
598 bp[0] & 0x01 ? "R" : "");
599 if (bp[0] & 0xf8) {
600 (void) printf("+0x%02x", bp[0] & 0xf8);
601 }
602 (void)printf(")");
603 }
604 }
605 return hdrlen + 2 + len;
606 default:
607 return -1;
608 }
609 trunc:
610 return -1;
611 }
612
613 static void
614 pimv2_print(register const u_char *bp, register u_int len)
615 {
616 register const u_char *ep;
617 register struct pim *pim = (struct pim *)bp;
618 int advance;
619
620 ep = (const u_char *)snapend;
621 if (bp >= ep)
622 return;
623 if (ep > bp + len)
624 ep = bp + len;
625 TCHECK(pim->pim_rsv);
626 pimv2_addr_len = pim->pim_rsv;
627 if (pimv2_addr_len != 0)
628 (void)printf(", RFC2117-encoding");
629
630 switch (PIM_TYPE(pim->pim_typever)) {
631 case PIMV2_TYPE_HELLO:
632 {
633 u_int16_t otype, olen;
634 bp += 4;
635 while (bp < ep) {
636 TCHECK2(bp[0], 4);
637 otype = EXTRACT_16BITS(&bp[0]);
638 olen = EXTRACT_16BITS(&bp[2]);
639 TCHECK2(bp[0], 4 + olen);
640
641 printf("\n\t %s Option (%u), length: %u, Value: ",
642 tok2str( pimv2_hello_option_values,"Unknown",otype),
643 otype,
644 olen);
645 bp += 4;
646
647 switch (otype) {
648 case PIMV2_HELLO_OPTION_HOLDTIME:
649 relts_print(EXTRACT_16BITS(bp));
650 break;
651
652 case PIMV2_HELLO_OPTION_LANPRUNEDELAY:
653 if (olen != 4) {
654 (void)printf("ERROR: Option Lenght != 4 Bytes (%u)", olen);
655 } else {
656 char t_bit;
657 u_int16_t lan_delay, override_interval;
658 lan_delay = EXTRACT_16BITS(bp);
659 override_interval = EXTRACT_16BITS(bp+2);
660 t_bit = (lan_delay & 0x8000)? 1 : 0;
661 lan_delay &= ~0x8000;
662 (void)printf("\n\t T-bit=%d, LAN delay %dms, Override interval %dms",
663 t_bit, lan_delay, override_interval);
664 }
665 break;
666
667 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD:
668 case PIMV2_HELLO_OPTION_DR_PRIORITY:
669 switch (olen) {
670 case 0:
671 printf("Bi-Directional Capability (Old)");
672 break;
673 case 4:
674 printf("%u", EXTRACT_32BITS(bp));
675 break;
676 default:
677 printf("ERROR: Option Lenght != 4 Bytes (%u)", olen);
678 break;
679 }
680 break;
681
682 case PIMV2_HELLO_OPTION_GENID:
683 (void)printf("0x%08x", EXTRACT_32BITS(bp));
684 break;
685
686 case PIMV2_HELLO_OPTION_REFRESH_CAP:
687 (void)printf("v%d", *bp);
688 if (*(bp+1) != 0) {
689 (void)printf(", interval ");
690 relts_print(*(bp+1));
691 }
692 if (EXTRACT_16BITS(bp+2) != 0) {
693 (void)printf(" ?0x%04x?", EXTRACT_16BITS(bp+2));
694 }
695 break;
696
697 case PIMV2_HELLO_OPTION_BIDIR_CAP:
698 break;
699
700 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD:
701 case PIMV2_HELLO_OPTION_ADDRESS_LIST:
702 if (vflag > 1) {
703 const u_char *ptr = bp;
704 while (ptr < (bp+olen)) {
705 int advance;
706
707 printf("\n\t ");
708 advance = pimv2_addr_print(ptr, pimv2_unicast, 0);
709 if (advance < 0) {
710 printf("...");
711 break;
712 }
713 ptr += advance;
714 }
715 }
716 break;
717 default:
718 if (vflag <= 1)
719 print_unknown_data(bp,"\n\t ",olen);
720 break;
721 }
722 /* do we want to see an additionally hexdump ? */
723 if (vflag> 1)
724 print_unknown_data(bp,"\n\t ",olen);
725 bp += olen;
726 }
727 break;
728 }
729
730 case PIMV2_TYPE_REGISTER:
731 {
732 struct ip *ip;
733
734 if (vflag && bp + 8 <= ep) {
735 (void)printf(" %s%s", bp[4] & 0x80 ? "B" : "",
736 bp[4] & 0x40 ? "N" : "");
737 }
738 bp += 8; len -= 8;
739
740 /* encapsulated multicast packet */
741 if (bp >= ep)
742 break;
743 ip = (struct ip *)bp;
744 switch (IP_V(ip)) {
745 case 4: /* IPv4 */
746 printf(" ");
747 ip_print(bp, len);
748 break;
749 #ifdef INET6
750 case 6: /* IPv6 */
751 printf(" ");
752 ip6_print(bp, len);
753 break;
754 #endif
755 default:
756 (void)printf(" IP ver %d", IP_V(ip));
757 break;
758 }
759 break;
760 }
761
762 case PIMV2_TYPE_REGISTER_STOP:
763 bp += 4; len -= 4;
764 if (bp >= ep)
765 break;
766 (void)printf(" group=");
767 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
768 (void)printf("...");
769 break;
770 }
771 bp += advance; len -= advance;
772 if (bp >= ep)
773 break;
774 (void)printf(" source=");
775 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
776 (void)printf("...");
777 break;
778 }
779 bp += advance; len -= advance;
780 break;
781
782 case PIMV2_TYPE_JOIN_PRUNE:
783 case PIMV2_TYPE_GRAFT:
784 case PIMV2_TYPE_GRAFT_ACK:
785
786
787 /*
788 * 0 1 2 3
789 * 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
790 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
791 * |PIM Ver| Type | Addr length | Checksum |
792 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
793 * | Unicast-Upstream Neighbor Address |
794 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
795 * | Reserved | Num groups | Holdtime |
796 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
797 * | Encoded-Multicast Group Address-1 |
798 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
799 * | Number of Joined Sources | Number of Pruned Sources |
800 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
801 * | Encoded-Joined Source Address-1 |
802 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
803 * | . |
804 * | . |
805 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
806 * | Encoded-Joined Source Address-n |
807 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
808 * | Encoded-Pruned Source Address-1 |
809 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
810 * | . |
811 * | . |
812 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
813 * | Encoded-Pruned Source Address-n |
814 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
815 * | . |
816 * | . |
817 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
818 * | Encoded-Multicast Group Address-n |
819 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
820 */
821
822 {
823 u_int8_t ngroup;
824 u_int16_t holdtime;
825 u_int16_t njoin;
826 u_int16_t nprune;
827 int i, j;
828
829 bp += 4; len -= 4;
830 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
831 if (bp >= ep)
832 break;
833 (void)printf(", upstream-neighbor: ");
834 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
835 (void)printf("...");
836 break;
837 }
838 bp += advance; len -= advance;
839 }
840 if (bp + 4 > ep)
841 break;
842 ngroup = bp[1];
843 holdtime = EXTRACT_16BITS(&bp[2]);
844 (void)printf("\n\t %u group(s)", ngroup);
845 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
846 (void)printf(", holdtime: ");
847 if (holdtime == 0xffff)
848 (void)printf("infinite");
849 else
850 relts_print(holdtime);
851 }
852 bp += 4; len -= 4;
853 for (i = 0; i < ngroup; i++) {
854 if (bp >= ep)
855 goto jp_done;
856 (void)printf("\n\t group #%u: ", i+1);
857 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
858 (void)printf("...)");
859 goto jp_done;
860 }
861 bp += advance; len -= advance;
862 if (bp + 4 > ep) {
863 (void)printf("...)");
864 goto jp_done;
865 }
866 njoin = EXTRACT_16BITS(&bp[0]);
867 nprune = EXTRACT_16BITS(&bp[2]);
868 (void)printf(", joined sources: %u, pruned sources: %u", njoin,nprune);
869 bp += 4; len -= 4;
870 for (j = 0; j < njoin; j++) {
871 (void)printf("\n\t joined source #%u: ",j+1);
872 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
873 (void)printf("...)");
874 goto jp_done;
875 }
876 bp += advance; len -= advance;
877 }
878 for (j = 0; j < nprune; j++) {
879 (void)printf("\n\t pruned source #%u: ",j+1);
880 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
881 (void)printf("...)");
882 goto jp_done;
883 }
884 bp += advance; len -= advance;
885 }
886 }
887 jp_done:
888 break;
889 }
890
891 case PIMV2_TYPE_BOOTSTRAP:
892 {
893 int i, j, frpcnt;
894 bp += 4;
895
896 /* Fragment Tag, Hash Mask len, and BSR-priority */
897 if (bp + sizeof(u_int16_t) >= ep) break;
898 (void)printf(" tag=%x", EXTRACT_16BITS(bp));
899 bp += sizeof(u_int16_t);
900 if (bp >= ep) break;
901 (void)printf(" hashmlen=%d", bp[0]);
902 if (bp + 1 >= ep) break;
903 (void)printf(" BSRprio=%d", bp[1]);
904 bp += 2;
905
906 /* Encoded-Unicast-BSR-Address */
907 if (bp >= ep) break;
908 (void)printf(" BSR=");
909 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
910 (void)printf("...");
911 break;
912 }
913 bp += advance;
914
915 for (i = 0; bp < ep; i++) {
916 /* Encoded-Group Address */
917 (void)printf(" (group%d: ", i);
918 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
919 < 0) {
920 (void)printf("...)");
921 goto bs_done;
922 }
923 bp += advance;
924
925 /* RP-Count, Frag RP-Cnt, and rsvd */
926 if (bp >= ep) {
927 (void)printf("...)");
928 goto bs_done;
929 }
930 (void)printf(" RPcnt=%d", bp[0]);
931 if (bp + 1 >= ep) {
932 (void)printf("...)");
933 goto bs_done;
934 }
935 (void)printf(" FRPcnt=%d", frpcnt = bp[1]);
936 bp += 4;
937
938 for (j = 0; j < frpcnt && bp < ep; j++) {
939 /* each RP info */
940 (void)printf(" RP%d=", j);
941 if ((advance = pimv2_addr_print(bp,
942 pimv2_unicast,
943 0)) < 0) {
944 (void)printf("...)");
945 goto bs_done;
946 }
947 bp += advance;
948
949 if (bp + 1 >= ep) {
950 (void)printf("...)");
951 goto bs_done;
952 }
953 (void)printf(",holdtime=");
954 relts_print(EXTRACT_16BITS(bp));
955 if (bp + 2 >= ep) {
956 (void)printf("...)");
957 goto bs_done;
958 }
959 (void)printf(",prio=%d", bp[2]);
960 bp += 4;
961 }
962 (void)printf(")");
963 }
964 bs_done:
965 break;
966 }
967 case PIMV2_TYPE_ASSERT:
968 bp += 4; len -= 4;
969 if (bp >= ep)
970 break;
971 (void)printf(" group=");
972 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
973 (void)printf("...");
974 break;
975 }
976 bp += advance; len -= advance;
977 if (bp >= ep)
978 break;
979 (void)printf(" src=");
980 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
981 (void)printf("...");
982 break;
983 }
984 bp += advance; len -= advance;
985 if (bp + 8 > ep)
986 break;
987 if (bp[0] & 0x80)
988 (void)printf(" RPT");
989 (void)printf(" pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff);
990 (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4]));
991 break;
992
993 case PIMV2_TYPE_CANDIDATE_RP:
994 {
995 int i, pfxcnt;
996 bp += 4;
997
998 /* Prefix-Cnt, Priority, and Holdtime */
999 if (bp >= ep) break;
1000 (void)printf(" prefix-cnt=%d", bp[0]);
1001 pfxcnt = bp[0];
1002 if (bp + 1 >= ep) break;
1003 (void)printf(" prio=%d", bp[1]);
1004 if (bp + 3 >= ep) break;
1005 (void)printf(" holdtime=");
1006 relts_print(EXTRACT_16BITS(&bp[2]));
1007 bp += 4;
1008
1009 /* Encoded-Unicast-RP-Address */
1010 if (bp >= ep) break;
1011 (void)printf(" RP=");
1012 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
1013 (void)printf("...");
1014 break;
1015 }
1016 bp += advance;
1017
1018 /* Encoded-Group Addresses */
1019 for (i = 0; i < pfxcnt && bp < ep; i++) {
1020 (void)printf(" Group%d=", i);
1021 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
1022 < 0) {
1023 (void)printf("...");
1024 break;
1025 }
1026 bp += advance;
1027 }
1028 break;
1029 }
1030
1031 case PIMV2_TYPE_PRUNE_REFRESH:
1032 (void)printf(" src=");
1033 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
1034 (void)printf("...");
1035 break;
1036 }
1037 bp += advance;
1038 (void)printf(" grp=");
1039 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
1040 (void)printf("...");
1041 break;
1042 }
1043 bp += advance;
1044 (void)printf(" forwarder=");
1045 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
1046 (void)printf("...");
1047 break;
1048 }
1049 bp += advance;
1050 TCHECK2(bp[0], 2);
1051 (void)printf(" TUNR ");
1052 relts_print(EXTRACT_16BITS(bp));
1053 break;
1054
1055
1056 default:
1057 (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever));
1058 break;
1059 }
1060
1061 return;
1062
1063 trunc:
1064 (void)printf("[|pim]");
1065 }