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