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