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