]> The Tcpdump Group git mirrors - tcpdump/blob - print-icmp6.c
The patches attached to this email are required to get a fully working tcpdump
[tcpdump] / print-icmp6.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
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-icmp6.c,v 1.86 2008-02-05 19:36:13 guy Exp $";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #ifdef INET6
32
33 #include <tcpdump-stdinc.h>
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "interface.h"
39 #include "addrtoname.h"
40 #include "extract.h"
41
42 #include "ip6.h"
43 #include "icmp6.h"
44 #include "ipproto.h"
45
46 #include "udp.h"
47 #include "ah.h"
48
49 static const char *get_rtpref(u_int);
50 static const char *get_lifetime(u_int32_t);
51 static void print_lladdr(const u_char *, size_t);
52 static void icmp6_opt_print(const u_char *, int);
53 static void mld6_print(const u_char *);
54 static void mldv2_report_print(const u_char *, u_int);
55 static void mldv2_query_print(const u_char *, u_int);
56 static struct udphdr *get_upperlayer(u_char *, u_int *);
57 static void dnsname_print(const u_char *, const u_char *);
58 static void icmp6_nodeinfo_print(u_int, const u_char *, const u_char *);
59 static void icmp6_rrenum_print(const u_char *, const u_char *);
60
61 #ifndef abs
62 #define abs(a) ((0 < (a)) ? (a) : -(a))
63 #endif
64
65 /* inline the various RPL definitions */
66 #define ND_RPL_MESSAGE 0x9B
67
68 static struct tok icmp6_type_values[] = {
69 { ICMP6_DST_UNREACH, "destination unreachable"},
70 { ICMP6_PACKET_TOO_BIG, "packet too big"},
71 { ICMP6_TIME_EXCEEDED, "time exceeded in-transit"},
72 { ICMP6_PARAM_PROB, "parameter problem"},
73 { ICMP6_ECHO_REQUEST, "echo request"},
74 { ICMP6_ECHO_REPLY, "echo reply"},
75 { MLD6_LISTENER_QUERY, "multicast listener query"},
76 { MLD6_LISTENER_REPORT, "multicast listener report"},
77 { MLD6_LISTENER_DONE, "multicast listener done"},
78 { ND_ROUTER_SOLICIT, "router solicitation"},
79 { ND_ROUTER_ADVERT, "router advertisement"},
80 { ND_NEIGHBOR_SOLICIT, "neighbor solicitation"},
81 { ND_NEIGHBOR_ADVERT, "neighbor advertisement"},
82 { ND_REDIRECT, "redirect"},
83 { ICMP6_ROUTER_RENUMBERING, "router renumbering"},
84 { IND_SOLICIT, "inverse neighbor solicitation"},
85 { IND_ADVERT, "inverse neighbor advertisement"},
86 { MLDV2_LISTENER_REPORT, "multicast listener report v2"},
87 { ICMP6_HADISCOV_REQUEST, "ha discovery request"},
88 { ICMP6_HADISCOV_REPLY, "ha discovery reply"},
89 { ICMP6_MOBILEPREFIX_SOLICIT, "mobile router solicitation"},
90 { ICMP6_MOBILEPREFIX_ADVERT, "mobile router advertisement"},
91 { ICMP6_WRUREQUEST, "who-are-you request"},
92 { ICMP6_WRUREPLY, "who-are-you reply"},
93 { ICMP6_NI_QUERY, "node information query"},
94 { ICMP6_NI_REPLY, "node information reply"},
95 { MLD6_MTRACE, "mtrace message"},
96 { MLD6_MTRACE_RESP, "mtrace response"},
97 { ND_RPL_MESSAGE, "RPL"},
98 { 0, NULL }
99 };
100
101 static struct tok icmp6_dst_unreach_code_values[] = {
102 { ICMP6_DST_UNREACH_NOROUTE, "unreachable route" },
103 { ICMP6_DST_UNREACH_ADMIN, " unreachable prohibited"},
104 { ICMP6_DST_UNREACH_BEYONDSCOPE, "beyond scope"},
105 { ICMP6_DST_UNREACH_ADDR, "unreachable address"},
106 { ICMP6_DST_UNREACH_NOPORT, "unreachable port"},
107 { 0, NULL }
108 };
109
110 static struct tok icmp6_opt_pi_flag_values[] = {
111 { ND_OPT_PI_FLAG_ONLINK, "onlink" },
112 { ND_OPT_PI_FLAG_AUTO, "auto" },
113 { ND_OPT_PI_FLAG_ROUTER, "router" },
114 { 0, NULL }
115 };
116
117 static struct tok icmp6_opt_ra_flag_values[] = {
118 { ND_RA_FLAG_MANAGED, "managed" },
119 { ND_RA_FLAG_OTHER, "other stateful"},
120 { ND_RA_FLAG_HOME_AGENT, "home agent"},
121 { 0, NULL }
122 };
123
124 static struct tok icmp6_nd_na_flag_values[] = {
125 { ND_NA_FLAG_ROUTER, "router" },
126 { ND_NA_FLAG_SOLICITED, "solicited" },
127 { ND_NA_FLAG_OVERRIDE, "override" },
128 { 0, NULL }
129 };
130
131
132 static struct tok icmp6_opt_values[] = {
133 { ND_OPT_SOURCE_LINKADDR, "source link-address"},
134 { ND_OPT_TARGET_LINKADDR, "destination link-address"},
135 { ND_OPT_PREFIX_INFORMATION, "prefix info"},
136 { ND_OPT_REDIRECTED_HEADER, "redirected header"},
137 { ND_OPT_MTU, "mtu"},
138 { ND_OPT_ADVINTERVAL, "advertisement interval"},
139 { ND_OPT_HOMEAGENT_INFO, "homeagent information"},
140 { ND_OPT_ROUTE_INFO, "route info"},
141 { 0, NULL }
142 };
143
144 /* mldv2 report types */
145 static struct tok mldv2report2str[] = {
146 { 1, "is_in" },
147 { 2, "is_ex" },
148 { 3, "to_in" },
149 { 4, "to_ex" },
150 { 5, "allow" },
151 { 6, "block" },
152 { 0, NULL }
153 };
154
155 static const char *
156 get_rtpref(u_int v)
157 {
158 static const char *rtpref_str[] = {
159 "medium", /* 00 */
160 "high", /* 01 */
161 "rsv", /* 10 */
162 "low" /* 11 */
163 };
164
165 return rtpref_str[((v & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff];
166 }
167
168 static const char *
169 get_lifetime(u_int32_t v)
170 {
171 static char buf[20];
172
173 if (v == (u_int32_t)~0UL)
174 return "infinity";
175 else {
176 snprintf(buf, sizeof(buf), "%u", v);
177 return buf;
178 }
179 }
180
181 static void
182 print_lladdr(const u_int8_t *p, size_t l)
183 {
184 const u_int8_t *ep, *q;
185
186 q = p;
187 ep = p + l;
188 while (l > 0 && q < ep) {
189 if (q > p)
190 printf(":");
191 printf("%02x", *q++);
192 l--;
193 }
194 }
195
196 static int icmp6_cksum(const struct ip6_hdr *ip6, const struct icmp6_hdr *icp,
197 u_int len)
198 {
199 size_t i;
200 register const u_int16_t *sp;
201 u_int32_t sum;
202 union {
203 struct {
204 struct in6_addr ph_src;
205 struct in6_addr ph_dst;
206 u_int32_t ph_len;
207 u_int8_t ph_zero[3];
208 u_int8_t ph_nxt;
209 } ph;
210 u_int16_t pa[20];
211 } phu;
212
213 /* pseudo-header */
214 memset(&phu, 0, sizeof(phu));
215 phu.ph.ph_src = ip6->ip6_src;
216 phu.ph.ph_dst = ip6->ip6_dst;
217 phu.ph.ph_len = htonl(len);
218 phu.ph.ph_nxt = IPPROTO_ICMPV6;
219
220 sum = 0;
221 for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++)
222 sum += phu.pa[i];
223
224 sp = (const u_int16_t *)icp;
225
226 for (i = 0; i < (len & ~1); i += 2)
227 sum += *sp++;
228
229 if (len & 1)
230 sum += htons((*(const u_int8_t *)sp) << 8);
231
232 while (sum > 0xffff)
233 sum = (sum & 0xffff) + (sum >> 16);
234 sum = ~sum & 0xffff;
235
236 return (sum);
237 }
238
239 enum ND_RPL_CODE {
240 ND_RPL_DAG_IS=0x01,
241 ND_RPL_DAG_IO=0x02,
242 ND_RPL_DAO =0x04
243 };
244
245 enum ND_RPL_DIO_FLAGS {
246 ND_RPL_DIO_GROUNDED = 0x80,
247 ND_RPL_DIO_DATRIG = 0x40,
248 ND_RPL_DIO_DASUPPORT= 0x20,
249 ND_RPL_DIO_RES4 = 0x10,
250 ND_RPL_DIO_RES3 = 0x08,
251 ND_RPL_DIO_PRF_MASK = 0x07, /* 3-bit preference */
252 };
253
254 struct nd_rpl_dio {
255 u_int8_t rpl_flags;
256 u_int8_t rpl_seq;
257 u_int8_t rpl_instanceid;
258 u_int8_t rpl_dagrank;
259 u_int8_t rpl_dagid[16];
260 };
261
262 void
263 rpl_print(netdissect_options *ndo,
264 const struct icmp6_hdr *hdr,
265 const u_char *bp, u_int length)
266 {
267 struct nd_rpl_dio *dio = (struct nd_rpl_dio *)bp;
268
269 ND_TCHECK(dio->rpl_dagid);
270
271 switch(hdr->icmp6_code) {
272 case ND_RPL_DAG_IS:
273 ND_PRINT((ndo, ", DAG Information Solicitation"));
274 if(ndo->ndo_vflag) {
275 }
276 break;
277 case ND_RPL_DAG_IO:
278 ND_PRINT((ndo, ", DAG Information Object"));
279 if(ndo->ndo_vflag) {
280 char dagid[65];
281 char *d = dagid;
282 int i;
283 for(i=0;i<16;i++) {
284 if(isprint(dio->rpl_dagid[i])) {
285 *d++ = dio->rpl_dagid[i];
286 } else {
287 int cnt=snprintf(d,4,"0x%02x",
288 dio->rpl_dagid[i]);
289 d += cnt;
290 }
291 }
292 *d++ = '\0';
293 ND_PRINT((ndo, " [seq:%u,instance:%u,rank:%u,dagid:%s]",
294 dio->rpl_seq,
295 dio->rpl_instanceid,
296 dio->rpl_dagrank,
297 dagid));
298 }
299 break;
300 case ND_RPL_DAO:
301 ND_PRINT((ndo, ", Destination Advertisement Object"));
302 if(ndo->ndo_vflag) {
303 }
304 break;
305 default:
306 ND_PRINT((ndo, ", RPL message, unknown code %u",hdr->icmp6_code));
307 break;
308 }
309 return;
310 trunc:
311 ND_PRINT((ndo," [|truncated]"));
312 return;
313
314 }
315
316
317 void
318 icmp6_print(netdissect_options *ndo,
319 const u_char *bp, u_int length, const u_char *bp2, int fragmented)
320 {
321 const struct icmp6_hdr *dp;
322 const struct ip6_hdr *ip;
323 const struct ip6_hdr *oip;
324 const struct udphdr *ouh;
325 int dport;
326 const u_char *ep;
327 u_int prot;
328
329 dp = (struct icmp6_hdr *)bp;
330 ip = (struct ip6_hdr *)bp2;
331 oip = (struct ip6_hdr *)(dp + 1);
332 /* 'ep' points to the end of available data. */
333 ep = snapend;
334
335 TCHECK(dp->icmp6_cksum);
336
337 if (vflag && !fragmented) {
338 int sum = dp->icmp6_cksum;
339
340 if (TTEST2(bp[0], length)) {
341 sum = icmp6_cksum(ip, dp, length);
342 if (sum != 0)
343 (void)printf("[bad icmp6 cksum %x!] ", sum);
344 else
345 (void)printf("[icmp6 sum ok] ");
346 }
347 }
348
349 printf("ICMP6, %s", tok2str(icmp6_type_values,"unknown icmp6 type (%u)",dp->icmp6_type));
350
351 /* display cosmetics: print the packet length for printer that use the vflag now */
352 if (vflag && (dp->icmp6_type ==
353 ND_ROUTER_SOLICIT ||
354 ND_ROUTER_ADVERT ||
355 ND_NEIGHBOR_ADVERT ||
356 ND_NEIGHBOR_SOLICIT ||
357 ND_REDIRECT ||
358 ICMP6_HADISCOV_REPLY ||
359 ICMP6_MOBILEPREFIX_ADVERT ))
360 printf(", length %u", length);
361
362 switch (dp->icmp6_type) {
363 case ICMP6_DST_UNREACH:
364 TCHECK(oip->ip6_dst);
365 printf(", %s", tok2str(icmp6_dst_unreach_code_values,"unknown unreach code (%u)",dp->icmp6_code));
366 switch (dp->icmp6_code) {
367
368 case ICMP6_DST_UNREACH_NOROUTE: /* fall through */
369 case ICMP6_DST_UNREACH_ADMIN:
370 case ICMP6_DST_UNREACH_ADDR:
371 printf(" %s",ip6addr_string(&oip->ip6_dst));
372 break;
373 case ICMP6_DST_UNREACH_BEYONDSCOPE:
374 printf(" %s, source address %s",
375 ip6addr_string(&oip->ip6_dst),
376 ip6addr_string(&oip->ip6_src));
377 break;
378 case ICMP6_DST_UNREACH_NOPORT:
379 if ((ouh = get_upperlayer((u_char *)oip, &prot))
380 == NULL)
381 goto trunc;
382
383 dport = EXTRACT_16BITS(&ouh->uh_dport);
384 switch (prot) {
385 case IPPROTO_TCP:
386 printf(", %s tcp port %s",
387 ip6addr_string(&oip->ip6_dst),
388 tcpport_string(dport));
389 break;
390 case IPPROTO_UDP:
391 printf(", %s udp port %s",
392 ip6addr_string(&oip->ip6_dst),
393 udpport_string(dport));
394 break;
395 default:
396 printf(", %s protocol %d port %d unreachable",
397 ip6addr_string(&oip->ip6_dst),
398 oip->ip6_nxt, dport);
399 break;
400 }
401 break;
402 default:
403 if (vflag <= 1) {
404 print_unknown_data(bp,"\n\t",length);
405 return;
406 }
407 break;
408 }
409 break;
410 case ICMP6_PACKET_TOO_BIG:
411 TCHECK(dp->icmp6_mtu);
412 printf(", mtu %u", EXTRACT_32BITS(&dp->icmp6_mtu));
413 break;
414 case ICMP6_TIME_EXCEEDED:
415 TCHECK(oip->ip6_dst);
416 switch (dp->icmp6_code) {
417 case ICMP6_TIME_EXCEED_TRANSIT:
418 printf(" for %s",
419 ip6addr_string(&oip->ip6_dst));
420 break;
421 case ICMP6_TIME_EXCEED_REASSEMBLY:
422 printf(" (reassembly)");
423 break;
424 default:
425 printf(", unknown code (%u)", dp->icmp6_code);
426 break;
427 }
428 break;
429 case ICMP6_PARAM_PROB:
430 TCHECK(oip->ip6_dst);
431 switch (dp->icmp6_code) {
432 case ICMP6_PARAMPROB_HEADER:
433 printf(", errorneous - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr));
434 break;
435 case ICMP6_PARAMPROB_NEXTHEADER:
436 printf(", next header - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr));
437 break;
438 case ICMP6_PARAMPROB_OPTION:
439 printf(", option - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr));
440 break;
441 default:
442 printf(", code-#%d",
443 dp->icmp6_code);
444 break;
445 }
446 break;
447 case ICMP6_ECHO_REQUEST:
448 case ICMP6_ECHO_REPLY:
449 TCHECK(dp->icmp6_seq);
450 printf(", seq %u", EXTRACT_16BITS(&dp->icmp6_seq));
451 break;
452 case ICMP6_MEMBERSHIP_QUERY:
453 if (length == MLD_MINLEN) {
454 mld6_print((const u_char *)dp);
455 } else if (length >= MLDV2_MINLEN) {
456 printf("v2 ");
457 mldv2_query_print((const u_char *)dp, length);
458 } else {
459 printf(" unknown-version (len %u) ", length);
460 }
461 break;
462 case ICMP6_MEMBERSHIP_REPORT:
463 mld6_print((const u_char *)dp);
464 break;
465 case ICMP6_MEMBERSHIP_REDUCTION:
466 mld6_print((const u_char *)dp);
467 break;
468 case ND_ROUTER_SOLICIT:
469 #define RTSOLLEN 8
470 if (vflag) {
471 icmp6_opt_print((const u_char *)dp + RTSOLLEN,
472 length - RTSOLLEN);
473 }
474 break;
475 case ND_ROUTER_ADVERT:
476 #define RTADVLEN 16
477 if (vflag) {
478 struct nd_router_advert *p;
479
480 p = (struct nd_router_advert *)dp;
481 TCHECK(p->nd_ra_retransmit);
482 printf("\n\thop limit %u, Flags [%s]" \
483 ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
484 (u_int)p->nd_ra_curhoplimit,
485 bittok2str(icmp6_opt_ra_flag_values,"none",(p->nd_ra_flags_reserved)),
486 get_rtpref(p->nd_ra_flags_reserved),
487 EXTRACT_16BITS(&p->nd_ra_router_lifetime),
488 EXTRACT_32BITS(&p->nd_ra_reachable),
489 EXTRACT_32BITS(&p->nd_ra_retransmit));
490
491 icmp6_opt_print((const u_char *)dp + RTADVLEN,
492 length - RTADVLEN);
493 }
494 break;
495 case ND_NEIGHBOR_SOLICIT:
496 {
497 struct nd_neighbor_solicit *p;
498 p = (struct nd_neighbor_solicit *)dp;
499 TCHECK(p->nd_ns_target);
500 printf(", who has %s", ip6addr_string(&p->nd_ns_target));
501 if (vflag) {
502 #define NDSOLLEN 24
503 icmp6_opt_print((const u_char *)dp + NDSOLLEN,
504 length - NDSOLLEN);
505 }
506 }
507 break;
508 case ND_NEIGHBOR_ADVERT:
509 {
510 struct nd_neighbor_advert *p;
511
512 p = (struct nd_neighbor_advert *)dp;
513 TCHECK(p->nd_na_target);
514 printf(", tgt is %s",
515 ip6addr_string(&p->nd_na_target));
516 if (vflag) {
517 printf(", Flags [%s]",
518 bittok2str(icmp6_nd_na_flag_values,
519 "none",
520 EXTRACT_32BITS(&p->nd_na_flags_reserved)));
521 #define NDADVLEN 24
522 icmp6_opt_print((const u_char *)dp + NDADVLEN,
523 length - NDADVLEN);
524 #undef NDADVLEN
525 }
526 }
527 break;
528 case ND_REDIRECT:
529 #define RDR(i) ((struct nd_redirect *)(i))
530 TCHECK(RDR(dp)->nd_rd_dst);
531 printf(", %s", getname6((const u_char *)&RDR(dp)->nd_rd_dst));
532 TCHECK(RDR(dp)->nd_rd_target);
533 printf(" to %s",
534 getname6((const u_char*)&RDR(dp)->nd_rd_target));
535 #define REDIRECTLEN 40
536 if (vflag) {
537 icmp6_opt_print((const u_char *)dp + REDIRECTLEN,
538 length - REDIRECTLEN);
539 }
540 break;
541 #undef REDIRECTLEN
542 #undef RDR
543 case ICMP6_ROUTER_RENUMBERING:
544 icmp6_rrenum_print(bp, ep);
545 break;
546 case ICMP6_NI_QUERY:
547 case ICMP6_NI_REPLY:
548 icmp6_nodeinfo_print(length, bp, ep);
549 break;
550 case IND_SOLICIT:
551 case IND_ADVERT:
552 break;
553 case ICMP6_V2_MEMBERSHIP_REPORT:
554 mldv2_report_print((const u_char *) dp, length);
555 break;
556 case ICMP6_MOBILEPREFIX_SOLICIT: /* fall through */
557 case ICMP6_HADISCOV_REQUEST:
558 TCHECK(dp->icmp6_data16[0]);
559 printf(", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0]));
560 break;
561 case ICMP6_HADISCOV_REPLY:
562 if (vflag) {
563 struct in6_addr *in6;
564 u_char *cp;
565
566 TCHECK(dp->icmp6_data16[0]);
567 printf(", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0]));
568 cp = (u_char *)dp + length;
569 in6 = (struct in6_addr *)(dp + 1);
570 for (; (u_char *)in6 < cp; in6++) {
571 TCHECK(*in6);
572 printf(", %s", ip6addr_string(in6));
573 }
574 }
575 break;
576 case ICMP6_MOBILEPREFIX_ADVERT:
577 if (vflag) {
578 TCHECK(dp->icmp6_data16[0]);
579 printf(", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0]));
580 if (dp->icmp6_data16[1] & 0xc0)
581 printf(" ");
582 if (dp->icmp6_data16[1] & 0x80)
583 printf("M");
584 if (dp->icmp6_data16[1] & 0x40)
585 printf("O");
586 #define MPADVLEN 8
587 icmp6_opt_print((const u_char *)dp + MPADVLEN,
588 length - MPADVLEN);
589 }
590 break;
591 case ND_RPL_MESSAGE:
592 rpl_print(ndo, dp, &dp->icmp6_data8[0], length);
593 break;
594 default:
595 printf(", length %u", length);
596 if (vflag <= 1)
597 print_unknown_data(bp,"\n\t", length);
598 return;
599 }
600 if (!vflag)
601 printf(", length %u", length);
602 return;
603 trunc:
604 fputs("[|icmp6]", stdout);
605 }
606
607 static struct udphdr *
608 get_upperlayer(u_char *bp, u_int *prot)
609 {
610 const u_char *ep;
611 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
612 struct udphdr *uh;
613 struct ip6_hbh *hbh;
614 struct ip6_frag *fragh;
615 struct ah *ah;
616 u_int nh;
617 int hlen;
618
619 /* 'ep' points to the end of available data. */
620 ep = snapend;
621
622 if (!TTEST(ip6->ip6_nxt))
623 return NULL;
624
625 nh = ip6->ip6_nxt;
626 hlen = sizeof(struct ip6_hdr);
627
628 while (bp < ep) {
629 bp += hlen;
630
631 switch(nh) {
632 case IPPROTO_UDP:
633 case IPPROTO_TCP:
634 uh = (struct udphdr *)bp;
635 if (TTEST(uh->uh_dport)) {
636 *prot = nh;
637 return(uh);
638 }
639 else
640 return(NULL);
641 /* NOTREACHED */
642
643 case IPPROTO_HOPOPTS:
644 case IPPROTO_DSTOPTS:
645 case IPPROTO_ROUTING:
646 hbh = (struct ip6_hbh *)bp;
647 if (!TTEST(hbh->ip6h_len))
648 return(NULL);
649 nh = hbh->ip6h_nxt;
650 hlen = (hbh->ip6h_len + 1) << 3;
651 break;
652
653 case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
654 fragh = (struct ip6_frag *)bp;
655 if (!TTEST(fragh->ip6f_offlg))
656 return(NULL);
657 /* fragments with non-zero offset are meaningless */
658 if ((EXTRACT_16BITS(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
659 return(NULL);
660 nh = fragh->ip6f_nxt;
661 hlen = sizeof(struct ip6_frag);
662 break;
663
664 case IPPROTO_AH:
665 ah = (struct ah *)bp;
666 if (!TTEST(ah->ah_len))
667 return(NULL);
668 nh = ah->ah_nxt;
669 hlen = (ah->ah_len + 2) << 2;
670 break;
671
672 default: /* unknown or undecodable header */
673 *prot = nh; /* meaningless, but set here anyway */
674 return(NULL);
675 }
676 }
677
678 return(NULL); /* should be notreached, though */
679 }
680
681 static void
682 icmp6_opt_print(const u_char *bp, int resid)
683 {
684 const struct nd_opt_hdr *op;
685 const struct nd_opt_hdr *opl; /* why there's no struct? */
686 const struct nd_opt_prefix_info *opp;
687 const struct icmp6_opts_redirect *opr;
688 const struct nd_opt_mtu *opm;
689 const struct nd_opt_advinterval *opa;
690 const struct nd_opt_homeagent_info *oph;
691 const struct nd_opt_route_info *opri;
692 const u_char *cp, *ep;
693 struct in6_addr in6, *in6p;
694 size_t l;
695
696 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
697
698 cp = bp;
699 /* 'ep' points to the end of available data. */
700 ep = snapend;
701
702 while (cp < ep) {
703 op = (struct nd_opt_hdr *)cp;
704
705 ECHECK(op->nd_opt_len);
706 if (resid <= 0)
707 return;
708 if (op->nd_opt_len == 0)
709 goto trunc;
710 if (cp + (op->nd_opt_len << 3) > ep)
711 goto trunc;
712
713 printf("\n\t %s option (%u), length %u (%u): ",
714 tok2str(icmp6_opt_values, "unknown", op->nd_opt_type),
715 op->nd_opt_type,
716 op->nd_opt_len << 3,
717 op->nd_opt_len);
718
719 switch (op->nd_opt_type) {
720 case ND_OPT_SOURCE_LINKADDR:
721 opl = (struct nd_opt_hdr *)op;
722 l = (op->nd_opt_len << 3) - 2;
723 print_lladdr(cp + 2, l);
724 break;
725 case ND_OPT_TARGET_LINKADDR:
726 opl = (struct nd_opt_hdr *)op;
727 l = (op->nd_opt_len << 3) - 2;
728 print_lladdr(cp + 2, l);
729 break;
730 case ND_OPT_PREFIX_INFORMATION:
731 opp = (struct nd_opt_prefix_info *)op;
732 TCHECK(opp->nd_opt_pi_prefix);
733 printf("%s/%u%s, Flags [%s], valid time %ss",
734 ip6addr_string(&opp->nd_opt_pi_prefix),
735 opp->nd_opt_pi_prefix_len,
736 (op->nd_opt_len != 4) ? "badlen" : "",
737 bittok2str(icmp6_opt_pi_flag_values, "none", opp->nd_opt_pi_flags_reserved),
738 get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_valid_time)));
739 printf(", pref. time %ss", get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_preferred_time)));
740 break;
741 case ND_OPT_REDIRECTED_HEADER:
742 opr = (struct icmp6_opts_redirect *)op;
743 print_unknown_data(bp,"\n\t ",op->nd_opt_len<<3);
744 /* xxx */
745 break;
746 case ND_OPT_MTU:
747 opm = (struct nd_opt_mtu *)op;
748 TCHECK(opm->nd_opt_mtu_mtu);
749 printf(" %u%s",
750 EXTRACT_32BITS(&opm->nd_opt_mtu_mtu),
751 (op->nd_opt_len != 1) ? "bad option length" : "" );
752 break;
753 case ND_OPT_ADVINTERVAL:
754 opa = (struct nd_opt_advinterval *)op;
755 TCHECK(opa->nd_opt_adv_interval);
756 printf(" %us", EXTRACT_32BITS(&opa->nd_opt_adv_interval));
757 break;
758 case ND_OPT_HOMEAGENT_INFO:
759 oph = (struct nd_opt_homeagent_info *)op;
760 TCHECK(oph->nd_opt_hai_lifetime);
761 printf(" preference %u, lifetime %u",
762 EXTRACT_16BITS(&oph->nd_opt_hai_preference),
763 EXTRACT_16BITS(&oph->nd_opt_hai_lifetime));
764 break;
765 case ND_OPT_ROUTE_INFO:
766 opri = (struct nd_opt_route_info *)op;
767 TCHECK(opri->nd_opt_rti_lifetime);
768 memset(&in6, 0, sizeof(in6));
769 in6p = (struct in6_addr *)(opri + 1);
770 switch (op->nd_opt_len) {
771 case 1:
772 break;
773 case 2:
774 TCHECK2(*in6p, 8);
775 memcpy(&in6, opri + 1, 8);
776 break;
777 case 3:
778 TCHECK(*in6p);
779 memcpy(&in6, opri + 1, sizeof(in6));
780 break;
781 default:
782 goto trunc;
783 }
784 printf(" %s/%u", ip6addr_string(&in6),
785 opri->nd_opt_rti_prefixlen);
786 printf(", pref=%s", get_rtpref(opri->nd_opt_rti_flags));
787 printf(", lifetime=%s",
788 get_lifetime(EXTRACT_32BITS(&opri->nd_opt_rti_lifetime)));
789 break;
790 default:
791 if (vflag <= 1) {
792 print_unknown_data(cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
793 return;
794 }
795 break;
796 }
797 /* do we want to see an additional hexdump ? */
798 if (vflag> 1)
799 print_unknown_data(cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
800
801 cp += op->nd_opt_len << 3;
802 resid -= op->nd_opt_len << 3;
803 }
804 return;
805
806 trunc:
807 fputs("[ndp opt]", stdout);
808 return;
809 #undef ECHECK
810 }
811
812 static void
813 mld6_print(const u_char *bp)
814 {
815 struct mld6_hdr *mp = (struct mld6_hdr *)bp;
816 const u_char *ep;
817
818 /* 'ep' points to the end of available data. */
819 ep = snapend;
820
821 if ((u_char *)mp + sizeof(*mp) > ep)
822 return;
823
824 printf("max resp delay: %d ", EXTRACT_16BITS(&mp->mld6_maxdelay));
825 printf("addr: %s", ip6addr_string(&mp->mld6_addr));
826 }
827
828 static void
829 mldv2_report_print(const u_char *bp, u_int len)
830 {
831 struct icmp6_hdr *icp = (struct icmp6_hdr *) bp;
832 u_int group, nsrcs, ngroups;
833 u_int i, j;
834
835 /* Minimum len is 8 */
836 if (len < 8) {
837 printf(" [invalid len %d]", len);
838 return;
839 }
840
841 TCHECK(icp->icmp6_data16[1]);
842 ngroups = ntohs(icp->icmp6_data16[1]);
843 printf(", %d group record(s)", ngroups);
844 if (vflag > 0) {
845 /* Print the group records */
846 group = 8;
847 for (i = 0; i < ngroups; i++) {
848 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
849 if (len < group + 20) {
850 printf(" [invalid number of groups]");
851 return;
852 }
853 TCHECK2(bp[group + 4], sizeof(struct in6_addr));
854 printf(" [gaddr %s", ip6addr_string(&bp[group + 4]));
855 printf(" %s", tok2str(mldv2report2str, " [v2-report-#%d]",
856 bp[group]));
857 nsrcs = (bp[group + 2] << 8) + bp[group + 3];
858 /* Check the number of sources and print them */
859 if (len < group + 20 + (nsrcs * sizeof(struct in6_addr))) {
860 printf(" [invalid number of sources %d]", nsrcs);
861 return;
862 }
863 if (vflag == 1)
864 printf(", %d source(s)", nsrcs);
865 else {
866 /* Print the sources */
867 (void)printf(" {");
868 for (j = 0; j < nsrcs; j++) {
869 TCHECK2(bp[group + 20 + j * sizeof(struct in6_addr)],
870 sizeof(struct in6_addr));
871 printf(" %s", ip6addr_string(&bp[group + 20 + j * sizeof(struct in6_addr)]));
872 }
873 (void)printf(" }");
874 }
875 /* Next group record */
876 group += 20 + nsrcs * sizeof(struct in6_addr);
877 printf("]");
878 }
879 }
880 return;
881 trunc:
882 (void)printf("[|icmp6]");
883 return;
884 }
885
886 static void
887 mldv2_query_print(const u_char *bp, u_int len)
888 {
889 struct icmp6_hdr *icp = (struct icmp6_hdr *) bp;
890 u_int mrc;
891 int mrt, qqi;
892 u_int nsrcs;
893 register u_int i;
894
895 /* Minimum len is 28 */
896 if (len < 28) {
897 printf(" [invalid len %d]", len);
898 return;
899 }
900 TCHECK(icp->icmp6_data16[0]);
901 mrc = ntohs(icp->icmp6_data16[0]);
902 if (mrc < 32768) {
903 mrt = mrc;
904 } else {
905 mrt = ((mrc & 0x0fff) | 0x1000) << (((mrc & 0x7000) >> 12) + 3);
906 }
907 if (vflag) {
908 (void)printf(" [max resp delay=%d]", mrt);
909 }
910 TCHECK2(bp[8], sizeof(struct in6_addr));
911 printf(" [gaddr %s", ip6addr_string(&bp[8]));
912
913 if (vflag) {
914 TCHECK(bp[25]);
915 if (bp[24] & 0x08) {
916 printf(" sflag");
917 }
918 if (bp[24] & 0x07) {
919 printf(" robustness=%d", bp[24] & 0x07);
920 }
921 if (bp[25] < 128) {
922 qqi = bp[25];
923 } else {
924 qqi = ((bp[25] & 0x0f) | 0x10) << (((bp[25] & 0x70) >> 4) + 3);
925 }
926 printf(" qqi=%d", qqi);
927 }
928
929 TCHECK2(bp[26], 2);
930 nsrcs = ntohs(*(u_short *)&bp[26]);
931 if (nsrcs > 0) {
932 if (len < 28 + nsrcs * sizeof(struct in6_addr))
933 printf(" [invalid number of sources]");
934 else if (vflag > 1) {
935 printf(" {");
936 for (i = 0; i < nsrcs; i++) {
937 TCHECK2(bp[28 + i * sizeof(struct in6_addr)],
938 sizeof(struct in6_addr));
939 printf(" %s", ip6addr_string(&bp[28 + i * sizeof(struct in6_addr)]));
940 }
941 printf(" }");
942 } else
943 printf(", %d source(s)", nsrcs);
944 }
945 printf("]");
946 return;
947 trunc:
948 (void)printf("[|icmp6]");
949 return;
950 }
951
952 static void
953 dnsname_print(const u_char *cp, const u_char *ep)
954 {
955 int i;
956
957 /* DNS name decoding - no decompression */
958 printf(", \"");
959 while (cp < ep) {
960 i = *cp++;
961 if (i) {
962 if (i > ep - cp) {
963 printf("???");
964 break;
965 }
966 while (i-- && cp < ep) {
967 safeputchar(*cp);
968 cp++;
969 }
970 if (cp + 1 < ep && *cp)
971 printf(".");
972 } else {
973 if (cp == ep) {
974 /* FQDN */
975 printf(".");
976 } else if (cp + 1 == ep && *cp == '\0') {
977 /* truncated */
978 } else {
979 /* invalid */
980 printf("???");
981 }
982 break;
983 }
984 }
985 printf("\"");
986 }
987
988 static void
989 icmp6_nodeinfo_print(u_int icmp6len, const u_char *bp, const u_char *ep)
990 {
991 struct icmp6_nodeinfo *ni6;
992 struct icmp6_hdr *dp;
993 const u_char *cp;
994 size_t siz, i;
995 int needcomma;
996
997 if (ep < bp)
998 return;
999 dp = (struct icmp6_hdr *)bp;
1000 ni6 = (struct icmp6_nodeinfo *)bp;
1001 siz = ep - bp;
1002
1003 switch (ni6->ni_type) {
1004 case ICMP6_NI_QUERY:
1005 if (siz == sizeof(*dp) + 4) {
1006 /* KAME who-are-you */
1007 printf(" who-are-you request");
1008 break;
1009 }
1010 printf(" node information query");
1011
1012 TCHECK2(*dp, sizeof(*ni6));
1013 ni6 = (struct icmp6_nodeinfo *)dp;
1014 printf(" ("); /*)*/
1015 switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
1016 case NI_QTYPE_NOOP:
1017 printf("noop");
1018 break;
1019 case NI_QTYPE_SUPTYPES:
1020 printf("supported qtypes");
1021 i = EXTRACT_16BITS(&ni6->ni_flags);
1022 if (i)
1023 printf(" [%s]", (i & 0x01) ? "C" : "");
1024 break;
1025 break;
1026 case NI_QTYPE_FQDN:
1027 printf("DNS name");
1028 break;
1029 case NI_QTYPE_NODEADDR:
1030 printf("node addresses");
1031 i = ni6->ni_flags;
1032 if (!i)
1033 break;
1034 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
1035 printf(" [%s%s%s%s%s%s]",
1036 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1037 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1038 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1039 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1040 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1041 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "");
1042 break;
1043 default:
1044 printf("unknown");
1045 break;
1046 }
1047
1048 if (ni6->ni_qtype == NI_QTYPE_NOOP ||
1049 ni6->ni_qtype == NI_QTYPE_SUPTYPES) {
1050 if (siz != sizeof(*ni6))
1051 if (vflag)
1052 printf(", invalid len");
1053 /*(*/
1054 printf(")");
1055 break;
1056 }
1057
1058
1059 /* XXX backward compat, icmp-name-lookup-03 */
1060 if (siz == sizeof(*ni6)) {
1061 printf(", 03 draft");
1062 /*(*/
1063 printf(")");
1064 break;
1065 }
1066
1067 switch (ni6->ni_code) {
1068 case ICMP6_NI_SUBJ_IPV6:
1069 if (!TTEST2(*dp,
1070 sizeof(*ni6) + sizeof(struct in6_addr)))
1071 break;
1072 if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) {
1073 if (vflag)
1074 printf(", invalid subject len");
1075 break;
1076 }
1077 printf(", subject=%s",
1078 getname6((const u_char *)(ni6 + 1)));
1079 break;
1080 case ICMP6_NI_SUBJ_FQDN:
1081 printf(", subject=DNS name");
1082 cp = (const u_char *)(ni6 + 1);
1083 if (cp[0] == ep - cp - 1) {
1084 /* icmp-name-lookup-03, pascal string */
1085 if (vflag)
1086 printf(", 03 draft");
1087 cp++;
1088 printf(", \"");
1089 while (cp < ep) {
1090 safeputchar(*cp);
1091 cp++;
1092 }
1093 printf("\"");
1094 } else
1095 dnsname_print(cp, ep);
1096 break;
1097 case ICMP6_NI_SUBJ_IPV4:
1098 if (!TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr)))
1099 break;
1100 if (siz != sizeof(*ni6) + sizeof(struct in_addr)) {
1101 if (vflag)
1102 printf(", invalid subject len");
1103 break;
1104 }
1105 printf(", subject=%s",
1106 getname((const u_char *)(ni6 + 1)));
1107 break;
1108 default:
1109 printf(", unknown subject");
1110 break;
1111 }
1112
1113 /*(*/
1114 printf(")");
1115 break;
1116
1117 case ICMP6_NI_REPLY:
1118 if (icmp6len > siz) {
1119 printf("[|icmp6: node information reply]");
1120 break;
1121 }
1122
1123 needcomma = 0;
1124
1125 ni6 = (struct icmp6_nodeinfo *)dp;
1126 printf(" node information reply");
1127 printf(" ("); /*)*/
1128 switch (ni6->ni_code) {
1129 case ICMP6_NI_SUCCESS:
1130 if (vflag) {
1131 printf("success");
1132 needcomma++;
1133 }
1134 break;
1135 case ICMP6_NI_REFUSED:
1136 printf("refused");
1137 needcomma++;
1138 if (siz != sizeof(*ni6))
1139 if (vflag)
1140 printf(", invalid length");
1141 break;
1142 case ICMP6_NI_UNKNOWN:
1143 printf("unknown");
1144 needcomma++;
1145 if (siz != sizeof(*ni6))
1146 if (vflag)
1147 printf(", invalid length");
1148 break;
1149 }
1150
1151 if (ni6->ni_code != ICMP6_NI_SUCCESS) {
1152 /*(*/
1153 printf(")");
1154 break;
1155 }
1156
1157 switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
1158 case NI_QTYPE_NOOP:
1159 if (needcomma)
1160 printf(", ");
1161 printf("noop");
1162 if (siz != sizeof(*ni6))
1163 if (vflag)
1164 printf(", invalid length");
1165 break;
1166 case NI_QTYPE_SUPTYPES:
1167 if (needcomma)
1168 printf(", ");
1169 printf("supported qtypes");
1170 i = EXTRACT_16BITS(&ni6->ni_flags);
1171 if (i)
1172 printf(" [%s]", (i & 0x01) ? "C" : "");
1173 break;
1174 case NI_QTYPE_FQDN:
1175 if (needcomma)
1176 printf(", ");
1177 printf("DNS name");
1178 cp = (const u_char *)(ni6 + 1) + 4;
1179 if (cp[0] == ep - cp - 1) {
1180 /* icmp-name-lookup-03, pascal string */
1181 if (vflag)
1182 printf(", 03 draft");
1183 cp++;
1184 printf(", \"");
1185 while (cp < ep) {
1186 safeputchar(*cp);
1187 cp++;
1188 }
1189 printf("\"");
1190 } else
1191 dnsname_print(cp, ep);
1192 if ((EXTRACT_16BITS(&ni6->ni_flags) & 0x01) != 0)
1193 printf(" [TTL=%u]", *(u_int32_t *)(ni6 + 1));
1194 break;
1195 case NI_QTYPE_NODEADDR:
1196 if (needcomma)
1197 printf(", ");
1198 printf("node addresses");
1199 i = sizeof(*ni6);
1200 while (i < siz) {
1201 if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz)
1202 break;
1203 printf(" %s", getname6(bp + i));
1204 i += sizeof(struct in6_addr);
1205 printf("(%d)", (int32_t)EXTRACT_32BITS(bp + i));
1206 i += sizeof(int32_t);
1207 }
1208 i = ni6->ni_flags;
1209 if (!i)
1210 break;
1211 printf(" [%s%s%s%s%s%s%s]",
1212 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1213 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1214 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1215 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1216 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1217 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
1218 (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : "");
1219 break;
1220 default:
1221 if (needcomma)
1222 printf(", ");
1223 printf("unknown");
1224 break;
1225 }
1226
1227 /*(*/
1228 printf(")");
1229 break;
1230 }
1231 return;
1232
1233 trunc:
1234 fputs("[|icmp6]", stdout);
1235 }
1236
1237 static void
1238 icmp6_rrenum_print(const u_char *bp, const u_char *ep)
1239 {
1240 struct icmp6_router_renum *rr6;
1241 const char *cp;
1242 struct rr_pco_match *match;
1243 struct rr_pco_use *use;
1244 char hbuf[NI_MAXHOST];
1245 int n;
1246
1247 if (ep < bp)
1248 return;
1249 rr6 = (struct icmp6_router_renum *)bp;
1250 cp = (const char *)(rr6 + 1);
1251
1252 TCHECK(rr6->rr_reserved);
1253 switch (rr6->rr_code) {
1254 case ICMP6_ROUTER_RENUMBERING_COMMAND:
1255 printf("router renum: command");
1256 break;
1257 case ICMP6_ROUTER_RENUMBERING_RESULT:
1258 printf("router renum: result");
1259 break;
1260 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET:
1261 printf("router renum: sequence number reset");
1262 break;
1263 default:
1264 printf("router renum: code-#%d", rr6->rr_code);
1265 break;
1266 }
1267
1268 printf(", seq=%u", EXTRACT_32BITS(&rr6->rr_seqnum));
1269
1270 if (vflag) {
1271 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1272 printf("["); /*]*/
1273 if (rr6->rr_flags) {
1274 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"),
1275 F(ICMP6_RR_FLAGS_REQRESULT, "R"),
1276 F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"),
1277 F(ICMP6_RR_FLAGS_SPECSITE, "S"),
1278 F(ICMP6_RR_FLAGS_PREVDONE, "P"));
1279 }
1280 printf("seg=%u,", rr6->rr_segnum);
1281 printf("maxdelay=%u", EXTRACT_16BITS(&rr6->rr_maxdelay));
1282 if (rr6->rr_reserved)
1283 printf("rsvd=0x%x", EXTRACT_32BITS(&rr6->rr_reserved));
1284 /*[*/
1285 printf("]");
1286 #undef F
1287 }
1288
1289 if (rr6->rr_code == ICMP6_ROUTER_RENUMBERING_COMMAND) {
1290 match = (struct rr_pco_match *)cp;
1291 cp = (const char *)(match + 1);
1292
1293 TCHECK(match->rpm_prefix);
1294
1295 if (vflag > 1)
1296 printf("\n\t");
1297 else
1298 printf(" ");
1299 printf("match("); /*)*/
1300 switch (match->rpm_code) {
1301 case RPM_PCO_ADD: printf("add"); break;
1302 case RPM_PCO_CHANGE: printf("change"); break;
1303 case RPM_PCO_SETGLOBAL: printf("setglobal"); break;
1304 default: printf("#%u", match->rpm_code); break;
1305 }
1306
1307 if (vflag) {
1308 printf(",ord=%u", match->rpm_ordinal);
1309 printf(",min=%u", match->rpm_minlen);
1310 printf(",max=%u", match->rpm_maxlen);
1311 }
1312 if (inet_ntop(AF_INET6, &match->rpm_prefix, hbuf, sizeof(hbuf)))
1313 printf(",%s/%u", hbuf, match->rpm_matchlen);
1314 else
1315 printf(",?/%u", match->rpm_matchlen);
1316 /*(*/
1317 printf(")");
1318
1319 n = match->rpm_len - 3;
1320 if (n % 4)
1321 goto trunc;
1322 n /= 4;
1323 while (n-- > 0) {
1324 use = (struct rr_pco_use *)cp;
1325 cp = (const char *)(use + 1);
1326
1327 TCHECK(use->rpu_prefix);
1328
1329 if (vflag > 1)
1330 printf("\n\t");
1331 else
1332 printf(" ");
1333 printf("use("); /*)*/
1334 if (use->rpu_flags) {
1335 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1336 printf("%s%s,",
1337 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"),
1338 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P"));
1339 #undef F
1340 }
1341 if (vflag) {
1342 printf("mask=0x%x,", use->rpu_ramask);
1343 printf("raflags=0x%x,", use->rpu_raflags);
1344 if (~use->rpu_vltime == 0)
1345 printf("vltime=infty,");
1346 else
1347 printf("vltime=%u,",
1348 EXTRACT_32BITS(&use->rpu_vltime));
1349 if (~use->rpu_pltime == 0)
1350 printf("pltime=infty,");
1351 else
1352 printf("pltime=%u,",
1353 EXTRACT_32BITS(&use->rpu_pltime));
1354 }
1355 if (inet_ntop(AF_INET6, &use->rpu_prefix, hbuf,
1356 sizeof(hbuf)))
1357 printf("%s/%u/%u", hbuf, use->rpu_uselen,
1358 use->rpu_keeplen);
1359 else
1360 printf("?/%u/%u", use->rpu_uselen,
1361 use->rpu_keeplen);
1362 /*(*/
1363 printf(")");
1364 }
1365 }
1366
1367 return;
1368
1369 trunc:
1370 fputs("[|icmp6]", stdout);
1371 }
1372
1373 #endif /* INET6 */