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