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