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