]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/icmp6.h
xnu-4903.221.2.tar.gz
[apple/xnu.git] / bsd / netinet / icmp6.h
1 /*
2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* $KAME: icmp6.h,v 1.46 2001/04/27 15:09:48 itojun Exp $ */
29
30 /*
31 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
32 * All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. Neither the name of the project nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 */
58
59 /*
60 * Copyright (c) 1982, 1986, 1993
61 * The Regents of the University of California. All rights reserved.
62 *
63 * Redistribution and use in source and binary forms, with or without
64 * modification, are permitted provided that the following conditions
65 * are met:
66 * 1. Redistributions of source code must retain the above copyright
67 * notice, this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in the
70 * documentation and/or other materials provided with the distribution.
71 * 3. All advertising materials mentioning features or use of this software
72 * must display the following acknowledgement:
73 * This product includes software developed by the University of
74 * California, Berkeley and its contributors.
75 * 4. Neither the name of the University nor the names of its contributors
76 * may be used to endorse or promote products derived from this software
77 * without specific prior written permission.
78 *
79 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
80 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
85 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
87 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
88 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 * SUCH DAMAGE.
90 *
91 * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93
92 */
93
94 #ifndef _NETINET_ICMP6_H_
95 #define _NETINET_ICMP6_H_
96 #include <sys/appleapiopts.h>
97
98 #define ICMPV6_PLD_MAXLEN 1232 /* IPV6_MMTU - sizeof(struct ip6_hdr)
99 - sizeof(struct icmp6_hdr) */
100
101 struct icmp6_hdr {
102 u_int8_t icmp6_type; /* type field */
103 u_int8_t icmp6_code; /* code field */
104 u_int16_t icmp6_cksum; /* checksum field */
105 union {
106 u_int32_t icmp6_un_data32[1]; /* type-specific field */
107 u_int16_t icmp6_un_data16[2]; /* type-specific field */
108 u_int8_t icmp6_un_data8[4]; /* type-specific field */
109 } icmp6_dataun;
110 } __attribute__((__packed__));
111
112 #define icmp6_data32 icmp6_dataun.icmp6_un_data32
113 #define icmp6_data16 icmp6_dataun.icmp6_un_data16
114 #define icmp6_data8 icmp6_dataun.icmp6_un_data8
115 #define icmp6_pptr icmp6_data32[0] /* parameter prob */
116 #define icmp6_mtu icmp6_data32[0] /* packet too big */
117 #define icmp6_id icmp6_data16[0] /* echo request/reply */
118 #define icmp6_seq icmp6_data16[1] /* echo request/reply */
119 #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
120
121 #define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */
122 #define ICMP6_PACKET_TOO_BIG 2 /* packet too big */
123 #define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */
124 #define ICMP6_PARAM_PROB 4 /* ip6 header bad */
125
126 #define ICMP6_ECHO_REQUEST 128 /* echo service */
127 #define ICMP6_ECHO_REPLY 129 /* echo reply */
128 #define MLD_LISTENER_QUERY 130 /* multicast listener query */
129 #define MLD_LISTENER_REPORT 131 /* multicast listener report */
130 #define MLD_LISTENER_DONE 132 /* multicast listener done */
131 #define MLD_LISTENER_REDUCTION MLD_LISTENER_DONE /* RFC3542 definition */
132
133 /* RFC2292 decls */
134 #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */
135 #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */
136 #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */
137
138 #ifndef KERNEL
139 /* the followings are for backward compatibility to old KAME apps. */
140 #define MLD6_LISTENER_QUERY MLD_LISTENER_QUERY
141 #define MLD6_LISTENER_REPORT MLD_LISTENER_REPORT
142 #define MLD6_LISTENER_DONE MLD_LISTENER_DONE
143 #endif
144
145 #define ND_ROUTER_SOLICIT 133 /* router solicitation */
146 #define ND_ROUTER_ADVERT 134 /* router advertisement */
147 #define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */
148 #define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisement */
149 #define ND_REDIRECT 137 /* redirect */
150
151 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
152
153 #define ICMP6_WRUREQUEST 139 /* who are you request */
154 #define ICMP6_WRUREPLY 140 /* who are you reply */
155 #define ICMP6_FQDN_QUERY 139 /* FQDN query */
156 #define ICMP6_FQDN_REPLY 140 /* FQDN reply */
157 #define ICMP6_NI_QUERY 139 /* node information request */
158 #define ICMP6_NI_REPLY 140 /* node information reply */
159 #define MLDV2_LISTENER_REPORT 143 /* RFC3810 listener report */
160
161 /* The definitions below are experimental. TBA */
162 #define MLD_MTRACE_RESP 200 /* mtrace resp (to sender) */
163 #define MLD_MTRACE 201 /* mtrace messages */
164
165 #ifndef KERNEL
166 #define MLD6_MTRACE_RESP MLD_MTRACE_RESP
167 #define MLD6_MTRACE MLD_MTRACE
168 #endif
169
170 #define ICMP6_MAXTYPE 201
171
172 #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
173 #define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */
174 #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */
175 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
176 #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
177 #define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */
178
179 #define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */
180 #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */
181
182 #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
183 #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */
184 #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */
185
186 #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
187
188 #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
189 #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
190 #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
191
192 #define ICMP6_NI_SUCCESS 0 /* node information successful reply */
193 #define ICMP6_NI_REFUSED 1 /* node information request is refused */
194 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
195
196 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
197 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
198 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */
199
200 /* Used in kernel only */
201 #define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */
202 #define ND_REDIRECT_ROUTER 1 /* redirect to a better router */
203
204 /*
205 * Multicast Listener Discovery
206 */
207 struct mld_hdr {
208 struct icmp6_hdr mld_icmp6_hdr;
209 struct in6_addr mld_addr; /* multicast address */
210 } __attribute__((__packed__));
211
212 /* definitions to provide backward compatibility to old KAME applications */
213 #ifndef KERNEL
214 #define mld6_hdr mld_hdr
215 #define mld6_type mld_type
216 #define mld6_code mld_code
217 #define mld6_cksum mld_cksum
218 #define mld6_maxdelay mld_maxdelay
219 #define mld6_reserved mld_reserved
220 #define mld6_addr mld_addr
221 #endif
222
223 /* shortcut macro definitions */
224 #define mld_type mld_icmp6_hdr.icmp6_type
225 #define mld_code mld_icmp6_hdr.icmp6_code
226 #define mld_cksum mld_icmp6_hdr.icmp6_cksum
227 #define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0]
228 #define mld_reserved mld_icmp6_hdr.icmp6_data16[1]
229 #define mld_v2_reserved mld_icmp6_hdr.icmp6_data16[0]
230 #define mld_v2_numrecs mld_icmp6_hdr.icmp6_data16[1]
231
232
233 #define ICMP6_ERRORTYPE(type) \
234 ((type) == ICMP6_DST_UNREACH || (type) == ICMP6_PACKET_TOO_BIG || \
235 (type) == ICMP6_TIME_EXCEEDED || (type) == ICMP6_PARAM_PROB)
236 /*
237 * Neighbor Discovery
238 */
239
240 struct nd_router_solicit { /* router solicitation */
241 struct icmp6_hdr nd_rs_hdr;
242 /* could be followed by options */
243 }__attribute__((__packed__));
244
245 #define nd_rs_type nd_rs_hdr.icmp6_type
246 #define nd_rs_code nd_rs_hdr.icmp6_code
247 #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
248 #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
249
250 struct nd_router_advert { /* router advertisement */
251 struct icmp6_hdr nd_ra_hdr;
252 u_int32_t nd_ra_reachable; /* reachable time */
253 u_int32_t nd_ra_retransmit; /* retransmit timer */
254 /* could be followed by options */
255 } __attribute__((__packed__));
256
257 #define nd_ra_type nd_ra_hdr.icmp6_type
258 #define nd_ra_code nd_ra_hdr.icmp6_code
259 #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
260 #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
261 #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
262 #define ND_RA_FLAG_MANAGED 0x80
263 #define ND_RA_FLAG_OTHER 0x40
264 #define ND_RA_FLAG_HA 0x20
265
266 /*
267 * Router preference values based on draft-draves-ipngwg-router-selection-01.
268 * These are non-standard definitions.
269 */
270 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
271
272 #define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */
273 #define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */
274 #define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */
275 #define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */
276
277 #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
278
279 struct nd_neighbor_solicit { /* neighbor solicitation */
280 struct icmp6_hdr nd_ns_hdr;
281 struct in6_addr nd_ns_target; /*target address */
282 /* could be followed by options */
283 }__attribute__((__packed__));
284
285 #define nd_ns_type nd_ns_hdr.icmp6_type
286 #define nd_ns_code nd_ns_hdr.icmp6_code
287 #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
288 #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
289
290 struct nd_neighbor_advert { /* neighbor advertisement */
291 struct icmp6_hdr nd_na_hdr;
292 struct in6_addr nd_na_target; /* target address */
293 /* could be followed by options */
294 }__attribute__((__packed__));
295
296 #define nd_na_type nd_na_hdr.icmp6_type
297 #define nd_na_code nd_na_hdr.icmp6_code
298 #define nd_na_cksum nd_na_hdr.icmp6_cksum
299 #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
300 #if BYTE_ORDER == BIG_ENDIAN
301 #define ND_NA_FLAG_ROUTER 0x80000000
302 #define ND_NA_FLAG_SOLICITED 0x40000000
303 #define ND_NA_FLAG_OVERRIDE 0x20000000
304 #else
305 #if BYTE_ORDER == LITTLE_ENDIAN
306 #define ND_NA_FLAG_ROUTER 0x80
307 #define ND_NA_FLAG_SOLICITED 0x40
308 #define ND_NA_FLAG_OVERRIDE 0x20
309 #endif
310 #endif
311
312 struct nd_redirect { /* redirect */
313 struct icmp6_hdr nd_rd_hdr;
314 struct in6_addr nd_rd_target; /* target address */
315 struct in6_addr nd_rd_dst; /* destination address */
316 /* could be followed by options */
317 }__attribute__((__packed__));
318
319 #define nd_rd_type nd_rd_hdr.icmp6_type
320 #define nd_rd_code nd_rd_hdr.icmp6_code
321 #define nd_rd_cksum nd_rd_hdr.icmp6_cksum
322 #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
323
324 struct nd_opt_hdr { /* Neighbor discovery option header */
325 u_int8_t nd_opt_type;
326 u_int8_t nd_opt_len;
327 /* followed by option specific data*/
328 }__attribute__((__packed__));
329
330 #define ND_OPT_SOURCE_LINKADDR 1
331 #define ND_OPT_TARGET_LINKADDR 2
332 #define ND_OPT_PREFIX_INFORMATION 3
333 #define ND_OPT_REDIRECTED_HEADER 4
334 #define ND_OPT_MTU 5
335 #define ND_OPT_NONCE 14 /* RFC 3971 */
336 #define ND_OPT_RDNSS 25 /* RFC 6106 */
337 #define ND_OPT_DNSSL 31 /* RFC 6106 */
338
339 #define ND_OPT_ROUTE_INFO 200 /* draft-ietf-ipngwg-router-preference, not officially assigned yet */
340
341 struct nd_opt_prefix_info { /* prefix information */
342 u_int8_t nd_opt_pi_type;
343 u_int8_t nd_opt_pi_len;
344 u_int8_t nd_opt_pi_prefix_len;
345 u_int8_t nd_opt_pi_flags_reserved;
346 u_int32_t nd_opt_pi_valid_time;
347 u_int32_t nd_opt_pi_preferred_time;
348 u_int32_t nd_opt_pi_reserved2;
349 struct in6_addr nd_opt_pi_prefix;
350 }__attribute__((__packed__));
351
352 #define ND_OPT_PI_FLAG_ONLINK 0x80
353 #define ND_OPT_PI_FLAG_AUTO 0x40
354
355 #define ND_OPT_NONCE_LEN ((1 * 8) - 2)
356 #if ((ND_OPT_NONCE_LEN + 2) % 8) != 0
357 #error "(ND_OPT_NONCE_LEN + 2) must be a multiple of 8."
358 #endif
359
360 struct nd_opt_nonce { /* nonce option */
361 u_int8_t nd_opt_nonce_type;
362 u_int8_t nd_opt_nonce_len;
363 u_int8_t nd_opt_nonce[ND_OPT_NONCE_LEN];
364 } __attribute__((__packed__));
365
366 struct nd_opt_rd_hdr { /* redirected header */
367 u_int8_t nd_opt_rh_type;
368 u_int8_t nd_opt_rh_len;
369 u_int16_t nd_opt_rh_reserved1;
370 u_int32_t nd_opt_rh_reserved2;
371 /* followed by IP header and data */
372 } __attribute__((__packed__));
373
374 struct nd_opt_mtu { /* MTU option */
375 u_int8_t nd_opt_mtu_type;
376 u_int8_t nd_opt_mtu_len;
377 u_int16_t nd_opt_mtu_reserved;
378 u_int32_t nd_opt_mtu_mtu;
379 }__attribute__((__packed__));
380
381 struct nd_opt_route_info { /* route info */
382 u_int8_t nd_opt_rti_type;
383 u_int8_t nd_opt_rti_len;
384 u_int8_t nd_opt_rti_prefixlen;
385 u_int8_t nd_opt_rti_flags;
386 u_int32_t nd_opt_rti_lifetime;
387 /* prefix follows */
388 }__attribute__((__packed__));
389
390 struct nd_opt_rdnss { /* recursive domain name system servers */
391 u_int8_t nd_opt_rdnss_type;
392 u_int8_t nd_opt_rdnss_len;
393 u_int16_t nd_opt_rdnss_reserved;
394 u_int32_t nd_opt_rdnss_lifetime;
395 struct in6_addr nd_opt_rdnss_addr[1];
396 } __attribute__((__packed__));
397
398 struct nd_opt_dnssl { /* domain name search list */
399 u_int8_t nd_opt_dnssl_type;
400 u_int8_t nd_opt_dnssl_len;
401 u_int16_t nd_opt_dnssl_reserved;
402 u_int32_t nd_opt_dnssl_lifetime;
403 u_int8_t nd_opt_dnssl_domains[8];
404 } __attribute__((__packed__));
405
406 /*
407 * icmp6 namelookup
408 */
409
410 struct icmp6_namelookup {
411 struct icmp6_hdr icmp6_nl_hdr;
412 u_int8_t icmp6_nl_nonce[8];
413 int32_t icmp6_nl_ttl;
414 #if 0
415 u_int8_t icmp6_nl_len;
416 u_int8_t icmp6_nl_name[3];
417 #endif
418 /* could be followed by options */
419 }__attribute__((__packed__));
420
421 /*
422 * icmp6 node information
423 */
424 struct icmp6_nodeinfo {
425 struct icmp6_hdr icmp6_ni_hdr;
426 u_int8_t icmp6_ni_nonce[8];
427 /* could be followed by reply data */
428 }__attribute__((__packed__));
429
430 #define ni_type icmp6_ni_hdr.icmp6_type
431 #define ni_code icmp6_ni_hdr.icmp6_code
432 #define ni_cksum icmp6_ni_hdr.icmp6_cksum
433 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
434 #define ni_flags icmp6_ni_hdr.icmp6_data16[1]
435
436 #define NI_QTYPE_NOOP 0 /* NOOP */
437 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */
438 #define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */
439 #define NI_QTYPE_DNSNAME 2 /* DNS Name */
440 #define NI_QTYPE_NODEADDR 3 /* Node Addresses */
441 #define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */
442
443 #if BYTE_ORDER == BIG_ENDIAN
444 #define NI_SUPTYPE_FLAG_COMPRESS 0x1
445 #define NI_FQDN_FLAG_VALIDTTL 0x1
446 #elif BYTE_ORDER == LITTLE_ENDIAN
447 #define NI_SUPTYPE_FLAG_COMPRESS 0x0100
448 #define NI_FQDN_FLAG_VALIDTTL 0x0100
449 #endif
450
451 #ifdef NAME_LOOKUPS_04
452 #if BYTE_ORDER == BIG_ENDIAN
453 #define NI_NODEADDR_FLAG_LINKLOCAL 0x1
454 #define NI_NODEADDR_FLAG_SITELOCAL 0x2
455 #define NI_NODEADDR_FLAG_GLOBAL 0x4
456 #define NI_NODEADDR_FLAG_ALL 0x8
457 #define NI_NODEADDR_FLAG_TRUNCATE 0x10
458 #define NI_NODEADDR_FLAG_ANYCAST 0x20 /* just experimental. not in spec */
459 #elif BYTE_ORDER == LITTLE_ENDIAN
460 #define NI_NODEADDR_FLAG_LINKLOCAL 0x0100
461 #define NI_NODEADDR_FLAG_SITELOCAL 0x0200
462 #define NI_NODEADDR_FLAG_GLOBAL 0x0400
463 #define NI_NODEADDR_FLAG_ALL 0x0800
464 #define NI_NODEADDR_FLAG_TRUNCATE 0x1000
465 #define NI_NODEADDR_FLAG_ANYCAST 0x2000 /* just experimental. not in spec */
466 #endif
467 #else /* draft-ietf-ipngwg-icmp-name-lookups-05 (and later?) */
468 #if BYTE_ORDER == BIG_ENDIAN
469 #define NI_NODEADDR_FLAG_TRUNCATE 0x1
470 #define NI_NODEADDR_FLAG_ALL 0x2
471 #define NI_NODEADDR_FLAG_COMPAT 0x4
472 #define NI_NODEADDR_FLAG_LINKLOCAL 0x8
473 #define NI_NODEADDR_FLAG_SITELOCAL 0x10
474 #define NI_NODEADDR_FLAG_GLOBAL 0x20
475 #define NI_NODEADDR_FLAG_ANYCAST 0x40 /* just experimental. not in spec */
476 #elif BYTE_ORDER == LITTLE_ENDIAN
477 #define NI_NODEADDR_FLAG_TRUNCATE 0x0100
478 #define NI_NODEADDR_FLAG_ALL 0x0200
479 #define NI_NODEADDR_FLAG_COMPAT 0x0400
480 #define NI_NODEADDR_FLAG_LINKLOCAL 0x0800
481 #define NI_NODEADDR_FLAG_SITELOCAL 0x1000
482 #define NI_NODEADDR_FLAG_GLOBAL 0x2000
483 #define NI_NODEADDR_FLAG_ANYCAST 0x4000 /* just experimental. not in spec */
484 #endif
485 #endif
486
487 struct ni_reply_fqdn {
488 u_int32_t ni_fqdn_ttl; /* TTL */
489 u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */
490 u_int8_t ni_fqdn_name[3]; /* XXX: alignment */
491 }__attribute__((__packed__));
492
493 /*
494 * Router Renumbering. as router-renum-08.txt
495 */
496 struct icmp6_router_renum { /* router renumbering header */
497 struct icmp6_hdr rr_hdr;
498 u_int8_t rr_segnum;
499 u_int8_t rr_flags;
500 u_int16_t rr_maxdelay;
501 u_int32_t rr_reserved;
502 } __attribute__((__packed__));
503
504 #define ICMP6_RR_FLAGS_TEST 0x80
505 #define ICMP6_RR_FLAGS_REQRESULT 0x40
506 #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20
507 #define ICMP6_RR_FLAGS_SPECSITE 0x10
508 #define ICMP6_RR_FLAGS_PREVDONE 0x08
509
510 #define rr_type rr_hdr.icmp6_type
511 #define rr_code rr_hdr.icmp6_code
512 #define rr_cksum rr_hdr.icmp6_cksum
513 #define rr_seqnum rr_hdr.icmp6_data32[0]
514
515 struct rr_pco_match { /* match prefix part */
516 u_int8_t rpm_code;
517 u_int8_t rpm_len;
518 u_int8_t rpm_ordinal;
519 u_int8_t rpm_matchlen;
520 u_int8_t rpm_minlen;
521 u_int8_t rpm_maxlen;
522 u_int16_t rpm_reserved;
523 struct in6_addr rpm_prefix;
524 } __attribute__((__packed__));
525
526 #define RPM_PCO_ADD 1
527 #define RPM_PCO_CHANGE 2
528 #define RPM_PCO_SETGLOBAL 3
529 #define RPM_PCO_MAX 4
530
531 struct rr_pco_use { /* use prefix part */
532 u_int8_t rpu_uselen;
533 u_int8_t rpu_keeplen;
534 u_int8_t rpu_ramask;
535 u_int8_t rpu_raflags;
536 u_int32_t rpu_vltime;
537 u_int32_t rpu_pltime;
538 u_int32_t rpu_flags;
539 struct in6_addr rpu_prefix;
540 } __attribute__((__packed__));
541 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80
542 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40
543
544 #if BYTE_ORDER == BIG_ENDIAN
545 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
546 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
547 #elif BYTE_ORDER == LITTLE_ENDIAN
548 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80
549 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40
550 #endif
551
552 struct rr_result { /* router renumbering result message */
553 u_int16_t rrr_flags;
554 u_int8_t rrr_ordinal;
555 u_int8_t rrr_matchedlen;
556 u_int32_t rrr_ifid;
557 struct in6_addr rrr_prefix;
558 } __attribute__((__packed__));
559 #if BYTE_ORDER == BIG_ENDIAN
560 #define ICMP6_RR_RESULT_FLAGS_OOB 0x0002
561 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001
562 #elif BYTE_ORDER == LITTLE_ENDIAN
563 #define ICMP6_RR_RESULT_FLAGS_OOB 0x0200
564 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100
565 #endif
566
567 /*
568 * icmp6 filter structures.
569 */
570
571 struct icmp6_filter {
572 u_int32_t icmp6_filt[8];
573 };
574
575 #ifdef KERNEL
576 #define ICMP6_FILTER_SETPASSALL(filterp) \
577 do { \
578 int i; u_char *ptr; \
579 ptr = (u_char *)filterp; \
580 for (i = 0; i < sizeof(struct icmp6_filter); i++) \
581 ptr[i] = 0xff; \
582 } while (0)
583 #define ICMP6_FILTER_SETBLOCKALL(filterp) \
584 bzero(filterp, sizeof(struct icmp6_filter))
585 #else /* KERNEL */
586 #define ICMP6_FILTER_SETPASSALL(filterp) \
587 memset(filterp, 0xff, sizeof(struct icmp6_filter))
588 #define ICMP6_FILTER_SETBLOCKALL(filterp) \
589 memset(filterp, 0x00, sizeof(struct icmp6_filter))
590 #endif /* KERNEL */
591
592 #define ICMP6_FILTER_SETPASS(type, filterp) \
593 (((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))
594 #define ICMP6_FILTER_SETBLOCK(type, filterp) \
595 (((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))
596 #define ICMP6_FILTER_WILLPASS(type, filterp) \
597 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
598 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
599 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
600
601 /*
602 * Variables related to this implementation
603 * of the internet control message protocol version 6.
604 */
605 struct icmp6errstat {
606 u_quad_t icp6errs_dst_unreach_noroute;
607 u_quad_t icp6errs_dst_unreach_admin;
608 u_quad_t icp6errs_dst_unreach_beyondscope;
609 u_quad_t icp6errs_dst_unreach_addr;
610 u_quad_t icp6errs_dst_unreach_noport;
611 u_quad_t icp6errs_packet_too_big;
612 u_quad_t icp6errs_time_exceed_transit;
613 u_quad_t icp6errs_time_exceed_reassembly;
614 u_quad_t icp6errs_paramprob_header;
615 u_quad_t icp6errs_paramprob_nextheader;
616 u_quad_t icp6errs_paramprob_option;
617 u_quad_t icp6errs_redirect; /* we regard redirect as an error here */
618 u_quad_t icp6errs_unknown;
619 };
620
621 struct icmp6stat {
622 /* statistics related to icmp6 packets generated */
623 u_quad_t icp6s_error; /* # of calls to icmp6_error */
624 u_quad_t icp6s_canterror; /* no error 'cuz old was icmp */
625 u_quad_t icp6s_toofreq; /* no error 'cuz rate limitation */
626 u_quad_t icp6s_outhist[256];
627 /* statistics related to input message processed */
628 u_quad_t icp6s_badcode; /* icmp6_code out of range */
629 u_quad_t icp6s_tooshort; /* packet < sizeof(struct icmp6_hdr) */
630 u_quad_t icp6s_checksum; /* bad checksum */
631 u_quad_t icp6s_badlen; /* calculated bound mismatch */
632 u_quad_t icp6s_reflect; /* number of responses */
633 u_quad_t icp6s_inhist[256];
634 u_quad_t icp6s_nd_toomanyopt; /* too many ND options */
635 struct icmp6errstat icp6s_outerrhist;
636 #define icp6s_odst_unreach_noroute \
637 icp6s_outerrhist.icp6errs_dst_unreach_noroute
638 #define icp6s_odst_unreach_admin icp6s_outerrhist.icp6errs_dst_unreach_admin
639 #define icp6s_odst_unreach_beyondscope \
640 icp6s_outerrhist.icp6errs_dst_unreach_beyondscope
641 #define icp6s_odst_unreach_addr icp6s_outerrhist.icp6errs_dst_unreach_addr
642 #define icp6s_odst_unreach_noport icp6s_outerrhist.icp6errs_dst_unreach_noport
643 #define icp6s_opacket_too_big icp6s_outerrhist.icp6errs_packet_too_big
644 #define icp6s_otime_exceed_transit \
645 icp6s_outerrhist.icp6errs_time_exceed_transit
646 #define icp6s_otime_exceed_reassembly \
647 icp6s_outerrhist.icp6errs_time_exceed_reassembly
648 #define icp6s_oparamprob_header icp6s_outerrhist.icp6errs_paramprob_header
649 #define icp6s_oparamprob_nextheader \
650 icp6s_outerrhist.icp6errs_paramprob_nextheader
651 #define icp6s_oparamprob_option icp6s_outerrhist.icp6errs_paramprob_option
652 #define icp6s_oredirect icp6s_outerrhist.icp6errs_redirect
653 #define icp6s_ounknown icp6s_outerrhist.icp6errs_unknown
654 u_quad_t icp6s_pmtuchg; /* path MTU changes */
655 u_quad_t icp6s_nd_badopt; /* bad ND options */
656 u_quad_t icp6s_badns; /* bad neighbor solicitation */
657 u_quad_t icp6s_badna; /* bad neighbor advertisement */
658 u_quad_t icp6s_badrs; /* bad router advertisement */
659 u_quad_t icp6s_badra; /* bad router advertisement */
660 u_quad_t icp6s_badredirect; /* bad redirect message */
661 u_quad_t icp6s_rfc6980_drop; /* NDP packet dropped based on RFC 6980 */
662 };
663
664 /*
665 * Names for ICMP sysctl objects
666 */
667 #define ICMPV6CTL_STATS 1
668 #define ICMPV6CTL_REDIRACCEPT 2 /* accept/process redirects */
669 #define ICMPV6CTL_REDIRTIMEOUT 3 /* redirect cache time */
670 #if 0 /*obsoleted*/
671 #define ICMPV6CTL_ERRRATELIMIT 5 /* ICMPv6 error rate limitation */
672 #endif
673 #define ICMPV6CTL_ND6_PRUNE 6
674 #define ICMPV6CTL_ND6_DELAY 8
675 #define ICMPV6CTL_ND6_UMAXTRIES 9
676 #define ICMPV6CTL_ND6_MMAXTRIES 10
677 #define ICMPV6CTL_ND6_USELOOPBACK 11
678 /*#define ICMPV6CTL_ND6_PROXYALL 12 obsoleted, do not reuse here */
679 #define ICMPV6CTL_NODEINFO 13
680 #define ICMPV6CTL_ERRPPSLIMIT 14 /* ICMPv6 error pps limitation */
681 #define ICMPV6CTL_ND6_MAXNUDHINT 15
682 #define ICMPV6CTL_MTUDISC_HIWAT 16
683 #define ICMPV6CTL_MTUDISC_LOWAT 17
684 #define ICMPV6CTL_ND6_DEBUG 18
685 #define ICMPV6CTL_ND6_DRLIST 19
686 #define ICMPV6CTL_ND6_PRLIST 20
687 #define ICMPV6CTL_MLD_MAXSRCFILTER 21
688 #define ICMPV6CTL_MLD_SOMAXSRC 22
689 #define ICMPV6CTL_MLD_VERSION 23
690 #define ICMPV6CTL_ND6_MAXQLEN 24
691 #define ICMPV6CTL_ND6_ACCEPT_6TO4 25
692 #define ICMPV6CTL_ND6_OPTIMISTIC_DAD 26 /* RFC 4429 */
693 #define ICMPV6CTL_MAXID 27
694
695 #ifdef BSD_KERNEL_PRIVATE
696 #define ICMPV6CTL_NAMES { \
697 { 0, 0 }, \
698 { 0, 0 }, \
699 { "rediraccept", CTLTYPE_INT }, \
700 { "redirtimeout", CTLTYPE_INT }, \
701 { 0, 0 }, \
702 { 0, 0 }, \
703 { "nd6_prune", CTLTYPE_INT }, \
704 { 0, 0 }, \
705 { "nd6_delay", CTLTYPE_INT }, \
706 { "nd6_umaxtries", CTLTYPE_INT }, \
707 { "nd6_mmaxtries", CTLTYPE_INT }, \
708 { "nd6_useloopback", CTLTYPE_INT }, \
709 { 0, 0 }, \
710 { "nodeinfo", CTLTYPE_INT }, \
711 { "errppslimit", CTLTYPE_INT }, \
712 { "nd6_maxnudhint", CTLTYPE_INT }, \
713 { "mtudisc_hiwat", CTLTYPE_INT }, \
714 { "mtudisc_lowat", CTLTYPE_INT }, \
715 { "nd6_debug", CTLTYPE_INT }, \
716 { 0, 0 }, \
717 { 0, 0 }, \
718 { 0, 0 }, \
719 { 0, 0 }, \
720 { 0, 0 }, \
721 { 0, 0 }, \
722 { "nd6_accept_6to4", CTLTYPE_INT }, \
723 { "nd6_optimistic_dad", CTLTYPE_INT }, \
724 }
725
726 # ifdef __STDC__
727 struct rtentry;
728 struct rttimer;
729 struct in6_multi;
730 # endif
731 struct ip6protosw;
732 void icmp6_init(struct ip6protosw *, struct domain *);
733 void icmp6_paramerror(struct mbuf *, int);
734
735 void icmp6_error_flag(struct mbuf *, int, int, int, int);
736 #define ICMP6_ERROR_RST_MRCVIF 0x1
737
738 void icmp6_error(struct mbuf *, int, int, int);
739 void icmp6_error2(struct mbuf *, int, int, int, struct ifnet *);
740 int icmp6_input(struct mbuf **, int *, int);
741 void icmp6_reflect(struct mbuf *, size_t);
742 void icmp6_prepare(struct mbuf *);
743 void icmp6_redirect_input(struct mbuf *, int);
744 void icmp6_redirect_output(struct mbuf *, struct rtentry *);
745
746 struct ip6ctlparam;
747 void icmp6_mtudisc_update(struct ip6ctlparam *, int);
748
749 extern lck_rw_t icmp6_ifs_rwlock;
750 /* XXX: is this the right place for these macros? */
751 /* N.B.: if_inet6data is never freed once set, so we don't need to lock */
752 #define icmp6_ifstat_inc(_ifp, _tag) do { \
753 if (_ifp != NULL && IN6_IFEXTRA(_ifp) != NULL) { \
754 IN6_IFEXTRA(_ifp)->icmp6_ifstat._tag++; \
755 } \
756 } while (0)
757
758 #define icmp6_ifoutstat_inc(ifp, type, code) do { \
759 icmp6_ifstat_inc(ifp, ifs6_out_msg); \
760 if (type < ICMP6_INFOMSG_MASK) \
761 icmp6_ifstat_inc(ifp, ifs6_out_error); \
762 switch (type) { \
763 case ICMP6_DST_UNREACH: \
764 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
765 if (code == ICMP6_DST_UNREACH_ADMIN) \
766 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib);\
767 break; \
768 case ICMP6_PACKET_TOO_BIG: \
769 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
770 break; \
771 case ICMP6_TIME_EXCEEDED: \
772 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
773 break; \
774 case ICMP6_PARAM_PROB: \
775 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
776 break; \
777 case ICMP6_ECHO_REQUEST: \
778 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
779 break; \
780 case ICMP6_ECHO_REPLY: \
781 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
782 break; \
783 case MLD_LISTENER_QUERY: \
784 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
785 break; \
786 case MLD_LISTENER_REPORT: \
787 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
788 break; \
789 case MLD_LISTENER_DONE: \
790 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
791 break; \
792 case ND_ROUTER_SOLICIT: \
793 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
794 break; \
795 case ND_ROUTER_ADVERT: \
796 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
797 break; \
798 case ND_NEIGHBOR_SOLICIT: \
799 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit);\
800 break; \
801 case ND_NEIGHBOR_ADVERT: \
802 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
803 break; \
804 case ND_REDIRECT: \
805 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
806 break; \
807 } \
808 } while (0)
809
810 extern int icmp6_rediraccept; /* accept/process redirects */
811 extern int icmp6_redirtimeout; /* cache time for redirect routes */
812
813 #define ICMP6_NODEINFO_FQDNOK 0x1
814 #define ICMP6_NODEINFO_NODEADDROK 0x2
815 #define ICMP6_NODEINFO_TMPADDROK 0x4
816 #define ICMP6_NODEINFO_GLOBALOK 0x8
817
818 #endif /* BSD_KERNEL_PRIVATE */
819
820 #endif /* !_NETINET_ICMP6_H_ */