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