2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
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
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.
23 static const char rcsid[] _U_ =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.85.2.1 2008-02-05 19:36:58 guy Exp $";
33 #include <tcpdump-stdinc.h>
38 #include "interface.h"
39 #include "addrtoname.h"
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 *);
62 #define abs(a) ((0 < (a)) ? (a) : -(a))
65 static struct tok icmp6_type_values[] = {
66 { ICMP6_DST_UNREACH, "destination unreachable"},
67 { ICMP6_PACKET_TOO_BIG, "packet too big"},
68 { ICMP6_TIME_EXCEEDED, "time exceeded in-transit"},
69 { ICMP6_PARAM_PROB, "parameter problem"},
70 { ICMP6_ECHO_REQUEST, "echo request"},
71 { ICMP6_ECHO_REPLY, "echo reply"},
72 { MLD6_LISTENER_QUERY, "multicast listener query"},
73 { MLD6_LISTENER_REPORT, "multicast listener report"},
74 { MLD6_LISTENER_DONE, "multicast listener done"},
75 { ND_ROUTER_SOLICIT, "router solicitation"},
76 { ND_ROUTER_ADVERT, "router advertisement"},
77 { ND_NEIGHBOR_SOLICIT, "neighbor solicitation"},
78 { ND_NEIGHBOR_ADVERT, "neighbor advertisement"},
79 { ND_REDIRECT, "redirect"},
80 { ICMP6_ROUTER_RENUMBERING, "router renumbering"},
81 { IND_SOLICIT, "inverse neighbor solicitation"},
82 { IND_ADVERT, "inverse neighbor advertisement"},
83 { MLDV2_LISTENER_REPORT, "multicast listener report v2"},
84 { ICMP6_HADISCOV_REQUEST, "ha discovery request"},
85 { ICMP6_HADISCOV_REPLY, "ha discovery reply"},
86 { ICMP6_MOBILEPREFIX_SOLICIT, "mobile router solicitation"},
87 { ICMP6_MOBILEPREFIX_ADVERT, "mobile router advertisement"},
88 { ICMP6_WRUREQUEST, "who-are-you request"},
89 { ICMP6_WRUREPLY, "who-are-you reply"},
90 { ICMP6_NI_QUERY, "node information query"},
91 { ICMP6_NI_REPLY, "node information reply"},
92 { MLD6_MTRACE, "mtrace message"},
93 { MLD6_MTRACE_RESP, "mtrace response"},
97 static struct tok icmp6_dst_unreach_code_values[] = {
98 { ICMP6_DST_UNREACH_NOROUTE, "unreachable route" },
99 { ICMP6_DST_UNREACH_ADMIN, " unreachable prohibited"},
100 { ICMP6_DST_UNREACH_BEYONDSCOPE, "beyond scope"},
101 { ICMP6_DST_UNREACH_ADDR, "unreachable address"},
102 { ICMP6_DST_UNREACH_NOPORT, "unreachable port"},
106 static struct tok icmp6_opt_pi_flag_values[] = {
107 { ND_OPT_PI_FLAG_ONLINK, "onlink" },
108 { ND_OPT_PI_FLAG_AUTO, "auto" },
109 { ND_OPT_PI_FLAG_ROUTER, "router" },
113 static struct tok icmp6_opt_ra_flag_values[] = {
114 { ND_RA_FLAG_MANAGED, "managed" },
115 { ND_RA_FLAG_OTHER, "other stateful"},
116 { ND_RA_FLAG_HOME_AGENT, "home agent"},
120 static struct tok icmp6_nd_na_flag_values[] = {
121 { ND_NA_FLAG_ROUTER, "router" },
122 { ND_NA_FLAG_SOLICITED, "solicited" },
123 { ND_NA_FLAG_OVERRIDE, "override" },
128 static struct tok icmp6_opt_values[] = {
129 { ND_OPT_SOURCE_LINKADDR, "source link-address"},
130 { ND_OPT_TARGET_LINKADDR, "destination link-address"},
131 { ND_OPT_PREFIX_INFORMATION, "prefix info"},
132 { ND_OPT_REDIRECTED_HEADER, "redirected header"},
133 { ND_OPT_MTU, "mtu"},
134 { ND_OPT_ADVINTERVAL, "advertisement interval"},
135 { ND_OPT_HOMEAGENT_INFO, "homeagent information"},
136 { ND_OPT_ROUTE_INFO, "route info"},
140 /* mldv2 report types */
141 static struct tok mldv2report2str[] = {
154 static const char *rtpref_str[] = {
161 return rtpref_str[((v & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff];
165 get_lifetime(u_int32_t v)
169 if (v == (u_int32_t)~0UL)
172 snprintf(buf, sizeof(buf), "%u", v);
178 print_lladdr(const u_int8_t *p, size_t l)
180 const u_int8_t *ep, *q;
184 while (l > 0 && q < ep) {
187 printf("%02x", *q++);
192 static int icmp6_cksum(const struct ip6_hdr *ip6, const struct icmp6_hdr *icp,
196 register const u_int16_t *sp;
200 struct in6_addr ph_src;
201 struct in6_addr ph_dst;
210 memset(&phu, 0, sizeof(phu));
211 phu.ph.ph_src = ip6->ip6_src;
212 phu.ph.ph_dst = ip6->ip6_dst;
213 phu.ph.ph_len = htonl(len);
214 phu.ph.ph_nxt = IPPROTO_ICMPV6;
217 for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++)
220 sp = (const u_int16_t *)icp;
222 for (i = 0; i < (len & ~1); i += 2)
226 sum += htons((*(const u_int8_t *)sp) << 8);
229 sum = (sum & 0xffff) + (sum >> 16);
236 icmp6_print(const u_char *bp, u_int length, const u_char *bp2, int fragmented)
238 const struct icmp6_hdr *dp;
239 const struct ip6_hdr *ip;
240 const struct ip6_hdr *oip;
241 const struct udphdr *ouh;
246 dp = (struct icmp6_hdr *)bp;
247 ip = (struct ip6_hdr *)bp2;
248 oip = (struct ip6_hdr *)(dp + 1);
249 /* 'ep' points to the end of available data. */
252 TCHECK(dp->icmp6_cksum);
254 if (vflag && !fragmented) {
255 int sum = dp->icmp6_cksum;
257 if (TTEST2(bp[0], length)) {
258 sum = icmp6_cksum(ip, dp, length);
260 (void)printf("[bad icmp6 cksum %x!] ", sum);
262 (void)printf("[icmp6 sum ok] ");
266 printf("ICMP6, %s", tok2str(icmp6_type_values,"unknown icmp6 type (%u)",dp->icmp6_type));
268 /* display cosmetics: print the packet length for printer that use the vflag now */
269 if (vflag && (dp->icmp6_type == ND_ROUTER_SOLICIT ||
270 dp->icmp6_type == ND_ROUTER_ADVERT ||
271 dp->icmp6_type == ND_NEIGHBOR_ADVERT ||
272 dp->icmp6_type == ND_NEIGHBOR_SOLICIT ||
273 dp->icmp6_type == ND_REDIRECT ||
274 dp->icmp6_type == ICMP6_HADISCOV_REPLY ||
275 dp->icmp6_type == ICMP6_MOBILEPREFIX_ADVERT ))
276 printf(", length %u", length);
278 switch (dp->icmp6_type) {
279 case ICMP6_DST_UNREACH:
280 TCHECK(oip->ip6_dst);
281 printf(", %s", tok2str(icmp6_dst_unreach_code_values,"unknown unreach code (%u)",dp->icmp6_code));
282 switch (dp->icmp6_code) {
284 case ICMP6_DST_UNREACH_NOROUTE: /* fall through */
285 case ICMP6_DST_UNREACH_ADMIN:
286 case ICMP6_DST_UNREACH_ADDR:
287 printf(" %s",ip6addr_string(&oip->ip6_dst));
289 case ICMP6_DST_UNREACH_BEYONDSCOPE:
290 printf(" %s, source address %s",
291 ip6addr_string(&oip->ip6_dst),
292 ip6addr_string(&oip->ip6_src));
294 case ICMP6_DST_UNREACH_NOPORT:
295 if ((ouh = get_upperlayer((u_char *)oip, &prot))
299 dport = EXTRACT_16BITS(&ouh->uh_dport);
302 printf(", %s tcp port %s",
303 ip6addr_string(&oip->ip6_dst),
304 tcpport_string(dport));
307 printf(", %s udp port %s",
308 ip6addr_string(&oip->ip6_dst),
309 udpport_string(dport));
312 printf(", %s protocol %d port %d unreachable",
313 ip6addr_string(&oip->ip6_dst),
314 oip->ip6_nxt, dport);
320 print_unknown_data(bp,"\n\t",length);
326 case ICMP6_PACKET_TOO_BIG:
327 TCHECK(dp->icmp6_mtu);
328 printf(", mtu %u", EXTRACT_32BITS(&dp->icmp6_mtu));
330 case ICMP6_TIME_EXCEEDED:
331 TCHECK(oip->ip6_dst);
332 switch (dp->icmp6_code) {
333 case ICMP6_TIME_EXCEED_TRANSIT:
335 ip6addr_string(&oip->ip6_dst));
337 case ICMP6_TIME_EXCEED_REASSEMBLY:
338 printf(" (reassembly)");
341 printf(", unknown code (%u)", dp->icmp6_code);
345 case ICMP6_PARAM_PROB:
346 TCHECK(oip->ip6_dst);
347 switch (dp->icmp6_code) {
348 case ICMP6_PARAMPROB_HEADER:
349 printf(", errorneous - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr));
351 case ICMP6_PARAMPROB_NEXTHEADER:
352 printf(", next header - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr));
354 case ICMP6_PARAMPROB_OPTION:
355 printf(", option - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr));
363 case ICMP6_ECHO_REQUEST:
364 case ICMP6_ECHO_REPLY:
365 TCHECK(dp->icmp6_seq);
366 printf(", seq %u", EXTRACT_16BITS(&dp->icmp6_seq));
368 case ICMP6_MEMBERSHIP_QUERY:
369 if (length == MLD_MINLEN) {
370 mld6_print((const u_char *)dp);
371 } else if (length >= MLDV2_MINLEN) {
373 mldv2_query_print((const u_char *)dp, length);
375 printf(" unknown-version (len %u) ", length);
378 case ICMP6_MEMBERSHIP_REPORT:
379 mld6_print((const u_char *)dp);
381 case ICMP6_MEMBERSHIP_REDUCTION:
382 mld6_print((const u_char *)dp);
384 case ND_ROUTER_SOLICIT:
387 icmp6_opt_print((const u_char *)dp + RTSOLLEN,
391 case ND_ROUTER_ADVERT:
394 struct nd_router_advert *p;
396 p = (struct nd_router_advert *)dp;
397 TCHECK(p->nd_ra_retransmit);
398 printf("\n\thop limit %u, Flags [%s]" \
399 ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
400 (u_int)p->nd_ra_curhoplimit,
401 bittok2str(icmp6_opt_ra_flag_values,"none",(p->nd_ra_flags_reserved)),
402 get_rtpref(p->nd_ra_flags_reserved),
403 EXTRACT_16BITS(&p->nd_ra_router_lifetime),
404 EXTRACT_32BITS(&p->nd_ra_reachable),
405 EXTRACT_32BITS(&p->nd_ra_retransmit));
407 icmp6_opt_print((const u_char *)dp + RTADVLEN,
411 case ND_NEIGHBOR_SOLICIT:
413 struct nd_neighbor_solicit *p;
414 p = (struct nd_neighbor_solicit *)dp;
415 TCHECK(p->nd_ns_target);
416 printf(", who has %s", ip6addr_string(&p->nd_ns_target));
419 icmp6_opt_print((const u_char *)dp + NDSOLLEN,
424 case ND_NEIGHBOR_ADVERT:
426 struct nd_neighbor_advert *p;
428 p = (struct nd_neighbor_advert *)dp;
429 TCHECK(p->nd_na_target);
430 printf(", tgt is %s",
431 ip6addr_string(&p->nd_na_target));
433 printf(", Flags [%s]",
434 bittok2str(icmp6_nd_na_flag_values,
436 EXTRACT_32BITS(&p->nd_na_flags_reserved)));
438 icmp6_opt_print((const u_char *)dp + NDADVLEN,
445 #define RDR(i) ((struct nd_redirect *)(i))
446 TCHECK(RDR(dp)->nd_rd_dst);
447 printf(", %s", getname6((const u_char *)&RDR(dp)->nd_rd_dst));
448 TCHECK(RDR(dp)->nd_rd_target);
450 getname6((const u_char*)&RDR(dp)->nd_rd_target));
451 #define REDIRECTLEN 40
453 icmp6_opt_print((const u_char *)dp + REDIRECTLEN,
454 length - REDIRECTLEN);
459 case ICMP6_ROUTER_RENUMBERING:
460 icmp6_rrenum_print(bp, ep);
464 icmp6_nodeinfo_print(length, bp, ep);
469 case ICMP6_V2_MEMBERSHIP_REPORT:
470 mldv2_report_print((const u_char *) dp, length);
472 case ICMP6_MOBILEPREFIX_SOLICIT: /* fall through */
473 case ICMP6_HADISCOV_REQUEST:
474 TCHECK(dp->icmp6_data16[0]);
475 printf(", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0]));
477 case ICMP6_HADISCOV_REPLY:
479 struct in6_addr *in6;
482 TCHECK(dp->icmp6_data16[0]);
483 printf(", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0]));
484 cp = (u_char *)dp + length;
485 in6 = (struct in6_addr *)(dp + 1);
486 for (; (u_char *)in6 < cp; in6++) {
488 printf(", %s", ip6addr_string(in6));
492 case ICMP6_MOBILEPREFIX_ADVERT:
494 TCHECK(dp->icmp6_data16[0]);
495 printf(", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0]));
496 if (dp->icmp6_data16[1] & 0xc0)
498 if (dp->icmp6_data16[1] & 0x80)
500 if (dp->icmp6_data16[1] & 0x40)
503 icmp6_opt_print((const u_char *)dp + MPADVLEN,
508 printf(", length %u", length);
510 print_unknown_data(bp,"\n\t", length);
514 printf(", length %u", length);
517 fputs("[|icmp6]", stdout);
520 static struct udphdr *
521 get_upperlayer(u_char *bp, u_int *prot)
524 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
527 struct ip6_frag *fragh;
532 /* 'ep' points to the end of available data. */
535 if (!TTEST(ip6->ip6_nxt))
539 hlen = sizeof(struct ip6_hdr);
547 uh = (struct udphdr *)bp;
548 if (TTEST(uh->uh_dport)) {
556 case IPPROTO_HOPOPTS:
557 case IPPROTO_DSTOPTS:
558 case IPPROTO_ROUTING:
559 hbh = (struct ip6_hbh *)bp;
560 if (!TTEST(hbh->ip6h_len))
563 hlen = (hbh->ip6h_len + 1) << 3;
566 case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
567 fragh = (struct ip6_frag *)bp;
568 if (!TTEST(fragh->ip6f_offlg))
570 /* fragments with non-zero offset are meaningless */
571 if ((EXTRACT_16BITS(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
573 nh = fragh->ip6f_nxt;
574 hlen = sizeof(struct ip6_frag);
578 ah = (struct ah *)bp;
579 if (!TTEST(ah->ah_len))
582 hlen = (ah->ah_len + 2) << 2;
585 default: /* unknown or undecodable header */
586 *prot = nh; /* meaningless, but set here anyway */
591 return(NULL); /* should be notreached, though */
595 icmp6_opt_print(const u_char *bp, int resid)
597 const struct nd_opt_hdr *op;
598 const struct nd_opt_hdr *opl; /* why there's no struct? */
599 const struct nd_opt_prefix_info *opp;
600 const struct icmp6_opts_redirect *opr;
601 const struct nd_opt_mtu *opm;
602 const struct nd_opt_advinterval *opa;
603 const struct nd_opt_homeagent_info *oph;
604 const struct nd_opt_route_info *opri;
605 const u_char *cp, *ep;
606 struct in6_addr in6, *in6p;
609 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
612 /* 'ep' points to the end of available data. */
616 op = (struct nd_opt_hdr *)cp;
618 ECHECK(op->nd_opt_len);
621 if (op->nd_opt_len == 0)
623 if (cp + (op->nd_opt_len << 3) > ep)
626 printf("\n\t %s option (%u), length %u (%u): ",
627 tok2str(icmp6_opt_values, "unknown", op->nd_opt_type),
632 switch (op->nd_opt_type) {
633 case ND_OPT_SOURCE_LINKADDR:
634 opl = (struct nd_opt_hdr *)op;
635 l = (op->nd_opt_len << 3) - 2;
636 print_lladdr(cp + 2, l);
638 case ND_OPT_TARGET_LINKADDR:
639 opl = (struct nd_opt_hdr *)op;
640 l = (op->nd_opt_len << 3) - 2;
641 print_lladdr(cp + 2, l);
643 case ND_OPT_PREFIX_INFORMATION:
644 opp = (struct nd_opt_prefix_info *)op;
645 TCHECK(opp->nd_opt_pi_prefix);
646 printf("%s/%u%s, Flags [%s], valid time %ss",
647 ip6addr_string(&opp->nd_opt_pi_prefix),
648 opp->nd_opt_pi_prefix_len,
649 (op->nd_opt_len != 4) ? "badlen" : "",
650 bittok2str(icmp6_opt_pi_flag_values, "none", opp->nd_opt_pi_flags_reserved),
651 get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_valid_time)));
652 printf(", pref. time %ss", get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_preferred_time)));
654 case ND_OPT_REDIRECTED_HEADER:
655 opr = (struct icmp6_opts_redirect *)op;
656 print_unknown_data(bp,"\n\t ",op->nd_opt_len<<3);
660 opm = (struct nd_opt_mtu *)op;
661 TCHECK(opm->nd_opt_mtu_mtu);
663 EXTRACT_32BITS(&opm->nd_opt_mtu_mtu),
664 (op->nd_opt_len != 1) ? "bad option length" : "" );
666 case ND_OPT_ADVINTERVAL:
667 opa = (struct nd_opt_advinterval *)op;
668 TCHECK(opa->nd_opt_adv_interval);
669 printf(" %us", EXTRACT_32BITS(&opa->nd_opt_adv_interval));
671 case ND_OPT_HOMEAGENT_INFO:
672 oph = (struct nd_opt_homeagent_info *)op;
673 TCHECK(oph->nd_opt_hai_lifetime);
674 printf(" preference %u, lifetime %u",
675 EXTRACT_16BITS(&oph->nd_opt_hai_preference),
676 EXTRACT_16BITS(&oph->nd_opt_hai_lifetime));
678 case ND_OPT_ROUTE_INFO:
679 opri = (struct nd_opt_route_info *)op;
680 TCHECK(opri->nd_opt_rti_lifetime);
681 memset(&in6, 0, sizeof(in6));
682 in6p = (struct in6_addr *)(opri + 1);
683 switch (op->nd_opt_len) {
688 memcpy(&in6, opri + 1, 8);
692 memcpy(&in6, opri + 1, sizeof(in6));
697 printf(" %s/%u", ip6addr_string(&in6),
698 opri->nd_opt_rti_prefixlen);
699 printf(", pref=%s", get_rtpref(opri->nd_opt_rti_flags));
700 printf(", lifetime=%s",
701 get_lifetime(EXTRACT_32BITS(&opri->nd_opt_rti_lifetime)));
705 print_unknown_data(cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
710 /* do we want to see an additional hexdump ? */
712 print_unknown_data(cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
714 cp += op->nd_opt_len << 3;
715 resid -= op->nd_opt_len << 3;
720 fputs("[ndp opt]", stdout);
726 mld6_print(const u_char *bp)
728 struct mld6_hdr *mp = (struct mld6_hdr *)bp;
731 /* 'ep' points to the end of available data. */
734 if ((u_char *)mp + sizeof(*mp) > ep)
737 printf("max resp delay: %d ", EXTRACT_16BITS(&mp->mld6_maxdelay));
738 printf("addr: %s", ip6addr_string(&mp->mld6_addr));
742 mldv2_report_print(const u_char *bp, u_int len)
744 struct icmp6_hdr *icp = (struct icmp6_hdr *) bp;
745 u_int group, nsrcs, ngroups;
748 /* Minimum len is 8 */
750 printf(" [invalid len %d]", len);
754 TCHECK(icp->icmp6_data16[1]);
755 ngroups = ntohs(icp->icmp6_data16[1]);
756 printf(", %d group record(s)", ngroups);
758 /* Print the group records */
760 for (i = 0; i < ngroups; i++) {
761 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
762 if (len < group + 20) {
763 printf(" [invalid number of groups]");
766 TCHECK2(bp[group + 4], sizeof(struct in6_addr));
767 printf(" [gaddr %s", ip6addr_string(&bp[group + 4]));
768 printf(" %s", tok2str(mldv2report2str, " [v2-report-#%d]",
770 nsrcs = (bp[group + 2] << 8) + bp[group + 3];
771 /* Check the number of sources and print them */
772 if (len < group + 20 + (nsrcs * sizeof(struct in6_addr))) {
773 printf(" [invalid number of sources %d]", nsrcs);
777 printf(", %d source(s)", nsrcs);
779 /* Print the sources */
781 for (j = 0; j < nsrcs; j++) {
782 TCHECK2(bp[group + 20 + j * sizeof(struct in6_addr)],
783 sizeof(struct in6_addr));
784 printf(" %s", ip6addr_string(&bp[group + 20 + j * sizeof(struct in6_addr)]));
788 /* Next group record */
789 group += 20 + nsrcs * sizeof(struct in6_addr);
795 (void)printf("[|icmp6]");
800 mldv2_query_print(const u_char *bp, u_int len)
802 struct icmp6_hdr *icp = (struct icmp6_hdr *) bp;
808 /* Minimum len is 28 */
810 printf(" [invalid len %d]", len);
813 TCHECK(icp->icmp6_data16[0]);
814 mrc = ntohs(icp->icmp6_data16[0]);
818 mrt = ((mrc & 0x0fff) | 0x1000) << (((mrc & 0x7000) >> 12) + 3);
821 (void)printf(" [max resp delay=%d]", mrt);
823 TCHECK2(bp[8], sizeof(struct in6_addr));
824 printf(" [gaddr %s", ip6addr_string(&bp[8]));
832 printf(" robustness=%d", bp[24] & 0x07);
837 qqi = ((bp[25] & 0x0f) | 0x10) << (((bp[25] & 0x70) >> 4) + 3);
839 printf(" qqi=%d", qqi);
843 nsrcs = ntohs(*(u_short *)&bp[26]);
845 if (len < 28 + nsrcs * sizeof(struct in6_addr))
846 printf(" [invalid number of sources]");
847 else if (vflag > 1) {
849 for (i = 0; i < nsrcs; i++) {
850 TCHECK2(bp[28 + i * sizeof(struct in6_addr)],
851 sizeof(struct in6_addr));
852 printf(" %s", ip6addr_string(&bp[28 + i * sizeof(struct in6_addr)]));
856 printf(", %d source(s)", nsrcs);
861 (void)printf("[|icmp6]");
866 dnsname_print(const u_char *cp, const u_char *ep)
870 /* DNS name decoding - no decompression */
879 while (i-- && cp < ep) {
883 if (cp + 1 < ep && *cp)
889 } else if (cp + 1 == ep && *cp == '\0') {
902 icmp6_nodeinfo_print(u_int icmp6len, const u_char *bp, const u_char *ep)
904 struct icmp6_nodeinfo *ni6;
905 struct icmp6_hdr *dp;
912 dp = (struct icmp6_hdr *)bp;
913 ni6 = (struct icmp6_nodeinfo *)bp;
916 switch (ni6->ni_type) {
918 if (siz == sizeof(*dp) + 4) {
919 /* KAME who-are-you */
920 printf(" who-are-you request");
923 printf(" node information query");
925 TCHECK2(*dp, sizeof(*ni6));
926 ni6 = (struct icmp6_nodeinfo *)dp;
928 switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
932 case NI_QTYPE_SUPTYPES:
933 printf("supported qtypes");
934 i = EXTRACT_16BITS(&ni6->ni_flags);
936 printf(" [%s]", (i & 0x01) ? "C" : "");
942 case NI_QTYPE_NODEADDR:
943 printf("node addresses");
947 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
948 printf(" [%s%s%s%s%s%s]",
949 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
950 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
951 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
952 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
953 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
954 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "");
961 if (ni6->ni_qtype == NI_QTYPE_NOOP ||
962 ni6->ni_qtype == NI_QTYPE_SUPTYPES) {
963 if (siz != sizeof(*ni6))
965 printf(", invalid len");
972 /* XXX backward compat, icmp-name-lookup-03 */
973 if (siz == sizeof(*ni6)) {
974 printf(", 03 draft");
980 switch (ni6->ni_code) {
981 case ICMP6_NI_SUBJ_IPV6:
983 sizeof(*ni6) + sizeof(struct in6_addr)))
985 if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) {
987 printf(", invalid subject len");
990 printf(", subject=%s",
991 getname6((const u_char *)(ni6 + 1)));
993 case ICMP6_NI_SUBJ_FQDN:
994 printf(", subject=DNS name");
995 cp = (const u_char *)(ni6 + 1);
996 if (cp[0] == ep - cp - 1) {
997 /* icmp-name-lookup-03, pascal string */
999 printf(", 03 draft");
1008 dnsname_print(cp, ep);
1010 case ICMP6_NI_SUBJ_IPV4:
1011 if (!TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr)))
1013 if (siz != sizeof(*ni6) + sizeof(struct in_addr)) {
1015 printf(", invalid subject len");
1018 printf(", subject=%s",
1019 getname((const u_char *)(ni6 + 1)));
1022 printf(", unknown subject");
1030 case ICMP6_NI_REPLY:
1031 if (icmp6len > siz) {
1032 printf("[|icmp6: node information reply]");
1038 ni6 = (struct icmp6_nodeinfo *)dp;
1039 printf(" node information reply");
1041 switch (ni6->ni_code) {
1042 case ICMP6_NI_SUCCESS:
1048 case ICMP6_NI_REFUSED:
1051 if (siz != sizeof(*ni6))
1053 printf(", invalid length");
1055 case ICMP6_NI_UNKNOWN:
1058 if (siz != sizeof(*ni6))
1060 printf(", invalid length");
1064 if (ni6->ni_code != ICMP6_NI_SUCCESS) {
1070 switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
1075 if (siz != sizeof(*ni6))
1077 printf(", invalid length");
1079 case NI_QTYPE_SUPTYPES:
1082 printf("supported qtypes");
1083 i = EXTRACT_16BITS(&ni6->ni_flags);
1085 printf(" [%s]", (i & 0x01) ? "C" : "");
1091 cp = (const u_char *)(ni6 + 1) + 4;
1092 if (cp[0] == ep - cp - 1) {
1093 /* icmp-name-lookup-03, pascal string */
1095 printf(", 03 draft");
1104 dnsname_print(cp, ep);
1105 if ((EXTRACT_16BITS(&ni6->ni_flags) & 0x01) != 0)
1106 printf(" [TTL=%u]", *(u_int32_t *)(ni6 + 1));
1108 case NI_QTYPE_NODEADDR:
1111 printf("node addresses");
1114 if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz)
1116 printf(" %s", getname6(bp + i));
1117 i += sizeof(struct in6_addr);
1118 printf("(%d)", (int32_t)EXTRACT_32BITS(bp + i));
1119 i += sizeof(int32_t);
1124 printf(" [%s%s%s%s%s%s%s]",
1125 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1126 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1127 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1128 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1129 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1130 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
1131 (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : "");
1147 fputs("[|icmp6]", stdout);
1151 icmp6_rrenum_print(const u_char *bp, const u_char *ep)
1153 struct icmp6_router_renum *rr6;
1155 struct rr_pco_match *match;
1156 struct rr_pco_use *use;
1157 char hbuf[NI_MAXHOST];
1162 rr6 = (struct icmp6_router_renum *)bp;
1163 cp = (const char *)(rr6 + 1);
1165 TCHECK(rr6->rr_reserved);
1166 switch (rr6->rr_code) {
1167 case ICMP6_ROUTER_RENUMBERING_COMMAND:
1168 printf("router renum: command");
1170 case ICMP6_ROUTER_RENUMBERING_RESULT:
1171 printf("router renum: result");
1173 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET:
1174 printf("router renum: sequence number reset");
1177 printf("router renum: code-#%d", rr6->rr_code);
1181 printf(", seq=%u", EXTRACT_32BITS(&rr6->rr_seqnum));
1184 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1186 if (rr6->rr_flags) {
1187 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"),
1188 F(ICMP6_RR_FLAGS_REQRESULT, "R"),
1189 F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"),
1190 F(ICMP6_RR_FLAGS_SPECSITE, "S"),
1191 F(ICMP6_RR_FLAGS_PREVDONE, "P"));
1193 printf("seg=%u,", rr6->rr_segnum);
1194 printf("maxdelay=%u", EXTRACT_16BITS(&rr6->rr_maxdelay));
1195 if (rr6->rr_reserved)
1196 printf("rsvd=0x%x", EXTRACT_32BITS(&rr6->rr_reserved));
1202 if (rr6->rr_code == ICMP6_ROUTER_RENUMBERING_COMMAND) {
1203 match = (struct rr_pco_match *)cp;
1204 cp = (const char *)(match + 1);
1206 TCHECK(match->rpm_prefix);
1212 printf("match("); /*)*/
1213 switch (match->rpm_code) {
1214 case RPM_PCO_ADD: printf("add"); break;
1215 case RPM_PCO_CHANGE: printf("change"); break;
1216 case RPM_PCO_SETGLOBAL: printf("setglobal"); break;
1217 default: printf("#%u", match->rpm_code); break;
1221 printf(",ord=%u", match->rpm_ordinal);
1222 printf(",min=%u", match->rpm_minlen);
1223 printf(",max=%u", match->rpm_maxlen);
1225 if (inet_ntop(AF_INET6, &match->rpm_prefix, hbuf, sizeof(hbuf)))
1226 printf(",%s/%u", hbuf, match->rpm_matchlen);
1228 printf(",?/%u", match->rpm_matchlen);
1232 n = match->rpm_len - 3;
1237 use = (struct rr_pco_use *)cp;
1238 cp = (const char *)(use + 1);
1240 TCHECK(use->rpu_prefix);
1246 printf("use("); /*)*/
1247 if (use->rpu_flags) {
1248 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1250 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"),
1251 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P"));
1255 printf("mask=0x%x,", use->rpu_ramask);
1256 printf("raflags=0x%x,", use->rpu_raflags);
1257 if (~use->rpu_vltime == 0)
1258 printf("vltime=infty,");
1260 printf("vltime=%u,",
1261 EXTRACT_32BITS(&use->rpu_vltime));
1262 if (~use->rpu_pltime == 0)
1263 printf("pltime=infty,");
1265 printf("pltime=%u,",
1266 EXTRACT_32BITS(&use->rpu_pltime));
1268 if (inet_ntop(AF_INET6, &use->rpu_prefix, hbuf,
1270 printf("%s/%u/%u", hbuf, use->rpu_uselen,
1273 printf("?/%u/%u", use->rpu_uselen,
1283 fputs("[|icmp6]", stdout);