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