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