2 * Copyright (c) 2000-2020 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
30 * All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
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.
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
57 #ifndef _NETINET6_ND6_H_
58 #define _NETINET6_ND6_H_
59 #include <sys/appleapiopts.h>
60 #include <net/net_kev.h>
62 /* see net/route.h, or net/if_inarp.h */
64 #define RTF_ANNOUNCE RTF_PROTO2
67 #include <sys/queue.h>
69 #ifdef BSD_KERNEL_PRIVATE
70 #include <net/flowadv.h>
71 #include <kern/locks.h>
73 #include <sys/eventhandler.h>
74 #include <netinet6/nd6_var.h>
78 * The following are protected by rnh_lock
80 struct llinfo_nd6
*ln_next
;
81 struct llinfo_nd6
*ln_prev
;
82 struct rtentry
*ln_rt
;
84 * The following are protected by rt_lock
86 struct ifnet
*ln_exclifp
; /* excluded interface (prefix proxy) */
87 struct mbuf
*ln_hold
; /* last packet until resolved/timeout */
88 uint32_t ln_asked
; /* # of queries already sent for this addr */
89 short ln_state
; /* reachability state */
90 short ln_router
; /* 2^0: ND6 router bit */
91 u_int32_t ln_flags
; /* flags; see below */
92 u_int64_t ln_expire
; /* lifetime for NDP state transition */
93 u_int64_t ln_lastused
; /* last used timestamp */
94 struct if_llreach
*ln_llreach
; /* link-layer reachability record */
97 /* Values for ln_flags */
98 #define ND6_LNF_TIMER_SKIP 0x1 /* modified by nd6_timer() */
99 #define ND6_LNF_IN_USE 0x2 /* currently in llinfo_nd6 list */
100 #endif /* BSD_KERNEL_PRIVATE */
102 #define ND6_LLINFO_PURGE -3
103 #define ND6_LLINFO_NOSTATE -2
105 * We don't need the WAITDELETE state any more, but we keep the definition
106 * in a comment line instead of removing it. This is necessary to avoid
107 * unintentionally reusing the value for another purpose, which might
108 * affect backward compatibility with old applications.
109 * (20000711 jinmei@kame.net)
111 /* #define ND6_LLINFO_WAITDELETE -1 */
112 #define ND6_LLINFO_INCOMPLETE 0
113 #define ND6_LLINFO_REACHABLE 1
114 #define ND6_LLINFO_STALE 2
115 #define ND6_LLINFO_DELAY 3
116 #define ND6_LLINFO_PROBE 4
118 #ifdef BSD_KERNEL_PRIVATE
120 #define ND6_CACHE_STATE_TRANSITION(ln, nstate) do {\
121 if (nd6_debug >= 1) {\
122 struct rtentry *ln_rt = ln != NULL ? (ln)->ln_rt : NULL; \
124 "[%s:%d]: NDP cache entry changed from %s -> %s for address %s.\n",\
127 ndcache_state2str((ln)->ln_state),\
128 ndcache_state2str(nstate),\
129 ln_rt != NULL ? ip6_sprintf(&SIN6(rt_key(ln_rt))->sin6_addr) : "N/A");\
132 (ln)->ln_state = nstate;\
135 #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE)
136 #define ND6_LLINFO_PERMANENT(n) \
137 (((n)->ln_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE))
139 #define ND6_EUI64_GBIT 0x01
140 #define ND6_EUI64_UBIT 0x02
142 #define ND6_EUI64_TO_IFID(in6) \
143 do {(in6)->s6_addr[8] ^= ND6_EUI64_UBIT; } while (0)
145 #define ND6_EUI64_GROUP(in6) ((in6)->s6_addr[8] & ND6_EUI64_GBIT)
146 #define ND6_EUI64_INDIVIDUAL(in6) (!ND6_EUI64_GROUP(in6))
147 #define ND6_EUI64_LOCAL(in6) ((in6)->s6_addr[8] & ND6_EUI64_UBIT)
148 #define ND6_EUI64_UNIVERSAL(in6) (!ND6_EUI64_LOCAL(in6))
149 #define ND6_IFID_LOCAL(in6) (!ND6_EUI64_LOCAL(in6))
150 #define ND6_IFID_UNIVERSAL(in6) (!ND6_EUI64_UNIVERSAL(in6))
151 #endif /* BSD_KERNEL_PRIVATE */
153 #if !defined(BSD_KERNEL_PRIVATE)
156 /* For binary compatibility, this structure must not change */
157 /* NOTE: nd_ifinfo is defined in nd6_var.h */
158 struct nd_ifinfo_compat
{
159 #endif /* !BSD_KERNEL_PRIVATE */
160 u_int32_t linkmtu
; /* LinkMTU */
161 u_int32_t maxmtu
; /* Upper bound of LinkMTU */
162 u_int32_t basereachable
; /* BaseReachableTime */
163 u_int32_t reachable
; /* Reachable Time */
164 u_int32_t retrans
; /* Retrans Timer */
165 u_int32_t flags
; /* Flags */
166 int recalctm
; /* BaseReacable re-calculation timer */
167 u_int8_t chlim
; /* CurHopLimit */
169 /* the following 3 members are for privacy extension for addrconf */
170 u_int8_t randomseed0
[8]; /* upper 64 bits of SHA1 digest */
171 u_int8_t randomseed1
[8]; /* lower 64 bits (usually the EUI64 IFID) */
172 u_int8_t randomid
[8]; /* current random ID */
175 #define ND6_IFF_PERFORMNUD 0x1
179 * APPLE: not used. Interface specific router advertisements are handled with a
180 * specific ifnet flag: IFEF_ACCEPT_RTADVD
182 #define ND6_IFF_ACCEPT_RTADV 0x2
184 /* APPLE: NOT USED not related to ND. */
185 #define ND6_IFF_PREFER_SOURCE 0x4
187 /* IPv6 operation is disabled due to * DAD failure. (XXX: not ND-specific) */
188 #define ND6_IFF_IFDISABLED 0x8
190 #define ND6_IFF_DONT_SET_IFROUTE 0x10 /* NOT USED */
192 #define ND6_IFF_PROXY_PREFIXES 0x20
193 #define ND6_IFF_IGNORE_NA 0x40
195 #define ND6_IFF_INSECURE 0x80
197 #define ND6_IFF_REPLICATED 0x100 /* sleep proxy registered */
198 #define ND6_IFF_DAD 0x200 /* Perform DAD on the interface */
200 extern int dad_enhanced
;
201 #define ND6_DAD_ENHANCED_DEFAULT 1
204 char ifname
[IFNAMSIZ
]; /* if name, e.g. "en0" */
205 struct in6_addr addr
; /* IPv6 address of the neighbor */
206 long asked
; /* # of queries already sent for this addr */
207 int isrouter
; /* if it acts as a router */
208 int state
; /* reachability state */
209 int expire
; /* lifetime for NDP state transition */
212 #if defined(BSD_KERNEL_PRIVATE)
213 struct in6_nbrinfo_32
{
214 char ifname
[IFNAMSIZ
];
215 struct in6_addr addr
;
222 struct in6_nbrinfo_64
{
223 char ifname
[IFNAMSIZ
];
224 struct in6_addr addr
;
226 int isrouter
__attribute__((aligned(8)));
229 } __attribute__((aligned(8)));
230 #endif /* BSD_KERNEL_PRIVATE */
236 char ifname
[IFNAMSIZ
];
238 struct in6_addr rtaddr
;
243 } defrouter
[DRLSTSIZ
];
246 #if defined(BSD_KERNEL_PRIVATE)
247 #define ND6_PROCESS_RTI_ENABLE 1
248 #define ND6_PROCESS_RTI_DISABLE 0
249 #define ND6_PROCESS_RTI_DEFAULT ND6_PROCESS_RTI_ENABLE
251 extern int nd6_process_rti
;
253 struct in6_drlist_32
{
254 char ifname
[IFNAMSIZ
];
256 struct in6_addr rtaddr
;
261 } defrouter
[DRLSTSIZ
];
264 struct in6_drlist_64
{
265 char ifname
[IFNAMSIZ
];
267 struct in6_addr rtaddr
;
270 u_long expire
__attribute__((aligned(8)));
271 u_short if_index
__attribute__((aligned(8)));
272 } defrouter
[DRLSTSIZ
] __attribute__((aligned(8)));
274 #endif /* BSD_KERNEL_PRIVATE */
276 /* valid values for stateflags */
277 #define NDDRF_INSTALLED 0x01 /* installed in the routing table */
278 #define NDDRF_IFSCOPE 0x02 /* installed as a scoped route */
279 #define NDDRF_STATIC 0x04 /* for internal use only */
280 #define NDDRF_MAPPED 0x08 /* Default router addr is mapped to a different one for routing */
281 #define NDDRF_INELIGIBLE 0x10 /* Default router entry is ineligible for default router selection */
283 struct in6_defrouter
{
284 struct sockaddr_in6 rtaddr
;
292 #if defined(BSD_KERNEL_PRIVATE)
293 struct in6_defrouter_32
{
294 struct sockaddr_in6 rtaddr
;
302 struct in6_defrouter_64
{
303 struct sockaddr_in6 rtaddr
;
307 u_long expire
__attribute__((aligned(8)));
308 u_short if_index
__attribute__((aligned(8)));
309 } __attribute__((aligned(8)));
310 #endif /* BSD_KERNEL_PRIVATE */
313 char ifname
[IFNAMSIZ
];
315 struct in6_addr prefix
;
316 struct prf_ra raflags
;
323 u_short advrtrs
; /* number of advertisement routers */
324 struct in6_addr advrtr
[DRLSTSIZ
]; /* XXX: explicit limit */
328 #if defined(BSD_KERNEL_PRIVATE)
329 struct in6_prlist_32
{
330 char ifname
[IFNAMSIZ
];
332 struct in6_addr prefix
;
333 struct prf_ra raflags
;
341 struct in6_addr advrtr
[DRLSTSIZ
];
345 struct in6_prlist_64
{
346 char ifname
[IFNAMSIZ
];
348 struct in6_addr prefix
;
349 struct prf_ra raflags
;
352 u_long vltime
__attribute__((aligned(8)));
353 u_long pltime
__attribute__((aligned(8)));
354 u_long expire
__attribute__((aligned(8)));
358 struct in6_addr advrtr
[DRLSTSIZ
];
361 #endif /* BSD_KERNEL_PRIVATE */
364 struct sockaddr_in6 prefix
;
365 struct prf_ra raflags
;
374 u_short advrtrs
; /* number of advertisement routers */
375 /* struct sockaddr_in6 advrtr[] */
378 #if defined(BSD_KERNEL_PRIVATE)
379 struct in6_prefix_32
{
380 struct sockaddr_in6 prefix
;
381 struct prf_ra raflags
;
390 u_short advrtrs
; /* number of advertisement routers */
391 /* struct sockaddr_in6 advrtr[] */
394 struct in6_prefix_64
{
395 struct sockaddr_in6 prefix
;
396 struct prf_ra raflags
;
399 u_long vltime
__attribute__((aligned(8)));
400 u_long pltime
__attribute__((aligned(8)));
401 u_long expire
__attribute__((aligned(8)));
402 u_int32_t flags
__attribute__((aligned(8)));
406 /* struct sockaddr_in6 advrtr[] */
408 #endif /* BSD_KERNEL_PRIVATE */
411 char ifname
[IFNAMSIZ
];
413 u_int32_t linkmtu
; /* LinkMTU */
414 u_int32_t maxmtu
; /* Upper bound of LinkMTU */
415 u_int32_t basereachable
; /* BaseReachableTime */
416 u_int32_t reachable
; /* Reachable Time */
417 u_int32_t retrans
; /* Retrans Timer */
418 u_int32_t flags
; /* Flags */
419 int recalctm
; /* BaseReacable re-calculation timer */
420 u_int8_t chlim
; /* CurHopLimit */
421 /* Number of routers learned on the interface */
424 * The current collision count value
425 * being used for secure address generation.
427 u_int8_t collision_count
;
431 #if !defined(BSD_KERNEL_PRIVATE)
433 char ifname
[IFNAMSIZ
];
434 struct nd_ifinfo ndi
;
438 char ifname
[IFNAMSIZ
];
439 struct nd_ifinfo_compat ndi
;
441 #endif /* !BSD_KERNEL_PRIVATE */
444 char ifname
[IFNAMSIZ
];
448 #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */
449 #define RTR_SOLICITATION_INTERVAL 4 /* 4sec */
451 #if defined(BSD_KERNEL_PRIVATE)
452 struct in6_ndifreq_32
{
453 char ifname
[IFNAMSIZ
];
457 struct in6_ndifreq_64
{
458 char ifname
[IFNAMSIZ
];
459 u_int64_t ifindex
__attribute__((aligned(8)));
461 #endif /* BSD_KERNEL_PRIVATE */
464 #define NDPRF_ONLINK 0x1
465 #define NDPRF_DETACHED 0x2
466 #define NDPRF_STATIC 0x100
467 #define NDPRF_IFSCOPE 0x1000
468 #define NDPRF_PRPROXY 0x2000
469 #ifdef BSD_KERNEL_PRIVATE
470 #define NDPRF_PROCESSED_ONLINK 0x08000
471 #define NDPRF_PROCESSED_SERVICE 0x10000
472 #define NDPRF_DEFUNCT 0x20000
473 #define NDPRF_CLAT46 0x40000
475 #define CLAT46_COLLISION_COUNT_OFFSET 128
478 /* protocol constants */
479 #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */
480 #define RTR_SOLICITATION_INTERVAL 4 /* 4sec */
481 #define MAX_RTR_SOLICITATIONS 3
483 #define ND6_INFINITE_LIFETIME 0xffffffff
484 #define ND6_MAX_LIFETIME 0x7fffffff
486 #ifdef BSD_KERNEL_PRIVATE
487 #define ND_IFINFO(ifp) \
488 ((ifp == NULL) ? NULL : \
489 ((IN6_IFEXTRA(ifp) == NULL) ? NULL : \
490 (&IN6_IFEXTRA(ifp)->nd_ifinfo)))
493 * In a more readable form, we derive linkmtu based on:
496 * linkmtu = IPV6_MMTU
497 * else if (ND_IFINFO(ifp) == NULL || !ND_IFINFO(ifp)->initialized)
498 * linkmtu = ifp->if_mtu;
499 * else if (ND_IFINFO(ifp)->linkmtu && ND_IFINFO(ifp)->linkmtu < ifp->if_mtu)
500 * linkmtu = ND_IFINFO(ifp)->linkmtu;
501 * else if ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < ifp->if_mtu))
502 * linkmtu = ND_IFINFO(ifp)->maxmtu;
504 * linkmtu = ifp->if_mtu;
506 #define IN6_LINKMTU(ifp) \
507 (ifp == NULL ? IPV6_MMTU : \
508 (ND_IFINFO(ifp) == NULL || !ND_IFINFO(ifp)->initialized) ? \
509 (ifp)->if_mtu : ((ND_IFINFO(ifp)->linkmtu && \
510 ND_IFINFO(ifp)->linkmtu < (ifp)->if_mtu) ? ND_IFINFO(ifp)->linkmtu : \
511 ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < (ifp)->if_mtu) ? \
512 ND_IFINFO(ifp)->maxmtu : (ifp)->if_mtu)))
515 #define MAX_REACHABLE_TIME 3600000 /* msec */
516 #define REACHABLE_TIME 30000 /* msec */
517 #define RETRANS_TIMER 1000 /* msec */
518 #define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */
519 #define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */
520 #define DEF_TEMP_VALID_LIFETIME 604800 /* 1 week */
521 #define DEF_TEMP_PREFERRED_LIFETIME 86400 /* 1 day */
522 #define TEMPADDR_REGEN_ADVANCE 5 /* sec */
523 #define MAX_TEMP_DESYNC_FACTOR 600 /* 10 min */
524 #define ND_COMPUTE_RTIME(x) \
525 (((MIN_RANDOM_FACTOR * (x >> 10)) + (RandomULong() & \
526 ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
528 #define IP6_USE_TMPADDR_DEFAULT 1
529 /* prefix expiry times */
530 #define ND6_PREFIX_EXPIRY_UNSPEC -1
531 #define ND6_PREFIX_EXPIRY_NEVER 0
533 TAILQ_HEAD(nd_drhead
, nd_defrouter
);
534 struct nd_defrouter
{
535 decl_lck_mtx_data(, nddr_lock
);
536 decl_lck_mtx_data(, nddr_ref_lock
);
537 TAILQ_ENTRY(nd_defrouter
) dr_entry
;
538 struct in6_addr rtaddr
;
539 u_int32_t nddr_refcount
;
540 u_int32_t nddr_debug
;
542 u_int64_t base_calendartime
; /* calendar time at creation */
543 u_int64_t base_uptime
; /* uptime at creation */
544 u_char flags
; /* flags on RA message */
546 u_int32_t rtlifetime
;
549 struct in6_addr rtaddr_mapped
; /* Mapped gateway address for routing */
550 void (*nddr_trace
)(struct nd_defrouter
*, int); /* trace callback fn */
553 #define NDDR_LOCK_ASSERT_HELD(_nddr) \
554 LCK_MTX_ASSERT(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_OWNED)
556 #define NDDR_LOCK_ASSERT_NOTHELD(_nddr) \
557 LCK_MTX_ASSERT(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_NOTOWNED)
559 #define NDDR_LOCK(_nddr) \
560 lck_mtx_lock(&(_nddr)->nddr_lock)
562 #define NDDR_LOCK_SPIN(_nddr) \
563 lck_mtx_lock_spin(&(_nddr)->nddr_lock)
565 #define NDDR_CONVERT_LOCK(_nddr) do { \
566 NDPR_LOCK_ASSERT_HELD(_nddr); \
567 lck_mtx_convert_spin(&(_nddr)->nddr_lock); \
570 #define NDDR_UNLOCK(_nddr) \
571 lck_mtx_unlock(&(_nddr)->nddr_lock)
573 #define NDDR_REF_LOCK(_nddr) \
574 lck_mtx_lock(&(_nddr)->nddr_ref_lock)
576 #define NDDR_REF_LOCK_SPIN(_nddr) \
577 lck_mtx_lock_spin(&(_nddr)->nddr_ref_lock)
579 #define NDDR_REF_UNLOCK(_nddr) \
580 lck_mtx_unlock(&(_nddr)->nddr_ref_lock)
582 #define NDDR_ADDREF(_nddr) \
585 #define NDDR_REMREF(_nddr) \
588 TAILQ_HEAD(nd_rtihead, nd_route_info);
590 * The ordering below is important and it should always start
591 * with nd_drhead as the first element.
592 * It gets passed in as the generic nd_drhead to router management code.
593 * The extra information stored here includes the prefix/prefix-length
594 * which the router list belongs to.
596 struct nd_route_info
{
597 struct nd_drhead nd_rti_router_list
;
598 TAILQ_ENTRY(nd_route_info
) nd_rti_entry
;
599 struct in6_addr nd_rti_prefix
;
600 u_int8_t nd_rti_prefixlen
;
603 struct nd_route_info
*ndrti_alloc(void);
604 void nd6_rti_list_wait(const char *);
605 void nd6_rti_list_signal_done(void);
606 void ndrti_free(struct nd_route_info
*rti
);
607 void nd6_rtilist_remove(struct nd_route_info
*);
608 void nd6_rtilist_update(struct nd_route_info
*, struct nd_defrouter
*);
609 int nd6_rtilist_add(struct nd_route_info
*, struct nd_defrouter
*,
610 struct nd_route_info
**);
611 void nd6_rti_purge(struct nd_route_info
*);
613 /* define struct prproxy_sols_tree */
614 RB_HEAD(prproxy_sols_tree
, nd6_prproxy_soltgt
);
617 decl_lck_mtx_data(, ndpr_lock
);
618 decl_lck_mtx_data(, ndpr_ref_lock
);
619 u_int32_t ndpr_refcount
; /* reference count */
620 u_int32_t ndpr_debug
; /* see ifa_debug flags */
621 struct ifnet
*ndpr_ifp
;
622 struct rtentry
*ndpr_rt
;
623 LIST_ENTRY(nd_prefix
) ndpr_entry
;
624 struct sockaddr_in6 ndpr_prefix
; /* prefix */
625 struct in6_addr ndpr_mask
; /* netmask derived from the prefix */
626 struct in6_addr ndpr_addr
; /* address that is derived from the prefix */
627 u_int32_t ndpr_vltime
; /* advertised valid lifetime */
628 u_int32_t ndpr_pltime
; /* advertised preferred lifetime */
629 u_int64_t ndpr_preferred
; /* preferred time of the prefix */
630 u_int64_t ndpr_expire
; /* expiration time of the prefix */
631 u_int64_t ndpr_lastupdate
; /* rx time of last advertisement */
632 u_int64_t ndpr_base_calendartime
; /* calendar time at creation */
633 u_int64_t ndpr_base_uptime
; /* uptime at creation */
634 struct prf_ra ndpr_flags
;
635 unsigned int ndpr_genid
; /* protects ndpr_advrtrs */
636 u_int32_t ndpr_stateflags
; /* actual state flags */
637 /* list of routers that advertise the prefix: */
638 LIST_HEAD(pr_rtrhead
, nd_pfxrouter
) ndpr_advrtrs
;
640 int ndpr_addrcnt
; /* reference counter from addresses */
641 u_int32_t ndpr_allmulti_cnt
; /* total all-multi reqs */
642 u_int32_t ndpr_prproxy_sols_cnt
; /* total # of proxied NS */
643 struct prproxy_sols_tree ndpr_prproxy_sols
; /* tree of proxied NS */
644 void (*ndpr_trace
)(struct nd_prefix
*, int); /* trace callback fn */
647 #define ndpr_next ndpr_entry.le_next
649 #define ndpr_raf ndpr_flags
650 #define ndpr_raf_onlink ndpr_flags.onlink
651 #define ndpr_raf_auto ndpr_flags.autonomous
652 #define ndpr_raf_router ndpr_flags.router
654 * We keep expired prefix for certain amount of time, for validation purposes.
655 * 1800s = MaxRtrAdvInterval
657 #define NDPR_KEEP_EXPIRED (1800 * 2)
659 #define NDPR_LOCK_ASSERT_HELD(_ndpr) \
660 LCK_MTX_ASSERT(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_OWNED)
662 #define NDPR_LOCK_ASSERT_NOTHELD(_ndpr) \
663 LCK_MTX_ASSERT(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_NOTOWNED)
665 #define NDPR_LOCK(_ndpr) \
666 lck_mtx_lock(&(_ndpr)->ndpr_lock)
668 #define NDPR_LOCK_SPIN(_ndpr) \
669 lck_mtx_lock_spin(&(_ndpr)->ndpr_lock)
671 #define NDPR_CONVERT_LOCK(_ndpr) do { \
672 NDPR_LOCK_ASSERT_HELD(_ndpr); \
673 lck_mtx_convert_spin(&(_ndpr)->ndpr_lock); \
676 #define NDPR_UNLOCK(_ndpr) \
677 lck_mtx_unlock(&(_ndpr)->ndpr_lock)
679 #define NDPR_REF_LOCK(_ndpr) \
680 lck_mtx_lock(&(_ndpr)->ndpr_ref_lock)
682 #define NDPR_REF_LOCK_SPIN(_ndpr) \
683 lck_mtx_lock_spin(&(_ndpr)->ndpr_ref_lock)
685 #define NDPR_REF_UNLOCK(_ndpr) \
686 lck_mtx_unlock(&(_ndpr)->ndpr_ref_lock)
688 #define NDPR_ADDREF(_ndpr) \
691 #define NDPR_REMREF(_ndpr) \
695 * Message format for use in obtaining information about prefixes
696 * from inet6 sysctl function
698 struct inet6_ndpr_msghdr
{
699 u_short inpm_msglen
; /* to skip over non-understood messages */
700 u_char inpm_version
; /* future binary compatibility */
701 u_char inpm_type
; /* message type */
702 struct in6_addr inpm_prefix
;
704 u_int32_t prm_pltime
;
705 u_int32_t prm_expire
;
706 u_int32_t prm_preferred
;
707 struct in6_prflags prm_flags
;
708 u_short prm_index
; /* index for associated ifp */
709 u_char prm_plen
; /* length of prefix in bits */
712 #define prm_raf_onlink prm_flags.prf_ra.onlink
713 #define prm_raf_auto prm_flags.prf_ra.autonomous
715 #define prm_statef_onlink prm_flags.prf_state.onlink
717 #define prm_rrf_decrvalid prm_flags.prf_rr.decrvalid
718 #define prm_rrf_decrprefd prm_flags.prf_rr.decrprefd
720 struct nd_pfxrouter
{
721 LIST_ENTRY(nd_pfxrouter
) pfr_entry
;
722 #define pfr_next pfr_entry.le_next
723 struct nd_defrouter
*router
;
726 LIST_HEAD(nd_prhead
, nd_prefix
);
728 struct nd_prefix_list
{
729 struct nd_prefix_list
*next
;
732 #endif /* BSD_KERNEL_PRIVATE */
735 struct kev_nd6_ndfailure
{
736 struct net_event_data link_data
;
739 struct kev_nd6_ndalive
{
740 struct net_event_data link_data
;
743 struct nd6_ra_prefix
{
744 struct sockaddr_in6 prefix
;
745 struct prf_ra raflags
;
757 /* ND6 router advertisement valid bits */
758 #define KEV_ND6_DATA_VALID_MTU (0x1 << 0)
759 #define KEV_ND6_DATA_VALID_PREFIX (0x1 << 1)
761 struct kev_nd6_ra_data
{
763 u_int32_t list_index
;
764 u_int32_t list_length
;
766 struct nd6_ra_prefix prefix
;
770 struct kev_nd6_event
{
771 struct net_event_data link_data
;
772 struct in6_addr in6_address
;
776 struct nd6_lookup_ipv6_args
{
777 char ifname
[IFNAMSIZ
];
778 struct sockaddr_in6 ip6_dest
;
779 u_int32_t ll_dest_len
;
782 struct sockaddr_dl _sdl
;
785 #define ll_dest_sdl ll_dest_._sdl
789 #if defined(BSD_KERNEL_PRIVATE)
791 extern int nd6_prune
;
792 extern int nd6_prune_lazy
;
793 extern int nd6_delay
;
794 extern int nd6_umaxtries
;
795 extern int nd6_mmaxtries
;
796 extern int nd6_useloopback
;
797 extern int nd6_accept_6to4
;
798 extern int nd6_maxnudhint
;
799 extern int nd6_gctimer
;
800 extern struct llinfo_nd6 llinfo_nd6
;
801 extern struct nd_drhead nd_defrouter_list
;
802 extern struct nd_rtihead nd_rti_list
;
803 extern struct nd_prhead nd_prefix
;
804 extern int nd6_debug
;
805 extern int nd6_onlink_ns_rfc4861
;
806 extern int nd6_optimistic_dad
;
810 #define nd6log0(type, ...) do { os_log_##type(OS_LOG_DEFAULT, __VA_ARGS__); } while (0)
811 #define nd6log(type, ...) do { if (nd6_debug >= 1) os_log_##type(OS_LOG_DEFAULT, __VA_ARGS__); } while (0)
812 #define nd6log2(type, ...) do { if (nd6_debug >= 2) os_log_##type(OS_LOG_DEFAULT, __VA_ARGS__); } while (0)
814 #define ND6_OPTIMISTIC_DAD_LINKLOCAL (1 << 0)
815 #define ND6_OPTIMISTIC_DAD_AUTOCONF (1 << 1)
816 #define ND6_OPTIMISTIC_DAD_TEMPORARY (1 << 2)
817 #define ND6_OPTIMISTIC_DAD_DYNAMIC (1 << 3)
818 #define ND6_OPTIMISTIC_DAD_SECURED (1 << 4)
819 #define ND6_OPTIMISTIC_DAD_MANUAL (1 << 5)
821 #define ND6_OPTIMISTIC_DAD_DEFAULT \
822 (ND6_OPTIMISTIC_DAD_LINKLOCAL | ND6_OPTIMISTIC_DAD_AUTOCONF | \
823 ND6_OPTIMISTIC_DAD_TEMPORARY | ND6_OPTIMISTIC_DAD_DYNAMIC | \
824 ND6_OPTIMISTIC_DAD_SECURED | ND6_OPTIMISTIC_DAD_MANUAL)
827 extern int nd6_defifindex
;
828 extern int ip6_desync_factor
; /* seconds */
829 /* ND6_INFINITE_LIFETIME does not apply to temporary addresses */
830 extern u_int32_t ip6_temp_preferred_lifetime
; /* seconds */
831 extern u_int32_t ip6_temp_valid_lifetime
; /* seconds */
832 extern int ip6_temp_regen_advance
; /* seconds */
835 struct nd_opt_hdr
*nd_opt_array
[26]; /* max = Route information option */
837 struct nd_opt_hdr
*zero
;
838 struct nd_opt_hdr
*src_lladdr
;
839 struct nd_opt_hdr
*tgt_lladdr
;
840 struct nd_opt_prefix_info
*pi_beg
; /* multiple opts, start */
841 struct nd_opt_rd_hdr
*rh
;
842 struct nd_opt_mtu
*mtu
;
843 struct nd_opt_hdr
*__res6
;
844 struct nd_opt_hdr
*__res7
;
845 struct nd_opt_hdr
*__res8
;
846 struct nd_opt_hdr
*__res9
;
847 struct nd_opt_hdr
*__res10
;
848 struct nd_opt_hdr
*__res11
;
849 struct nd_opt_hdr
*__res12
;
850 struct nd_opt_hdr
*__res13
;
851 struct nd_opt_nonce
*nonce
;
852 struct nd_opt_hdr
*__res15
;
853 struct nd_opt_hdr
*__res16
;
854 struct nd_opt_hdr
*__res17
;
855 struct nd_opt_hdr
*__res18
;
856 struct nd_opt_hdr
*__res19
;
857 struct nd_opt_hdr
*__res20
;
858 struct nd_opt_hdr
*__res21
;
859 struct nd_opt_hdr
*__res22
;
860 struct nd_opt_hdr
*__res23
;
861 struct nd_opt_route_info
*rti_beg
;
862 struct nd_opt_hdr
*__res25
;
863 struct nd_opt_hdr
*search
; /* multiple opts */
864 struct nd_opt_hdr
*last
; /* multiple opts */
866 struct nd_opt_prefix_info
*pi_end
; /* multiple prefix opts, end */
867 struct nd_opt_route_info
*rti_end
; /* multiple route info opts, end */
870 #define nd_opts_src_lladdr nd_opt_each.src_lladdr
871 #define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr
872 #define nd_opts_pi nd_opt_each.pi_beg
873 #define nd_opts_pi_end nd_opt_each.pi_end
874 #define nd_opts_rh nd_opt_each.rh
875 #define nd_opts_mtu nd_opt_each.mtu
876 #define nd_opts_nonce nd_opt_each.nonce
877 #define nd_opts_rti nd_opt_each.rti_beg
878 #define nd_opts_rti_end nd_opt_each.rti_end
879 #define nd_opts_search nd_opt_each.search
880 #define nd_opts_last nd_opt_each.last
881 #define nd_opts_done nd_opt_each.done
883 /* XXX: need nd6_var.h?? */
885 extern int nd6_sched_timeout_want
;
886 extern void nd6_sched_timeout(struct timeval
*, struct timeval
*);
887 extern void nd6_init(void);
888 extern void nd6_ifreset(struct ifnet
*ifp
);
889 extern void nd6_ifattach(struct ifnet
*);
890 extern int nd6_is_addr_neighbor(struct sockaddr_in6
*, struct ifnet
*, int);
891 extern void nd6_option_init(void *, int, union nd_opts
*);
892 extern struct nd_opt_hdr
*nd6_option(union nd_opts
*);
893 extern int nd6_options(union nd_opts
*);
894 extern struct rtentry
*nd6_lookup(struct in6_addr
*, int, struct ifnet
*, int);
895 extern void nd6_setmtu(struct ifnet
*);
896 extern void nd6_purge(struct ifnet
*);
897 extern void nd6_free(struct rtentry
*);
898 extern void nd6_nud_hint(struct rtentry
*, struct in6_addr
*, int);
899 extern int nd6_resolve(struct ifnet
*, struct rtentry
*,
900 struct mbuf
*, struct sockaddr
*, u_char
*);
901 extern void nd6_rtrequest(int, struct rtentry
*, struct sockaddr
*);
902 extern int nd6_ioctl(u_long
, caddr_t
, struct ifnet
*);
903 extern void nd6_cache_lladdr(struct ifnet
*, struct in6_addr
*,
904 char *, int, int, int);
905 extern int nd6_output_list(struct ifnet
*, struct ifnet
*, struct mbuf
*,
906 struct sockaddr_in6
*, struct rtentry
*, struct flowadv
*);
907 extern int nd6_output(struct ifnet
*, struct ifnet
*, struct mbuf
*,
908 struct sockaddr_in6
*, struct rtentry
*, struct flowadv
*);
909 extern int nd6_storelladdr(struct ifnet
*, struct rtentry
*, struct mbuf
*,
910 struct sockaddr
*, u_char
*);
911 extern int nd6_need_cache(struct ifnet
*);
912 extern void nd6_drain(void *);
913 extern void nd6_post_msg(u_int32_t
, struct nd_prefix_list
*, u_int32_t
,
915 extern int nd6_setifinfo(struct ifnet
*, u_int32_t
, u_int32_t
);
916 extern const char *ndcache_state2str(short);
917 extern void ln_setexpire(struct llinfo_nd6
*, uint64_t);
920 extern void nd6_nbr_init(void);
921 extern void nd6_na_input(struct mbuf
*, int, int);
922 extern void nd6_na_output(struct ifnet
*, const struct in6_addr
*,
923 const struct in6_addr
*, u_int32_t
, int, struct sockaddr
*);
924 extern void nd6_ns_input(struct mbuf
*, int, int);
925 extern void nd6_ns_output(struct ifnet
*, const struct in6_addr
*,
926 const struct in6_addr
*, struct llinfo_nd6
*, uint8_t *);
927 extern caddr_t
nd6_ifptomac(struct ifnet
*);
928 extern void nd6_dad_start(struct ifaddr
*, int *);
929 extern void nd6_dad_stop(struct ifaddr
*);
930 extern void nd6_llreach_alloc(struct rtentry
*, struct ifnet
*, void *,
931 unsigned int, boolean_t
);
932 extern void nd6_llreach_set_reachable(struct ifnet
*, void *, unsigned int);
933 extern void nd6_llreach_use(struct llinfo_nd6
*);
934 extern void nd6_alt_node_addr_decompose(struct ifnet
*, struct sockaddr
*,
935 struct sockaddr_dl
*, struct sockaddr_in6
*);
936 extern int nd6_alt_node_present(struct ifnet
*, struct sockaddr_in6
*,
937 struct sockaddr_dl
*, int32_t, int, int);
938 extern void nd6_alt_node_absent(struct ifnet
*, struct sockaddr_in6
*, struct sockaddr_dl
*);
941 extern struct in6_ifaddr
*in6_pfx_newpersistaddr(struct nd_prefix
*, int,
942 int *, boolean_t
, uint8_t);
943 extern void nd6_rtr_init(void);
944 extern void nd6_rs_input(struct mbuf
*, int, int);
945 extern void nd6_ra_input(struct mbuf
*, int, int);
946 extern void prelist_del(struct nd_prefix
*);
947 extern struct nd_defrouter
*defrtrlist_update(struct nd_defrouter
*,
949 extern void defrouter_select(struct ifnet
*, struct nd_drhead
*);
950 extern void defrouter_reset(void);
951 extern int defrtrlist_ioctl(u_long
, caddr_t
);
952 extern void defrtrlist_del(struct nd_defrouter
*, struct nd_drhead
*);
953 extern int defrtrlist_add_static(struct nd_defrouter
*);
954 extern int defrtrlist_del_static(struct nd_defrouter
*);
955 extern void prelist_remove(struct nd_prefix
*);
956 extern int prelist_update(struct nd_prefix
*, struct nd_defrouter
*,
958 extern int nd6_prelist_add(struct nd_prefix
*, struct nd_defrouter
*,
959 struct nd_prefix
**, boolean_t
);
960 extern int nd6_prefix_onlink(struct nd_prefix
*);
961 extern int nd6_prefix_onlink_scoped(struct nd_prefix
*, unsigned int);
962 extern int nd6_prefix_offlink(struct nd_prefix
*);
963 extern void pfxlist_onlink_check(void);
964 extern struct nd_defrouter
*defrouter_lookup(struct nd_drhead
*,
965 struct in6_addr
*, struct ifnet
*);
966 extern struct nd_prefix
*nd6_prefix_lookup(struct nd_prefix
*, int);
967 extern int in6_init_prefix_ltimes(struct nd_prefix
*ndpr
);
968 extern void rt6_flush(struct in6_addr
*, struct ifnet
*);
969 extern int nd6_setdefaultiface(int);
970 extern int in6_tmpifadd(const struct in6_ifaddr
*, int);
971 extern void nddr_addref(struct nd_defrouter
*);
972 extern struct nd_defrouter
*nddr_remref(struct nd_defrouter
*);
973 extern uint64_t nddr_getexpire(struct nd_defrouter
*);
974 extern void ndpr_addref(struct nd_prefix
*);
975 extern struct nd_prefix
*ndpr_remref(struct nd_prefix
*);
976 extern uint64_t ndpr_getexpire(struct nd_prefix
*);
980 extern u_int32_t nd6_prproxy
;
981 extern int nd6_if_prproxy(struct ifnet
*, boolean_t
);
982 extern void nd6_prproxy_prelist_update(struct nd_prefix
*, struct nd_prefix
*);
983 extern boolean_t
nd6_prproxy_ifaddr(struct in6_ifaddr
*);
984 extern void nd6_proxy_find_fwdroute(struct ifnet
*, struct route_in6
*);
985 extern boolean_t
nd6_prproxy_isours(struct mbuf
*, struct ip6_hdr
*,
986 struct route_in6
*, unsigned int);
987 extern void nd6_prproxy_ns_output(struct ifnet
*, struct ifnet
*,
988 struct in6_addr
*, struct in6_addr
*, struct llinfo_nd6
*);
989 extern void nd6_prproxy_ns_input(struct ifnet
*, struct in6_addr
*,
990 char *, int, struct in6_addr
*, struct in6_addr
*, uint8_t *nonce
);
991 extern void nd6_prproxy_na_input(struct ifnet
*, struct in6_addr
*,
992 struct in6_addr
*, struct in6_addr
*, int);
993 extern void nd6_prproxy_sols_reap(struct nd_prefix
*);
994 extern void nd6_prproxy_sols_prune(struct nd_prefix
*, u_int32_t
);
995 extern int nd6_if_disable(struct ifnet
*, boolean_t
);
996 void in6_ifaddr_set_dadprogress(struct in6_ifaddr
*ia
);
997 #endif /* BSD_KERNEL_PRIVATE */
1002 * @function nd6_lookup_ipv6
1003 * @discussion This function will check the routing table for a cached
1004 * neighbor discovery entry or trigger an neighbor discovery query
1005 * to resolve the IPv6 address to a link-layer address.
1006 * nd entries are stored in the routing table. This function will
1007 * lookup the IPv6 destination in the routing table. If the
1008 * destination requires forwarding to a gateway, the route of the
1009 * gateway will be looked up. The route entry is inspected to
1010 * determine if the link layer destination address is known. If
1011 * unknown, neighbor discovery will be used to resolve the entry.
1012 * @param interface The interface the packet is being sent on.
1013 * @param ip6_dest The IPv6 destination of the packet.
1014 * @param ll_dest On output, the link-layer destination.
1015 * @param ll_dest_len The length of the buffer for ll_dest.
1016 * @param hint Any routing hint passed down from the protocol.
1017 * @param packet The packet being transmitted.
1018 * @result May return an error such as EHOSTDOWN or ENETUNREACH. If
1019 * this function returns EJUSTRETURN, the packet has been queued
1020 * and will be sent when the address is resolved. If any other
1021 * value is returned, the caller is responsible for disposing of
1024 extern errno_t
nd6_lookup_ipv6(ifnet_t interface
,
1025 const struct sockaddr_in6
*ip6_dest
, struct sockaddr_dl
*ll_dest
,
1026 size_t ll_dest_len
, route_t hint
, mbuf_t packet
);
1031 #ifdef BSD_KERNEL_PRIVATE
1035 * value using CGA tx SEND rx SEND
1036 * -------- --------- ------- -------
1040 extern int nd6_send_opstate
;
1042 #define ND6_SEND_OPMODE_DISABLED 0
1043 #define ND6_SEND_OPMODE_CGA_QUIET 1
1045 #endif /* BSD_KERNEL_PRIVATE */
1046 #endif /* _NETINET6_ND6_H_ */