]> The Tcpdump Group git mirrors - tcpdump/blob - print-icmp6.c
Revert "Clean a bunch of fuzzed files not to fuzz the container."
[tcpdump] / print-icmp6.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 */
21
22 /* \summary: IPv6 Internet Control Message Protocol (ICMPv6) printer */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "netdissect-stdinc.h"
29
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "netdissect.h"
34 #include "addrtoname.h"
35 #include "addrtostr.h"
36 #include "extract.h"
37
38 #include "ip6.h"
39 #include "ipproto.h"
40
41 #include "udp.h"
42 #include "ah.h"
43
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 $ */
46
47 /*
48 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
49 * All rights reserved.
50 *
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
53 * are met:
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.
62 *
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
73 * SUCH DAMAGE.
74 */
75
76 struct icmp6_hdr {
77 nd_uint8_t icmp6_type; /* type field */
78 nd_uint8_t icmp6_code; /* code field */
79 nd_uint16_t icmp6_cksum; /* checksum field */
80 union {
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 */
85 } icmp6_dataun;
86 };
87
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 */
97
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 */
102
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 */
111
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 */
117
118 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
119
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 */
128
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
135
136 #define MLD6_MTRACE_RESP 200 /* mtrace response(to sender) */
137 #define MLD6_MTRACE 201 /* mtrace messages */
138
139 #define ICMP6_MAXTYPE 201
140
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 */
147
148 #define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */
149 #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */
150
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 */
154 #define ICMP6_PARAMPROB_FRAGHDRCHAIN 3 /* incomplete header chain */
155
156 #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
157
158 #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
159 #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
160 #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
161
162 #define ICMP6_NI_SUCCESS 0 /* node information successful reply */
163 #define ICMP6_NI_REFUSED 1 /* node information request is refused */
164 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
165
166 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
167 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
168 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */
169
170 /* Used in kernel only */
171 #define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */
172 #define ND_REDIRECT_ROUTER 1 /* redirect to a better router */
173
174 /*
175 * Multicast Listener Discovery
176 */
177 struct mld6_hdr {
178 struct icmp6_hdr mld6_hdr;
179 nd_ipv6 mld6_addr; /* multicast address */
180 };
181
182 #define mld6_type mld6_hdr.icmp6_type
183 #define mld6_code mld6_hdr.icmp6_code
184 #define mld6_cksum mld6_hdr.icmp6_cksum
185 #define mld6_maxdelay mld6_hdr.icmp6_data16[0]
186 #define mld6_reserved mld6_hdr.icmp6_data16[1]
187
188 #define MLD_MINLEN 24
189 #define MLDV2_MINLEN 28
190
191 /*
192 * Neighbor Discovery
193 */
194
195 struct nd_router_solicit { /* router solicitation */
196 struct icmp6_hdr nd_rs_hdr;
197 /* could be followed by options */
198 };
199
200 #define nd_rs_type nd_rs_hdr.icmp6_type
201 #define nd_rs_code nd_rs_hdr.icmp6_code
202 #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
203 #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
204
205 struct nd_router_advert { /* router advertisement */
206 struct icmp6_hdr nd_ra_hdr;
207 nd_uint32_t nd_ra_reachable; /* reachable time */
208 nd_uint32_t nd_ra_retransmit; /* retransmit timer */
209 /* could be followed by options */
210 };
211
212 #define nd_ra_type nd_ra_hdr.icmp6_type
213 #define nd_ra_code nd_ra_hdr.icmp6_code
214 #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
215 #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
216 #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
217 #define ND_RA_FLAG_MANAGED 0x80
218 #define ND_RA_FLAG_OTHER 0x40
219 #define ND_RA_FLAG_HOME_AGENT 0x20
220 #define ND_RA_FLAG_IPV6ONLY 0x02
221
222 /*
223 * Router preference values based on draft-draves-ipngwg-router-selection-01.
224 * These are non-standard definitions.
225 */
226 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
227
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 */
232
233 #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
234
235 struct nd_neighbor_solicit { /* neighbor solicitation */
236 struct icmp6_hdr nd_ns_hdr;
237 nd_ipv6 nd_ns_target; /*target address */
238 /* could be followed by options */
239 };
240
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]
245
246 struct nd_neighbor_advert { /* neighbor advertisement */
247 struct icmp6_hdr nd_na_hdr;
248 nd_ipv6 nd_na_target; /* target address */
249 /* could be followed by options */
250 };
251
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]
256
257 #define ND_NA_FLAG_ROUTER 0x80000000
258 #define ND_NA_FLAG_SOLICITED 0x40000000
259 #define ND_NA_FLAG_OVERRIDE 0x20000000
260
261 struct nd_redirect { /* redirect */
262 struct icmp6_hdr nd_rd_hdr;
263 nd_ipv6 nd_rd_target; /* target address */
264 nd_ipv6 nd_rd_dst; /* destination address */
265 /* could be followed by options */
266 };
267
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]
272
273 struct nd_opt_hdr { /* Neighbor discovery option header */
274 nd_uint8_t nd_opt_type;
275 nd_uint8_t nd_opt_len;
276 /* followed by option specific data*/
277 };
278
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
283 #define ND_OPT_MTU 5
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
289
290 struct nd_opt_prefix_info { /* prefix information */
291 nd_uint8_t nd_opt_pi_type;
292 nd_uint8_t nd_opt_pi_len;
293 nd_uint8_t nd_opt_pi_prefix_len;
294 nd_uint8_t nd_opt_pi_flags_reserved;
295 nd_uint32_t nd_opt_pi_valid_time;
296 nd_uint32_t nd_opt_pi_preferred_time;
297 nd_uint32_t nd_opt_pi_reserved2;
298 nd_ipv6 nd_opt_pi_prefix;
299 };
300
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*/
304
305 struct nd_opt_rd_hdr { /* redirected header */
306 nd_uint8_t nd_opt_rh_type;
307 nd_uint8_t nd_opt_rh_len;
308 nd_uint16_t nd_opt_rh_reserved1;
309 nd_uint32_t nd_opt_rh_reserved2;
310 /* followed by IP header and data */
311 };
312
313 struct nd_opt_mtu { /* MTU option */
314 nd_uint8_t nd_opt_mtu_type;
315 nd_uint8_t nd_opt_mtu_len;
316 nd_uint16_t nd_opt_mtu_reserved;
317 nd_uint32_t nd_opt_mtu_mtu;
318 };
319
320 struct nd_opt_rdnss { /* RDNSS RFC 6106 5.1 */
321 nd_uint8_t nd_opt_rdnss_type;
322 nd_uint8_t nd_opt_rdnss_len;
323 nd_uint16_t nd_opt_rdnss_reserved;
324 nd_uint32_t nd_opt_rdnss_lifetime;
325 nd_ipv6 nd_opt_rdnss_addr[1]; /* variable-length */
326 };
327
328 struct nd_opt_dnssl { /* DNSSL RFC 6106 5.2 */
329 nd_uint8_t nd_opt_dnssl_type;
330 nd_uint8_t nd_opt_dnssl_len;
331 nd_uint16_t nd_opt_dnssl_reserved;
332 nd_uint32_t nd_opt_dnssl_lifetime;
333 /* followed by list of DNS search domains, variable-length */
334 };
335
336 struct nd_opt_advinterval { /* Advertisement interval option */
337 nd_uint8_t nd_opt_adv_type;
338 nd_uint8_t nd_opt_adv_len;
339 nd_uint16_t nd_opt_adv_reserved;
340 nd_uint32_t nd_opt_adv_interval;
341 };
342
343 struct nd_opt_homeagent_info { /* Home Agent info */
344 nd_uint8_t nd_opt_hai_type;
345 nd_uint8_t nd_opt_hai_len;
346 nd_uint16_t nd_opt_hai_reserved;
347 nd_uint16_t nd_opt_hai_preference;
348 nd_uint16_t nd_opt_hai_lifetime;
349 };
350
351 struct nd_opt_route_info { /* route info */
352 nd_uint8_t nd_opt_rti_type;
353 nd_uint8_t nd_opt_rti_len;
354 nd_uint8_t nd_opt_rti_prefixlen;
355 nd_uint8_t nd_opt_rti_flags;
356 nd_uint32_t nd_opt_rti_lifetime;
357 /* prefix follows */
358 };
359
360 /*
361 * icmp6 namelookup
362 */
363
364 struct icmp6_namelookup {
365 struct icmp6_hdr icmp6_nl_hdr;
366 nd_byte icmp6_nl_nonce[8];
367 nd_int32_t icmp6_nl_ttl;
368 #if 0
369 nd_uint8_t icmp6_nl_len;
370 nd_byte icmp6_nl_name[3];
371 #endif
372 /* could be followed by options */
373 };
374
375 /*
376 * icmp6 node information
377 */
378 struct icmp6_nodeinfo {
379 struct icmp6_hdr icmp6_ni_hdr;
380 nd_byte icmp6_ni_nonce[8];
381 /* could be followed by reply data */
382 };
383
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]
389
390 #define NI_QTYPE_NOOP 0 /* NOOP */
391 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes (drafts up to 09) */
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 */
396
397 /* network endian */
398 #define NI_SUPTYPE_FLAG_COMPRESS ((uint16_t)htons(0x1))
399 #define NI_FQDN_FLAG_VALIDTTL ((uint16_t)htons(0x1))
400
401 /* network endian */
402 #define NI_NODEADDR_FLAG_TRUNCATE ((uint16_t)htons(0x1))
403 #define NI_NODEADDR_FLAG_ALL ((uint16_t)htons(0x2))
404 #define NI_NODEADDR_FLAG_COMPAT ((uint16_t)htons(0x4))
405 #define NI_NODEADDR_FLAG_LINKLOCAL ((uint16_t)htons(0x8))
406 #define NI_NODEADDR_FLAG_SITELOCAL ((uint16_t)htons(0x10))
407 #define NI_NODEADDR_FLAG_GLOBAL ((uint16_t)htons(0x20))
408 #define NI_NODEADDR_FLAG_ANYCAST ((uint16_t)htons(0x40)) /* just experimental. not in spec */
409
410 struct ni_reply_fqdn {
411 nd_uint32_t ni_fqdn_ttl; /* TTL */
412 nd_uint8_t ni_fqdn_namelen; /* length in octets of the FQDN */
413 nd_byte ni_fqdn_name[3]; /* XXX: alignment */
414 };
415
416 /*
417 * Router Renumbering. as router-renum-08.txt
418 */
419 struct icmp6_router_renum { /* router renumbering header */
420 struct icmp6_hdr rr_hdr;
421 nd_uint8_t rr_segnum;
422 nd_uint8_t rr_flags;
423 nd_uint16_t rr_maxdelay;
424 nd_uint32_t rr_reserved;
425 };
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
431
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]
436
437 struct rr_pco_match { /* match prefix part */
438 nd_uint8_t rpm_code;
439 nd_uint8_t rpm_len;
440 nd_uint8_t rpm_ordinal;
441 nd_uint8_t rpm_matchlen;
442 nd_uint8_t rpm_minlen;
443 nd_uint8_t rpm_maxlen;
444 nd_uint16_t rpm_reserved;
445 nd_ipv6 rpm_prefix;
446 };
447
448 #define RPM_PCO_ADD 1
449 #define RPM_PCO_CHANGE 2
450 #define RPM_PCO_SETGLOBAL 3
451 #define RPM_PCO_MAX 4
452
453 struct rr_pco_use { /* use prefix part */
454 nd_uint8_t rpu_uselen;
455 nd_uint8_t rpu_keeplen;
456 nd_uint8_t rpu_ramask;
457 nd_uint8_t rpu_raflags;
458 nd_uint32_t rpu_vltime;
459 nd_uint32_t rpu_pltime;
460 nd_uint32_t rpu_flags;
461 nd_ipv6 rpu_prefix;
462 };
463 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80
464 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40
465
466 /* network endian */
467 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME ((uint32_t)htonl(0x80000000))
468 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME ((uint32_t)htonl(0x40000000))
469
470 struct rr_result { /* router renumbering result message */
471 nd_uint16_t rrr_flags;
472 nd_uint8_t rrr_ordinal;
473 nd_uint8_t rrr_matchedlen;
474 nd_uint32_t rrr_ifid;
475 nd_ipv6 rrr_prefix;
476 };
477 /* network endian */
478 #define ICMP6_RR_RESULT_FLAGS_OOB ((uint16_t)htons(0x0002))
479 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN ((uint16_t)htons(0x0001))
480
481 static const char *get_rtpref(u_int);
482 static const char *get_lifetime(uint32_t);
483 static void print_lladdr(netdissect_options *ndo, const u_char *, size_t);
484 static int 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 const struct udphdr *get_upperlayer(netdissect_options *ndo, const 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 *);
492
493 /*
494 * DIO: Updated to RFC6550, as published in 2012: section 6. (page 30)
495 */
496
497 #define ND_RPL_MESSAGE 155 /* 0x9B */
498
499 enum ND_RPL_CODE {
500 ND_RPL_DAG_IS=0x00,
501 ND_RPL_DAG_IO=0x01,
502 ND_RPL_DAO =0x02,
503 ND_RPL_DAO_ACK=0x03,
504 ND_RPL_SEC_DAG_IS = 0x80,
505 ND_RPL_SEC_DAG_IO = 0x81,
506 ND_RPL_SEC_DAG = 0x82,
507 ND_RPL_SEC_DAG_ACK= 0x83,
508 ND_RPL_SEC_CONSIST= 0x8A
509 };
510
511 enum ND_RPL_DIO_FLAGS {
512 ND_RPL_DIO_GROUNDED = 0x80,
513 ND_RPL_DIO_DATRIG = 0x40,
514 ND_RPL_DIO_DASUPPORT= 0x20,
515 ND_RPL_DIO_RES4 = 0x10,
516 ND_RPL_DIO_RES3 = 0x08,
517 ND_RPL_DIO_PRF_MASK = 0x07 /* 3-bit preference */
518 };
519
520 #define DAGID_LEN 16
521
522 /* section 6 of draft-ietf-roll-rpl-19 */
523 struct nd_rpl_security {
524 nd_uint8_t rpl_sec_t_reserved; /* bit 7 is T-bit */
525 nd_uint8_t rpl_sec_algo;
526 nd_uint16_t rpl_sec_kim_lvl_flags; /* bit 15/14, KIM */
527 /* bit 10-8, LVL, bit 7-0 flags */
528 nd_uint32_t rpl_sec_counter;
529 #if 0
530 nd_byte rpl_sec_ki[0]; /* depends upon kim */
531 #endif
532 };
533
534 /* section 6.2.1, DODAG Information Solication (DIS_IS) */
535 struct nd_rpl_dis_is {
536 nd_uint8_t rpl_dis_flags;
537 nd_uint8_t rpl_dis_reserved;
538 #if 0
539 nd_byte rpl_dis_options[0];
540 #endif
541 };
542
543 /* section 6.3.1, DODAG Information Object (DIO) */
544 struct nd_rpl_dio {
545 nd_uint8_t rpl_instanceid;
546 nd_uint8_t rpl_version;
547 nd_uint16_t rpl_dagrank;
548 nd_uint8_t rpl_mopprf; /* bit 7=G, 5-3=MOP, 2-0=PRF */
549 nd_uint8_t rpl_dtsn; /* Dest. Advertisement Trigger Sequence Number */
550 nd_uint8_t rpl_flags; /* no flags defined yet */
551 nd_uint8_t rpl_resv1;
552 nd_byte rpl_dagid[DAGID_LEN];
553 };
554 #define RPL_DIO_GROUND_FLAG 0x80
555 #define RPL_DIO_MOP_SHIFT 3
556 #define RPL_DIO_MOP_MASK (7 << RPL_DIO_MOP_SHIFT)
557 #define RPL_DIO_PRF_SHIFT 0
558 #define RPL_DIO_PRF_MASK (7 << RPL_DIO_PRF_SHIFT)
559 #define RPL_DIO_GROUNDED(X) ((X)&RPL_DIO_GROUND_FLAG)
560 #define RPL_DIO_MOP(X) (enum RPL_DIO_MOP)(((X)&RPL_DIO_MOP_MASK) >> RPL_DIO_MOP_SHIFT)
561 #define RPL_DIO_PRF(X) (((X)&RPL_DIO_PRF_MASK) >> RPL_DIO_PRF_SHIFT)
562
563 enum RPL_DIO_MOP {
564 RPL_DIO_NONSTORING= 0x0,
565 RPL_DIO_STORING = 0x1,
566 RPL_DIO_NONSTORING_MULTICAST = 0x2,
567 RPL_DIO_STORING_MULTICAST = 0x3
568 };
569
570 enum RPL_SUBOPT {
571 RPL_OPT_PAD1 = 0,
572 RPL_OPT_PADN = 1,
573 RPL_DIO_METRICS = 2,
574 RPL_DIO_ROUTINGINFO = 3,
575 RPL_DIO_CONFIG = 4,
576 RPL_DAO_RPLTARGET = 5,
577 RPL_DAO_TRANSITINFO = 6,
578 RPL_DIO_DESTPREFIX = 8,
579 RPL_DAO_RPLTARGET_DESC=9
580 };
581
582 struct rpl_genoption {
583 nd_uint8_t rpl_dio_type;
584 nd_uint8_t rpl_dio_len; /* suboption length, not including type/len */
585 };
586 #define RPL_GENOPTION_LEN 2
587
588 #define RPL_DIO_LIFETIME_INFINITE 0xffffffff
589 #define RPL_DIO_LIFETIME_DISCONNECT 0
590
591 struct rpl_dio_destprefix {
592 nd_uint8_t rpl_dio_type;
593 nd_uint8_t rpl_dio_len;
594 nd_uint8_t rpl_dio_prefixlen; /* in bits */
595 nd_uint8_t rpl_dio_prf; /* flags, including Route Preference */
596 nd_uint32_t rpl_dio_prefixlifetime; /* in seconds */
597 #if 0
598 nd_byte rpl_dio_prefix[0]; /* variable number of bytes */
599 #endif
600 };
601
602 /* section 6.4.1, DODAG Information Object (DIO) */
603 struct nd_rpl_dao {
604 nd_uint8_t rpl_instanceid;
605 nd_uint8_t rpl_flags; /* bit 7=K, 6=D */
606 nd_uint8_t rpl_resv;
607 nd_uint8_t rpl_daoseq;
608 nd_byte rpl_dagid[DAGID_LEN]; /* present when D set. */
609 };
610 #define ND_RPL_DAO_MIN_LEN 4 /* length without DAGID */
611
612 /* indicates if this DAO is to be acK'ed */
613 #define RPL_DAO_K_SHIFT 7
614 #define RPL_DAO_K_MASK (1 << RPL_DAO_K_SHIFT)
615 #define RPL_DAO_K(X) (((X)&RPL_DAO_K_MASK) >> RPL_DAO_K_SHIFT)
616
617 /* indicates if the DAGID is present */
618 #define RPL_DAO_D_SHIFT 6
619 #define RPL_DAO_D_MASK (1 << RPL_DAO_D_SHIFT)
620 #define RPL_DAO_D(X) (((X)&RPL_DAO_D_MASK) >> RPL_DAO_D_SHIFT)
621
622 struct rpl_dao_target {
623 nd_uint8_t rpl_dao_type;
624 nd_uint8_t rpl_dao_len;
625 nd_uint8_t rpl_dao_flags; /* unused */
626 nd_uint8_t rpl_dao_prefixlen; /* in bits */
627 #if 0
628 nd_byte rpl_dao_prefix[0]; /* variable number of bytes */
629 #endif
630 };
631
632 /* section 6.5.1, Destination Advertisement Object Acknowledgement (DAO-ACK) */
633 struct nd_rpl_daoack {
634 nd_uint8_t rpl_instanceid;
635 nd_uint8_t rpl_flags; /* bit 7=D */
636 nd_uint8_t rpl_daoseq;
637 nd_uint8_t rpl_status;
638 nd_byte rpl_dagid[DAGID_LEN]; /* present when D set. */
639 };
640 #define ND_RPL_DAOACK_MIN_LEN 4 /* length without DAGID */
641 /* indicates if the DAGID is present */
642 #define RPL_DAOACK_D_SHIFT 7
643 #define RPL_DAOACK_D_MASK (1 << RPL_DAOACK_D_SHIFT)
644 #define RPL_DAOACK_D(X) (((X)&RPL_DAOACK_D_MASK) >> RPL_DAOACK_D_SHIFT)
645
646 static const struct tok icmp6_type_values[] = {
647 { ICMP6_DST_UNREACH, "destination unreachable"},
648 { ICMP6_PACKET_TOO_BIG, "packet too big"},
649 { ICMP6_TIME_EXCEEDED, "time exceeded in-transit"},
650 { ICMP6_PARAM_PROB, "parameter problem"},
651 { ICMP6_ECHO_REQUEST, "echo request"},
652 { ICMP6_ECHO_REPLY, "echo reply"},
653 { MLD6_LISTENER_QUERY, "multicast listener query"},
654 { MLD6_LISTENER_REPORT, "multicast listener report"},
655 { MLD6_LISTENER_DONE, "multicast listener done"},
656 { ND_ROUTER_SOLICIT, "router solicitation"},
657 { ND_ROUTER_ADVERT, "router advertisement"},
658 { ND_NEIGHBOR_SOLICIT, "neighbor solicitation"},
659 { ND_NEIGHBOR_ADVERT, "neighbor advertisement"},
660 { ND_REDIRECT, "redirect"},
661 { ICMP6_ROUTER_RENUMBERING, "router renumbering"},
662 { IND_SOLICIT, "inverse neighbor solicitation"},
663 { IND_ADVERT, "inverse neighbor advertisement"},
664 { MLDV2_LISTENER_REPORT, "multicast listener report v2"},
665 { ICMP6_HADISCOV_REQUEST, "ha discovery request"},
666 { ICMP6_HADISCOV_REPLY, "ha discovery reply"},
667 { ICMP6_MOBILEPREFIX_SOLICIT, "mobile router solicitation"},
668 { ICMP6_MOBILEPREFIX_ADVERT, "mobile router advertisement"},
669 { ICMP6_WRUREQUEST, "who-are-you request"},
670 { ICMP6_WRUREPLY, "who-are-you reply"},
671 { ICMP6_NI_QUERY, "node information query"},
672 { ICMP6_NI_REPLY, "node information reply"},
673 { MLD6_MTRACE, "mtrace message"},
674 { MLD6_MTRACE_RESP, "mtrace response"},
675 { ND_RPL_MESSAGE, "RPL"},
676 { 0, NULL }
677 };
678
679 static const struct tok icmp6_dst_unreach_code_values[] = {
680 { ICMP6_DST_UNREACH_NOROUTE, "unreachable route" },
681 { ICMP6_DST_UNREACH_ADMIN, " unreachable prohibited"},
682 { ICMP6_DST_UNREACH_BEYONDSCOPE, "beyond scope"},
683 { ICMP6_DST_UNREACH_ADDR, "unreachable address"},
684 { ICMP6_DST_UNREACH_NOPORT, "unreachable port"},
685 { 0, NULL }
686 };
687
688 static const struct tok icmp6_opt_pi_flag_values[] = {
689 { ND_OPT_PI_FLAG_ONLINK, "onlink" },
690 { ND_OPT_PI_FLAG_AUTO, "auto" },
691 { ND_OPT_PI_FLAG_ROUTER, "router" },
692 { 0, NULL }
693 };
694
695 static const struct tok icmp6_opt_ra_flag_values[] = {
696 { ND_RA_FLAG_MANAGED, "managed" },
697 { ND_RA_FLAG_OTHER, "other stateful"},
698 { ND_RA_FLAG_HOME_AGENT, "home agent"},
699 { ND_RA_FLAG_IPV6ONLY, "ipv6 only"},
700 { 0, NULL }
701 };
702
703 static const struct tok icmp6_nd_na_flag_values[] = {
704 { ND_NA_FLAG_ROUTER, "router" },
705 { ND_NA_FLAG_SOLICITED, "solicited" },
706 { ND_NA_FLAG_OVERRIDE, "override" },
707 { 0, NULL }
708 };
709
710 static const struct tok icmp6_opt_values[] = {
711 { ND_OPT_SOURCE_LINKADDR, "source link-address"},
712 { ND_OPT_TARGET_LINKADDR, "destination link-address"},
713 { ND_OPT_PREFIX_INFORMATION, "prefix info"},
714 { ND_OPT_REDIRECTED_HEADER, "redirected header"},
715 { ND_OPT_MTU, "mtu"},
716 { ND_OPT_RDNSS, "rdnss"},
717 { ND_OPT_DNSSL, "dnssl"},
718 { ND_OPT_ADVINTERVAL, "advertisement interval"},
719 { ND_OPT_HOMEAGENT_INFO, "homeagent information"},
720 { ND_OPT_ROUTE_INFO, "route info"},
721 { 0, NULL }
722 };
723
724 /* mldv2 report types */
725 static const struct tok mldv2report2str[] = {
726 { 1, "is_in" },
727 { 2, "is_ex" },
728 { 3, "to_in" },
729 { 4, "to_ex" },
730 { 5, "allow" },
731 { 6, "block" },
732 { 0, NULL }
733 };
734
735 static const char *
736 get_rtpref(u_int v)
737 {
738 static const char *rtpref_str[] = {
739 "medium", /* 00 */
740 "high", /* 01 */
741 "rsv", /* 10 */
742 "low" /* 11 */
743 };
744
745 return rtpref_str[((v & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff];
746 }
747
748 static const char *
749 get_lifetime(uint32_t v)
750 {
751 static char buf[20];
752
753 if (v == (uint32_t)~0UL)
754 return "infinity";
755 else {
756 snprintf(buf, sizeof(buf), "%us", v);
757 return buf;
758 }
759 }
760
761 static void
762 print_lladdr(netdissect_options *ndo, const uint8_t *p, size_t l)
763 {
764 const uint8_t *ep, *q;
765
766 q = p;
767 ep = p + l;
768 while (l > 0 && q < ep) {
769 if (q > p)
770 ND_PRINT(":");
771 ND_PRINT("%02x", GET_U_1(q));
772 q++;
773 l--;
774 }
775 }
776
777 static uint16_t icmp6_cksum(netdissect_options *ndo, const struct ip6_hdr *ip6,
778 const struct icmp6_hdr *icp, u_int len)
779 {
780 return nextproto6_cksum(ndo, ip6, (const uint8_t *)(const void *)icp, len, len,
781 IPPROTO_ICMPV6);
782 }
783
784 static const struct tok rpl_mop_values[] = {
785 { RPL_DIO_NONSTORING, "nonstoring"},
786 { RPL_DIO_STORING, "storing"},
787 { RPL_DIO_NONSTORING_MULTICAST, "nonstoring-multicast"},
788 { RPL_DIO_STORING_MULTICAST, "storing-multicast"},
789 { 0, NULL},
790 };
791
792 static const struct tok rpl_subopt_values[] = {
793 { RPL_OPT_PAD1, "pad1"},
794 { RPL_OPT_PADN, "padN"},
795 { RPL_DIO_METRICS, "metrics"},
796 { RPL_DIO_ROUTINGINFO, "routinginfo"},
797 { RPL_DIO_CONFIG, "config"},
798 { RPL_DAO_RPLTARGET, "rpltarget"},
799 { RPL_DAO_TRANSITINFO, "transitinfo"},
800 { RPL_DIO_DESTPREFIX, "destprefix"},
801 { RPL_DAO_RPLTARGET_DESC, "rpltargetdesc"},
802 { 0, NULL},
803 };
804
805 static void
806 rpl_printopts(netdissect_options *ndo, const uint8_t *opts, u_int length)
807 {
808 const struct rpl_genoption *opt;
809 uint8_t dio_type;
810 u_int optlen;
811
812 while (length != 0) {
813 opt = (const struct rpl_genoption *)opts;
814 dio_type = GET_U_1(opt->rpl_dio_type);
815 if (dio_type == RPL_OPT_PAD1) {
816 optlen = 1;
817 ND_PRINT(" opt:pad1");
818 } else {
819 if (length < RPL_GENOPTION_LEN)
820 goto trunc;
821 optlen = GET_U_1(opt->rpl_dio_len)+RPL_GENOPTION_LEN;
822 ND_PRINT(" opt:%s len:%u ",
823 tok2str(rpl_subopt_values, "subopt:%u", dio_type),
824 optlen);
825 ND_TCHECK_LEN(opt, optlen);
826 if (length < optlen)
827 goto trunc;
828 if (ndo->ndo_vflag > 2) {
829 hex_print(ndo,
830 " ",
831 opts + RPL_GENOPTION_LEN, /* content of DIO option */
832 optlen - RPL_GENOPTION_LEN);
833 }
834 }
835 opts += optlen;
836 length -= optlen;
837 }
838 return;
839 trunc:
840 nd_print_trunc(ndo);
841 }
842
843 static void
844 rpl_dio_print(netdissect_options *ndo,
845 const u_char *bp, u_int length)
846 {
847 const struct nd_rpl_dio *dio = (const struct nd_rpl_dio *)bp;
848
849 ND_ICHECK_ZU(length, <, sizeof(struct nd_rpl_dio));
850 ND_PRINT(" [dagid:%s,seq:%u,instance:%u,rank:%u,%smop:%s,prf:%u]",
851 GET_IP6ADDR_STRING(dio->rpl_dagid),
852 GET_U_1(dio->rpl_dtsn),
853 GET_U_1(dio->rpl_instanceid),
854 GET_BE_U_2(dio->rpl_dagrank),
855 RPL_DIO_GROUNDED(GET_U_1(dio->rpl_mopprf)) ? "grounded,":"",
856 tok2str(rpl_mop_values, "mop%u",
857 RPL_DIO_MOP(GET_U_1(dio->rpl_mopprf))),
858 RPL_DIO_PRF(GET_U_1(dio->rpl_mopprf)));
859
860 if(ndo->ndo_vflag > 1) {
861 rpl_printopts(ndo, bp + sizeof(struct nd_rpl_dio),
862 length - sizeof(struct nd_rpl_dio));
863 }
864 return;
865 invalid:
866 nd_print_invalid(ndo);
867 }
868
869 static void
870 rpl_dao_print(netdissect_options *ndo,
871 const u_char *bp, u_int length)
872 {
873 const struct nd_rpl_dao *dao = (const struct nd_rpl_dao *)bp;
874 const char *dagid_str = "<elided>";
875 uint8_t rpl_flags;
876
877 ND_ICHECK_U(length, <, ND_RPL_DAO_MIN_LEN);
878
879 bp += ND_RPL_DAO_MIN_LEN;
880 length -= ND_RPL_DAO_MIN_LEN;
881 rpl_flags = GET_U_1(dao->rpl_flags);
882 if(RPL_DAO_D(rpl_flags)) {
883 ND_ICHECK_U(length, <, DAGID_LEN);
884 dagid_str = GET_IP6ADDR_STRING(dao->rpl_dagid);
885 bp += DAGID_LEN;
886 length -= DAGID_LEN;
887 }
888
889 ND_PRINT(" [dagid:%s,seq:%u,instance:%u%s%s,flags:%02x]",
890 dagid_str,
891 GET_U_1(dao->rpl_daoseq),
892 GET_U_1(dao->rpl_instanceid),
893 RPL_DAO_K(rpl_flags) ? ",acK":"",
894 RPL_DAO_D(rpl_flags) ? ",Dagid":"",
895 rpl_flags);
896
897 if(ndo->ndo_vflag > 1) {
898 rpl_printopts(ndo, bp, length);
899 }
900 return;
901 invalid:
902 nd_print_invalid(ndo);
903 }
904
905 static void
906 rpl_daoack_print(netdissect_options *ndo,
907 const u_char *bp, u_int length)
908 {
909 const struct nd_rpl_daoack *daoack = (const struct nd_rpl_daoack *)bp;
910 const char *dagid_str = "<elided>";
911
912 ND_ICHECK_U(length, <, ND_RPL_DAOACK_MIN_LEN);
913
914 bp += ND_RPL_DAOACK_MIN_LEN;
915 length -= ND_RPL_DAOACK_MIN_LEN;
916 if(RPL_DAOACK_D(GET_U_1(daoack->rpl_flags))) {
917 ND_ICHECK_U(length, <, DAGID_LEN);
918 dagid_str = GET_IP6ADDR_STRING(daoack->rpl_dagid);
919 bp += DAGID_LEN;
920 length -= DAGID_LEN;
921 }
922
923 ND_PRINT(" [dagid:%s,seq:%u,instance:%u,status:%u]",
924 dagid_str,
925 GET_U_1(daoack->rpl_daoseq),
926 GET_U_1(daoack->rpl_instanceid),
927 GET_U_1(daoack->rpl_status));
928
929 /* no officially defined options for DAOACK, but print any we find */
930 if(ndo->ndo_vflag > 1) {
931 rpl_printopts(ndo, bp, length);
932 }
933 return;
934 invalid:
935 nd_print_invalid(ndo);
936 }
937
938 static void
939 rpl_print(netdissect_options *ndo,
940 uint8_t icmp6_code,
941 const u_char *bp, u_int length)
942 {
943 int secured = icmp6_code & 0x80;
944 int basecode= icmp6_code & 0x7f;
945
946 if(secured) {
947 ND_PRINT(", (SEC) [worktodo]");
948 /* XXX
949 * the next header pointer needs to move forward to
950 * skip the secure part.
951 */
952 return;
953 } else {
954 ND_PRINT(", (CLR)");
955 }
956
957 switch(basecode) {
958 case ND_RPL_DAG_IS:
959 ND_PRINT("DODAG Information Solicitation");
960 if(ndo->ndo_vflag) {
961 }
962 break;
963 case ND_RPL_DAG_IO:
964 ND_PRINT("DODAG Information Object");
965 if(ndo->ndo_vflag) {
966 rpl_dio_print(ndo, bp, length);
967 }
968 break;
969 case ND_RPL_DAO:
970 ND_PRINT("Destination Advertisement Object");
971 if(ndo->ndo_vflag) {
972 rpl_dao_print(ndo, bp, length);
973 }
974 break;
975 case ND_RPL_DAO_ACK:
976 ND_PRINT("Destination Advertisement Object Ack");
977 if(ndo->ndo_vflag) {
978 rpl_daoack_print(ndo, bp, length);
979 }
980 break;
981 default:
982 ND_PRINT("RPL message, unknown code %u",icmp6_code);
983 break;
984 }
985 return;
986
987 #if 0
988 trunc:
989 nd_print_trunc(ndo);
990 return;
991 #endif
992
993 }
994
995 void
996 icmp6_print(netdissect_options *ndo,
997 const u_char *bp, u_int length, const u_char *bp2, int fragmented)
998 {
999 const struct icmp6_hdr *dp;
1000 uint8_t icmp6_type, icmp6_code;
1001 const struct ip6_hdr *ip;
1002 const struct ip6_hdr *oip;
1003 const struct udphdr *ouh;
1004 uint16_t dport;
1005 const u_char *ep;
1006 u_int prot;
1007
1008 ndo->ndo_protocol = "icmp6";
1009 dp = (const struct icmp6_hdr *)bp;
1010 ip = (const struct ip6_hdr *)bp2;
1011 oip = (const struct ip6_hdr *)(dp + 1);
1012 /* 'ep' points to the end of available data. */
1013 ep = ndo->ndo_snapend;
1014 if (length == 0) {
1015 ND_PRINT("ICMP6, length 0");
1016 nd_print_invalid(ndo);
1017 return;
1018 }
1019
1020 if (ndo->ndo_vflag && !fragmented) {
1021 uint16_t sum, udp_sum;
1022
1023 if (ND_TTEST_LEN(bp, length)) {
1024 udp_sum = GET_BE_U_2(dp->icmp6_cksum);
1025 sum = icmp6_cksum(ndo, ip, dp, length);
1026 if (sum != 0)
1027 ND_PRINT("[bad icmp6 cksum 0x%04x -> 0x%04x!] ",
1028 udp_sum,
1029 in_cksum_shouldbe(udp_sum, sum));
1030 else
1031 ND_PRINT("[icmp6 sum ok] ");
1032 }
1033 }
1034
1035 icmp6_type = GET_U_1(dp->icmp6_type);
1036 ND_PRINT("ICMP6, %s", tok2str(icmp6_type_values,"unknown icmp6 type (%u)",icmp6_type));
1037
1038 /* display cosmetics: print the packet length for printer that use the vflag now */
1039 if (ndo->ndo_vflag && (icmp6_type == ND_ROUTER_SOLICIT ||
1040 icmp6_type == ND_ROUTER_ADVERT ||
1041 icmp6_type == ND_NEIGHBOR_ADVERT ||
1042 icmp6_type == ND_NEIGHBOR_SOLICIT ||
1043 icmp6_type == ND_REDIRECT ||
1044 icmp6_type == ICMP6_HADISCOV_REPLY ||
1045 icmp6_type == ICMP6_MOBILEPREFIX_ADVERT ))
1046 ND_PRINT(", length %u", length);
1047
1048 icmp6_code = GET_U_1(dp->icmp6_code);
1049
1050 switch (icmp6_type) {
1051 case ICMP6_DST_UNREACH:
1052 ND_PRINT(", %s", tok2str(icmp6_dst_unreach_code_values,"unknown unreach code (%u)",icmp6_code));
1053 switch (icmp6_code) {
1054
1055 case ICMP6_DST_UNREACH_NOROUTE: /* fall through */
1056 case ICMP6_DST_UNREACH_ADMIN:
1057 case ICMP6_DST_UNREACH_ADDR:
1058 ND_PRINT(" %s",GET_IP6ADDR_STRING(oip->ip6_dst));
1059 break;
1060 case ICMP6_DST_UNREACH_BEYONDSCOPE:
1061 ND_PRINT(" %s, source address %s",
1062 GET_IP6ADDR_STRING(oip->ip6_dst),
1063 GET_IP6ADDR_STRING(oip->ip6_src));
1064 break;
1065 case ICMP6_DST_UNREACH_NOPORT:
1066 if ((ouh = get_upperlayer(ndo, (const u_char *)oip, &prot))
1067 == NULL)
1068 goto trunc;
1069
1070 dport = GET_BE_U_2(ouh->uh_dport);
1071 switch (prot) {
1072 case IPPROTO_TCP:
1073 ND_PRINT(", %s tcp port %s",
1074 GET_IP6ADDR_STRING(oip->ip6_dst),
1075 tcpport_string(ndo, dport));
1076 break;
1077 case IPPROTO_UDP:
1078 ND_PRINT(", %s udp port %s",
1079 GET_IP6ADDR_STRING(oip->ip6_dst),
1080 udpport_string(ndo, dport));
1081 break;
1082 default:
1083 ND_PRINT(", %s protocol %u port %u unreachable",
1084 GET_IP6ADDR_STRING(oip->ip6_dst),
1085 prot, dport);
1086 break;
1087 }
1088 break;
1089 default:
1090 if (ndo->ndo_vflag <= 1) {
1091 print_unknown_data(ndo, bp,"\n\t",length);
1092 return;
1093 }
1094 break;
1095 }
1096 break;
1097 case ICMP6_PACKET_TOO_BIG:
1098 ND_PRINT(", mtu %u", GET_BE_U_4(dp->icmp6_mtu));
1099 break;
1100 case ICMP6_TIME_EXCEEDED:
1101 switch (icmp6_code) {
1102 case ICMP6_TIME_EXCEED_TRANSIT:
1103 ND_PRINT(" for %s",
1104 GET_IP6ADDR_STRING(oip->ip6_dst));
1105 break;
1106 case ICMP6_TIME_EXCEED_REASSEMBLY:
1107 ND_PRINT(" (reassembly)");
1108 break;
1109 default:
1110 ND_PRINT(", unknown code (%u)", icmp6_code);
1111 break;
1112 }
1113 break;
1114 case ICMP6_PARAM_PROB:
1115 ND_TCHECK_16(oip->ip6_dst);
1116 switch (icmp6_code) {
1117 case ICMP6_PARAMPROB_HEADER:
1118 ND_PRINT(", erroneous - octet %u",
1119 GET_BE_U_4(dp->icmp6_pptr));
1120 break;
1121 case ICMP6_PARAMPROB_NEXTHEADER:
1122 ND_PRINT(", next header - octet %u",
1123 GET_BE_U_4(dp->icmp6_pptr));
1124 break;
1125 case ICMP6_PARAMPROB_OPTION:
1126 ND_PRINT(", option - octet %u",
1127 GET_BE_U_4(dp->icmp6_pptr));
1128 break;
1129 case ICMP6_PARAMPROB_FRAGHDRCHAIN:
1130 ND_PRINT(", incomplete header chain - octet %u",
1131 GET_BE_U_4(dp->icmp6_pptr));
1132 break;
1133 default:
1134 ND_PRINT(", code-#%u",
1135 icmp6_code);
1136 break;
1137 }
1138 break;
1139 case ICMP6_ECHO_REQUEST:
1140 case ICMP6_ECHO_REPLY:
1141 ND_PRINT(", id %u, seq %u", GET_BE_U_2(dp->icmp6_id),
1142 GET_BE_U_2(dp->icmp6_seq));
1143 break;
1144 case ICMP6_MEMBERSHIP_QUERY:
1145 if (length == MLD_MINLEN) {
1146 mld6_print(ndo, (const u_char *)dp);
1147 } else if (length >= MLDV2_MINLEN) {
1148 ND_PRINT(" v2");
1149 mldv2_query_print(ndo, (const u_char *)dp, length);
1150 } else {
1151 ND_PRINT(" unknown-version (len %u) ", length);
1152 }
1153 break;
1154 case ICMP6_MEMBERSHIP_REPORT:
1155 mld6_print(ndo, (const u_char *)dp);
1156 break;
1157 case ICMP6_MEMBERSHIP_REDUCTION:
1158 mld6_print(ndo, (const u_char *)dp);
1159 break;
1160 case ND_ROUTER_SOLICIT:
1161 #define RTSOLLEN 8
1162 if (ndo->ndo_vflag) {
1163 if (icmp6_opt_print(ndo, (const u_char *)dp + RTSOLLEN,
1164 length - RTSOLLEN) == -1)
1165 goto trunc;
1166 }
1167 break;
1168 case ND_ROUTER_ADVERT:
1169 #define RTADVLEN 16
1170 if (ndo->ndo_vflag) {
1171 const struct nd_router_advert *p;
1172
1173 p = (const struct nd_router_advert *)dp;
1174 ND_PRINT("\n\thop limit %u, Flags [%s]"
1175 ", pref %s, router lifetime %us, reachable time %ums, retrans timer %ums",
1176 GET_U_1(p->nd_ra_curhoplimit),
1177 bittok2str(icmp6_opt_ra_flag_values,"none",GET_U_1(p->nd_ra_flags_reserved)),
1178 get_rtpref(GET_U_1(p->nd_ra_flags_reserved)),
1179 GET_BE_U_2(p->nd_ra_router_lifetime),
1180 GET_BE_U_4(p->nd_ra_reachable),
1181 GET_BE_U_4(p->nd_ra_retransmit));
1182
1183 if (icmp6_opt_print(ndo, (const u_char *)dp + RTADVLEN,
1184 length - RTADVLEN) == -1)
1185 goto trunc;
1186 }
1187 break;
1188 case ND_NEIGHBOR_SOLICIT:
1189 {
1190 const struct nd_neighbor_solicit *p;
1191 p = (const struct nd_neighbor_solicit *)dp;
1192 ND_PRINT(", who has %s", GET_IP6ADDR_STRING(p->nd_ns_target));
1193 if (ndo->ndo_vflag) {
1194 #define NDSOLLEN 24
1195 if (icmp6_opt_print(ndo, (const u_char *)dp + NDSOLLEN,
1196 length - NDSOLLEN) == -1)
1197 goto trunc;
1198 }
1199 }
1200 break;
1201 case ND_NEIGHBOR_ADVERT:
1202 {
1203 const struct nd_neighbor_advert *p;
1204
1205 p = (const struct nd_neighbor_advert *)dp;
1206 ND_PRINT(", tgt is %s",
1207 GET_IP6ADDR_STRING(p->nd_na_target));
1208 if (ndo->ndo_vflag) {
1209 ND_PRINT(", Flags [%s]",
1210 bittok2str(icmp6_nd_na_flag_values,
1211 "none",
1212 GET_BE_U_4(p->nd_na_flags_reserved)));
1213 #define NDADVLEN 24
1214 if (icmp6_opt_print(ndo, (const u_char *)dp + NDADVLEN,
1215 length - NDADVLEN) == -1)
1216 goto trunc;
1217 #undef NDADVLEN
1218 }
1219 }
1220 break;
1221 case ND_REDIRECT:
1222 {
1223 const struct nd_redirect *p;
1224
1225 p = (const struct nd_redirect *)dp;
1226 ND_PRINT(", %s", GET_IP6ADDR_STRING(p->nd_rd_dst));
1227 ND_PRINT(" to %s", GET_IP6ADDR_STRING(p->nd_rd_target));
1228 #define REDIRECTLEN 40
1229 if (ndo->ndo_vflag) {
1230 if (icmp6_opt_print(ndo, (const u_char *)dp + REDIRECTLEN,
1231 length - REDIRECTLEN) == -1)
1232 goto trunc;
1233 #undef REDIRECTLEN
1234 }
1235 }
1236 break;
1237 case ICMP6_ROUTER_RENUMBERING:
1238 icmp6_rrenum_print(ndo, bp, ep);
1239 break;
1240 case ICMP6_NI_QUERY:
1241 case ICMP6_NI_REPLY:
1242 icmp6_nodeinfo_print(ndo, length, bp, ep);
1243 break;
1244 case IND_SOLICIT:
1245 case IND_ADVERT:
1246 break;
1247 case ICMP6_V2_MEMBERSHIP_REPORT:
1248 mldv2_report_print(ndo, (const u_char *) dp, length);
1249 break;
1250 case ICMP6_MOBILEPREFIX_SOLICIT: /* fall through */
1251 case ICMP6_HADISCOV_REQUEST:
1252 ND_PRINT(", id 0x%04x", GET_BE_U_2(dp->icmp6_data16[0]));
1253 break;
1254 case ICMP6_HADISCOV_REPLY:
1255 if (ndo->ndo_vflag) {
1256 const u_char *cp;
1257 const u_char *p;
1258
1259 ND_PRINT(", id 0x%04x",
1260 GET_BE_U_2(dp->icmp6_data16[0]));
1261 cp = (const u_char *)dp + length;
1262 p = (const u_char *)(dp + 1);
1263 while (p < cp) {
1264 ND_PRINT(", %s", GET_IP6ADDR_STRING(p));
1265 p += 16;
1266 }
1267 }
1268 break;
1269 case ICMP6_MOBILEPREFIX_ADVERT:
1270 if (ndo->ndo_vflag) {
1271 uint16_t flags;
1272
1273 ND_PRINT(", id 0x%04x",
1274 GET_BE_U_2(dp->icmp6_data16[0]));
1275 flags = GET_BE_U_2(dp->icmp6_data16[1]);
1276 if (flags & 0xc000)
1277 ND_PRINT(" ");
1278 if (flags & 0x8000)
1279 ND_PRINT("M");
1280 if (flags & 0x4000)
1281 ND_PRINT("O");
1282 #define MPADVLEN 8
1283 if (icmp6_opt_print(ndo, (const u_char *)dp + MPADVLEN,
1284 length - MPADVLEN) == -1)
1285 goto trunc;
1286 }
1287 break;
1288 case ND_RPL_MESSAGE:
1289 /* plus 4, because struct icmp6_hdr contains 4 bytes of icmp payload */
1290 rpl_print(ndo, icmp6_code, dp->icmp6_data, length-sizeof(struct icmp6_hdr)+4);
1291 break;
1292 default:
1293 ND_PRINT(", length %u", length);
1294 if (ndo->ndo_vflag <= 1)
1295 print_unknown_data(ndo, bp,"\n\t", length);
1296 return;
1297 }
1298 if (!ndo->ndo_vflag)
1299 ND_PRINT(", length %u", length);
1300 return;
1301 trunc:
1302 nd_print_trunc(ndo);
1303 }
1304
1305 static const struct udphdr *
1306 get_upperlayer(netdissect_options *ndo, const u_char *bp, u_int *prot)
1307 {
1308 const u_char *ep;
1309 const struct ip6_hdr *ip6 = (const struct ip6_hdr *)bp;
1310 const struct udphdr *uh;
1311 const struct ip6_hbh *hbh;
1312 const struct ip6_frag *fragh;
1313 const struct ah *ah;
1314 u_int nh;
1315 int hlen;
1316
1317 /* 'ep' points to the end of available data. */
1318 ep = ndo->ndo_snapend;
1319
1320 if (!ND_TTEST_1(ip6->ip6_nxt))
1321 return NULL;
1322
1323 nh = GET_U_1(ip6->ip6_nxt);
1324 hlen = sizeof(struct ip6_hdr);
1325
1326 while (bp < ep) {
1327 bp += hlen;
1328
1329 switch(nh) {
1330 case IPPROTO_UDP:
1331 case IPPROTO_TCP:
1332 uh = (const struct udphdr *)bp;
1333 if (ND_TTEST_2(uh->uh_dport)) {
1334 *prot = nh;
1335 return(uh);
1336 }
1337 else
1338 return(NULL);
1339 /* NOTREACHED */
1340
1341 case IPPROTO_HOPOPTS:
1342 case IPPROTO_DSTOPTS:
1343 case IPPROTO_ROUTING:
1344 hbh = (const struct ip6_hbh *)bp;
1345 if (!ND_TTEST_1(hbh->ip6h_len))
1346 return(NULL);
1347 nh = GET_U_1(hbh->ip6h_nxt);
1348 hlen = (GET_U_1(hbh->ip6h_len) + 1) << 3;
1349 break;
1350
1351 case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */
1352 fragh = (const struct ip6_frag *)bp;
1353 if (!ND_TTEST_2(fragh->ip6f_offlg))
1354 return(NULL);
1355 /* fragments with non-zero offset are meaningless */
1356 if ((GET_BE_U_2(fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0)
1357 return(NULL);
1358 nh = GET_U_1(fragh->ip6f_nxt);
1359 hlen = sizeof(struct ip6_frag);
1360 break;
1361
1362 case IPPROTO_AH:
1363 ah = (const struct ah *)bp;
1364 if (!ND_TTEST_1(ah->ah_len))
1365 return(NULL);
1366 nh = GET_U_1(ah->ah_nxt);
1367 hlen = (GET_U_1(ah->ah_len) + 2) << 2;
1368 break;
1369
1370 default: /* unknown or undecodable header */
1371 *prot = nh; /* meaningless, but set here anyway */
1372 return(NULL);
1373 }
1374 }
1375
1376 return(NULL); /* should be notreached, though */
1377 }
1378
1379 static int
1380 icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid)
1381 {
1382 const struct nd_opt_hdr *op;
1383 uint8_t opt_type;
1384 u_int opt_len;
1385 const struct nd_opt_prefix_info *opp;
1386 const struct nd_opt_mtu *opm;
1387 const struct nd_opt_rdnss *oprd;
1388 const struct nd_opt_dnssl *opds;
1389 const struct nd_opt_advinterval *opa;
1390 const struct nd_opt_homeagent_info *oph;
1391 const struct nd_opt_route_info *opri;
1392 const u_char *cp, *ep, *domp;
1393 nd_ipv6 in6;
1394 size_t l;
1395 u_int i;
1396
1397 cp = bp;
1398 /* 'ep' points to the end of available data. */
1399 ep = ndo->ndo_snapend;
1400
1401 while (cp < ep) {
1402 op = (const struct nd_opt_hdr *)cp;
1403
1404 ND_TCHECK_1(op->nd_opt_len);
1405 if (resid <= 0)
1406 return 0;
1407 opt_type = GET_U_1(op->nd_opt_type);
1408 opt_len = GET_U_1(op->nd_opt_len);
1409 if (opt_len == 0)
1410 goto trunc;
1411 if (cp + (opt_len << 3) > ep)
1412 goto trunc;
1413
1414 ND_PRINT("\n\t %s option (%u), length %u (%u): ",
1415 tok2str(icmp6_opt_values, "unknown", opt_type),
1416 opt_type,
1417 opt_len << 3,
1418 opt_len);
1419
1420 switch (opt_type) {
1421 case ND_OPT_SOURCE_LINKADDR:
1422 l = (opt_len << 3) - 2;
1423 print_lladdr(ndo, cp + 2, l);
1424 break;
1425 case ND_OPT_TARGET_LINKADDR:
1426 l = (opt_len << 3) - 2;
1427 print_lladdr(ndo, cp + 2, l);
1428 break;
1429 case ND_OPT_PREFIX_INFORMATION:
1430 opp = (const struct nd_opt_prefix_info *)op;
1431 ND_PRINT("%s/%u%s, Flags [%s], valid time %s",
1432 GET_IP6ADDR_STRING(opp->nd_opt_pi_prefix),
1433 GET_U_1(opp->nd_opt_pi_prefix_len),
1434 (opt_len != 4) ? "badlen" : "",
1435 bittok2str(icmp6_opt_pi_flag_values, "none", GET_U_1(opp->nd_opt_pi_flags_reserved)),
1436 get_lifetime(GET_BE_U_4(opp->nd_opt_pi_valid_time)));
1437 ND_PRINT(", pref. time %s",
1438 get_lifetime(GET_BE_U_4(opp->nd_opt_pi_preferred_time)));
1439 break;
1440 case ND_OPT_REDIRECTED_HEADER:
1441 print_unknown_data(ndo, bp,"\n\t ",opt_len<<3);
1442 /* xxx */
1443 break;
1444 case ND_OPT_MTU:
1445 opm = (const struct nd_opt_mtu *)op;
1446 ND_PRINT(" %u%s",
1447 GET_BE_U_4(opm->nd_opt_mtu_mtu),
1448 (opt_len != 1) ? "bad option length" : "" );
1449 break;
1450 case ND_OPT_RDNSS:
1451 oprd = (const struct nd_opt_rdnss *)op;
1452 l = (opt_len - 1) / 2;
1453 ND_PRINT(" lifetime %us,",
1454 GET_BE_U_4(oprd->nd_opt_rdnss_lifetime));
1455 for (i = 0; i < l; i++) {
1456 ND_PRINT(" addr: %s",
1457 GET_IP6ADDR_STRING(oprd->nd_opt_rdnss_addr[i]));
1458 }
1459 break;
1460 case ND_OPT_DNSSL:
1461 opds = (const struct nd_opt_dnssl *)op;
1462 ND_PRINT(" lifetime %us, domain(s):",
1463 GET_BE_U_4(opds->nd_opt_dnssl_lifetime));
1464 domp = cp + 8; /* domain names, variable-sized, RFC1035-encoded */
1465 while (domp < cp + (opt_len << 3) && GET_U_1(domp) != '\0')
1466 {
1467 ND_PRINT(" ");
1468 if ((domp = fqdn_print(ndo, domp, bp)) == NULL)
1469 goto trunc;
1470 }
1471 break;
1472 case ND_OPT_ADVINTERVAL:
1473 opa = (const struct nd_opt_advinterval *)op;
1474 ND_PRINT(" %ums",
1475 GET_BE_U_4(opa->nd_opt_adv_interval));
1476 break;
1477 case ND_OPT_HOMEAGENT_INFO:
1478 oph = (const struct nd_opt_homeagent_info *)op;
1479 ND_PRINT(" preference %u, lifetime %u",
1480 GET_BE_U_2(oph->nd_opt_hai_preference),
1481 GET_BE_U_2(oph->nd_opt_hai_lifetime));
1482 break;
1483 case ND_OPT_ROUTE_INFO:
1484 opri = (const struct nd_opt_route_info *)op;
1485 ND_TCHECK_4(opri->nd_opt_rti_lifetime);
1486 memset(&in6, 0, sizeof(in6));
1487 switch (opt_len) {
1488 case 1:
1489 break;
1490 case 2:
1491 GET_CPY_BYTES(&in6, opri + 1, 8);
1492 break;
1493 case 3:
1494 GET_CPY_BYTES(&in6, opri + 1, 16);
1495 break;
1496 default:
1497 goto trunc;
1498 }
1499 ND_PRINT(" %s/%u", ip6addr_string(ndo, (const u_char *)&in6), /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */
1500 GET_U_1(opri->nd_opt_rti_prefixlen));
1501 ND_PRINT(", pref=%s",
1502 get_rtpref(GET_U_1(opri->nd_opt_rti_flags)));
1503 ND_PRINT(", lifetime=%s",
1504 get_lifetime(GET_BE_U_4(opri->nd_opt_rti_lifetime)));
1505 break;
1506 default:
1507 if (ndo->ndo_vflag <= 1) {
1508 print_unknown_data(ndo,cp+2,"\n\t ", (opt_len << 3) - 2); /* skip option header */
1509 return 0;
1510 }
1511 break;
1512 }
1513 /* do we want to see an additional hexdump ? */
1514 if (ndo->ndo_vflag> 1)
1515 print_unknown_data(ndo, cp+2,"\n\t ", (opt_len << 3) - 2); /* skip option header */
1516
1517 cp += opt_len << 3;
1518 resid -= opt_len << 3;
1519 }
1520 return 0;
1521
1522 trunc:
1523 return -1;
1524 }
1525
1526 static void
1527 mld6_print(netdissect_options *ndo, const u_char *bp)
1528 {
1529 const struct mld6_hdr *mp = (const struct mld6_hdr *)bp;
1530 const u_char *ep;
1531
1532 /* 'ep' points to the end of available data. */
1533 ep = ndo->ndo_snapend;
1534
1535 if ((const u_char *)mp + sizeof(*mp) > ep)
1536 return;
1537
1538 ND_PRINT("max resp delay: %u ", GET_BE_U_2(mp->mld6_maxdelay));
1539 ND_PRINT("addr: %s", GET_IP6ADDR_STRING(mp->mld6_addr));
1540 }
1541
1542 static void
1543 mldv2_report_print(netdissect_options *ndo, const u_char *bp, u_int len)
1544 {
1545 const struct icmp6_hdr *icp = (const struct icmp6_hdr *) bp;
1546 u_int group, nsrcs, ngroups;
1547 u_int i, j;
1548
1549 /* Minimum len is 8 */
1550 if (len < 8) {
1551 ND_PRINT(" [invalid len %u]", len);
1552 return;
1553 }
1554
1555 ngroups = GET_BE_U_2(icp->icmp6_data16[1]);
1556 ND_PRINT(", %u group record(s)", ngroups);
1557 if (ndo->ndo_vflag > 0) {
1558 /* Print the group records */
1559 group = 8;
1560 for (i = 0; i < ngroups; i++) {
1561 /* type(1) + auxlen(1) + numsrc(2) + grp(16) */
1562 if (len < group + 20) {
1563 ND_PRINT(" [invalid number of groups]");
1564 return;
1565 }
1566 ND_PRINT(" [gaddr %s", GET_IP6ADDR_STRING(bp + group + 4));
1567 ND_PRINT(" %s", tok2str(mldv2report2str, " [v2-report-#%u]",
1568 GET_U_1(bp + group)));
1569 nsrcs = GET_BE_U_2(bp + group + 2);
1570 /* Check the number of sources and print them */
1571 if (len < group + 20 + (nsrcs * sizeof(nd_ipv6))) {
1572 ND_PRINT(" [invalid number of sources %u]", nsrcs);
1573 return;
1574 }
1575 if (ndo->ndo_vflag == 1)
1576 ND_PRINT(", %u source(s)", nsrcs);
1577 else {
1578 /* Print the sources */
1579 ND_PRINT(" {");
1580 for (j = 0; j < nsrcs; j++) {
1581 ND_PRINT(" %s", GET_IP6ADDR_STRING(bp + group + 20 + (j * sizeof(nd_ipv6))));
1582 }
1583 ND_PRINT(" }");
1584 }
1585 /* Next group record */
1586 group += 20 + nsrcs * sizeof(nd_ipv6);
1587 ND_PRINT("]");
1588 }
1589 }
1590 }
1591
1592 static void
1593 mldv2_query_print(netdissect_options *ndo, const u_char *bp, u_int len)
1594 {
1595 const struct icmp6_hdr *icp = (const struct icmp6_hdr *) bp;
1596 u_int mrc;
1597 u_int mrt, qqi;
1598 u_int nsrcs;
1599 u_int i;
1600
1601 /* Minimum len is 28 */
1602 if (len < 28) {
1603 ND_PRINT(" [invalid len %u]", len);
1604 return;
1605 }
1606 mrc = GET_BE_U_2(icp->icmp6_data16[0]);
1607 if (mrc < 32768) {
1608 mrt = mrc;
1609 } else {
1610 mrt = ((mrc & 0x0fff) | 0x1000) << (((mrc & 0x7000) >> 12) + 3);
1611 }
1612 if (ndo->ndo_vflag) {
1613 ND_PRINT(" [max resp delay=%u]", mrt);
1614 }
1615 ND_PRINT(" [gaddr %s", GET_IP6ADDR_STRING(bp + 8));
1616
1617 if (ndo->ndo_vflag) {
1618 if (GET_U_1(bp + 24) & 0x08) {
1619 ND_PRINT(" sflag");
1620 }
1621 if (GET_U_1(bp + 24) & 0x07) {
1622 ND_PRINT(" robustness=%u", GET_U_1(bp + 24) & 0x07);
1623 }
1624 if (GET_U_1(bp + 25) < 128) {
1625 qqi = GET_U_1(bp + 25);
1626 } else {
1627 qqi = ((GET_U_1(bp + 25) & 0x0f) | 0x10) <<
1628 (((GET_U_1(bp + 25) & 0x70) >> 4) + 3);
1629 }
1630 ND_PRINT(" qqi=%u", qqi);
1631 }
1632
1633 nsrcs = GET_BE_U_2(bp + 26);
1634 if (nsrcs > 0) {
1635 if (len < 28 + nsrcs * sizeof(nd_ipv6))
1636 ND_PRINT(" [invalid number of sources]");
1637 else if (ndo->ndo_vflag > 1) {
1638 ND_PRINT(" {");
1639 for (i = 0; i < nsrcs; i++) {
1640 ND_PRINT(" %s", GET_IP6ADDR_STRING(bp + 28 + (i * sizeof(nd_ipv6))));
1641 }
1642 ND_PRINT(" }");
1643 } else
1644 ND_PRINT(", %u source(s)", nsrcs);
1645 }
1646 ND_PRINT("]");
1647 }
1648
1649 static void
1650 dnsname_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
1651 {
1652 int i;
1653
1654 /* DNS name decoding - no decompression */
1655 ND_PRINT(", \"");
1656 while (cp < ep) {
1657 i = GET_U_1(cp);
1658 cp++;
1659 if (i) {
1660 if (i > ep - cp) {
1661 ND_PRINT("???");
1662 break;
1663 }
1664 while (i-- && cp < ep) {
1665 fn_print_char(ndo, GET_U_1(cp));
1666 cp++;
1667 }
1668 if (cp + 1 < ep && GET_U_1(cp))
1669 ND_PRINT(".");
1670 } else {
1671 if (cp == ep) {
1672 /* FQDN */
1673 ND_PRINT(".");
1674 } else if (cp + 1 == ep && GET_U_1(cp) == '\0') {
1675 /* truncated */
1676 } else {
1677 /* invalid */
1678 ND_PRINT("???");
1679 }
1680 break;
1681 }
1682 }
1683 ND_PRINT("\"");
1684 }
1685
1686 static void
1687 icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp, const u_char *ep)
1688 {
1689 const struct icmp6_nodeinfo *ni6;
1690 const struct icmp6_hdr *dp;
1691 const u_char *cp;
1692 size_t siz, i;
1693 int needcomma;
1694
1695 if (ep < bp)
1696 return;
1697 dp = (const struct icmp6_hdr *)bp;
1698 ni6 = (const struct icmp6_nodeinfo *)bp;
1699 siz = ep - bp;
1700
1701 switch (GET_U_1(ni6->ni_type)) {
1702 case ICMP6_NI_QUERY:
1703 if (siz == sizeof(*dp) + 4) {
1704 /* KAME who-are-you */
1705 ND_PRINT(" who-are-you request");
1706 break;
1707 }
1708 ND_PRINT(" node information query");
1709
1710 ND_TCHECK_LEN(dp, sizeof(*ni6));
1711 ni6 = (const struct icmp6_nodeinfo *)dp;
1712 ND_PRINT(" ("); /*)*/
1713 switch (GET_BE_U_2(ni6->ni_qtype)) {
1714 case NI_QTYPE_NOOP:
1715 ND_PRINT("noop");
1716 break;
1717 case NI_QTYPE_SUPTYPES:
1718 ND_PRINT("supported qtypes");
1719 i = GET_BE_U_2(ni6->ni_flags);
1720 if (i)
1721 ND_PRINT(" [%s]", (i & 0x01) ? "C" : "");
1722 break;
1723 case NI_QTYPE_FQDN:
1724 ND_PRINT("DNS name");
1725 break;
1726 case NI_QTYPE_NODEADDR:
1727 ND_PRINT("node addresses");
1728 i = GET_BE_U_2(ni6->ni_flags);
1729 if (!i)
1730 break;
1731 /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */
1732 ND_PRINT(" [%s%s%s%s%s%s]",
1733 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1734 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1735 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1736 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1737 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1738 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "");
1739 break;
1740 default:
1741 ND_PRINT("unknown");
1742 break;
1743 }
1744
1745 if (GET_BE_U_2(ni6->ni_qtype) == NI_QTYPE_NOOP ||
1746 GET_BE_U_2(ni6->ni_qtype) == NI_QTYPE_SUPTYPES) {
1747 if (siz != sizeof(*ni6))
1748 if (ndo->ndo_vflag)
1749 ND_PRINT(", invalid len");
1750 /*(*/
1751 ND_PRINT(")");
1752 break;
1753 }
1754
1755 /* XXX backward compat, icmp-name-lookup-03 */
1756 if (siz == sizeof(*ni6)) {
1757 ND_PRINT(", 03 draft");
1758 /*(*/
1759 ND_PRINT(")");
1760 break;
1761 }
1762
1763 cp = (const u_char *)(ni6 + 1);
1764 switch (GET_U_1(ni6->ni_code)) {
1765 case ICMP6_NI_SUBJ_IPV6:
1766 if (!ND_TTEST_LEN(dp, sizeof(*ni6) + sizeof(nd_ipv6)))
1767 break;
1768 if (siz != sizeof(*ni6) + sizeof(nd_ipv6)) {
1769 if (ndo->ndo_vflag)
1770 ND_PRINT(", invalid subject len");
1771 break;
1772 }
1773 ND_PRINT(", subject=%s",
1774 GET_IP6ADDR_STRING(cp));
1775 break;
1776 case ICMP6_NI_SUBJ_FQDN:
1777 ND_PRINT(", subject=DNS name");
1778 if (GET_U_1(cp) == ep - cp - 1) {
1779 /* icmp-name-lookup-03, pascal string */
1780 if (ndo->ndo_vflag)
1781 ND_PRINT(", 03 draft");
1782 cp++;
1783 ND_PRINT(", \"");
1784 while (cp < ep) {
1785 fn_print_char(ndo, GET_U_1(cp));
1786 cp++;
1787 }
1788 ND_PRINT("\"");
1789 } else
1790 dnsname_print(ndo, cp, ep);
1791 break;
1792 case ICMP6_NI_SUBJ_IPV4:
1793 if (!ND_TTEST_LEN(dp, sizeof(*ni6) + sizeof(nd_ipv4)))
1794 break;
1795 if (siz != sizeof(*ni6) + sizeof(nd_ipv4)) {
1796 if (ndo->ndo_vflag)
1797 ND_PRINT(", invalid subject len");
1798 break;
1799 }
1800 ND_PRINT(", subject=%s",
1801 GET_IPADDR_STRING(cp));
1802 break;
1803 default:
1804 ND_PRINT(", unknown subject");
1805 break;
1806 }
1807
1808 /*(*/
1809 ND_PRINT(")");
1810 break;
1811
1812 case ICMP6_NI_REPLY:
1813 if (icmp6len > siz)
1814 goto trunc;
1815
1816 needcomma = 0;
1817
1818 ND_TCHECK_LEN(dp, sizeof(*ni6));
1819 ni6 = (const struct icmp6_nodeinfo *)dp;
1820 ND_PRINT(" node information reply");
1821 ND_PRINT(" ("); /*)*/
1822 switch (GET_U_1(ni6->ni_code)) {
1823 case ICMP6_NI_SUCCESS:
1824 if (ndo->ndo_vflag) {
1825 ND_PRINT("success");
1826 needcomma++;
1827 }
1828 break;
1829 case ICMP6_NI_REFUSED:
1830 ND_PRINT("refused");
1831 needcomma++;
1832 if (siz != sizeof(*ni6))
1833 if (ndo->ndo_vflag)
1834 ND_PRINT(", invalid length");
1835 break;
1836 case ICMP6_NI_UNKNOWN:
1837 ND_PRINT("unknown");
1838 needcomma++;
1839 if (siz != sizeof(*ni6))
1840 if (ndo->ndo_vflag)
1841 ND_PRINT(", invalid length");
1842 break;
1843 }
1844
1845 if (GET_U_1(ni6->ni_code) != ICMP6_NI_SUCCESS) {
1846 /*(*/
1847 ND_PRINT(")");
1848 break;
1849 }
1850
1851 switch (GET_BE_U_2(ni6->ni_qtype)) {
1852 case NI_QTYPE_NOOP:
1853 if (needcomma)
1854 ND_PRINT(", ");
1855 ND_PRINT("noop");
1856 if (siz != sizeof(*ni6))
1857 if (ndo->ndo_vflag)
1858 ND_PRINT(", invalid length");
1859 break;
1860 case NI_QTYPE_SUPTYPES:
1861 if (needcomma)
1862 ND_PRINT(", ");
1863 ND_PRINT("supported qtypes");
1864 i = GET_BE_U_2(ni6->ni_flags);
1865 if (i)
1866 ND_PRINT(" [%s]", (i & 0x01) ? "C" : "");
1867 break;
1868 case NI_QTYPE_FQDN:
1869 if (needcomma)
1870 ND_PRINT(", ");
1871 ND_PRINT("DNS name");
1872 cp = (const u_char *)(ni6 + 1) + 4;
1873 if (GET_U_1(cp) == ep - cp - 1) {
1874 /* icmp-name-lookup-03, pascal string */
1875 if (ndo->ndo_vflag)
1876 ND_PRINT(", 03 draft");
1877 cp++;
1878 ND_PRINT(", \"");
1879 while (cp < ep) {
1880 fn_print_char(ndo, GET_U_1(cp));
1881 cp++;
1882 }
1883 ND_PRINT("\"");
1884 } else
1885 dnsname_print(ndo, cp, ep);
1886 if ((GET_BE_U_2(ni6->ni_flags) & 0x01) != 0)
1887 ND_PRINT(" [TTL=%u]", GET_BE_U_4(ni6 + 1));
1888 break;
1889 case NI_QTYPE_NODEADDR:
1890 if (needcomma)
1891 ND_PRINT(", ");
1892 ND_PRINT("node addresses");
1893 i = sizeof(*ni6);
1894 while (i < siz) {
1895 if (i + sizeof(uint32_t) + sizeof(nd_ipv6) > siz)
1896 break;
1897 ND_PRINT(" %s(%u)",
1898 GET_IP6ADDR_STRING(bp + i + sizeof(uint32_t)),
1899 GET_BE_U_4(bp + i));
1900 i += sizeof(uint32_t) + sizeof(nd_ipv6);
1901 }
1902 i = GET_BE_U_2(ni6->ni_flags);
1903 if (!i)
1904 break;
1905 ND_PRINT(" [%s%s%s%s%s%s%s]",
1906 (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "",
1907 (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "",
1908 (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "",
1909 (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "",
1910 (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "",
1911 (i & NI_NODEADDR_FLAG_ALL) ? "A" : "",
1912 (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : "");
1913 break;
1914 default:
1915 if (needcomma)
1916 ND_PRINT(", ");
1917 ND_PRINT("unknown");
1918 break;
1919 }
1920
1921 /*(*/
1922 ND_PRINT(")");
1923 break;
1924 }
1925 return;
1926
1927 trunc:
1928 nd_print_trunc(ndo);
1929 }
1930
1931 static void
1932 icmp6_rrenum_print(netdissect_options *ndo, const u_char *bp, const u_char *ep)
1933 {
1934 const struct icmp6_router_renum *rr6;
1935 const char *cp;
1936 const struct rr_pco_match *match;
1937 const struct rr_pco_use *use;
1938 char hbuf[NI_MAXHOST];
1939 int n;
1940
1941 if (ep < bp)
1942 return;
1943 rr6 = (const struct icmp6_router_renum *)bp;
1944 cp = (const char *)(rr6 + 1);
1945
1946 ND_TCHECK_4(rr6->rr_reserved);
1947 switch (GET_U_1(rr6->rr_code)) {
1948 case ICMP6_ROUTER_RENUMBERING_COMMAND:
1949 ND_PRINT("router renum: command");
1950 break;
1951 case ICMP6_ROUTER_RENUMBERING_RESULT:
1952 ND_PRINT("router renum: result");
1953 break;
1954 case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET:
1955 ND_PRINT("router renum: sequence number reset");
1956 break;
1957 default:
1958 ND_PRINT("router renum: code-#%u", GET_U_1(rr6->rr_code));
1959 break;
1960 }
1961
1962 ND_PRINT(", seq=%u", GET_BE_U_4(rr6->rr_seqnum));
1963
1964 if (ndo->ndo_vflag) {
1965 uint8_t rr_flags = GET_U_1(rr6->rr_flags);
1966 #define F(x, y) (rr_flags & (x) ? (y) : "")
1967 ND_PRINT("["); /*]*/
1968 if (rr_flags) {
1969 ND_PRINT("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"),
1970 F(ICMP6_RR_FLAGS_REQRESULT, "R"),
1971 F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"),
1972 F(ICMP6_RR_FLAGS_SPECSITE, "S"),
1973 F(ICMP6_RR_FLAGS_PREVDONE, "P"));
1974 }
1975 ND_PRINT("seg=%u,", GET_U_1(rr6->rr_segnum));
1976 ND_PRINT("maxdelay=%u", GET_BE_U_2(rr6->rr_maxdelay));
1977 if (GET_BE_U_4(rr6->rr_reserved))
1978 ND_PRINT("rsvd=0x%x", GET_BE_U_4(rr6->rr_reserved));
1979 /*[*/
1980 ND_PRINT("]");
1981 #undef F
1982 }
1983
1984 if (GET_U_1(rr6->rr_code) == ICMP6_ROUTER_RENUMBERING_COMMAND) {
1985 match = (const struct rr_pco_match *)cp;
1986 cp = (const char *)(match + 1);
1987
1988 ND_TCHECK_16(match->rpm_prefix);
1989
1990 if (ndo->ndo_vflag > 1)
1991 ND_PRINT("\n\t");
1992 else
1993 ND_PRINT(" ");
1994 ND_PRINT("match("); /*)*/
1995 switch (GET_U_1(match->rpm_code)) {
1996 case RPM_PCO_ADD: ND_PRINT("add"); break;
1997 case RPM_PCO_CHANGE: ND_PRINT("change"); break;
1998 case RPM_PCO_SETGLOBAL: ND_PRINT("setglobal"); break;
1999 default: ND_PRINT("#%u",
2000 GET_U_1(match->rpm_code)); break;
2001 }
2002
2003 if (ndo->ndo_vflag) {
2004 ND_PRINT(",ord=%u", GET_U_1(match->rpm_ordinal));
2005 ND_PRINT(",min=%u", GET_U_1(match->rpm_minlen));
2006 ND_PRINT(",max=%u", GET_U_1(match->rpm_maxlen));
2007 }
2008 if (addrtostr6(match->rpm_prefix, hbuf, sizeof(hbuf)))
2009 ND_PRINT(",%s/%u", hbuf, GET_U_1(match->rpm_matchlen));
2010 else
2011 ND_PRINT(",?/%u", GET_U_1(match->rpm_matchlen));
2012 /*(*/
2013 ND_PRINT(")");
2014
2015 n = GET_U_1(match->rpm_len) - 3;
2016 if (n % 4)
2017 goto trunc;
2018 n /= 4;
2019 while (n-- > 0) {
2020 use = (const struct rr_pco_use *)cp;
2021 cp = (const char *)(use + 1);
2022
2023 ND_TCHECK_16(use->rpu_prefix);
2024
2025 if (ndo->ndo_vflag > 1)
2026 ND_PRINT("\n\t");
2027 else
2028 ND_PRINT(" ");
2029 ND_PRINT("use("); /*)*/
2030 if (GET_U_1(use->rpu_flags)) {
2031 #define F(x, y) (GET_U_1(use->rpu_flags) & (x) ? (y) : "")
2032 ND_PRINT("%s%s,",
2033 F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"),
2034 F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P"));
2035 #undef F
2036 }
2037 if (ndo->ndo_vflag) {
2038 ND_PRINT("mask=0x%x,",
2039 GET_U_1(use->rpu_ramask));
2040 ND_PRINT("raflags=0x%x,",
2041 GET_U_1(use->rpu_raflags));
2042 if (GET_BE_U_4(use->rpu_vltime) == 0xffffffff)
2043 ND_PRINT("vltime=infty,");
2044 else
2045 ND_PRINT("vltime=%u,",
2046 GET_BE_U_4(use->rpu_vltime));
2047 if (GET_BE_U_4(use->rpu_pltime) == 0xffffffff)
2048 ND_PRINT("pltime=infty,");
2049 else
2050 ND_PRINT("pltime=%u,",
2051 GET_BE_U_4(use->rpu_pltime));
2052 }
2053 if (addrtostr6(use->rpu_prefix, hbuf, sizeof(hbuf)))
2054 ND_PRINT("%s/%u/%u", hbuf,
2055 GET_U_1(use->rpu_uselen),
2056 GET_U_1(use->rpu_keeplen));
2057 else
2058 ND_PRINT("?/%u/%u", GET_U_1(use->rpu_uselen),
2059 GET_U_1(use->rpu_keeplen));
2060 /*(*/
2061 ND_PRINT(")");
2062 }
2063 }
2064
2065 return;
2066
2067 trunc:
2068 nd_print_trunc(ndo);
2069 }