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