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.86 2008-02-05 19:36:13 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 /* inline the various RPL definitions */
66 #define ND_RPL_MESSAGE 0x9B
68 static struct tok icmp6_type_values
[] = {
69 { ICMP6_DST_UNREACH
, "destination unreachable"},
70 { ICMP6_PACKET_TOO_BIG
, "packet too big"},
71 { ICMP6_TIME_EXCEEDED
, "time exceeded in-transit"},
72 { ICMP6_PARAM_PROB
, "parameter problem"},
73 { ICMP6_ECHO_REQUEST
, "echo request"},
74 { ICMP6_ECHO_REPLY
, "echo reply"},
75 { MLD6_LISTENER_QUERY
, "multicast listener query"},
76 { MLD6_LISTENER_REPORT
, "multicast listener report"},
77 { MLD6_LISTENER_DONE
, "multicast listener done"},
78 { ND_ROUTER_SOLICIT
, "router solicitation"},
79 { ND_ROUTER_ADVERT
, "router advertisement"},
80 { ND_NEIGHBOR_SOLICIT
, "neighbor solicitation"},
81 { ND_NEIGHBOR_ADVERT
, "neighbor advertisement"},
82 { ND_REDIRECT
, "redirect"},
83 { ICMP6_ROUTER_RENUMBERING
, "router renumbering"},
84 { IND_SOLICIT
, "inverse neighbor solicitation"},
85 { IND_ADVERT
, "inverse neighbor advertisement"},
86 { MLDV2_LISTENER_REPORT
, "multicast listener report v2"},
87 { ICMP6_HADISCOV_REQUEST
, "ha discovery request"},
88 { ICMP6_HADISCOV_REPLY
, "ha discovery reply"},
89 { ICMP6_MOBILEPREFIX_SOLICIT
, "mobile router solicitation"},
90 { ICMP6_MOBILEPREFIX_ADVERT
, "mobile router advertisement"},
91 { ICMP6_WRUREQUEST
, "who-are-you request"},
92 { ICMP6_WRUREPLY
, "who-are-you reply"},
93 { ICMP6_NI_QUERY
, "node information query"},
94 { ICMP6_NI_REPLY
, "node information reply"},
95 { MLD6_MTRACE
, "mtrace message"},
96 { MLD6_MTRACE_RESP
, "mtrace response"},
97 { ND_RPL_MESSAGE
, "RPL"},
101 static struct tok icmp6_dst_unreach_code_values
[] = {
102 { ICMP6_DST_UNREACH_NOROUTE
, "unreachable route" },
103 { ICMP6_DST_UNREACH_ADMIN
, " unreachable prohibited"},
104 { ICMP6_DST_UNREACH_BEYONDSCOPE
, "beyond scope"},
105 { ICMP6_DST_UNREACH_ADDR
, "unreachable address"},
106 { ICMP6_DST_UNREACH_NOPORT
, "unreachable port"},
110 static struct tok icmp6_opt_pi_flag_values
[] = {
111 { ND_OPT_PI_FLAG_ONLINK
, "onlink" },
112 { ND_OPT_PI_FLAG_AUTO
, "auto" },
113 { ND_OPT_PI_FLAG_ROUTER
, "router" },
117 static struct tok icmp6_opt_ra_flag_values
[] = {
118 { ND_RA_FLAG_MANAGED
, "managed" },
119 { ND_RA_FLAG_OTHER
, "other stateful"},
120 { ND_RA_FLAG_HOME_AGENT
, "home agent"},
124 static struct tok icmp6_nd_na_flag_values
[] = {
125 { ND_NA_FLAG_ROUTER
, "router" },
126 { ND_NA_FLAG_SOLICITED
, "solicited" },
127 { ND_NA_FLAG_OVERRIDE
, "override" },
132 static struct tok icmp6_opt_values
[] = {
133 { ND_OPT_SOURCE_LINKADDR
, "source link-address"},
134 { ND_OPT_TARGET_LINKADDR
, "destination link-address"},
135 { ND_OPT_PREFIX_INFORMATION
, "prefix info"},
136 { ND_OPT_REDIRECTED_HEADER
, "redirected header"},
137 { ND_OPT_MTU
, "mtu"},
138 { ND_OPT_RDNSS
, "rdnss"},
139 { ND_OPT_ADVINTERVAL
, "advertisement interval"},
140 { ND_OPT_HOMEAGENT_INFO
, "homeagent information"},
141 { ND_OPT_ROUTE_INFO
, "route info"},
145 /* mldv2 report types */
146 static struct tok mldv2report2str
[] = {
159 static const char *rtpref_str
[] = {
166 return rtpref_str
[((v
& ND_RA_FLAG_RTPREF_MASK
) >> 3) & 0xff];
170 get_lifetime(u_int32_t v
)
174 if (v
== (u_int32_t
)~0UL)
177 snprintf(buf
, sizeof(buf
), "%u", v
);
183 print_lladdr(const u_int8_t
*p
, size_t l
)
185 const u_int8_t
*ep
, *q
;
189 while (l
> 0 && q
< ep
) {
192 printf("%02x", *q
++);
197 static int icmp6_cksum(const struct ip6_hdr
*ip6
, const struct icmp6_hdr
*icp
,
200 return (nextproto6_cksum(ip6
, (const u_int8_t
*)(void *)icp
, len
,
212 ND_RPL_SDAO_ACK
=0x83,
216 enum ND_RPL_DIO_FLAGS
{
217 ND_RPL_DIO_GROUNDED
= 0x80,
218 ND_RPL_DIO_DATRIG
= 0x40,
219 ND_RPL_DIO_DASUPPORT
= 0x20,
220 ND_RPL_DIO_RES4
= 0x10,
221 ND_RPL_DIO_RES3
= 0x08,
222 ND_RPL_DIO_PRF_MASK
= 0x07, /* 3-bit preference */
228 u_int8_t rpl_instanceid
;
229 u_int8_t rpl_dagrank
;
230 u_int8_t rpl_dagid
[16];
234 rpl_print(netdissect_options
*ndo
,
235 const struct icmp6_hdr
*hdr
,
236 const u_char
*bp
, u_int length _U_
)
238 struct nd_rpl_dio
*dio
= (struct nd_rpl_dio
*)bp
;
239 int secured
= hdr
->icmp6_code
& 0x80;
240 int basecode
= hdr
->icmp6_code
& 0x7f;
242 ND_TCHECK(dio
->rpl_dagid
);
245 ND_PRINT((ndo
, ", (SEC)"));
247 ND_PRINT((ndo
, ", (CLR)"));
252 ND_PRINT((ndo
, "DODAG Information Solicitation"));
257 ND_PRINT((ndo
, "DODAG Information Object"));
263 if(isprint(dio
->rpl_dagid
[i
])) {
264 *d
++ = dio
->rpl_dagid
[i
];
266 int cnt
=snprintf(d
,4,"0x%02x",
272 ND_PRINT((ndo
, " [seq:%u,instance:%u,rank:%u,dagid:%s]",
280 ND_PRINT((ndo
, "Destination Advertisement Object"));
285 ND_PRINT((ndo
, "Destination Advertisement Object Ack"));
290 ND_PRINT((ndo
, "RPL message, unknown code %u",hdr
->icmp6_code
));
295 ND_PRINT((ndo
," [|truncated]"));
302 icmp6_print(netdissect_options
*ndo
,
303 const u_char
*bp
, u_int length
, const u_char
*bp2
, int fragmented
)
305 const struct icmp6_hdr
*dp
;
306 const struct ip6_hdr
*ip
;
307 const struct ip6_hdr
*oip
;
308 const struct udphdr
*ouh
;
313 dp
= (struct icmp6_hdr
*)bp
;
314 ip
= (struct ip6_hdr
*)bp2
;
315 oip
= (struct ip6_hdr
*)(dp
+ 1);
316 /* 'ep' points to the end of available data. */
319 TCHECK(dp
->icmp6_cksum
);
321 if (vflag
&& !fragmented
) {
322 u_int16_t sum
, udp_sum
;
324 if (TTEST2(bp
[0], length
)) {
325 udp_sum
= EXTRACT_16BITS(&dp
->icmp6_cksum
);
326 sum
= icmp6_cksum(ip
, dp
, length
);
328 (void)printf("[bad icmp6 cksum 0x%04x -> 0x%04x!] ",
330 in_cksum_shouldbe(udp_sum
, sum
));
332 (void)printf("[icmp6 sum ok] ");
336 printf("ICMP6, %s", tok2str(icmp6_type_values
,"unknown icmp6 type (%u)",dp
->icmp6_type
));
338 /* display cosmetics: print the packet length for printer that use the vflag now */
339 if (vflag
&& (dp
->icmp6_type
== ND_ROUTER_SOLICIT
||
340 dp
->icmp6_type
== ND_ROUTER_ADVERT
||
341 dp
->icmp6_type
== ND_NEIGHBOR_ADVERT
||
342 dp
->icmp6_type
== ND_NEIGHBOR_SOLICIT
||
343 dp
->icmp6_type
== ND_REDIRECT
||
344 dp
->icmp6_type
== ICMP6_HADISCOV_REPLY
||
345 dp
->icmp6_type
== ICMP6_MOBILEPREFIX_ADVERT
))
346 printf(", length %u", length
);
348 switch (dp
->icmp6_type
) {
349 case ICMP6_DST_UNREACH
:
350 TCHECK(oip
->ip6_dst
);
351 printf(", %s", tok2str(icmp6_dst_unreach_code_values
,"unknown unreach code (%u)",dp
->icmp6_code
));
352 switch (dp
->icmp6_code
) {
354 case ICMP6_DST_UNREACH_NOROUTE
: /* fall through */
355 case ICMP6_DST_UNREACH_ADMIN
:
356 case ICMP6_DST_UNREACH_ADDR
:
357 printf(" %s",ip6addr_string(&oip
->ip6_dst
));
359 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
360 printf(" %s, source address %s",
361 ip6addr_string(&oip
->ip6_dst
),
362 ip6addr_string(&oip
->ip6_src
));
364 case ICMP6_DST_UNREACH_NOPORT
:
365 if ((ouh
= get_upperlayer((u_char
*)oip
, &prot
))
369 dport
= EXTRACT_16BITS(&ouh
->uh_dport
);
372 printf(", %s tcp port %s",
373 ip6addr_string(&oip
->ip6_dst
),
374 tcpport_string(dport
));
377 printf(", %s udp port %s",
378 ip6addr_string(&oip
->ip6_dst
),
379 udpport_string(dport
));
382 printf(", %s protocol %d port %d unreachable",
383 ip6addr_string(&oip
->ip6_dst
),
384 oip
->ip6_nxt
, dport
);
390 print_unknown_data(bp
,"\n\t",length
);
396 case ICMP6_PACKET_TOO_BIG
:
397 TCHECK(dp
->icmp6_mtu
);
398 printf(", mtu %u", EXTRACT_32BITS(&dp
->icmp6_mtu
));
400 case ICMP6_TIME_EXCEEDED
:
401 TCHECK(oip
->ip6_dst
);
402 switch (dp
->icmp6_code
) {
403 case ICMP6_TIME_EXCEED_TRANSIT
:
405 ip6addr_string(&oip
->ip6_dst
));
407 case ICMP6_TIME_EXCEED_REASSEMBLY
:
408 printf(" (reassembly)");
411 printf(", unknown code (%u)", dp
->icmp6_code
);
415 case ICMP6_PARAM_PROB
:
416 TCHECK(oip
->ip6_dst
);
417 switch (dp
->icmp6_code
) {
418 case ICMP6_PARAMPROB_HEADER
:
419 printf(", errorneous - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
));
421 case ICMP6_PARAMPROB_NEXTHEADER
:
422 printf(", next header - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
));
424 case ICMP6_PARAMPROB_OPTION
:
425 printf(", option - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
));
433 case ICMP6_ECHO_REQUEST
:
434 case ICMP6_ECHO_REPLY
:
435 TCHECK(dp
->icmp6_seq
);
436 printf(", seq %u", EXTRACT_16BITS(&dp
->icmp6_seq
));
438 case ICMP6_MEMBERSHIP_QUERY
:
439 if (length
== MLD_MINLEN
) {
440 mld6_print((const u_char
*)dp
);
441 } else if (length
>= MLDV2_MINLEN
) {
443 mldv2_query_print((const u_char
*)dp
, length
);
445 printf(" unknown-version (len %u) ", length
);
448 case ICMP6_MEMBERSHIP_REPORT
:
449 mld6_print((const u_char
*)dp
);
451 case ICMP6_MEMBERSHIP_REDUCTION
:
452 mld6_print((const u_char
*)dp
);
454 case ND_ROUTER_SOLICIT
:
457 icmp6_opt_print((const u_char
*)dp
+ RTSOLLEN
,
461 case ND_ROUTER_ADVERT
:
464 struct nd_router_advert
*p
;
466 p
= (struct nd_router_advert
*)dp
;
467 TCHECK(p
->nd_ra_retransmit
);
468 printf("\n\thop limit %u, Flags [%s]" \
469 ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
470 (u_int
)p
->nd_ra_curhoplimit
,
471 bittok2str(icmp6_opt_ra_flag_values
,"none",(p
->nd_ra_flags_reserved
)),
472 get_rtpref(p
->nd_ra_flags_reserved
),
473 EXTRACT_16BITS(&p
->nd_ra_router_lifetime
),
474 EXTRACT_32BITS(&p
->nd_ra_reachable
),
475 EXTRACT_32BITS(&p
->nd_ra_retransmit
));
477 icmp6_opt_print((const u_char
*)dp
+ RTADVLEN
,
481 case ND_NEIGHBOR_SOLICIT
:
483 struct nd_neighbor_solicit
*p
;
484 p
= (struct nd_neighbor_solicit
*)dp
;
485 TCHECK(p
->nd_ns_target
);
486 printf(", who has %s", ip6addr_string(&p
->nd_ns_target
));
489 icmp6_opt_print((const u_char
*)dp
+ NDSOLLEN
,
494 case ND_NEIGHBOR_ADVERT
:
496 struct nd_neighbor_advert
*p
;
498 p
= (struct nd_neighbor_advert
*)dp
;
499 TCHECK(p
->nd_na_target
);
500 printf(", tgt is %s",
501 ip6addr_string(&p
->nd_na_target
));
503 printf(", Flags [%s]",
504 bittok2str(icmp6_nd_na_flag_values
,
506 EXTRACT_32BITS(&p
->nd_na_flags_reserved
)));
508 icmp6_opt_print((const u_char
*)dp
+ NDADVLEN
,
515 #define RDR(i) ((struct nd_redirect *)(i))
516 TCHECK(RDR(dp
)->nd_rd_dst
);
517 printf(", %s", getname6((const u_char
*)&RDR(dp
)->nd_rd_dst
));
518 TCHECK(RDR(dp
)->nd_rd_target
);
520 getname6((const u_char
*)&RDR(dp
)->nd_rd_target
));
521 #define REDIRECTLEN 40
523 icmp6_opt_print((const u_char
*)dp
+ REDIRECTLEN
,
524 length
- REDIRECTLEN
);
529 case ICMP6_ROUTER_RENUMBERING
:
530 icmp6_rrenum_print(bp
, ep
);
534 icmp6_nodeinfo_print(length
, bp
, ep
);
539 case ICMP6_V2_MEMBERSHIP_REPORT
:
540 mldv2_report_print((const u_char
*) dp
, length
);
542 case ICMP6_MOBILEPREFIX_SOLICIT
: /* fall through */
543 case ICMP6_HADISCOV_REQUEST
:
544 TCHECK(dp
->icmp6_data16
[0]);
545 printf(", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
547 case ICMP6_HADISCOV_REPLY
:
549 struct in6_addr
*in6
;
552 TCHECK(dp
->icmp6_data16
[0]);
553 printf(", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
554 cp
= (u_char
*)dp
+ length
;
555 in6
= (struct in6_addr
*)(dp
+ 1);
556 for (; (u_char
*)in6
< cp
; in6
++) {
558 printf(", %s", ip6addr_string(in6
));
562 case ICMP6_MOBILEPREFIX_ADVERT
:
564 TCHECK(dp
->icmp6_data16
[0]);
565 printf(", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
566 if (dp
->icmp6_data16
[1] & 0xc0)
568 if (dp
->icmp6_data16
[1] & 0x80)
570 if (dp
->icmp6_data16
[1] & 0x40)
573 icmp6_opt_print((const u_char
*)dp
+ MPADVLEN
,
578 rpl_print(ndo
, dp
, &dp
->icmp6_data8
[0], length
);
581 printf(", length %u", length
);
583 print_unknown_data(bp
,"\n\t", length
);
587 printf(", length %u", length
);
590 fputs("[|icmp6]", stdout
);
593 static struct udphdr
*
594 get_upperlayer(u_char
*bp
, u_int
*prot
)
597 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
600 struct ip6_frag
*fragh
;
605 /* 'ep' points to the end of available data. */
608 if (!TTEST(ip6
->ip6_nxt
))
612 hlen
= sizeof(struct ip6_hdr
);
620 uh
= (struct udphdr
*)bp
;
621 if (TTEST(uh
->uh_dport
)) {
629 case IPPROTO_HOPOPTS
:
630 case IPPROTO_DSTOPTS
:
631 case IPPROTO_ROUTING
:
632 hbh
= (struct ip6_hbh
*)bp
;
633 if (!TTEST(hbh
->ip6h_len
))
636 hlen
= (hbh
->ip6h_len
+ 1) << 3;
639 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
640 fragh
= (struct ip6_frag
*)bp
;
641 if (!TTEST(fragh
->ip6f_offlg
))
643 /* fragments with non-zero offset are meaningless */
644 if ((EXTRACT_16BITS(&fragh
->ip6f_offlg
) & IP6F_OFF_MASK
) != 0)
646 nh
= fragh
->ip6f_nxt
;
647 hlen
= sizeof(struct ip6_frag
);
651 ah
= (struct ah
*)bp
;
652 if (!TTEST(ah
->ah_len
))
655 hlen
= (ah
->ah_len
+ 2) << 2;
658 default: /* unknown or undecodable header */
659 *prot
= nh
; /* meaningless, but set here anyway */
664 return(NULL
); /* should be notreached, though */
668 icmp6_opt_print(const u_char
*bp
, int resid
)
670 const struct nd_opt_hdr
*op
;
671 const struct nd_opt_hdr
*opl
; /* why there's no struct? */
672 const struct nd_opt_prefix_info
*opp
;
673 const struct icmp6_opts_redirect
*opr
;
674 const struct nd_opt_mtu
*opm
;
675 const struct nd_opt_rdnss
*oprd
;
676 const struct nd_opt_advinterval
*opa
;
677 const struct nd_opt_homeagent_info
*oph
;
678 const struct nd_opt_route_info
*opri
;
679 const u_char
*cp
, *ep
;
680 struct in6_addr in6
, *in6p
;
684 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
687 /* 'ep' points to the end of available data. */
691 op
= (struct nd_opt_hdr
*)cp
;
693 ECHECK(op
->nd_opt_len
);
696 if (op
->nd_opt_len
== 0)
698 if (cp
+ (op
->nd_opt_len
<< 3) > ep
)
701 printf("\n\t %s option (%u), length %u (%u): ",
702 tok2str(icmp6_opt_values
, "unknown", op
->nd_opt_type
),
707 switch (op
->nd_opt_type
) {
708 case ND_OPT_SOURCE_LINKADDR
:
709 opl
= (struct nd_opt_hdr
*)op
;
710 l
= (op
->nd_opt_len
<< 3) - 2;
711 print_lladdr(cp
+ 2, l
);
713 case ND_OPT_TARGET_LINKADDR
:
714 opl
= (struct nd_opt_hdr
*)op
;
715 l
= (op
->nd_opt_len
<< 3) - 2;
716 print_lladdr(cp
+ 2, l
);
718 case ND_OPT_PREFIX_INFORMATION
:
719 opp
= (struct nd_opt_prefix_info
*)op
;
720 TCHECK(opp
->nd_opt_pi_prefix
);
721 printf("%s/%u%s, Flags [%s], valid time %ss",
722 ip6addr_string(&opp
->nd_opt_pi_prefix
),
723 opp
->nd_opt_pi_prefix_len
,
724 (op
->nd_opt_len
!= 4) ? "badlen" : "",
725 bittok2str(icmp6_opt_pi_flag_values
, "none", opp
->nd_opt_pi_flags_reserved
),
726 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_valid_time
)));
727 printf(", pref. time %ss", get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_preferred_time
)));
729 case ND_OPT_REDIRECTED_HEADER
:
730 opr
= (struct icmp6_opts_redirect
*)op
;
731 print_unknown_data(bp
,"\n\t ",op
->nd_opt_len
<<3);
735 opm
= (struct nd_opt_mtu
*)op
;
736 TCHECK(opm
->nd_opt_mtu_mtu
);
738 EXTRACT_32BITS(&opm
->nd_opt_mtu_mtu
),
739 (op
->nd_opt_len
!= 1) ? "bad option length" : "" );
742 oprd
= (struct nd_opt_rdnss
*)op
;
743 l
= (op
->nd_opt_len
- 1) / 2;
744 printf(" lifetime %us,",
745 EXTRACT_32BITS(&oprd
->nd_opt_rdnss_lifetime
));
746 for (i
= 0; i
< l
; i
++) {
747 TCHECK(oprd
->nd_opt_rdnss_addr
[i
]);
749 ip6addr_string(&oprd
->nd_opt_rdnss_addr
[i
]));
752 case ND_OPT_ADVINTERVAL
:
753 opa
= (struct nd_opt_advinterval
*)op
;
754 TCHECK(opa
->nd_opt_adv_interval
);
755 printf(" %ums", EXTRACT_32BITS(&opa
->nd_opt_adv_interval
));
757 case ND_OPT_HOMEAGENT_INFO
:
758 oph
= (struct nd_opt_homeagent_info
*)op
;
759 TCHECK(oph
->nd_opt_hai_lifetime
);
760 printf(" preference %u, lifetime %u",
761 EXTRACT_16BITS(&oph
->nd_opt_hai_preference
),
762 EXTRACT_16BITS(&oph
->nd_opt_hai_lifetime
));
764 case ND_OPT_ROUTE_INFO
:
765 opri
= (struct nd_opt_route_info
*)op
;
766 TCHECK(opri
->nd_opt_rti_lifetime
);
767 memset(&in6
, 0, sizeof(in6
));
768 in6p
= (struct in6_addr
*)(opri
+ 1);
769 switch (op
->nd_opt_len
) {
774 memcpy(&in6
, opri
+ 1, 8);
778 memcpy(&in6
, opri
+ 1, sizeof(in6
));
783 printf(" %s/%u", ip6addr_string(&in6
),
784 opri
->nd_opt_rti_prefixlen
);
785 printf(", pref=%s", get_rtpref(opri
->nd_opt_rti_flags
));
786 printf(", lifetime=%s",
787 get_lifetime(EXTRACT_32BITS(&opri
->nd_opt_rti_lifetime
)));
791 print_unknown_data(cp
+2,"\n\t ", (op
->nd_opt_len
<< 3) - 2); /* skip option header */
796 /* do we want to see an additional hexdump ? */
798 print_unknown_data(cp
+2,"\n\t ", (op
->nd_opt_len
<< 3) - 2); /* skip option header */
800 cp
+= op
->nd_opt_len
<< 3;
801 resid
-= op
->nd_opt_len
<< 3;
806 fputs("[ndp opt]", stdout
);
812 mld6_print(const u_char
*bp
)
814 struct mld6_hdr
*mp
= (struct mld6_hdr
*)bp
;
817 /* 'ep' points to the end of available data. */
820 if ((u_char
*)mp
+ sizeof(*mp
) > ep
)
823 printf("max resp delay: %d ", EXTRACT_16BITS(&mp
->mld6_maxdelay
));
824 printf("addr: %s", ip6addr_string(&mp
->mld6_addr
));
828 mldv2_report_print(const u_char
*bp
, u_int len
)
830 struct icmp6_hdr
*icp
= (struct icmp6_hdr
*) bp
;
831 u_int group
, nsrcs
, ngroups
;
834 /* Minimum len is 8 */
836 printf(" [invalid len %d]", len
);
840 TCHECK(icp
->icmp6_data16
[1]);
841 ngroups
= EXTRACT_16BITS(&icp
->icmp6_data16
[1]);
842 printf(", %d group record(s)", ngroups
);
844 /* Print the group records */
846 for (i
= 0; i
< ngroups
; i
++) {
847 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
848 if (len
< group
+ 20) {
849 printf(" [invalid number of groups]");
852 TCHECK2(bp
[group
+ 4], sizeof(struct in6_addr
));
853 printf(" [gaddr %s", ip6addr_string(&bp
[group
+ 4]));
854 printf(" %s", tok2str(mldv2report2str
, " [v2-report-#%d]",
856 nsrcs
= (bp
[group
+ 2] << 8) + bp
[group
+ 3];
857 /* Check the number of sources and print them */
858 if (len
< group
+ 20 + (nsrcs
* sizeof(struct in6_addr
))) {
859 printf(" [invalid number of sources %d]", nsrcs
);
863 printf(", %d source(s)", nsrcs
);
865 /* Print the sources */
867 for (j
= 0; j
< nsrcs
; j
++) {
868 TCHECK2(bp
[group
+ 20 + j
* sizeof(struct in6_addr
)],
869 sizeof(struct in6_addr
));
870 printf(" %s", ip6addr_string(&bp
[group
+ 20 + j
* sizeof(struct in6_addr
)]));
874 /* Next group record */
875 group
+= 20 + nsrcs
* sizeof(struct in6_addr
);
881 (void)printf("[|icmp6]");
886 mldv2_query_print(const u_char
*bp
, u_int len
)
888 struct icmp6_hdr
*icp
= (struct icmp6_hdr
*) bp
;
894 /* Minimum len is 28 */
896 printf(" [invalid len %d]", len
);
899 TCHECK(icp
->icmp6_data16
[0]);
900 mrc
= EXTRACT_16BITS(&icp
->icmp6_data16
[0]);
904 mrt
= ((mrc
& 0x0fff) | 0x1000) << (((mrc
& 0x7000) >> 12) + 3);
907 (void)printf(" [max resp delay=%d]", mrt
);
909 TCHECK2(bp
[8], sizeof(struct in6_addr
));
910 printf(" [gaddr %s", ip6addr_string(&bp
[8]));
918 printf(" robustness=%d", bp
[24] & 0x07);
923 qqi
= ((bp
[25] & 0x0f) | 0x10) << (((bp
[25] & 0x70) >> 4) + 3);
925 printf(" qqi=%d", qqi
);
929 nsrcs
= EXTRACT_16BITS(&bp
[26]);
931 if (len
< 28 + nsrcs
* sizeof(struct in6_addr
))
932 printf(" [invalid number of sources]");
933 else if (vflag
> 1) {
935 for (i
= 0; i
< nsrcs
; i
++) {
936 TCHECK2(bp
[28 + i
* sizeof(struct in6_addr
)],
937 sizeof(struct in6_addr
));
938 printf(" %s", ip6addr_string(&bp
[28 + i
* sizeof(struct in6_addr
)]));
942 printf(", %d source(s)", nsrcs
);
947 (void)printf("[|icmp6]");
952 dnsname_print(const u_char
*cp
, const u_char
*ep
)
956 /* DNS name decoding - no decompression */
965 while (i
-- && cp
< ep
) {
969 if (cp
+ 1 < ep
&& *cp
)
975 } else if (cp
+ 1 == ep
&& *cp
== '\0') {
988 icmp6_nodeinfo_print(u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
990 struct icmp6_nodeinfo
*ni6
;
991 struct icmp6_hdr
*dp
;
998 dp
= (struct icmp6_hdr
*)bp
;
999 ni6
= (struct icmp6_nodeinfo
*)bp
;
1002 switch (ni6
->ni_type
) {
1003 case ICMP6_NI_QUERY
:
1004 if (siz
== sizeof(*dp
) + 4) {
1005 /* KAME who-are-you */
1006 printf(" who-are-you request");
1009 printf(" node information query");
1011 TCHECK2(*dp
, sizeof(*ni6
));
1012 ni6
= (struct icmp6_nodeinfo
*)dp
;
1014 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
1018 case NI_QTYPE_SUPTYPES
:
1019 printf("supported qtypes");
1020 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
1022 printf(" [%s]", (i
& 0x01) ? "C" : "");
1028 case NI_QTYPE_NODEADDR
:
1029 printf("node addresses");
1033 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
1034 printf(" [%s%s%s%s%s%s]",
1035 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1036 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1037 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1038 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1039 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1040 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "");
1047 if (ni6
->ni_qtype
== NI_QTYPE_NOOP
||
1048 ni6
->ni_qtype
== NI_QTYPE_SUPTYPES
) {
1049 if (siz
!= sizeof(*ni6
))
1051 printf(", invalid len");
1058 /* XXX backward compat, icmp-name-lookup-03 */
1059 if (siz
== sizeof(*ni6
)) {
1060 printf(", 03 draft");
1066 switch (ni6
->ni_code
) {
1067 case ICMP6_NI_SUBJ_IPV6
:
1069 sizeof(*ni6
) + sizeof(struct in6_addr
)))
1071 if (siz
!= sizeof(*ni6
) + sizeof(struct in6_addr
)) {
1073 printf(", invalid subject len");
1076 printf(", subject=%s",
1077 getname6((const u_char
*)(ni6
+ 1)));
1079 case ICMP6_NI_SUBJ_FQDN
:
1080 printf(", subject=DNS name");
1081 cp
= (const u_char
*)(ni6
+ 1);
1082 if (cp
[0] == ep
- cp
- 1) {
1083 /* icmp-name-lookup-03, pascal string */
1085 printf(", 03 draft");
1094 dnsname_print(cp
, ep
);
1096 case ICMP6_NI_SUBJ_IPV4
:
1097 if (!TTEST2(*dp
, sizeof(*ni6
) + sizeof(struct in_addr
)))
1099 if (siz
!= sizeof(*ni6
) + sizeof(struct in_addr
)) {
1101 printf(", invalid subject len");
1104 printf(", subject=%s",
1105 getname((const u_char
*)(ni6
+ 1)));
1108 printf(", unknown subject");
1116 case ICMP6_NI_REPLY
:
1117 if (icmp6len
> siz
) {
1118 printf("[|icmp6: node information reply]");
1124 ni6
= (struct icmp6_nodeinfo
*)dp
;
1125 printf(" node information reply");
1127 switch (ni6
->ni_code
) {
1128 case ICMP6_NI_SUCCESS
:
1134 case ICMP6_NI_REFUSED
:
1137 if (siz
!= sizeof(*ni6
))
1139 printf(", invalid length");
1141 case ICMP6_NI_UNKNOWN
:
1144 if (siz
!= sizeof(*ni6
))
1146 printf(", invalid length");
1150 if (ni6
->ni_code
!= ICMP6_NI_SUCCESS
) {
1156 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
1161 if (siz
!= sizeof(*ni6
))
1163 printf(", invalid length");
1165 case NI_QTYPE_SUPTYPES
:
1168 printf("supported qtypes");
1169 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
1171 printf(" [%s]", (i
& 0x01) ? "C" : "");
1177 cp
= (const u_char
*)(ni6
+ 1) + 4;
1178 if (cp
[0] == ep
- cp
- 1) {
1179 /* icmp-name-lookup-03, pascal string */
1181 printf(", 03 draft");
1190 dnsname_print(cp
, ep
);
1191 if ((EXTRACT_16BITS(&ni6
->ni_flags
) & 0x01) != 0)
1192 printf(" [TTL=%u]", *(u_int32_t
*)(ni6
+ 1));
1194 case NI_QTYPE_NODEADDR
:
1197 printf("node addresses");
1200 if (i
+ sizeof(struct in6_addr
) + sizeof(int32_t) > siz
)
1202 printf(" %s", getname6(bp
+ i
));
1203 i
+= sizeof(struct in6_addr
);
1204 printf("(%d)", (int32_t)EXTRACT_32BITS(bp
+ i
));
1205 i
+= sizeof(int32_t);
1210 printf(" [%s%s%s%s%s%s%s]",
1211 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1212 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1213 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1214 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1215 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1216 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
1217 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : "");
1233 fputs("[|icmp6]", stdout
);
1237 icmp6_rrenum_print(const u_char
*bp
, const u_char
*ep
)
1239 struct icmp6_router_renum
*rr6
;
1241 struct rr_pco_match
*match
;
1242 struct rr_pco_use
*use
;
1243 char hbuf
[NI_MAXHOST
];
1248 rr6
= (struct icmp6_router_renum
*)bp
;
1249 cp
= (const char *)(rr6
+ 1);
1251 TCHECK(rr6
->rr_reserved
);
1252 switch (rr6
->rr_code
) {
1253 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
1254 printf("router renum: command");
1256 case ICMP6_ROUTER_RENUMBERING_RESULT
:
1257 printf("router renum: result");
1259 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
1260 printf("router renum: sequence number reset");
1263 printf("router renum: code-#%d", rr6
->rr_code
);
1267 printf(", seq=%u", EXTRACT_32BITS(&rr6
->rr_seqnum
));
1270 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1272 if (rr6
->rr_flags
) {
1273 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
1274 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
1275 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
1276 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
1277 F(ICMP6_RR_FLAGS_PREVDONE
, "P"));
1279 printf("seg=%u,", rr6
->rr_segnum
);
1280 printf("maxdelay=%u", EXTRACT_16BITS(&rr6
->rr_maxdelay
));
1281 if (rr6
->rr_reserved
)
1282 printf("rsvd=0x%x", EXTRACT_32BITS(&rr6
->rr_reserved
));
1288 if (rr6
->rr_code
== ICMP6_ROUTER_RENUMBERING_COMMAND
) {
1289 match
= (struct rr_pco_match
*)cp
;
1290 cp
= (const char *)(match
+ 1);
1292 TCHECK(match
->rpm_prefix
);
1298 printf("match("); /*)*/
1299 switch (match
->rpm_code
) {
1300 case RPM_PCO_ADD
: printf("add"); break;
1301 case RPM_PCO_CHANGE
: printf("change"); break;
1302 case RPM_PCO_SETGLOBAL
: printf("setglobal"); break;
1303 default: printf("#%u", match
->rpm_code
); break;
1307 printf(",ord=%u", match
->rpm_ordinal
);
1308 printf(",min=%u", match
->rpm_minlen
);
1309 printf(",max=%u", match
->rpm_maxlen
);
1311 if (inet_ntop(AF_INET6
, &match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
1312 printf(",%s/%u", hbuf
, match
->rpm_matchlen
);
1314 printf(",?/%u", match
->rpm_matchlen
);
1318 n
= match
->rpm_len
- 3;
1323 use
= (struct rr_pco_use
*)cp
;
1324 cp
= (const char *)(use
+ 1);
1326 TCHECK(use
->rpu_prefix
);
1332 printf("use("); /*)*/
1333 if (use
->rpu_flags
) {
1334 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1336 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
1337 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P"));
1341 printf("mask=0x%x,", use
->rpu_ramask
);
1342 printf("raflags=0x%x,", use
->rpu_raflags
);
1343 if (~use
->rpu_vltime
== 0)
1344 printf("vltime=infty,");
1346 printf("vltime=%u,",
1347 EXTRACT_32BITS(&use
->rpu_vltime
));
1348 if (~use
->rpu_pltime
== 0)
1349 printf("pltime=infty,");
1351 printf("pltime=%u,",
1352 EXTRACT_32BITS(&use
->rpu_pltime
));
1354 if (inet_ntop(AF_INET6
, &use
->rpu_prefix
, hbuf
,
1356 printf("%s/%u/%u", hbuf
, use
->rpu_uselen
,
1359 printf("?/%u/%u", use
->rpu_uselen
,
1369 fputs("[|icmp6]", stdout
);