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.72.2.6 2004-07-28 20:09:17 guy Exp $";
33 #include <tcpdump-stdinc.h>
42 #include "interface.h"
43 #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 /* mldv2 report types */
66 static struct tok mldv2report2str
[] = {
79 static const char *rtpref_str
[] = {
86 return rtpref_str
[((v
& ND_RA_FLAG_RTPREF_MASK
) >> 3) & 0xff];
90 get_lifetime(u_int32_t v
)
94 if (v
== (u_int32_t
)~0UL)
97 snprintf(buf
, sizeof(buf
), "%u", v
);
103 print_lladdr(const u_int8_t
*p
, size_t l
)
105 const u_int8_t
*ep
, *q
;
109 while (l
> 0 && q
< ep
) {
112 printf("%02x", *q
++);
117 static int icmp6_cksum(const struct ip6_hdr
*ip6
, const struct icmp6_hdr
*icp
,
121 register const u_int16_t
*sp
;
125 struct in6_addr ph_src
;
126 struct in6_addr ph_dst
;
135 memset(&phu
, 0, sizeof(phu
));
136 phu
.ph
.ph_src
= ip6
->ip6_src
;
137 phu
.ph
.ph_dst
= ip6
->ip6_dst
;
138 phu
.ph
.ph_len
= htonl(len
);
139 phu
.ph
.ph_nxt
= IPPROTO_ICMPV6
;
142 for (i
= 0; i
< sizeof(phu
.pa
) / sizeof(phu
.pa
[0]); i
++)
145 sp
= (const u_int16_t
*)icp
;
147 for (i
= 0; i
< (len
& ~1); i
+= 2)
151 sum
+= htons((*(const u_int8_t
*)sp
) << 8);
154 sum
= (sum
& 0xffff) + (sum
>> 16);
161 icmp6_print(const u_char
*bp
, u_int length
, const u_char
*bp2
, int fragmented
)
163 const struct icmp6_hdr
*dp
;
164 const struct ip6_hdr
*ip
;
166 const struct ip6_hdr
*oip
;
167 const struct udphdr
*ouh
;
173 dp
= (struct icmp6_hdr
*)bp
;
174 ip
= (struct ip6_hdr
*)bp2
;
175 oip
= (struct ip6_hdr
*)(dp
+ 1);
177 /* 'ep' points to the end of available data. */
180 TCHECK(dp
->icmp6_cksum
);
182 if (vflag
&& !fragmented
) {
183 int sum
= dp
->icmp6_cksum
;
185 if (TTEST2(bp
[0], length
)) {
186 sum
= icmp6_cksum(ip
, dp
, length
);
188 (void)printf("[bad icmp6 cksum %x!] ", sum
);
190 (void)printf("[icmp6 sum ok] ");
194 switch (dp
->icmp6_type
) {
195 case ICMP6_DST_UNREACH
:
196 TCHECK(oip
->ip6_dst
);
197 switch (dp
->icmp6_code
) {
198 case ICMP6_DST_UNREACH_NOROUTE
:
199 printf("icmp6: %s unreachable route",
200 ip6addr_string(&oip
->ip6_dst
));
202 case ICMP6_DST_UNREACH_ADMIN
:
203 printf("icmp6: %s unreachable prohibited",
204 ip6addr_string(&oip
->ip6_dst
));
206 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
207 printf("icmp6: %s beyond scope of source address %s",
208 ip6addr_string(&oip
->ip6_dst
),
209 ip6addr_string(&oip
->ip6_src
));
211 case ICMP6_DST_UNREACH_ADDR
:
212 printf("icmp6: %s unreachable address",
213 ip6addr_string(&oip
->ip6_dst
));
215 case ICMP6_DST_UNREACH_NOPORT
:
216 if ((ouh
= get_upperlayer((u_char
*)oip
, &prot
))
220 dport
= EXTRACT_16BITS(&ouh
->uh_dport
);
223 printf("icmp6: %s tcp port %s unreachable",
224 ip6addr_string(&oip
->ip6_dst
),
225 tcpport_string(dport
));
228 printf("icmp6: %s udp port %s unreachable",
229 ip6addr_string(&oip
->ip6_dst
),
230 udpport_string(dport
));
233 printf("icmp6: %s protocol %d port %d unreachable",
234 ip6addr_string(&oip
->ip6_dst
),
235 oip
->ip6_nxt
, dport
);
240 printf("icmp6: %s unreachable code-#%d",
241 ip6addr_string(&oip
->ip6_dst
),
246 case ICMP6_PACKET_TOO_BIG
:
247 TCHECK(dp
->icmp6_mtu
);
248 printf("icmp6: too big %u", EXTRACT_32BITS(&dp
->icmp6_mtu
));
250 case ICMP6_TIME_EXCEEDED
:
251 TCHECK(oip
->ip6_dst
);
252 switch (dp
->icmp6_code
) {
253 case ICMP6_TIME_EXCEED_TRANSIT
:
254 printf("icmp6: time exceeded in-transit for %s",
255 ip6addr_string(&oip
->ip6_dst
));
257 case ICMP6_TIME_EXCEED_REASSEMBLY
:
258 printf("icmp6: ip6 reassembly time exceeded");
261 printf("icmp6: time exceeded code-#%d",
266 case ICMP6_PARAM_PROB
:
267 TCHECK(oip
->ip6_dst
);
268 switch (dp
->icmp6_code
) {
269 case ICMP6_PARAMPROB_HEADER
:
270 printf("icmp6: parameter problem errorneous - octet %u",
271 EXTRACT_32BITS(&dp
->icmp6_pptr
));
273 case ICMP6_PARAMPROB_NEXTHEADER
:
274 printf("icmp6: parameter problem next header - octet %u",
275 EXTRACT_32BITS(&dp
->icmp6_pptr
));
277 case ICMP6_PARAMPROB_OPTION
:
278 printf("icmp6: parameter problem option - octet %u",
279 EXTRACT_32BITS(&dp
->icmp6_pptr
));
282 printf("icmp6: parameter problem code-#%d",
287 case ICMP6_ECHO_REQUEST
:
288 case ICMP6_ECHO_REPLY
:
289 TCHECK(dp
->icmp6_seq
);
290 printf("icmp6: echo %s seq %u",
291 dp
->icmp6_type
== ICMP6_ECHO_REQUEST
?
293 EXTRACT_16BITS(&dp
->icmp6_seq
));
295 case ICMP6_MEMBERSHIP_QUERY
:
296 printf("icmp6: multicast listener query ");
297 if (length
== MLD_MINLEN
) {
298 mld6_print((const u_char
*)dp
);
299 } else if (length
>= MLDV2_MINLEN
) {
301 mldv2_query_print((const u_char
*)dp
, length
);
303 printf(" unknown-version(len=%d) ", length
);
306 case ICMP6_MEMBERSHIP_REPORT
:
307 printf("icmp6: multicast listener report ");
308 mld6_print((const u_char
*)dp
);
310 case ICMP6_MEMBERSHIP_REDUCTION
:
311 printf("icmp6: multicast listener done ");
312 mld6_print((const u_char
*)dp
);
314 case ND_ROUTER_SOLICIT
:
315 printf("icmp6: router solicitation ");
318 icmp6_opt_print((const u_char
*)dp
+ RTSOLLEN
,
322 case ND_ROUTER_ADVERT
:
323 printf("icmp6: router advertisement");
325 struct nd_router_advert
*p
;
327 p
= (struct nd_router_advert
*)dp
;
328 TCHECK(p
->nd_ra_retransmit
);
329 printf("(chlim=%d, ", (int)p
->nd_ra_curhoplimit
);
330 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_MANAGED
)
332 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_OTHER
)
334 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_HOME_AGENT
)
337 if ((p
->nd_ra_flags_reserved
& ~ND_RA_FLAG_RTPREF_MASK
)
342 get_rtpref(p
->nd_ra_flags_reserved
));
344 printf("router_ltime=%d, ", EXTRACT_16BITS(&p
->nd_ra_router_lifetime
));
345 printf("reachable_time=%u, ",
346 EXTRACT_32BITS(&p
->nd_ra_reachable
));
347 printf("retrans_time=%u)",
348 EXTRACT_32BITS(&p
->nd_ra_retransmit
));
350 icmp6_opt_print((const u_char
*)dp
+ RTADVLEN
,
354 case ND_NEIGHBOR_SOLICIT
:
356 struct nd_neighbor_solicit
*p
;
357 p
= (struct nd_neighbor_solicit
*)dp
;
358 TCHECK(p
->nd_ns_target
);
359 printf("icmp6: neighbor sol: who has %s",
360 ip6addr_string(&p
->nd_ns_target
));
363 icmp6_opt_print((const u_char
*)dp
+ NDSOLLEN
,
368 case ND_NEIGHBOR_ADVERT
:
370 struct nd_neighbor_advert
*p
;
372 p
= (struct nd_neighbor_advert
*)dp
;
373 TCHECK(p
->nd_na_target
);
374 printf("icmp6: neighbor adv: tgt is %s",
375 ip6addr_string(&p
->nd_na_target
));
377 #define ND_NA_FLAG_ALL \
378 (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE)
379 /* we don't need ntohl() here. see advanced-api-04. */
380 if (p
->nd_na_flags_reserved
& ND_NA_FLAG_ALL
) {
381 #undef ND_NA_FLAG_ALL
384 flags
= p
->nd_na_flags_reserved
;
386 if (flags
& ND_NA_FLAG_ROUTER
)
388 if (flags
& ND_NA_FLAG_SOLICITED
)
390 if (flags
& ND_NA_FLAG_OVERRIDE
)
395 icmp6_opt_print((const u_char
*)dp
+ NDADVLEN
,
402 #define RDR(i) ((struct nd_redirect *)(i))
403 TCHECK(RDR(dp
)->nd_rd_dst
);
404 printf("icmp6: redirect %s",
405 getname6((const u_char
*)&RDR(dp
)->nd_rd_dst
));
406 TCHECK(RDR(dp
)->nd_rd_target
);
408 getname6((const u_char
*)&RDR(dp
)->nd_rd_target
));
409 #define REDIRECTLEN 40
411 icmp6_opt_print((const u_char
*)dp
+ REDIRECTLEN
,
412 length
- REDIRECTLEN
);
417 case ICMP6_ROUTER_RENUMBERING
:
418 icmp6_rrenum_print(bp
, ep
);
422 icmp6_nodeinfo_print(length
, bp
, ep
);
425 printf("icmp6: inverse neighbor solicitation");
428 printf("icmp6: inverse neighbor advertisement");
430 case ICMP6_V2_MEMBERSHIP_REPORT
:
431 printf("icmp6: multicast listener report v2 ");
432 mldv2_report_print((const u_char
*) dp
, length
);
434 case ICMP6_HADISCOV_REQUEST
:
435 printf("icmp6: ha discovery request");
437 TCHECK(dp
->icmp6_data16
[0]);
438 printf("(id=%d)", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
441 case ICMP6_HADISCOV_REPLY
:
442 printf("icmp6: ha discovery reply");
444 struct in6_addr
*in6
;
447 TCHECK(dp
->icmp6_data16
[0]);
448 printf("(id=%d", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
449 cp
= (u_char
*)dp
+ length
;
450 in6
= (struct in6_addr
*)(dp
+ 1);
451 for (; (u_char
*)in6
< cp
; in6
++) {
453 printf(", %s", ip6addr_string(in6
));
458 case ICMP6_MOBILEPREFIX_SOLICIT
:
459 printf("icmp6: mobile router solicitation");
461 TCHECK(dp
->icmp6_data16
[0]);
462 printf("(id=%d)", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
465 case ICMP6_MOBILEPREFIX_ADVERT
:
466 printf("icmp6: mobile router advertisement");
468 TCHECK(dp
->icmp6_data16
[0]);
469 printf("(id=%d", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
470 if (dp
->icmp6_data16
[1] & 0xc0)
472 if (dp
->icmp6_data16
[1] & 0x80)
474 if (dp
->icmp6_data16
[1] & 0x40)
478 icmp6_opt_print((const u_char
*)dp
+ MPADVLEN
,
483 printf("icmp6: type-#%d", dp
->icmp6_type
);
488 fputs("[|icmp6]", stdout
);
491 static struct udphdr
*
492 get_upperlayer(u_char
*bp
, u_int
*prot
)
495 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
498 struct ip6_frag
*fragh
;
503 /* 'ep' points to the end of available data. */
506 if (!TTEST(ip6
->ip6_nxt
))
510 hlen
= sizeof(struct ip6_hdr
);
512 while (bp
< snapend
) {
518 uh
= (struct udphdr
*)bp
;
519 if (TTEST(uh
->uh_dport
)) {
527 case IPPROTO_HOPOPTS
:
528 case IPPROTO_DSTOPTS
:
529 case IPPROTO_ROUTING
:
530 hbh
= (struct ip6_hbh
*)bp
;
531 if (!TTEST(hbh
->ip6h_len
))
534 hlen
= (hbh
->ip6h_len
+ 1) << 3;
537 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
538 fragh
= (struct ip6_frag
*)bp
;
539 if (!TTEST(fragh
->ip6f_offlg
))
541 /* fragments with non-zero offset are meaningless */
542 if ((EXTRACT_16BITS(&fragh
->ip6f_offlg
) & IP6F_OFF_MASK
) != 0)
544 nh
= fragh
->ip6f_nxt
;
545 hlen
= sizeof(struct ip6_frag
);
549 ah
= (struct ah
*)bp
;
550 if (!TTEST(ah
->ah_len
))
553 hlen
= (ah
->ah_len
+ 2) << 2;
556 default: /* unknown or undecodable header */
557 *prot
= nh
; /* meaningless, but set here anyway */
562 return(NULL
); /* should be notreached, though */
566 icmp6_opt_print(const u_char
*bp
, int resid
)
568 const struct nd_opt_hdr
*op
;
569 const struct nd_opt_hdr
*opl
; /* why there's no struct? */
570 const struct nd_opt_prefix_info
*opp
;
571 const struct icmp6_opts_redirect
*opr
;
572 const struct nd_opt_mtu
*opm
;
573 const struct nd_opt_advinterval
*opa
;
574 const struct nd_opt_homeagent_info
*oph
;
575 const struct nd_opt_route_info
*opri
;
576 const u_char
*cp
, *ep
;
577 struct in6_addr in6
, *in6p
;
580 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
583 /* 'ep' points to the end of available data. */
587 op
= (struct nd_opt_hdr
*)cp
;
589 ECHECK(op
->nd_opt_len
);
592 if (op
->nd_opt_len
== 0)
594 if (cp
+ (op
->nd_opt_len
<< 3) > ep
)
597 switch (op
->nd_opt_type
) {
598 case ND_OPT_SOURCE_LINKADDR
:
599 opl
= (struct nd_opt_hdr
*)op
;
600 printf("(src lladdr: ");
601 l
= (op
->nd_opt_len
<< 3) - 2;
602 print_lladdr(cp
+ 2, l
);
606 case ND_OPT_TARGET_LINKADDR
:
607 opl
= (struct nd_opt_hdr
*)op
;
608 printf("(tgt lladdr: ");
609 l
= (op
->nd_opt_len
<< 3) - 2;
610 print_lladdr(cp
+ 2, l
);
614 case ND_OPT_PREFIX_INFORMATION
:
615 opp
= (struct nd_opt_prefix_info
*)op
;
616 TCHECK(opp
->nd_opt_pi_prefix
);
617 printf("(prefix info: "); /*)*/
618 if (op
->nd_opt_len
!= 4) {
624 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_ONLINK
)
626 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_AUTO
)
628 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_ROUTER
)
630 if (opp
->nd_opt_pi_flags_reserved
)
632 printf("valid_ltime=%s,",
633 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_valid_time
)));
634 printf("preferred_ltime=%s,",
635 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_preferred_time
)));
636 printf("prefix=%s/%d",
637 ip6addr_string(&opp
->nd_opt_pi_prefix
),
638 opp
->nd_opt_pi_prefix_len
);
639 if (opp
->nd_opt_pi_len
!= 4)
644 case ND_OPT_REDIRECTED_HEADER
:
645 opr
= (struct icmp6_opts_redirect
*)op
;
646 printf("(redirect)");
650 opm
= (struct nd_opt_mtu
*)op
;
651 TCHECK(opm
->nd_opt_mtu_mtu
);
652 printf("(mtu:"); /*)*/
653 if (op
->nd_opt_len
!= 1) {
659 printf(" mtu=%u", EXTRACT_32BITS(&opm
->nd_opt_mtu_mtu
));
660 if (opm
->nd_opt_mtu_len
!= 1)
664 case ND_OPT_ADVINTERVAL
:
665 opa
= (struct nd_opt_advinterval
*)op
;
666 TCHECK(opa
->nd_opt_adv_interval
);
667 printf("(advint:"); /*)*/
669 EXTRACT_32BITS(&opa
->nd_opt_adv_interval
));
673 case ND_OPT_HOMEAGENT_INFO
:
674 oph
= (struct nd_opt_homeagent_info
*)op
;
675 TCHECK(oph
->nd_opt_hai_lifetime
);
676 printf("(ha info:"); /*)*/
677 printf(" pref=%d", EXTRACT_16BITS(&oph
->nd_opt_hai_preference
));
678 printf(", lifetime=%u", EXTRACT_16BITS(&oph
->nd_opt_hai_lifetime
));
681 case ND_OPT_ROUTE_INFO
:
682 opri
= (struct nd_opt_route_info
*)op
;
683 TCHECK(opri
->nd_opt_rti_lifetime
);
684 memset(&in6
, 0, sizeof(in6
));
685 in6p
= (struct in6_addr
*)(opri
+ 1);
686 switch (op
->nd_opt_len
) {
691 memcpy(&in6
, opri
+ 1, 8);
695 memcpy(&in6
, opri
+ 1, sizeof(in6
));
700 printf("(rtinfo:"); /*)*/
701 printf(" %s/%u", ip6addr_string(&in6
),
702 opri
->nd_opt_rti_prefixlen
);
703 printf(", pref=%s", get_rtpref(opri
->nd_opt_rti_flags
));
704 printf(", lifetime=%s",
705 get_lifetime(EXTRACT_32BITS(&opri
->nd_opt_rti_lifetime
)));
710 printf("(unknown opt_type=%d, opt_len=%d)",
711 op
->nd_opt_type
, op
->nd_opt_len
);
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("icmp6: who-are-you request");
922 printf("icmp6: 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("icmp6: 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
;
1153 struct icmp6_hdr
*dp
;
1156 struct rr_pco_match
*match
;
1157 struct rr_pco_use
*use
;
1158 char hbuf
[NI_MAXHOST
];
1163 dp
= (struct icmp6_hdr
*)bp
;
1164 rr6
= (struct icmp6_router_renum
*)bp
;
1166 cp
= (const char *)(rr6
+ 1);
1168 TCHECK(rr6
->rr_reserved
);
1169 switch (rr6
->rr_code
) {
1170 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
1171 printf("router renum: command");
1173 case ICMP6_ROUTER_RENUMBERING_RESULT
:
1174 printf("router renum: result");
1176 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
1177 printf("router renum: sequence number reset");
1180 printf("router renum: code-#%d", rr6
->rr_code
);
1184 printf(", seq=%u", EXTRACT_32BITS(&rr6
->rr_seqnum
));
1187 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1189 if (rr6
->rr_flags
) {
1190 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
1191 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
1192 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
1193 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
1194 F(ICMP6_RR_FLAGS_PREVDONE
, "P"));
1196 printf("seg=%u,", rr6
->rr_segnum
);
1197 printf("maxdelay=%u", rr6
->rr_maxdelay
);
1198 if (rr6
->rr_reserved
)
1199 printf("rsvd=0x%x", EXTRACT_16BITS(&rr6
->rr_reserved
));
1205 if (rr6
->rr_code
== ICMP6_ROUTER_RENUMBERING_COMMAND
) {
1206 match
= (struct rr_pco_match
*)cp
;
1207 cp
= (const char *)(match
+ 1);
1209 TCHECK(match
->rpm_prefix
);
1215 printf("match("); /*)*/
1216 switch (match
->rpm_code
) {
1217 case RPM_PCO_ADD
: printf("add"); break;
1218 case RPM_PCO_CHANGE
: printf("change"); break;
1219 case RPM_PCO_SETGLOBAL
: printf("setglobal"); break;
1220 default: printf("#%u", match
->rpm_code
); break;
1224 printf(",ord=%u", match
->rpm_ordinal
);
1225 printf(",min=%u", match
->rpm_minlen
);
1226 printf(",max=%u", match
->rpm_maxlen
);
1228 if (inet_ntop(AF_INET6
, &match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
1229 printf(",%s/%u", hbuf
, match
->rpm_matchlen
);
1231 printf(",?/%u", match
->rpm_matchlen
);
1235 n
= match
->rpm_len
- 3;
1240 use
= (struct rr_pco_use
*)cp
;
1241 cp
= (const char *)(use
+ 1);
1243 TCHECK(use
->rpu_prefix
);
1249 printf("use("); /*)*/
1250 if (use
->rpu_flags
) {
1251 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1253 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
1254 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P"));
1258 printf("mask=0x%x,", use
->rpu_ramask
);
1259 printf("raflags=0x%x,", use
->rpu_raflags
);
1260 if (~use
->rpu_vltime
== 0)
1261 printf("vltime=infty,");
1263 printf("vltime=%u,",
1264 EXTRACT_32BITS(&use
->rpu_vltime
));
1265 if (~use
->rpu_pltime
== 0)
1266 printf("pltime=infty,");
1268 printf("pltime=%u,",
1269 EXTRACT_32BITS(&use
->rpu_pltime
));
1271 if (inet_ntop(AF_INET6
, &use
->rpu_prefix
, hbuf
,
1273 printf("%s/%u/%u", hbuf
, use
->rpu_uselen
,
1276 printf("?/%u/%u", use
->rpu_uselen
,
1286 fputs("[|icmp6]", stdout
);