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