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