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 "netdissect.h"
39 #include "addrtoname.h"
48 /* NetBSD: icmp6.h,v 1.13 2000/08/03 16:30:37 itojun Exp */
49 /* $KAME: icmp6.h,v 1.22 2000/08/03 15:25:16 jinmei Exp $ */
52 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
53 * All rights reserved.
55 * Redistribution and use in source and binary forms, with or without
56 * modification, are permitted provided that the following conditions
58 * 1. Redistributions of source code must retain the above copyright
59 * notice, this list of conditions and the following disclaimer.
60 * 2. Redistributions in binary form must reproduce the above copyright
61 * notice, this list of conditions and the following disclaimer in the
62 * documentation and/or other materials provided with the distribution.
63 * 3. Neither the name of the project nor the names of its contributors
64 * may be used to endorse or promote products derived from this software
65 * without specific prior written permission.
67 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
68 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
70 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
71 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
72 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
73 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
74 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
75 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
76 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
81 u_int8_t icmp6_type
; /* type field */
82 u_int8_t icmp6_code
; /* code field */
83 u_int16_t icmp6_cksum
; /* checksum field */
85 u_int32_t icmp6_un_data32
[1]; /* type-specific field */
86 u_int16_t icmp6_un_data16
[2]; /* type-specific field */
87 u_int8_t icmp6_un_data8
[4]; /* type-specific field */
91 #define icmp6_data32 icmp6_dataun.icmp6_un_data32
92 #define icmp6_data16 icmp6_dataun.icmp6_un_data16
93 #define icmp6_data8 icmp6_dataun.icmp6_un_data8
94 #define icmp6_pptr icmp6_data32[0] /* parameter prob */
95 #define icmp6_mtu icmp6_data32[0] /* packet too big */
96 #define icmp6_id icmp6_data16[0] /* echo request/reply */
97 #define icmp6_seq icmp6_data16[1] /* echo request/reply */
98 #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
100 #define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */
101 #define ICMP6_PACKET_TOO_BIG 2 /* packet too big */
102 #define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */
103 #define ICMP6_PARAM_PROB 4 /* ip6 header bad */
105 #define ICMP6_ECHO_REQUEST 128 /* echo service */
106 #define ICMP6_ECHO_REPLY 129 /* echo reply */
107 #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */
108 #define MLD6_LISTENER_QUERY 130 /* multicast listener query */
109 #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */
110 #define MLD6_LISTENER_REPORT 131 /* multicast listener report */
111 #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */
112 #define MLD6_LISTENER_DONE 132 /* multicast listener done */
114 #define ND_ROUTER_SOLICIT 133 /* router solicitation */
115 #define ND_ROUTER_ADVERT 134 /* router advertisement */
116 #define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */
117 #define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisement */
118 #define ND_REDIRECT 137 /* redirect */
120 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
122 #define ICMP6_WRUREQUEST 139 /* who are you request */
123 #define ICMP6_WRUREPLY 140 /* who are you reply */
124 #define ICMP6_FQDN_QUERY 139 /* FQDN query */
125 #define ICMP6_FQDN_REPLY 140 /* FQDN reply */
126 #define ICMP6_NI_QUERY 139 /* node information request */
127 #define ICMP6_NI_REPLY 140 /* node information reply */
128 #define IND_SOLICIT 141 /* inverse neighbor solicitation */
129 #define IND_ADVERT 142 /* inverse neighbor advertisement */
131 #define ICMP6_V2_MEMBERSHIP_REPORT 143 /* v2 membership report */
132 #define MLDV2_LISTENER_REPORT 143 /* v2 multicast listener report */
133 #define ICMP6_HADISCOV_REQUEST 144
134 #define ICMP6_HADISCOV_REPLY 145
135 #define ICMP6_MOBILEPREFIX_SOLICIT 146
136 #define ICMP6_MOBILEPREFIX_ADVERT 147
138 #define MLD6_MTRACE_RESP 200 /* mtrace response(to sender) */
139 #define MLD6_MTRACE 201 /* mtrace messages */
141 #define ICMP6_MAXTYPE 201
143 #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
144 #define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */
145 #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */
146 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
147 #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
148 #define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */
150 #define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */
151 #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */
153 #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
154 #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */
155 #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */
157 #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
159 #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
160 #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
161 #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
163 #define ICMP6_NI_SUCCESS 0 /* node information successful reply */
164 #define ICMP6_NI_REFUSED 1 /* node information request is refused */
165 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
167 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
168 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
169 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */
171 /* Used in kernel only */
172 #define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */
173 #define ND_REDIRECT_ROUTER 1 /* redirect to a better router */
176 * Multicast Listener Discovery
179 struct icmp6_hdr mld6_hdr
;
180 struct in6_addr mld6_addr
; /* multicast address */
183 #define mld6_type mld6_hdr.icmp6_type
184 #define mld6_code mld6_hdr.icmp6_code
185 #define mld6_cksum mld6_hdr.icmp6_cksum
186 #define mld6_maxdelay mld6_hdr.icmp6_data16[0]
187 #define mld6_reserved mld6_hdr.icmp6_data16[1]
189 #define MLD_MINLEN 24
190 #define MLDV2_MINLEN 28
196 struct nd_router_solicit
{ /* router solicitation */
197 struct icmp6_hdr nd_rs_hdr
;
198 /* could be followed by options */
201 #define nd_rs_type nd_rs_hdr.icmp6_type
202 #define nd_rs_code nd_rs_hdr.icmp6_code
203 #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
204 #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
206 struct nd_router_advert
{ /* router advertisement */
207 struct icmp6_hdr nd_ra_hdr
;
208 u_int32_t nd_ra_reachable
; /* reachable time */
209 u_int32_t nd_ra_retransmit
; /* retransmit timer */
210 /* could be followed by options */
213 #define nd_ra_type nd_ra_hdr.icmp6_type
214 #define nd_ra_code nd_ra_hdr.icmp6_code
215 #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
216 #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
217 #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
218 #define ND_RA_FLAG_MANAGED 0x80
219 #define ND_RA_FLAG_OTHER 0x40
220 #define ND_RA_FLAG_HOME_AGENT 0x20
223 * Router preference values based on draft-draves-ipngwg-router-selection-01.
224 * These are non-standard definitions.
226 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
228 #define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */
229 #define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */
230 #define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */
231 #define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */
233 #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
235 struct nd_neighbor_solicit
{ /* neighbor solicitation */
236 struct icmp6_hdr nd_ns_hdr
;
237 struct in6_addr nd_ns_target
; /*target address */
238 /* could be followed by options */
241 #define nd_ns_type nd_ns_hdr.icmp6_type
242 #define nd_ns_code nd_ns_hdr.icmp6_code
243 #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
244 #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
246 struct nd_neighbor_advert
{ /* neighbor advertisement */
247 struct icmp6_hdr nd_na_hdr
;
248 struct in6_addr nd_na_target
; /* target address */
249 /* could be followed by options */
252 #define nd_na_type nd_na_hdr.icmp6_type
253 #define nd_na_code nd_na_hdr.icmp6_code
254 #define nd_na_cksum nd_na_hdr.icmp6_cksum
255 #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
257 #define ND_NA_FLAG_ROUTER 0x80000000
258 #define ND_NA_FLAG_SOLICITED 0x40000000
259 #define ND_NA_FLAG_OVERRIDE 0x20000000
261 struct nd_redirect
{ /* redirect */
262 struct icmp6_hdr nd_rd_hdr
;
263 struct in6_addr nd_rd_target
; /* target address */
264 struct in6_addr nd_rd_dst
; /* destination address */
265 /* could be followed by options */
268 #define nd_rd_type nd_rd_hdr.icmp6_type
269 #define nd_rd_code nd_rd_hdr.icmp6_code
270 #define nd_rd_cksum nd_rd_hdr.icmp6_cksum
271 #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
273 struct nd_opt_hdr
{ /* Neighbor discovery option header */
274 u_int8_t nd_opt_type
;
276 /* followed by option specific data*/
279 #define ND_OPT_SOURCE_LINKADDR 1
280 #define ND_OPT_TARGET_LINKADDR 2
281 #define ND_OPT_PREFIX_INFORMATION 3
282 #define ND_OPT_REDIRECTED_HEADER 4
284 #define ND_OPT_ADVINTERVAL 7
285 #define ND_OPT_HOMEAGENT_INFO 8
286 #define ND_OPT_ROUTE_INFO 24 /* RFC4191 */
287 #define ND_OPT_RDNSS 25
288 #define ND_OPT_DNSSL 31
290 struct nd_opt_prefix_info
{ /* prefix information */
291 u_int8_t nd_opt_pi_type
;
292 u_int8_t nd_opt_pi_len
;
293 u_int8_t nd_opt_pi_prefix_len
;
294 u_int8_t nd_opt_pi_flags_reserved
;
295 u_int8_t nd_opt_pi_valid_time
[4];
296 u_int8_t nd_opt_pi_preferred_time
[4];
297 u_int8_t nd_opt_pi_reserved2
[4];
298 struct in6_addr nd_opt_pi_prefix
;
301 #define ND_OPT_PI_FLAG_ONLINK 0x80
302 #define ND_OPT_PI_FLAG_AUTO 0x40
303 #define ND_OPT_PI_FLAG_ROUTER 0x20 /*2292bis*/
305 struct nd_opt_rd_hdr
{ /* redirected header */
306 u_int8_t nd_opt_rh_type
;
307 u_int8_t nd_opt_rh_len
;
308 u_int16_t nd_opt_rh_reserved1
;
309 u_int32_t nd_opt_rh_reserved2
;
310 /* followed by IP header and data */
313 struct nd_opt_mtu
{ /* MTU option */
314 u_int8_t nd_opt_mtu_type
;
315 u_int8_t nd_opt_mtu_len
;
316 u_int16_t nd_opt_mtu_reserved
;
317 u_int32_t nd_opt_mtu_mtu
;
320 struct nd_opt_rdnss
{ /* RDNSS RFC 6106 5.1 */
321 u_int8_t nd_opt_rdnss_type
;
322 u_int8_t nd_opt_rdnss_len
;
323 u_int16_t nd_opt_rdnss_reserved
;
324 u_int32_t nd_opt_rdnss_lifetime
;
325 struct in6_addr nd_opt_rdnss_addr
[1]; /* variable-length */
328 struct nd_opt_dnssl
{ /* DNSSL RFC 6106 5.2 */
329 u_int8_t nd_opt_dnssl_type
;
330 u_int8_t nd_opt_dnssl_len
;
331 u_int16_t nd_opt_dnssl_reserved
;
332 u_int32_t nd_opt_dnssl_lifetime
;
333 /* followed by list of DNS search domains, variable-length */
336 struct nd_opt_advinterval
{ /* Advertisement interval option */
337 u_int8_t nd_opt_adv_type
;
338 u_int8_t nd_opt_adv_len
;
339 u_int16_t nd_opt_adv_reserved
;
340 u_int32_t nd_opt_adv_interval
;
343 struct nd_opt_homeagent_info
{ /* Home Agent info */
344 u_int8_t nd_opt_hai_type
;
345 u_int8_t nd_opt_hai_len
;
346 u_int16_t nd_opt_hai_reserved
;
347 int16_t nd_opt_hai_preference
;
348 u_int16_t nd_opt_hai_lifetime
;
351 struct nd_opt_route_info
{ /* route info */
352 u_int8_t nd_opt_rti_type
;
353 u_int8_t nd_opt_rti_len
;
354 u_int8_t nd_opt_rti_prefixlen
;
355 u_int8_t nd_opt_rti_flags
;
356 u_int32_t nd_opt_rti_lifetime
;
364 struct icmp6_namelookup
{
365 struct icmp6_hdr icmp6_nl_hdr
;
366 u_int8_t icmp6_nl_nonce
[8];
367 int32_t icmp6_nl_ttl
;
369 u_int8_t icmp6_nl_len
;
370 u_int8_t icmp6_nl_name
[3];
372 /* could be followed by options */
376 * icmp6 node information
378 struct icmp6_nodeinfo
{
379 struct icmp6_hdr icmp6_ni_hdr
;
380 u_int8_t icmp6_ni_nonce
[8];
381 /* could be followed by reply data */
384 #define ni_type icmp6_ni_hdr.icmp6_type
385 #define ni_code icmp6_ni_hdr.icmp6_code
386 #define ni_cksum icmp6_ni_hdr.icmp6_cksum
387 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
388 #define ni_flags icmp6_ni_hdr.icmp6_data16[1]
390 #define NI_QTYPE_NOOP 0 /* NOOP */
391 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */
392 #define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */
393 #define NI_QTYPE_DNSNAME 2 /* DNS Name */
394 #define NI_QTYPE_NODEADDR 3 /* Node Addresses */
395 #define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */
398 #define NI_SUPTYPE_FLAG_COMPRESS ((u_int16_t)htons(0x1))
399 #define NI_FQDN_FLAG_VALIDTTL ((u_int16_t)htons(0x1))
402 #define NI_NODEADDR_FLAG_TRUNCATE ((u_int16_t)htons(0x1))
403 #define NI_NODEADDR_FLAG_ALL ((u_int16_t)htons(0x2))
404 #define NI_NODEADDR_FLAG_COMPAT ((u_int16_t)htons(0x4))
405 #define NI_NODEADDR_FLAG_LINKLOCAL ((u_int16_t)htons(0x8))
406 #define NI_NODEADDR_FLAG_SITELOCAL ((u_int16_t)htons(0x10))
407 #define NI_NODEADDR_FLAG_GLOBAL ((u_int16_t)htons(0x20))
408 #define NI_NODEADDR_FLAG_ANYCAST ((u_int16_t)htons(0x40)) /* just experimental. not in spec */
410 struct ni_reply_fqdn
{
411 u_int32_t ni_fqdn_ttl
; /* TTL */
412 u_int8_t ni_fqdn_namelen
; /* length in octets of the FQDN */
413 u_int8_t ni_fqdn_name
[3]; /* XXX: alignment */
417 * Router Renumbering. as router-renum-08.txt
419 struct icmp6_router_renum
{ /* router renumbering header */
420 struct icmp6_hdr rr_hdr
;
423 u_int16_t rr_maxdelay
;
424 u_int32_t rr_reserved
;
426 #define ICMP6_RR_FLAGS_TEST 0x80
427 #define ICMP6_RR_FLAGS_REQRESULT 0x40
428 #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
429 #define ICMP6_RR_FLAGS_SPECSITE 0x10
430 #define ICMP6_RR_FLAGS_PREVDONE 0x08
432 #define rr_type rr_hdr.icmp6_type
433 #define rr_code rr_hdr.icmp6_code
434 #define rr_cksum rr_hdr.icmp6_cksum
435 #define rr_seqnum rr_hdr.icmp6_data32[0]
437 struct rr_pco_match
{ /* match prefix part */
440 u_int8_t rpm_ordinal
;
441 u_int8_t rpm_matchlen
;
444 u_int16_t rpm_reserved
;
445 struct in6_addr rpm_prefix
;
448 #define RPM_PCO_ADD 1
449 #define RPM_PCO_CHANGE 2
450 #define RPM_PCO_SETGLOBAL 3
451 #define RPM_PCO_MAX 4
453 struct rr_pco_use
{ /* use prefix part */
455 u_int8_t rpu_keeplen
;
457 u_int8_t rpu_raflags
;
458 u_int32_t rpu_vltime
;
459 u_int32_t rpu_pltime
;
461 struct in6_addr rpu_prefix
;
463 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80
464 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40
467 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME ((u_int32_t)htonl(0x80000000))
468 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME ((u_int32_t)htonl(0x40000000))
470 struct rr_result
{ /* router renumbering result message */
472 u_int8_t rrr_ordinal
;
473 u_int8_t rrr_matchedlen
;
475 struct in6_addr rrr_prefix
;
478 #define ICMP6_RR_RESULT_FLAGS_OOB ((u_int16_t)htons(0x0002))
479 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN ((u_int16_t)htons(0x0001))
481 static const char *get_rtpref(u_int
);
482 static const char *get_lifetime(u_int32_t
);
483 static void print_lladdr(netdissect_options
*ndo
, const u_char
*, size_t);
484 static void icmp6_opt_print(netdissect_options
*ndo
, const u_char
*, int);
485 static void mld6_print(netdissect_options
*ndo
, const u_char
*);
486 static void mldv2_report_print(netdissect_options
*ndo
, const u_char
*, u_int
);
487 static void mldv2_query_print(netdissect_options
*ndo
, const u_char
*, u_int
);
488 static struct udphdr
*get_upperlayer(netdissect_options
*ndo
, u_char
*, u_int
*);
489 static void dnsname_print(netdissect_options
*ndo
, const u_char
*, const u_char
*);
490 static void icmp6_nodeinfo_print(netdissect_options
*ndo
, u_int
, const u_char
*, const u_char
*);
491 static void icmp6_rrenum_print(netdissect_options
*ndo
, const u_char
*, const u_char
*);
494 #define abs(a) ((0 < (a)) ? (a) : -(a))
497 /* inline the various RPL definitions */
498 #define ND_RPL_MESSAGE 0x9B
500 static const struct tok icmp6_type_values
[] = {
501 { ICMP6_DST_UNREACH
, "destination unreachable"},
502 { ICMP6_PACKET_TOO_BIG
, "packet too big"},
503 { ICMP6_TIME_EXCEEDED
, "time exceeded in-transit"},
504 { ICMP6_PARAM_PROB
, "parameter problem"},
505 { ICMP6_ECHO_REQUEST
, "echo request"},
506 { ICMP6_ECHO_REPLY
, "echo reply"},
507 { MLD6_LISTENER_QUERY
, "multicast listener query"},
508 { MLD6_LISTENER_REPORT
, "multicast listener report"},
509 { MLD6_LISTENER_DONE
, "multicast listener done"},
510 { ND_ROUTER_SOLICIT
, "router solicitation"},
511 { ND_ROUTER_ADVERT
, "router advertisement"},
512 { ND_NEIGHBOR_SOLICIT
, "neighbor solicitation"},
513 { ND_NEIGHBOR_ADVERT
, "neighbor advertisement"},
514 { ND_REDIRECT
, "redirect"},
515 { ICMP6_ROUTER_RENUMBERING
, "router renumbering"},
516 { IND_SOLICIT
, "inverse neighbor solicitation"},
517 { IND_ADVERT
, "inverse neighbor advertisement"},
518 { MLDV2_LISTENER_REPORT
, "multicast listener report v2"},
519 { ICMP6_HADISCOV_REQUEST
, "ha discovery request"},
520 { ICMP6_HADISCOV_REPLY
, "ha discovery reply"},
521 { ICMP6_MOBILEPREFIX_SOLICIT
, "mobile router solicitation"},
522 { ICMP6_MOBILEPREFIX_ADVERT
, "mobile router advertisement"},
523 { ICMP6_WRUREQUEST
, "who-are-you request"},
524 { ICMP6_WRUREPLY
, "who-are-you reply"},
525 { ICMP6_NI_QUERY
, "node information query"},
526 { ICMP6_NI_REPLY
, "node information reply"},
527 { MLD6_MTRACE
, "mtrace message"},
528 { MLD6_MTRACE_RESP
, "mtrace response"},
529 { ND_RPL_MESSAGE
, "RPL"},
533 static const struct tok icmp6_dst_unreach_code_values
[] = {
534 { ICMP6_DST_UNREACH_NOROUTE
, "unreachable route" },
535 { ICMP6_DST_UNREACH_ADMIN
, " unreachable prohibited"},
536 { ICMP6_DST_UNREACH_BEYONDSCOPE
, "beyond scope"},
537 { ICMP6_DST_UNREACH_ADDR
, "unreachable address"},
538 { ICMP6_DST_UNREACH_NOPORT
, "unreachable port"},
542 static const struct tok icmp6_opt_pi_flag_values
[] = {
543 { ND_OPT_PI_FLAG_ONLINK
, "onlink" },
544 { ND_OPT_PI_FLAG_AUTO
, "auto" },
545 { ND_OPT_PI_FLAG_ROUTER
, "router" },
549 static const struct tok icmp6_opt_ra_flag_values
[] = {
550 { ND_RA_FLAG_MANAGED
, "managed" },
551 { ND_RA_FLAG_OTHER
, "other stateful"},
552 { ND_RA_FLAG_HOME_AGENT
, "home agent"},
556 static const struct tok icmp6_nd_na_flag_values
[] = {
557 { ND_NA_FLAG_ROUTER
, "router" },
558 { ND_NA_FLAG_SOLICITED
, "solicited" },
559 { ND_NA_FLAG_OVERRIDE
, "override" },
564 static const struct tok icmp6_opt_values
[] = {
565 { ND_OPT_SOURCE_LINKADDR
, "source link-address"},
566 { ND_OPT_TARGET_LINKADDR
, "destination link-address"},
567 { ND_OPT_PREFIX_INFORMATION
, "prefix info"},
568 { ND_OPT_REDIRECTED_HEADER
, "redirected header"},
569 { ND_OPT_MTU
, "mtu"},
570 { ND_OPT_RDNSS
, "rdnss"},
571 { ND_OPT_DNSSL
, "dnssl"},
572 { ND_OPT_ADVINTERVAL
, "advertisement interval"},
573 { ND_OPT_HOMEAGENT_INFO
, "homeagent information"},
574 { ND_OPT_ROUTE_INFO
, "route info"},
578 /* mldv2 report types */
579 static const struct tok mldv2report2str
[] = {
592 static const char *rtpref_str
[] = {
599 return rtpref_str
[((v
& ND_RA_FLAG_RTPREF_MASK
) >> 3) & 0xff];
603 get_lifetime(u_int32_t v
)
607 if (v
== (u_int32_t
)~0UL)
610 snprintf(buf
, sizeof(buf
), "%us", v
);
616 print_lladdr(netdissect_options
*ndo
, const u_int8_t
*p
, size_t l
)
618 const u_int8_t
*ep
, *q
;
622 while (l
> 0 && q
< ep
) {
625 ND_PRINT((ndo
,"%02x", *q
++));
630 static int icmp6_cksum(const struct ip6_hdr
*ip6
, const struct icmp6_hdr
*icp
,
633 return (nextproto6_cksum(ip6
, (const u_int8_t
*)(void *)icp
, len
,
645 ND_RPL_SDAO_ACK
=0x83,
649 enum ND_RPL_DIO_FLAGS
{
650 ND_RPL_DIO_GROUNDED
= 0x80,
651 ND_RPL_DIO_DATRIG
= 0x40,
652 ND_RPL_DIO_DASUPPORT
= 0x20,
653 ND_RPL_DIO_RES4
= 0x10,
654 ND_RPL_DIO_RES3
= 0x08,
655 ND_RPL_DIO_PRF_MASK
= 0x07, /* 3-bit preference */
661 u_int8_t rpl_instanceid
;
662 u_int8_t rpl_dagrank
;
663 u_int8_t rpl_dagid
[16];
667 rpl_print(netdissect_options
*ndo
,
668 const struct icmp6_hdr
*hdr
,
669 const u_char
*bp
, u_int length _U_
)
671 struct nd_rpl_dio
*dio
= (struct nd_rpl_dio
*)bp
;
672 int secured
= hdr
->icmp6_code
& 0x80;
673 int basecode
= hdr
->icmp6_code
& 0x7f;
675 ND_TCHECK(dio
->rpl_dagid
);
678 ND_PRINT((ndo
, ", (SEC)"));
680 ND_PRINT((ndo
, ", (CLR)"));
685 ND_PRINT((ndo
, "DODAG Information Solicitation"));
690 ND_PRINT((ndo
, "DODAG Information Object"));
696 if(isprint(dio
->rpl_dagid
[i
])) {
697 *d
++ = dio
->rpl_dagid
[i
];
699 int cnt
=snprintf(d
,4,"0x%02x",
705 ND_PRINT((ndo
, " [seq:%u,instance:%u,rank:%u,dagid:%s]",
713 ND_PRINT((ndo
, "Destination Advertisement Object"));
718 ND_PRINT((ndo
, "Destination Advertisement Object Ack"));
723 ND_PRINT((ndo
, "RPL message, unknown code %u",hdr
->icmp6_code
));
728 ND_PRINT((ndo
," [|truncated]"));
735 icmp6_print(netdissect_options
*ndo
,
736 const u_char
*bp
, u_int length
, const u_char
*bp2
, int fragmented
)
738 const struct icmp6_hdr
*dp
;
739 const struct ip6_hdr
*ip
;
740 const struct ip6_hdr
*oip
;
741 const struct udphdr
*ouh
;
746 dp
= (struct icmp6_hdr
*)bp
;
747 ip
= (struct ip6_hdr
*)bp2
;
748 oip
= (struct ip6_hdr
*)(dp
+ 1);
749 /* 'ep' points to the end of available data. */
750 ep
= ndo
->ndo_snapend
;
752 ND_TCHECK(dp
->icmp6_cksum
);
754 if (ndo
->ndo_vflag
&& !fragmented
) {
755 u_int16_t sum
, udp_sum
;
757 if (ND_TTEST2(bp
[0], length
)) {
758 udp_sum
= EXTRACT_16BITS(&dp
->icmp6_cksum
);
759 sum
= icmp6_cksum(ip
, dp
, length
);
761 (void)ND_PRINT((ndo
,"[bad icmp6 cksum 0x%04x -> 0x%04x!] ",
763 in_cksum_shouldbe(udp_sum
, sum
)));
765 (void)ND_PRINT((ndo
,"[icmp6 sum ok] "));
769 ND_PRINT((ndo
,"ICMP6, %s", tok2str(icmp6_type_values
,"unknown icmp6 type (%u)",dp
->icmp6_type
)));
771 /* display cosmetics: print the packet length for printer that use the vflag now */
772 if (ndo
->ndo_vflag
&& (dp
->icmp6_type
== ND_ROUTER_SOLICIT
||
773 dp
->icmp6_type
== ND_ROUTER_ADVERT
||
774 dp
->icmp6_type
== ND_NEIGHBOR_ADVERT
||
775 dp
->icmp6_type
== ND_NEIGHBOR_SOLICIT
||
776 dp
->icmp6_type
== ND_REDIRECT
||
777 dp
->icmp6_type
== ICMP6_HADISCOV_REPLY
||
778 dp
->icmp6_type
== ICMP6_MOBILEPREFIX_ADVERT
))
779 ND_PRINT((ndo
,", length %u", length
));
781 switch (dp
->icmp6_type
) {
782 case ICMP6_DST_UNREACH
:
783 ND_TCHECK(oip
->ip6_dst
);
784 ND_PRINT((ndo
,", %s", tok2str(icmp6_dst_unreach_code_values
,"unknown unreach code (%u)",dp
->icmp6_code
)));
785 switch (dp
->icmp6_code
) {
787 case ICMP6_DST_UNREACH_NOROUTE
: /* fall through */
788 case ICMP6_DST_UNREACH_ADMIN
:
789 case ICMP6_DST_UNREACH_ADDR
:
790 ND_PRINT((ndo
," %s",ip6addr_string(&oip
->ip6_dst
)));
792 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
793 ND_PRINT((ndo
," %s, source address %s",
794 ip6addr_string(&oip
->ip6_dst
),
795 ip6addr_string(&oip
->ip6_src
)));
797 case ICMP6_DST_UNREACH_NOPORT
:
798 if ((ouh
= get_upperlayer(ndo
, (u_char
*)oip
, &prot
))
802 dport
= EXTRACT_16BITS(&ouh
->uh_dport
);
805 ND_PRINT((ndo
,", %s tcp port %s",
806 ip6addr_string(&oip
->ip6_dst
),
807 tcpport_string(dport
)));
810 ND_PRINT((ndo
,", %s udp port %s",
811 ip6addr_string(&oip
->ip6_dst
),
812 udpport_string(dport
)));
815 ND_PRINT((ndo
,", %s protocol %d port %d unreachable",
816 ip6addr_string(&oip
->ip6_dst
),
817 oip
->ip6_nxt
, dport
));
822 if (ndo
->ndo_vflag
<= 1) {
823 print_unknown_data(ndo
, bp
,"\n\t",length
);
829 case ICMP6_PACKET_TOO_BIG
:
830 ND_TCHECK(dp
->icmp6_mtu
);
831 ND_PRINT((ndo
,", mtu %u", EXTRACT_32BITS(&dp
->icmp6_mtu
)));
833 case ICMP6_TIME_EXCEEDED
:
834 ND_TCHECK(oip
->ip6_dst
);
835 switch (dp
->icmp6_code
) {
836 case ICMP6_TIME_EXCEED_TRANSIT
:
837 ND_PRINT((ndo
," for %s",
838 ip6addr_string(&oip
->ip6_dst
)));
840 case ICMP6_TIME_EXCEED_REASSEMBLY
:
841 ND_PRINT((ndo
," (reassembly)"));
844 ND_PRINT((ndo
,", unknown code (%u)", dp
->icmp6_code
));
848 case ICMP6_PARAM_PROB
:
849 ND_TCHECK(oip
->ip6_dst
);
850 switch (dp
->icmp6_code
) {
851 case ICMP6_PARAMPROB_HEADER
:
852 ND_PRINT((ndo
,", erroneous - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
)));
854 case ICMP6_PARAMPROB_NEXTHEADER
:
855 ND_PRINT((ndo
,", next header - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
)));
857 case ICMP6_PARAMPROB_OPTION
:
858 ND_PRINT((ndo
,", option - octet %u", EXTRACT_32BITS(&dp
->icmp6_pptr
)));
861 ND_PRINT((ndo
,", code-#%d",
866 case ICMP6_ECHO_REQUEST
:
867 case ICMP6_ECHO_REPLY
:
868 ND_TCHECK(dp
->icmp6_seq
);
869 ND_PRINT((ndo
,", seq %u", EXTRACT_16BITS(&dp
->icmp6_seq
)));
871 case ICMP6_MEMBERSHIP_QUERY
:
872 if (length
== MLD_MINLEN
) {
873 mld6_print(ndo
, (const u_char
*)dp
);
874 } else if (length
>= MLDV2_MINLEN
) {
875 ND_PRINT((ndo
," v2"));
876 mldv2_query_print(ndo
, (const u_char
*)dp
, length
);
878 ND_PRINT((ndo
," unknown-version (len %u) ", length
));
881 case ICMP6_MEMBERSHIP_REPORT
:
882 mld6_print(ndo
, (const u_char
*)dp
);
884 case ICMP6_MEMBERSHIP_REDUCTION
:
885 mld6_print(ndo
, (const u_char
*)dp
);
887 case ND_ROUTER_SOLICIT
:
889 if (ndo
->ndo_vflag
) {
890 icmp6_opt_print(ndo
, (const u_char
*)dp
+ RTSOLLEN
,
894 case ND_ROUTER_ADVERT
:
896 if (ndo
->ndo_vflag
) {
897 struct nd_router_advert
*p
;
899 p
= (struct nd_router_advert
*)dp
;
900 ND_TCHECK(p
->nd_ra_retransmit
);
901 ND_PRINT((ndo
,"\n\thop limit %u, Flags [%s]" \
902 ", pref %s, router lifetime %us, reachable time %us, retrans time %us",
903 (u_int
)p
->nd_ra_curhoplimit
,
904 bittok2str(icmp6_opt_ra_flag_values
,"none",(p
->nd_ra_flags_reserved
)),
905 get_rtpref(p
->nd_ra_flags_reserved
),
906 EXTRACT_16BITS(&p
->nd_ra_router_lifetime
),
907 EXTRACT_32BITS(&p
->nd_ra_reachable
),
908 EXTRACT_32BITS(&p
->nd_ra_retransmit
)));
910 icmp6_opt_print(ndo
, (const u_char
*)dp
+ RTADVLEN
,
914 case ND_NEIGHBOR_SOLICIT
:
916 struct nd_neighbor_solicit
*p
;
917 p
= (struct nd_neighbor_solicit
*)dp
;
918 ND_TCHECK(p
->nd_ns_target
);
919 ND_PRINT((ndo
,", who has %s", ip6addr_string(&p
->nd_ns_target
)));
920 if (ndo
->ndo_vflag
) {
922 icmp6_opt_print(ndo
, (const u_char
*)dp
+ NDSOLLEN
,
927 case ND_NEIGHBOR_ADVERT
:
929 struct nd_neighbor_advert
*p
;
931 p
= (struct nd_neighbor_advert
*)dp
;
932 ND_TCHECK(p
->nd_na_target
);
933 ND_PRINT((ndo
,", tgt is %s",
934 ip6addr_string(&p
->nd_na_target
)));
935 if (ndo
->ndo_vflag
) {
936 ND_PRINT((ndo
,", Flags [%s]",
937 bittok2str(icmp6_nd_na_flag_values
,
939 EXTRACT_32BITS(&p
->nd_na_flags_reserved
))));
941 icmp6_opt_print(ndo
, (const u_char
*)dp
+ NDADVLEN
,
948 #define RDR(i) ((struct nd_redirect *)(i))
949 ND_TCHECK(RDR(dp
)->nd_rd_dst
);
950 ND_PRINT((ndo
,", %s", getname6((const u_char
*)&RDR(dp
)->nd_rd_dst
)));
951 ND_TCHECK(RDR(dp
)->nd_rd_target
);
952 ND_PRINT((ndo
," to %s",
953 getname6((const u_char
*)&RDR(dp
)->nd_rd_target
)));
954 #define REDIRECTLEN 40
955 if (ndo
->ndo_vflag
) {
956 icmp6_opt_print(ndo
, (const u_char
*)dp
+ REDIRECTLEN
,
957 length
- REDIRECTLEN
);
962 case ICMP6_ROUTER_RENUMBERING
:
963 icmp6_rrenum_print(ndo
, bp
, ep
);
967 icmp6_nodeinfo_print(ndo
, length
, bp
, ep
);
972 case ICMP6_V2_MEMBERSHIP_REPORT
:
973 mldv2_report_print(ndo
, (const u_char
*) dp
, length
);
975 case ICMP6_MOBILEPREFIX_SOLICIT
: /* fall through */
976 case ICMP6_HADISCOV_REQUEST
:
977 ND_TCHECK(dp
->icmp6_data16
[0]);
978 ND_PRINT((ndo
,", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0])));
980 case ICMP6_HADISCOV_REPLY
:
981 if (ndo
->ndo_vflag
) {
982 struct in6_addr
*in6
;
985 ND_TCHECK(dp
->icmp6_data16
[0]);
986 ND_PRINT((ndo
,", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0])));
987 cp
= (u_char
*)dp
+ length
;
988 in6
= (struct in6_addr
*)(dp
+ 1);
989 for (; (u_char
*)in6
< cp
; in6
++) {
991 ND_PRINT((ndo
,", %s", ip6addr_string(in6
)));
995 case ICMP6_MOBILEPREFIX_ADVERT
:
996 if (ndo
->ndo_vflag
) {
997 ND_TCHECK(dp
->icmp6_data16
[0]);
998 ND_PRINT((ndo
,", id 0x%04x", EXTRACT_16BITS(&dp
->icmp6_data16
[0])));
999 if (dp
->icmp6_data16
[1] & 0xc0)
1000 ND_PRINT((ndo
," "));
1001 if (dp
->icmp6_data16
[1] & 0x80)
1002 ND_PRINT((ndo
,"M"));
1003 if (dp
->icmp6_data16
[1] & 0x40)
1004 ND_PRINT((ndo
,"O"));
1006 icmp6_opt_print(ndo
, (const u_char
*)dp
+ MPADVLEN
,
1010 case ND_RPL_MESSAGE
:
1011 rpl_print(ndo
, dp
, &dp
->icmp6_data8
[0], length
);
1014 ND_PRINT((ndo
,", length %u", length
));
1015 if (ndo
->ndo_vflag
<= 1)
1016 print_unknown_data(ndo
, bp
,"\n\t", length
);
1019 if (!ndo
->ndo_vflag
)
1020 ND_PRINT((ndo
,", length %u", length
));
1023 ND_PRINT((ndo
, "[|icmp6]"));
1026 static struct udphdr
*
1027 get_upperlayer(netdissect_options
*ndo
, u_char
*bp
, u_int
*prot
)
1030 struct ip6_hdr
*ip6
= (struct ip6_hdr
*)bp
;
1032 struct ip6_hbh
*hbh
;
1033 struct ip6_frag
*fragh
;
1038 /* 'ep' points to the end of available data. */
1039 ep
= ndo
->ndo_snapend
;
1041 if (!ND_TTEST(ip6
->ip6_nxt
))
1045 hlen
= sizeof(struct ip6_hdr
);
1053 uh
= (struct udphdr
*)bp
;
1054 if (ND_TTEST(uh
->uh_dport
)) {
1062 case IPPROTO_HOPOPTS
:
1063 case IPPROTO_DSTOPTS
:
1064 case IPPROTO_ROUTING
:
1065 hbh
= (struct ip6_hbh
*)bp
;
1066 if (!ND_TTEST(hbh
->ip6h_len
))
1069 hlen
= (hbh
->ip6h_len
+ 1) << 3;
1072 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
1073 fragh
= (struct ip6_frag
*)bp
;
1074 if (!ND_TTEST(fragh
->ip6f_offlg
))
1076 /* fragments with non-zero offset are meaningless */
1077 if ((EXTRACT_16BITS(&fragh
->ip6f_offlg
) & IP6F_OFF_MASK
) != 0)
1079 nh
= fragh
->ip6f_nxt
;
1080 hlen
= sizeof(struct ip6_frag
);
1084 ah
= (struct ah
*)bp
;
1085 if (!ND_TTEST(ah
->ah_len
))
1088 hlen
= (ah
->ah_len
+ 2) << 2;
1091 default: /* unknown or undecodable header */
1092 *prot
= nh
; /* meaningless, but set here anyway */
1097 return(NULL
); /* should be notreached, though */
1101 icmp6_opt_print(netdissect_options
*ndo
, const u_char
*bp
, int resid
)
1103 const struct nd_opt_hdr
*op
;
1104 const struct nd_opt_prefix_info
*opp
;
1105 const struct nd_opt_mtu
*opm
;
1106 const struct nd_opt_rdnss
*oprd
;
1107 const struct nd_opt_dnssl
*opds
;
1108 const struct nd_opt_advinterval
*opa
;
1109 const struct nd_opt_homeagent_info
*oph
;
1110 const struct nd_opt_route_info
*opri
;
1111 const u_char
*cp
, *ep
, *domp
;
1112 struct in6_addr in6
, *in6p
;
1116 #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return
1119 /* 'ep' points to the end of available data. */
1120 ep
= ndo
->ndo_snapend
;
1123 op
= (struct nd_opt_hdr
*)cp
;
1125 ECHECK(op
->nd_opt_len
);
1128 if (op
->nd_opt_len
== 0)
1130 if (cp
+ (op
->nd_opt_len
<< 3) > ep
)
1133 ND_PRINT((ndo
,"\n\t %s option (%u), length %u (%u): ",
1134 tok2str(icmp6_opt_values
, "unknown", op
->nd_opt_type
),
1136 op
->nd_opt_len
<< 3,
1139 switch (op
->nd_opt_type
) {
1140 case ND_OPT_SOURCE_LINKADDR
:
1141 l
= (op
->nd_opt_len
<< 3) - 2;
1142 print_lladdr(ndo
, cp
+ 2, l
);
1144 case ND_OPT_TARGET_LINKADDR
:
1145 l
= (op
->nd_opt_len
<< 3) - 2;
1146 print_lladdr(ndo
, cp
+ 2, l
);
1148 case ND_OPT_PREFIX_INFORMATION
:
1149 opp
= (struct nd_opt_prefix_info
*)op
;
1150 ND_TCHECK(opp
->nd_opt_pi_prefix
);
1151 ND_PRINT((ndo
,"%s/%u%s, Flags [%s], valid time %s",
1152 ip6addr_string(&opp
->nd_opt_pi_prefix
),
1153 opp
->nd_opt_pi_prefix_len
,
1154 (op
->nd_opt_len
!= 4) ? "badlen" : "",
1155 bittok2str(icmp6_opt_pi_flag_values
, "none", opp
->nd_opt_pi_flags_reserved
),
1156 get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_valid_time
))));
1157 ND_PRINT((ndo
,", pref. time %s", get_lifetime(EXTRACT_32BITS(&opp
->nd_opt_pi_preferred_time
))));
1159 case ND_OPT_REDIRECTED_HEADER
:
1160 print_unknown_data(ndo
, bp
,"\n\t ",op
->nd_opt_len
<<3);
1164 opm
= (struct nd_opt_mtu
*)op
;
1165 ND_TCHECK(opm
->nd_opt_mtu_mtu
);
1166 ND_PRINT((ndo
," %u%s",
1167 EXTRACT_32BITS(&opm
->nd_opt_mtu_mtu
),
1168 (op
->nd_opt_len
!= 1) ? "bad option length" : "" ));
1171 oprd
= (struct nd_opt_rdnss
*)op
;
1172 l
= (op
->nd_opt_len
- 1) / 2;
1173 ND_PRINT((ndo
," lifetime %us,",
1174 EXTRACT_32BITS(&oprd
->nd_opt_rdnss_lifetime
)));
1175 for (i
= 0; i
< l
; i
++) {
1176 ND_TCHECK(oprd
->nd_opt_rdnss_addr
[i
]);
1177 ND_PRINT((ndo
," addr: %s",
1178 ip6addr_string(&oprd
->nd_opt_rdnss_addr
[i
])));
1182 opds
= (struct nd_opt_dnssl
*)op
;
1183 ND_PRINT((ndo
," lifetime %us, domain(s):",
1184 EXTRACT_32BITS(&opds
->nd_opt_dnssl_lifetime
)));
1185 domp
= cp
+ 8; /* domain names, variable-sized, RFC1035-encoded */
1186 while (domp
< cp
+ (op
->nd_opt_len
<< 3) && *domp
!= '\0')
1189 if ((domp
= ns_nprint (domp
, bp
)) == NULL
)
1193 case ND_OPT_ADVINTERVAL
:
1194 opa
= (struct nd_opt_advinterval
*)op
;
1195 ND_TCHECK(opa
->nd_opt_adv_interval
);
1196 ND_PRINT((ndo
," %ums", EXTRACT_32BITS(&opa
->nd_opt_adv_interval
)));
1198 case ND_OPT_HOMEAGENT_INFO
:
1199 oph
= (struct nd_opt_homeagent_info
*)op
;
1200 ND_TCHECK(oph
->nd_opt_hai_lifetime
);
1201 ND_PRINT((ndo
," preference %u, lifetime %u",
1202 EXTRACT_16BITS(&oph
->nd_opt_hai_preference
),
1203 EXTRACT_16BITS(&oph
->nd_opt_hai_lifetime
)));
1205 case ND_OPT_ROUTE_INFO
:
1206 opri
= (struct nd_opt_route_info
*)op
;
1207 ND_TCHECK(opri
->nd_opt_rti_lifetime
);
1208 memset(&in6
, 0, sizeof(in6
));
1209 in6p
= (struct in6_addr
*)(opri
+ 1);
1210 switch (op
->nd_opt_len
) {
1214 ND_TCHECK2(*in6p
, 8);
1215 memcpy(&in6
, opri
+ 1, 8);
1219 memcpy(&in6
, opri
+ 1, sizeof(in6
));
1224 ND_PRINT((ndo
," %s/%u", ip6addr_string(&in6
),
1225 opri
->nd_opt_rti_prefixlen
));
1226 ND_PRINT((ndo
,", pref=%s", get_rtpref(opri
->nd_opt_rti_flags
)));
1227 ND_PRINT((ndo
,", lifetime=%s",
1228 get_lifetime(EXTRACT_32BITS(&opri
->nd_opt_rti_lifetime
))));
1231 if (ndo
->ndo_vflag
<= 1) {
1232 print_unknown_data(ndo
,cp
+2,"\n\t ", (op
->nd_opt_len
<< 3) - 2); /* skip option header */
1237 /* do we want to see an additional hexdump ? */
1238 if (ndo
->ndo_vflag
> 1)
1239 print_unknown_data(ndo
, cp
+2,"\n\t ", (op
->nd_opt_len
<< 3) - 2); /* skip option header */
1241 cp
+= op
->nd_opt_len
<< 3;
1242 resid
-= op
->nd_opt_len
<< 3;
1247 ND_PRINT((ndo
, "[ndp opt]"));
1253 mld6_print(netdissect_options
*ndo
, const u_char
*bp
)
1255 struct mld6_hdr
*mp
= (struct mld6_hdr
*)bp
;
1258 /* 'ep' points to the end of available data. */
1259 ep
= ndo
->ndo_snapend
;
1261 if ((u_char
*)mp
+ sizeof(*mp
) > ep
)
1264 ND_PRINT((ndo
,"max resp delay: %d ", EXTRACT_16BITS(&mp
->mld6_maxdelay
)));
1265 ND_PRINT((ndo
,"addr: %s", ip6addr_string(&mp
->mld6_addr
)));
1269 mldv2_report_print(netdissect_options
*ndo
, const u_char
*bp
, u_int len
)
1271 struct icmp6_hdr
*icp
= (struct icmp6_hdr
*) bp
;
1272 u_int group
, nsrcs
, ngroups
;
1275 /* Minimum len is 8 */
1277 ND_PRINT((ndo
," [invalid len %d]", len
));
1281 ND_TCHECK(icp
->icmp6_data16
[1]);
1282 ngroups
= EXTRACT_16BITS(&icp
->icmp6_data16
[1]);
1283 ND_PRINT((ndo
,", %d group record(s)", ngroups
));
1284 if (ndo
->ndo_vflag
> 0) {
1285 /* Print the group records */
1287 for (i
= 0; i
< ngroups
; i
++) {
1288 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
1289 if (len
< group
+ 20) {
1290 ND_PRINT((ndo
," [invalid number of groups]"));
1293 ND_TCHECK2(bp
[group
+ 4], sizeof(struct in6_addr
));
1294 ND_PRINT((ndo
," [gaddr %s", ip6addr_string(&bp
[group
+ 4])));
1295 ND_PRINT((ndo
," %s", tok2str(mldv2report2str
, " [v2-report-#%d]",
1297 nsrcs
= (bp
[group
+ 2] << 8) + bp
[group
+ 3];
1298 /* Check the number of sources and print them */
1299 if (len
< group
+ 20 + (nsrcs
* sizeof(struct in6_addr
))) {
1300 ND_PRINT((ndo
," [invalid number of sources %d]", nsrcs
));
1303 if (ndo
->ndo_vflag
== 1)
1304 ND_PRINT((ndo
,", %d source(s)", nsrcs
));
1306 /* Print the sources */
1307 (void)ND_PRINT((ndo
," {"));
1308 for (j
= 0; j
< nsrcs
; j
++) {
1309 ND_TCHECK2(bp
[group
+ 20 + j
* sizeof(struct in6_addr
)],
1310 sizeof(struct in6_addr
));
1311 ND_PRINT((ndo
," %s", ip6addr_string(&bp
[group
+ 20 + j
* sizeof(struct in6_addr
)])));
1313 (void)ND_PRINT((ndo
," }"));
1315 /* Next group record */
1316 group
+= 20 + nsrcs
* sizeof(struct in6_addr
);
1317 ND_PRINT((ndo
,"]"));
1322 (void)ND_PRINT((ndo
,"[|icmp6]"));
1327 mldv2_query_print(netdissect_options
*ndo
, const u_char
*bp
, u_int len
)
1329 struct icmp6_hdr
*icp
= (struct icmp6_hdr
*) bp
;
1335 /* Minimum len is 28 */
1337 ND_PRINT((ndo
," [invalid len %d]", len
));
1340 ND_TCHECK(icp
->icmp6_data16
[0]);
1341 mrc
= EXTRACT_16BITS(&icp
->icmp6_data16
[0]);
1345 mrt
= ((mrc
& 0x0fff) | 0x1000) << (((mrc
& 0x7000) >> 12) + 3);
1347 if (ndo
->ndo_vflag
) {
1348 (void)ND_PRINT((ndo
," [max resp delay=%d]", mrt
));
1350 ND_TCHECK2(bp
[8], sizeof(struct in6_addr
));
1351 ND_PRINT((ndo
," [gaddr %s", ip6addr_string(&bp
[8])));
1353 if (ndo
->ndo_vflag
) {
1355 if (bp
[24] & 0x08) {
1356 ND_PRINT((ndo
," sflag"));
1358 if (bp
[24] & 0x07) {
1359 ND_PRINT((ndo
," robustness=%d", bp
[24] & 0x07));
1364 qqi
= ((bp
[25] & 0x0f) | 0x10) << (((bp
[25] & 0x70) >> 4) + 3);
1366 ND_PRINT((ndo
," qqi=%d", qqi
));
1369 ND_TCHECK2(bp
[26], 2);
1370 nsrcs
= EXTRACT_16BITS(&bp
[26]);
1372 if (len
< 28 + nsrcs
* sizeof(struct in6_addr
))
1373 ND_PRINT((ndo
," [invalid number of sources]"));
1374 else if (ndo
->ndo_vflag
> 1) {
1375 ND_PRINT((ndo
," {"));
1376 for (i
= 0; i
< nsrcs
; i
++) {
1377 ND_TCHECK2(bp
[28 + i
* sizeof(struct in6_addr
)],
1378 sizeof(struct in6_addr
));
1379 ND_PRINT((ndo
," %s", ip6addr_string(&bp
[28 + i
* sizeof(struct in6_addr
)])));
1381 ND_PRINT((ndo
," }"));
1383 ND_PRINT((ndo
,", %d source(s)", nsrcs
));
1385 ND_PRINT((ndo
,"]"));
1388 (void)ND_PRINT((ndo
,"[|icmp6]"));
1393 dnsname_print(netdissect_options
*ndo
, const u_char
*cp
, const u_char
*ep
)
1397 /* DNS name decoding - no decompression */
1398 ND_PRINT((ndo
,", \""));
1403 ND_PRINT((ndo
,"???"));
1406 while (i
-- && cp
< ep
) {
1410 if (cp
+ 1 < ep
&& *cp
)
1411 ND_PRINT((ndo
,"."));
1415 ND_PRINT((ndo
,"."));
1416 } else if (cp
+ 1 == ep
&& *cp
== '\0') {
1420 ND_PRINT((ndo
,"???"));
1425 ND_PRINT((ndo
,"\""));
1429 icmp6_nodeinfo_print(netdissect_options
*ndo
, u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
1431 struct icmp6_nodeinfo
*ni6
;
1432 struct icmp6_hdr
*dp
;
1439 dp
= (struct icmp6_hdr
*)bp
;
1440 ni6
= (struct icmp6_nodeinfo
*)bp
;
1443 switch (ni6
->ni_type
) {
1444 case ICMP6_NI_QUERY
:
1445 if (siz
== sizeof(*dp
) + 4) {
1446 /* KAME who-are-you */
1447 ND_PRINT((ndo
," who-are-you request"));
1450 ND_PRINT((ndo
," node information query"));
1452 ND_TCHECK2(*dp
, sizeof(*ni6
));
1453 ni6
= (struct icmp6_nodeinfo
*)dp
;
1454 ND_PRINT((ndo
," (")); /*)*/
1455 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
1457 ND_PRINT((ndo
,"noop"));
1459 case NI_QTYPE_SUPTYPES
:
1460 ND_PRINT((ndo
,"supported qtypes"));
1461 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
1463 ND_PRINT((ndo
," [%s]", (i
& 0x01) ? "C" : ""));
1467 ND_PRINT((ndo
,"DNS name"));
1469 case NI_QTYPE_NODEADDR
:
1470 ND_PRINT((ndo
,"node addresses"));
1474 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
1475 ND_PRINT((ndo
," [%s%s%s%s%s%s]",
1476 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1477 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1478 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1479 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1480 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1481 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : ""));
1484 ND_PRINT((ndo
,"unknown"));
1488 if (ni6
->ni_qtype
== NI_QTYPE_NOOP
||
1489 ni6
->ni_qtype
== NI_QTYPE_SUPTYPES
) {
1490 if (siz
!= sizeof(*ni6
))
1492 ND_PRINT((ndo
,", invalid len"));
1494 ND_PRINT((ndo
,")"));
1499 /* XXX backward compat, icmp-name-lookup-03 */
1500 if (siz
== sizeof(*ni6
)) {
1501 ND_PRINT((ndo
,", 03 draft"));
1503 ND_PRINT((ndo
,")"));
1507 switch (ni6
->ni_code
) {
1508 case ICMP6_NI_SUBJ_IPV6
:
1510 sizeof(*ni6
) + sizeof(struct in6_addr
)))
1512 if (siz
!= sizeof(*ni6
) + sizeof(struct in6_addr
)) {
1514 ND_PRINT((ndo
,", invalid subject len"));
1517 ND_PRINT((ndo
,", subject=%s",
1518 getname6((const u_char
*)(ni6
+ 1))));
1520 case ICMP6_NI_SUBJ_FQDN
:
1521 ND_PRINT((ndo
,", subject=DNS name"));
1522 cp
= (const u_char
*)(ni6
+ 1);
1523 if (cp
[0] == ep
- cp
- 1) {
1524 /* icmp-name-lookup-03, pascal string */
1526 ND_PRINT((ndo
,", 03 draft"));
1528 ND_PRINT((ndo
,", \""));
1533 ND_PRINT((ndo
,"\""));
1535 dnsname_print(ndo
, cp
, ep
);
1537 case ICMP6_NI_SUBJ_IPV4
:
1538 if (!ND_TTEST2(*dp
, sizeof(*ni6
) + sizeof(struct in_addr
)))
1540 if (siz
!= sizeof(*ni6
) + sizeof(struct in_addr
)) {
1542 ND_PRINT((ndo
,", invalid subject len"));
1545 ND_PRINT((ndo
,", subject=%s",
1546 getname((const u_char
*)(ni6
+ 1))));
1549 ND_PRINT((ndo
,", unknown subject"));
1554 ND_PRINT((ndo
,")"));
1557 case ICMP6_NI_REPLY
:
1558 if (icmp6len
> siz
) {
1559 ND_PRINT((ndo
,"[|icmp6: node information reply]"));
1565 ni6
= (struct icmp6_nodeinfo
*)dp
;
1566 ND_PRINT((ndo
," node information reply"));
1567 ND_PRINT((ndo
," (")); /*)*/
1568 switch (ni6
->ni_code
) {
1569 case ICMP6_NI_SUCCESS
:
1570 if (ndo
->ndo_vflag
) {
1571 ND_PRINT((ndo
,"success"));
1575 case ICMP6_NI_REFUSED
:
1576 ND_PRINT((ndo
,"refused"));
1578 if (siz
!= sizeof(*ni6
))
1580 ND_PRINT((ndo
,", invalid length"));
1582 case ICMP6_NI_UNKNOWN
:
1583 ND_PRINT((ndo
,"unknown"));
1585 if (siz
!= sizeof(*ni6
))
1587 ND_PRINT((ndo
,", invalid length"));
1591 if (ni6
->ni_code
!= ICMP6_NI_SUCCESS
) {
1593 ND_PRINT((ndo
,")"));
1597 switch (EXTRACT_16BITS(&ni6
->ni_qtype
)) {
1600 ND_PRINT((ndo
,", "));
1601 ND_PRINT((ndo
,"noop"));
1602 if (siz
!= sizeof(*ni6
))
1604 ND_PRINT((ndo
,", invalid length"));
1606 case NI_QTYPE_SUPTYPES
:
1608 ND_PRINT((ndo
,", "));
1609 ND_PRINT((ndo
,"supported qtypes"));
1610 i
= EXTRACT_16BITS(&ni6
->ni_flags
);
1612 ND_PRINT((ndo
," [%s]", (i
& 0x01) ? "C" : ""));
1616 ND_PRINT((ndo
,", "));
1617 ND_PRINT((ndo
,"DNS name"));
1618 cp
= (const u_char
*)(ni6
+ 1) + 4;
1619 if (cp
[0] == ep
- cp
- 1) {
1620 /* icmp-name-lookup-03, pascal string */
1622 ND_PRINT((ndo
,", 03 draft"));
1624 ND_PRINT((ndo
,", \""));
1629 ND_PRINT((ndo
,"\""));
1631 dnsname_print(ndo
, cp
, ep
);
1632 if ((EXTRACT_16BITS(&ni6
->ni_flags
) & 0x01) != 0)
1633 ND_PRINT((ndo
," [TTL=%u]", *(u_int32_t
*)(ni6
+ 1)));
1635 case NI_QTYPE_NODEADDR
:
1637 ND_PRINT((ndo
,", "));
1638 ND_PRINT((ndo
,"node addresses"));
1641 if (i
+ sizeof(struct in6_addr
) + sizeof(int32_t) > siz
)
1643 ND_PRINT((ndo
," %s", getname6(bp
+ i
)));
1644 i
+= sizeof(struct in6_addr
);
1645 ND_PRINT((ndo
,"(%d)", (int32_t)EXTRACT_32BITS(bp
+ i
)));
1646 i
+= sizeof(int32_t);
1651 ND_PRINT((ndo
," [%s%s%s%s%s%s%s]",
1652 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1653 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1654 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1655 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1656 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1657 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
1658 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : ""));
1662 ND_PRINT((ndo
,", "));
1663 ND_PRINT((ndo
,"unknown"));
1668 ND_PRINT((ndo
,")"));
1674 ND_PRINT((ndo
, "[|icmp6]"));
1678 icmp6_rrenum_print(netdissect_options
*ndo
, const u_char
*bp
, const u_char
*ep
)
1680 struct icmp6_router_renum
*rr6
;
1682 struct rr_pco_match
*match
;
1683 struct rr_pco_use
*use
;
1684 char hbuf
[NI_MAXHOST
];
1689 rr6
= (struct icmp6_router_renum
*)bp
;
1690 cp
= (const char *)(rr6
+ 1);
1692 ND_TCHECK(rr6
->rr_reserved
);
1693 switch (rr6
->rr_code
) {
1694 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
1695 ND_PRINT((ndo
,"router renum: command"));
1697 case ICMP6_ROUTER_RENUMBERING_RESULT
:
1698 ND_PRINT((ndo
,"router renum: result"));
1700 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
1701 ND_PRINT((ndo
,"router renum: sequence number reset"));
1704 ND_PRINT((ndo
,"router renum: code-#%d", rr6
->rr_code
));
1708 ND_PRINT((ndo
,", seq=%u", EXTRACT_32BITS(&rr6
->rr_seqnum
)));
1710 if (ndo
->ndo_vflag
) {
1711 #define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "")
1712 ND_PRINT((ndo
,"[")); /*]*/
1713 if (rr6
->rr_flags
) {
1714 ND_PRINT((ndo
,"%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
1715 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
1716 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
1717 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
1718 F(ICMP6_RR_FLAGS_PREVDONE
, "P")));
1720 ND_PRINT((ndo
,"seg=%u,", rr6
->rr_segnum
));
1721 ND_PRINT((ndo
,"maxdelay=%u", EXTRACT_16BITS(&rr6
->rr_maxdelay
)));
1722 if (rr6
->rr_reserved
)
1723 ND_PRINT((ndo
,"rsvd=0x%x", EXTRACT_32BITS(&rr6
->rr_reserved
)));
1725 ND_PRINT((ndo
,"]"));
1729 if (rr6
->rr_code
== ICMP6_ROUTER_RENUMBERING_COMMAND
) {
1730 match
= (struct rr_pco_match
*)cp
;
1731 cp
= (const char *)(match
+ 1);
1733 ND_TCHECK(match
->rpm_prefix
);
1735 if (ndo
->ndo_vflag
> 1)
1736 ND_PRINT((ndo
,"\n\t"));
1738 ND_PRINT((ndo
," "));
1739 ND_PRINT((ndo
,"match(")); /*)*/
1740 switch (match
->rpm_code
) {
1741 case RPM_PCO_ADD
: ND_PRINT((ndo
,"add")); break;
1742 case RPM_PCO_CHANGE
: ND_PRINT((ndo
,"change")); break;
1743 case RPM_PCO_SETGLOBAL
: ND_PRINT((ndo
,"setglobal")); break;
1744 default: ND_PRINT((ndo
,"#%u", match
->rpm_code
)); break;
1747 if (ndo
->ndo_vflag
) {
1748 ND_PRINT((ndo
,",ord=%u", match
->rpm_ordinal
));
1749 ND_PRINT((ndo
,",min=%u", match
->rpm_minlen
));
1750 ND_PRINT((ndo
,",max=%u", match
->rpm_maxlen
));
1752 if (inet_ntop(AF_INET6
, &match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
1753 ND_PRINT((ndo
,",%s/%u", hbuf
, match
->rpm_matchlen
));
1755 ND_PRINT((ndo
,",?/%u", match
->rpm_matchlen
));
1757 ND_PRINT((ndo
,")"));
1759 n
= match
->rpm_len
- 3;
1764 use
= (struct rr_pco_use
*)cp
;
1765 cp
= (const char *)(use
+ 1);
1767 ND_TCHECK(use
->rpu_prefix
);
1769 if (ndo
->ndo_vflag
> 1)
1770 ND_PRINT((ndo
,"\n\t"));
1772 ND_PRINT((ndo
," "));
1773 ND_PRINT((ndo
,"use(")); /*)*/
1774 if (use
->rpu_flags
) {
1775 #define F(x, y) ((use->rpu_flags) & (x) ? (y) : "")
1776 ND_PRINT((ndo
,"%s%s,",
1777 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
1778 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P")));
1781 if (ndo
->ndo_vflag
) {
1782 ND_PRINT((ndo
,"mask=0x%x,", use
->rpu_ramask
));
1783 ND_PRINT((ndo
,"raflags=0x%x,", use
->rpu_raflags
));
1784 if (~use
->rpu_vltime
== 0)
1785 ND_PRINT((ndo
,"vltime=infty,"));
1787 ND_PRINT((ndo
,"vltime=%u,",
1788 EXTRACT_32BITS(&use
->rpu_vltime
)));
1789 if (~use
->rpu_pltime
== 0)
1790 ND_PRINT((ndo
,"pltime=infty,"));
1792 ND_PRINT((ndo
,"pltime=%u,",
1793 EXTRACT_32BITS(&use
->rpu_pltime
)));
1795 if (inet_ntop(AF_INET6
, &use
->rpu_prefix
, hbuf
,
1797 ND_PRINT((ndo
,"%s/%u/%u", hbuf
, use
->rpu_uselen
,
1800 ND_PRINT((ndo
,"?/%u/%u", use
->rpu_uselen
,
1803 ND_PRINT((ndo
,")"));
1810 ND_PRINT((ndo
,"[|icmp6]"));
1817 * c-style: whitesmith