]> The Tcpdump Group git mirrors - tcpdump/blob - print-pim.c
NDOize EIGRP, ICMP, L2TP, STP and UDP decoders
[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 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <tcpdump-stdinc.h>
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #include "interface.h"
32 #include "addrtoname.h"
33 #include "extract.h"
34
35 #include "ip.h"
36
37 #define PIMV2_TYPE_HELLO 0
38 #define PIMV2_TYPE_REGISTER 1
39 #define PIMV2_TYPE_REGISTER_STOP 2
40 #define PIMV2_TYPE_JOIN_PRUNE 3
41 #define PIMV2_TYPE_BOOTSTRAP 4
42 #define PIMV2_TYPE_ASSERT 5
43 #define PIMV2_TYPE_GRAFT 6
44 #define PIMV2_TYPE_GRAFT_ACK 7
45 #define PIMV2_TYPE_CANDIDATE_RP 8
46 #define PIMV2_TYPE_PRUNE_REFRESH 9
47
48 static const struct tok pimv2_type_values[] = {
49 { PIMV2_TYPE_HELLO, "Hello" },
50 { PIMV2_TYPE_REGISTER, "Register" },
51 { PIMV2_TYPE_REGISTER_STOP, "Register Stop" },
52 { PIMV2_TYPE_JOIN_PRUNE, "Join / Prune" },
53 { PIMV2_TYPE_BOOTSTRAP, "Bootstrap" },
54 { PIMV2_TYPE_ASSERT, "Assert" },
55 { PIMV2_TYPE_GRAFT, "Graft" },
56 { PIMV2_TYPE_GRAFT_ACK, "Graft Acknowledgement" },
57 { PIMV2_TYPE_CANDIDATE_RP, "Candidate RP Advertisement" },
58 { PIMV2_TYPE_PRUNE_REFRESH, "Prune Refresh" },
59 { 0, NULL}
60 };
61
62 #define PIMV2_HELLO_OPTION_HOLDTIME 1
63 #define PIMV2_HELLO_OPTION_LANPRUNEDELAY 2
64 #define PIMV2_HELLO_OPTION_DR_PRIORITY_OLD 18
65 #define PIMV2_HELLO_OPTION_DR_PRIORITY 19
66 #define PIMV2_HELLO_OPTION_GENID 20
67 #define PIMV2_HELLO_OPTION_REFRESH_CAP 21
68 #define PIMV2_HELLO_OPTION_BIDIR_CAP 22
69 #define PIMV2_HELLO_OPTION_ADDRESS_LIST 24
70 #define PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD 65001
71
72 static const struct tok pimv2_hello_option_values[] = {
73 { PIMV2_HELLO_OPTION_HOLDTIME, "Hold Time" },
74 { PIMV2_HELLO_OPTION_LANPRUNEDELAY, "LAN Prune Delay" },
75 { PIMV2_HELLO_OPTION_DR_PRIORITY_OLD, "DR Priority (Old)" },
76 { PIMV2_HELLO_OPTION_DR_PRIORITY, "DR Priority" },
77 { PIMV2_HELLO_OPTION_GENID, "Generation ID" },
78 { PIMV2_HELLO_OPTION_REFRESH_CAP, "State Refresh Capability" },
79 { PIMV2_HELLO_OPTION_BIDIR_CAP, "Bi-Directional Capability" },
80 { PIMV2_HELLO_OPTION_ADDRESS_LIST, "Address List" },
81 { PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD, "Address List (Old)" },
82 { 0, NULL}
83 };
84
85 #define PIMV2_REGISTER_FLAG_LEN 4
86 #define PIMV2_REGISTER_FLAG_BORDER 0x80000000
87 #define PIMV2_REGISTER_FLAG_NULL 0x40000000
88
89 static const struct tok pimv2_register_flag_values[] = {
90 { PIMV2_REGISTER_FLAG_BORDER, "Border" },
91 { PIMV2_REGISTER_FLAG_NULL, "Null" },
92 { 0, NULL}
93 };
94
95 /*
96 * XXX: We consider a case where IPv6 is not ready yet for portability,
97 * but PIM dependent defintions should be independent of IPv6...
98 */
99
100 struct pim {
101 u_int8_t pim_typever;
102 /* upper 4bit: PIM version number; 2 for PIMv2 */
103 /* lower 4bit: the PIM message type, currently they are:
104 * Hello, Register, Register-Stop, Join/Prune,
105 * Bootstrap, Assert, Graft (PIM-DM only),
106 * Graft-Ack (PIM-DM only), C-RP-Adv
107 */
108 #define PIM_VER(x) (((x) & 0xf0) >> 4)
109 #define PIM_TYPE(x) ((x) & 0x0f)
110 u_char pim_rsv; /* Reserved */
111 u_short pim_cksum; /* IP style check sum */
112 };
113
114 static void pimv2_print(register const u_char *bp, register u_int len, u_int cksum);
115
116 static void
117 pimv1_join_prune_print(register const u_char *bp, register u_int len)
118 {
119 int ngroups, njoin, nprune;
120 int njp;
121
122 /* If it's a single group and a single source, use 1-line output. */
123 if (TTEST2(bp[0], 30) && bp[11] == 1 &&
124 ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) {
125 int hold;
126
127 (void)printf(" RPF %s ", ipaddr_string(bp));
128 hold = EXTRACT_16BITS(&bp[6]);
129 if (hold != 180) {
130 (void)printf("Hold ");
131 relts_print(hold);
132 }
133 (void)printf("%s (%s/%d, %s", njoin ? "Join" : "Prune",
134 ipaddr_string(&bp[26]), bp[25] & 0x3f,
135 ipaddr_string(&bp[12]));
136 if (EXTRACT_32BITS(&bp[16]) != 0xffffffff)
137 (void)printf("/%s", ipaddr_string(&bp[16]));
138 (void)printf(") %s%s %s",
139 (bp[24] & 0x01) ? "Sparse" : "Dense",
140 (bp[25] & 0x80) ? " WC" : "",
141 (bp[25] & 0x40) ? "RP" : "SPT");
142 return;
143 }
144
145 TCHECK2(bp[0], sizeof(struct in_addr));
146 if (vflag > 1)
147 (void)printf("\n");
148 (void)printf(" Upstream Nbr: %s", ipaddr_string(bp));
149 TCHECK2(bp[6], 2);
150 if (vflag > 1)
151 (void)printf("\n");
152 (void)printf(" Hold time: ");
153 relts_print(EXTRACT_16BITS(&bp[6]));
154 if (vflag < 2)
155 return;
156 bp += 8;
157 len -= 8;
158
159 TCHECK2(bp[0], 4);
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] & 0x02) {
394 (void)printf(" bidir");
395 }
396 if (bp[0] & 0xfc) {
397 (void)printf("[rsvd=0x%02x]", bp[0] & 0xfc);
398 }
399 s = ',';
400 bp += 6; len -= 6;
401 }
402 }
403 return;
404
405 trunc:
406 (void)printf("[|autorp]");
407 return;
408 }
409
410 void
411 pim_print(register const u_char *bp, register u_int len, u_int cksum)
412 {
413 register const u_char *ep;
414 register struct pim *pim = (struct pim *)bp;
415
416 ep = (const u_char *)snapend;
417 if (bp >= ep)
418 return;
419 #ifdef notyet /* currently we see only version and type */
420 TCHECK(pim->pim_rsv);
421 #endif
422
423 switch (PIM_VER(pim->pim_typever)) {
424 case 2:
425 if (!vflag) {
426 printf("PIMv%u, %s, length %u",
427 PIM_VER(pim->pim_typever),
428 tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim->pim_typever)),
429 len);
430 return;
431 } else {
432 printf("PIMv%u, length %u\n\t%s",
433 PIM_VER(pim->pim_typever),
434 len,
435 tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim->pim_typever)));
436 pimv2_print(bp, len, cksum);
437 }
438 break;
439 default:
440 printf("PIMv%u, length %u",
441 PIM_VER(pim->pim_typever),
442 len);
443 break;
444 }
445 return;
446 }
447
448 /*
449 * PIMv2 uses encoded address representations.
450 *
451 * The last PIM-SM I-D before RFC2117 was published specified the
452 * following representation for unicast addresses. However, RFC2117
453 * specified no encoding for unicast addresses with the unicast
454 * address length specified in the header. Therefore, we have to
455 * guess which encoding is being used (Cisco's PIMv2 implementation
456 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
457 * field into a 'unicast-address-length-in-bytes' field. We guess
458 * that it's the draft encoding if this reserved field is zero.
459 *
460 * RFC2362 goes back to the encoded format, and calls the addr length
461 * field "reserved" again.
462 *
463 * The first byte is the address family, from:
464 *
465 * 0 Reserved
466 * 1 IP (IP version 4)
467 * 2 IP6 (IP version 6)
468 * 3 NSAP
469 * 4 HDLC (8-bit multidrop)
470 * 5 BBN 1822
471 * 6 802 (includes all 802 media plus Ethernet "canonical format")
472 * 7 E.163
473 * 8 E.164 (SMDS, Frame Relay, ATM)
474 * 9 F.69 (Telex)
475 * 10 X.121 (X.25, Frame Relay)
476 * 11 IPX
477 * 12 Appletalk
478 * 13 Decnet IV
479 * 14 Banyan Vines
480 * 15 E.164 with NSAP format subaddress
481 *
482 * In addition, the second byte is an "Encoding". 0 is the default
483 * encoding for the address family, and no other encodings are currently
484 * specified.
485 *
486 */
487
488 static int pimv2_addr_len;
489
490 enum pimv2_addrtype {
491 pimv2_unicast, pimv2_group, pimv2_source
492 };
493
494 /* 0 1 2 3
495 * 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
496 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
497 * | Addr Family | Encoding Type | Unicast 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 | Reserved | Mask Len |
503 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
504 * | Group multicast Address |
505 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
506 * 0 1 2 3
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 | Rsrvd |S|W|R| Mask Len |
510 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
511 * | Source Address |
512 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
513 */
514 static int
515 pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent)
516 {
517 int af;
518 int len, hdrlen;
519
520 TCHECK(bp[0]);
521
522 if (pimv2_addr_len == 0) {
523 TCHECK(bp[1]);
524 switch (bp[0]) {
525 case 1:
526 af = AF_INET;
527 len = sizeof(struct in_addr);
528 break;
529 #ifdef INET6
530 case 2:
531 af = AF_INET6;
532 len = sizeof(struct in6_addr);
533 break;
534 #endif
535 default:
536 return -1;
537 }
538 if (bp[1] != 0)
539 return -1;
540 hdrlen = 2;
541 } else {
542 switch (pimv2_addr_len) {
543 case sizeof(struct in_addr):
544 af = AF_INET;
545 break;
546 #ifdef INET6
547 case sizeof(struct in6_addr):
548 af = AF_INET6;
549 break;
550 #endif
551 default:
552 return -1;
553 break;
554 }
555 len = pimv2_addr_len;
556 hdrlen = 0;
557 }
558
559 bp += hdrlen;
560 switch (at) {
561 case pimv2_unicast:
562 TCHECK2(bp[0], len);
563 if (af == AF_INET) {
564 if (!silent)
565 (void)printf("%s", ipaddr_string(bp));
566 }
567 #ifdef INET6
568 else if (af == AF_INET6) {
569 if (!silent)
570 (void)printf("%s", ip6addr_string(bp));
571 }
572 #endif
573 return hdrlen + len;
574 case pimv2_group:
575 case pimv2_source:
576 TCHECK2(bp[0], len + 2);
577 if (af == AF_INET) {
578 if (!silent) {
579 (void)printf("%s", ipaddr_string(bp + 2));
580 if (bp[1] != 32)
581 (void)printf("/%u", bp[1]);
582 }
583 }
584 #ifdef INET6
585 else if (af == AF_INET6) {
586 if (!silent) {
587 (void)printf("%s", ip6addr_string(bp + 2));
588 if (bp[1] != 128)
589 (void)printf("/%u", bp[1]);
590 }
591 }
592 #endif
593 if (bp[0] && !silent) {
594 if (at == pimv2_group) {
595 (void)printf("(0x%02x)", bp[0]);
596 } else {
597 (void)printf("(%s%s%s",
598 bp[0] & 0x04 ? "S" : "",
599 bp[0] & 0x02 ? "W" : "",
600 bp[0] & 0x01 ? "R" : "");
601 if (bp[0] & 0xf8) {
602 (void) printf("+0x%02x", bp[0] & 0xf8);
603 }
604 (void)printf(")");
605 }
606 }
607 return hdrlen + 2 + len;
608 default:
609 return -1;
610 }
611 trunc:
612 return -1;
613 }
614
615 static void
616 pimv2_print(register const u_char *bp, register u_int len, u_int cksum)
617 {
618 register const u_char *ep;
619 register struct pim *pim = (struct pim *)bp;
620 int advance;
621
622 ep = (const u_char *)snapend;
623 if (bp >= ep)
624 return;
625 if (ep > bp + len)
626 ep = bp + len;
627 TCHECK(pim->pim_rsv);
628 pimv2_addr_len = pim->pim_rsv;
629 if (pimv2_addr_len != 0)
630 (void)printf(", RFC2117-encoding");
631
632 printf(", cksum 0x%04x ", EXTRACT_16BITS(&pim->pim_cksum));
633 if (EXTRACT_16BITS(&pim->pim_cksum) == 0) {
634 printf("(unverified)");
635 } else {
636 printf("(%scorrect)", TTEST2(bp[0], len) && cksum ? "in" : "" );
637 }
638
639 switch (PIM_TYPE(pim->pim_typever)) {
640 case PIMV2_TYPE_HELLO:
641 {
642 u_int16_t otype, olen;
643 bp += 4;
644 while (bp < ep) {
645 TCHECK2(bp[0], 4);
646 otype = EXTRACT_16BITS(&bp[0]);
647 olen = EXTRACT_16BITS(&bp[2]);
648 TCHECK2(bp[0], 4 + olen);
649
650 printf("\n\t %s Option (%u), length %u, Value: ",
651 tok2str( pimv2_hello_option_values,"Unknown",otype),
652 otype,
653 olen);
654 bp += 4;
655
656 switch (otype) {
657 case PIMV2_HELLO_OPTION_HOLDTIME:
658 relts_print(EXTRACT_16BITS(bp));
659 break;
660
661 case PIMV2_HELLO_OPTION_LANPRUNEDELAY:
662 if (olen != 4) {
663 (void)printf("ERROR: Option Length != 4 Bytes (%u)", olen);
664 } else {
665 char t_bit;
666 u_int16_t lan_delay, override_interval;
667 lan_delay = EXTRACT_16BITS(bp);
668 override_interval = EXTRACT_16BITS(bp+2);
669 t_bit = (lan_delay & 0x8000)? 1 : 0;
670 lan_delay &= ~0x8000;
671 (void)printf("\n\t T-bit=%d, LAN delay %dms, Override interval %dms",
672 t_bit, lan_delay, override_interval);
673 }
674 break;
675
676 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD:
677 case PIMV2_HELLO_OPTION_DR_PRIORITY:
678 switch (olen) {
679 case 0:
680 printf("Bi-Directional Capability (Old)");
681 break;
682 case 4:
683 printf("%u", EXTRACT_32BITS(bp));
684 break;
685 default:
686 printf("ERROR: Option Length != 4 Bytes (%u)", olen);
687 break;
688 }
689 break;
690
691 case PIMV2_HELLO_OPTION_GENID:
692 (void)printf("0x%08x", EXTRACT_32BITS(bp));
693 break;
694
695 case PIMV2_HELLO_OPTION_REFRESH_CAP:
696 (void)printf("v%d", *bp);
697 if (*(bp+1) != 0) {
698 (void)printf(", interval ");
699 relts_print(*(bp+1));
700 }
701 if (EXTRACT_16BITS(bp+2) != 0) {
702 (void)printf(" ?0x%04x?", EXTRACT_16BITS(bp+2));
703 }
704 break;
705
706 case PIMV2_HELLO_OPTION_BIDIR_CAP:
707 break;
708
709 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD:
710 case PIMV2_HELLO_OPTION_ADDRESS_LIST:
711 if (vflag > 1) {
712 const u_char *ptr = bp;
713 while (ptr < (bp+olen)) {
714 int advance;
715
716 printf("\n\t ");
717 advance = pimv2_addr_print(ptr, pimv2_unicast, 0);
718 if (advance < 0) {
719 printf("...");
720 break;
721 }
722 ptr += advance;
723 }
724 }
725 break;
726 default:
727 if (vflag <= 1)
728 print_unknown_data(gndo,bp,"\n\t ",olen);
729 break;
730 }
731 /* do we want to see an additionally hexdump ? */
732 if (vflag> 1)
733 print_unknown_data(gndo,bp,"\n\t ",olen);
734 bp += olen;
735 }
736 break;
737 }
738
739 case PIMV2_TYPE_REGISTER:
740 {
741 struct ip *ip;
742
743 if (!TTEST2(*(bp+4), PIMV2_REGISTER_FLAG_LEN))
744 goto trunc;
745
746 printf(", Flags [ %s ]\n\t",
747 tok2str(pimv2_register_flag_values,
748 "none",
749 EXTRACT_32BITS(bp+4)));
750
751 bp += 8; len -= 8;
752 /* encapsulated multicast packet */
753 ip = (struct ip *)bp;
754 switch (IP_V(ip)) {
755 case 0: /* Null header */
756 (void)printf("IP-Null-header %s > %s",
757 ipaddr_string(&ip->ip_src),
758 ipaddr_string(&ip->ip_dst));
759 break;
760
761 case 4: /* IPv4 */
762 ip_print(gndo, bp, len);
763 break;
764 #ifdef INET6
765 case 6: /* IPv6 */
766 ip6_print(gndo, bp, len);
767 break;
768 #endif
769 default:
770 (void)printf("IP ver %d", IP_V(ip));
771 break;
772 }
773 break;
774 }
775
776 case PIMV2_TYPE_REGISTER_STOP:
777 bp += 4; len -= 4;
778 if (bp >= ep)
779 break;
780 (void)printf(" group=");
781 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
782 (void)printf("...");
783 break;
784 }
785 bp += advance; len -= advance;
786 if (bp >= ep)
787 break;
788 (void)printf(" source=");
789 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
790 (void)printf("...");
791 break;
792 }
793 bp += advance; len -= advance;
794 break;
795
796 case PIMV2_TYPE_JOIN_PRUNE:
797 case PIMV2_TYPE_GRAFT:
798 case PIMV2_TYPE_GRAFT_ACK:
799
800
801 /*
802 * 0 1 2 3
803 * 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
804 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
805 * |PIM Ver| Type | Addr length | Checksum |
806 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
807 * | Unicast-Upstream Neighbor Address |
808 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
809 * | Reserved | Num groups | Holdtime |
810 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
811 * | Encoded-Multicast Group Address-1 |
812 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
813 * | Number of Joined Sources | Number of Pruned Sources |
814 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
815 * | Encoded-Joined Source Address-1 |
816 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
817 * | . |
818 * | . |
819 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
820 * | Encoded-Joined Source Address-n |
821 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
822 * | Encoded-Pruned Source Address-1 |
823 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
824 * | . |
825 * | . |
826 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
827 * | Encoded-Pruned Source Address-n |
828 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
829 * | . |
830 * | . |
831 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
832 * | Encoded-Multicast Group Address-n |
833 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
834 */
835
836 {
837 u_int8_t ngroup;
838 u_int16_t holdtime;
839 u_int16_t njoin;
840 u_int16_t nprune;
841 int i, j;
842
843 bp += 4; len -= 4;
844 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
845 if (bp >= ep)
846 break;
847 (void)printf(", upstream-neighbor: ");
848 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
849 (void)printf("...");
850 break;
851 }
852 bp += advance; len -= advance;
853 }
854 if (bp + 4 > ep)
855 break;
856 ngroup = bp[1];
857 holdtime = EXTRACT_16BITS(&bp[2]);
858 (void)printf("\n\t %u group(s)", ngroup);
859 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
860 (void)printf(", holdtime: ");
861 if (holdtime == 0xffff)
862 (void)printf("infinite");
863 else
864 relts_print(holdtime);
865 }
866 bp += 4; len -= 4;
867 for (i = 0; i < ngroup; i++) {
868 if (bp >= ep)
869 goto jp_done;
870 (void)printf("\n\t group #%u: ", i+1);
871 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
872 (void)printf("...)");
873 goto jp_done;
874 }
875 bp += advance; len -= advance;
876 if (bp + 4 > ep) {
877 (void)printf("...)");
878 goto jp_done;
879 }
880 njoin = EXTRACT_16BITS(&bp[0]);
881 nprune = EXTRACT_16BITS(&bp[2]);
882 (void)printf(", joined sources: %u, pruned sources: %u", njoin,nprune);
883 bp += 4; len -= 4;
884 for (j = 0; j < njoin; j++) {
885 (void)printf("\n\t joined source #%u: ",j+1);
886 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
887 (void)printf("...)");
888 goto jp_done;
889 }
890 bp += advance; len -= advance;
891 }
892 for (j = 0; j < nprune; j++) {
893 (void)printf("\n\t pruned source #%u: ",j+1);
894 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
895 (void)printf("...)");
896 goto jp_done;
897 }
898 bp += advance; len -= advance;
899 }
900 }
901 jp_done:
902 break;
903 }
904
905 case PIMV2_TYPE_BOOTSTRAP:
906 {
907 int i, j, frpcnt;
908 bp += 4;
909
910 /* Fragment Tag, Hash Mask len, and BSR-priority */
911 if (bp + sizeof(u_int16_t) >= ep) break;
912 (void)printf(" tag=%x", EXTRACT_16BITS(bp));
913 bp += sizeof(u_int16_t);
914 if (bp >= ep) break;
915 (void)printf(" hashmlen=%d", bp[0]);
916 if (bp + 1 >= ep) break;
917 (void)printf(" BSRprio=%d", bp[1]);
918 bp += 2;
919
920 /* Encoded-Unicast-BSR-Address */
921 if (bp >= ep) break;
922 (void)printf(" BSR=");
923 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
924 (void)printf("...");
925 break;
926 }
927 bp += advance;
928
929 for (i = 0; bp < ep; i++) {
930 /* Encoded-Group Address */
931 (void)printf(" (group%d: ", i);
932 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
933 < 0) {
934 (void)printf("...)");
935 goto bs_done;
936 }
937 bp += advance;
938
939 /* RP-Count, Frag RP-Cnt, and rsvd */
940 if (bp >= ep) {
941 (void)printf("...)");
942 goto bs_done;
943 }
944 (void)printf(" RPcnt=%d", bp[0]);
945 if (bp + 1 >= ep) {
946 (void)printf("...)");
947 goto bs_done;
948 }
949 (void)printf(" FRPcnt=%d", frpcnt = bp[1]);
950 bp += 4;
951
952 for (j = 0; j < frpcnt && bp < ep; j++) {
953 /* each RP info */
954 (void)printf(" RP%d=", j);
955 if ((advance = pimv2_addr_print(bp,
956 pimv2_unicast,
957 0)) < 0) {
958 (void)printf("...)");
959 goto bs_done;
960 }
961 bp += advance;
962
963 if (bp + 1 >= ep) {
964 (void)printf("...)");
965 goto bs_done;
966 }
967 (void)printf(",holdtime=");
968 relts_print(EXTRACT_16BITS(bp));
969 if (bp + 2 >= ep) {
970 (void)printf("...)");
971 goto bs_done;
972 }
973 (void)printf(",prio=%d", bp[2]);
974 bp += 4;
975 }
976 (void)printf(")");
977 }
978 bs_done:
979 break;
980 }
981 case PIMV2_TYPE_ASSERT:
982 bp += 4; len -= 4;
983 if (bp >= ep)
984 break;
985 (void)printf(" group=");
986 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
987 (void)printf("...");
988 break;
989 }
990 bp += advance; len -= advance;
991 if (bp >= ep)
992 break;
993 (void)printf(" src=");
994 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
995 (void)printf("...");
996 break;
997 }
998 bp += advance; len -= advance;
999 if (bp + 8 > ep)
1000 break;
1001 if (bp[0] & 0x80)
1002 (void)printf(" RPT");
1003 (void)printf(" pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff);
1004 (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4]));
1005 break;
1006
1007 case PIMV2_TYPE_CANDIDATE_RP:
1008 {
1009 int i, pfxcnt;
1010 bp += 4;
1011
1012 /* Prefix-Cnt, Priority, and Holdtime */
1013 if (bp >= ep) break;
1014 (void)printf(" prefix-cnt=%d", bp[0]);
1015 pfxcnt = bp[0];
1016 if (bp + 1 >= ep) break;
1017 (void)printf(" prio=%d", bp[1]);
1018 if (bp + 3 >= ep) break;
1019 (void)printf(" holdtime=");
1020 relts_print(EXTRACT_16BITS(&bp[2]));
1021 bp += 4;
1022
1023 /* Encoded-Unicast-RP-Address */
1024 if (bp >= ep) break;
1025 (void)printf(" RP=");
1026 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
1027 (void)printf("...");
1028 break;
1029 }
1030 bp += advance;
1031
1032 /* Encoded-Group Addresses */
1033 for (i = 0; i < pfxcnt && bp < ep; i++) {
1034 (void)printf(" Group%d=", i);
1035 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
1036 < 0) {
1037 (void)printf("...");
1038 break;
1039 }
1040 bp += advance;
1041 }
1042 break;
1043 }
1044
1045 case PIMV2_TYPE_PRUNE_REFRESH:
1046 (void)printf(" src=");
1047 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
1048 (void)printf("...");
1049 break;
1050 }
1051 bp += advance;
1052 (void)printf(" grp=");
1053 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
1054 (void)printf("...");
1055 break;
1056 }
1057 bp += advance;
1058 (void)printf(" forwarder=");
1059 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
1060 (void)printf("...");
1061 break;
1062 }
1063 bp += advance;
1064 TCHECK2(bp[0], 2);
1065 (void)printf(" TUNR ");
1066 relts_print(EXTRACT_16BITS(bp));
1067 break;
1068
1069
1070 default:
1071 (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever));
1072 break;
1073 }
1074
1075 return;
1076
1077 trunc:
1078 (void)printf("[|pim]");
1079 }
1080
1081 /*
1082 * Local Variables:
1083 * c-style: whitesmith
1084 * c-basic-offset: 8
1085 * End:
1086 */