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
==
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], sizeof(struct in6_addr
));
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
* sizeof(struct in6_addr
))) {
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
* sizeof(struct in6_addr
)],
784 sizeof(struct in6_addr
));
785 printf(" %s", ip6addr_string(&bp
[group
+ 20 + j
* sizeof(struct in6_addr
)]));
789 /* Next group record */
790 group
+= 20 + nsrcs
* sizeof(struct in6_addr
);
796 (void)printf("[|icmp6]");
801 mldv2_query_print(const u_char
*bp
, u_int len
)
803 struct icmp6_hdr
*icp
= (struct icmp6_hdr
*) bp
;
809 /* Minimum len is 28 */
811 printf(" [invalid len %d]", len
);
814 TCHECK(icp
->icmp6_data16
[0]);
815 mrc
= ntohs(icp
->icmp6_data16
[0]);
819 mrt
= ((mrc
& 0x0fff) | 0x1000) << (((mrc
& 0x7000) >> 12) + 3);
822 (void)printf(" [max resp delay=%d]", mrt
);
824 TCHECK2(bp
[8], sizeof(struct in6_addr
));
825 printf(" [gaddr %s", ip6addr_string(&bp
[8]));
833 printf(" robustness=%d", bp
[24] & 0x07);
838 qqi
= ((bp
[25] & 0x0f) | 0x10) << (((bp
[25] & 0x70) >> 4) + 3);
840 printf(" qqi=%d", qqi
);
844 nsrcs
= ntohs(*(u_short
*)&bp
[26]);
846 if (len
< 28 + nsrcs
* sizeof(struct in6_addr
))
847 printf(" [invalid number of sources]");
848 else if (vflag
> 1) {
850 for (i
= 0; i
< nsrcs
; i
++) {
851 TCHECK2(bp
[28 + i
* sizeof(struct in6_addr
)],
852 sizeof(struct in6_addr
));
853 printf(" %s", ip6addr_string(&bp
[28 + i
* sizeof(struct in6_addr
)]));
857 printf(", %d source(s)", nsrcs
);
862 (void)printf("[|icmp6]");
867 dnsname_print(const u_char
*cp
, const u_char
*ep
)
871 /* DNS name decoding - no decompression */
880 while (i
-- && cp
< ep
) {
884 if (cp
+ 1 < ep
&& *cp
)
890 } else if (cp
+ 1 == ep
&& *cp
== '\0') {
903 icmp6_nodeinfo_print(u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
905 struct icmp6_nodeinfo
*ni6
;
906 struct icmp6_hdr
*dp
;
913 dp
= (struct icmp6_hdr
*)bp
;
914 ni6
= (struct icmp6_nodeinfo
*)bp
;
917 switch (ni6
->ni_type
) {
919 if (siz
== sizeof(*dp
) + 4) {
920 /* KAME who-are-you */
921 printf(" who-are-you request");
924 printf(" node information query");
926 TCHECK2(*dp
, sizeof(*ni6
));
927 ni6
= (struct icmp6_nodeinfo
*)dp
;
929 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
933 case NI_QTYPE_SUPTYPES
:
934 printf("supported qtypes");
935 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
937 printf(" [%s]", (i
& 0x01) ? "C" : "");
943 case NI_QTYPE_NODEADDR
:
944 printf("node addresses");
948 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
949 printf(" [%s%s%s%s%s%s]",
950 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
951 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
952 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
953 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
954 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
955 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "");
962 if (ni6
->ni_qtype
== NI_QTYPE_NOOP
||
963 ni6
->ni_qtype
== NI_QTYPE_SUPTYPES
) {
964 if (siz
!= sizeof(*ni6
))
966 printf(", invalid len");
973 /* XXX backward compat, icmp-name-lookup-03 */
974 if (siz
== sizeof(*ni6
)) {
975 printf(", 03 draft");
981 switch (ni6
->ni_code
) {
982 case ICMP6_NI_SUBJ_IPV6
:
984 sizeof(*ni6
) + sizeof(struct in6_addr
)))
986 if (siz
!= sizeof(*ni6
) + sizeof(struct in6_addr
)) {
988 printf(", invalid subject len");
991 printf(", subject=%s",
992 getname6((const u_char
*)(ni6
+ 1)));
994 case ICMP6_NI_SUBJ_FQDN
:
995 printf(", subject=DNS name");
996 cp
= (const u_char
*)(ni6
+ 1);
997 if (cp
[0] == ep
- cp
- 1) {
998 /* icmp-name-lookup-03, pascal string */
1000 printf(", 03 draft");
1009 dnsname_print(cp
, ep
);
1011 case ICMP6_NI_SUBJ_IPV4
:
1012 if (!TTEST2(*dp
, sizeof(*ni6
) + sizeof(struct in_addr
)))
1014 if (siz
!= sizeof(*ni6
) + sizeof(struct in_addr
)) {
1016 printf(", invalid subject len");
1019 printf(", subject=%s",
1020 getname((const u_char
*)(ni6
+ 1)));
1023 printf(", unknown subject");
1031 case ICMP6_NI_REPLY
:
1032 if (icmp6len
> siz
) {
1033 printf("[|icmp6: node information reply]");
1039 ni6
= (struct icmp6_nodeinfo
*)dp
;
1040 printf(" node information reply");
1042 switch (ni6
->ni_code
) {
1043 case ICMP6_NI_SUCCESS
:
1049 case ICMP6_NI_REFUSED
:
1052 if (siz
!= sizeof(*ni6
))
1054 printf(", invalid length");
1056 case ICMP6_NI_UNKNOWN
:
1059 if (siz
!= sizeof(*ni6
))
1061 printf(", invalid length");
1065 if (ni6
->ni_code
!= ICMP6_NI_SUCCESS
) {
1071 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
1076 if (siz
!= sizeof(*ni6
))
1078 printf(", invalid length");
1080 case NI_QTYPE_SUPTYPES
:
1083 printf("supported qtypes");
1084 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
1086 printf(" [%s]", (i
& 0x01) ? "C" : "");
1092 cp
= (const u_char
*)(ni6
+ 1) + 4;
1093 if (cp
[0] == ep
- cp
- 1) {
1094 /* icmp-name-lookup-03, pascal string */
1096 printf(", 03 draft");
1105 dnsname_print(cp
, ep
);
1106 if ((EXTRACT_16BITS(&ni6
->ni_flags
) & 0x01) != 0)
1107 printf(" [TTL=%u]", *(u_int32_t
*)(ni6
+ 1));
1109 case NI_QTYPE_NODEADDR
:
1112 printf("node addresses");
1115 if (i
+ sizeof(struct in6_addr
) + sizeof(int32_t) > siz
)
1117 printf(" %s", getname6(bp
+ i
));
1118 i
+= sizeof(struct in6_addr
);
1119 printf("(%d)", (int32_t)EXTRACT_32BITS(bp
+ i
));
1120 i
+= sizeof(int32_t);
1125 printf(" [%s%s%s%s%s%s%s]",
1126 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1127 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1128 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1129 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1130 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1131 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
1132 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : "");
1148 fputs("[|icmp6]", stdout
);
1152 icmp6_rrenum_print(const u_char
*bp
, const u_char
*ep
)
1154 struct icmp6_router_renum
*rr6
;
1156 struct rr_pco_match
*match
;
1157 struct rr_pco_use
*use
;
1158 char hbuf
[NI_MAXHOST
];
1163 rr6
= (struct icmp6_router_renum
*)bp
;
1164 cp
= (const char *)(rr6
+ 1);
1166 TCHECK(rr6
->rr_reserved
);
1167 switch (rr6
->rr_code
) {
1168 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
1169 printf("router renum: command");
1171 case ICMP6_ROUTER_RENUMBERING_RESULT
:
1172 printf("router renum: result");
1174 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
1175 printf("router renum: sequence number reset");
1178 printf("router renum: code-#%d", rr6
->rr_code
);
1182 printf(", seq=%u", EXTRACT_32BITS(&rr6
->rr_seqnum
));
1185 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1187 if (rr6
->rr_flags
) {
1188 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
1189 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
1190 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
1191 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
1192 F(ICMP6_RR_FLAGS_PREVDONE
, "P"));
1194 printf("seg=%u,", rr6
->rr_segnum
);
1195 printf("maxdelay=%u", EXTRACT_16BITS(&rr6
->rr_maxdelay
));
1196 if (rr6
->rr_reserved
)
1197 printf("rsvd=0x%x", EXTRACT_32BITS(&rr6
->rr_reserved
));
1203 if (rr6
->rr_code
== ICMP6_ROUTER_RENUMBERING_COMMAND
) {
1204 match
= (struct rr_pco_match
*)cp
;
1205 cp
= (const char *)(match
+ 1);
1207 TCHECK(match
->rpm_prefix
);
1213 printf("match("); /*)*/
1214 switch (match
->rpm_code
) {
1215 case RPM_PCO_ADD
: printf("add"); break;
1216 case RPM_PCO_CHANGE
: printf("change"); break;
1217 case RPM_PCO_SETGLOBAL
: printf("setglobal"); break;
1218 default: printf("#%u", match
->rpm_code
); break;
1222 printf(",ord=%u", match
->rpm_ordinal
);
1223 printf(",min=%u", match
->rpm_minlen
);
1224 printf(",max=%u", match
->rpm_maxlen
);
1226 if (inet_ntop(AF_INET6
, &match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
1227 printf(",%s/%u", hbuf
, match
->rpm_matchlen
);
1229 printf(",?/%u", match
->rpm_matchlen
);
1233 n
= match
->rpm_len
- 3;
1238 use
= (struct rr_pco_use
*)cp
;
1239 cp
= (const char *)(use
+ 1);
1241 TCHECK(use
->rpu_prefix
);
1247 printf("use("); /*)*/
1248 if (use
->rpu_flags
) {
1249 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1251 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
1252 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P"));
1256 printf("mask=0x%x,", use
->rpu_ramask
);
1257 printf("raflags=0x%x,", use
->rpu_raflags
);
1258 if (~use
->rpu_vltime
== 0)
1259 printf("vltime=infty,");
1261 printf("vltime=%u,",
1262 EXTRACT_32BITS(&use
->rpu_vltime
));
1263 if (~use
->rpu_pltime
== 0)
1264 printf("pltime=infty,");
1266 printf("pltime=%u,",
1267 EXTRACT_32BITS(&use
->rpu_pltime
));
1269 if (inet_ntop(AF_INET6
, &use
->rpu_prefix
, hbuf
,
1271 printf("%s/%u/%u", hbuf
, use
->rpu_uselen
,
1274 printf("?/%u/%u", use
->rpu_uselen
,
1284 fputs("[|icmp6]", stdout
);