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
,
201 register const u_int16_t
*sp
;
205 struct in6_addr ph_src
;
206 struct in6_addr ph_dst
;
215 memset(&phu
, 0, sizeof(phu
));
216 phu
.ph
.ph_src
= ip6
->ip6_src
;
217 phu
.ph
.ph_dst
= ip6
->ip6_dst
;
218 phu
.ph
.ph_len
= htonl(len
);
219 phu
.ph
.ph_nxt
= IPPROTO_ICMPV6
;
222 for (i
= 0; i
< sizeof(phu
.pa
) / sizeof(phu
.pa
[0]); i
++)
225 sp
= (const u_int16_t
*)icp
;
227 for (i
= 0; i
< (len
& ~1); i
+= 2)
231 sum
+= htons((*(const u_int8_t
*)sp
) << 8);
234 sum
= (sum
& 0xffff) + (sum
>> 16);
248 ND_RPL_SDAO_ACK
=0x83,
252 enum ND_RPL_DIO_FLAGS
{
253 ND_RPL_DIO_GROUNDED
= 0x80,
254 ND_RPL_DIO_DATRIG
= 0x40,
255 ND_RPL_DIO_DASUPPORT
= 0x20,
256 ND_RPL_DIO_RES4
= 0x10,
257 ND_RPL_DIO_RES3
= 0x08,
258 ND_RPL_DIO_PRF_MASK
= 0x07, /* 3-bit preference */
264 u_int8_t rpl_instanceid
;
265 u_int8_t rpl_dagrank
;
266 u_int8_t rpl_dagid
[16];
270 rpl_print(netdissect_options
*ndo
,
271 const struct icmp6_hdr
*hdr
,
272 const u_char
*bp
, u_int length _U_
)
274 struct nd_rpl_dio
*dio
= (struct nd_rpl_dio
*)bp
;
275 int secured
= hdr
->icmp6_code
& 0x80;
276 int basecode
= hdr
->icmp6_code
& 0x7f;
278 ND_TCHECK(dio
->rpl_dagid
);
281 ND_PRINT((ndo
, ", (SEC)"));
283 ND_PRINT((ndo
, ", (CLR)"));
288 ND_PRINT((ndo
, "DODAG Information Solicitation"));
293 ND_PRINT((ndo
, "DODAG Information Object"));
299 if(isprint(dio
->rpl_dagid
[i
])) {
300 *d
++ = dio
->rpl_dagid
[i
];
302 int cnt
=snprintf(d
,4,"0x%02x",
308 ND_PRINT((ndo
, " [seq:%u,instance:%u,rank:%u,dagid:%s]",
316 ND_PRINT((ndo
, "Destination Advertisement Object"));
321 ND_PRINT((ndo
, "Destination Advertisement Object Ack"));
326 ND_PRINT((ndo
, "RPL message, unknown code %u",hdr
->icmp6_code
));
331 ND_PRINT((ndo
," [|truncated]"));
338 icmp6_print(netdissect_options
*ndo
,
339 const u_char
*bp
, u_int length
, const u_char
*bp2
, int fragmented
)
341 const struct icmp6_hdr
*dp
;
342 const struct ip6_hdr
*ip
;
343 const struct ip6_hdr
*oip
;
344 const struct udphdr
*ouh
;
349 dp
= (struct icmp6_hdr
*)bp
;
350 ip
= (struct ip6_hdr
*)bp2
;
351 oip
= (struct ip6_hdr
*)(dp
+ 1);
352 /* 'ep' points to the end of available data. */
355 TCHECK(dp
->icmp6_cksum
);
357 if (vflag
&& !fragmented
) {
358 int sum
= dp
->icmp6_cksum
;
360 if (TTEST2(bp
[0], length
)) {
361 sum
= icmp6_cksum(ip
, dp
, length
);
363 (void)printf("[bad icmp6 cksum %x!] ", sum
);
365 (void)printf("[icmp6 sum ok] ");
369 printf("ICMP6, %s", tok2str(icmp6_type_values
,"unknown icmp6 type (%u)",dp
->icmp6_type
));
371 /* display cosmetics: print the packet length for printer that use the vflag now */
372 if (vflag
&& (dp
->icmp6_type
== ND_ROUTER_SOLICIT
||
373 dp
->icmp6_type
== ND_ROUTER_ADVERT
||
374 dp
->icmp6_type
== ND_NEIGHBOR_ADVERT
||
375 dp
->icmp6_type
== ND_NEIGHBOR_SOLICIT
||
376 dp
->icmp6_type
== ND_REDIRECT
||
377 dp
->icmp6_type
== ICMP6_HADISCOV_REPLY
||
378 dp
->icmp6_type
== ICMP6_MOBILEPREFIX_ADVERT
))
379 printf(", length %u", length
);
381 switch (dp
->icmp6_type
) {
382 case ICMP6_DST_UNREACH
:
383 TCHECK(oip
->ip6_dst
);
384 printf(", %s", tok2str(icmp6_dst_unreach_code_values
,"unknown unreach code (%u)",dp
->icmp6_code
));
385 switch (dp
->icmp6_code
) {
387 case ICMP6_DST_UNREACH_NOROUTE
: /* fall through */
388 case ICMP6_DST_UNREACH_ADMIN
:
389 case ICMP6_DST_UNREACH_ADDR
:
390 printf(" %s",ip6addr_string(&oip
->ip6_dst
));
392 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
393 printf(" %s, source address %s",
394 ip6addr_string(&oip
->ip6_dst
),
395 ip6addr_string(&oip
->ip6_src
));
397 case ICMP6_DST_UNREACH_NOPORT
:
398 if ((ouh
= get_upperlayer((u_char
*)oip
, &prot
))
402 dport
= EXTRACT_16BITS(&ouh
->uh_dport
);
405 printf(", %s tcp port %s",
406 ip6addr_string(&oip
->ip6_dst
),
407 tcpport_string(dport
));
410 printf(", %s udp port %s",
411 ip6addr_string(&oip
->ip6_dst
),
412 udpport_string(dport
));
415 printf(", %s protocol %d port %d unreachable",
416 ip6addr_string(&oip
->ip6_dst
),
417 oip
->ip6_nxt
, dport
);
423 print_unknown_data(bp
,"\n\t",length
);
429 case ICMP6_PACKET_TOO_BIG
:
430 TCHECK(dp
->icmp6_mtu
);
431 printf(", mtu %u", EXTRACT_32BITS(&dp
->icmp6_mtu
));
433 case ICMP6_TIME_EXCEEDED
:
434 TCHECK(oip
->ip6_dst
);
435 switch (dp
->icmp6_code
) {
436 case ICMP6_TIME_EXCEED_TRANSIT
:
438 ip6addr_string(&oip
->ip6_dst
));
440 case ICMP6_TIME_EXCEED_REASSEMBLY
:
441 printf(" (reassembly)");
444 printf(", unknown code (%u)", dp
->icmp6_code
);
448 case ICMP6_PARAM_PROB
:
449 TCHECK(oip
->ip6_dst
);
450 switch (dp
->icmp6_code
) {
451 case ICMP6_PARAMPROB_HEADER
:
452 printf(", errorneous - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
));
454 case ICMP6_PARAMPROB_NEXTHEADER
:
455 printf(", next header - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
));
457 case ICMP6_PARAMPROB_OPTION
:
458 printf(", option - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
));
466 case ICMP6_ECHO_REQUEST
:
467 case ICMP6_ECHO_REPLY
:
468 TCHECK(dp
->icmp6_seq
);
469 printf(", seq %u", EXTRACT_16BITS(&dp
->icmp6_seq
));
471 case ICMP6_MEMBERSHIP_QUERY
:
472 if (length
== MLD_MINLEN
) {
473 mld6_print((const u_char
*)dp
);
474 } else if (length
>= MLDV2_MINLEN
) {
476 mldv2_query_print((const u_char
*)dp
, length
);
478 printf(" unknown-version (len %u) ", length
);
481 case ICMP6_MEMBERSHIP_REPORT
:
482 mld6_print((const u_char
*)dp
);
484 case ICMP6_MEMBERSHIP_REDUCTION
:
485 mld6_print((const u_char
*)dp
);
487 case ND_ROUTER_SOLICIT
:
490 icmp6_opt_print((const u_char
*)dp
+ RTSOLLEN
,
494 case ND_ROUTER_ADVERT
:
497 struct nd_router_advert
*p
;
499 p
= (struct nd_router_advert
*)dp
;
500 TCHECK(p
->nd_ra_retransmit
);
501 printf("\n\thop limit %u, Flags [%s]" \
502 ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
503 (u_int
)p
->nd_ra_curhoplimit
,
504 bittok2str(icmp6_opt_ra_flag_values
,"none",(p
->nd_ra_flags_reserved
)),
505 get_rtpref(p
->nd_ra_flags_reserved
),
506 EXTRACT_16BITS(&p
->nd_ra_router_lifetime
),
507 EXTRACT_32BITS(&p
->nd_ra_reachable
),
508 EXTRACT_32BITS(&p
->nd_ra_retransmit
));
510 icmp6_opt_print((const u_char
*)dp
+ RTADVLEN
,
514 case ND_NEIGHBOR_SOLICIT
:
516 struct nd_neighbor_solicit
*p
;
517 p
= (struct nd_neighbor_solicit
*)dp
;
518 TCHECK(p
->nd_ns_target
);
519 printf(", who has %s", ip6addr_string(&p
->nd_ns_target
));
522 icmp6_opt_print((const u_char
*)dp
+ NDSOLLEN
,
527 case ND_NEIGHBOR_ADVERT
:
529 struct nd_neighbor_advert
*p
;
531 p
= (struct nd_neighbor_advert
*)dp
;
532 TCHECK(p
->nd_na_target
);
533 printf(", tgt is %s",
534 ip6addr_string(&p
->nd_na_target
));
536 printf(", Flags [%s]",
537 bittok2str(icmp6_nd_na_flag_values
,
539 EXTRACT_32BITS(&p
->nd_na_flags_reserved
)));
541 icmp6_opt_print((const u_char
*)dp
+ NDADVLEN
,
548 #define RDR(i) ((struct nd_redirect *)(i))
549 TCHECK(RDR(dp
)->nd_rd_dst
);
550 printf(", %s", getname6((const u_char
*)&RDR(dp
)->nd_rd_dst
));
551 TCHECK(RDR(dp
)->nd_rd_target
);
553 getname6((const u_char
*)&RDR(dp
)->nd_rd_target
));
554 #define REDIRECTLEN 40
556 icmp6_opt_print((const u_char
*)dp
+ REDIRECTLEN
,
557 length
- REDIRECTLEN
);
562 case ICMP6_ROUTER_RENUMBERING
:
563 icmp6_rrenum_print(bp
, ep
);
567 icmp6_nodeinfo_print(length
, bp
, ep
);
572 case ICMP6_V2_MEMBERSHIP_REPORT
:
573 mldv2_report_print((const u_char
*) dp
, length
);
575 case ICMP6_MOBILEPREFIX_SOLICIT
: /* fall through */
576 case ICMP6_HADISCOV_REQUEST
:
577 TCHECK(dp
->icmp6_data16
[0]);
578 printf(", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
580 case ICMP6_HADISCOV_REPLY
:
582 struct in6_addr
*in6
;
585 TCHECK(dp
->icmp6_data16
[0]);
586 printf(", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
587 cp
= (u_char
*)dp
+ length
;
588 in6
= (struct in6_addr
*)(dp
+ 1);
589 for (; (u_char
*)in6
< cp
; in6
++) {
591 printf(", %s", ip6addr_string(in6
));
595 case ICMP6_MOBILEPREFIX_ADVERT
:
597 TCHECK(dp
->icmp6_data16
[0]);
598 printf(", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
599 if (dp
->icmp6_data16
[1] & 0xc0)
601 if (dp
->icmp6_data16
[1] & 0x80)
603 if (dp
->icmp6_data16
[1] & 0x40)
606 icmp6_opt_print((const u_char
*)dp
+ MPADVLEN
,
611 rpl_print(ndo
, dp
, &dp
->icmp6_data8
[0], length
);
614 printf(", length %u", length
);
616 print_unknown_data(bp
,"\n\t", length
);
620 printf(", length %u", length
);
623 fputs("[|icmp6]", stdout
);
626 static struct udphdr
*
627 get_upperlayer(u_char
*bp
, u_int
*prot
)
630 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
633 struct ip6_frag
*fragh
;
638 /* 'ep' points to the end of available data. */
641 if (!TTEST(ip6
->ip6_nxt
))
645 hlen
= sizeof(struct ip6_hdr
);
653 uh
= (struct udphdr
*)bp
;
654 if (TTEST(uh
->uh_dport
)) {
662 case IPPROTO_HOPOPTS
:
663 case IPPROTO_DSTOPTS
:
664 case IPPROTO_ROUTING
:
665 hbh
= (struct ip6_hbh
*)bp
;
666 if (!TTEST(hbh
->ip6h_len
))
669 hlen
= (hbh
->ip6h_len
+ 1) << 3;
672 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
673 fragh
= (struct ip6_frag
*)bp
;
674 if (!TTEST(fragh
->ip6f_offlg
))
676 /* fragments with non-zero offset are meaningless */
677 if ((EXTRACT_16BITS(&fragh
->ip6f_offlg
) & IP6F_OFF_MASK
) != 0)
679 nh
= fragh
->ip6f_nxt
;
680 hlen
= sizeof(struct ip6_frag
);
684 ah
= (struct ah
*)bp
;
685 if (!TTEST(ah
->ah_len
))
688 hlen
= (ah
->ah_len
+ 2) << 2;
691 default: /* unknown or undecodable header */
692 *prot
= nh
; /* meaningless, but set here anyway */
697 return(NULL
); /* should be notreached, though */
701 icmp6_opt_print(const u_char
*bp
, int resid
)
703 const struct nd_opt_hdr
*op
;
704 const struct nd_opt_hdr
*opl
; /* why there's no struct? */
705 const struct nd_opt_prefix_info
*opp
;
706 const struct icmp6_opts_redirect
*opr
;
707 const struct nd_opt_mtu
*opm
;
708 const struct nd_opt_rdnss
*oprd
;
709 const struct nd_opt_advinterval
*opa
;
710 const struct nd_opt_homeagent_info
*oph
;
711 const struct nd_opt_route_info
*opri
;
712 const u_char
*cp
, *ep
;
713 struct in6_addr in6
, *in6p
;
717 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
720 /* 'ep' points to the end of available data. */
724 op
= (struct nd_opt_hdr
*)cp
;
726 ECHECK(op
->nd_opt_len
);
729 if (op
->nd_opt_len
== 0)
731 if (cp
+ (op
->nd_opt_len
<< 3) > ep
)
734 printf("\n\t %s option (%u), length %u (%u): ",
735 tok2str(icmp6_opt_values
, "unknown", op
->nd_opt_type
),
740 switch (op
->nd_opt_type
) {
741 case ND_OPT_SOURCE_LINKADDR
:
742 opl
= (struct nd_opt_hdr
*)op
;
743 l
= (op
->nd_opt_len
<< 3) - 2;
744 print_lladdr(cp
+ 2, l
);
746 case ND_OPT_TARGET_LINKADDR
:
747 opl
= (struct nd_opt_hdr
*)op
;
748 l
= (op
->nd_opt_len
<< 3) - 2;
749 print_lladdr(cp
+ 2, l
);
751 case ND_OPT_PREFIX_INFORMATION
:
752 opp
= (struct nd_opt_prefix_info
*)op
;
753 TCHECK(opp
->nd_opt_pi_prefix
);
754 printf("%s/%u%s, Flags [%s], valid time %ss",
755 ip6addr_string(&opp
->nd_opt_pi_prefix
),
756 opp
->nd_opt_pi_prefix_len
,
757 (op
->nd_opt_len
!= 4) ? "badlen" : "",
758 bittok2str(icmp6_opt_pi_flag_values
, "none", opp
->nd_opt_pi_flags_reserved
),
759 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_valid_time
)));
760 printf(", pref. time %ss", get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_preferred_time
)));
762 case ND_OPT_REDIRECTED_HEADER
:
763 opr
= (struct icmp6_opts_redirect
*)op
;
764 print_unknown_data(bp
,"\n\t ",op
->nd_opt_len
<<3);
768 opm
= (struct nd_opt_mtu
*)op
;
769 TCHECK(opm
->nd_opt_mtu_mtu
);
771 EXTRACT_32BITS(&opm
->nd_opt_mtu_mtu
),
772 (op
->nd_opt_len
!= 1) ? "bad option length" : "" );
775 oprd
= (struct nd_opt_rdnss
*)op
;
776 l
= (op
->nd_opt_len
- 1) / 2;
777 printf(" lifetime %us,",
778 EXTRACT_32BITS(&oprd
->nd_opt_rdnss_lifetime
));
779 for (i
= 0; i
< l
; i
++) {
780 TCHECK(oprd
->nd_opt_rdnss_addr
[i
]);
782 ip6addr_string(&oprd
->nd_opt_rdnss_addr
[i
]));
785 case ND_OPT_ADVINTERVAL
:
786 opa
= (struct nd_opt_advinterval
*)op
;
787 TCHECK(opa
->nd_opt_adv_interval
);
788 printf(" %us", EXTRACT_32BITS(&opa
->nd_opt_adv_interval
));
790 case ND_OPT_HOMEAGENT_INFO
:
791 oph
= (struct nd_opt_homeagent_info
*)op
;
792 TCHECK(oph
->nd_opt_hai_lifetime
);
793 printf(" preference %u, lifetime %u",
794 EXTRACT_16BITS(&oph
->nd_opt_hai_preference
),
795 EXTRACT_16BITS(&oph
->nd_opt_hai_lifetime
));
797 case ND_OPT_ROUTE_INFO
:
798 opri
= (struct nd_opt_route_info
*)op
;
799 TCHECK(opri
->nd_opt_rti_lifetime
);
800 memset(&in6
, 0, sizeof(in6
));
801 in6p
= (struct in6_addr
*)(opri
+ 1);
802 switch (op
->nd_opt_len
) {
807 memcpy(&in6
, opri
+ 1, 8);
811 memcpy(&in6
, opri
+ 1, sizeof(in6
));
816 printf(" %s/%u", ip6addr_string(&in6
),
817 opri
->nd_opt_rti_prefixlen
);
818 printf(", pref=%s", get_rtpref(opri
->nd_opt_rti_flags
));
819 printf(", lifetime=%s",
820 get_lifetime(EXTRACT_32BITS(&opri
->nd_opt_rti_lifetime
)));
824 print_unknown_data(cp
+2,"\n\t ", (op
->nd_opt_len
<< 3) - 2); /* skip option header */
829 /* do we want to see an additional hexdump ? */
831 print_unknown_data(cp
+2,"\n\t ", (op
->nd_opt_len
<< 3) - 2); /* skip option header */
833 cp
+= op
->nd_opt_len
<< 3;
834 resid
-= op
->nd_opt_len
<< 3;
839 fputs("[ndp opt]", stdout
);
845 mld6_print(const u_char
*bp
)
847 struct mld6_hdr
*mp
= (struct mld6_hdr
*)bp
;
850 /* 'ep' points to the end of available data. */
853 if ((u_char
*)mp
+ sizeof(*mp
) > ep
)
856 printf("max resp delay: %d ", EXTRACT_16BITS(&mp
->mld6_maxdelay
));
857 printf("addr: %s", ip6addr_string(&mp
->mld6_addr
));
861 mldv2_report_print(const u_char
*bp
, u_int len
)
863 struct icmp6_hdr
*icp
= (struct icmp6_hdr
*) bp
;
864 u_int group
, nsrcs
, ngroups
;
867 /* Minimum len is 8 */
869 printf(" [invalid len %d]", len
);
873 TCHECK(icp
->icmp6_data16
[1]);
874 ngroups
= EXTRACT_16BITS(&icp
->icmp6_data16
[1]);
875 printf(", %d group record(s)", ngroups
);
877 /* Print the group records */
879 for (i
= 0; i
< ngroups
; i
++) {
880 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
881 if (len
< group
+ 20) {
882 printf(" [invalid number of groups]");
885 TCHECK2(bp
[group
+ 4], sizeof(struct in6_addr
));
886 printf(" [gaddr %s", ip6addr_string(&bp
[group
+ 4]));
887 printf(" %s", tok2str(mldv2report2str
, " [v2-report-#%d]",
889 nsrcs
= (bp
[group
+ 2] << 8) + bp
[group
+ 3];
890 /* Check the number of sources and print them */
891 if (len
< group
+ 20 + (nsrcs
* sizeof(struct in6_addr
))) {
892 printf(" [invalid number of sources %d]", nsrcs
);
896 printf(", %d source(s)", nsrcs
);
898 /* Print the sources */
900 for (j
= 0; j
< nsrcs
; j
++) {
901 TCHECK2(bp
[group
+ 20 + j
* sizeof(struct in6_addr
)],
902 sizeof(struct in6_addr
));
903 printf(" %s", ip6addr_string(&bp
[group
+ 20 + j
* sizeof(struct in6_addr
)]));
907 /* Next group record */
908 group
+= 20 + nsrcs
* sizeof(struct in6_addr
);
914 (void)printf("[|icmp6]");
919 mldv2_query_print(const u_char
*bp
, u_int len
)
921 struct icmp6_hdr
*icp
= (struct icmp6_hdr
*) bp
;
927 /* Minimum len is 28 */
929 printf(" [invalid len %d]", len
);
932 TCHECK(icp
->icmp6_data16
[0]);
933 mrc
= EXTRACT_16BITS(&icp
->icmp6_data16
[0]);
937 mrt
= ((mrc
& 0x0fff) | 0x1000) << (((mrc
& 0x7000) >> 12) + 3);
940 (void)printf(" [max resp delay=%d]", mrt
);
942 TCHECK2(bp
[8], sizeof(struct in6_addr
));
943 printf(" [gaddr %s", ip6addr_string(&bp
[8]));
951 printf(" robustness=%d", bp
[24] & 0x07);
956 qqi
= ((bp
[25] & 0x0f) | 0x10) << (((bp
[25] & 0x70) >> 4) + 3);
958 printf(" qqi=%d", qqi
);
962 nsrcs
= EXTRACT_16BITS(&bp
[26]);
964 if (len
< 28 + nsrcs
* sizeof(struct in6_addr
))
965 printf(" [invalid number of sources]");
966 else if (vflag
> 1) {
968 for (i
= 0; i
< nsrcs
; i
++) {
969 TCHECK2(bp
[28 + i
* sizeof(struct in6_addr
)],
970 sizeof(struct in6_addr
));
971 printf(" %s", ip6addr_string(&bp
[28 + i
* sizeof(struct in6_addr
)]));
975 printf(", %d source(s)", nsrcs
);
980 (void)printf("[|icmp6]");
985 dnsname_print(const u_char
*cp
, const u_char
*ep
)
989 /* DNS name decoding - no decompression */
998 while (i
-- && cp
< ep
) {
1002 if (cp
+ 1 < ep
&& *cp
)
1008 } else if (cp
+ 1 == ep
&& *cp
== '\0') {
1021 icmp6_nodeinfo_print(u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
1023 struct icmp6_nodeinfo
*ni6
;
1024 struct icmp6_hdr
*dp
;
1031 dp
= (struct icmp6_hdr
*)bp
;
1032 ni6
= (struct icmp6_nodeinfo
*)bp
;
1035 switch (ni6
->ni_type
) {
1036 case ICMP6_NI_QUERY
:
1037 if (siz
== sizeof(*dp
) + 4) {
1038 /* KAME who-are-you */
1039 printf(" who-are-you request");
1042 printf(" node information query");
1044 TCHECK2(*dp
, sizeof(*ni6
));
1045 ni6
= (struct icmp6_nodeinfo
*)dp
;
1047 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
1051 case NI_QTYPE_SUPTYPES
:
1052 printf("supported qtypes");
1053 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
1055 printf(" [%s]", (i
& 0x01) ? "C" : "");
1061 case NI_QTYPE_NODEADDR
:
1062 printf("node addresses");
1066 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
1067 printf(" [%s%s%s%s%s%s]",
1068 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1069 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1070 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1071 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1072 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1073 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "");
1080 if (ni6
->ni_qtype
== NI_QTYPE_NOOP
||
1081 ni6
->ni_qtype
== NI_QTYPE_SUPTYPES
) {
1082 if (siz
!= sizeof(*ni6
))
1084 printf(", invalid len");
1091 /* XXX backward compat, icmp-name-lookup-03 */
1092 if (siz
== sizeof(*ni6
)) {
1093 printf(", 03 draft");
1099 switch (ni6
->ni_code
) {
1100 case ICMP6_NI_SUBJ_IPV6
:
1102 sizeof(*ni6
) + sizeof(struct in6_addr
)))
1104 if (siz
!= sizeof(*ni6
) + sizeof(struct in6_addr
)) {
1106 printf(", invalid subject len");
1109 printf(", subject=%s",
1110 getname6((const u_char
*)(ni6
+ 1)));
1112 case ICMP6_NI_SUBJ_FQDN
:
1113 printf(", subject=DNS name");
1114 cp
= (const u_char
*)(ni6
+ 1);
1115 if (cp
[0] == ep
- cp
- 1) {
1116 /* icmp-name-lookup-03, pascal string */
1118 printf(", 03 draft");
1127 dnsname_print(cp
, ep
);
1129 case ICMP6_NI_SUBJ_IPV4
:
1130 if (!TTEST2(*dp
, sizeof(*ni6
) + sizeof(struct in_addr
)))
1132 if (siz
!= sizeof(*ni6
) + sizeof(struct in_addr
)) {
1134 printf(", invalid subject len");
1137 printf(", subject=%s",
1138 getname((const u_char
*)(ni6
+ 1)));
1141 printf(", unknown subject");
1149 case ICMP6_NI_REPLY
:
1150 if (icmp6len
> siz
) {
1151 printf("[|icmp6: node information reply]");
1157 ni6
= (struct icmp6_nodeinfo
*)dp
;
1158 printf(" node information reply");
1160 switch (ni6
->ni_code
) {
1161 case ICMP6_NI_SUCCESS
:
1167 case ICMP6_NI_REFUSED
:
1170 if (siz
!= sizeof(*ni6
))
1172 printf(", invalid length");
1174 case ICMP6_NI_UNKNOWN
:
1177 if (siz
!= sizeof(*ni6
))
1179 printf(", invalid length");
1183 if (ni6
->ni_code
!= ICMP6_NI_SUCCESS
) {
1189 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
1194 if (siz
!= sizeof(*ni6
))
1196 printf(", invalid length");
1198 case NI_QTYPE_SUPTYPES
:
1201 printf("supported qtypes");
1202 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
1204 printf(" [%s]", (i
& 0x01) ? "C" : "");
1210 cp
= (const u_char
*)(ni6
+ 1) + 4;
1211 if (cp
[0] == ep
- cp
- 1) {
1212 /* icmp-name-lookup-03, pascal string */
1214 printf(", 03 draft");
1223 dnsname_print(cp
, ep
);
1224 if ((EXTRACT_16BITS(&ni6
->ni_flags
) & 0x01) != 0)
1225 printf(" [TTL=%u]", *(u_int32_t
*)(ni6
+ 1));
1227 case NI_QTYPE_NODEADDR
:
1230 printf("node addresses");
1233 if (i
+ sizeof(struct in6_addr
) + sizeof(int32_t) > siz
)
1235 printf(" %s", getname6(bp
+ i
));
1236 i
+= sizeof(struct in6_addr
);
1237 printf("(%d)", (int32_t)EXTRACT_32BITS(bp
+ i
));
1238 i
+= sizeof(int32_t);
1243 printf(" [%s%s%s%s%s%s%s]",
1244 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1245 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1246 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1247 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1248 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1249 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
1250 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : "");
1266 fputs("[|icmp6]", stdout
);
1270 icmp6_rrenum_print(const u_char
*bp
, const u_char
*ep
)
1272 struct icmp6_router_renum
*rr6
;
1274 struct rr_pco_match
*match
;
1275 struct rr_pco_use
*use
;
1276 char hbuf
[NI_MAXHOST
];
1281 rr6
= (struct icmp6_router_renum
*)bp
;
1282 cp
= (const char *)(rr6
+ 1);
1284 TCHECK(rr6
->rr_reserved
);
1285 switch (rr6
->rr_code
) {
1286 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
1287 printf("router renum: command");
1289 case ICMP6_ROUTER_RENUMBERING_RESULT
:
1290 printf("router renum: result");
1292 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
1293 printf("router renum: sequence number reset");
1296 printf("router renum: code-#%d", rr6
->rr_code
);
1300 printf(", seq=%u", EXTRACT_32BITS(&rr6
->rr_seqnum
));
1303 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1305 if (rr6
->rr_flags
) {
1306 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
1307 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
1308 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
1309 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
1310 F(ICMP6_RR_FLAGS_PREVDONE
, "P"));
1312 printf("seg=%u,", rr6
->rr_segnum
);
1313 printf("maxdelay=%u", EXTRACT_16BITS(&rr6
->rr_maxdelay
));
1314 if (rr6
->rr_reserved
)
1315 printf("rsvd=0x%x", EXTRACT_32BITS(&rr6
->rr_reserved
));
1321 if (rr6
->rr_code
== ICMP6_ROUTER_RENUMBERING_COMMAND
) {
1322 match
= (struct rr_pco_match
*)cp
;
1323 cp
= (const char *)(match
+ 1);
1325 TCHECK(match
->rpm_prefix
);
1331 printf("match("); /*)*/
1332 switch (match
->rpm_code
) {
1333 case RPM_PCO_ADD
: printf("add"); break;
1334 case RPM_PCO_CHANGE
: printf("change"); break;
1335 case RPM_PCO_SETGLOBAL
: printf("setglobal"); break;
1336 default: printf("#%u", match
->rpm_code
); break;
1340 printf(",ord=%u", match
->rpm_ordinal
);
1341 printf(",min=%u", match
->rpm_minlen
);
1342 printf(",max=%u", match
->rpm_maxlen
);
1344 if (inet_ntop(AF_INET6
, &match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
1345 printf(",%s/%u", hbuf
, match
->rpm_matchlen
);
1347 printf(",?/%u", match
->rpm_matchlen
);
1351 n
= match
->rpm_len
- 3;
1356 use
= (struct rr_pco_use
*)cp
;
1357 cp
= (const char *)(use
+ 1);
1359 TCHECK(use
->rpu_prefix
);
1365 printf("use("); /*)*/
1366 if (use
->rpu_flags
) {
1367 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1369 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
1370 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P"));
1374 printf("mask=0x%x,", use
->rpu_ramask
);
1375 printf("raflags=0x%x,", use
->rpu_raflags
);
1376 if (~use
->rpu_vltime
== 0)
1377 printf("vltime=infty,");
1379 printf("vltime=%u,",
1380 EXTRACT_32BITS(&use
->rpu_vltime
));
1381 if (~use
->rpu_pltime
== 0)
1382 printf("pltime=infty,");
1384 printf("pltime=%u,",
1385 EXTRACT_32BITS(&use
->rpu_pltime
));
1387 if (inet_ntop(AF_INET6
, &use
->rpu_prefix
, hbuf
,
1389 printf("%s/%u/%u", hbuf
, use
->rpu_uselen
,
1392 printf("?/%u/%u", use
->rpu_uselen
,
1402 fputs("[|icmp6]", stdout
);