xref: /xnu-11417.140.69/bsd/netinet6/nd6.h (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1*43a90889SApple OSS Distributions /*
2*43a90889SApple OSS Distributions  * Copyright (c) 2000-2024 Apple Inc. All rights reserved.
3*43a90889SApple OSS Distributions  *
4*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*43a90889SApple OSS Distributions  *
6*43a90889SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*43a90889SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*43a90889SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*43a90889SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*43a90889SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*43a90889SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*43a90889SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*43a90889SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*43a90889SApple OSS Distributions  *
15*43a90889SApple OSS Distributions  * Please obtain a copy of the License at
16*43a90889SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*43a90889SApple OSS Distributions  *
18*43a90889SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*43a90889SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*43a90889SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*43a90889SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*43a90889SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*43a90889SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*43a90889SApple OSS Distributions  * limitations under the License.
25*43a90889SApple OSS Distributions  *
26*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*43a90889SApple OSS Distributions  */
28*43a90889SApple OSS Distributions /*
29*43a90889SApple OSS Distributions  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
30*43a90889SApple OSS Distributions  * All rights reserved.
31*43a90889SApple OSS Distributions  *
32*43a90889SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
33*43a90889SApple OSS Distributions  * modification, are permitted provided that the following conditions
34*43a90889SApple OSS Distributions  * are met:
35*43a90889SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
36*43a90889SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
37*43a90889SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
38*43a90889SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
39*43a90889SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
40*43a90889SApple OSS Distributions  * 3. Neither the name of the project nor the names of its contributors
41*43a90889SApple OSS Distributions  *    may be used to endorse or promote products derived from this software
42*43a90889SApple OSS Distributions  *    without specific prior written permission.
43*43a90889SApple OSS Distributions  *
44*43a90889SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
45*43a90889SApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46*43a90889SApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47*43a90889SApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
48*43a90889SApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49*43a90889SApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50*43a90889SApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51*43a90889SApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52*43a90889SApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53*43a90889SApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54*43a90889SApple OSS Distributions  * SUCH DAMAGE.
55*43a90889SApple OSS Distributions  */
56*43a90889SApple OSS Distributions 
57*43a90889SApple OSS Distributions #ifndef _NETINET6_ND6_H_
58*43a90889SApple OSS Distributions #define _NETINET6_ND6_H_
59*43a90889SApple OSS Distributions #include <sys/appleapiopts.h>
60*43a90889SApple OSS Distributions #include <net/net_kev.h>
61*43a90889SApple OSS Distributions 
62*43a90889SApple OSS Distributions /* see net/route.h, or net/if_inarp.h */
63*43a90889SApple OSS Distributions #ifndef RTF_ANNOUNCE
64*43a90889SApple OSS Distributions #define RTF_ANNOUNCE    RTF_PROTO2
65*43a90889SApple OSS Distributions #endif
66*43a90889SApple OSS Distributions 
67*43a90889SApple OSS Distributions #include <sys/queue.h>
68*43a90889SApple OSS Distributions 
69*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
70*43a90889SApple OSS Distributions #include <net/flowadv.h>
71*43a90889SApple OSS Distributions #include <kern/locks.h>
72*43a90889SApple OSS Distributions #include <sys/tree.h>
73*43a90889SApple OSS Distributions #include <sys/eventhandler.h>
74*43a90889SApple OSS Distributions #include <netinet6/nd6_var.h>
75*43a90889SApple OSS Distributions #include <sys/sdt.h>
76*43a90889SApple OSS Distributions 
77*43a90889SApple OSS Distributions struct  llinfo_nd6 {
78*43a90889SApple OSS Distributions 	/*
79*43a90889SApple OSS Distributions 	 * The following are protected by rnh_lock
80*43a90889SApple OSS Distributions 	 */
81*43a90889SApple OSS Distributions 	struct  llinfo_nd6 *ln_next;
82*43a90889SApple OSS Distributions 	struct  llinfo_nd6 *ln_prev;
83*43a90889SApple OSS Distributions 	struct  rtentry *ln_rt;
84*43a90889SApple OSS Distributions 	/*
85*43a90889SApple OSS Distributions 	 * The following are protected by rt_lock
86*43a90889SApple OSS Distributions 	 */
87*43a90889SApple OSS Distributions 	struct ifnet *ln_exclifp; /* excluded interface (prefix proxy) */
88*43a90889SApple OSS Distributions 	struct  mbuf *ln_hold;  /* last packet until resolved/timeout */
89*43a90889SApple OSS Distributions 	uint32_t ln_asked;      /* # of queries already sent for this addr */
90*43a90889SApple OSS Distributions 	short   ln_state;       /* reachability state */
91*43a90889SApple OSS Distributions 	short   ln_router;      /* 2^0: ND6 router bit */
92*43a90889SApple OSS Distributions 	u_int32_t ln_flags;     /* flags; see below */
93*43a90889SApple OSS Distributions 	u_int64_t ln_expire;    /* lifetime for NDP state transition */
94*43a90889SApple OSS Distributions 	u_int64_t ln_lastused;  /* last used timestamp */
95*43a90889SApple OSS Distributions 	struct  if_llreach *ln_llreach; /* link-layer reachability record */
96*43a90889SApple OSS Distributions };
97*43a90889SApple OSS Distributions 
98*43a90889SApple OSS Distributions /* Values for ln_flags */
99*43a90889SApple OSS Distributions #define ND6_LNF_TIMER_SKIP      0x1     /* modified by nd6_timer() */
100*43a90889SApple OSS Distributions #define ND6_LNF_IN_USE          0x2     /* currently in llinfo_nd6 list */
101*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
102*43a90889SApple OSS Distributions 
103*43a90889SApple OSS Distributions #define ND6_LLINFO_PURGE        -3
104*43a90889SApple OSS Distributions #define ND6_LLINFO_NOSTATE      -2
105*43a90889SApple OSS Distributions /*
106*43a90889SApple OSS Distributions  * We don't need the WAITDELETE state any more, but we keep the definition
107*43a90889SApple OSS Distributions  * in a comment line instead of removing it. This is necessary to avoid
108*43a90889SApple OSS Distributions  * unintentionally reusing the value for another purpose, which might
109*43a90889SApple OSS Distributions  * affect backward compatibility with old applications.
110*43a90889SApple OSS Distributions  * (20000711 [email protected])
111*43a90889SApple OSS Distributions  */
112*43a90889SApple OSS Distributions /* #define	ND6_LLINFO_WAITDELETE	-1 */
113*43a90889SApple OSS Distributions #define ND6_LLINFO_INCOMPLETE   0
114*43a90889SApple OSS Distributions #define ND6_LLINFO_REACHABLE    1
115*43a90889SApple OSS Distributions #define ND6_LLINFO_STALE        2
116*43a90889SApple OSS Distributions #define ND6_LLINFO_DELAY        3
117*43a90889SApple OSS Distributions #define ND6_LLINFO_PROBE        4
118*43a90889SApple OSS Distributions 
119*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
120*43a90889SApple OSS Distributions 
121*43a90889SApple OSS Distributions #define ND6_CACHE_STATE_TRANSITION(ln, nstate) do {\
122*43a90889SApple OSS Distributions 	DTRACE_IP2(nd6_state_transition, struct llinfo_nd6 *, (ln), int, (nstate));\
123*43a90889SApple OSS Distributions 	if (nd6_debug >= 3) {\
124*43a90889SApple OSS Distributions 	        struct rtentry *ln_rt = (ln) != NULL ? (ln)->ln_rt : NULL; \
125*43a90889SApple OSS Distributions 	        nd6log3(info,\
126*43a90889SApple OSS Distributions 	            "[%s:%d]: NDP cache entry changed from %s -> %s for address %s.\n",\
127*43a90889SApple OSS Distributions 	            __func__,\
128*43a90889SApple OSS Distributions 	            __LINE__,\
129*43a90889SApple OSS Distributions 	            ndcache_state2str((ln)->ln_state),\
130*43a90889SApple OSS Distributions 	            ndcache_state2str((nstate)),\
131*43a90889SApple OSS Distributions 	            ln_rt != NULL ? ip6_sprintf(&SIN6(rt_key(ln_rt))->sin6_addr) : "N/A");\
132*43a90889SApple OSS Distributions 	}\
133*43a90889SApple OSS Distributions 	if ((ln) != NULL) {\
134*43a90889SApple OSS Distributions 	        if ((ln)->ln_rt != NULL && (ln)->ln_rt->rt_ifp != NULL &&\
135*43a90889SApple OSS Distributions 	            ((ln)->ln_rt->rt_ifp->if_eflags & IFEF_IPV6_ND6ALT) &&\
136*43a90889SApple OSS Distributions 	            ((ln)->ln_state == ND6_LLINFO_REACHABLE)) {\
137*43a90889SApple OSS Distributions 	                VERIFY((nstate) != ND6_LLINFO_STALE &&\
138*43a90889SApple OSS Distributions 	                    (nstate) != ND6_LLINFO_DELAY &&\
139*43a90889SApple OSS Distributions 	                    (nstate) != ND6_LLINFO_PROBE);\
140*43a90889SApple OSS Distributions 	        }\
141*43a90889SApple OSS Distributions 	        (ln)->ln_state = (nstate);\
142*43a90889SApple OSS Distributions 	}\
143*43a90889SApple OSS Distributions } while(0)
144*43a90889SApple OSS Distributions 
145*43a90889SApple OSS Distributions #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE)
146*43a90889SApple OSS Distributions #define ND6_LLINFO_PERMANENT(n) \
147*43a90889SApple OSS Distributions 	(((n)->ln_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE))
148*43a90889SApple OSS Distributions 
149*43a90889SApple OSS Distributions #define ND6_EUI64_GBIT  0x01
150*43a90889SApple OSS Distributions #define ND6_EUI64_UBIT  0x02
151*43a90889SApple OSS Distributions 
152*43a90889SApple OSS Distributions #define ND6_EUI64_TO_IFID(in6) \
153*43a90889SApple OSS Distributions 	do {(in6)->s6_addr[8] ^= ND6_EUI64_UBIT; } while (0)
154*43a90889SApple OSS Distributions 
155*43a90889SApple OSS Distributions #define ND6_EUI64_GROUP(in6)            ((in6)->s6_addr[8] & ND6_EUI64_GBIT)
156*43a90889SApple OSS Distributions #define ND6_EUI64_INDIVIDUAL(in6)       (!ND6_EUI64_GROUP(in6))
157*43a90889SApple OSS Distributions #define ND6_EUI64_LOCAL(in6)            ((in6)->s6_addr[8] & ND6_EUI64_UBIT)
158*43a90889SApple OSS Distributions #define ND6_EUI64_UNIVERSAL(in6)        (!ND6_EUI64_LOCAL(in6))
159*43a90889SApple OSS Distributions #define ND6_IFID_LOCAL(in6)             (!ND6_EUI64_LOCAL(in6))
160*43a90889SApple OSS Distributions #define ND6_IFID_UNIVERSAL(in6)         (!ND6_EUI64_UNIVERSAL(in6))
161*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
162*43a90889SApple OSS Distributions 
163*43a90889SApple OSS Distributions #if !defined(BSD_KERNEL_PRIVATE)
164*43a90889SApple OSS Distributions struct nd_ifinfo {
165*43a90889SApple OSS Distributions #else
166*43a90889SApple OSS Distributions /* For binary compatibility, this structure must not change */
167*43a90889SApple OSS Distributions /* NOTE: nd_ifinfo is defined in nd6_var.h */
168*43a90889SApple OSS Distributions struct nd_ifinfo_compat {
169*43a90889SApple OSS Distributions #endif /* !BSD_KERNEL_PRIVATE */
170*43a90889SApple OSS Distributions 	u_int32_t linkmtu;              /* LinkMTU */
171*43a90889SApple OSS Distributions 	u_int32_t maxmtu;               /* Upper bound of LinkMTU */
172*43a90889SApple OSS Distributions 	u_int32_t basereachable;        /* BaseReachableTime */
173*43a90889SApple OSS Distributions 	u_int32_t reachable;            /* Reachable Time */
174*43a90889SApple OSS Distributions 	u_int32_t retrans;              /* Retrans Timer */
175*43a90889SApple OSS Distributions 	u_int32_t flags;                /* Flags */
176*43a90889SApple OSS Distributions 	int recalctm;                   /* BaseReacable re-calculation timer */
177*43a90889SApple OSS Distributions 	u_int8_t chlim;                 /* CurHopLimit */
178*43a90889SApple OSS Distributions 	u_int8_t receivedra;
179*43a90889SApple OSS Distributions 	/* the following 3 members are for privacy extension for addrconf */
180*43a90889SApple OSS Distributions 	u_int8_t randomseed0[8]; /* upper 64 bits of SHA256 digest */
181*43a90889SApple OSS Distributions 	u_int8_t randomseed1[8]; /* lower 64 bits (usually the EUI64 IFID) */
182*43a90889SApple OSS Distributions 	u_int8_t randomid[8];   /* current random ID */
183*43a90889SApple OSS Distributions };
184*43a90889SApple OSS Distributions 
185*43a90889SApple OSS Distributions #define ND6_IFF_PERFORMNUD              0x1
186*43a90889SApple OSS Distributions #if defined(PRIVATE)
187*43a90889SApple OSS Distributions 
188*43a90889SApple OSS Distributions /*
189*43a90889SApple OSS Distributions  * APPLE: not used. Interface specific router advertisements are handled with a
190*43a90889SApple OSS Distributions  * specific ifnet flag: IFEF_ACCEPT_RTADVD
191*43a90889SApple OSS Distributions  */
192*43a90889SApple OSS Distributions #define ND6_IFF_ACCEPT_RTADV            0x2
193*43a90889SApple OSS Distributions 
194*43a90889SApple OSS Distributions /* APPLE: NOT USED not related to ND. */
195*43a90889SApple OSS Distributions #define ND6_IFF_PREFER_SOURCE           0x4
196*43a90889SApple OSS Distributions 
197*43a90889SApple OSS Distributions /* IPv6 operation is disabled due to * DAD failure.  (XXX: not ND-specific) */
198*43a90889SApple OSS Distributions #define ND6_IFF_IFDISABLED              0x8
199*43a90889SApple OSS Distributions 
200*43a90889SApple OSS Distributions #define ND6_IFF_DONT_SET_IFROUTE        0x10 /* NOT USED */
201*43a90889SApple OSS Distributions #endif /* PRIVATE */
202*43a90889SApple OSS Distributions #define ND6_IFF_PROXY_PREFIXES          0x20
203*43a90889SApple OSS Distributions #define ND6_IFF_IGNORE_NA               0x40
204*43a90889SApple OSS Distributions #if defined(PRIVATE)
205*43a90889SApple OSS Distributions #define ND6_IFF_INSECURE                0x80
206*43a90889SApple OSS Distributions #endif
207*43a90889SApple OSS Distributions #define ND6_IFF_REPLICATED              0x100   /* sleep proxy registered */
208*43a90889SApple OSS Distributions #define ND6_IFF_DAD                     0x200   /* Perform DAD on the interface */
209*43a90889SApple OSS Distributions 
210*43a90889SApple OSS Distributions extern int dad_enhanced;
211*43a90889SApple OSS Distributions #define ND6_DAD_ENHANCED_DEFAULT        1
212*43a90889SApple OSS Distributions 
213*43a90889SApple OSS Distributions struct in6_nbrinfo {
214*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];  /* if name, e.g. "en0" */
215*43a90889SApple OSS Distributions 	struct in6_addr addr;   /* IPv6 address of the neighbor */
216*43a90889SApple OSS Distributions 	long    asked;          /* # of queries already sent for this addr */
217*43a90889SApple OSS Distributions 	int     isrouter;       /* if it acts as a router */
218*43a90889SApple OSS Distributions 	int     state;          /* reachability state */
219*43a90889SApple OSS Distributions 	int     expire;         /* lifetime for NDP state transition */
220*43a90889SApple OSS Distributions };
221*43a90889SApple OSS Distributions 
222*43a90889SApple OSS Distributions #if defined(BSD_KERNEL_PRIVATE)
223*43a90889SApple OSS Distributions struct in6_nbrinfo_32 {
224*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];
225*43a90889SApple OSS Distributions 	struct in6_addr addr;
226*43a90889SApple OSS Distributions 	u_int32_t asked;
227*43a90889SApple OSS Distributions 	int     isrouter;
228*43a90889SApple OSS Distributions 	int     state;
229*43a90889SApple OSS Distributions 	int     expire;
230*43a90889SApple OSS Distributions };
231*43a90889SApple OSS Distributions 
232*43a90889SApple OSS Distributions struct in6_nbrinfo_64 {
233*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];
234*43a90889SApple OSS Distributions 	struct in6_addr addr;
235*43a90889SApple OSS Distributions 	long    asked;
236*43a90889SApple OSS Distributions 	int     isrouter        __attribute__((aligned(8)));
237*43a90889SApple OSS Distributions 	int     state;
238*43a90889SApple OSS Distributions 	int     expire;
239*43a90889SApple OSS Distributions } __attribute__((aligned(8)));
240*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
241*43a90889SApple OSS Distributions 
242*43a90889SApple OSS Distributions #if defined(BSD_KERNEL_PRIVATE)
243*43a90889SApple OSS Distributions #define ND6_PROCESS_RTI_ENABLE    1
244*43a90889SApple OSS Distributions #define ND6_PROCESS_RTI_DISABLE   0
245*43a90889SApple OSS Distributions #define ND6_PROCESS_RTI_DEFAULT   ND6_PROCESS_RTI_ENABLE
246*43a90889SApple OSS Distributions 
247*43a90889SApple OSS Distributions extern int nd6_process_rti;
248*43a90889SApple OSS Distributions 
249*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
250*43a90889SApple OSS Distributions 
251*43a90889SApple OSS Distributions /* valid values for stateflags */
252*43a90889SApple OSS Distributions #define NDDRF_INSTALLED 0x01     /* installed in the routing table */
253*43a90889SApple OSS Distributions #define NDDRF_IFSCOPE   0x02     /* installed as a scoped route */
254*43a90889SApple OSS Distributions #define NDDRF_STATIC    0x04     /* for internal use only */
255*43a90889SApple OSS Distributions #define NDDRF_MAPPED    0x08     /* Default router addr is mapped to a different one for routing */
256*43a90889SApple OSS Distributions #define NDDRF_INELIGIBLE     0x10     /* Default router entry is ineligible for default router selection */
257*43a90889SApple OSS Distributions #define NDDRF_LOCAL          0x20     /* Router's address is locally hosted as well */
258*43a90889SApple OSS Distributions 
259*43a90889SApple OSS Distributions struct  in6_defrouter {
260*43a90889SApple OSS Distributions 	struct  sockaddr_in6 rtaddr;
261*43a90889SApple OSS Distributions 	u_char  flags;
262*43a90889SApple OSS Distributions 	u_char  stateflags;
263*43a90889SApple OSS Distributions 	u_short rtlifetime;
264*43a90889SApple OSS Distributions 	u_long  expire;
265*43a90889SApple OSS Distributions 	u_short if_index;
266*43a90889SApple OSS Distributions };
267*43a90889SApple OSS Distributions 
268*43a90889SApple OSS Distributions #if defined(BSD_KERNEL_PRIVATE)
269*43a90889SApple OSS Distributions struct  in6_defrouter_32 {
270*43a90889SApple OSS Distributions 	struct  sockaddr_in6 rtaddr;
271*43a90889SApple OSS Distributions 	u_char  flags;
272*43a90889SApple OSS Distributions 	u_char  stateflags;
273*43a90889SApple OSS Distributions 	u_short rtlifetime;
274*43a90889SApple OSS Distributions 	u_int32_t expire;
275*43a90889SApple OSS Distributions 	u_short if_index;
276*43a90889SApple OSS Distributions };
277*43a90889SApple OSS Distributions 
278*43a90889SApple OSS Distributions struct  in6_defrouter_64 {
279*43a90889SApple OSS Distributions 	struct  sockaddr_in6 rtaddr;
280*43a90889SApple OSS Distributions 	u_char  flags;
281*43a90889SApple OSS Distributions 	u_char  stateflags;
282*43a90889SApple OSS Distributions 	u_short rtlifetime;
283*43a90889SApple OSS Distributions 	u_long  expire          __attribute__((aligned(8)));
284*43a90889SApple OSS Distributions 	u_short if_index        __attribute__((aligned(8)));
285*43a90889SApple OSS Distributions } __attribute__((aligned(8)));
286*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
287*43a90889SApple OSS Distributions 
288*43a90889SApple OSS Distributions struct in6_prefix {
289*43a90889SApple OSS Distributions 	struct  sockaddr_in6 prefix;
290*43a90889SApple OSS Distributions 	struct prf_ra raflags;
291*43a90889SApple OSS Distributions 	u_char  prefixlen;
292*43a90889SApple OSS Distributions 	u_char  origin;
293*43a90889SApple OSS Distributions 	u_long  vltime;
294*43a90889SApple OSS Distributions 	u_long  pltime;
295*43a90889SApple OSS Distributions 	u_long  expire;
296*43a90889SApple OSS Distributions 	u_int32_t flags;
297*43a90889SApple OSS Distributions 	int refcnt;
298*43a90889SApple OSS Distributions 	u_short if_index;
299*43a90889SApple OSS Distributions 	u_short advrtrs; /* number of advertisement routers */
300*43a90889SApple OSS Distributions 	/* struct sockaddr_in6 advrtr[] */
301*43a90889SApple OSS Distributions };
302*43a90889SApple OSS Distributions 
303*43a90889SApple OSS Distributions #if defined(BSD_KERNEL_PRIVATE)
304*43a90889SApple OSS Distributions struct in6_prefix_32 {
305*43a90889SApple OSS Distributions 	struct  sockaddr_in6 prefix;
306*43a90889SApple OSS Distributions 	struct prf_ra raflags;
307*43a90889SApple OSS Distributions 	u_char  prefixlen;
308*43a90889SApple OSS Distributions 	u_char  origin;
309*43a90889SApple OSS Distributions 	u_int32_t vltime;
310*43a90889SApple OSS Distributions 	u_int32_t pltime;
311*43a90889SApple OSS Distributions 	u_int32_t expire;
312*43a90889SApple OSS Distributions 	u_int32_t flags;
313*43a90889SApple OSS Distributions 	int refcnt;
314*43a90889SApple OSS Distributions 	u_short if_index;
315*43a90889SApple OSS Distributions 	u_short advrtrs; /* number of advertisement routers */
316*43a90889SApple OSS Distributions 	/* struct sockaddr_in6 advrtr[] */
317*43a90889SApple OSS Distributions };
318*43a90889SApple OSS Distributions 
319*43a90889SApple OSS Distributions struct in6_prefix_64 {
320*43a90889SApple OSS Distributions 	struct  sockaddr_in6 prefix;
321*43a90889SApple OSS Distributions 	struct prf_ra raflags;
322*43a90889SApple OSS Distributions 	u_char  prefixlen;
323*43a90889SApple OSS Distributions 	u_char  origin;
324*43a90889SApple OSS Distributions 	u_long  vltime  __attribute__((aligned(8)));
325*43a90889SApple OSS Distributions 	u_long  pltime  __attribute__((aligned(8)));
326*43a90889SApple OSS Distributions 	u_long  expire  __attribute__((aligned(8)));
327*43a90889SApple OSS Distributions 	u_int32_t flags __attribute__((aligned(8)));
328*43a90889SApple OSS Distributions 	int refcnt;
329*43a90889SApple OSS Distributions 	u_short if_index;
330*43a90889SApple OSS Distributions 	u_short advrtrs;
331*43a90889SApple OSS Distributions 	/* struct sockaddr_in6 advrtr[] */
332*43a90889SApple OSS Distributions };
333*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
334*43a90889SApple OSS Distributions 
335*43a90889SApple OSS Distributions struct  in6_ondireq {
336*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];
337*43a90889SApple OSS Distributions 	struct {
338*43a90889SApple OSS Distributions 		u_int32_t linkmtu;      /* LinkMTU */
339*43a90889SApple OSS Distributions 		u_int32_t maxmtu;       /* Upper bound of LinkMTU */
340*43a90889SApple OSS Distributions 		u_int32_t basereachable; /* BaseReachableTime */
341*43a90889SApple OSS Distributions 		u_int32_t reachable;    /* Reachable Time */
342*43a90889SApple OSS Distributions 		u_int32_t retrans;      /* Retrans Timer */
343*43a90889SApple OSS Distributions 		u_int32_t flags;        /* Flags */
344*43a90889SApple OSS Distributions 		int recalctm;           /* BaseReacable re-calculation timer */
345*43a90889SApple OSS Distributions 		u_int8_t chlim;         /* CurHopLimit */
346*43a90889SApple OSS Distributions 		/* Number of routers learned on the  interface */
347*43a90889SApple OSS Distributions 		u_int8_t receivedra;
348*43a90889SApple OSS Distributions 		/*
349*43a90889SApple OSS Distributions 		 * The current collision count value
350*43a90889SApple OSS Distributions 		 * being used for secure address generation.
351*43a90889SApple OSS Distributions 		 */
352*43a90889SApple OSS Distributions 		u_int8_t collision_count;
353*43a90889SApple OSS Distributions 	} ndi;
354*43a90889SApple OSS Distributions };
355*43a90889SApple OSS Distributions 
356*43a90889SApple OSS Distributions #if !defined(BSD_KERNEL_PRIVATE)
357*43a90889SApple OSS Distributions struct  in6_ndireq {
358*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];
359*43a90889SApple OSS Distributions 	struct nd_ifinfo ndi;
360*43a90889SApple OSS Distributions };
361*43a90889SApple OSS Distributions #else
362*43a90889SApple OSS Distributions struct  in6_ndireq {
363*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];
364*43a90889SApple OSS Distributions 	struct nd_ifinfo_compat ndi;
365*43a90889SApple OSS Distributions };
366*43a90889SApple OSS Distributions #endif /* !BSD_KERNEL_PRIVATE */
367*43a90889SApple OSS Distributions 
368*43a90889SApple OSS Distributions struct  in6_ndifreq {
369*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];
370*43a90889SApple OSS Distributions 	u_long ifindex;
371*43a90889SApple OSS Distributions };
372*43a90889SApple OSS Distributions 
373*43a90889SApple OSS Distributions #define MAX_RTR_SOLICITATION_DELAY      1       /* 1sec */
374*43a90889SApple OSS Distributions #define RTR_SOLICITATION_INTERVAL       4       /* 4sec */
375*43a90889SApple OSS Distributions 
376*43a90889SApple OSS Distributions #if defined(BSD_KERNEL_PRIVATE)
377*43a90889SApple OSS Distributions struct  in6_ndifreq_32 {
378*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];
379*43a90889SApple OSS Distributions 	u_int32_t ifindex;
380*43a90889SApple OSS Distributions };
381*43a90889SApple OSS Distributions 
382*43a90889SApple OSS Distributions struct  in6_ndifreq_64 {
383*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];
384*43a90889SApple OSS Distributions 	u_int64_t ifindex  __attribute__((aligned(8)));
385*43a90889SApple OSS Distributions };
386*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
387*43a90889SApple OSS Distributions 
388*43a90889SApple OSS Distributions /* Prefix status */
389*43a90889SApple OSS Distributions #define NDPRF_ONLINK            0x1
390*43a90889SApple OSS Distributions #define NDPRF_DETACHED          0x2
391*43a90889SApple OSS Distributions #define NDPRF_STATIC            0x100
392*43a90889SApple OSS Distributions #define NDPRF_IFSCOPE           0x1000
393*43a90889SApple OSS Distributions #define NDPRF_PRPROXY           0x2000
394*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
395*43a90889SApple OSS Distributions #define NDPRF_PROCESSED_ONLINK  0x08000
396*43a90889SApple OSS Distributions #define NDPRF_PROCESSED_SERVICE 0x10000
397*43a90889SApple OSS Distributions #define NDPRF_DEFUNCT           0x20000
398*43a90889SApple OSS Distributions #define NDPRF_CLAT46            0x40000
399*43a90889SApple OSS Distributions 
400*43a90889SApple OSS Distributions #define CLAT46_COLLISION_COUNT_OFFSET   128
401*43a90889SApple OSS Distributions #endif
402*43a90889SApple OSS Distributions 
403*43a90889SApple OSS Distributions /* protocol constants */
404*43a90889SApple OSS Distributions #define MAX_RTR_SOLICITATION_DELAY      1       /* 1sec */
405*43a90889SApple OSS Distributions #define RTR_SOLICITATION_INTERVAL       4       /* 4sec */
406*43a90889SApple OSS Distributions #define MAX_RTR_SOLICITATIONS           3
407*43a90889SApple OSS Distributions 
408*43a90889SApple OSS Distributions #define ND6_INFINITE_LIFETIME           0xffffffff
409*43a90889SApple OSS Distributions #define ND6_MAX_LIFETIME                0x7fffffff
410*43a90889SApple OSS Distributions 
411*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
412*43a90889SApple OSS Distributions #define ND_IFINFO(ifp)                          \
413*43a90889SApple OSS Distributions     ((ifp == NULL) ? NULL :                     \
414*43a90889SApple OSS Distributions      ((IN6_IFEXTRA(ifp) == NULL) ? NULL :       \
415*43a90889SApple OSS Distributions       (&IN6_IFEXTRA(ifp)->nd_ifinfo)))
416*43a90889SApple OSS Distributions 
417*43a90889SApple OSS Distributions /*
418*43a90889SApple OSS Distributions  * In a more readable form, we derive linkmtu based on:
419*43a90889SApple OSS Distributions  *
420*43a90889SApple OSS Distributions  * if (ifp == NULL)
421*43a90889SApple OSS Distributions  *         linkmtu = IPV6_MMTU
422*43a90889SApple OSS Distributions  * else if (ND_IFINFO(ifp) == NULL || !ND_IFINFO(ifp)->initialized)
423*43a90889SApple OSS Distributions  *         linkmtu = ifp->if_mtu;
424*43a90889SApple OSS Distributions  * else if (ND_IFINFO(ifp)->linkmtu && ND_IFINFO(ifp)->linkmtu < ifp->if_mtu)
425*43a90889SApple OSS Distributions  *         linkmtu = ND_IFINFO(ifp)->linkmtu;
426*43a90889SApple OSS Distributions  * else if ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < ifp->if_mtu))
427*43a90889SApple OSS Distributions  *         linkmtu = ND_IFINFO(ifp)->maxmtu;
428*43a90889SApple OSS Distributions  * else
429*43a90889SApple OSS Distributions  *         linkmtu = ifp->if_mtu;
430*43a90889SApple OSS Distributions  */
431*43a90889SApple OSS Distributions #define IN6_LINKMTU(ifp)                                                      \
432*43a90889SApple OSS Distributions 	(ifp == NULL ? IPV6_MMTU :                                            \
433*43a90889SApple OSS Distributions 	(ND_IFINFO(ifp) == NULL || !ND_IFINFO(ifp)->initialized) ?            \
434*43a90889SApple OSS Distributions 	(ifp)->if_mtu :	((ND_IFINFO(ifp)->linkmtu &&                          \
435*43a90889SApple OSS Distributions 	ND_IFINFO(ifp)->linkmtu < (ifp)->if_mtu) ? ND_IFINFO(ifp)->linkmtu :  \
436*43a90889SApple OSS Distributions 	((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < (ifp)->if_mtu) ? \
437*43a90889SApple OSS Distributions 	ND_IFINFO(ifp)->maxmtu : (ifp)->if_mtu)))
438*43a90889SApple OSS Distributions 
439*43a90889SApple OSS Distributions /* node constants */
440*43a90889SApple OSS Distributions #define MAX_REACHABLE_TIME              3600000 /* msec */
441*43a90889SApple OSS Distributions #define REACHABLE_TIME                  30000   /* msec */
442*43a90889SApple OSS Distributions #define RETRANS_TIMER                   1000    /* msec */
443*43a90889SApple OSS Distributions #define MIN_RANDOM_FACTOR               512     /* 1024 * 0.5 */
444*43a90889SApple OSS Distributions #define MAX_RANDOM_FACTOR               1536    /* 1024 * 1.5 */
445*43a90889SApple OSS Distributions #define DEF_TEMP_VALID_LIFETIME         604800  /* 1 week */
446*43a90889SApple OSS Distributions #define DEF_TEMP_PREFERRED_LIFETIME     86400   /* 1 day */
447*43a90889SApple OSS Distributions #define TEMPADDR_REGEN_ADVANCE          5       /* sec */
448*43a90889SApple OSS Distributions #define MAX_TEMP_DESYNC_FACTOR          600     /* 10 min */
449*43a90889SApple OSS Distributions #define ND_COMPUTE_RTIME(x) \
450*43a90889SApple OSS Distributions 	        (((MIN_RANDOM_FACTOR * (x >> 10)) + (RandomULong() & \
451*43a90889SApple OSS Distributions 	        ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
452*43a90889SApple OSS Distributions 
453*43a90889SApple OSS Distributions #define IP6_USE_TMPADDR_DEFAULT         1
454*43a90889SApple OSS Distributions #define IP6_ULA_USE_TMPADDR_DEFAULT     0
455*43a90889SApple OSS Distributions /* prefix expiry times */
456*43a90889SApple OSS Distributions #define ND6_PREFIX_EXPIRY_UNSPEC        -1
457*43a90889SApple OSS Distributions #define ND6_PREFIX_EXPIRY_NEVER         0
458*43a90889SApple OSS Distributions 
459*43a90889SApple OSS Distributions TAILQ_HEAD(nd_drhead, nd_defrouter);
460*43a90889SApple OSS Distributions struct nd_defrouter {
461*43a90889SApple OSS Distributions 	decl_lck_mtx_data(, nddr_lock);
462*43a90889SApple OSS Distributions 	decl_lck_mtx_data(, nddr_ref_lock);
463*43a90889SApple OSS Distributions 	TAILQ_ENTRY(nd_defrouter) dr_entry;
464*43a90889SApple OSS Distributions 	struct in6_addr rtaddr;
465*43a90889SApple OSS Distributions 	u_int32_t       nddr_refcount;
466*43a90889SApple OSS Distributions 	u_int32_t       nddr_debug;
467*43a90889SApple OSS Distributions 	u_int64_t       expire;
468*43a90889SApple OSS Distributions 	u_int64_t       base_calendartime;      /* calendar time at creation */
469*43a90889SApple OSS Distributions 	u_int64_t       base_uptime;            /* uptime at creation */
470*43a90889SApple OSS Distributions 	u_char          flags;                  /* flags on RA message */
471*43a90889SApple OSS Distributions 	u_char          stateflags;
472*43a90889SApple OSS Distributions 	u_int32_t       rtlifetime;
473*43a90889SApple OSS Distributions 	int             err;
474*43a90889SApple OSS Distributions 	struct ifnet    *ifp;
475*43a90889SApple OSS Distributions 	struct in6_addr rtaddr_mapped;          /* Mapped gateway address for routing */
476*43a90889SApple OSS Distributions 	boolean_t       is_reachable;
477*43a90889SApple OSS Distributions 	void (*nddr_trace)(struct nd_defrouter *, int); /* trace callback fn */
478*43a90889SApple OSS Distributions };
479*43a90889SApple OSS Distributions 
480*43a90889SApple OSS Distributions #define NDDR_LOCK_ASSERT_HELD(_nddr)                                    \
481*43a90889SApple OSS Distributions 	LCK_MTX_ASSERT(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_OWNED)
482*43a90889SApple OSS Distributions 
483*43a90889SApple OSS Distributions #define NDDR_LOCK_ASSERT_NOTHELD(_nddr)                                 \
484*43a90889SApple OSS Distributions 	LCK_MTX_ASSERT(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_NOTOWNED)
485*43a90889SApple OSS Distributions 
486*43a90889SApple OSS Distributions #define NDDR_LOCK(_nddr)                                                \
487*43a90889SApple OSS Distributions 	lck_mtx_lock(&(_nddr)->nddr_lock)
488*43a90889SApple OSS Distributions 
489*43a90889SApple OSS Distributions #define NDDR_LOCK_SPIN(_nddr)                                           \
490*43a90889SApple OSS Distributions 	lck_mtx_lock_spin(&(_nddr)->nddr_lock)
491*43a90889SApple OSS Distributions 
492*43a90889SApple OSS Distributions #define NDDR_CONVERT_LOCK(_nddr) do {                                   \
493*43a90889SApple OSS Distributions 	NDPR_LOCK_ASSERT_HELD(_nddr);                                   \
494*43a90889SApple OSS Distributions 	lck_mtx_convert_spin(&(_nddr)->nddr_lock);                      \
495*43a90889SApple OSS Distributions } while (0)
496*43a90889SApple OSS Distributions 
497*43a90889SApple OSS Distributions #define NDDR_UNLOCK(_nddr)                                              \
498*43a90889SApple OSS Distributions 	lck_mtx_unlock(&(_nddr)->nddr_lock)
499*43a90889SApple OSS Distributions 
500*43a90889SApple OSS Distributions #define NDDR_REF_LOCK(_nddr)                                            \
501*43a90889SApple OSS Distributions 	lck_mtx_lock(&(_nddr)->nddr_ref_lock)
502*43a90889SApple OSS Distributions 
503*43a90889SApple OSS Distributions #define NDDR_REF_LOCK_SPIN(_nddr)                                       \
504*43a90889SApple OSS Distributions 	lck_mtx_lock_spin(&(_nddr)->nddr_ref_lock)
505*43a90889SApple OSS Distributions 
506*43a90889SApple OSS Distributions #define NDDR_REF_UNLOCK(_nddr)                                          \
507*43a90889SApple OSS Distributions 	lck_mtx_unlock(&(_nddr)->nddr_ref_lock)
508*43a90889SApple OSS Distributions 
509*43a90889SApple OSS Distributions #define NDDR_ADDREF(_nddr)                                              \
510*43a90889SApple OSS Distributions 	nddr_addref(_nddr)
511*43a90889SApple OSS Distributions 
512*43a90889SApple OSS Distributions #define NDDR_REMREF(_nddr)                                              \
513*43a90889SApple OSS Distributions 	nddr_remref(_nddr)                                              \
514*43a90889SApple OSS Distributions 
515*43a90889SApple OSS Distributions TAILQ_HEAD(nd_rtihead, nd_route_info);
516*43a90889SApple OSS Distributions /*
517*43a90889SApple OSS Distributions  * The ordering below is important and it should always start
518*43a90889SApple OSS Distributions  * with nd_drhead as the first element.
519*43a90889SApple OSS Distributions  * It gets passed in as the generic nd_drhead to router management code.
520*43a90889SApple OSS Distributions  * The extra information stored here includes the prefix/prefix-length
521*43a90889SApple OSS Distributions  * which the router list belongs to.
522*43a90889SApple OSS Distributions  */
523*43a90889SApple OSS Distributions struct nd_route_info {
524*43a90889SApple OSS Distributions 	struct nd_drhead nd_rti_router_list;
525*43a90889SApple OSS Distributions 	TAILQ_ENTRY(nd_route_info) nd_rti_entry;
526*43a90889SApple OSS Distributions 	struct in6_addr nd_rti_prefix;
527*43a90889SApple OSS Distributions 	u_int8_t nd_rti_prefixlen;
528*43a90889SApple OSS Distributions };
529*43a90889SApple OSS Distributions 
530*43a90889SApple OSS Distributions struct nd_route_info *ndrti_alloc(void);
531*43a90889SApple OSS Distributions void nd6_rti_list_wait(const char *);
532*43a90889SApple OSS Distributions void nd6_rti_list_signal_done(void);
533*43a90889SApple OSS Distributions void ndrti_free(struct nd_route_info *rti);
534*43a90889SApple OSS Distributions void nd6_rtilist_remove(struct nd_route_info *);
535*43a90889SApple OSS Distributions void nd6_rtilist_update(struct nd_route_info *, struct nd_defrouter *);
536*43a90889SApple OSS Distributions int nd6_rtilist_add(struct nd_route_info *, struct nd_defrouter *,
537*43a90889SApple OSS Distributions     struct nd_route_info **);
538*43a90889SApple OSS Distributions void nd6_rti_purge(struct nd_route_info *);
539*43a90889SApple OSS Distributions void nd6_rti_delreq(struct nd_route_info *);
540*43a90889SApple OSS Distributions void nd6_rti_select(struct nd_route_info *, struct ifnet *);
541*43a90889SApple OSS Distributions 
542*43a90889SApple OSS Distributions /* define struct prproxy_sols_tree */
543*43a90889SApple OSS Distributions RB_HEAD(prproxy_sols_tree, nd6_prproxy_soltgt);
544*43a90889SApple OSS Distributions 
545*43a90889SApple OSS Distributions struct nd_prefix {
546*43a90889SApple OSS Distributions 	decl_lck_mtx_data(, ndpr_lock);
547*43a90889SApple OSS Distributions 	decl_lck_mtx_data(, ndpr_ref_lock);
548*43a90889SApple OSS Distributions 	u_int32_t       ndpr_refcount;  /* reference count */
549*43a90889SApple OSS Distributions 	u_int32_t       ndpr_debug;     /* see ifa_debug flags */
550*43a90889SApple OSS Distributions 	struct ifnet     *ndpr_ifp;
551*43a90889SApple OSS Distributions 	struct rtentry   *ndpr_rt;
552*43a90889SApple OSS Distributions 	LIST_ENTRY(nd_prefix) ndpr_entry;
553*43a90889SApple OSS Distributions 	struct sockaddr_in6 ndpr_prefix; /* prefix */
554*43a90889SApple OSS Distributions 	struct in6_addr ndpr_mask; /* netmask derived from the prefix */
555*43a90889SApple OSS Distributions 	struct in6_addr ndpr_addr; /* address that is derived from the prefix */
556*43a90889SApple OSS Distributions 	u_int32_t       ndpr_vltime;    /* advertised valid lifetime */
557*43a90889SApple OSS Distributions 	u_int32_t       ndpr_pltime;    /* advertised preferred lifetime */
558*43a90889SApple OSS Distributions 	u_int64_t       ndpr_preferred; /* preferred time of the prefix */
559*43a90889SApple OSS Distributions 	u_int64_t       ndpr_expire;    /* expiration time of the prefix */
560*43a90889SApple OSS Distributions 	u_int64_t       ndpr_lastupdate; /* rx time of last advertisement */
561*43a90889SApple OSS Distributions 	u_int64_t       ndpr_base_calendartime; /* calendar time at creation */
562*43a90889SApple OSS Distributions 	u_int64_t       ndpr_base_uptime;       /* uptime at creation */
563*43a90889SApple OSS Distributions 	struct prf_ra   ndpr_flags;
564*43a90889SApple OSS Distributions 	unsigned int    ndpr_genid;     /* protects ndpr_advrtrs */
565*43a90889SApple OSS Distributions 	u_int32_t       ndpr_stateflags; /* actual state flags */
566*43a90889SApple OSS Distributions 	/* list of routers that advertise the prefix: */
567*43a90889SApple OSS Distributions 	LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs;
568*43a90889SApple OSS Distributions 	u_char          ndpr_plen;
569*43a90889SApple OSS Distributions 	int             ndpr_addrcnt;   /* reference counter from addresses */
570*43a90889SApple OSS Distributions 	int             ndpr_manual_addrcnt; /* reference counter non-autoconf addresses */
571*43a90889SApple OSS Distributions 	u_int32_t       ndpr_allmulti_cnt;      /* total all-multi reqs */
572*43a90889SApple OSS Distributions 	u_int32_t       ndpr_prproxy_sols_cnt;  /* total # of proxied NS */
573*43a90889SApple OSS Distributions 	struct prproxy_sols_tree ndpr_prproxy_sols; /* tree of proxied NS */
574*43a90889SApple OSS Distributions 	void (*ndpr_trace)(struct nd_prefix *, int); /* trace callback fn */
575*43a90889SApple OSS Distributions };
576*43a90889SApple OSS Distributions 
577*43a90889SApple OSS Distributions #define ndpr_next               ndpr_entry.le_next
578*43a90889SApple OSS Distributions 
579*43a90889SApple OSS Distributions #define ndpr_raf                ndpr_flags
580*43a90889SApple OSS Distributions #define ndpr_raf_onlink         ndpr_flags.onlink
581*43a90889SApple OSS Distributions #define ndpr_raf_auto           ndpr_flags.autonomous
582*43a90889SApple OSS Distributions #define ndpr_raf_router         ndpr_flags.router
583*43a90889SApple OSS Distributions /*
584*43a90889SApple OSS Distributions  * We keep expired prefix for certain amount of time, for validation purposes.
585*43a90889SApple OSS Distributions  * 1800s = MaxRtrAdvInterval
586*43a90889SApple OSS Distributions  */
587*43a90889SApple OSS Distributions #define NDPR_KEEP_EXPIRED       (1800 * 2)
588*43a90889SApple OSS Distributions 
589*43a90889SApple OSS Distributions #define NDPR_LOCK_ASSERT_HELD(_ndpr)                                    \
590*43a90889SApple OSS Distributions 	LCK_MTX_ASSERT(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_OWNED)
591*43a90889SApple OSS Distributions 
592*43a90889SApple OSS Distributions #define NDPR_LOCK_ASSERT_NOTHELD(_ndpr)                                 \
593*43a90889SApple OSS Distributions 	LCK_MTX_ASSERT(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_NOTOWNED)
594*43a90889SApple OSS Distributions 
595*43a90889SApple OSS Distributions #define NDPR_LOCK(_ndpr)                                                \
596*43a90889SApple OSS Distributions 	lck_mtx_lock(&(_ndpr)->ndpr_lock)
597*43a90889SApple OSS Distributions 
598*43a90889SApple OSS Distributions #define NDPR_LOCK_SPIN(_ndpr)                                           \
599*43a90889SApple OSS Distributions 	lck_mtx_lock_spin(&(_ndpr)->ndpr_lock)
600*43a90889SApple OSS Distributions 
601*43a90889SApple OSS Distributions #define NDPR_CONVERT_LOCK(_ndpr) do {                                   \
602*43a90889SApple OSS Distributions 	NDPR_LOCK_ASSERT_HELD(_ndpr);                                   \
603*43a90889SApple OSS Distributions 	lck_mtx_convert_spin(&(_ndpr)->ndpr_lock);                      \
604*43a90889SApple OSS Distributions } while (0)
605*43a90889SApple OSS Distributions 
606*43a90889SApple OSS Distributions #define NDPR_UNLOCK(_ndpr)                                              \
607*43a90889SApple OSS Distributions 	lck_mtx_unlock(&(_ndpr)->ndpr_lock)
608*43a90889SApple OSS Distributions 
609*43a90889SApple OSS Distributions #define NDPR_REF_LOCK(_ndpr)                                            \
610*43a90889SApple OSS Distributions 	lck_mtx_lock(&(_ndpr)->ndpr_ref_lock)
611*43a90889SApple OSS Distributions 
612*43a90889SApple OSS Distributions #define NDPR_REF_LOCK_SPIN(_ndpr)                                       \
613*43a90889SApple OSS Distributions 	lck_mtx_lock_spin(&(_ndpr)->ndpr_ref_lock)
614*43a90889SApple OSS Distributions 
615*43a90889SApple OSS Distributions #define NDPR_REF_UNLOCK(_ndpr)                                          \
616*43a90889SApple OSS Distributions 	lck_mtx_unlock(&(_ndpr)->ndpr_ref_lock)
617*43a90889SApple OSS Distributions 
618*43a90889SApple OSS Distributions #define NDPR_ADDREF(_ndpr)                                              \
619*43a90889SApple OSS Distributions 	ndpr_addref(_ndpr)
620*43a90889SApple OSS Distributions 
621*43a90889SApple OSS Distributions #define NDPR_REMREF(_ndpr)                                              \
622*43a90889SApple OSS Distributions 	ndpr_remref(_ndpr)                                              \
623*43a90889SApple OSS Distributions 
624*43a90889SApple OSS Distributions /*
625*43a90889SApple OSS Distributions  * Message format for use in obtaining information about prefixes
626*43a90889SApple OSS Distributions  * from inet6 sysctl function
627*43a90889SApple OSS Distributions  */
628*43a90889SApple OSS Distributions struct inet6_ndpr_msghdr {
629*43a90889SApple OSS Distributions 	u_short inpm_msglen;    /* to skip over non-understood messages */
630*43a90889SApple OSS Distributions 	u_char  inpm_version;   /* future binary compatibility */
631*43a90889SApple OSS Distributions 	u_char  inpm_type;      /* message type */
632*43a90889SApple OSS Distributions 	struct in6_addr inpm_prefix;
633*43a90889SApple OSS Distributions 	u_int32_t       prm_vltim;
634*43a90889SApple OSS Distributions 	u_int32_t       prm_pltime;
635*43a90889SApple OSS Distributions 	u_int32_t       prm_expire;
636*43a90889SApple OSS Distributions 	u_int32_t       prm_preferred;
637*43a90889SApple OSS Distributions 	struct in6_prflags prm_flags;
638*43a90889SApple OSS Distributions 	u_short prm_index;      /* index for associated ifp */
639*43a90889SApple OSS Distributions 	u_char  prm_plen;       /* length of prefix in bits */
640*43a90889SApple OSS Distributions };
641*43a90889SApple OSS Distributions 
642*43a90889SApple OSS Distributions #define prm_raf_onlink          prm_flags.prf_ra.onlink
643*43a90889SApple OSS Distributions #define prm_raf_auto            prm_flags.prf_ra.autonomous
644*43a90889SApple OSS Distributions 
645*43a90889SApple OSS Distributions #define prm_statef_onlink       prm_flags.prf_state.onlink
646*43a90889SApple OSS Distributions 
647*43a90889SApple OSS Distributions #define prm_rrf_decrvalid       prm_flags.prf_rr.decrvalid
648*43a90889SApple OSS Distributions #define prm_rrf_decrprefd       prm_flags.prf_rr.decrprefd
649*43a90889SApple OSS Distributions 
650*43a90889SApple OSS Distributions struct nd_pfxrouter {
651*43a90889SApple OSS Distributions 	LIST_ENTRY(nd_pfxrouter) pfr_entry;
652*43a90889SApple OSS Distributions #define pfr_next pfr_entry.le_next
653*43a90889SApple OSS Distributions 	struct nd_defrouter *router;
654*43a90889SApple OSS Distributions };
655*43a90889SApple OSS Distributions 
656*43a90889SApple OSS Distributions LIST_HEAD(nd_prhead, nd_prefix);
657*43a90889SApple OSS Distributions 
658*43a90889SApple OSS Distributions struct nd_prefix_list {
659*43a90889SApple OSS Distributions 	struct nd_prefix_list *next;
660*43a90889SApple OSS Distributions 	struct nd_prefix pr;
661*43a90889SApple OSS Distributions };
662*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
663*43a90889SApple OSS Distributions 
664*43a90889SApple OSS Distributions #if defined(PRIVATE)
665*43a90889SApple OSS Distributions struct kev_nd6_ndfailure {
666*43a90889SApple OSS Distributions 	struct net_event_data link_data;
667*43a90889SApple OSS Distributions };
668*43a90889SApple OSS Distributions 
669*43a90889SApple OSS Distributions struct kev_nd6_ndalive {
670*43a90889SApple OSS Distributions 	struct net_event_data link_data;
671*43a90889SApple OSS Distributions };
672*43a90889SApple OSS Distributions 
673*43a90889SApple OSS Distributions struct nd6_ra_prefix {
674*43a90889SApple OSS Distributions 	struct sockaddr_in6 prefix;
675*43a90889SApple OSS Distributions 	struct prf_ra raflags;
676*43a90889SApple OSS Distributions 	u_int32_t prefixlen;
677*43a90889SApple OSS Distributions 	u_int32_t origin;
678*43a90889SApple OSS Distributions 	u_int64_t vltime;
679*43a90889SApple OSS Distributions 	u_int64_t pltime;
680*43a90889SApple OSS Distributions 	u_int64_t expire;
681*43a90889SApple OSS Distributions 	u_int32_t flags;
682*43a90889SApple OSS Distributions 	u_int32_t refcnt;
683*43a90889SApple OSS Distributions 	u_int32_t if_index;
684*43a90889SApple OSS Distributions 	u_int32_t pad;
685*43a90889SApple OSS Distributions };
686*43a90889SApple OSS Distributions 
687*43a90889SApple OSS Distributions /* ND6 router advertisement valid bits */
688*43a90889SApple OSS Distributions #define KEV_ND6_DATA_VALID_MTU          (0x1 << 0)
689*43a90889SApple OSS Distributions #define KEV_ND6_DATA_VALID_PREFIX       (0x1 << 1)
690*43a90889SApple OSS Distributions 
691*43a90889SApple OSS Distributions struct kev_nd6_ra_data {
692*43a90889SApple OSS Distributions 	u_int32_t mtu;
693*43a90889SApple OSS Distributions 	u_int32_t list_index;
694*43a90889SApple OSS Distributions 	u_int32_t list_length;
695*43a90889SApple OSS Distributions 	u_int32_t flags;
696*43a90889SApple OSS Distributions 	struct nd6_ra_prefix prefix;
697*43a90889SApple OSS Distributions 	u_int32_t pad;
698*43a90889SApple OSS Distributions };
699*43a90889SApple OSS Distributions 
700*43a90889SApple OSS Distributions struct kev_nd6_event {
701*43a90889SApple OSS Distributions 	struct net_event_data link_data;
702*43a90889SApple OSS Distributions 	struct in6_addr in6_address;
703*43a90889SApple OSS Distributions 	uint32_t val;
704*43a90889SApple OSS Distributions };
705*43a90889SApple OSS Distributions 
706*43a90889SApple OSS Distributions struct nd6_lookup_ipv6_args {
707*43a90889SApple OSS Distributions 	char ifname[IFNAMSIZ];
708*43a90889SApple OSS Distributions 	struct sockaddr_in6 ip6_dest;
709*43a90889SApple OSS Distributions 	u_int32_t ll_dest_len;
710*43a90889SApple OSS Distributions 	union {
711*43a90889SApple OSS Distributions 		char buffer[256];
712*43a90889SApple OSS Distributions 		struct sockaddr_dl _sdl;
713*43a90889SApple OSS Distributions 	} ll_dest_;
714*43a90889SApple OSS Distributions };
715*43a90889SApple OSS Distributions #define ll_dest_sdl ll_dest_._sdl
716*43a90889SApple OSS Distributions 
717*43a90889SApple OSS Distributions #endif /* PRIVATE */
718*43a90889SApple OSS Distributions 
719*43a90889SApple OSS Distributions #if defined(BSD_KERNEL_PRIVATE)
720*43a90889SApple OSS Distributions /* nd6.c */
721*43a90889SApple OSS Distributions extern int nd6_prune;
722*43a90889SApple OSS Distributions extern int nd6_prune_lazy;
723*43a90889SApple OSS Distributions extern int nd6_delay;
724*43a90889SApple OSS Distributions extern int nd6_umaxtries;
725*43a90889SApple OSS Distributions extern int nd6_mmaxtries;
726*43a90889SApple OSS Distributions extern int nd6_useloopback;
727*43a90889SApple OSS Distributions extern int nd6_accept_6to4;
728*43a90889SApple OSS Distributions extern int nd6_maxnudhint;
729*43a90889SApple OSS Distributions extern int nd6_gctimer;
730*43a90889SApple OSS Distributions extern struct llinfo_nd6 llinfo_nd6;
731*43a90889SApple OSS Distributions extern struct nd_drhead nd_defrouter_list;
732*43a90889SApple OSS Distributions extern struct nd_rtihead nd_rti_list;
733*43a90889SApple OSS Distributions extern struct nd_prhead nd_prefix;
734*43a90889SApple OSS Distributions extern int nd6_debug;
735*43a90889SApple OSS Distributions extern int nd6_onlink_ns_rfc4861;
736*43a90889SApple OSS Distributions extern int nd6_optimistic_dad;
737*43a90889SApple OSS Distributions 
738*43a90889SApple OSS Distributions #include <os/log.h>
739*43a90889SApple OSS Distributions 
740*43a90889SApple OSS Distributions #define nd6log0(type, ...)      do { os_log_##type(OS_LOG_DEFAULT, ##__VA_ARGS__); } while (0)
741*43a90889SApple OSS Distributions #define nd6log(type, ...)       do { if (nd6_debug >= 1) os_log_##type(OS_LOG_DEFAULT, ##__VA_ARGS__); } while (0)
742*43a90889SApple OSS Distributions #define nd6log2(type, ...)      do { if (nd6_debug >= 2) os_log_##type(OS_LOG_DEFAULT, ##__VA_ARGS__); } while (0)
743*43a90889SApple OSS Distributions #define nd6log3(type, ...)      do { if (nd6_debug >= 3) os_log_##type(OS_LOG_DEFAULT, ##__VA_ARGS__); } while (0)
744*43a90889SApple OSS Distributions 
745*43a90889SApple OSS Distributions #define ND6_OPTIMISTIC_DAD_LINKLOCAL    (1 << 0)
746*43a90889SApple OSS Distributions #define ND6_OPTIMISTIC_DAD_AUTOCONF     (1 << 1)
747*43a90889SApple OSS Distributions #define ND6_OPTIMISTIC_DAD_TEMPORARY    (1 << 2)
748*43a90889SApple OSS Distributions #define ND6_OPTIMISTIC_DAD_DYNAMIC      (1 << 3)
749*43a90889SApple OSS Distributions #define ND6_OPTIMISTIC_DAD_SECURED      (1 << 4)
750*43a90889SApple OSS Distributions #define ND6_OPTIMISTIC_DAD_MANUAL       (1 << 5)
751*43a90889SApple OSS Distributions 
752*43a90889SApple OSS Distributions #define ND6_OPTIMISTIC_DAD_DEFAULT                                  \
753*43a90889SApple OSS Distributions 	(ND6_OPTIMISTIC_DAD_LINKLOCAL | ND6_OPTIMISTIC_DAD_AUTOCONF |   \
754*43a90889SApple OSS Distributions 	 ND6_OPTIMISTIC_DAD_TEMPORARY | ND6_OPTIMISTIC_DAD_DYNAMIC |    \
755*43a90889SApple OSS Distributions 	 ND6_OPTIMISTIC_DAD_SECURED | ND6_OPTIMISTIC_DAD_MANUAL)
756*43a90889SApple OSS Distributions 
757*43a90889SApple OSS Distributions /* nd6_rtr.c */
758*43a90889SApple OSS Distributions extern int nd6_defifindex;
759*43a90889SApple OSS Distributions extern int ip6_desync_factor;   /* seconds */
760*43a90889SApple OSS Distributions /* ND6_INFINITE_LIFETIME does not apply to temporary addresses */
761*43a90889SApple OSS Distributions extern u_int32_t ip6_temp_preferred_lifetime; /* seconds */
762*43a90889SApple OSS Distributions extern u_int32_t ip6_temp_valid_lifetime; /* seconds */
763*43a90889SApple OSS Distributions extern int ip6_temp_regen_advance; /* seconds */
764*43a90889SApple OSS Distributions 
765*43a90889SApple OSS Distributions union nd_opts {
766*43a90889SApple OSS Distributions 	struct nd_opt_hdr *nd_opt_array[26];    /* max = Route information option */
767*43a90889SApple OSS Distributions 	struct {
768*43a90889SApple OSS Distributions 		struct nd_opt_hdr *zero;
769*43a90889SApple OSS Distributions 		struct nd_opt_hdr *src_lladdr;
770*43a90889SApple OSS Distributions 		struct nd_opt_hdr *tgt_lladdr;
771*43a90889SApple OSS Distributions 		struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */
772*43a90889SApple OSS Distributions 		struct nd_opt_rd_hdr *rh;
773*43a90889SApple OSS Distributions 		struct nd_opt_mtu *mtu;
774*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res6;
775*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res7;
776*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res8;
777*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res9;
778*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res10;
779*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res11;
780*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res12;
781*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res13;
782*43a90889SApple OSS Distributions 		struct nd_opt_nonce *nonce;
783*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res15;
784*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res16;
785*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res17;
786*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res18;
787*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res19;
788*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res20;
789*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res21;
790*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res22;
791*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res23;
792*43a90889SApple OSS Distributions 		struct nd_opt_route_info *rti_beg;
793*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__res25;
794*43a90889SApple OSS Distributions 		struct nd_opt_hdr *__ended_by(last) search; /* multiple opts */
795*43a90889SApple OSS Distributions 		struct nd_opt_hdr *last;                    /* multiple opts */
796*43a90889SApple OSS Distributions 		uint8_t done;
797*43a90889SApple OSS Distributions 		uint8_t initialized;
798*43a90889SApple OSS Distributions 		struct nd_opt_prefix_info *pi_end; /* multiple prefix opts, end */
799*43a90889SApple OSS Distributions 		struct nd_opt_route_info *rti_end; /* multiple route info opts, end */
800*43a90889SApple OSS Distributions 	} nd_opt_each;
801*43a90889SApple OSS Distributions };
802*43a90889SApple OSS Distributions #define nd_opts_src_lladdr      nd_opt_each.src_lladdr
803*43a90889SApple OSS Distributions #define nd_opts_tgt_lladdr      nd_opt_each.tgt_lladdr
804*43a90889SApple OSS Distributions #define nd_opts_pi              nd_opt_each.pi_beg
805*43a90889SApple OSS Distributions #define nd_opts_pi_end          nd_opt_each.pi_end
806*43a90889SApple OSS Distributions #define nd_opts_rh              nd_opt_each.rh
807*43a90889SApple OSS Distributions #define nd_opts_mtu             nd_opt_each.mtu
808*43a90889SApple OSS Distributions #define nd_opts_nonce           nd_opt_each.nonce
809*43a90889SApple OSS Distributions #define nd_opts_rti             nd_opt_each.rti_beg
810*43a90889SApple OSS Distributions #define nd_opts_rti_end         nd_opt_each.rti_end
811*43a90889SApple OSS Distributions #define nd_opts_search          nd_opt_each.search
812*43a90889SApple OSS Distributions #define nd_opts_last            nd_opt_each.last
813*43a90889SApple OSS Distributions #define nd_opts_done            nd_opt_each.done
814*43a90889SApple OSS Distributions #define nd_opts_initialized     nd_opt_each.initialized
815*43a90889SApple OSS Distributions 
816*43a90889SApple OSS Distributions #define ND_OPT_LLADDR(opt, optlen, val, vallen) ({                                \
817*43a90889SApple OSS Distributions     (vallen) = opt->optlen << 3;                                                  \
818*43a90889SApple OSS Distributions     struct nd_opt_hdr* __hdr = __unsafe_forge_bidi_indexable(struct nd_opt_hdr *, \
819*43a90889SApple OSS Distributions     (opt), sizeof(struct nd_opt_hdr) + (vallen));                                 \
820*43a90889SApple OSS Distributions     (val) = (char *)(__hdr + 1);                                                  \
821*43a90889SApple OSS Distributions })
822*43a90889SApple OSS Distributions 
823*43a90889SApple OSS Distributions #if __has_ptrcheck
824*43a90889SApple OSS Distributions #define TAKE_ND_NEXT_OPT(opt, start, end) ({                                                          \
825*43a90889SApple OSS Distributions     size_t __ndoptlen = (u_char*)ndopts.end - (u_char*)ndopts.start;                                  \
826*43a90889SApple OSS Distributions     struct nd_opt_hdr* __hdr = __unsafe_forge_bidi_indexable(struct nd_opt_hdr *, (opt), __ndoptlen); \
827*43a90889SApple OSS Distributions     __hdr;                                                                                            \
828*43a90889SApple OSS Distributions })
829*43a90889SApple OSS Distributions #else
830*43a90889SApple OSS Distributions #define TAKE_ND_NEXT_OPT(opt, start, end) ({                                                          \
831*43a90889SApple OSS Distributions      (struct nd_opt_hdr *)opt;                                                                        \
832*43a90889SApple OSS Distributions })
833*43a90889SApple OSS Distributions #endif
834*43a90889SApple OSS Distributions 
835*43a90889SApple OSS Distributions /* XXX: need nd6_var.h?? */
836*43a90889SApple OSS Distributions /* nd6.c */
837*43a90889SApple OSS Distributions extern int nd6_sched_timeout_want;
838*43a90889SApple OSS Distributions extern void nd6_sched_timeout(struct timeval *, struct timeval *);
839*43a90889SApple OSS Distributions extern void nd6_init(void);
840*43a90889SApple OSS Distributions extern void nd6_ifreset(struct ifnet *ifp);
841*43a90889SApple OSS Distributions extern void nd6_ifattach(struct ifnet *);
842*43a90889SApple OSS Distributions extern int nd6_is_addr_neighbor(struct sockaddr_in6 *, struct ifnet *, int);
843*43a90889SApple OSS Distributions extern void nd6_option_init(void *__sized_by(icmp6len), size_t icmp6len, union nd_opts *);
844*43a90889SApple OSS Distributions extern struct nd_opt_hdr *nd6_option(union nd_opts *);
845*43a90889SApple OSS Distributions extern int nd6_options(union nd_opts *);
846*43a90889SApple OSS Distributions extern struct rtentry *nd6_lookup(struct in6_addr *, int, struct ifnet *, int);
847*43a90889SApple OSS Distributions extern void nd6_setmtu(struct ifnet *);
848*43a90889SApple OSS Distributions extern void nd6_purge(struct ifnet *);
849*43a90889SApple OSS Distributions extern void nd6_free(struct rtentry *);
850*43a90889SApple OSS Distributions extern void nd6_nud_hint(struct rtentry *, struct in6_addr *, int);
851*43a90889SApple OSS Distributions extern int nd6_resolve(struct ifnet *, struct rtentry *,
852*43a90889SApple OSS Distributions     struct mbuf *, struct sockaddr *, u_char *);
853*43a90889SApple OSS Distributions extern void nd6_rtrequest(int, struct rtentry *, struct sockaddr *);
854*43a90889SApple OSS Distributions extern int nd6_ioctl(u_long cmd, caddr_t __counted_by(IOCPARM_LEN(cmd)), struct ifnet *);
855*43a90889SApple OSS Distributions extern void nd6_cache_lladdr(struct ifnet *, struct in6_addr *,
856*43a90889SApple OSS Distributions     char *lladdr __sized_by(lladdrlen), int lladdrlen,
857*43a90889SApple OSS Distributions     int, int, int *);
858*43a90889SApple OSS Distributions extern int nd6_output_list(struct ifnet *, struct ifnet *, struct mbuf *,
859*43a90889SApple OSS Distributions     struct sockaddr_in6 *, struct rtentry *, struct flowadv *);
860*43a90889SApple OSS Distributions extern int nd6_output(struct ifnet *, struct ifnet *, struct mbuf *,
861*43a90889SApple OSS Distributions     struct sockaddr_in6 *, struct rtentry *, struct flowadv *);
862*43a90889SApple OSS Distributions extern int nd6_need_cache(struct ifnet *);
863*43a90889SApple OSS Distributions extern void nd6_drain(void *);
864*43a90889SApple OSS Distributions extern void nd6_post_msg(u_int32_t, struct nd_prefix_list *, u_int32_t,
865*43a90889SApple OSS Distributions     u_int32_t);
866*43a90889SApple OSS Distributions extern int nd6_setifinfo(struct ifnet *, u_int32_t, u_int32_t);
867*43a90889SApple OSS Distributions extern const char *ndcache_state2str(short);
868*43a90889SApple OSS Distributions extern void ln_setexpire(struct llinfo_nd6 *, uint64_t);
869*43a90889SApple OSS Distributions 
870*43a90889SApple OSS Distributions /* nd6_nbr.c */
871*43a90889SApple OSS Distributions extern void nd6_nbr_init(void);
872*43a90889SApple OSS Distributions extern void nd6_na_input(struct mbuf *, int, int);
873*43a90889SApple OSS Distributions extern void nd6_na_output(struct ifnet *, const struct in6_addr *,
874*43a90889SApple OSS Distributions     const struct in6_addr *, u_int32_t, int, struct sockaddr *);
875*43a90889SApple OSS Distributions extern void nd6_ns_input(struct mbuf *, int, int);
876*43a90889SApple OSS Distributions extern void nd6_ns_output(struct ifnet *, const struct in6_addr *,
877*43a90889SApple OSS Distributions     const struct in6_addr *, struct llinfo_nd6 *,
878*43a90889SApple OSS Distributions     uint8_t *__counted_by(noncelen) nonce, size_t noncelen);
879*43a90889SApple OSS Distributions 
880*43a90889SApple OSS Distributions static inline caddr_t __header_indexable __stateful_pure
nd6_ifptomac(struct ifnet * ifp)881*43a90889SApple OSS Distributions nd6_ifptomac(struct ifnet *ifp)
882*43a90889SApple OSS Distributions {
883*43a90889SApple OSS Distributions 	switch (ifp->if_type) {
884*43a90889SApple OSS Distributions 	case IFT_ARCNET:
885*43a90889SApple OSS Distributions 	case IFT_ETHER:
886*43a90889SApple OSS Distributions 	case IFT_IEEE8023ADLAG:
887*43a90889SApple OSS Distributions 	case IFT_FDDI:
888*43a90889SApple OSS Distributions 	case IFT_IEEE1394:
889*43a90889SApple OSS Distributions #ifdef IFT_L2VLAN
890*43a90889SApple OSS Distributions 	case IFT_L2VLAN:
891*43a90889SApple OSS Distributions #endif
892*43a90889SApple OSS Distributions #ifdef IFT_IEEE80211
893*43a90889SApple OSS Distributions 	case IFT_IEEE80211:
894*43a90889SApple OSS Distributions #endif
895*43a90889SApple OSS Distributions #ifdef IFT_CARP
896*43a90889SApple OSS Distributions 	case IFT_CARP:
897*43a90889SApple OSS Distributions #endif
898*43a90889SApple OSS Distributions 	case IFT_BRIDGE:
899*43a90889SApple OSS Distributions 	case IFT_ISO88025:
900*43a90889SApple OSS Distributions 		return (caddr_t)IF_LLADDR(ifp);
901*43a90889SApple OSS Distributions 	default:
902*43a90889SApple OSS Distributions 		return NULL;
903*43a90889SApple OSS Distributions 	}
904*43a90889SApple OSS Distributions }
905*43a90889SApple OSS Distributions 
906*43a90889SApple OSS Distributions extern void nd6_dad_start(struct ifaddr *, int *);
907*43a90889SApple OSS Distributions extern void nd6_dad_stop(struct ifaddr *);
908*43a90889SApple OSS Distributions extern void nd6_llreach_alloc(struct rtentry *, struct ifnet *,
909*43a90889SApple OSS Distributions     void * __sized_by(alen), unsigned int alen, boolean_t);
910*43a90889SApple OSS Distributions extern void nd6_llreach_set_reachable(struct ifnet *, void *__sized_by(alen) addr, unsigned int alen);
911*43a90889SApple OSS Distributions extern void nd6_llreach_use(struct llinfo_nd6 *);
912*43a90889SApple OSS Distributions extern void nd6_alt_node_addr_decompose(struct ifnet *, struct sockaddr *,
913*43a90889SApple OSS Distributions     struct sockaddr_dl *, struct sockaddr_in6 *);
914*43a90889SApple OSS Distributions extern int nd6_alt_node_present(struct ifnet *, struct sockaddr_in6 *,
915*43a90889SApple OSS Distributions     struct sockaddr_dl *, int32_t, int, int);
916*43a90889SApple OSS Distributions extern int nd6_alt_node_absent(struct ifnet *, struct sockaddr_in6 *, struct sockaddr_dl *);
917*43a90889SApple OSS Distributions 
918*43a90889SApple OSS Distributions /* nd6_rtr.c */
919*43a90889SApple OSS Distributions extern struct in6_ifaddr *in6_pfx_newpersistaddr(struct nd_prefix *, int,
920*43a90889SApple OSS Distributions     int *, boolean_t, uint8_t);
921*43a90889SApple OSS Distributions extern void nd6_rtr_init(void);
922*43a90889SApple OSS Distributions extern void nd6_rs_input(struct mbuf *, int, int);
923*43a90889SApple OSS Distributions extern void nd6_ra_input(struct mbuf *, int, int);
924*43a90889SApple OSS Distributions extern void prelist_del(struct nd_prefix *);
925*43a90889SApple OSS Distributions extern struct nd_defrouter *defrtrlist_update(struct nd_defrouter *,
926*43a90889SApple OSS Distributions     struct nd_drhead *);
927*43a90889SApple OSS Distributions extern void defrouter_select(struct ifnet *, struct nd_drhead *);
928*43a90889SApple OSS Distributions extern void defrouter_reset(void);
929*43a90889SApple OSS Distributions extern int defrtrlist_ioctl(u_long cmd, caddr_t __sized_by(IOCPARM_LEN(cmd)));
930*43a90889SApple OSS Distributions extern void defrtrlist_del(struct nd_defrouter *, struct nd_drhead *);
931*43a90889SApple OSS Distributions extern int defrtrlist_add_static(struct nd_defrouter *);
932*43a90889SApple OSS Distributions extern int defrtrlist_del_static(struct nd_defrouter *);
933*43a90889SApple OSS Distributions extern void prelist_remove(struct nd_prefix *);
934*43a90889SApple OSS Distributions extern int prelist_update(struct nd_prefix *, struct nd_defrouter *,
935*43a90889SApple OSS Distributions     struct mbuf *, int);
936*43a90889SApple OSS Distributions extern int nd6_prelist_add(struct nd_prefix *, struct nd_defrouter *,
937*43a90889SApple OSS Distributions     struct nd_prefix **, boolean_t);
938*43a90889SApple OSS Distributions extern int nd6_prefix_onlink(struct nd_prefix *);
939*43a90889SApple OSS Distributions extern int nd6_prefix_onlink_scoped(struct nd_prefix *, unsigned int);
940*43a90889SApple OSS Distributions extern int nd6_prefix_offlink(struct nd_prefix *);
941*43a90889SApple OSS Distributions extern void pfxlist_onlink_check(void);
942*43a90889SApple OSS Distributions extern void defrouter_set_reachability(struct in6_addr *, struct ifnet *, boolean_t);
943*43a90889SApple OSS Distributions extern struct nd_defrouter *defrouter_lookup(struct nd_drhead *,
944*43a90889SApple OSS Distributions     struct in6_addr *, struct ifnet *);
945*43a90889SApple OSS Distributions extern struct nd_pfxrouter *pfxrtr_lookup(struct nd_prefix *, struct nd_defrouter *);
946*43a90889SApple OSS Distributions extern struct nd_prefix *nd6_prefix_lookup(struct nd_prefix *, int);
947*43a90889SApple OSS Distributions extern int in6_init_prefix_ltimes(struct nd_prefix *ndpr);
948*43a90889SApple OSS Distributions extern void rt6_flush(struct in6_addr *, struct ifnet *);
949*43a90889SApple OSS Distributions extern int nd6_setdefaultiface(int);
950*43a90889SApple OSS Distributions extern int in6_tmpifadd(const struct in6_ifaddr *, int);
951*43a90889SApple OSS Distributions extern void nddr_addref(struct nd_defrouter *);
952*43a90889SApple OSS Distributions extern struct nd_defrouter *nddr_remref(struct nd_defrouter *);
953*43a90889SApple OSS Distributions extern uint64_t nddr_getexpire(struct nd_defrouter *);
954*43a90889SApple OSS Distributions extern void ndpr_addref(struct nd_prefix *);
955*43a90889SApple OSS Distributions extern struct nd_prefix *ndpr_remref(struct nd_prefix *);
956*43a90889SApple OSS Distributions extern uint64_t ndpr_getexpire(struct nd_prefix *);
957*43a90889SApple OSS Distributions extern void defrouter_delreq(struct nd_defrouter *, struct nd_route_info *);
958*43a90889SApple OSS Distributions 
959*43a90889SApple OSS Distributions /* nd6_prproxy.c */
960*43a90889SApple OSS Distributions struct ip6_hdr;
961*43a90889SApple OSS Distributions extern u_int32_t nd6_prproxy;
962*43a90889SApple OSS Distributions extern int nd6_if_prproxy(struct ifnet *, boolean_t);
963*43a90889SApple OSS Distributions extern void nd6_prproxy_prelist_update(struct nd_prefix *, struct nd_prefix *);
964*43a90889SApple OSS Distributions extern boolean_t nd6_prproxy_ifaddr(struct in6_ifaddr *);
965*43a90889SApple OSS Distributions extern void nd6_proxy_find_fwdroute(struct ifnet *, struct route_in6 *);
966*43a90889SApple OSS Distributions extern boolean_t nd6_prproxy_isours(struct mbuf *, struct ip6_hdr *,
967*43a90889SApple OSS Distributions     struct route_in6 *, unsigned int);
968*43a90889SApple OSS Distributions extern void nd6_prproxy_ns_output(struct ifnet *, struct ifnet *,
969*43a90889SApple OSS Distributions     struct in6_addr *, struct in6_addr *, struct llinfo_nd6 *);
970*43a90889SApple OSS Distributions extern void nd6_prproxy_ns_input(struct ifnet *, struct in6_addr *,
971*43a90889SApple OSS Distributions     char *__sized_by(lladdrlen) lladdr, int lladdrlen, struct in6_addr *,
972*43a90889SApple OSS Distributions     struct in6_addr *, uint8_t *__counted_by(noncelen) nonce, size_t noncelen);
973*43a90889SApple OSS Distributions extern void nd6_prproxy_na_input(struct ifnet *, struct in6_addr *,
974*43a90889SApple OSS Distributions     struct in6_addr *, struct in6_addr *, int);
975*43a90889SApple OSS Distributions extern void nd6_prproxy_sols_reap(struct nd_prefix *);
976*43a90889SApple OSS Distributions extern void nd6_prproxy_sols_prune(struct nd_prefix *, u_int32_t);
977*43a90889SApple OSS Distributions extern int nd6_if_disable(struct ifnet *, boolean_t);
978*43a90889SApple OSS Distributions void in6_ifaddr_set_dadprogress(struct in6_ifaddr *ia);
979*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
980*43a90889SApple OSS Distributions 
981*43a90889SApple OSS Distributions #ifdef KERNEL
982*43a90889SApple OSS Distributions 
983*43a90889SApple OSS Distributions /*
984*43a90889SApple OSS Distributions  *	@function nd6_lookup_ipv6
985*43a90889SApple OSS Distributions  *	@discussion This function will check the routing table for a cached
986*43a90889SApple OSS Distributions  *		neighbor discovery entry or trigger an neighbor discovery query
987*43a90889SApple OSS Distributions  *		to resolve the IPv6 address to a link-layer address.
988*43a90889SApple OSS Distributions  *		nd entries are stored in the routing table. This function will
989*43a90889SApple OSS Distributions  *		lookup the IPv6 destination in the routing table. If the
990*43a90889SApple OSS Distributions  *		destination requires forwarding to a gateway, the route of the
991*43a90889SApple OSS Distributions  *		gateway will be looked up. The route entry is inspected to
992*43a90889SApple OSS Distributions  *		determine if the link layer destination address is known. If
993*43a90889SApple OSS Distributions  *		unknown, neighbor discovery will be used to resolve the entry.
994*43a90889SApple OSS Distributions  *	@param interface The interface the packet is being sent on.
995*43a90889SApple OSS Distributions  *	@param ip6_dest The IPv6 destination of the packet.
996*43a90889SApple OSS Distributions  *	@param ll_dest On output, the link-layer destination.
997*43a90889SApple OSS Distributions  *	@param ll_dest_len The length of the buffer for ll_dest.
998*43a90889SApple OSS Distributions  *	@param hint Any routing hint passed down from the protocol.
999*43a90889SApple OSS Distributions  *	@param packet The packet being transmitted.
1000*43a90889SApple OSS Distributions  *	@result May return an error such as EHOSTDOWN or ENETUNREACH. If
1001*43a90889SApple OSS Distributions  *		this function returns EJUSTRETURN, the packet has been queued
1002*43a90889SApple OSS Distributions  *		and will be sent when the address is resolved. If any other
1003*43a90889SApple OSS Distributions  *		value is returned, the caller is responsible for disposing of
1004*43a90889SApple OSS Distributions  *		the packet.
1005*43a90889SApple OSS Distributions  */
1006*43a90889SApple OSS Distributions extern errno_t nd6_lookup_ipv6(ifnet_t interface,
1007*43a90889SApple OSS Distributions     const struct sockaddr_in6 *ip6_dest, struct sockaddr_dl *ll_dest,
1008*43a90889SApple OSS Distributions     size_t ll_dest_len, route_t hint, mbuf_t packet);
1009*43a90889SApple OSS Distributions 
1010*43a90889SApple OSS Distributions #endif /* KERNEL */
1011*43a90889SApple OSS Distributions 
1012*43a90889SApple OSS Distributions /* nd6_send.c */
1013*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
1014*43a90889SApple OSS Distributions /*
1015*43a90889SApple OSS Distributions  * nd6_send_opmode
1016*43a90889SApple OSS Distributions  *
1017*43a90889SApple OSS Distributions  *      value	using CGA	tx SEND		rx SEND
1018*43a90889SApple OSS Distributions  *   --------	---------	-------		-------
1019*43a90889SApple OSS Distributions  *   DISABLED	       NO	     NO		     NO
1020*43a90889SApple OSS Distributions  *      QUIET	      YES	     NO		     NO
1021*43a90889SApple OSS Distributions  */
1022*43a90889SApple OSS Distributions extern int nd6_send_opstate;
1023*43a90889SApple OSS Distributions 
1024*43a90889SApple OSS Distributions #define ND6_SEND_OPMODE_DISABLED        0
1025*43a90889SApple OSS Distributions #define ND6_SEND_OPMODE_CGA_QUIET       1
1026*43a90889SApple OSS Distributions 
1027*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
1028*43a90889SApple OSS Distributions #endif /* _NETINET6_ND6_H_ */
1029