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);
246 enum ND_RPL_DIO_FLAGS
{
247 ND_RPL_DIO_GROUNDED
= 0x80,
248 ND_RPL_DIO_DATRIG
= 0x40,
249 ND_RPL_DIO_DASUPPORT
= 0x20,
250 ND_RPL_DIO_RES4
= 0x10,
251 ND_RPL_DIO_RES3
= 0x08,
252 ND_RPL_DIO_PRF_MASK
= 0x07, /* 3-bit preference */
258 u_int8_t rpl_instanceid
;
259 u_int8_t rpl_dagrank
;
260 u_int8_t rpl_dagid
[16];
264 rpl_print(netdissect_options
*ndo
,
265 const struct icmp6_hdr
*hdr
,
266 const u_char
*bp
, u_int length _U_
)
268 struct nd_rpl_dio
*dio
= (struct nd_rpl_dio
*)bp
;
270 ND_TCHECK(dio
->rpl_dagid
);
272 switch(hdr
->icmp6_code
) {
274 ND_PRINT((ndo
, ", DAG Information Solicitation"));
279 ND_PRINT((ndo
, ", DAG Information Object"));
285 if(isprint(dio
->rpl_dagid
[i
])) {
286 *d
++ = dio
->rpl_dagid
[i
];
288 int cnt
=snprintf(d
,4,"0x%02x",
294 ND_PRINT((ndo
, " [seq:%u,instance:%u,rank:%u,dagid:%s]",
302 ND_PRINT((ndo
, ", Destination Advertisement Object"));
307 ND_PRINT((ndo
, ", RPL message, unknown code %u",hdr
->icmp6_code
));
312 ND_PRINT((ndo
," [|truncated]"));
319 icmp6_print(netdissect_options
*ndo
,
320 const u_char
*bp
, u_int length
, const u_char
*bp2
, int fragmented
)
322 const struct icmp6_hdr
*dp
;
323 const struct ip6_hdr
*ip
;
324 const struct ip6_hdr
*oip
;
325 const struct udphdr
*ouh
;
330 dp
= (struct icmp6_hdr
*)bp
;
331 ip
= (struct ip6_hdr
*)bp2
;
332 oip
= (struct ip6_hdr
*)(dp
+ 1);
333 /* 'ep' points to the end of available data. */
336 TCHECK(dp
->icmp6_cksum
);
338 if (vflag
&& !fragmented
) {
339 int sum
= dp
->icmp6_cksum
;
341 if (TTEST2(bp
[0], length
)) {
342 sum
= icmp6_cksum(ip
, dp
, length
);
344 (void)printf("[bad icmp6 cksum %x!] ", sum
);
346 (void)printf("[icmp6 sum ok] ");
350 printf("ICMP6, %s", tok2str(icmp6_type_values
,"unknown icmp6 type (%u)",dp
->icmp6_type
));
352 /* display cosmetics: print the packet length for printer that use the vflag now */
353 if (vflag
&& (dp
->icmp6_type
==
356 ND_NEIGHBOR_ADVERT
||
357 ND_NEIGHBOR_SOLICIT
||
359 ICMP6_HADISCOV_REPLY
||
360 ICMP6_MOBILEPREFIX_ADVERT
))
361 printf(", length %u", length
);
363 switch (dp
->icmp6_type
) {
364 case ICMP6_DST_UNREACH
:
365 TCHECK(oip
->ip6_dst
);
366 printf(", %s", tok2str(icmp6_dst_unreach_code_values
,"unknown unreach code (%u)",dp
->icmp6_code
));
367 switch (dp
->icmp6_code
) {
369 case ICMP6_DST_UNREACH_NOROUTE
: /* fall through */
370 case ICMP6_DST_UNREACH_ADMIN
:
371 case ICMP6_DST_UNREACH_ADDR
:
372 printf(" %s",ip6addr_string(&oip
->ip6_dst
));
374 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
375 printf(" %s, source address %s",
376 ip6addr_string(&oip
->ip6_dst
),
377 ip6addr_string(&oip
->ip6_src
));
379 case ICMP6_DST_UNREACH_NOPORT
:
380 if ((ouh
= get_upperlayer((u_char
*)oip
, &prot
))
384 dport
= EXTRACT_16BITS(&ouh
->uh_dport
);
387 printf(", %s tcp port %s",
388 ip6addr_string(&oip
->ip6_dst
),
389 tcpport_string(dport
));
392 printf(", %s udp port %s",
393 ip6addr_string(&oip
->ip6_dst
),
394 udpport_string(dport
));
397 printf(", %s protocol %d port %d unreachable",
398 ip6addr_string(&oip
->ip6_dst
),
399 oip
->ip6_nxt
, dport
);
405 print_unknown_data(bp
,"\n\t",length
);
411 case ICMP6_PACKET_TOO_BIG
:
412 TCHECK(dp
->icmp6_mtu
);
413 printf(", mtu %u", EXTRACT_32BITS(&dp
->icmp6_mtu
));
415 case ICMP6_TIME_EXCEEDED
:
416 TCHECK(oip
->ip6_dst
);
417 switch (dp
->icmp6_code
) {
418 case ICMP6_TIME_EXCEED_TRANSIT
:
420 ip6addr_string(&oip
->ip6_dst
));
422 case ICMP6_TIME_EXCEED_REASSEMBLY
:
423 printf(" (reassembly)");
426 printf(", unknown code (%u)", dp
->icmp6_code
);
430 case ICMP6_PARAM_PROB
:
431 TCHECK(oip
->ip6_dst
);
432 switch (dp
->icmp6_code
) {
433 case ICMP6_PARAMPROB_HEADER
:
434 printf(", errorneous - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
));
436 case ICMP6_PARAMPROB_NEXTHEADER
:
437 printf(", next header - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
));
439 case ICMP6_PARAMPROB_OPTION
:
440 printf(", option - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
));
448 case ICMP6_ECHO_REQUEST
:
449 case ICMP6_ECHO_REPLY
:
450 TCHECK(dp
->icmp6_seq
);
451 printf(", seq %u", EXTRACT_16BITS(&dp
->icmp6_seq
));
453 case ICMP6_MEMBERSHIP_QUERY
:
454 if (length
== MLD_MINLEN
) {
455 mld6_print((const u_char
*)dp
);
456 } else if (length
>= MLDV2_MINLEN
) {
458 mldv2_query_print((const u_char
*)dp
, length
);
460 printf(" unknown-version (len %u) ", length
);
463 case ICMP6_MEMBERSHIP_REPORT
:
464 mld6_print((const u_char
*)dp
);
466 case ICMP6_MEMBERSHIP_REDUCTION
:
467 mld6_print((const u_char
*)dp
);
469 case ND_ROUTER_SOLICIT
:
472 icmp6_opt_print((const u_char
*)dp
+ RTSOLLEN
,
476 case ND_ROUTER_ADVERT
:
479 struct nd_router_advert
*p
;
481 p
= (struct nd_router_advert
*)dp
;
482 TCHECK(p
->nd_ra_retransmit
);
483 printf("\n\thop limit %u, Flags [%s]" \
484 ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
485 (u_int
)p
->nd_ra_curhoplimit
,
486 bittok2str(icmp6_opt_ra_flag_values
,"none",(p
->nd_ra_flags_reserved
)),
487 get_rtpref(p
->nd_ra_flags_reserved
),
488 EXTRACT_16BITS(&p
->nd_ra_router_lifetime
),
489 EXTRACT_32BITS(&p
->nd_ra_reachable
),
490 EXTRACT_32BITS(&p
->nd_ra_retransmit
));
492 icmp6_opt_print((const u_char
*)dp
+ RTADVLEN
,
496 case ND_NEIGHBOR_SOLICIT
:
498 struct nd_neighbor_solicit
*p
;
499 p
= (struct nd_neighbor_solicit
*)dp
;
500 TCHECK(p
->nd_ns_target
);
501 printf(", who has %s", ip6addr_string(&p
->nd_ns_target
));
504 icmp6_opt_print((const u_char
*)dp
+ NDSOLLEN
,
509 case ND_NEIGHBOR_ADVERT
:
511 struct nd_neighbor_advert
*p
;
513 p
= (struct nd_neighbor_advert
*)dp
;
514 TCHECK(p
->nd_na_target
);
515 printf(", tgt is %s",
516 ip6addr_string(&p
->nd_na_target
));
518 printf(", Flags [%s]",
519 bittok2str(icmp6_nd_na_flag_values
,
521 EXTRACT_32BITS(&p
->nd_na_flags_reserved
)));
523 icmp6_opt_print((const u_char
*)dp
+ NDADVLEN
,
530 #define RDR(i) ((struct nd_redirect *)(i))
531 TCHECK(RDR(dp
)->nd_rd_dst
);
532 printf(", %s", getname6((const u_char
*)&RDR(dp
)->nd_rd_dst
));
533 TCHECK(RDR(dp
)->nd_rd_target
);
535 getname6((const u_char
*)&RDR(dp
)->nd_rd_target
));
536 #define REDIRECTLEN 40
538 icmp6_opt_print((const u_char
*)dp
+ REDIRECTLEN
,
539 length
- REDIRECTLEN
);
544 case ICMP6_ROUTER_RENUMBERING
:
545 icmp6_rrenum_print(bp
, ep
);
549 icmp6_nodeinfo_print(length
, bp
, ep
);
554 case ICMP6_V2_MEMBERSHIP_REPORT
:
555 mldv2_report_print((const u_char
*) dp
, length
);
557 case ICMP6_MOBILEPREFIX_SOLICIT
: /* fall through */
558 case ICMP6_HADISCOV_REQUEST
:
559 TCHECK(dp
->icmp6_data16
[0]);
560 printf(", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
562 case ICMP6_HADISCOV_REPLY
:
564 struct in6_addr
*in6
;
567 TCHECK(dp
->icmp6_data16
[0]);
568 printf(", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
569 cp
= (u_char
*)dp
+ length
;
570 in6
= (struct in6_addr
*)(dp
+ 1);
571 for (; (u_char
*)in6
< cp
; in6
++) {
573 printf(", %s", ip6addr_string(in6
));
577 case ICMP6_MOBILEPREFIX_ADVERT
:
579 TCHECK(dp
->icmp6_data16
[0]);
580 printf(", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0]));
581 if (dp
->icmp6_data16
[1] & 0xc0)
583 if (dp
->icmp6_data16
[1] & 0x80)
585 if (dp
->icmp6_data16
[1] & 0x40)
588 icmp6_opt_print((const u_char
*)dp
+ MPADVLEN
,
593 rpl_print(ndo
, dp
, &dp
->icmp6_data8
[0], length
);
596 printf(", length %u", length
);
598 print_unknown_data(bp
,"\n\t", length
);
602 printf(", length %u", length
);
605 fputs("[|icmp6]", stdout
);
608 static struct udphdr
*
609 get_upperlayer(u_char
*bp
, u_int
*prot
)
612 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
615 struct ip6_frag
*fragh
;
620 /* 'ep' points to the end of available data. */
623 if (!TTEST(ip6
->ip6_nxt
))
627 hlen
= sizeof(struct ip6_hdr
);
635 uh
= (struct udphdr
*)bp
;
636 if (TTEST(uh
->uh_dport
)) {
644 case IPPROTO_HOPOPTS
:
645 case IPPROTO_DSTOPTS
:
646 case IPPROTO_ROUTING
:
647 hbh
= (struct ip6_hbh
*)bp
;
648 if (!TTEST(hbh
->ip6h_len
))
651 hlen
= (hbh
->ip6h_len
+ 1) << 3;
654 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
655 fragh
= (struct ip6_frag
*)bp
;
656 if (!TTEST(fragh
->ip6f_offlg
))
658 /* fragments with non-zero offset are meaningless */
659 if ((EXTRACT_16BITS(&fragh
->ip6f_offlg
) & IP6F_OFF_MASK
) != 0)
661 nh
= fragh
->ip6f_nxt
;
662 hlen
= sizeof(struct ip6_frag
);
666 ah
= (struct ah
*)bp
;
667 if (!TTEST(ah
->ah_len
))
670 hlen
= (ah
->ah_len
+ 2) << 2;
673 default: /* unknown or undecodable header */
674 *prot
= nh
; /* meaningless, but set here anyway */
679 return(NULL
); /* should be notreached, though */
683 icmp6_opt_print(const u_char
*bp
, int resid
)
685 const struct nd_opt_hdr
*op
;
686 const struct nd_opt_hdr
*opl
; /* why there's no struct? */
687 const struct nd_opt_prefix_info
*opp
;
688 const struct icmp6_opts_redirect
*opr
;
689 const struct nd_opt_mtu
*opm
;
690 const struct nd_opt_rdnss
*oprd
;
691 const struct nd_opt_advinterval
*opa
;
692 const struct nd_opt_homeagent_info
*oph
;
693 const struct nd_opt_route_info
*opri
;
694 const u_char
*cp
, *ep
;
695 struct in6_addr in6
, *in6p
;
699 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
702 /* 'ep' points to the end of available data. */
706 op
= (struct nd_opt_hdr
*)cp
;
708 ECHECK(op
->nd_opt_len
);
711 if (op
->nd_opt_len
== 0)
713 if (cp
+ (op
->nd_opt_len
<< 3) > ep
)
716 printf("\n\t %s option (%u), length %u (%u): ",
717 tok2str(icmp6_opt_values
, "unknown", op
->nd_opt_type
),
722 switch (op
->nd_opt_type
) {
723 case ND_OPT_SOURCE_LINKADDR
:
724 opl
= (struct nd_opt_hdr
*)op
;
725 l
= (op
->nd_opt_len
<< 3) - 2;
726 print_lladdr(cp
+ 2, l
);
728 case ND_OPT_TARGET_LINKADDR
:
729 opl
= (struct nd_opt_hdr
*)op
;
730 l
= (op
->nd_opt_len
<< 3) - 2;
731 print_lladdr(cp
+ 2, l
);
733 case ND_OPT_PREFIX_INFORMATION
:
734 opp
= (struct nd_opt_prefix_info
*)op
;
735 TCHECK(opp
->nd_opt_pi_prefix
);
736 printf("%s/%u%s, Flags [%s], valid time %ss",
737 ip6addr_string(&opp
->nd_opt_pi_prefix
),
738 opp
->nd_opt_pi_prefix_len
,
739 (op
->nd_opt_len
!= 4) ? "badlen" : "",
740 bittok2str(icmp6_opt_pi_flag_values
, "none", opp
->nd_opt_pi_flags_reserved
),
741 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_valid_time
)));
742 printf(", pref. time %ss", get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_preferred_time
)));
744 case ND_OPT_REDIRECTED_HEADER
:
745 opr
= (struct icmp6_opts_redirect
*)op
;
746 print_unknown_data(bp
,"\n\t ",op
->nd_opt_len
<<3);
750 opm
= (struct nd_opt_mtu
*)op
;
751 TCHECK(opm
->nd_opt_mtu_mtu
);
753 EXTRACT_32BITS(&opm
->nd_opt_mtu_mtu
),
754 (op
->nd_opt_len
!= 1) ? "bad option length" : "" );
757 oprd
= (struct nd_opt_rdnss
*)op
;
758 l
= (op
->nd_opt_len
- 1) / 2;
759 printf(" lifetime %us,",
760 EXTRACT_32BITS(&oprd
->nd_opt_rdnss_lifetime
));
761 for (i
= 0; i
< l
; i
++) {
762 TCHECK(oprd
->nd_opt_rdnss_addr
[i
]);
764 ip6addr_string(&oprd
->nd_opt_rdnss_addr
[i
]));
767 case ND_OPT_ADVINTERVAL
:
768 opa
= (struct nd_opt_advinterval
*)op
;
769 TCHECK(opa
->nd_opt_adv_interval
);
770 printf(" %us", EXTRACT_32BITS(&opa
->nd_opt_adv_interval
));
772 case ND_OPT_HOMEAGENT_INFO
:
773 oph
= (struct nd_opt_homeagent_info
*)op
;
774 TCHECK(oph
->nd_opt_hai_lifetime
);
775 printf(" preference %u, lifetime %u",
776 EXTRACT_16BITS(&oph
->nd_opt_hai_preference
),
777 EXTRACT_16BITS(&oph
->nd_opt_hai_lifetime
));
779 case ND_OPT_ROUTE_INFO
:
780 opri
= (struct nd_opt_route_info
*)op
;
781 TCHECK(opri
->nd_opt_rti_lifetime
);
782 memset(&in6
, 0, sizeof(in6
));
783 in6p
= (struct in6_addr
*)(opri
+ 1);
784 switch (op
->nd_opt_len
) {
789 memcpy(&in6
, opri
+ 1, 8);
793 memcpy(&in6
, opri
+ 1, sizeof(in6
));
798 printf(" %s/%u", ip6addr_string(&in6
),
799 opri
->nd_opt_rti_prefixlen
);
800 printf(", pref=%s", get_rtpref(opri
->nd_opt_rti_flags
));
801 printf(", lifetime=%s",
802 get_lifetime(EXTRACT_32BITS(&opri
->nd_opt_rti_lifetime
)));
806 print_unknown_data(cp
+2,"\n\t ", (op
->nd_opt_len
<< 3) - 2); /* skip option header */
811 /* do we want to see an additional hexdump ? */
813 print_unknown_data(cp
+2,"\n\t ", (op
->nd_opt_len
<< 3) - 2); /* skip option header */
815 cp
+= op
->nd_opt_len
<< 3;
816 resid
-= op
->nd_opt_len
<< 3;
821 fputs("[ndp opt]", stdout
);
827 mld6_print(const u_char
*bp
)
829 struct mld6_hdr
*mp
= (struct mld6_hdr
*)bp
;
832 /* 'ep' points to the end of available data. */
835 if ((u_char
*)mp
+ sizeof(*mp
) > ep
)
838 printf("max resp delay: %d ", EXTRACT_16BITS(&mp
->mld6_maxdelay
));
839 printf("addr: %s", ip6addr_string(&mp
->mld6_addr
));
843 mldv2_report_print(const u_char
*bp
, u_int len
)
845 struct icmp6_hdr
*icp
= (struct icmp6_hdr
*) bp
;
846 u_int group
, nsrcs
, ngroups
;
849 /* Minimum len is 8 */
851 printf(" [invalid len %d]", len
);
855 TCHECK(icp
->icmp6_data16
[1]);
856 ngroups
= EXTRACT_16BITS(&icp
->icmp6_data16
[1]);
857 printf(", %d group record(s)", ngroups
);
859 /* Print the group records */
861 for (i
= 0; i
< ngroups
; i
++) {
862 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
863 if (len
< group
+ 20) {
864 printf(" [invalid number of groups]");
867 TCHECK2(bp
[group
+ 4], sizeof(struct in6_addr
));
868 printf(" [gaddr %s", ip6addr_string(&bp
[group
+ 4]));
869 printf(" %s", tok2str(mldv2report2str
, " [v2-report-#%d]",
871 nsrcs
= (bp
[group
+ 2] << 8) + bp
[group
+ 3];
872 /* Check the number of sources and print them */
873 if (len
< group
+ 20 + (nsrcs
* sizeof(struct in6_addr
))) {
874 printf(" [invalid number of sources %d]", nsrcs
);
878 printf(", %d source(s)", nsrcs
);
880 /* Print the sources */
882 for (j
= 0; j
< nsrcs
; j
++) {
883 TCHECK2(bp
[group
+ 20 + j
* sizeof(struct in6_addr
)],
884 sizeof(struct in6_addr
));
885 printf(" %s", ip6addr_string(&bp
[group
+ 20 + j
* sizeof(struct in6_addr
)]));
889 /* Next group record */
890 group
+= 20 + nsrcs
* sizeof(struct in6_addr
);
896 (void)printf("[|icmp6]");
901 mldv2_query_print(const u_char
*bp
, u_int len
)
903 struct icmp6_hdr
*icp
= (struct icmp6_hdr
*) bp
;
909 /* Minimum len is 28 */
911 printf(" [invalid len %d]", len
);
914 TCHECK(icp
->icmp6_data16
[0]);
915 mrc
= EXTRACT_16BITS(&icp
->icmp6_data16
[0]);
919 mrt
= ((mrc
& 0x0fff) | 0x1000) << (((mrc
& 0x7000) >> 12) + 3);
922 (void)printf(" [max resp delay=%d]", mrt
);
924 TCHECK2(bp
[8], sizeof(struct in6_addr
));
925 printf(" [gaddr %s", ip6addr_string(&bp
[8]));
933 printf(" robustness=%d", bp
[24] & 0x07);
938 qqi
= ((bp
[25] & 0x0f) | 0x10) << (((bp
[25] & 0x70) >> 4) + 3);
940 printf(" qqi=%d", qqi
);
944 nsrcs
= EXTRACT_16BITS(&bp
[26]);
946 if (len
< 28 + nsrcs
* sizeof(struct in6_addr
))
947 printf(" [invalid number of sources]");
948 else if (vflag
> 1) {
950 for (i
= 0; i
< nsrcs
; i
++) {
951 TCHECK2(bp
[28 + i
* sizeof(struct in6_addr
)],
952 sizeof(struct in6_addr
));
953 printf(" %s", ip6addr_string(&bp
[28 + i
* sizeof(struct in6_addr
)]));
957 printf(", %d source(s)", nsrcs
);
962 (void)printf("[|icmp6]");
967 dnsname_print(const u_char
*cp
, const u_char
*ep
)
971 /* DNS name decoding - no decompression */
980 while (i
-- && cp
< ep
) {
984 if (cp
+ 1 < ep
&& *cp
)
990 } else if (cp
+ 1 == ep
&& *cp
== '\0') {
1003 icmp6_nodeinfo_print(u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
1005 struct icmp6_nodeinfo
*ni6
;
1006 struct icmp6_hdr
*dp
;
1013 dp
= (struct icmp6_hdr
*)bp
;
1014 ni6
= (struct icmp6_nodeinfo
*)bp
;
1017 switch (ni6
->ni_type
) {
1018 case ICMP6_NI_QUERY
:
1019 if (siz
== sizeof(*dp
) + 4) {
1020 /* KAME who-are-you */
1021 printf(" who-are-you request");
1024 printf(" node information query");
1026 TCHECK2(*dp
, sizeof(*ni6
));
1027 ni6
= (struct icmp6_nodeinfo
*)dp
;
1029 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
1033 case NI_QTYPE_SUPTYPES
:
1034 printf("supported qtypes");
1035 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
1037 printf(" [%s]", (i
& 0x01) ? "C" : "");
1043 case NI_QTYPE_NODEADDR
:
1044 printf("node addresses");
1048 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
1049 printf(" [%s%s%s%s%s%s]",
1050 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1051 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1052 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1053 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1054 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1055 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "");
1062 if (ni6
->ni_qtype
== NI_QTYPE_NOOP
||
1063 ni6
->ni_qtype
== NI_QTYPE_SUPTYPES
) {
1064 if (siz
!= sizeof(*ni6
))
1066 printf(", invalid len");
1073 /* XXX backward compat, icmp-name-lookup-03 */
1074 if (siz
== sizeof(*ni6
)) {
1075 printf(", 03 draft");
1081 switch (ni6
->ni_code
) {
1082 case ICMP6_NI_SUBJ_IPV6
:
1084 sizeof(*ni6
) + sizeof(struct in6_addr
)))
1086 if (siz
!= sizeof(*ni6
) + sizeof(struct in6_addr
)) {
1088 printf(", invalid subject len");
1091 printf(", subject=%s",
1092 getname6((const u_char
*)(ni6
+ 1)));
1094 case ICMP6_NI_SUBJ_FQDN
:
1095 printf(", subject=DNS name");
1096 cp
= (const u_char
*)(ni6
+ 1);
1097 if (cp
[0] == ep
- cp
- 1) {
1098 /* icmp-name-lookup-03, pascal string */
1100 printf(", 03 draft");
1109 dnsname_print(cp
, ep
);
1111 case ICMP6_NI_SUBJ_IPV4
:
1112 if (!TTEST2(*dp
, sizeof(*ni6
) + sizeof(struct in_addr
)))
1114 if (siz
!= sizeof(*ni6
) + sizeof(struct in_addr
)) {
1116 printf(", invalid subject len");
1119 printf(", subject=%s",
1120 getname((const u_char
*)(ni6
+ 1)));
1123 printf(", unknown subject");
1131 case ICMP6_NI_REPLY
:
1132 if (icmp6len
> siz
) {
1133 printf("[|icmp6: node information reply]");
1139 ni6
= (struct icmp6_nodeinfo
*)dp
;
1140 printf(" node information reply");
1142 switch (ni6
->ni_code
) {
1143 case ICMP6_NI_SUCCESS
:
1149 case ICMP6_NI_REFUSED
:
1152 if (siz
!= sizeof(*ni6
))
1154 printf(", invalid length");
1156 case ICMP6_NI_UNKNOWN
:
1159 if (siz
!= sizeof(*ni6
))
1161 printf(", invalid length");
1165 if (ni6
->ni_code
!= ICMP6_NI_SUCCESS
) {
1171 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
1176 if (siz
!= sizeof(*ni6
))
1178 printf(", invalid length");
1180 case NI_QTYPE_SUPTYPES
:
1183 printf("supported qtypes");
1184 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
1186 printf(" [%s]", (i
& 0x01) ? "C" : "");
1192 cp
= (const u_char
*)(ni6
+ 1) + 4;
1193 if (cp
[0] == ep
- cp
- 1) {
1194 /* icmp-name-lookup-03, pascal string */
1196 printf(", 03 draft");
1205 dnsname_print(cp
, ep
);
1206 if ((EXTRACT_16BITS(&ni6
->ni_flags
) & 0x01) != 0)
1207 printf(" [TTL=%u]", *(u_int32_t
*)(ni6
+ 1));
1209 case NI_QTYPE_NODEADDR
:
1212 printf("node addresses");
1215 if (i
+ sizeof(struct in6_addr
) + sizeof(int32_t) > siz
)
1217 printf(" %s", getname6(bp
+ i
));
1218 i
+= sizeof(struct in6_addr
);
1219 printf("(%d)", (int32_t)EXTRACT_32BITS(bp
+ i
));
1220 i
+= sizeof(int32_t);
1225 printf(" [%s%s%s%s%s%s%s]",
1226 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1227 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1228 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1229 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1230 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1231 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
1232 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : "");
1248 fputs("[|icmp6]", stdout
);
1252 icmp6_rrenum_print(const u_char
*bp
, const u_char
*ep
)
1254 struct icmp6_router_renum
*rr6
;
1256 struct rr_pco_match
*match
;
1257 struct rr_pco_use
*use
;
1258 char hbuf
[NI_MAXHOST
];
1263 rr6
= (struct icmp6_router_renum
*)bp
;
1264 cp
= (const char *)(rr6
+ 1);
1266 TCHECK(rr6
->rr_reserved
);
1267 switch (rr6
->rr_code
) {
1268 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
1269 printf("router renum: command");
1271 case ICMP6_ROUTER_RENUMBERING_RESULT
:
1272 printf("router renum: result");
1274 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
1275 printf("router renum: sequence number reset");
1278 printf("router renum: code-#%d", rr6
->rr_code
);
1282 printf(", seq=%u", EXTRACT_32BITS(&rr6
->rr_seqnum
));
1285 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1287 if (rr6
->rr_flags
) {
1288 printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
1289 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
1290 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
1291 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
1292 F(ICMP6_RR_FLAGS_PREVDONE
, "P"));
1294 printf("seg=%u,", rr6
->rr_segnum
);
1295 printf("maxdelay=%u", EXTRACT_16BITS(&rr6
->rr_maxdelay
));
1296 if (rr6
->rr_reserved
)
1297 printf("rsvd=0x%x", EXTRACT_32BITS(&rr6
->rr_reserved
));
1303 if (rr6
->rr_code
== ICMP6_ROUTER_RENUMBERING_COMMAND
) {
1304 match
= (struct rr_pco_match
*)cp
;
1305 cp
= (const char *)(match
+ 1);
1307 TCHECK(match
->rpm_prefix
);
1313 printf("match("); /*)*/
1314 switch (match
->rpm_code
) {
1315 case RPM_PCO_ADD
: printf("add"); break;
1316 case RPM_PCO_CHANGE
: printf("change"); break;
1317 case RPM_PCO_SETGLOBAL
: printf("setglobal"); break;
1318 default: printf("#%u", match
->rpm_code
); break;
1322 printf(",ord=%u", match
->rpm_ordinal
);
1323 printf(",min=%u", match
->rpm_minlen
);
1324 printf(",max=%u", match
->rpm_maxlen
);
1326 if (inet_ntop(AF_INET6
, &match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
1327 printf(",%s/%u", hbuf
, match
->rpm_matchlen
);
1329 printf(",?/%u", match
->rpm_matchlen
);
1333 n
= match
->rpm_len
- 3;
1338 use
= (struct rr_pco_use
*)cp
;
1339 cp
= (const char *)(use
+ 1);
1341 TCHECK(use
->rpu_prefix
);
1347 printf("use("); /*)*/
1348 if (use
->rpu_flags
) {
1349 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1351 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
1352 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P"));
1356 printf("mask=0x%x,", use
->rpu_ramask
);
1357 printf("raflags=0x%x,", use
->rpu_raflags
);
1358 if (~use
->rpu_vltime
== 0)
1359 printf("vltime=infty,");
1361 printf("vltime=%u,",
1362 EXTRACT_32BITS(&use
->rpu_vltime
));
1363 if (~use
->rpu_pltime
== 0)
1364 printf("pltime=infty,");
1366 printf("pltime=%u,",
1367 EXTRACT_32BITS(&use
->rpu_pltime
));
1369 if (inet_ntop(AF_INET6
, &use
->rpu_prefix
, hbuf
,
1371 printf("%s/%u/%u", hbuf
, use
->rpu_uselen
,
1374 printf("?/%u/%u", use
->rpu_uselen
,
1384 fputs("[|icmp6]", stdout
);