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