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.4 2004-03-24 00:14:09 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 struct udphdr
*get_upperlayer(u_char
*, u_int
*);
55 static void dnsname_print(const u_char
*, const u_char
*);
56 static void icmp6_nodeinfo_print(u_int
, const u_char
*, const u_char
*);
57 static void icmp6_rrenum_print(const u_char
*, const u_char
*);
60 #define abs(a) ((0 < (a)) ? (a) : -(a))
66 static const char *rtpref_str
[] = {
73 return rtpref_str
[((v
& ND_RA_FLAG_RTPREF_MASK
) >> 3) & 0xff];
77 get_lifetime(u_int32_t v
)
81 if (v
== (u_int32_t
)~0UL)
84 snprintf(buf
, sizeof(buf
), "%u", v
);
90 print_lladdr(const u_int8_t
*p
, size_t l
)
92 const u_int8_t
*ep
, *q
;
96 while (l
> 0 && q
< ep
) {
104 static int icmp6_cksum(const struct ip6_hdr
*ip6
, const struct icmp6_hdr
*icp
,
108 register const u_int16_t
*sp
;
112 struct in6_addr ph_src
;
113 struct in6_addr ph_dst
;
122 memset(&phu
, 0, sizeof(phu
));
123 phu
.ph
.ph_src
= ip6
->ip6_src
;
124 phu
.ph
.ph_dst
= ip6
->ip6_dst
;
125 phu
.ph
.ph_len
= htonl(len
);
126 phu
.ph
.ph_nxt
= IPPROTO_ICMPV6
;
129 for (i
= 0; i
< sizeof(phu
.pa
) / sizeof(phu
.pa
[0]); i
++)
132 sp
= (const u_int16_t
*)icp
;
134 for (i
= 0; i
< (len
& ~1); i
+= 2)
138 sum
+= htons((*(const u_int8_t
*)sp
) << 8);
141 sum
= (sum
& 0xffff) + (sum
>> 16);
148 icmp6_print(const u_char
*bp
, u_int length
, const u_char
*bp2
, int fragmented
)
150 const struct icmp6_hdr
*dp
;
151 const struct ip6_hdr
*ip
;
153 const struct ip6_hdr
*oip
;
154 const struct udphdr
*ouh
;
160 dp
= (struct icmp6_hdr
*)bp
;
161 ip
= (struct ip6_hdr
*)bp2
;
162 oip
= (struct ip6_hdr
*)(dp
+ 1);
164 /* 'ep' points to the end of available data. */
167 TCHECK(dp
->icmp6_cksum
);
169 if (vflag
&& !fragmented
) {
170 int sum
= dp
->icmp6_cksum
;
172 if (TTEST2(bp
[0], length
)) {
173 sum
= icmp6_cksum(ip
, dp
, length
);
175 (void)printf("[bad icmp6 cksum %x!] ", sum
);
177 (void)printf("[icmp6 sum ok] ");
181 switch (dp
->icmp6_type
) {
182 case ICMP6_DST_UNREACH
:
183 TCHECK(oip
->ip6_dst
);
184 switch (dp
->icmp6_code
) {
185 case ICMP6_DST_UNREACH_NOROUTE
:
186 printf("icmp6: %s unreachable route",
187 ip6addr_string(&oip
->ip6_dst
));
189 case ICMP6_DST_UNREACH_ADMIN
:
190 printf("icmp6: %s unreachable prohibited",
191 ip6addr_string(&oip
->ip6_dst
));
193 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
194 printf("icmp6: %s beyond scope of source address %s",
195 ip6addr_string(&oip
->ip6_dst
),
196 ip6addr_string(&oip
->ip6_src
));
198 case ICMP6_DST_UNREACH_ADDR
:
199 printf("icmp6: %s unreachable address",
200 ip6addr_string(&oip
->ip6_dst
));
202 case ICMP6_DST_UNREACH_NOPORT
:
203 if ((ouh
= get_upperlayer((u_char
*)oip
, &prot
))
207 dport
= EXTRACT_16BITS(&ouh
->uh_dport
);
210 printf("icmp6: %s tcp port %s unreachable",
211 ip6addr_string(&oip
->ip6_dst
),
212 tcpport_string(dport
));
215 printf("icmp6: %s udp port %s unreachable",
216 ip6addr_string(&oip
->ip6_dst
),
217 udpport_string(dport
));
220 printf("icmp6: %s protocol %d port %d unreachable",
221 ip6addr_string(&oip
->ip6_dst
),
222 oip
->ip6_nxt
, dport
);
227 printf("icmp6: %s unreachable code-#%d",
228 ip6addr_string(&oip
->ip6_dst
),
233 case ICMP6_PACKET_TOO_BIG
:
234 TCHECK(dp
->icmp6_mtu
);
235 printf("icmp6: too big %u", EXTRACT_32BITS(&dp
->icmp6_mtu
));
237 case ICMP6_TIME_EXCEEDED
:
238 TCHECK(oip
->ip6_dst
);
239 switch (dp
->icmp6_code
) {
240 case ICMP6_TIME_EXCEED_TRANSIT
:
241 printf("icmp6: time exceeded in-transit for %s",
242 ip6addr_string(&oip
->ip6_dst
));
244 case ICMP6_TIME_EXCEED_REASSEMBLY
:
245 printf("icmp6: ip6 reassembly time exceeded");
248 printf("icmp6: time exceeded code-#%d",
253 case ICMP6_PARAM_PROB
:
254 TCHECK(oip
->ip6_dst
);
255 switch (dp
->icmp6_code
) {
256 case ICMP6_PARAMPROB_HEADER
:
257 printf("icmp6: parameter problem errorneous - octet %u",
258 EXTRACT_32BITS(&dp
->icmp6_pptr
));
260 case ICMP6_PARAMPROB_NEXTHEADER
:
261 printf("icmp6: parameter problem next header - octet %u",
262 EXTRACT_32BITS(&dp
->icmp6_pptr
));
264 case ICMP6_PARAMPROB_OPTION
:
265 printf("icmp6: parameter problem option - octet %u",
266 EXTRACT_32BITS(&dp
->icmp6_pptr
));
269 printf("icmp6: parameter problem code-#%d",
274 case ICMP6_ECHO_REQUEST
:
275 case ICMP6_ECHO_REPLY
:
276 TCHECK(dp
->icmp6_seq
);
277 printf("icmp6: echo %s seq %u",
278 dp
->icmp6_type
== ICMP6_ECHO_REQUEST
?
280 EXTRACT_16BITS(&dp
->icmp6_seq
));
282 case ICMP6_MEMBERSHIP_QUERY
:
283 printf("icmp6: multicast listener query ");
284 mld6_print((const u_char
*)dp
);
286 case ICMP6_MEMBERSHIP_REPORT
:
287 printf("icmp6: multicast listener report ");
288 mld6_print((const u_char
*)dp
);
290 case ICMP6_MEMBERSHIP_REDUCTION
:
291 printf("icmp6: multicast listener done ");
292 mld6_print((const u_char
*)dp
);
294 case ND_ROUTER_SOLICIT
:
295 printf("icmp6: router solicitation ");
298 icmp6_opt_print((const u_char
*)dp
+ RTSOLLEN
,
302 case ND_ROUTER_ADVERT
:
303 printf("icmp6: router advertisement");
305 struct nd_router_advert
*p
;
307 p
= (struct nd_router_advert
*)dp
;
308 TCHECK(p
->nd_ra_retransmit
);
309 printf("(chlim=%d, ", (int)p
->nd_ra_curhoplimit
);
310 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_MANAGED
)
312 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_OTHER
)
314 if (p
->nd_ra_flags_reserved
& ND_RA_FLAG_HOME_AGENT
)
317 if ((p
->nd_ra_flags_reserved
& ~ND_RA_FLAG_RTPREF_MASK
)
322 get_rtpref(p
->nd_ra_flags_reserved
));
324 printf("router_ltime=%d, ", EXTRACT_16BITS(&p
->nd_ra_router_lifetime
));
325 printf("reachable_time=%u, ",
326 EXTRACT_32BITS(&p
->nd_ra_reachable
));
327 printf("retrans_time=%u)",
328 EXTRACT_32BITS(&p
->nd_ra_retransmit
));
330 icmp6_opt_print((const u_char
*)dp
+ RTADVLEN
,
334 case ND_NEIGHBOR_SOLICIT
:
336 struct nd_neighbor_solicit
*p
;
337 p
= (struct nd_neighbor_solicit
*)dp
;
338 TCHECK(p
->nd_ns_target
);
339 printf("icmp6: neighbor sol: who has %s",
340 ip6addr_string(&p
->nd_ns_target
));
343 icmp6_opt_print((const u_char
*)dp
+ NDSOLLEN
,
348 case ND_NEIGHBOR_ADVERT
:
350 struct nd_neighbor_advert
*p
;
352 p
= (struct nd_neighbor_advert
*)dp
;
353 TCHECK(p
->nd_na_target
);
354 printf("icmp6: neighbor adv: tgt is %s",
355 ip6addr_string(&p
->nd_na_target
));
357 #define ND_NA_FLAG_ALL \
358 (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE)
359 /* we don't need ntohl() here. see advanced-api-04. */
360 if (p
->nd_na_flags_reserved
& ND_NA_FLAG_ALL
) {
361 #undef ND_NA_FLAG_ALL
364 flags
= p
->nd_na_flags_reserved
;
366 if (flags
& ND_NA_FLAG_ROUTER
)
368 if (flags
& ND_NA_FLAG_SOLICITED
)
370 if (flags
& ND_NA_FLAG_OVERRIDE
)
375 icmp6_opt_print((const u_char
*)dp
+ NDADVLEN
,
382 #define RDR(i) ((struct nd_redirect *)(i))
383 TCHECK(RDR(dp
)->nd_rd_dst
);
384 printf("icmp6: redirect %s",
385 getname6((const u_char
*)&RDR(dp
)->nd_rd_dst
));
386 TCHECK(RDR(dp
)->nd_rd_target
);
388 getname6((const u_char
*)&RDR(dp
)->nd_rd_target
));
389 #define REDIRECTLEN 40
391 icmp6_opt_print((const u_char
*)dp
+ REDIRECTLEN
,
392 length
- REDIRECTLEN
);
397 case ICMP6_ROUTER_RENUMBERING
:
398 icmp6_rrenum_print(bp
, ep
);
402 icmp6_nodeinfo_print(length
, bp
, ep
);
404 case ICMP6_HADISCOV_REQUEST
:
405 printf("icmp6: ha discovery request");
407 TCHECK(dp
->icmp6_data16
[0]);
408 printf("(id=%d)", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
411 case ICMP6_HADISCOV_REPLY
:
412 printf("icmp6: ha discovery reply");
414 struct in6_addr
*in6
;
417 TCHECK(dp
->icmp6_data16
[0]);
418 printf("(id=%d", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
419 cp
= (u_char
*)dp
+ length
;
420 in6
= (struct in6_addr
*)(dp
+ 1);
421 for (; (u_char
*)in6
< cp
; in6
++) {
423 printf(", %s", ip6addr_string(in6
));
428 case ICMP6_MOBILEPREFIX_SOLICIT
:
429 printf("icmp6: mobile router solicitation");
431 TCHECK(dp
->icmp6_data16
[0]);
432 printf("(id=%d)", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
435 case ICMP6_MOBILEPREFIX_ADVERT
:
436 printf("icmp6: mobile router advertisement");
438 TCHECK(dp
->icmp6_data16
[0]);
439 printf("(id=%d", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
440 if (dp
->icmp6_data16
[1] & 0xc0)
442 if (dp
->icmp6_data16
[1] & 0x80)
444 if (dp
->icmp6_data16
[1] & 0x40)
448 icmp6_opt_print((const u_char
*)dp
+ MPADVLEN
,
453 printf("icmp6: type-#%d", dp
->icmp6_type
);
458 fputs("[|icmp6]", stdout
);
461 static struct udphdr
*
462 get_upperlayer(u_char
*bp
, u_int
*prot
)
465 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
468 struct ip6_frag
*fragh
;
473 /* 'ep' points to the end of available data. */
476 if (!TTEST(ip6
->ip6_nxt
))
480 hlen
= sizeof(struct ip6_hdr
);
482 while (bp
< snapend
) {
488 uh
= (struct udphdr
*)bp
;
489 if (TTEST(uh
->uh_dport
)) {
497 case IPPROTO_HOPOPTS
:
498 case IPPROTO_DSTOPTS
:
499 case IPPROTO_ROUTING
:
500 hbh
= (struct ip6_hbh
*)bp
;
501 if (!TTEST(hbh
->ip6h_len
))
504 hlen
= (hbh
->ip6h_len
+ 1) << 3;
507 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
508 fragh
= (struct ip6_frag
*)bp
;
509 if (!TTEST(fragh
->ip6f_offlg
))
511 /* fragments with non-zero offset are meaningless */
512 if ((EXTRACT_16BITS(&fragh
->ip6f_offlg
) & IP6F_OFF_MASK
) != 0)
514 nh
= fragh
->ip6f_nxt
;
515 hlen
= sizeof(struct ip6_frag
);
519 ah
= (struct ah
*)bp
;
520 if (!TTEST(ah
->ah_len
))
523 hlen
= (ah
->ah_len
+ 2) << 2;
526 default: /* unknown or undecodable header */
527 *prot
= nh
; /* meaningless, but set here anyway */
532 return(NULL
); /* should be notreached, though */
536 icmp6_opt_print(const u_char
*bp
, int resid
)
538 const struct nd_opt_hdr
*op
;
539 const struct nd_opt_hdr
*opl
; /* why there's no struct? */
540 const struct nd_opt_prefix_info
*opp
;
541 const struct icmp6_opts_redirect
*opr
;
542 const struct nd_opt_mtu
*opm
;
543 const struct nd_opt_advinterval
*opa
;
544 const struct nd_opt_homeagent_info
*oph
;
545 const struct nd_opt_route_info
*opri
;
546 const u_char
*cp
, *ep
;
547 struct in6_addr in6
, *in6p
;
550 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
553 /* 'ep' points to the end of available data. */
557 op
= (struct nd_opt_hdr
*)cp
;
559 ECHECK(op
->nd_opt_len
);
562 if (op
->nd_opt_len
== 0)
564 if (cp
+ (op
->nd_opt_len
<< 3) > ep
)
567 switch (op
->nd_opt_type
) {
568 case ND_OPT_SOURCE_LINKADDR
:
569 opl
= (struct nd_opt_hdr
*)op
;
570 printf("(src lladdr: ");
571 l
= (op
->nd_opt_len
<< 3) - 2;
572 print_lladdr(cp
+ 2, l
);
576 case ND_OPT_TARGET_LINKADDR
:
577 opl
= (struct nd_opt_hdr
*)op
;
578 printf("(tgt lladdr: ");
579 l
= (op
->nd_opt_len
<< 3) - 2;
580 print_lladdr(cp
+ 2, l
);
584 case ND_OPT_PREFIX_INFORMATION
:
585 opp
= (struct nd_opt_prefix_info
*)op
;
586 TCHECK(opp
->nd_opt_pi_prefix
);
587 printf("(prefix info: "); /*)*/
588 if (op
->nd_opt_len
!= 4) {
594 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_ONLINK
)
596 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_AUTO
)
598 if (opp
->nd_opt_pi_flags_reserved
& ND_OPT_PI_FLAG_ROUTER
)
600 if (opp
->nd_opt_pi_flags_reserved
)
602 printf("valid_ltime=%s,",
603 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_valid_time
)));
604 printf("preferred_ltime=%s,",
605 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_preferred_time
)));
606 printf("prefix=%s/%d",
607 ip6addr_string(&opp
->nd_opt_pi_prefix
),
608 opp
->nd_opt_pi_prefix_len
);
609 if (opp
->nd_opt_pi_len
!= 4)
614 case ND_OPT_REDIRECTED_HEADER
:
615 opr
= (struct icmp6_opts_redirect
*)op
;
616 printf("(redirect)");
620 opm
= (struct nd_opt_mtu
*)op
;
621 TCHECK(opm
->nd_opt_mtu_mtu
);
622 printf("(mtu:"); /*)*/
623 if (op
->nd_opt_len
!= 1) {
629 printf(" mtu=%u", EXTRACT_32BITS(&opm
->nd_opt_mtu_mtu
));
630 if (opm
->nd_opt_mtu_len
!= 1)
634 case ND_OPT_ADVINTERVAL
:
635 opa
= (struct nd_opt_advinterval
*)op
;
636 TCHECK(opa
->nd_opt_adv_interval
);
637 printf("(advint:"); /*)*/
639 EXTRACT_32BITS(&opa
->nd_opt_adv_interval
));
643 case ND_OPT_HOMEAGENT_INFO
:
644 oph
= (struct nd_opt_homeagent_info
*)op
;
645 TCHECK(oph
->nd_opt_hai_lifetime
);
646 printf("(ha info:"); /*)*/
647 printf(" pref=%d", EXTRACT_16BITS(&oph
->nd_opt_hai_preference
));
648 printf(", lifetime=%u", EXTRACT_16BITS(&oph
->nd_opt_hai_lifetime
));
651 case ND_OPT_ROUTE_INFO
:
652 opri
= (struct nd_opt_route_info
*)op
;
653 TCHECK(opri
->nd_opt_rti_lifetime
);
654 memset(&in6
, 0, sizeof(in6
));
655 in6p
= (struct in6_addr
*)(opri
+ 1);
656 switch (op
->nd_opt_len
) {
661 memcpy(&in6
, opri
+ 1, 8);
665 memcpy(&in6
, opri
+ 1, sizeof(in6
));
670 printf("(rtinfo:"); /*)*/
671 printf(" %s/%u", ip6addr_string(&in6
),
672 opri
->nd_opt_rti_prefixlen
);
673 printf(", pref=%s", get_rtpref(opri
->nd_opt_rti_flags
));
674 printf(", lifetime=%s",
675 get_lifetime(EXTRACT_32BITS(&opri
->nd_opt_rti_lifetime
)));
680 printf("(unknown opt_type=%d, opt_len=%d)",
681 op
->nd_opt_type
, op
->nd_opt_len
);
685 cp
+= op
->nd_opt_len
<< 3;
686 resid
-= op
->nd_opt_len
<< 3;
691 fputs("[ndp opt]", stdout
);
697 mld6_print(const u_char
*bp
)
699 struct mld6_hdr
*mp
= (struct mld6_hdr
*)bp
;
702 /* 'ep' points to the end of available data. */
705 if ((u_char
*)mp
+ sizeof(*mp
) > ep
)
708 printf("max resp delay: %d ", EXTRACT_16BITS(&mp
->mld6_maxdelay
));
709 printf("addr: %s", ip6addr_string(&mp
->mld6_addr
));
713 dnsname_print(const u_char
*cp
, const u_char
*ep
)
717 /* DNS name decoding - no decompression */
726 while (i
-- && cp
< ep
) {
730 if (cp
+ 1 < ep
&& *cp
)
736 } else if (cp
+ 1 == ep
&& *cp
== '\0') {
749 icmp6_nodeinfo_print(u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
751 struct icmp6_nodeinfo
*ni6
;
752 struct icmp6_hdr
*dp
;
759 dp
= (struct icmp6_hdr
*)bp
;
760 ni6
= (struct icmp6_nodeinfo
*)bp
;
763 switch (ni6
->ni_type
) {
765 if (siz
== sizeof(*dp
) + 4) {
766 /* KAME who-are-you */
767 printf("icmp6: who-are-you request");
770 printf("icmp6: node information query");
772 TCHECK2(*dp
, sizeof(*ni6
));
773 ni6
= (struct icmp6_nodeinfo
*)dp
;
775 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
779 case NI_QTYPE_SUPTYPES
:
780 printf("supported qtypes");
781 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
783 printf(" [%s]", (i
& 0x01) ? "C" : "");
789 case NI_QTYPE_NODEADDR
:
790 printf("node addresses");
794 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
795 printf(" [%s%s%s%s%s%s]",
796 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
797 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
798 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
799 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
800 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
801 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "");
808 if (ni6
->ni_qtype
== NI_QTYPE_NOOP
||
809 ni6
->ni_qtype
== NI_QTYPE_SUPTYPES
) {
810 if (siz
!= sizeof(*ni6
))
812 printf(", invalid len");
819 /* XXX backward compat, icmp-name-lookup-03 */
820 if (siz
== sizeof(*ni6
)) {
821 printf(", 03 draft");
827 switch (ni6
->ni_code
) {
828 case ICMP6_NI_SUBJ_IPV6
:
830 sizeof(*ni6
) + sizeof(struct in6_addr
)))
832 if (siz
!= sizeof(*ni6
) + sizeof(struct in6_addr
)) {
834 printf(", invalid subject len");
837 printf(", subject=%s",
838 getname6((const u_char
*)(ni6
+ 1)));
840 case ICMP6_NI_SUBJ_FQDN
:
841 printf(", subject=DNS name");
842 cp
= (const u_char
*)(ni6
+ 1);
843 if (cp
[0] == ep
- cp
- 1) {
844 /* icmp-name-lookup-03, pascal string */
846 printf(", 03 draft");
855 dnsname_print(cp
, ep
);
857 case ICMP6_NI_SUBJ_IPV4
:
858 if (!TTEST2(*dp
, sizeof(*ni6
) + sizeof(struct in_addr
)))
860 if (siz
!= sizeof(*ni6
) + sizeof(struct in_addr
)) {
862 printf(", invalid subject len");
865 printf(", subject=%s",
866 getname((const u_char
*)(ni6
+ 1)));
869 printf(", unknown subject");
878 if (icmp6len
> siz
) {
879 printf("[|icmp6: node information reply]");
885 ni6
= (struct icmp6_nodeinfo
*)dp
;
886 printf("icmp6: node information reply");
888 switch (ni6
->ni_code
) {
889 case ICMP6_NI_SUCCESS
:
895 case ICMP6_NI_REFUSED
:
898 if (siz
!= sizeof(*ni6
))
900 printf(", invalid length");
902 case ICMP6_NI_UNKNOWN
:
905 if (siz
!= sizeof(*ni6
))
907 printf(", invalid length");
911 if (ni6
->ni_code
!= ICMP6_NI_SUCCESS
) {
917 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
922 if (siz
!= sizeof(*ni6
))
924 printf(", invalid length");
926 case NI_QTYPE_SUPTYPES
:
929 printf("supported qtypes");
930 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
932 printf(" [%s]", (i
& 0x01) ? "C" : "");
938 cp
= (const u_char
*)(ni6
+ 1) + 4;
939 if (cp
[0] == ep
- cp
- 1) {
940 /* icmp-name-lookup-03, pascal string */
942 printf(", 03 draft");
951 dnsname_print(cp
, ep
);
952 if ((EXTRACT_16BITS(&ni6
->ni_flags
) & 0x01) != 0)
953 printf(" [TTL=%u]", *(u_int32_t
*)(ni6
+ 1));
955 case NI_QTYPE_NODEADDR
:
958 printf("node addresses");
961 if (i
+ sizeof(struct in6_addr
) + sizeof(int32_t) > siz
)
963 printf(" %s", getname6(bp
+ i
));
964 i
+= sizeof(struct in6_addr
);
965 printf("(%d)", (int32_t)EXTRACT_32BITS(bp
+ i
));
966 i
+= sizeof(int32_t);
971 printf(" [%s%s%s%s%s%s%s]",
972 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
973 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
974 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
975 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
976 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
977 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
978 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : "");
994 fputs("[|icmp6]", stdout
);
998 icmp6_rrenum_print(const u_char
*bp
, const u_char
*ep
)
1000 struct icmp6_router_renum
*rr6
;
1001 struct icmp6_hdr
*dp
;
1004 struct rr_pco_match
*match
;
1005 struct rr_pco_use
*use
;
1006 char hbuf
[NI_MAXHOST
];
1011 dp
= (struct icmp6_hdr
*)bp
;
1012 rr6
= (struct icmp6_router_renum
*)bp
;
1014 cp
= (const char *)(rr6
+ 1);
1016 TCHECK(rr6
->rr_reserved
);
1017 switch (rr6
->rr_code
) {
1018 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
1019 printf("router renum: command");
1021 case ICMP6_ROUTER_RENUMBERING_RESULT
:
1022 printf("router renum: result");
1024 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
1025 printf("router renum: sequence number reset");
1028 printf("router renum: code-#%d", rr6
->rr_code
);
1032 printf(", seq=%u", EXTRACT_32BITS(&rr6
->rr_seqnum
));
1035 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1037 if (rr6
->rr_flags
) {
1038 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
1039 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
1040 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
1041 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
1042 F(ICMP6_RR_FLAGS_PREVDONE
, "P"));
1044 printf("seg=%u,", rr6
->rr_segnum
);
1045 printf("maxdelay=%u", rr6
->rr_maxdelay
);
1046 if (rr6
->rr_reserved
)
1047 printf("rsvd=0x%x", EXTRACT_16BITS(&rr6
->rr_reserved
));
1053 if (rr6
->rr_code
== ICMP6_ROUTER_RENUMBERING_COMMAND
) {
1054 match
= (struct rr_pco_match
*)cp
;
1055 cp
= (const char *)(match
+ 1);
1057 TCHECK(match
->rpm_prefix
);
1063 printf("match("); /*)*/
1064 switch (match
->rpm_code
) {
1065 case RPM_PCO_ADD
: printf("add"); break;
1066 case RPM_PCO_CHANGE
: printf("change"); break;
1067 case RPM_PCO_SETGLOBAL
: printf("setglobal"); break;
1068 default: printf("#%u", match
->rpm_code
); break;
1072 printf(",ord=%u", match
->rpm_ordinal
);
1073 printf(",min=%u", match
->rpm_minlen
);
1074 printf(",max=%u", match
->rpm_maxlen
);
1076 if (inet_ntop(AF_INET6
, &match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
1077 printf(",%s/%u", hbuf
, match
->rpm_matchlen
);
1079 printf(",?/%u", match
->rpm_matchlen
);
1083 n
= match
->rpm_len
- 3;
1088 use
= (struct rr_pco_use
*)cp
;
1089 cp
= (const char *)(use
+ 1);
1091 TCHECK(use
->rpu_prefix
);
1097 printf("use("); /*)*/
1098 if (use
->rpu_flags
) {
1099 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1101 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
1102 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P"));
1106 printf("mask=0x%x,", use
->rpu_ramask
);
1107 printf("raflags=0x%x,", use
->rpu_raflags
);
1108 if (~use
->rpu_vltime
== 0)
1109 printf("vltime=infty,");
1111 printf("vltime=%u,",
1112 EXTRACT_32BITS(&use
->rpu_vltime
));
1113 if (~use
->rpu_pltime
== 0)
1114 printf("pltime=infty,");
1116 printf("pltime=%u,",
1117 EXTRACT_32BITS(&use
->rpu_pltime
));
1119 if (inet_ntop(AF_INET6
, &use
->rpu_prefix
, hbuf
,
1121 printf("%s/%u/%u", hbuf
, use
->rpu_uselen
,
1124 printf("?/%u/%u", use
->rpu_uselen
,
1134 fputs("[|icmp6]", stdout
);