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