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