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