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.79.2.4 2005/05/14 00:42:54 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 advertisment"},
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, "advertisment 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 ==
272 ND_NEIGHBOR_ADVERT ||
273 ND_NEIGHBOR_SOLICIT ||
275 ICMP6_HADISCOV_REPLY ||
276 ICMP6_MOBILEPREFIX_ADVERT ))
277 printf(", length %u", length);
279 switch (dp->icmp6_type) {
280 case ICMP6_DST_UNREACH:
281 TCHECK(oip->ip6_dst);
282 printf(", %s", tok2str(icmp6_dst_unreach_code_values,"unknown unreach code (%u)",dp->icmp6_code));
283 switch (dp->icmp6_code) {
285 case ICMP6_DST_UNREACH_NOROUTE: /* fall through */
286 case ICMP6_DST_UNREACH_ADMIN:
287 case ICMP6_DST_UNREACH_ADDR:
288 printf(" %s",ip6addr_string(&oip->ip6_dst));
290 case ICMP6_DST_UNREACH_BEYONDSCOPE:
291 printf(" %s, source address %s",
292 ip6addr_string(&oip->ip6_dst),
293 ip6addr_string(&oip->ip6_src));
295 case ICMP6_DST_UNREACH_NOPORT:
296 if ((ouh = get_upperlayer((u_char *)oip, &prot))
300 dport = EXTRACT_16BITS(&ouh->uh_dport);
303 printf(", %s tcp port %s",
304 ip6addr_string(&oip->ip6_dst),
305 tcpport_string(dport));
308 printf(", %s udp port %s",
309 ip6addr_string(&oip->ip6_dst),
310 udpport_string(dport));
313 printf(", %s protocol %d port %d unreachable",
314 ip6addr_string(&oip->ip6_dst),
315 oip->ip6_nxt, dport);
321 print_unknown_data(bp,"\n\t",length);
327 case ICMP6_PACKET_TOO_BIG:
328 TCHECK(dp->icmp6_mtu);
329 printf(", mtu %u", EXTRACT_32BITS(&dp->icmp6_mtu));
331 case ICMP6_TIME_EXCEEDED:
332 TCHECK(oip->ip6_dst);
333 switch (dp->icmp6_code) {
334 case ICMP6_TIME_EXCEED_TRANSIT:
336 ip6addr_string(&oip->ip6_dst));
338 case ICMP6_TIME_EXCEED_REASSEMBLY:
339 printf(" (reassembly)");
342 printf(", unknown code (%u)", dp->icmp6_code);
346 case ICMP6_PARAM_PROB:
347 TCHECK(oip->ip6_dst);
348 switch (dp->icmp6_code) {
349 case ICMP6_PARAMPROB_HEADER:
350 printf(", errorneous - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr));
352 case ICMP6_PARAMPROB_NEXTHEADER:
353 printf(", next header - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr));
355 case ICMP6_PARAMPROB_OPTION:
356 printf(", option - octet %u", EXTRACT_32BITS(&dp->icmp6_pptr));
364 case ICMP6_ECHO_REQUEST:
365 case ICMP6_ECHO_REPLY:
366 TCHECK(dp->icmp6_seq);
367 printf(", seq %u", EXTRACT_16BITS(&dp->icmp6_seq));
369 case ICMP6_MEMBERSHIP_QUERY:
370 if (length == MLD_MINLEN) {
371 mld6_print((const u_char *)dp);
372 } else if (length >= MLDV2_MINLEN) {
374 mldv2_query_print((const u_char *)dp, length);
376 printf(" unknown-version (len %u) ", length);
379 case ICMP6_MEMBERSHIP_REPORT:
380 mld6_print((const u_char *)dp);
382 case ICMP6_MEMBERSHIP_REDUCTION:
383 mld6_print((const u_char *)dp);
385 case ND_ROUTER_SOLICIT:
388 icmp6_opt_print((const u_char *)dp + RTSOLLEN,
392 case ND_ROUTER_ADVERT:
395 struct nd_router_advert *p;
397 p = (struct nd_router_advert *)dp;
398 TCHECK(p->nd_ra_retransmit);
399 printf("\n\thop limit %u, Flags [%s]" \
400 ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
401 (u_int)p->nd_ra_curhoplimit,
402 bittok2str(icmp6_opt_ra_flag_values,"none",(p->nd_ra_flags_reserved)),
403 get_rtpref(p->nd_ra_flags_reserved),
404 EXTRACT_16BITS(&p->nd_ra_router_lifetime),
405 EXTRACT_32BITS(&p->nd_ra_reachable),
406 EXTRACT_32BITS(&p->nd_ra_retransmit));
408 icmp6_opt_print((const u_char *)dp + RTADVLEN,
412 case ND_NEIGHBOR_SOLICIT:
414 struct nd_neighbor_solicit *p;
415 p = (struct nd_neighbor_solicit *)dp;
416 TCHECK(p->nd_ns_target);
417 printf(", who has %s", ip6addr_string(&p->nd_ns_target));
420 icmp6_opt_print((const u_char *)dp + NDSOLLEN,
425 case ND_NEIGHBOR_ADVERT:
427 struct nd_neighbor_advert *p;
429 p = (struct nd_neighbor_advert *)dp;
430 TCHECK(p->nd_na_target);
431 printf(", tgt is %s",
432 ip6addr_string(&p->nd_na_target));
434 printf(", Flags [%s]",
435 bittok2str(icmp6_nd_na_flag_values,
437 EXTRACT_32BITS(&p->nd_na_flags_reserved)));
439 icmp6_opt_print((const u_char *)dp + NDADVLEN,
446 #define RDR(i) ((struct nd_redirect *)(i))
447 TCHECK(RDR(dp)->nd_rd_dst);
448 printf(", %s", getname6((const u_char *)&RDR(dp)->nd_rd_dst));
449 TCHECK(RDR(dp)->nd_rd_target);
451 getname6((const u_char*)&RDR(dp)->nd_rd_target));
452 #define REDIRECTLEN 40
454 icmp6_opt_print((const u_char *)dp + REDIRECTLEN,
455 length - REDIRECTLEN);
460 case ICMP6_ROUTER_RENUMBERING:
461 icmp6_rrenum_print(bp, ep);
465 icmp6_nodeinfo_print(length, bp, ep);
470 case ICMP6_V2_MEMBERSHIP_REPORT:
471 mldv2_report_print((const u_char *) dp, length);
473 case ICMP6_MOBILEPREFIX_SOLICIT: /* fall through */
474 case ICMP6_HADISCOV_REQUEST:
475 TCHECK(dp->icmp6_data16[0]);
476 printf(", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0]));
478 case ICMP6_HADISCOV_REPLY:
480 struct in6_addr *in6;
483 TCHECK(dp->icmp6_data16[0]);
484 printf(", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0]));
485 cp = (u_char *)dp + length;
486 in6 = (struct in6_addr *)(dp + 1);
487 for (; (u_char *)in6 < cp; in6++) {
489 printf(", %s", ip6addr_string(in6));
493 case ICMP6_MOBILEPREFIX_ADVERT:
495 TCHECK(dp->icmp6_data16[0]);
496 printf(", id 0x%04x", EXTRACT_16BITS(&dp->icmp6_data16[0]));
497 if (dp->icmp6_data16[1] & 0xc0)
499 if (dp->icmp6_data16[1] & 0x80)
501 if (dp->icmp6_data16[1] & 0x40)
504 icmp6_opt_print((const u_char *)dp + MPADVLEN,
509 printf(", length %u", length);
511 print_unknown_data(bp,"\n\t", length);
515 printf(", length %u", length);
518 fputs("[|icmp6]", stdout);
521 static struct udphdr *
522 get_upperlayer(u_char *bp, u_int *prot)
525 struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
528 struct ip6_frag *fragh;
533 /* 'ep' points to the end of available data. */
536 if (!TTEST(ip6->ip6_nxt))
540 hlen = sizeof(struct ip6_hdr);
548 uh = (struct udphdr *)bp;
549 if (TTEST(uh->uh_dport)) {
557 case IPPROTO_HOPOPTS:
558 case IPPROTO_DSTOPTS:
559 case IPPROTO_ROUTING:
560 hbh = (struct ip6_hbh *)bp;
561 if (!TTEST(hbh->ip6h_len))
564 hlen = (hbh->ip6h_len + 1) << 3;
567 case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
568 fragh = (struct ip6_frag *)bp;
569 if (!TTEST(fragh->ip6f_offlg))
571 /* fragments with non-zero offset are meaningless */
572 if ((EXTRACT_16BITS(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
574 nh = fragh->ip6f_nxt;
575 hlen = sizeof(struct ip6_frag);
579 ah = (struct ah *)bp;
580 if (!TTEST(ah->ah_len))
583 hlen = (ah->ah_len + 2) << 2;
586 default: /* unknown or undecodable header */
587 *prot = nh; /* meaningless, but set here anyway */
592 return(NULL); /* should be notreached, though */
596 icmp6_opt_print(const u_char *bp, int resid)
598 const struct nd_opt_hdr *op;
599 const struct nd_opt_hdr *opl; /* why there's no struct? */
600 const struct nd_opt_prefix_info *opp;
601 const struct icmp6_opts_redirect *opr;
602 const struct nd_opt_mtu *opm;
603 const struct nd_opt_advinterval *opa;
604 const struct nd_opt_homeagent_info *oph;
605 const struct nd_opt_route_info *opri;
606 const u_char *cp, *ep;
607 struct in6_addr in6, *in6p;
610 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
613 /* 'ep' points to the end of available data. */
617 op = (struct nd_opt_hdr *)cp;
619 ECHECK(op->nd_opt_len);
622 if (op->nd_opt_len == 0)
624 if (cp + (op->nd_opt_len << 3) > ep)
627 printf("\n\t %s option (%u), length %u (%u): ",
628 tok2str(icmp6_opt_values, "unknown", op->nd_opt_type),
633 switch (op->nd_opt_type) {
634 case ND_OPT_SOURCE_LINKADDR:
635 opl = (struct nd_opt_hdr *)op;
636 l = (op->nd_opt_len << 3) - 2;
637 print_lladdr(cp + 2, l);
639 case ND_OPT_TARGET_LINKADDR:
640 opl = (struct nd_opt_hdr *)op;
641 l = (op->nd_opt_len << 3) - 2;
642 print_lladdr(cp + 2, l);
644 case ND_OPT_PREFIX_INFORMATION:
645 opp = (struct nd_opt_prefix_info *)op;
646 TCHECK(opp->nd_opt_pi_prefix);
647 printf("%s/%u%s, Flags [%s], valid time %ss",
648 ip6addr_string(&opp->nd_opt_pi_prefix),
649 opp->nd_opt_pi_prefix_len,
650 (op->nd_opt_len != 4) ? "badlen" : "",
651 bittok2str(icmp6_opt_pi_flag_values, "none", opp->nd_opt_pi_flags_reserved),
652 get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_valid_time)));
653 printf(", pref. time %ss", get_lifetime(EXTRACT_32BITS(&opp->nd_opt_pi_preferred_time)));
655 case ND_OPT_REDIRECTED_HEADER:
656 opr = (struct icmp6_opts_redirect *)op;
657 print_unknown_data(bp,"\n\t ",op->nd_opt_len<<3);
661 opm = (struct nd_opt_mtu *)op;
662 TCHECK(opm->nd_opt_mtu_mtu);
664 EXTRACT_32BITS(&opm->nd_opt_mtu_mtu),
665 (op->nd_opt_len != 1) ? "bad option length" : "" );
667 case ND_OPT_ADVINTERVAL:
668 opa = (struct nd_opt_advinterval *)op;
669 TCHECK(opa->nd_opt_adv_interval);
670 printf(" %us", EXTRACT_32BITS(&opa->nd_opt_adv_interval));
672 case ND_OPT_HOMEAGENT_INFO:
673 oph = (struct nd_opt_homeagent_info *)op;
674 TCHECK(oph->nd_opt_hai_lifetime);
675 printf(" preference %u, lifetime %u",
676 EXTRACT_16BITS(&oph->nd_opt_hai_preference),
677 EXTRACT_16BITS(&oph->nd_opt_hai_lifetime));
679 case ND_OPT_ROUTE_INFO:
680 opri = (struct nd_opt_route_info *)op;
681 TCHECK(opri->nd_opt_rti_lifetime);
682 memset(&in6, 0, sizeof(in6));
683 in6p = (struct in6_addr *)(opri + 1);
684 switch (op->nd_opt_len) {
689 memcpy(&in6, opri + 1, 8);
693 memcpy(&in6, opri + 1, sizeof(in6));
698 printf(" %s/%u", ip6addr_string(&in6),
699 opri->nd_opt_rti_prefixlen);
700 printf(", pref=%s", get_rtpref(opri->nd_opt_rti_flags));
701 printf(", lifetime=%s",
702 get_lifetime(EXTRACT_32BITS(&opri->nd_opt_rti_lifetime)));
706 print_unknown_data(cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
711 /* do we want to see an additional hexdump ? */
713 print_unknown_data(cp+2,"\n\t ", (op->nd_opt_len << 3) - 2); /* skip option header */
715 cp += op->nd_opt_len << 3;
716 resid -= op->nd_opt_len << 3;
721 fputs("[ndp opt]", stdout);
727 mld6_print(const u_char *bp)
729 struct mld6_hdr *mp = (struct mld6_hdr *)bp;
732 /* 'ep' points to the end of available data. */
735 if ((u_char *)mp + sizeof(*mp) > ep)
738 printf("max resp delay: %d ", EXTRACT_16BITS(&mp->mld6_maxdelay));
739 printf("addr: %s", ip6addr_string(&mp->mld6_addr));
743 mldv2_report_print(const u_char *bp, u_int len)
745 struct icmp6_hdr *icp = (struct icmp6_hdr *) bp;
746 u_int group, nsrcs, ngroups;
749 /* Minimum len is 8 */
751 printf(" [invalid len %d]", len);
755 TCHECK(icp->icmp6_data16[1]);
756 ngroups = ntohs(icp->icmp6_data16[1]);
757 printf(", %d group record(s)", ngroups);
759 /* Print the group records */
761 for (i = 0; i < ngroups; i++) {
762 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
763 if (len < group + 20) {
764 printf(" [invalid number of groups]");
767 TCHECK2(bp[group + 4], 16);
768 printf(" [gaddr %s", ip6addr_string(&bp[group + 4]));
769 printf(" %s", tok2str(mldv2report2str, " [v2-report-#%d]",
771 nsrcs = (bp[group + 2] << 8) + bp[group + 3];
772 /* Check the number of sources and print them */
773 if (len < group + 20 + (nsrcs * 16)) {
774 printf(" [invalid number of sources %d]", nsrcs);
778 printf(", %d source(s)", nsrcs);
780 /* Print the sources */
782 for (j = 0; j < nsrcs; j++) {
783 TCHECK2(bp[group + 20 + j * 16], 16);
784 printf(" %s", ip6addr_string(&bp[group + 20 + j * 16]));
788 /* Next group record */
789 group += 20 + nsrcs * 16;
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);
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 * 16)
846 printf(" [invalid number of sources]");
847 else if (vflag > 1) {
849 for (i = 0; i < nsrcs; i++) {
850 TCHECK2(bp[28 + i * 16], 16);
851 printf(" %s", ip6addr_string(&bp[28 + i * 16]));
855 printf(", %d source(s)", nsrcs);
860 (void)printf("[|icmp6]");
865 dnsname_print(const u_char *cp, const u_char *ep)
869 /* DNS name decoding - no decompression */
878 while (i-- && cp < ep) {
882 if (cp + 1 < ep && *cp)
888 } else if (cp + 1 == ep && *cp == '\0') {
901 icmp6_nodeinfo_print(u_int icmp6len, const u_char *bp, const u_char *ep)
903 struct icmp6_nodeinfo *ni6;
904 struct icmp6_hdr *dp;
911 dp = (struct icmp6_hdr *)bp;
912 ni6 = (struct icmp6_nodeinfo *)bp;
915 switch (ni6->ni_type) {
917 if (siz == sizeof(*dp) + 4) {
918 /* KAME who-are-you */
919 printf(" who-are-you request");
922 printf(" node information query");
924 TCHECK2(*dp, sizeof(*ni6));
925 ni6 = (struct icmp6_nodeinfo *)dp;
927 switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
931 case NI_QTYPE_SUPTYPES:
932 printf("supported qtypes");
933 i = EXTRACT_16BITS(&ni6->ni_flags);
935 printf(" [%s]", (i & 0x01) ? "C" : "");
941 case NI_QTYPE_NODEADDR:
942 printf("node addresses");
946 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
947 printf(" [%s%s%s%s%s%s]",
948 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
949 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
950 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
951 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
952 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
953 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "");
960 if (ni6->ni_qtype == NI_QTYPE_NOOP ||
961 ni6->ni_qtype == NI_QTYPE_SUPTYPES) {
962 if (siz != sizeof(*ni6))
964 printf(", invalid len");
971 /* XXX backward compat, icmp-name-lookup-03 */
972 if (siz == sizeof(*ni6)) {
973 printf(", 03 draft");
979 switch (ni6->ni_code) {
980 case ICMP6_NI_SUBJ_IPV6:
982 sizeof(*ni6) + sizeof(struct in6_addr)))
984 if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) {
986 printf(", invalid subject len");
989 printf(", subject=%s",
990 getname6((const u_char *)(ni6 + 1)));
992 case ICMP6_NI_SUBJ_FQDN:
993 printf(", subject=DNS name");
994 cp = (const u_char *)(ni6 + 1);
995 if (cp[0] == ep - cp - 1) {
996 /* icmp-name-lookup-03, pascal string */
998 printf(", 03 draft");
1007 dnsname_print(cp, ep);
1009 case ICMP6_NI_SUBJ_IPV4:
1010 if (!TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr)))
1012 if (siz != sizeof(*ni6) + sizeof(struct in_addr)) {
1014 printf(", invalid subject len");
1017 printf(", subject=%s",
1018 getname((const u_char *)(ni6 + 1)));
1021 printf(", unknown subject");
1029 case ICMP6_NI_REPLY:
1030 if (icmp6len > siz) {
1031 printf("[|icmp6: node information reply]");
1037 ni6 = (struct icmp6_nodeinfo *)dp;
1038 printf(" node information reply");
1040 switch (ni6->ni_code) {
1041 case ICMP6_NI_SUCCESS:
1047 case ICMP6_NI_REFUSED:
1050 if (siz != sizeof(*ni6))
1052 printf(", invalid length");
1054 case ICMP6_NI_UNKNOWN:
1057 if (siz != sizeof(*ni6))
1059 printf(", invalid length");
1063 if (ni6->ni_code != ICMP6_NI_SUCCESS) {
1069 switch (EXTRACT_16BITS(&ni6->ni_qtype)) {
1074 if (siz != sizeof(*ni6))
1076 printf(", invalid length");
1078 case NI_QTYPE_SUPTYPES:
1081 printf("supported qtypes");
1082 i = EXTRACT_16BITS(&ni6->ni_flags);
1084 printf(" [%s]", (i & 0x01) ? "C" : "");
1090 cp = (const u_char *)(ni6 + 1) + 4;
1091 if (cp[0] == ep - cp - 1) {
1092 /* icmp-name-lookup-03, pascal string */
1094 printf(", 03 draft");
1103 dnsname_print(cp, ep);
1104 if ((EXTRACT_16BITS(&ni6->ni_flags) & 0x01) != 0)
1105 printf(" [TTL=%u]", *(u_int32_t *)(ni6 + 1));
1107 case NI_QTYPE_NODEADDR:
1110 printf("node addresses");
1113 if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz)
1115 printf(" %s", getname6(bp + i));
1116 i += sizeof(struct in6_addr);
1117 printf("(%d)", (int32_t)EXTRACT_32BITS(bp + i));
1118 i += sizeof(int32_t);
1123 printf(" [%s%s%s%s%s%s%s]",
1124 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1125 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1126 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1127 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1128 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1129 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
1130 (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : "");
1146 fputs("[|icmp6]", stdout);
1150 icmp6_rrenum_print(const u_char *bp, const u_char *ep)
1152 struct icmp6_router_renum *rr6;
1154 struct rr_pco_match *match;
1155 struct rr_pco_use *use;
1156 char hbuf[NI_MAXHOST];
1161 rr6 = (struct icmp6_router_renum *)bp;
1162 cp = (const char *)(rr6 + 1);
1164 TCHECK(rr6->rr_reserved);
1165 switch (rr6->rr_code) {
1166 case ICMP6_ROUTER_RENUMBERING_COMMAND:
1167 printf("router renum: command");
1169 case ICMP6_ROUTER_RENUMBERING_RESULT:
1170 printf("router renum: result");
1172 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET:
1173 printf("router renum: sequence number reset");
1176 printf("router renum: code-#%d", rr6->rr_code);
1180 printf(", seq=%u", EXTRACT_32BITS(&rr6->rr_seqnum));
1183 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1185 if (rr6->rr_flags) {
1186 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"),
1187 F(ICMP6_RR_FLAGS_REQRESULT, "R"),
1188 F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"),
1189 F(ICMP6_RR_FLAGS_SPECSITE, "S"),
1190 F(ICMP6_RR_FLAGS_PREVDONE, "P"));
1192 printf("seg=%u,", rr6->rr_segnum);
1193 printf("maxdelay=%u", rr6->rr_maxdelay);
1194 if (rr6->rr_reserved)
1195 printf("rsvd=0x%x", EXTRACT_16BITS(&rr6->rr_reserved));
1201 if (rr6->rr_code == ICMP6_ROUTER_RENUMBERING_COMMAND) {
1202 match = (struct rr_pco_match *)cp;
1203 cp = (const char *)(match + 1);
1205 TCHECK(match->rpm_prefix);
1211 printf("match("); /*)*/
1212 switch (match->rpm_code) {
1213 case RPM_PCO_ADD: printf("add"); break;
1214 case RPM_PCO_CHANGE: printf("change"); break;
1215 case RPM_PCO_SETGLOBAL: printf("setglobal"); break;
1216 default: printf("#%u", match->rpm_code); break;
1220 printf(",ord=%u", match->rpm_ordinal);
1221 printf(",min=%u", match->rpm_minlen);
1222 printf(",max=%u", match->rpm_maxlen);
1224 if (inet_ntop(AF_INET6, &match->rpm_prefix, hbuf, sizeof(hbuf)))
1225 printf(",%s/%u", hbuf, match->rpm_matchlen);
1227 printf(",?/%u", match->rpm_matchlen);
1231 n = match->rpm_len - 3;
1236 use = (struct rr_pco_use *)cp;
1237 cp = (const char *)(use + 1);
1239 TCHECK(use->rpu_prefix);
1245 printf("use("); /*)*/
1246 if (use->rpu_flags) {
1247 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1249 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"),
1250 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P"));
1254 printf("mask=0x%x,", use->rpu_ramask);
1255 printf("raflags=0x%x,", use->rpu_raflags);
1256 if (~use->rpu_vltime == 0)
1257 printf("vltime=infty,");
1259 printf("vltime=%u,",
1260 EXTRACT_32BITS(&use->rpu_vltime));
1261 if (~use->rpu_pltime == 0)
1262 printf("pltime=infty,");
1264 printf("pltime=%u,",
1265 EXTRACT_32BITS(&use->rpu_pltime));
1267 if (inet_ntop(AF_INET6, &use->rpu_prefix, hbuf,
1269 printf("%s/%u/%u", hbuf, use->rpu_uselen,
1272 printf("?/%u/%u", use->rpu_uselen,
1282 fputs("[|icmp6]", stdout);