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.
22 /* \summary: IPv6 Internet Control Message Protocol (ICMPv6) printer */
28 #include "netdissect-stdinc.h"
33 #include "netdissect.h"
34 #include "addrtoname.h"
35 #include "addrtostr.h"
44 /* NetBSD: icmp6.h,v 1.13 2000/08/03 16:30:37 itojun Exp */
45 /* $KAME: icmp6.h,v 1.22 2000/08/03 15:25:16 jinmei Exp $ */
48 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
49 * All rights reserved.
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
54 * 1. Redistributions of source code must retain the above copyright
55 * notice, this list of conditions and the following disclaimer.
56 * 2. Redistributions in binary form must reproduce the above copyright
57 * notice, this list of conditions and the following disclaimer in the
58 * documentation and/or other materials provided with the distribution.
59 * 3. Neither the name of the project nor the names of its contributors
60 * may be used to endorse or promote products derived from this software
61 * without specific prior written permission.
63 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77 nd_uint8_t icmp6_type
; /* type field */
78 nd_uint8_t icmp6_code
; /* code field */
79 nd_uint16_t icmp6_cksum
; /* checksum field */
81 nd_uint32_t icmp6_un_data32
[1]; /* type-specific field */
82 nd_uint16_t icmp6_un_data16
[2]; /* type-specific field */
83 nd_uint8_t icmp6_un_data8
[4]; /* type-specific field */
84 nd_byte icmp6_un_data
[1]; /* type-specific field */
88 #define icmp6_data32 icmp6_dataun.icmp6_un_data32
89 #define icmp6_data16 icmp6_dataun.icmp6_un_data16
90 #define icmp6_data8 icmp6_dataun.icmp6_un_data8
91 #define icmp6_data icmp6_dataun.icmp6_un_data
92 #define icmp6_pptr icmp6_data32[0] /* parameter prob */
93 #define icmp6_mtu icmp6_data32[0] /* packet too big */
94 #define icmp6_id icmp6_data16[0] /* echo request/reply */
95 #define icmp6_seq icmp6_data16[1] /* echo request/reply */
96 #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
98 #define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */
99 #define ICMP6_PACKET_TOO_BIG 2 /* packet too big */
100 #define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */
101 #define ICMP6_PARAM_PROB 4 /* ip6 header bad */
103 #define ICMP6_ECHO_REQUEST 128 /* echo service */
104 #define ICMP6_ECHO_REPLY 129 /* echo reply */
105 #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */
106 #define MLD6_LISTENER_QUERY 130 /* multicast listener query */
107 #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */
108 #define MLD6_LISTENER_REPORT 131 /* multicast listener report */
109 #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */
110 #define MLD6_LISTENER_DONE 132 /* multicast listener done */
112 #define ND_ROUTER_SOLICIT 133 /* router solicitation */
113 #define ND_ROUTER_ADVERT 134 /* router advertisement */
114 #define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */
115 #define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisement */
116 #define ND_REDIRECT 137 /* redirect */
118 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
120 #define ICMP6_WRUREQUEST 139 /* who are you request */
121 #define ICMP6_WRUREPLY 140 /* who are you reply */
122 #define ICMP6_FQDN_QUERY 139 /* FQDN query */
123 #define ICMP6_FQDN_REPLY 140 /* FQDN reply */
124 #define ICMP6_NI_QUERY 139 /* node information request - RFC 4620 */
125 #define ICMP6_NI_REPLY 140 /* node information reply - RFC 4620 */
126 #define IND_SOLICIT 141 /* inverse neighbor solicitation */
127 #define IND_ADVERT 142 /* inverse neighbor advertisement */
129 #define ICMP6_V2_MEMBERSHIP_REPORT 143 /* v2 membership report */
130 #define MLDV2_LISTENER_REPORT 143 /* v2 multicast listener report */
131 #define ICMP6_HADISCOV_REQUEST 144
132 #define ICMP6_HADISCOV_REPLY 145
133 #define ICMP6_MOBILEPREFIX_SOLICIT 146
134 #define ICMP6_MOBILEPREFIX_ADVERT 147
136 #define MLD6_MTRACE_RESP 200 /* mtrace response(to sender) */
137 #define MLD6_MTRACE 201 /* mtrace messages */
139 #define ICMP6_MAXTYPE 201
141 #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
142 #define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */
143 #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */
144 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
145 #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
146 #define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */
148 #define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */
149 #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */
151 #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
152 #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */
153 #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */
155 #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
157 #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
158 #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
159 #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
161 #define ICMP6_NI_SUCCESS 0 /* node information successful reply */
162 #define ICMP6_NI_REFUSED 1 /* node information request is refused */
163 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
165 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
166 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
167 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */
169 /* Used in kernel only */
170 #define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */
171 #define ND_REDIRECT_ROUTER 1 /* redirect to a better router */
174 * Multicast Listener Discovery
177 struct icmp6_hdr mld6_hdr
;
178 nd_ipv6 mld6_addr
; /* multicast address */
181 #define mld6_type mld6_hdr.icmp6_type
182 #define mld6_code mld6_hdr.icmp6_code
183 #define mld6_cksum mld6_hdr.icmp6_cksum
184 #define mld6_maxdelay mld6_hdr.icmp6_data16[0]
185 #define mld6_reserved mld6_hdr.icmp6_data16[1]
187 #define MLD_MINLEN 24
188 #define MLDV2_MINLEN 28
194 struct nd_router_solicit
{ /* router solicitation */
195 struct icmp6_hdr nd_rs_hdr
;
196 /* could be followed by options */
199 #define nd_rs_type nd_rs_hdr.icmp6_type
200 #define nd_rs_code nd_rs_hdr.icmp6_code
201 #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
202 #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
204 struct nd_router_advert
{ /* router advertisement */
205 struct icmp6_hdr nd_ra_hdr
;
206 nd_uint32_t nd_ra_reachable
; /* reachable time */
207 nd_uint32_t nd_ra_retransmit
; /* retransmit timer */
208 /* could be followed by options */
211 #define nd_ra_type nd_ra_hdr.icmp6_type
212 #define nd_ra_code nd_ra_hdr.icmp6_code
213 #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
214 #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
215 #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
216 #define ND_RA_FLAG_MANAGED 0x80
217 #define ND_RA_FLAG_OTHER 0x40
218 #define ND_RA_FLAG_HOME_AGENT 0x20
221 * Router preference values based on draft-draves-ipngwg-router-selection-01.
222 * These are non-standard definitions.
224 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
226 #define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */
227 #define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */
228 #define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */
229 #define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */
231 #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
233 struct nd_neighbor_solicit
{ /* neighbor solicitation */
234 struct icmp6_hdr nd_ns_hdr
;
235 nd_ipv6 nd_ns_target
; /*target address */
236 /* could be followed by options */
239 #define nd_ns_type nd_ns_hdr.icmp6_type
240 #define nd_ns_code nd_ns_hdr.icmp6_code
241 #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
242 #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
244 struct nd_neighbor_advert
{ /* neighbor advertisement */
245 struct icmp6_hdr nd_na_hdr
;
246 nd_ipv6 nd_na_target
; /* target address */
247 /* could be followed by options */
250 #define nd_na_type nd_na_hdr.icmp6_type
251 #define nd_na_code nd_na_hdr.icmp6_code
252 #define nd_na_cksum nd_na_hdr.icmp6_cksum
253 #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
255 #define ND_NA_FLAG_ROUTER 0x80000000
256 #define ND_NA_FLAG_SOLICITED 0x40000000
257 #define ND_NA_FLAG_OVERRIDE 0x20000000
259 struct nd_redirect
{ /* redirect */
260 struct icmp6_hdr nd_rd_hdr
;
261 nd_ipv6 nd_rd_target
; /* target address */
262 nd_ipv6 nd_rd_dst
; /* destination address */
263 /* could be followed by options */
266 #define nd_rd_type nd_rd_hdr.icmp6_type
267 #define nd_rd_code nd_rd_hdr.icmp6_code
268 #define nd_rd_cksum nd_rd_hdr.icmp6_cksum
269 #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
271 struct nd_opt_hdr
{ /* Neighbor discovery option header */
272 nd_uint8_t nd_opt_type
;
273 nd_uint8_t nd_opt_len
;
274 /* followed by option specific data*/
277 #define ND_OPT_SOURCE_LINKADDR 1
278 #define ND_OPT_TARGET_LINKADDR 2
279 #define ND_OPT_PREFIX_INFORMATION 3
280 #define ND_OPT_REDIRECTED_HEADER 4
282 #define ND_OPT_ADVINTERVAL 7
283 #define ND_OPT_HOMEAGENT_INFO 8
284 #define ND_OPT_ROUTE_INFO 24 /* RFC4191 */
285 #define ND_OPT_RDNSS 25
286 #define ND_OPT_DNSSL 31
288 struct nd_opt_prefix_info
{ /* prefix information */
289 nd_uint8_t nd_opt_pi_type
;
290 nd_uint8_t nd_opt_pi_len
;
291 nd_uint8_t nd_opt_pi_prefix_len
;
292 nd_uint8_t nd_opt_pi_flags_reserved
;
293 nd_uint32_t nd_opt_pi_valid_time
;
294 nd_uint32_t nd_opt_pi_preferred_time
;
295 nd_uint32_t nd_opt_pi_reserved2
;
296 nd_ipv6 nd_opt_pi_prefix
;
299 #define ND_OPT_PI_FLAG_ONLINK 0x80
300 #define ND_OPT_PI_FLAG_AUTO 0x40
301 #define ND_OPT_PI_FLAG_ROUTER 0x20 /*2292bis*/
303 struct nd_opt_rd_hdr
{ /* redirected header */
304 nd_uint8_t nd_opt_rh_type
;
305 nd_uint8_t nd_opt_rh_len
;
306 nd_uint16_t nd_opt_rh_reserved1
;
307 nd_uint32_t nd_opt_rh_reserved2
;
308 /* followed by IP header and data */
311 struct nd_opt_mtu
{ /* MTU option */
312 nd_uint8_t nd_opt_mtu_type
;
313 nd_uint8_t nd_opt_mtu_len
;
314 nd_uint16_t nd_opt_mtu_reserved
;
315 nd_uint32_t nd_opt_mtu_mtu
;
318 struct nd_opt_rdnss
{ /* RDNSS RFC 6106 5.1 */
319 nd_uint8_t nd_opt_rdnss_type
;
320 nd_uint8_t nd_opt_rdnss_len
;
321 nd_uint16_t nd_opt_rdnss_reserved
;
322 nd_uint32_t nd_opt_rdnss_lifetime
;
323 nd_ipv6 nd_opt_rdnss_addr
[1]; /* variable-length */
326 struct nd_opt_dnssl
{ /* DNSSL RFC 6106 5.2 */
327 nd_uint8_t nd_opt_dnssl_type
;
328 nd_uint8_t nd_opt_dnssl_len
;
329 nd_uint16_t nd_opt_dnssl_reserved
;
330 nd_uint32_t nd_opt_dnssl_lifetime
;
331 /* followed by list of DNS search domains, variable-length */
334 struct nd_opt_advinterval
{ /* Advertisement interval option */
335 nd_uint8_t nd_opt_adv_type
;
336 nd_uint8_t nd_opt_adv_len
;
337 nd_uint16_t nd_opt_adv_reserved
;
338 nd_uint32_t nd_opt_adv_interval
;
341 struct nd_opt_homeagent_info
{ /* Home Agent info */
342 nd_uint8_t nd_opt_hai_type
;
343 nd_uint8_t nd_opt_hai_len
;
344 nd_uint16_t nd_opt_hai_reserved
;
345 nd_uint16_t nd_opt_hai_preference
;
346 nd_uint16_t nd_opt_hai_lifetime
;
349 struct nd_opt_route_info
{ /* route info */
350 nd_uint8_t nd_opt_rti_type
;
351 nd_uint8_t nd_opt_rti_len
;
352 nd_uint8_t nd_opt_rti_prefixlen
;
353 nd_uint8_t nd_opt_rti_flags
;
354 nd_uint32_t nd_opt_rti_lifetime
;
362 struct icmp6_namelookup
{
363 struct icmp6_hdr icmp6_nl_hdr
;
364 nd_byte icmp6_nl_nonce
[8];
365 nd_int32_t icmp6_nl_ttl
;
367 nd_uint8_t icmp6_nl_len
;
368 nd_byte icmp6_nl_name
[3];
370 /* could be followed by options */
374 * icmp6 node information
376 struct icmp6_nodeinfo
{
377 struct icmp6_hdr icmp6_ni_hdr
;
378 nd_byte icmp6_ni_nonce
[8];
379 /* could be followed by reply data */
382 #define ni_type icmp6_ni_hdr.icmp6_type
383 #define ni_code icmp6_ni_hdr.icmp6_code
384 #define ni_cksum icmp6_ni_hdr.icmp6_cksum
385 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
386 #define ni_flags icmp6_ni_hdr.icmp6_data16[1]
388 #define NI_QTYPE_NOOP 0 /* NOOP */
389 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes (drafts up to 09) */
390 #define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */
391 #define NI_QTYPE_DNSNAME 2 /* DNS Name */
392 #define NI_QTYPE_NODEADDR 3 /* Node Addresses */
393 #define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */
396 #define NI_SUPTYPE_FLAG_COMPRESS ((uint16_t)htons(0x1))
397 #define NI_FQDN_FLAG_VALIDTTL ((uint16_t)htons(0x1))
400 #define NI_NODEADDR_FLAG_TRUNCATE ((uint16_t)htons(0x1))
401 #define NI_NODEADDR_FLAG_ALL ((uint16_t)htons(0x2))
402 #define NI_NODEADDR_FLAG_COMPAT ((uint16_t)htons(0x4))
403 #define NI_NODEADDR_FLAG_LINKLOCAL ((uint16_t)htons(0x8))
404 #define NI_NODEADDR_FLAG_SITELOCAL ((uint16_t)htons(0x10))
405 #define NI_NODEADDR_FLAG_GLOBAL ((uint16_t)htons(0x20))
406 #define NI_NODEADDR_FLAG_ANYCAST ((uint16_t)htons(0x40)) /* just experimental. not in spec */
408 struct ni_reply_fqdn
{
409 nd_uint32_t ni_fqdn_ttl
; /* TTL */
410 nd_uint8_t ni_fqdn_namelen
; /* length in octets of the FQDN */
411 nd_byte ni_fqdn_name
[3]; /* XXX: alignment */
415 * Router Renumbering. as router-renum-08.txt
417 struct icmp6_router_renum
{ /* router renumbering header */
418 struct icmp6_hdr rr_hdr
;
419 nd_uint8_t rr_segnum
;
421 nd_uint16_t rr_maxdelay
;
422 nd_uint32_t rr_reserved
;
424 #define ICMP6_RR_FLAGS_TEST 0x80
425 #define ICMP6_RR_FLAGS_REQRESULT 0x40
426 #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
427 #define ICMP6_RR_FLAGS_SPECSITE 0x10
428 #define ICMP6_RR_FLAGS_PREVDONE 0x08
430 #define rr_type rr_hdr.icmp6_type
431 #define rr_code rr_hdr.icmp6_code
432 #define rr_cksum rr_hdr.icmp6_cksum
433 #define rr_seqnum rr_hdr.icmp6_data32[0]
435 struct rr_pco_match
{ /* match prefix part */
438 nd_uint8_t rpm_ordinal
;
439 nd_uint8_t rpm_matchlen
;
440 nd_uint8_t rpm_minlen
;
441 nd_uint8_t rpm_maxlen
;
442 nd_uint16_t rpm_reserved
;
446 #define RPM_PCO_ADD 1
447 #define RPM_PCO_CHANGE 2
448 #define RPM_PCO_SETGLOBAL 3
449 #define RPM_PCO_MAX 4
451 struct rr_pco_use
{ /* use prefix part */
452 nd_uint8_t rpu_uselen
;
453 nd_uint8_t rpu_keeplen
;
454 nd_uint8_t rpu_ramask
;
455 nd_uint8_t rpu_raflags
;
456 nd_uint32_t rpu_vltime
;
457 nd_uint32_t rpu_pltime
;
458 nd_uint32_t rpu_flags
;
461 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80
462 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40
465 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME ((uint32_t)htonl(0x80000000))
466 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME ((uint32_t)htonl(0x40000000))
468 struct rr_result
{ /* router renumbering result message */
469 nd_uint16_t rrr_flags
;
470 nd_uint8_t rrr_ordinal
;
471 nd_uint8_t rrr_matchedlen
;
472 nd_uint32_t rrr_ifid
;
476 #define ICMP6_RR_RESULT_FLAGS_OOB ((uint16_t)htons(0x0002))
477 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN ((uint16_t)htons(0x0001))
479 static const char *get_rtpref(u_int
);
480 static const char *get_lifetime(uint32_t);
481 static void print_lladdr(netdissect_options
*ndo
, const u_char
*, size_t);
482 static int icmp6_opt_print(netdissect_options
*ndo
, const u_char
*, int);
483 static void mld6_print(netdissect_options
*ndo
, const u_char
*);
484 static void mldv2_report_print(netdissect_options
*ndo
, const u_char
*, u_int
);
485 static void mldv2_query_print(netdissect_options
*ndo
, const u_char
*, u_int
);
486 static const struct udphdr
*get_upperlayer(netdissect_options
*ndo
, const u_char
*, u_int
*);
487 static void dnsname_print(netdissect_options
*ndo
, const u_char
*, const u_char
*);
488 static void icmp6_nodeinfo_print(netdissect_options
*ndo
, u_int
, const u_char
*, const u_char
*);
489 static void icmp6_rrenum_print(netdissect_options
*ndo
, const u_char
*, const u_char
*);
492 #define abs(a) ((0 < (a)) ? (a) : -(a))
496 * DIO: Updated to RFC6550, as published in 2012: section 6. (page 30)
499 #define ND_RPL_MESSAGE 155 /* 0x9B */
506 ND_RPL_SEC_DAG_IS
= 0x80,
507 ND_RPL_SEC_DAG_IO
= 0x81,
508 ND_RPL_SEC_DAG
= 0x82,
509 ND_RPL_SEC_DAG_ACK
= 0x83,
510 ND_RPL_SEC_CONSIST
= 0x8A
513 enum ND_RPL_DIO_FLAGS
{
514 ND_RPL_DIO_GROUNDED
= 0x80,
515 ND_RPL_DIO_DATRIG
= 0x40,
516 ND_RPL_DIO_DASUPPORT
= 0x20,
517 ND_RPL_DIO_RES4
= 0x10,
518 ND_RPL_DIO_RES3
= 0x08,
519 ND_RPL_DIO_PRF_MASK
= 0x07 /* 3-bit preference */
524 /* section 6 of draft-ietf-roll-rpl-19 */
525 struct nd_rpl_security
{
526 nd_uint8_t rpl_sec_t_reserved
; /* bit 7 is T-bit */
527 nd_uint8_t rpl_sec_algo
;
528 nd_uint16_t rpl_sec_kim_lvl_flags
; /* bit 15/14, KIM */
529 /* bit 10-8, LVL, bit 7-0 flags */
530 nd_uint32_t rpl_sec_counter
;
532 nd_byte rpl_sec_ki
[0]; /* depends upon kim */
536 /* section 6.2.1, DODAG Information Solication (DIS_IS) */
537 struct nd_rpl_dis_is
{
538 nd_uint8_t rpl_dis_flags
;
539 nd_uint8_t rpl_dis_reserved
;
541 nd_byte rpl_dis_options
[0];
545 /* section 6.3.1, DODAG Information Object (DIO) */
547 nd_uint8_t rpl_instanceid
;
548 nd_uint8_t rpl_version
;
549 nd_uint16_t rpl_dagrank
;
550 nd_uint8_t rpl_mopprf
; /* bit 7=G, 5-3=MOP, 2-0=PRF */
551 nd_uint8_t rpl_dtsn
; /* Dest. Advertisement Trigger Sequence Number */
552 nd_uint8_t rpl_flags
; /* no flags defined yet */
553 nd_uint8_t rpl_resv1
;
554 nd_byte rpl_dagid
[DAGID_LEN
];
556 #define RPL_DIO_GROUND_FLAG 0x80
557 #define RPL_DIO_MOP_SHIFT 3
558 #define RPL_DIO_MOP_MASK (7 << RPL_DIO_MOP_SHIFT)
559 #define RPL_DIO_PRF_SHIFT 0
560 #define RPL_DIO_PRF_MASK (7 << RPL_DIO_PRF_SHIFT)
561 #define RPL_DIO_GROUNDED(X) ((X)&RPL_DIO_GROUND_FLAG)
562 #define RPL_DIO_MOP(X) (enum RPL_DIO_MOP)(((X)&RPL_DIO_MOP_MASK) >> RPL_DIO_MOP_SHIFT)
563 #define RPL_DIO_PRF(X) (((X)&RPL_DIO_PRF_MASK) >> RPL_DIO_PRF_SHIFT)
566 RPL_DIO_NONSTORING
= 0x0,
567 RPL_DIO_STORING
= 0x1,
568 RPL_DIO_NONSTORING_MULTICAST
= 0x2,
569 RPL_DIO_STORING_MULTICAST
= 0x3
576 RPL_DIO_ROUTINGINFO
= 3,
578 RPL_DAO_RPLTARGET
= 5,
579 RPL_DAO_TRANSITINFO
= 6,
580 RPL_DIO_DESTPREFIX
= 8,
581 RPL_DAO_RPLTARGET_DESC
=9
584 struct rpl_genoption
{
585 nd_uint8_t rpl_dio_type
;
586 nd_uint8_t rpl_dio_len
; /* suboption length, not including type/len */
588 #define RPL_GENOPTION_LEN 2
590 #define RPL_DIO_LIFETIME_INFINITE 0xffffffff
591 #define RPL_DIO_LIFETIME_DISCONNECT 0
593 struct rpl_dio_destprefix
{
594 nd_uint8_t rpl_dio_type
;
595 nd_uint8_t rpl_dio_len
;
596 nd_uint8_t rpl_dio_prefixlen
; /* in bits */
597 nd_uint8_t rpl_dio_prf
; /* flags, including Route Preference */
598 nd_uint32_t rpl_dio_prefixlifetime
; /* in seconds */
600 nd_byte rpl_dio_prefix
[0]; /* variable number of bytes */
604 /* section 6.4.1, DODAG Information Object (DIO) */
606 nd_uint8_t rpl_instanceid
;
607 nd_uint8_t rpl_flags
; /* bit 7=K, 6=D */
609 nd_uint8_t rpl_daoseq
;
610 nd_byte rpl_dagid
[DAGID_LEN
]; /* present when D set. */
612 #define ND_RPL_DAO_MIN_LEN 4 /* length without DAGID */
614 /* indicates if this DAO is to be acK'ed */
615 #define RPL_DAO_K_SHIFT 7
616 #define RPL_DAO_K_MASK (1 << RPL_DAO_K_SHIFT)
617 #define RPL_DAO_K(X) (((X)&RPL_DAO_K_MASK) >> RPL_DAO_K_SHIFT)
619 /* indicates if the DAGID is present */
620 #define RPL_DAO_D_SHIFT 6
621 #define RPL_DAO_D_MASK (1 << RPL_DAO_D_SHIFT)
622 #define RPL_DAO_D(X) (((X)&RPL_DAO_D_MASK) >> RPL_DAO_D_SHIFT)
624 struct rpl_dao_target
{
625 nd_uint8_t rpl_dao_type
;
626 nd_uint8_t rpl_dao_len
;
627 nd_uint8_t rpl_dao_flags
; /* unused */
628 nd_uint8_t rpl_dao_prefixlen
; /* in bits */
630 nd_byte rpl_dao_prefix
[0]; /* variable number of bytes */
634 /* section 6.5.1, Destination Advertisement Object Acknowledgement (DAO-ACK) */
635 struct nd_rpl_daoack
{
636 nd_uint8_t rpl_instanceid
;
637 nd_uint8_t rpl_flags
; /* bit 7=D */
638 nd_uint8_t rpl_daoseq
;
639 nd_uint8_t rpl_status
;
640 nd_byte rpl_dagid
[DAGID_LEN
]; /* present when D set. */
642 #define ND_RPL_DAOACK_MIN_LEN 4 /* length without DAGID */
643 /* indicates if the DAGID is present */
644 #define RPL_DAOACK_D_SHIFT 7
645 #define RPL_DAOACK_D_MASK (1 << RPL_DAOACK_D_SHIFT)
646 #define RPL_DAOACK_D(X) (((X)&RPL_DAOACK_D_MASK) >> RPL_DAOACK_D_SHIFT)
648 static const struct tok icmp6_type_values
[] = {
649 { ICMP6_DST_UNREACH
, "destination unreachable"},
650 { ICMP6_PACKET_TOO_BIG
, "packet too big"},
651 { ICMP6_TIME_EXCEEDED
, "time exceeded in-transit"},
652 { ICMP6_PARAM_PROB
, "parameter problem"},
653 { ICMP6_ECHO_REQUEST
, "echo request"},
654 { ICMP6_ECHO_REPLY
, "echo reply"},
655 { MLD6_LISTENER_QUERY
, "multicast listener query"},
656 { MLD6_LISTENER_REPORT
, "multicast listener report"},
657 { MLD6_LISTENER_DONE
, "multicast listener done"},
658 { ND_ROUTER_SOLICIT
, "router solicitation"},
659 { ND_ROUTER_ADVERT
, "router advertisement"},
660 { ND_NEIGHBOR_SOLICIT
, "neighbor solicitation"},
661 { ND_NEIGHBOR_ADVERT
, "neighbor advertisement"},
662 { ND_REDIRECT
, "redirect"},
663 { ICMP6_ROUTER_RENUMBERING
, "router renumbering"},
664 { IND_SOLICIT
, "inverse neighbor solicitation"},
665 { IND_ADVERT
, "inverse neighbor advertisement"},
666 { MLDV2_LISTENER_REPORT
, "multicast listener report v2"},
667 { ICMP6_HADISCOV_REQUEST
, "ha discovery request"},
668 { ICMP6_HADISCOV_REPLY
, "ha discovery reply"},
669 { ICMP6_MOBILEPREFIX_SOLICIT
, "mobile router solicitation"},
670 { ICMP6_MOBILEPREFIX_ADVERT
, "mobile router advertisement"},
671 { ICMP6_WRUREQUEST
, "who-are-you request"},
672 { ICMP6_WRUREPLY
, "who-are-you reply"},
673 { ICMP6_NI_QUERY
, "node information query"},
674 { ICMP6_NI_REPLY
, "node information reply"},
675 { MLD6_MTRACE
, "mtrace message"},
676 { MLD6_MTRACE_RESP
, "mtrace response"},
677 { ND_RPL_MESSAGE
, "RPL"},
681 static const struct tok icmp6_dst_unreach_code_values
[] = {
682 { ICMP6_DST_UNREACH_NOROUTE
, "unreachable route" },
683 { ICMP6_DST_UNREACH_ADMIN
, " unreachable prohibited"},
684 { ICMP6_DST_UNREACH_BEYONDSCOPE
, "beyond scope"},
685 { ICMP6_DST_UNREACH_ADDR
, "unreachable address"},
686 { ICMP6_DST_UNREACH_NOPORT
, "unreachable port"},
690 static const struct tok icmp6_opt_pi_flag_values
[] = {
691 { ND_OPT_PI_FLAG_ONLINK
, "onlink" },
692 { ND_OPT_PI_FLAG_AUTO
, "auto" },
693 { ND_OPT_PI_FLAG_ROUTER
, "router" },
697 static const struct tok icmp6_opt_ra_flag_values
[] = {
698 { ND_RA_FLAG_MANAGED
, "managed" },
699 { ND_RA_FLAG_OTHER
, "other stateful"},
700 { ND_RA_FLAG_HOME_AGENT
, "home agent"},
704 static const struct tok icmp6_nd_na_flag_values
[] = {
705 { ND_NA_FLAG_ROUTER
, "router" },
706 { ND_NA_FLAG_SOLICITED
, "solicited" },
707 { ND_NA_FLAG_OVERRIDE
, "override" },
712 static const struct tok icmp6_opt_values
[] = {
713 { ND_OPT_SOURCE_LINKADDR
, "source link-address"},
714 { ND_OPT_TARGET_LINKADDR
, "destination link-address"},
715 { ND_OPT_PREFIX_INFORMATION
, "prefix info"},
716 { ND_OPT_REDIRECTED_HEADER
, "redirected header"},
717 { ND_OPT_MTU
, "mtu"},
718 { ND_OPT_RDNSS
, "rdnss"},
719 { ND_OPT_DNSSL
, "dnssl"},
720 { ND_OPT_ADVINTERVAL
, "advertisement interval"},
721 { ND_OPT_HOMEAGENT_INFO
, "homeagent information"},
722 { ND_OPT_ROUTE_INFO
, "route info"},
726 /* mldv2 report types */
727 static const struct tok mldv2report2str
[] = {
740 static const char *rtpref_str
[] = {
747 return rtpref_str
[((v
& ND_RA_FLAG_RTPREF_MASK
) >> 3) & 0xff];
751 get_lifetime(uint32_t v
)
755 if (v
== (uint32_t)~0UL)
758 nd_snprintf(buf
, sizeof(buf
), "%us", v
);
764 print_lladdr(netdissect_options
*ndo
, const uint8_t *p
, size_t l
)
766 const uint8_t *ep
, *q
;
770 while (l
> 0 && q
< ep
) {
773 ND_PRINT("%02x", EXTRACT_U_1(q
));
779 static uint16_t icmp6_cksum(netdissect_options
*ndo
, const struct ip6_hdr
*ip6
,
780 const struct icmp6_hdr
*icp
, u_int len
)
782 return nextproto6_cksum(ndo
, ip6
, (const uint8_t *)(const void *)icp
, len
, len
,
786 static const struct tok rpl_mop_values
[] = {
787 { RPL_DIO_NONSTORING
, "nonstoring"},
788 { RPL_DIO_STORING
, "storing"},
789 { RPL_DIO_NONSTORING_MULTICAST
, "nonstoring-multicast"},
790 { RPL_DIO_STORING_MULTICAST
, "storing-multicast"},
794 static const struct tok rpl_subopt_values
[] = {
795 { RPL_OPT_PAD1
, "pad1"},
796 { RPL_OPT_PADN
, "padN"},
797 { RPL_DIO_METRICS
, "metrics"},
798 { RPL_DIO_ROUTINGINFO
, "routinginfo"},
799 { RPL_DIO_CONFIG
, "config"},
800 { RPL_DAO_RPLTARGET
, "rpltarget"},
801 { RPL_DAO_TRANSITINFO
, "transitinfo"},
802 { RPL_DIO_DESTPREFIX
, "destprefix"},
803 { RPL_DAO_RPLTARGET_DESC
, "rpltargetdesc"},
808 rpl_printopts(netdissect_options
*ndo
, const uint8_t *opts
, u_int length
)
810 const struct rpl_genoption
*opt
;
814 while (length
!= 0) {
815 opt
= (const struct rpl_genoption
*)opts
;
816 ND_TCHECK_1(opt
->rpl_dio_type
);
817 dio_type
= EXTRACT_U_1(opt
->rpl_dio_type
);
818 if (dio_type
== RPL_OPT_PAD1
) {
820 ND_PRINT(" opt:pad1");
822 if (length
< RPL_GENOPTION_LEN
)
824 optlen
= EXTRACT_U_1(opt
->rpl_dio_len
)+RPL_GENOPTION_LEN
;
825 ND_PRINT(" opt:%s len:%u ",
826 tok2str(rpl_subopt_values
, "subopt:%u", dio_type
),
828 ND_TCHECK_LEN(opt
, optlen
);
831 if (ndo
->ndo_vflag
> 2) {
834 opts
+ RPL_GENOPTION_LEN
, /* content of DIO option */
835 optlen
- RPL_GENOPTION_LEN
);
848 rpl_dio_print(netdissect_options
*ndo
,
849 const u_char
*bp
, u_int length
)
851 const struct nd_rpl_dio
*dio
= (const struct nd_rpl_dio
*)bp
;
852 const char *dagid_str
;
855 dagid_str
= ip6addr_string (ndo
, dio
->rpl_dagid
);
857 ND_PRINT(" [dagid:%s,seq:%u,instance:%u,rank:%u,%smop:%s,prf:%u]",
859 EXTRACT_U_1(dio
->rpl_dtsn
),
860 EXTRACT_U_1(dio
->rpl_instanceid
),
861 EXTRACT_BE_U_2(dio
->rpl_dagrank
),
862 RPL_DIO_GROUNDED(EXTRACT_U_1(dio
->rpl_mopprf
)) ? "grounded,":"",
863 tok2str(rpl_mop_values
, "mop%u", RPL_DIO_MOP(EXTRACT_U_1(dio
->rpl_mopprf
))),
864 RPL_DIO_PRF(EXTRACT_U_1(dio
->rpl_mopprf
)));
866 if(ndo
->ndo_vflag
> 1) {
867 rpl_printopts(ndo
, bp
+ sizeof(struct nd_rpl_dio
),
868 length
- sizeof(struct nd_rpl_dio
));
877 rpl_dao_print(netdissect_options
*ndo
,
878 const u_char
*bp
, u_int length
)
880 const struct nd_rpl_dao
*dao
= (const struct nd_rpl_dao
*)bp
;
881 const char *dagid_str
= "<elided>";
885 if (length
< ND_RPL_DAO_MIN_LEN
)
888 bp
+= ND_RPL_DAO_MIN_LEN
;
889 length
-= ND_RPL_DAO_MIN_LEN
;
890 rpl_flags
= EXTRACT_U_1(dao
->rpl_flags
);
891 if(RPL_DAO_D(rpl_flags
)) {
892 ND_TCHECK_LEN(dao
->rpl_dagid
, DAGID_LEN
);
893 if (length
< DAGID_LEN
)
895 dagid_str
= ip6addr_string (ndo
, dao
->rpl_dagid
);
900 ND_PRINT(" [dagid:%s,seq:%u,instance:%u%s%s,%02x]",
902 EXTRACT_U_1(dao
->rpl_daoseq
),
903 EXTRACT_U_1(dao
->rpl_instanceid
),
904 RPL_DAO_K(rpl_flags
) ? ",acK":"",
905 RPL_DAO_D(rpl_flags
) ? ",Dagid":"",
908 if(ndo
->ndo_vflag
> 1) {
909 rpl_printopts(ndo
, bp
, length
);
918 ND_PRINT(" [|length too short]");
923 rpl_daoack_print(netdissect_options
*ndo
,
924 const u_char
*bp
, u_int length
)
926 const struct nd_rpl_daoack
*daoack
= (const struct nd_rpl_daoack
*)bp
;
927 const char *dagid_str
= "<elided>";
929 ND_TCHECK_LEN(daoack
, ND_RPL_DAOACK_MIN_LEN
);
930 if (length
< ND_RPL_DAOACK_MIN_LEN
)
933 bp
+= ND_RPL_DAOACK_MIN_LEN
;
934 length
-= ND_RPL_DAOACK_MIN_LEN
;
935 if(RPL_DAOACK_D(EXTRACT_U_1(daoack
->rpl_flags
))) {
936 ND_TCHECK_LEN(daoack
->rpl_dagid
, DAGID_LEN
);
937 if (length
< DAGID_LEN
)
939 dagid_str
= ip6addr_string (ndo
, daoack
->rpl_dagid
);
944 ND_PRINT(" [dagid:%s,seq:%u,instance:%u,status:%u]",
946 EXTRACT_U_1(daoack
->rpl_daoseq
),
947 EXTRACT_U_1(daoack
->rpl_instanceid
),
948 EXTRACT_U_1(daoack
->rpl_status
));
950 /* no officially defined options for DAOACK, but print any we find */
951 if(ndo
->ndo_vflag
> 1) {
952 rpl_printopts(ndo
, bp
, length
);
961 ND_PRINT(" [|dao-length too short]");
966 rpl_print(netdissect_options
*ndo
,
968 const u_char
*bp
, u_int length
)
970 int secured
= icmp6_code
& 0x80;
971 int basecode
= icmp6_code
& 0x7f;
974 ND_PRINT(", (SEC) [worktodo]");
976 * the next header pointer needs to move forward to
977 * skip the secure part.
986 ND_PRINT("DODAG Information Solicitation");
991 ND_PRINT("DODAG Information Object");
993 rpl_dio_print(ndo
, bp
, length
);
997 ND_PRINT("Destination Advertisement Object");
999 rpl_dao_print(ndo
, bp
, length
);
1002 case ND_RPL_DAO_ACK
:
1003 ND_PRINT("Destination Advertisement Object Ack");
1004 if(ndo
->ndo_vflag
) {
1005 rpl_daoack_print(ndo
, bp
, length
);
1009 ND_PRINT("RPL message, unknown code %u",icmp6_code
);
1016 nd_print_trunc(ndo
);
1024 icmp6_print(netdissect_options
*ndo
,
1025 const u_char
*bp
, u_int length
, const u_char
*bp2
, int fragmented
)
1027 const struct icmp6_hdr
*dp
;
1028 uint8_t icmp6_type
, icmp6_code
;
1029 const struct ip6_hdr
*ip
;
1030 const struct ip6_hdr
*oip
;
1031 const struct udphdr
*ouh
;
1036 ndo
->ndo_protocol
= "icmp6";
1037 dp
= (const struct icmp6_hdr
*)bp
;
1038 ip
= (const struct ip6_hdr
*)bp2
;
1039 oip
= (const struct ip6_hdr
*)(dp
+ 1);
1040 /* 'ep' points to the end of available data. */
1041 ep
= ndo
->ndo_snapend
;
1043 ND_PRINT("ICMP6, length 0");
1044 nd_print_invalid(ndo
);
1048 if (ndo
->ndo_vflag
&& !fragmented
) {
1049 uint16_t sum
, udp_sum
;
1051 if (ND_TTEST_LEN(bp
, length
)) {
1052 ND_TCHECK_2(dp
->icmp6_cksum
);
1053 udp_sum
= EXTRACT_BE_U_2(dp
->icmp6_cksum
);
1054 sum
= icmp6_cksum(ndo
, ip
, dp
, length
);
1056 ND_PRINT("[bad icmp6 cksum 0x%04x -> 0x%04x!] ",
1058 in_cksum_shouldbe(udp_sum
, sum
));
1060 ND_PRINT("[icmp6 sum ok] ");
1064 ND_TCHECK_1(dp
->icmp6_type
);
1065 icmp6_type
= EXTRACT_U_1(dp
->icmp6_type
);
1066 ND_PRINT("ICMP6, %s", tok2str(icmp6_type_values
,"unknown icmp6 type (%u)",icmp6_type
));
1068 /* display cosmetics: print the packet length for printer that use the vflag now */
1069 if (ndo
->ndo_vflag
&& (icmp6_type
== ND_ROUTER_SOLICIT
||
1070 icmp6_type
== ND_ROUTER_ADVERT
||
1071 icmp6_type
== ND_NEIGHBOR_ADVERT
||
1072 icmp6_type
== ND_NEIGHBOR_SOLICIT
||
1073 icmp6_type
== ND_REDIRECT
||
1074 icmp6_type
== ICMP6_HADISCOV_REPLY
||
1075 icmp6_type
== ICMP6_MOBILEPREFIX_ADVERT
))
1076 ND_PRINT(", length %u", length
);
1078 ND_TCHECK_1(dp
->icmp6_code
);
1079 icmp6_code
= EXTRACT_U_1(dp
->icmp6_code
);
1081 switch (icmp6_type
) {
1082 case ICMP6_DST_UNREACH
:
1083 ND_TCHECK_16(oip
->ip6_dst
);
1084 ND_PRINT(", %s", tok2str(icmp6_dst_unreach_code_values
,"unknown unreach code (%u)",icmp6_code
));
1085 switch (icmp6_code
) {
1087 case ICMP6_DST_UNREACH_NOROUTE
: /* fall through */
1088 case ICMP6_DST_UNREACH_ADMIN
:
1089 case ICMP6_DST_UNREACH_ADDR
:
1090 ND_PRINT(" %s",ip6addr_string(ndo
, oip
->ip6_dst
));
1092 case ICMP6_DST_UNREACH_BEYONDSCOPE
:
1093 ND_PRINT(" %s, source address %s",
1094 ip6addr_string(ndo
, oip
->ip6_dst
),
1095 ip6addr_string(ndo
, oip
->ip6_src
));
1097 case ICMP6_DST_UNREACH_NOPORT
:
1098 if ((ouh
= get_upperlayer(ndo
, (const u_char
*)oip
, &prot
))
1102 dport
= EXTRACT_BE_U_2(ouh
->uh_dport
);
1105 ND_PRINT(", %s tcp port %s",
1106 ip6addr_string(ndo
, oip
->ip6_dst
),
1107 tcpport_string(ndo
, dport
));
1110 ND_PRINT(", %s udp port %s",
1111 ip6addr_string(ndo
, oip
->ip6_dst
),
1112 udpport_string(ndo
, dport
));
1115 ND_PRINT(", %s protocol %u port %u unreachable",
1116 ip6addr_string(ndo
, oip
->ip6_dst
),
1122 if (ndo
->ndo_vflag
<= 1) {
1123 print_unknown_data(ndo
, bp
,"\n\t",length
);
1129 case ICMP6_PACKET_TOO_BIG
:
1130 ND_TCHECK_4(dp
->icmp6_mtu
);
1131 ND_PRINT(", mtu %u", EXTRACT_BE_U_4(dp
->icmp6_mtu
));
1133 case ICMP6_TIME_EXCEEDED
:
1134 ND_TCHECK_16(oip
->ip6_dst
);
1135 switch (icmp6_code
) {
1136 case ICMP6_TIME_EXCEED_TRANSIT
:
1138 ip6addr_string(ndo
, oip
->ip6_dst
));
1140 case ICMP6_TIME_EXCEED_REASSEMBLY
:
1141 ND_PRINT(" (reassembly)");
1144 ND_PRINT(", unknown code (%u)", icmp6_code
);
1148 case ICMP6_PARAM_PROB
:
1149 ND_TCHECK_16(oip
->ip6_dst
);
1150 switch (icmp6_code
) {
1151 case ICMP6_PARAMPROB_HEADER
:
1152 ND_PRINT(", erroneous - octet %u", EXTRACT_BE_U_4(dp
->icmp6_pptr
));
1154 case ICMP6_PARAMPROB_NEXTHEADER
:
1155 ND_PRINT(", next header - octet %u", EXTRACT_BE_U_4(dp
->icmp6_pptr
));
1157 case ICMP6_PARAMPROB_OPTION
:
1158 ND_PRINT(", option - octet %u", EXTRACT_BE_U_4(dp
->icmp6_pptr
));
1161 ND_PRINT(", code-#%u",
1166 case ICMP6_ECHO_REQUEST
:
1167 case ICMP6_ECHO_REPLY
:
1168 /* The check below covers both icmp6_id and icmp6_seq. */
1169 ND_TCHECK_2(dp
->icmp6_seq
);
1170 ND_PRINT(", id %u, seq %u", EXTRACT_BE_U_2(dp
->icmp6_id
), EXTRACT_BE_U_2(dp
->icmp6_seq
));
1172 case ICMP6_MEMBERSHIP_QUERY
:
1173 if (length
== MLD_MINLEN
) {
1174 mld6_print(ndo
, (const u_char
*)dp
);
1175 } else if (length
>= MLDV2_MINLEN
) {
1177 mldv2_query_print(ndo
, (const u_char
*)dp
, length
);
1179 ND_PRINT(" unknown-version (len %u) ", length
);
1182 case ICMP6_MEMBERSHIP_REPORT
:
1183 mld6_print(ndo
, (const u_char
*)dp
);
1185 case ICMP6_MEMBERSHIP_REDUCTION
:
1186 mld6_print(ndo
, (const u_char
*)dp
);
1188 case ND_ROUTER_SOLICIT
:
1190 if (ndo
->ndo_vflag
) {
1191 if (icmp6_opt_print(ndo
, (const u_char
*)dp
+ RTSOLLEN
,
1192 length
- RTSOLLEN
) == -1)
1196 case ND_ROUTER_ADVERT
:
1198 if (ndo
->ndo_vflag
) {
1199 const struct nd_router_advert
*p
;
1201 p
= (const struct nd_router_advert
*)dp
;
1202 ND_TCHECK_4(p
->nd_ra_retransmit
);
1203 ND_PRINT("\n\thop limit %u, Flags [%s]"
1204 ", pref %s, router lifetime %us, reachable time %ums, retrans timer %ums",
1205 EXTRACT_U_1(p
->nd_ra_curhoplimit
),
1206 bittok2str(icmp6_opt_ra_flag_values
,"none",EXTRACT_U_1(p
->nd_ra_flags_reserved
)),
1207 get_rtpref(EXTRACT_U_1(p
->nd_ra_flags_reserved
)),
1208 EXTRACT_BE_U_2(p
->nd_ra_router_lifetime
),
1209 EXTRACT_BE_U_4(p
->nd_ra_reachable
),
1210 EXTRACT_BE_U_4(p
->nd_ra_retransmit
));
1212 if (icmp6_opt_print(ndo
, (const u_char
*)dp
+ RTADVLEN
,
1213 length
- RTADVLEN
) == -1)
1217 case ND_NEIGHBOR_SOLICIT
:
1219 const struct nd_neighbor_solicit
*p
;
1220 p
= (const struct nd_neighbor_solicit
*)dp
;
1221 ND_TCHECK_16(p
->nd_ns_target
);
1222 ND_PRINT(", who has %s", ip6addr_string(ndo
, p
->nd_ns_target
));
1223 if (ndo
->ndo_vflag
) {
1225 if (icmp6_opt_print(ndo
, (const u_char
*)dp
+ NDSOLLEN
,
1226 length
- NDSOLLEN
) == -1)
1231 case ND_NEIGHBOR_ADVERT
:
1233 const struct nd_neighbor_advert
*p
;
1235 p
= (const struct nd_neighbor_advert
*)dp
;
1236 ND_TCHECK_16(p
->nd_na_target
);
1237 ND_PRINT(", tgt is %s",
1238 ip6addr_string(ndo
, p
->nd_na_target
));
1239 if (ndo
->ndo_vflag
) {
1240 ND_PRINT(", Flags [%s]",
1241 bittok2str(icmp6_nd_na_flag_values
,
1243 EXTRACT_BE_U_4(p
->nd_na_flags_reserved
)));
1245 if (icmp6_opt_print(ndo
, (const u_char
*)dp
+ NDADVLEN
,
1246 length
- NDADVLEN
) == -1)
1254 const struct nd_redirect
*p
;
1256 p
= (const struct nd_redirect
*)dp
;
1257 ND_TCHECK_16(p
->nd_rd_dst
);
1258 ND_PRINT(", %s", ip6addr_string(ndo
, p
->nd_rd_dst
));
1259 ND_TCHECK_16(p
->nd_rd_target
);
1260 ND_PRINT(" to %s", ip6addr_string(ndo
, p
->nd_rd_target
));
1261 #define REDIRECTLEN 40
1262 if (ndo
->ndo_vflag
) {
1263 if (icmp6_opt_print(ndo
, (const u_char
*)dp
+ REDIRECTLEN
,
1264 length
- REDIRECTLEN
) == -1)
1270 case ICMP6_ROUTER_RENUMBERING
:
1271 icmp6_rrenum_print(ndo
, bp
, ep
);
1273 case ICMP6_NI_QUERY
:
1274 case ICMP6_NI_REPLY
:
1275 icmp6_nodeinfo_print(ndo
, length
, bp
, ep
);
1280 case ICMP6_V2_MEMBERSHIP_REPORT
:
1281 mldv2_report_print(ndo
, (const u_char
*) dp
, length
);
1283 case ICMP6_MOBILEPREFIX_SOLICIT
: /* fall through */
1284 case ICMP6_HADISCOV_REQUEST
:
1285 ND_TCHECK_2(dp
->icmp6_data16
[0]);
1286 ND_PRINT(", id 0x%04x", EXTRACT_BE_U_2(dp
->icmp6_data16
[0]));
1288 case ICMP6_HADISCOV_REPLY
:
1289 if (ndo
->ndo_vflag
) {
1293 ND_TCHECK_2(dp
->icmp6_data16
[0]);
1294 ND_PRINT(", id 0x%04x", EXTRACT_BE_U_2(dp
->icmp6_data16
[0]));
1295 cp
= (const u_char
*)dp
+ length
;
1296 p
= (const u_char
*)(dp
+ 1);
1299 ND_PRINT(", %s", ip6addr_string(ndo
, p
));
1304 case ICMP6_MOBILEPREFIX_ADVERT
:
1305 if (ndo
->ndo_vflag
) {
1308 ND_TCHECK_2(dp
->icmp6_data16
[0]);
1309 ND_PRINT(", id 0x%04x", EXTRACT_BE_U_2(dp
->icmp6_data16
[0]));
1310 ND_TCHECK_2(dp
->icmp6_data16
[1]);
1311 flags
= EXTRACT_BE_U_2(dp
->icmp6_data16
[1]);
1319 if (icmp6_opt_print(ndo
, (const u_char
*)dp
+ MPADVLEN
,
1320 length
- MPADVLEN
) == -1)
1324 case ND_RPL_MESSAGE
:
1325 /* plus 4, because struct icmp6_hdr contains 4 bytes of icmp payload */
1326 rpl_print(ndo
, icmp6_code
, dp
->icmp6_data
, length
-sizeof(struct icmp6_hdr
)+4);
1329 ND_PRINT(", length %u", length
);
1330 if (ndo
->ndo_vflag
<= 1)
1331 print_unknown_data(ndo
, bp
,"\n\t", length
);
1334 if (!ndo
->ndo_vflag
)
1335 ND_PRINT(", length %u", length
);
1338 nd_print_trunc(ndo
);
1341 static const struct udphdr
*
1342 get_upperlayer(netdissect_options
*ndo
, const u_char
*bp
, u_int
*prot
)
1345 const struct ip6_hdr
*ip6
= (const struct ip6_hdr
*)bp
;
1346 const struct udphdr
*uh
;
1347 const struct ip6_hbh
*hbh
;
1348 const struct ip6_frag
*fragh
;
1349 const struct ah
*ah
;
1353 /* 'ep' points to the end of available data. */
1354 ep
= ndo
->ndo_snapend
;
1356 if (!ND_TTEST_1(ip6
->ip6_nxt
))
1359 nh
= EXTRACT_U_1(ip6
->ip6_nxt
);
1360 hlen
= sizeof(struct ip6_hdr
);
1368 uh
= (const struct udphdr
*)bp
;
1369 if (ND_TTEST_2(uh
->uh_dport
)) {
1377 case IPPROTO_HOPOPTS
:
1378 case IPPROTO_DSTOPTS
:
1379 case IPPROTO_ROUTING
:
1380 hbh
= (const struct ip6_hbh
*)bp
;
1381 if (!ND_TTEST_1(hbh
->ip6h_len
))
1383 nh
= EXTRACT_U_1(hbh
->ip6h_nxt
);
1384 hlen
= (EXTRACT_U_1(hbh
->ip6h_len
) + 1) << 3;
1387 case IPPROTO_FRAGMENT
: /* this should be odd, but try anyway */
1388 fragh
= (const struct ip6_frag
*)bp
;
1389 if (!ND_TTEST_2(fragh
->ip6f_offlg
))
1391 /* fragments with non-zero offset are meaningless */
1392 if ((EXTRACT_BE_U_2(fragh
->ip6f_offlg
) & IP6F_OFF_MASK
) != 0)
1394 nh
= EXTRACT_U_1(fragh
->ip6f_nxt
);
1395 hlen
= sizeof(struct ip6_frag
);
1399 ah
= (const struct ah
*)bp
;
1400 if (!ND_TTEST_1(ah
->ah_len
))
1402 nh
= EXTRACT_U_1(ah
->ah_nxt
);
1403 hlen
= (EXTRACT_U_1(ah
->ah_len
) + 2) << 2;
1406 default: /* unknown or undecodable header */
1407 *prot
= nh
; /* meaningless, but set here anyway */
1412 return(NULL
); /* should be notreached, though */
1416 icmp6_opt_print(netdissect_options
*ndo
, const u_char
*bp
, int resid
)
1418 const struct nd_opt_hdr
*op
;
1419 uint8_t opt_type
, opt_len
;
1420 const struct nd_opt_prefix_info
*opp
;
1421 const struct nd_opt_mtu
*opm
;
1422 const struct nd_opt_rdnss
*oprd
;
1423 const struct nd_opt_dnssl
*opds
;
1424 const struct nd_opt_advinterval
*opa
;
1425 const struct nd_opt_homeagent_info
*oph
;
1426 const struct nd_opt_route_info
*opri
;
1427 const u_char
*cp
, *ep
, *domp
;
1428 struct in6_addr in6
;
1433 /* 'ep' points to the end of available data. */
1434 ep
= ndo
->ndo_snapend
;
1437 op
= (const struct nd_opt_hdr
*)cp
;
1439 ND_TCHECK_1(op
->nd_opt_len
);
1442 opt_type
= EXTRACT_U_1(op
->nd_opt_type
);
1443 opt_len
= EXTRACT_U_1(op
->nd_opt_len
);
1446 if (cp
+ (opt_len
<< 3) > ep
)
1449 ND_PRINT("\n\t %s option (%u), length %u (%u): ",
1450 tok2str(icmp6_opt_values
, "unknown", opt_type
),
1456 case ND_OPT_SOURCE_LINKADDR
:
1457 l
= (opt_len
<< 3) - 2;
1458 print_lladdr(ndo
, cp
+ 2, l
);
1460 case ND_OPT_TARGET_LINKADDR
:
1461 l
= (opt_len
<< 3) - 2;
1462 print_lladdr(ndo
, cp
+ 2, l
);
1464 case ND_OPT_PREFIX_INFORMATION
:
1465 opp
= (const struct nd_opt_prefix_info
*)op
;
1466 ND_TCHECK_16(opp
->nd_opt_pi_prefix
);
1467 ND_PRINT("%s/%u%s, Flags [%s], valid time %s",
1468 ip6addr_string(ndo
, opp
->nd_opt_pi_prefix
),
1469 EXTRACT_U_1(opp
->nd_opt_pi_prefix_len
),
1470 (opt_len
!= 4) ? "badlen" : "",
1471 bittok2str(icmp6_opt_pi_flag_values
, "none", EXTRACT_U_1(opp
->nd_opt_pi_flags_reserved
)),
1472 get_lifetime(EXTRACT_BE_U_4(opp
->nd_opt_pi_valid_time
)));
1473 ND_PRINT(", pref. time %s", get_lifetime(EXTRACT_BE_U_4(opp
->nd_opt_pi_preferred_time
)));
1475 case ND_OPT_REDIRECTED_HEADER
:
1476 print_unknown_data(ndo
, bp
,"\n\t ",opt_len
<<3);
1480 opm
= (const struct nd_opt_mtu
*)op
;
1481 ND_TCHECK_4(opm
->nd_opt_mtu_mtu
);
1483 EXTRACT_BE_U_4(opm
->nd_opt_mtu_mtu
),
1484 (opt_len
!= 1) ? "bad option length" : "" );
1487 oprd
= (const struct nd_opt_rdnss
*)op
;
1488 l
= (opt_len
- 1) / 2;
1489 ND_PRINT(" lifetime %us,",
1490 EXTRACT_BE_U_4(oprd
->nd_opt_rdnss_lifetime
));
1491 for (i
= 0; i
< l
; i
++) {
1492 ND_TCHECK_16(oprd
->nd_opt_rdnss_addr
[i
]);
1493 ND_PRINT(" addr: %s",
1494 ip6addr_string(ndo
, oprd
->nd_opt_rdnss_addr
[i
]));
1498 opds
= (const struct nd_opt_dnssl
*)op
;
1499 ND_PRINT(" lifetime %us, domain(s):",
1500 EXTRACT_BE_U_4(opds
->nd_opt_dnssl_lifetime
));
1501 domp
= cp
+ 8; /* domain names, variable-sized, RFC1035-encoded */
1502 while (domp
< cp
+ (opt_len
<< 3) && EXTRACT_U_1(domp
) != '\0')
1505 if ((domp
= ns_nprint(ndo
, domp
, bp
)) == NULL
)
1509 case ND_OPT_ADVINTERVAL
:
1510 opa
= (const struct nd_opt_advinterval
*)op
;
1511 ND_TCHECK_4(opa
->nd_opt_adv_interval
);
1512 ND_PRINT(" %ums", EXTRACT_BE_U_4(opa
->nd_opt_adv_interval
));
1514 case ND_OPT_HOMEAGENT_INFO
:
1515 oph
= (const struct nd_opt_homeagent_info
*)op
;
1516 ND_TCHECK_2(oph
->nd_opt_hai_lifetime
);
1517 ND_PRINT(" preference %u, lifetime %u",
1518 EXTRACT_BE_U_2(oph
->nd_opt_hai_preference
),
1519 EXTRACT_BE_U_2(oph
->nd_opt_hai_lifetime
));
1521 case ND_OPT_ROUTE_INFO
:
1522 opri
= (const struct nd_opt_route_info
*)op
;
1523 ND_TCHECK_4(opri
->nd_opt_rti_lifetime
);
1524 memset(&in6
, 0, sizeof(in6
));
1529 ND_TCHECK_8(opri
+ 1);
1530 memcpy(&in6
, opri
+ 1, 8);
1533 ND_TCHECK_16(opri
+ 1);
1534 memcpy(&in6
, opri
+ 1, 16);
1539 ND_PRINT(" %s/%u", ip6addr_string(ndo
, (const u_char
*)&in6
),
1540 EXTRACT_U_1(opri
->nd_opt_rti_prefixlen
));
1541 ND_PRINT(", pref=%s", get_rtpref(EXTRACT_U_1(opri
->nd_opt_rti_flags
)));
1542 ND_PRINT(", lifetime=%s",
1543 get_lifetime(EXTRACT_BE_U_4(opri
->nd_opt_rti_lifetime
)));
1546 if (ndo
->ndo_vflag
<= 1) {
1547 print_unknown_data(ndo
,cp
+2,"\n\t ", (opt_len
<< 3) - 2); /* skip option header */
1552 /* do we want to see an additional hexdump ? */
1553 if (ndo
->ndo_vflag
> 1)
1554 print_unknown_data(ndo
, cp
+2,"\n\t ", (opt_len
<< 3) - 2); /* skip option header */
1557 resid
-= opt_len
<< 3;
1566 mld6_print(netdissect_options
*ndo
, const u_char
*bp
)
1568 const struct mld6_hdr
*mp
= (const struct mld6_hdr
*)bp
;
1571 /* 'ep' points to the end of available data. */
1572 ep
= ndo
->ndo_snapend
;
1574 if ((const u_char
*)mp
+ sizeof(*mp
) > ep
)
1577 ND_PRINT("max resp delay: %u ", EXTRACT_BE_U_2(mp
->mld6_maxdelay
));
1578 ND_PRINT("addr: %s", ip6addr_string(ndo
, mp
->mld6_addr
));
1582 mldv2_report_print(netdissect_options
*ndo
, const u_char
*bp
, u_int len
)
1584 const struct icmp6_hdr
*icp
= (const struct icmp6_hdr
*) bp
;
1585 u_int group
, nsrcs
, ngroups
;
1588 /* Minimum len is 8 */
1590 ND_PRINT(" [invalid len %u]", len
);
1594 ND_TCHECK_2(icp
->icmp6_data16
[1]);
1595 ngroups
= EXTRACT_BE_U_2(icp
->icmp6_data16
[1]);
1596 ND_PRINT(", %u group record(s)", ngroups
);
1597 if (ndo
->ndo_vflag
> 0) {
1598 /* Print the group records */
1600 for (i
= 0; i
< ngroups
; i
++) {
1601 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
1602 if (len
< group
+ 20) {
1603 ND_PRINT(" [invalid number of groups]");
1606 ND_TCHECK_LEN(bp
+ 4 + group
, sizeof(nd_ipv6
));
1607 ND_PRINT(" [gaddr %s", ip6addr_string(ndo
, bp
+ group
+ 4));
1608 ND_PRINT(" %s", tok2str(mldv2report2str
, " [v2-report-#%u]",
1609 EXTRACT_U_1(bp
+ group
)));
1610 nsrcs
= EXTRACT_BE_U_2(bp
+ group
+ 2);
1611 /* Check the number of sources and print them */
1612 if (len
< group
+ 20 + (nsrcs
* sizeof(nd_ipv6
))) {
1613 ND_PRINT(" [invalid number of sources %u]", nsrcs
);
1616 if (ndo
->ndo_vflag
== 1)
1617 ND_PRINT(", %u source(s)", nsrcs
);
1619 /* Print the sources */
1621 for (j
= 0; j
< nsrcs
; j
++) {
1622 ND_TCHECK_LEN(bp
+ group
+ 20 + (j
* sizeof(nd_ipv6
)),
1624 ND_PRINT(" %s", ip6addr_string(ndo
, bp
+ group
+ 20 + (j
* sizeof(nd_ipv6
))));
1628 /* Next group record */
1629 group
+= 20 + nsrcs
* sizeof(nd_ipv6
);
1635 nd_print_trunc(ndo
);
1640 mldv2_query_print(netdissect_options
*ndo
, const u_char
*bp
, u_int len
)
1642 const struct icmp6_hdr
*icp
= (const struct icmp6_hdr
*) bp
;
1648 /* Minimum len is 28 */
1650 ND_PRINT(" [invalid len %u]", len
);
1653 ND_TCHECK_2(icp
->icmp6_data16
[0]);
1654 mrc
= EXTRACT_BE_U_2(icp
->icmp6_data16
[0]);
1658 mrt
= ((mrc
& 0x0fff) | 0x1000) << (((mrc
& 0x7000) >> 12) + 3);
1660 if (ndo
->ndo_vflag
) {
1661 ND_PRINT(" [max resp delay=%u]", mrt
);
1663 ND_TCHECK_LEN(bp
+ 8, sizeof(nd_ipv6
));
1664 ND_PRINT(" [gaddr %s", ip6addr_string(ndo
, bp
+ 8));
1666 if (ndo
->ndo_vflag
) {
1667 ND_TCHECK_1(bp
+ 25);
1668 if (EXTRACT_U_1(bp
+ 24) & 0x08) {
1671 if (EXTRACT_U_1(bp
+ 24) & 0x07) {
1672 ND_PRINT(" robustness=%u", EXTRACT_U_1(bp
+ 24) & 0x07);
1674 if (EXTRACT_U_1(bp
+ 25) < 128) {
1675 qqi
= EXTRACT_U_1(bp
+ 25);
1677 qqi
= ((EXTRACT_U_1(bp
+ 25) & 0x0f) | 0x10) <<
1678 (((EXTRACT_U_1(bp
+ 25) & 0x70) >> 4) + 3);
1680 ND_PRINT(" qqi=%u", qqi
);
1683 ND_TCHECK_2(bp
+ 26);
1684 nsrcs
= EXTRACT_BE_U_2(bp
+ 26);
1686 if (len
< 28 + nsrcs
* sizeof(nd_ipv6
))
1687 ND_PRINT(" [invalid number of sources]");
1688 else if (ndo
->ndo_vflag
> 1) {
1690 for (i
= 0; i
< nsrcs
; i
++) {
1691 ND_TCHECK_LEN(bp
+ 28 + (i
* sizeof(nd_ipv6
)),
1693 ND_PRINT(" %s", ip6addr_string(ndo
, bp
+ 28 + (i
* sizeof(nd_ipv6
))));
1697 ND_PRINT(", %u source(s)", nsrcs
);
1702 nd_print_trunc(ndo
);
1707 dnsname_print(netdissect_options
*ndo
, const u_char
*cp
, const u_char
*ep
)
1711 /* DNS name decoding - no decompression */
1714 i
= EXTRACT_U_1(cp
);
1721 while (i
-- && cp
< ep
) {
1722 fn_print_char(ndo
, EXTRACT_U_1(cp
));
1725 if (cp
+ 1 < ep
&& EXTRACT_U_1(cp
))
1731 } else if (cp
+ 1 == ep
&& EXTRACT_U_1(cp
) == '\0') {
1744 icmp6_nodeinfo_print(netdissect_options
*ndo
, u_int icmp6len
, const u_char
*bp
, const u_char
*ep
)
1746 const struct icmp6_nodeinfo
*ni6
;
1747 const struct icmp6_hdr
*dp
;
1754 dp
= (const struct icmp6_hdr
*)bp
;
1755 ni6
= (const struct icmp6_nodeinfo
*)bp
;
1758 switch (EXTRACT_U_1(ni6
->ni_type
)) {
1759 case ICMP6_NI_QUERY
:
1760 if (siz
== sizeof(*dp
) + 4) {
1761 /* KAME who-are-you */
1762 ND_PRINT(" who-are-you request");
1765 ND_PRINT(" node information query");
1767 ND_TCHECK_LEN(dp
, sizeof(*ni6
));
1768 ni6
= (const struct icmp6_nodeinfo
*)dp
;
1769 ND_PRINT(" ("); /*)*/
1770 switch (EXTRACT_BE_U_2(ni6
->ni_qtype
)) {
1774 case NI_QTYPE_SUPTYPES
:
1775 ND_PRINT("supported qtypes");
1776 i
= EXTRACT_BE_U_2(ni6
->ni_flags
);
1778 ND_PRINT(" [%s]", (i
& 0x01) ? "C" : "");
1781 ND_PRINT("DNS name");
1783 case NI_QTYPE_NODEADDR
:
1784 ND_PRINT("node addresses");
1785 i
= EXTRACT_BE_U_2(ni6
->ni_flags
);
1788 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
1789 ND_PRINT(" [%s%s%s%s%s%s]",
1790 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1791 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1792 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1793 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1794 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1795 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "");
1798 ND_PRINT("unknown");
1802 if (EXTRACT_BE_U_2(ni6
->ni_qtype
) == NI_QTYPE_NOOP
||
1803 EXTRACT_BE_U_2(ni6
->ni_qtype
) == NI_QTYPE_SUPTYPES
) {
1804 if (siz
!= sizeof(*ni6
))
1806 ND_PRINT(", invalid len");
1813 /* XXX backward compat, icmp-name-lookup-03 */
1814 if (siz
== sizeof(*ni6
)) {
1815 ND_PRINT(", 03 draft");
1821 cp
= (const u_char
*)(ni6
+ 1);
1822 switch (EXTRACT_U_1(ni6
->ni_code
)) {
1823 case ICMP6_NI_SUBJ_IPV6
:
1824 if (!ND_TTEST_LEN(dp
, sizeof(*ni6
) + sizeof(nd_ipv6
)))
1826 if (siz
!= sizeof(*ni6
) + sizeof(nd_ipv6
)) {
1828 ND_PRINT(", invalid subject len");
1831 ND_PRINT(", subject=%s",
1832 ip6addr_string(ndo
, cp
));
1834 case ICMP6_NI_SUBJ_FQDN
:
1835 ND_PRINT(", subject=DNS name");
1836 if (EXTRACT_U_1(cp
) == ep
- cp
- 1) {
1837 /* icmp-name-lookup-03, pascal string */
1839 ND_PRINT(", 03 draft");
1843 fn_print_char(ndo
, EXTRACT_U_1(cp
));
1848 dnsname_print(ndo
, cp
, ep
);
1850 case ICMP6_NI_SUBJ_IPV4
:
1851 if (!ND_TTEST_LEN(dp
, sizeof(*ni6
) + sizeof(nd_ipv4
)))
1853 if (siz
!= sizeof(*ni6
) + sizeof(nd_ipv4
)) {
1855 ND_PRINT(", invalid subject len");
1858 ND_PRINT(", subject=%s",
1859 ipaddr_string(ndo
, cp
));
1862 ND_PRINT(", unknown subject");
1870 case ICMP6_NI_REPLY
:
1876 ND_TCHECK_LEN(dp
, sizeof(*ni6
));
1877 ni6
= (const struct icmp6_nodeinfo
*)dp
;
1878 ND_PRINT(" node information reply");
1879 ND_PRINT(" ("); /*)*/
1880 switch (EXTRACT_U_1(ni6
->ni_code
)) {
1881 case ICMP6_NI_SUCCESS
:
1882 if (ndo
->ndo_vflag
) {
1883 ND_PRINT("success");
1887 case ICMP6_NI_REFUSED
:
1888 ND_PRINT("refused");
1890 if (siz
!= sizeof(*ni6
))
1892 ND_PRINT(", invalid length");
1894 case ICMP6_NI_UNKNOWN
:
1895 ND_PRINT("unknown");
1897 if (siz
!= sizeof(*ni6
))
1899 ND_PRINT(", invalid length");
1903 if (EXTRACT_U_1(ni6
->ni_code
) != ICMP6_NI_SUCCESS
) {
1909 switch (EXTRACT_BE_U_2(ni6
->ni_qtype
)) {
1914 if (siz
!= sizeof(*ni6
))
1916 ND_PRINT(", invalid length");
1918 case NI_QTYPE_SUPTYPES
:
1921 ND_PRINT("supported qtypes");
1922 i
= EXTRACT_BE_U_2(ni6
->ni_flags
);
1924 ND_PRINT(" [%s]", (i
& 0x01) ? "C" : "");
1929 ND_PRINT("DNS name");
1930 cp
= (const u_char
*)(ni6
+ 1) + 4;
1932 if (EXTRACT_U_1(cp
) == ep
- cp
- 1) {
1933 /* icmp-name-lookup-03, pascal string */
1935 ND_PRINT(", 03 draft");
1939 fn_print_char(ndo
, EXTRACT_U_1(cp
));
1944 dnsname_print(ndo
, cp
, ep
);
1945 if ((EXTRACT_BE_U_2(ni6
->ni_flags
) & 0x01) != 0)
1946 ND_PRINT(" [TTL=%u]", EXTRACT_BE_U_4(ni6
+ 1));
1948 case NI_QTYPE_NODEADDR
:
1951 ND_PRINT("node addresses");
1954 if (i
+ sizeof(uint32_t) + sizeof(nd_ipv6
) > siz
)
1957 ip6addr_string(ndo
, bp
+ i
+ sizeof(uint32_t)),
1958 EXTRACT_BE_U_4(bp
+ i
));
1959 i
+= sizeof(uint32_t) + sizeof(nd_ipv6
);
1961 i
= EXTRACT_BE_U_2(ni6
->ni_flags
);
1964 ND_PRINT(" [%s%s%s%s%s%s%s]",
1965 (i
& NI_NODEADDR_FLAG_ANYCAST
) ? "a" : "",
1966 (i
& NI_NODEADDR_FLAG_GLOBAL
) ? "G" : "",
1967 (i
& NI_NODEADDR_FLAG_SITELOCAL
) ? "S" : "",
1968 (i
& NI_NODEADDR_FLAG_LINKLOCAL
) ? "L" : "",
1969 (i
& NI_NODEADDR_FLAG_COMPAT
) ? "C" : "",
1970 (i
& NI_NODEADDR_FLAG_ALL
) ? "A" : "",
1971 (i
& NI_NODEADDR_FLAG_TRUNCATE
) ? "T" : "");
1976 ND_PRINT("unknown");
1987 nd_print_trunc(ndo
);
1991 icmp6_rrenum_print(netdissect_options
*ndo
, const u_char
*bp
, const u_char
*ep
)
1993 const struct icmp6_router_renum
*rr6
;
1995 const struct rr_pco_match
*match
;
1996 const struct rr_pco_use
*use
;
1997 char hbuf
[NI_MAXHOST
];
2002 rr6
= (const struct icmp6_router_renum
*)bp
;
2003 cp
= (const char *)(rr6
+ 1);
2005 ND_TCHECK_4(rr6
->rr_reserved
);
2006 switch (EXTRACT_U_1(rr6
->rr_code
)) {
2007 case ICMP6_ROUTER_RENUMBERING_COMMAND
:
2008 ND_PRINT("router renum: command");
2010 case ICMP6_ROUTER_RENUMBERING_RESULT
:
2011 ND_PRINT("router renum: result");
2013 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
:
2014 ND_PRINT("router renum: sequence number reset");
2017 ND_PRINT("router renum: code-#%u", EXTRACT_U_1(rr6
->rr_code
));
2021 ND_PRINT(", seq=%u", EXTRACT_BE_U_4(rr6
->rr_seqnum
));
2023 if (ndo
->ndo_vflag
) {
2024 uint8_t rr_flags
= EXTRACT_U_1(rr6
->rr_flags
);
2025 #define F(x, y) (rr_flags & (x) ? (y) : "")
2026 ND_PRINT("["); /*]*/
2028 ND_PRINT("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST
, "T"),
2029 F(ICMP6_RR_FLAGS_REQRESULT
, "R"),
2030 F(ICMP6_RR_FLAGS_FORCEAPPLY
, "A"),
2031 F(ICMP6_RR_FLAGS_SPECSITE
, "S"),
2032 F(ICMP6_RR_FLAGS_PREVDONE
, "P"));
2034 ND_PRINT("seg=%u,", EXTRACT_U_1(rr6
->rr_segnum
));
2035 ND_PRINT("maxdelay=%u", EXTRACT_BE_U_2(rr6
->rr_maxdelay
));
2036 if (EXTRACT_BE_U_4(rr6
->rr_reserved
))
2037 ND_PRINT("rsvd=0x%x", EXTRACT_BE_U_4(rr6
->rr_reserved
));
2043 if (EXTRACT_U_1(rr6
->rr_code
) == ICMP6_ROUTER_RENUMBERING_COMMAND
) {
2044 match
= (const struct rr_pco_match
*)cp
;
2045 cp
= (const char *)(match
+ 1);
2047 ND_TCHECK_16(match
->rpm_prefix
);
2049 if (ndo
->ndo_vflag
> 1)
2053 ND_PRINT("match("); /*)*/
2054 switch (EXTRACT_U_1(match
->rpm_code
)) {
2055 case RPM_PCO_ADD
: ND_PRINT("add"); break;
2056 case RPM_PCO_CHANGE
: ND_PRINT("change"); break;
2057 case RPM_PCO_SETGLOBAL
: ND_PRINT("setglobal"); break;
2058 default: ND_PRINT("#%u", EXTRACT_U_1(match
->rpm_code
)); break;
2061 if (ndo
->ndo_vflag
) {
2062 ND_PRINT(",ord=%u", EXTRACT_U_1(match
->rpm_ordinal
));
2063 ND_PRINT(",min=%u", EXTRACT_U_1(match
->rpm_minlen
));
2064 ND_PRINT(",max=%u", EXTRACT_U_1(match
->rpm_maxlen
));
2066 if (addrtostr6(match
->rpm_prefix
, hbuf
, sizeof(hbuf
)))
2067 ND_PRINT(",%s/%u", hbuf
, EXTRACT_U_1(match
->rpm_matchlen
));
2069 ND_PRINT(",?/%u", EXTRACT_U_1(match
->rpm_matchlen
));
2073 n
= EXTRACT_U_1(match
->rpm_len
) - 3;
2078 use
= (const struct rr_pco_use
*)cp
;
2079 cp
= (const char *)(use
+ 1);
2081 ND_TCHECK_16(use
->rpu_prefix
);
2083 if (ndo
->ndo_vflag
> 1)
2087 ND_PRINT("use("); /*)*/
2088 if (EXTRACT_U_1(use
->rpu_flags
)) {
2089 #define F(x, y) (EXTRACT_U_1(use->rpu_flags) & (x) ? (y) : "")
2091 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
, "V"),
2092 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
, "P"));
2095 if (ndo
->ndo_vflag
) {
2096 ND_PRINT("mask=0x%x,", EXTRACT_U_1(use
->rpu_ramask
));
2097 ND_PRINT("raflags=0x%x,", EXTRACT_U_1(use
->rpu_raflags
));
2098 if (EXTRACT_BE_U_4(use
->rpu_vltime
) == 0xffffffff)
2099 ND_PRINT("vltime=infty,");
2101 ND_PRINT("vltime=%u,",
2102 EXTRACT_BE_U_4(use
->rpu_vltime
));
2103 if (EXTRACT_BE_U_4(use
->rpu_pltime
) == 0xffffffff)
2104 ND_PRINT("pltime=infty,");
2106 ND_PRINT("pltime=%u,",
2107 EXTRACT_BE_U_4(use
->rpu_pltime
));
2109 if (addrtostr6(use
->rpu_prefix
, hbuf
, sizeof(hbuf
)))
2110 ND_PRINT("%s/%u/%u", hbuf
, EXTRACT_U_1(use
->rpu_uselen
),
2111 EXTRACT_U_1(use
->rpu_keeplen
));
2113 ND_PRINT("?/%u/%u", EXTRACT_U_1(use
->rpu_uselen
),
2114 EXTRACT_U_1(use
->rpu_keeplen
));
2123 nd_print_trunc(ndo
);