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