xref: /xnu-10063.121.3/bsd/netinet6/nd6.h (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
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 SHA256 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 	boolean_t       is_reachable;
562 	void (*nddr_trace)(struct nd_defrouter *, int); /* trace callback fn */
563 };
564 
565 #define NDDR_LOCK_ASSERT_HELD(_nddr)                                    \
566 	LCK_MTX_ASSERT(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_OWNED)
567 
568 #define NDDR_LOCK_ASSERT_NOTHELD(_nddr)                                 \
569 	LCK_MTX_ASSERT(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_NOTOWNED)
570 
571 #define NDDR_LOCK(_nddr)                                                \
572 	lck_mtx_lock(&(_nddr)->nddr_lock)
573 
574 #define NDDR_LOCK_SPIN(_nddr)                                           \
575 	lck_mtx_lock_spin(&(_nddr)->nddr_lock)
576 
577 #define NDDR_CONVERT_LOCK(_nddr) do {                                   \
578 	NDPR_LOCK_ASSERT_HELD(_nddr);                                   \
579 	lck_mtx_convert_spin(&(_nddr)->nddr_lock);                      \
580 } while (0)
581 
582 #define NDDR_UNLOCK(_nddr)                                              \
583 	lck_mtx_unlock(&(_nddr)->nddr_lock)
584 
585 #define NDDR_REF_LOCK(_nddr)                                            \
586 	lck_mtx_lock(&(_nddr)->nddr_ref_lock)
587 
588 #define NDDR_REF_LOCK_SPIN(_nddr)                                       \
589 	lck_mtx_lock_spin(&(_nddr)->nddr_ref_lock)
590 
591 #define NDDR_REF_UNLOCK(_nddr)                                          \
592 	lck_mtx_unlock(&(_nddr)->nddr_ref_lock)
593 
594 #define NDDR_ADDREF(_nddr)                                              \
595 	nddr_addref(_nddr)
596 
597 #define NDDR_REMREF(_nddr)                                              \
598 	nddr_remref(_nddr)                                              \
599 
600 TAILQ_HEAD(nd_rtihead, nd_route_info);
601 /*
602  * The ordering below is important and it should always start
603  * with nd_drhead as the first element.
604  * It gets passed in as the generic nd_drhead to router management code.
605  * The extra information stored here includes the prefix/prefix-length
606  * which the router list belongs to.
607  */
608 struct nd_route_info {
609 	struct nd_drhead nd_rti_router_list;
610 	TAILQ_ENTRY(nd_route_info) nd_rti_entry;
611 	struct in6_addr nd_rti_prefix;
612 	u_int8_t nd_rti_prefixlen;
613 };
614 
615 struct nd_route_info *ndrti_alloc(void);
616 void nd6_rti_list_wait(const char *);
617 void nd6_rti_list_signal_done(void);
618 void ndrti_free(struct nd_route_info *rti);
619 void nd6_rtilist_remove(struct nd_route_info *);
620 void nd6_rtilist_update(struct nd_route_info *, struct nd_defrouter *);
621 int nd6_rtilist_add(struct nd_route_info *, struct nd_defrouter *,
622     struct nd_route_info **);
623 void nd6_rti_purge(struct nd_route_info *);
624 
625 /* define struct prproxy_sols_tree */
626 RB_HEAD(prproxy_sols_tree, nd6_prproxy_soltgt);
627 
628 struct nd_prefix {
629 	decl_lck_mtx_data(, ndpr_lock);
630 	decl_lck_mtx_data(, ndpr_ref_lock);
631 	u_int32_t       ndpr_refcount;  /* reference count */
632 	u_int32_t       ndpr_debug;     /* see ifa_debug flags */
633 	struct ifnet     *ndpr_ifp;
634 	struct rtentry   *ndpr_rt;
635 	LIST_ENTRY(nd_prefix) ndpr_entry;
636 	struct sockaddr_in6 ndpr_prefix; /* prefix */
637 	struct in6_addr ndpr_mask; /* netmask derived from the prefix */
638 	struct in6_addr ndpr_addr; /* address that is derived from the prefix */
639 	u_int32_t       ndpr_vltime;    /* advertised valid lifetime */
640 	u_int32_t       ndpr_pltime;    /* advertised preferred lifetime */
641 	u_int64_t       ndpr_preferred; /* preferred time of the prefix */
642 	u_int64_t       ndpr_expire;    /* expiration time of the prefix */
643 	u_int64_t       ndpr_lastupdate; /* rx time of last advertisement */
644 	u_int64_t       ndpr_base_calendartime; /* calendar time at creation */
645 	u_int64_t       ndpr_base_uptime;       /* uptime at creation */
646 	struct prf_ra   ndpr_flags;
647 	unsigned int    ndpr_genid;     /* protects ndpr_advrtrs */
648 	u_int32_t       ndpr_stateflags; /* actual state flags */
649 	/* list of routers that advertise the prefix: */
650 	LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs;
651 	u_char          ndpr_plen;
652 	int             ndpr_addrcnt;   /* reference counter from addresses */
653 	int             ndpr_manual_addrcnt; /* reference counter non-autoconf addresses */
654 	u_int32_t       ndpr_allmulti_cnt;      /* total all-multi reqs */
655 	u_int32_t       ndpr_prproxy_sols_cnt;  /* total # of proxied NS */
656 	struct prproxy_sols_tree ndpr_prproxy_sols; /* tree of proxied NS */
657 	void (*ndpr_trace)(struct nd_prefix *, int); /* trace callback fn */
658 };
659 
660 #define ndpr_next               ndpr_entry.le_next
661 
662 #define ndpr_raf                ndpr_flags
663 #define ndpr_raf_onlink         ndpr_flags.onlink
664 #define ndpr_raf_auto           ndpr_flags.autonomous
665 #define ndpr_raf_router         ndpr_flags.router
666 /*
667  * We keep expired prefix for certain amount of time, for validation purposes.
668  * 1800s = MaxRtrAdvInterval
669  */
670 #define NDPR_KEEP_EXPIRED       (1800 * 2)
671 
672 #define NDPR_LOCK_ASSERT_HELD(_ndpr)                                    \
673 	LCK_MTX_ASSERT(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_OWNED)
674 
675 #define NDPR_LOCK_ASSERT_NOTHELD(_ndpr)                                 \
676 	LCK_MTX_ASSERT(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_NOTOWNED)
677 
678 #define NDPR_LOCK(_ndpr)                                                \
679 	lck_mtx_lock(&(_ndpr)->ndpr_lock)
680 
681 #define NDPR_LOCK_SPIN(_ndpr)                                           \
682 	lck_mtx_lock_spin(&(_ndpr)->ndpr_lock)
683 
684 #define NDPR_CONVERT_LOCK(_ndpr) do {                                   \
685 	NDPR_LOCK_ASSERT_HELD(_ndpr);                                   \
686 	lck_mtx_convert_spin(&(_ndpr)->ndpr_lock);                      \
687 } while (0)
688 
689 #define NDPR_UNLOCK(_ndpr)                                              \
690 	lck_mtx_unlock(&(_ndpr)->ndpr_lock)
691 
692 #define NDPR_REF_LOCK(_ndpr)                                            \
693 	lck_mtx_lock(&(_ndpr)->ndpr_ref_lock)
694 
695 #define NDPR_REF_LOCK_SPIN(_ndpr)                                       \
696 	lck_mtx_lock_spin(&(_ndpr)->ndpr_ref_lock)
697 
698 #define NDPR_REF_UNLOCK(_ndpr)                                          \
699 	lck_mtx_unlock(&(_ndpr)->ndpr_ref_lock)
700 
701 #define NDPR_ADDREF(_ndpr)                                              \
702 	ndpr_addref(_ndpr)
703 
704 #define NDPR_REMREF(_ndpr)                                              \
705 	ndpr_remref(_ndpr)                                              \
706 
707 /*
708  * Message format for use in obtaining information about prefixes
709  * from inet6 sysctl function
710  */
711 struct inet6_ndpr_msghdr {
712 	u_short inpm_msglen;    /* to skip over non-understood messages */
713 	u_char  inpm_version;   /* future binary compatibility */
714 	u_char  inpm_type;      /* message type */
715 	struct in6_addr inpm_prefix;
716 	u_int32_t       prm_vltim;
717 	u_int32_t       prm_pltime;
718 	u_int32_t       prm_expire;
719 	u_int32_t       prm_preferred;
720 	struct in6_prflags prm_flags;
721 	u_short prm_index;      /* index for associated ifp */
722 	u_char  prm_plen;       /* length of prefix in bits */
723 };
724 
725 #define prm_raf_onlink          prm_flags.prf_ra.onlink
726 #define prm_raf_auto            prm_flags.prf_ra.autonomous
727 
728 #define prm_statef_onlink       prm_flags.prf_state.onlink
729 
730 #define prm_rrf_decrvalid       prm_flags.prf_rr.decrvalid
731 #define prm_rrf_decrprefd       prm_flags.prf_rr.decrprefd
732 
733 struct nd_pfxrouter {
734 	LIST_ENTRY(nd_pfxrouter) pfr_entry;
735 #define pfr_next pfr_entry.le_next
736 	struct nd_defrouter *router;
737 };
738 
739 LIST_HEAD(nd_prhead, nd_prefix);
740 
741 struct nd_prefix_list {
742 	struct nd_prefix_list *next;
743 	struct nd_prefix pr;
744 };
745 #endif /* BSD_KERNEL_PRIVATE */
746 
747 #if defined(PRIVATE)
748 struct kev_nd6_ndfailure {
749 	struct net_event_data link_data;
750 };
751 
752 struct kev_nd6_ndalive {
753 	struct net_event_data link_data;
754 };
755 
756 struct nd6_ra_prefix {
757 	struct sockaddr_in6 prefix;
758 	struct prf_ra raflags;
759 	u_int32_t prefixlen;
760 	u_int32_t origin;
761 	u_int64_t vltime;
762 	u_int64_t pltime;
763 	u_int64_t expire;
764 	u_int32_t flags;
765 	u_int32_t refcnt;
766 	u_int32_t if_index;
767 	u_int32_t pad;
768 };
769 
770 /* ND6 router advertisement valid bits */
771 #define KEV_ND6_DATA_VALID_MTU          (0x1 << 0)
772 #define KEV_ND6_DATA_VALID_PREFIX       (0x1 << 1)
773 
774 struct kev_nd6_ra_data {
775 	u_int32_t mtu;
776 	u_int32_t list_index;
777 	u_int32_t list_length;
778 	u_int32_t flags;
779 	struct nd6_ra_prefix prefix;
780 	u_int32_t pad;
781 };
782 
783 struct kev_nd6_event {
784 	struct net_event_data link_data;
785 	struct in6_addr in6_address;
786 	uint32_t val;
787 };
788 
789 struct nd6_lookup_ipv6_args {
790 	char ifname[IFNAMSIZ];
791 	struct sockaddr_in6 ip6_dest;
792 	u_int32_t ll_dest_len;
793 	union {
794 		char buffer[256];
795 		struct sockaddr_dl _sdl;
796 	} ll_dest_;
797 };
798 #define ll_dest_sdl ll_dest_._sdl
799 
800 #endif /* PRIVATE */
801 
802 #if defined(BSD_KERNEL_PRIVATE)
803 /* nd6.c */
804 extern int nd6_prune;
805 extern int nd6_prune_lazy;
806 extern int nd6_delay;
807 extern int nd6_umaxtries;
808 extern int nd6_mmaxtries;
809 extern int nd6_useloopback;
810 extern int nd6_accept_6to4;
811 extern int nd6_maxnudhint;
812 extern int nd6_gctimer;
813 extern struct llinfo_nd6 llinfo_nd6;
814 extern struct nd_drhead nd_defrouter_list;
815 extern struct nd_rtihead nd_rti_list;
816 extern struct nd_prhead nd_prefix;
817 extern int nd6_debug;
818 extern int nd6_onlink_ns_rfc4861;
819 extern int nd6_optimistic_dad;
820 
821 #include <os/log.h>
822 
823 #define nd6log0(type, ...)      do { os_log_##type(OS_LOG_DEFAULT, __VA_ARGS__); } while (0)
824 #define nd6log(type, ...)       do { if (nd6_debug >= 1) os_log_##type(OS_LOG_DEFAULT, __VA_ARGS__); } while (0)
825 #define nd6log2(type, ...)      do { if (nd6_debug >= 2) os_log_##type(OS_LOG_DEFAULT, __VA_ARGS__); } while (0)
826 
827 #define ND6_OPTIMISTIC_DAD_LINKLOCAL    (1 << 0)
828 #define ND6_OPTIMISTIC_DAD_AUTOCONF     (1 << 1)
829 #define ND6_OPTIMISTIC_DAD_TEMPORARY    (1 << 2)
830 #define ND6_OPTIMISTIC_DAD_DYNAMIC      (1 << 3)
831 #define ND6_OPTIMISTIC_DAD_SECURED      (1 << 4)
832 #define ND6_OPTIMISTIC_DAD_MANUAL       (1 << 5)
833 
834 #define ND6_OPTIMISTIC_DAD_DEFAULT                                      \
835 	(ND6_OPTIMISTIC_DAD_LINKLOCAL | ND6_OPTIMISTIC_DAD_AUTOCONF |   \
836 	 ND6_OPTIMISTIC_DAD_TEMPORARY | ND6_OPTIMISTIC_DAD_DYNAMIC |    \
837 	 ND6_OPTIMISTIC_DAD_SECURED | ND6_OPTIMISTIC_DAD_MANUAL)
838 
839 /* nd6_rtr.c */
840 extern int nd6_defifindex;
841 extern int ip6_desync_factor;   /* seconds */
842 /* ND6_INFINITE_LIFETIME does not apply to temporary addresses */
843 extern u_int32_t ip6_temp_preferred_lifetime; /* seconds */
844 extern u_int32_t ip6_temp_valid_lifetime; /* seconds */
845 extern int ip6_temp_regen_advance; /* seconds */
846 
847 union nd_opts {
848 	struct nd_opt_hdr *nd_opt_array[26];    /* max = Route information option */
849 	struct {
850 		struct nd_opt_hdr *zero;
851 		struct nd_opt_hdr *src_lladdr;
852 		struct nd_opt_hdr *tgt_lladdr;
853 		struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */
854 		struct nd_opt_rd_hdr *rh;
855 		struct nd_opt_mtu *mtu;
856 		struct nd_opt_hdr *__res6;
857 		struct nd_opt_hdr *__res7;
858 		struct nd_opt_hdr *__res8;
859 		struct nd_opt_hdr *__res9;
860 		struct nd_opt_hdr *__res10;
861 		struct nd_opt_hdr *__res11;
862 		struct nd_opt_hdr *__res12;
863 		struct nd_opt_hdr *__res13;
864 		struct nd_opt_nonce *nonce;
865 		struct nd_opt_hdr *__res15;
866 		struct nd_opt_hdr *__res16;
867 		struct nd_opt_hdr *__res17;
868 		struct nd_opt_hdr *__res18;
869 		struct nd_opt_hdr *__res19;
870 		struct nd_opt_hdr *__res20;
871 		struct nd_opt_hdr *__res21;
872 		struct nd_opt_hdr *__res22;
873 		struct nd_opt_hdr *__res23;
874 		struct nd_opt_route_info *rti_beg;
875 		struct nd_opt_hdr *__res25;
876 		struct nd_opt_hdr *search;      /* multiple opts */
877 		struct nd_opt_hdr *last;        /* multiple opts */
878 		int done;
879 		struct nd_opt_prefix_info *pi_end; /* multiple prefix opts, end */
880 		struct nd_opt_route_info *rti_end; /* multiple route info opts, end */
881 	} nd_opt_each;
882 };
883 #define nd_opts_src_lladdr      nd_opt_each.src_lladdr
884 #define nd_opts_tgt_lladdr      nd_opt_each.tgt_lladdr
885 #define nd_opts_pi              nd_opt_each.pi_beg
886 #define nd_opts_pi_end          nd_opt_each.pi_end
887 #define nd_opts_rh              nd_opt_each.rh
888 #define nd_opts_mtu             nd_opt_each.mtu
889 #define nd_opts_nonce           nd_opt_each.nonce
890 #define nd_opts_rti             nd_opt_each.rti_beg
891 #define nd_opts_rti_end         nd_opt_each.rti_end
892 #define nd_opts_search          nd_opt_each.search
893 #define nd_opts_last            nd_opt_each.last
894 #define nd_opts_done            nd_opt_each.done
895 
896 /* XXX: need nd6_var.h?? */
897 /* nd6.c */
898 extern int nd6_sched_timeout_want;
899 extern void nd6_sched_timeout(struct timeval *, struct timeval *);
900 extern void nd6_init(void);
901 extern void nd6_ifreset(struct ifnet *ifp);
902 extern void nd6_ifattach(struct ifnet *);
903 extern int nd6_is_addr_neighbor(struct sockaddr_in6 *, struct ifnet *, int);
904 extern void nd6_option_init(void *, int, union nd_opts *);
905 extern struct nd_opt_hdr *nd6_option(union nd_opts *);
906 extern int nd6_options(union nd_opts *);
907 extern struct rtentry *nd6_lookup(struct in6_addr *, int, struct ifnet *, int);
908 extern void nd6_setmtu(struct ifnet *);
909 extern void nd6_purge(struct ifnet *);
910 extern void nd6_free(struct rtentry *);
911 extern void nd6_nud_hint(struct rtentry *, struct in6_addr *, int);
912 extern int nd6_resolve(struct ifnet *, struct rtentry *,
913     struct mbuf *, struct sockaddr *, u_char *);
914 extern void nd6_rtrequest(int, struct rtentry *, struct sockaddr *);
915 extern int nd6_ioctl(u_long, caddr_t, struct ifnet *);
916 extern void nd6_cache_lladdr(struct ifnet *, struct in6_addr *,
917     char *, int, int, int, int *);
918 extern int nd6_output_list(struct ifnet *, struct ifnet *, struct mbuf *,
919     struct sockaddr_in6 *, struct rtentry *, struct flowadv *);
920 extern int nd6_output(struct ifnet *, struct ifnet *, struct mbuf *,
921     struct sockaddr_in6 *, struct rtentry *, struct flowadv *);
922 extern int nd6_storelladdr(struct ifnet *, struct rtentry *, struct mbuf *,
923     struct sockaddr *, u_char *);
924 extern int nd6_need_cache(struct ifnet *);
925 extern void nd6_drain(void *);
926 extern void nd6_post_msg(u_int32_t, struct nd_prefix_list *, u_int32_t,
927     u_int32_t);
928 extern int nd6_setifinfo(struct ifnet *, u_int32_t, u_int32_t);
929 extern const char *ndcache_state2str(short);
930 extern void ln_setexpire(struct llinfo_nd6 *, uint64_t);
931 
932 /* nd6_nbr.c */
933 extern void nd6_nbr_init(void);
934 extern void nd6_na_input(struct mbuf *, int, int);
935 extern void nd6_na_output(struct ifnet *, const struct in6_addr *,
936     const struct in6_addr *, u_int32_t, int, struct sockaddr *);
937 extern void nd6_ns_input(struct mbuf *, int, int);
938 extern void nd6_ns_output(struct ifnet *, const struct in6_addr *,
939     const struct in6_addr *, struct llinfo_nd6 *, uint8_t *);
940 extern caddr_t nd6_ifptomac(struct ifnet *);
941 extern void nd6_dad_start(struct ifaddr *, int *);
942 extern void nd6_dad_stop(struct ifaddr *);
943 extern void nd6_llreach_alloc(struct rtentry *, struct ifnet *, void *,
944     unsigned int, boolean_t);
945 extern void nd6_llreach_set_reachable(struct ifnet *, void *, unsigned int);
946 extern void nd6_llreach_use(struct llinfo_nd6 *);
947 extern void nd6_alt_node_addr_decompose(struct ifnet *, struct sockaddr *,
948     struct sockaddr_dl *, struct sockaddr_in6 *);
949 extern int nd6_alt_node_present(struct ifnet *, struct sockaddr_in6 *,
950     struct sockaddr_dl *, int32_t, int, int);
951 extern int nd6_alt_node_absent(struct ifnet *, struct sockaddr_in6 *, struct sockaddr_dl *);
952 
953 /* nd6_rtr.c */
954 extern struct in6_ifaddr *in6_pfx_newpersistaddr(struct nd_prefix *, int,
955     int *, boolean_t, uint8_t);
956 extern void nd6_rtr_init(void);
957 extern void nd6_rs_input(struct mbuf *, int, int);
958 extern void nd6_ra_input(struct mbuf *, int, int);
959 extern void prelist_del(struct nd_prefix *);
960 extern struct nd_defrouter *defrtrlist_update(struct nd_defrouter *,
961     struct nd_drhead *);
962 extern void defrouter_select(struct ifnet *, struct nd_drhead *);
963 extern void defrouter_reset(void);
964 extern int defrtrlist_ioctl(u_long, caddr_t);
965 extern void defrtrlist_del(struct nd_defrouter *, struct nd_drhead *);
966 extern int defrtrlist_add_static(struct nd_defrouter *);
967 extern int defrtrlist_del_static(struct nd_defrouter *);
968 extern void prelist_remove(struct nd_prefix *);
969 extern int prelist_update(struct nd_prefix *, struct nd_defrouter *,
970     struct mbuf *, int);
971 extern int nd6_prelist_add(struct nd_prefix *, struct nd_defrouter *,
972     struct nd_prefix **, boolean_t);
973 extern int nd6_prefix_onlink(struct nd_prefix *);
974 extern int nd6_prefix_onlink_scoped(struct nd_prefix *, unsigned int);
975 extern int nd6_prefix_offlink(struct nd_prefix *);
976 extern void pfxlist_onlink_check(void);
977 extern void defrouter_set_reachability(struct in6_addr *, struct ifnet *, boolean_t);
978 extern struct nd_defrouter *defrouter_lookup(struct nd_drhead *,
979     struct in6_addr *, struct ifnet *);
980 extern struct nd_pfxrouter *pfxrtr_lookup(struct nd_prefix *, struct nd_defrouter *);
981 extern struct nd_prefix *nd6_prefix_lookup(struct nd_prefix *, int);
982 extern int in6_init_prefix_ltimes(struct nd_prefix *ndpr);
983 extern void rt6_flush(struct in6_addr *, struct ifnet *);
984 extern int nd6_setdefaultiface(int);
985 extern int in6_tmpifadd(const struct in6_ifaddr *, int);
986 extern void nddr_addref(struct nd_defrouter *);
987 extern struct nd_defrouter *nddr_remref(struct nd_defrouter *);
988 extern uint64_t nddr_getexpire(struct nd_defrouter *);
989 extern void ndpr_addref(struct nd_prefix *);
990 extern struct nd_prefix *ndpr_remref(struct nd_prefix *);
991 extern uint64_t ndpr_getexpire(struct nd_prefix *);
992 
993 /* nd6_prproxy.c */
994 struct ip6_hdr;
995 extern u_int32_t nd6_prproxy;
996 extern int nd6_if_prproxy(struct ifnet *, boolean_t);
997 extern void nd6_prproxy_prelist_update(struct nd_prefix *, struct nd_prefix *);
998 extern boolean_t nd6_prproxy_ifaddr(struct in6_ifaddr *);
999 extern void nd6_proxy_find_fwdroute(struct ifnet *, struct route_in6 *);
1000 extern boolean_t nd6_prproxy_isours(struct mbuf *, struct ip6_hdr *,
1001     struct route_in6 *, unsigned int);
1002 extern void nd6_prproxy_ns_output(struct ifnet *, struct ifnet *,
1003     struct in6_addr *, struct in6_addr *, struct llinfo_nd6 *);
1004 extern void nd6_prproxy_ns_input(struct ifnet *, struct in6_addr *,
1005     char *, int, struct in6_addr *, struct in6_addr *, uint8_t *nonce);
1006 extern void nd6_prproxy_na_input(struct ifnet *, struct in6_addr *,
1007     struct in6_addr *, struct in6_addr *, int);
1008 extern void nd6_prproxy_sols_reap(struct nd_prefix *);
1009 extern void nd6_prproxy_sols_prune(struct nd_prefix *, u_int32_t);
1010 extern int nd6_if_disable(struct ifnet *, boolean_t);
1011 void in6_ifaddr_set_dadprogress(struct in6_ifaddr *ia);
1012 #endif /* BSD_KERNEL_PRIVATE */
1013 
1014 #ifdef KERNEL
1015 
1016 /*
1017  *	@function nd6_lookup_ipv6
1018  *	@discussion This function will check the routing table for a cached
1019  *		neighbor discovery entry or trigger an neighbor discovery query
1020  *		to resolve the IPv6 address to a link-layer address.
1021  *		nd entries are stored in the routing table. This function will
1022  *		lookup the IPv6 destination in the routing table. If the
1023  *		destination requires forwarding to a gateway, the route of the
1024  *		gateway will be looked up. The route entry is inspected to
1025  *		determine if the link layer destination address is known. If
1026  *		unknown, neighbor discovery will be used to resolve the entry.
1027  *	@param interface The interface the packet is being sent on.
1028  *	@param ip6_dest The IPv6 destination of the packet.
1029  *	@param ll_dest On output, the link-layer destination.
1030  *	@param ll_dest_len The length of the buffer for ll_dest.
1031  *	@param hint Any routing hint passed down from the protocol.
1032  *	@param packet The packet being transmitted.
1033  *	@result May return an error such as EHOSTDOWN or ENETUNREACH. If
1034  *		this function returns EJUSTRETURN, the packet has been queued
1035  *		and will be sent when the address is resolved. If any other
1036  *		value is returned, the caller is responsible for disposing of
1037  *		the packet.
1038  */
1039 extern errno_t nd6_lookup_ipv6(ifnet_t interface,
1040     const struct sockaddr_in6 *ip6_dest, struct sockaddr_dl *ll_dest,
1041     size_t ll_dest_len, route_t hint, mbuf_t packet);
1042 
1043 #endif /* KERNEL */
1044 
1045 /* nd6_send.c */
1046 #ifdef BSD_KERNEL_PRIVATE
1047 /*
1048  * nd6_send_opmode
1049  *
1050  *      value	using CGA	tx SEND		rx SEND
1051  *   --------	---------	-------		-------
1052  *   DISABLED	       NO	     NO		     NO
1053  *      QUIET	      YES	     NO		     NO
1054  */
1055 extern int nd6_send_opstate;
1056 
1057 #define ND6_SEND_OPMODE_DISABLED        0
1058 #define ND6_SEND_OPMODE_CGA_QUIET       1
1059 
1060 #endif /* BSD_KERNEL_PRIVATE */
1061 #endif /* _NETINET6_ND6_H_ */
1062