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