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