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