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