2 * Copyright (c) 2000-2012 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 /* $FreeBSD: src/sys/netinet6/nd6.h,v 1.2.2.3 2001/08/13 01:10:49 simokawa Exp $ */
30 /* $KAME: nd6.h,v 1.55 2001/04/27 15:09:49 itojun Exp $ */
33 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the project nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 #ifndef _NETINET6_ND6_H_
62 #define _NETINET6_ND6_H_
63 #include <sys/appleapiopts.h>
65 /* see net/route.h, or net/if_inarp.h */
67 #define RTF_ANNOUNCE RTF_PROTO2
70 #include <sys/queue.h>
72 #ifdef XNU_KERNEL_PRIVATE
73 #include <net/flowadv.h>
74 #include <kern/locks.h>
79 * The following are protected by rnh_lock
81 struct llinfo_nd6
*ln_next
;
82 struct llinfo_nd6
*ln_prev
;
83 struct rtentry
*ln_rt
;
85 * The following are protected by rt_lock
87 struct mbuf
*ln_hold
; /* last packet until resolved/timeout */
88 long ln_asked
; /* number of queries already sent for this addr */
89 u_int32_t ln_expire
; /* lifetime for NDP state transition */
90 short ln_state
; /* reachability state */
91 short ln_router
; /* 2^0: ND6 router bit */
92 int ln_byhint
; /* # of times we made it reachable by UL hint */
93 u_int32_t ln_flags
; /* flags; see below */
94 struct if_llreach
*ln_llreach
; /* link-layer reachability record */
95 u_int64_t ln_lastused
; /* last used timestamp */
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 /* XNU_KERNEL_PRIVATE */
103 #define ND6_LLINFO_PURGE -3
104 #define ND6_LLINFO_NOSTATE -2
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 jinmei@kame.net)
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
119 #ifdef XNU_KERNEL_PRIVATE
120 #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE)
121 #define ND6_LLINFO_PERMANENT(n) (((n)->ln_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE))
123 #define ND6_EUI64_GBIT 0x01
124 #define ND6_EUI64_UBIT 0x02
126 #define ND6_EUI64_TO_IFID(in6) do {(in6)->s6_addr[8] ^= ND6_EUI64_UBIT; } while (0)
127 #define ND6_EUI64_GROUP(in6) ((in6)->s6_addr[8] & ND6_EUI64_GBIT)
128 #define ND6_EUI64_INDIVIDUAL(in6) (!ND6_EUI64_GROUP(in6))
129 #define ND6_EUI64_LOCAL(in6) ((in6)->s6_addr[8] & ND6_EUI64_UBIT)
130 #define ND6_EUI64_UNIVERSAL(in6) (!ND6_EUI64_LOCAL(in6))
131 #define ND6_IFID_LOCAL(in6) (!ND6_EUI64_LOCAL(in6))
132 #define ND6_IFID_UNIVERSAL(in6) (!ND6_EUI64_UNIVERSAL(in6))
133 #endif /* XNU_KERNEL_PRIVATE */
135 #if !defined(XNU_KERNEL_PRIVATE)
138 /* For binary compatibility, this structure must not change */
139 struct nd_ifinfo_compat
{
140 #endif /* !XNU_KERNEL_PRIVATE */
141 u_int32_t linkmtu
; /* LinkMTU */
142 u_int32_t maxmtu
; /* Upper bound of LinkMTU */
143 u_int32_t basereachable
; /* BaseReachableTime */
144 u_int32_t reachable
; /* Reachable Time */
145 u_int32_t retrans
; /* Retrans Timer */
146 u_int32_t flags
; /* Flags */
147 int recalctm
; /* BaseReacable re-calculation timer */
148 u_int8_t chlim
; /* CurHopLimit */
150 /* the following 3 members are for privacy extension for addrconf */
151 u_int8_t randomseed0
[8]; /* upper 64 bits of SHA1 digest */
152 u_int8_t randomseed1
[8]; /* lower 64 bits (usually the EUI64 IFID) */
153 u_int8_t randomid
[8]; /* current random ID */
156 #if defined(XNU_KERNEL_PRIVATE)
158 decl_lck_mtx_data(, lock
);
159 boolean_t initialized
; /* Flag to see the entry is initialized */
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 */
173 /* keep track of routers and prefixes on this link */
177 #endif /* XNU_KERNEL_PRIVATE */
179 #define ND6_IFF_PERFORMNUD 0x1
181 #define ND6_IFF_ACCEPT_RTADV 0x2 /* APPLE: not used. Innterface specific router
182 * advertisments are handled with a specific ifnet
183 * flag: IFEF_ACCEPT_RTADVD
185 #define ND6_IFF_PREFER_SOURCE 0x4 /* APPLE: NOT USED not related to ND. */
186 #define ND6_IFF_IFDISABLED 0x8 /* IPv6 operation is disabled due to
187 * DAD failure. (XXX: not ND-specific)
189 #define ND6_IFF_DONT_SET_IFROUTE 0x10 /* NOT USED */
191 #define ND6_IFF_PROXY_PREFIXES 0x20
192 #define ND6_IFF_IGNORE_NA 0x40
195 char ifname
[IFNAMSIZ
]; /* if name, e.g. "en0" */
196 struct in6_addr addr
; /* IPv6 address of the neighbor */
197 long asked
; /* number of queries already sent for this addr */
198 int isrouter
; /* if it acts as a router */
199 int state
; /* reachability state */
200 int expire
; /* lifetime for NDP state transition */
203 #if defined(XNU_KERNEL_PRIVATE)
204 struct in6_nbrinfo_32
{
205 char ifname
[IFNAMSIZ
];
206 struct in6_addr addr
;
213 struct in6_nbrinfo_64
{
214 char ifname
[IFNAMSIZ
];
215 struct in6_addr addr
;
217 int isrouter
__attribute__((aligned(8)));
220 } __attribute__((aligned(8)));
221 #endif /* XNU_KERNEL_PRIVATE */
227 char ifname
[IFNAMSIZ
];
229 struct in6_addr rtaddr
;
234 } defrouter
[DRLSTSIZ
];
237 #if defined(XNU_KERNEL_PRIVATE)
238 struct in6_drlist_32
{
239 char ifname
[IFNAMSIZ
];
241 struct in6_addr rtaddr
;
246 } defrouter
[DRLSTSIZ
];
249 struct in6_drlist_64
{
250 char ifname
[IFNAMSIZ
];
252 struct in6_addr rtaddr
;
255 u_long expire
__attribute__((aligned(8)));
256 u_short if_index
__attribute__((aligned(8)));
257 } defrouter
[DRLSTSIZ
] __attribute__((aligned(8)));
259 #endif /* XNU_KERNEL_PRIVATE */
261 /* valid values for stateflags */
262 #define NDDRF_INSTALLED 0x1 /* installed in the routing table */
263 #define NDDRF_IFSCOPE 0x2 /* installed as a scoped route */
264 #define NDDRF_STATIC 0x4 /* for internal use only */
265 #ifdef XNU_KERNEL_PRIVATE
266 #define NDDRF_PROCESSED 0x10
269 struct in6_defrouter
{
270 struct sockaddr_in6 rtaddr
;
278 #if defined(XNU_KERNEL_PRIVATE)
279 struct in6_defrouter_32
{
280 struct sockaddr_in6 rtaddr
;
288 struct in6_defrouter_64
{
289 struct sockaddr_in6 rtaddr
;
293 u_long expire
__attribute__((aligned(8)));
294 u_short if_index
__attribute__((aligned(8)));
295 } __attribute__((aligned(8)));
296 #endif /* XNU_KERNEL_PRIVATE */
299 char ifname
[IFNAMSIZ
];
301 struct in6_addr prefix
;
302 struct prf_ra raflags
;
309 u_short advrtrs
; /* number of advertisement routers */
310 struct in6_addr advrtr
[DRLSTSIZ
]; /* XXX: explicit limit */
314 #if defined(XNU_KERNEL_PRIVATE)
315 struct in6_prlist_32
{
316 char ifname
[IFNAMSIZ
];
318 struct in6_addr prefix
;
319 struct prf_ra raflags
;
327 struct in6_addr advrtr
[DRLSTSIZ
];
331 struct in6_prlist_64
{
332 char ifname
[IFNAMSIZ
];
334 struct in6_addr prefix
;
335 struct prf_ra raflags
;
338 u_long vltime
__attribute__((aligned(8)));
339 u_long pltime
__attribute__((aligned(8)));
340 u_long expire
__attribute__((aligned(8)));
344 struct in6_addr advrtr
[DRLSTSIZ
];
347 #endif /* XNU_KERNEL_PRIVATE */
350 struct sockaddr_in6 prefix
;
351 struct prf_ra raflags
;
360 u_short advrtrs
; /* number of advertisement routers */
361 /* struct sockaddr_in6 advrtr[] */
364 #if defined(XNU_KERNEL_PRIVATE)
365 struct in6_prefix_32
{
366 struct sockaddr_in6 prefix
;
367 struct prf_ra raflags
;
376 u_short advrtrs
; /* number of advertisement routers */
377 /* struct sockaddr_in6 advrtr[] */
380 struct in6_prefix_64
{
381 struct sockaddr_in6 prefix
;
382 struct prf_ra raflags
;
385 u_long vltime
__attribute__((aligned(8)));
386 u_long pltime
__attribute__((aligned(8)));
387 u_long expire
__attribute__((aligned(8)));
388 u_int32_t flags
__attribute__((aligned(8)));
392 /* struct sockaddr_in6 advrtr[] */
394 #endif /* XNU_KERNEL_PRIVATE */
397 char ifname
[IFNAMSIZ
];
399 u_int32_t linkmtu
; /* LinkMTU */
400 u_int32_t maxmtu
; /* Upper bound of LinkMTU */
401 u_int32_t basereachable
; /* BaseReachableTime */
402 u_int32_t reachable
; /* Reachable Time */
403 u_int32_t retrans
; /* Retrans Timer */
404 u_int32_t flags
; /* Flags */
405 int recalctm
; /* BaseReacable re-calculation timer */
406 u_int8_t chlim
; /* CurHopLimit */
411 #if !defined(XNU_KERNEL_PRIVATE)
413 char ifname
[IFNAMSIZ
];
414 struct nd_ifinfo ndi
;
418 char ifname
[IFNAMSIZ
];
419 struct nd_ifinfo_compat ndi
;
421 #endif /* !XNU_KERNEL_PRIVATE */
424 char ifname
[IFNAMSIZ
];
428 #define MAX_RTR_SOLICITATION_DELAY 1 /* 1sec */
429 #define RTR_SOLICITATION_INTERVAL 4 /* 4sec */
431 #if defined(XNU_KERNEL_PRIVATE)
432 struct in6_ndifreq_32
{
433 char ifname
[IFNAMSIZ
];
437 struct in6_ndifreq_64
{
438 char ifname
[IFNAMSIZ
];
439 u_long ifindex
__attribute__((aligned(8)));
441 #endif /* XNU_KERNEL_PRIVATE */
444 #define NDPRF_ONLINK 0x1
445 #define NDPRF_DETACHED 0x2
446 #define NDPRF_STATIC 0x100
447 #define NDPRF_IFSCOPE 0x1000
448 #define NDPRF_PRPROXY 0x2000
449 #ifdef XNU_KERNEL_PRIVATE
450 #define NDPRF_PROCESSED 0x08000
453 /* protocol constants */
454 #define MAX_RTR_SOLICITATION_DELAY 1 /*1sec*/
455 #define RTR_SOLICITATION_INTERVAL 4 /*4sec*/
456 #define MAX_RTR_SOLICITATIONS 3
458 #define ND6_INFINITE_LIFETIME 0xffffffff
459 #define ND6_MAX_LIFETIME 0x7fffffff
461 #ifdef XNU_KERNEL_PRIVATE
463 * Protects nd_ifinfo[]
465 __private_extern__ lck_rw_t
*nd_if_rwlock
;
467 #define ND_IFINFO(ifp) \
468 ((ifp)->if_index < nd_ifinfo_indexlim ? &nd_ifinfo[(ifp)->if_index] : NULL)
471 * In a more readable form, we derive linkmtu based on:
473 * if (ND_IFINFO(ifp) == NULL || !ND_IFINFO(ifp)->initialized)
474 * linkmtu = ifp->if_mtu;
475 * else if (ND_IFINFO(ifp)->linkmtu && ND_IFINFO(ifp)->linkmtu < ifp->if_mtu)
476 * linkmtu = ND_IFINFO(ifp)->linkmtu;
477 * else if ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < ifp->if_mtu))
478 * linkmtu = ND_IFINFO(ifp)->maxmtu;
480 * linkmtu = ifp->if_mtu;
482 #define IN6_LINKMTU(ifp) \
483 ((ND_IFINFO(ifp) == NULL || !ND_IFINFO(ifp)->initialized) ? \
484 (ifp)->if_mtu : ((ND_IFINFO(ifp)->linkmtu && \
485 ND_IFINFO(ifp)->linkmtu < (ifp)->if_mtu) ? ND_IFINFO(ifp)->linkmtu : \
486 ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < (ifp)->if_mtu) ? \
487 ND_IFINFO(ifp)->maxmtu : (ifp)->if_mtu)))
490 #define MAX_REACHABLE_TIME 3600000 /* msec */
491 #define REACHABLE_TIME 30000 /* msec */
492 #define RETRANS_TIMER 1000 /* msec */
493 #define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */
494 #define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */
495 #define DEF_TEMP_VALID_LIFETIME 604800 /* 1 week */
496 #define DEF_TEMP_PREFERRED_LIFETIME 86400 /* 1 day */
497 #define TEMPADDR_REGEN_ADVANCE 5 /* sec */
498 #define MAX_TEMP_DESYNC_FACTOR 600 /* 10 min */
499 #define ND_COMPUTE_RTIME(x) \
500 (((MIN_RANDOM_FACTOR * (x >> 10)) + (random() & \
501 ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
503 TAILQ_HEAD(nd_drhead
, nd_defrouter
);
504 struct nd_defrouter
{
505 decl_lck_mtx_data(, nddr_lock
);
506 uint32_t nddr_refcount
;
508 TAILQ_ENTRY(nd_defrouter
) dr_entry
;
509 struct in6_addr rtaddr
;
510 u_char flags
; /* flags on RA message */
517 void (*nddr_trace
) /* callback fn for tracing refs */
518 (struct nd_defrouter
*, int);
521 #define NDDR_LOCK_ASSERT_HELD(_nddr) \
522 lck_mtx_assert(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_OWNED)
524 #define NDDR_LOCK_ASSERT_NOTHELD(_nddr) \
525 lck_mtx_assert(&(_nddr)->nddr_lock, LCK_MTX_ASSERT_NOTOWNED)
527 #define NDDR_LOCK(_nddr) \
528 lck_mtx_lock(&(_nddr)->nddr_lock)
530 #define NDDR_LOCK_SPIN(_nddr) \
531 lck_mtx_lock_spin(&(_nddr)->nddr_lock)
533 #define NDDR_CONVERT_LOCK(_nddr) do { \
534 NDPR_LOCK_ASSERT_HELD(_nddr); \
535 lck_mtx_convert_spin(&(_nddr)->nddr_lock); \
538 #define NDDR_UNLOCK(_nddr) \
539 lck_mtx_unlock(&(_nddr)->nddr_lock)
541 #define NDDR_ADDREF(_nddr) \
542 nddr_addref(_nddr, 0)
544 #define NDDR_ADDREF_LOCKED(_nddr) \
545 nddr_addref(_nddr, 1)
547 #define NDDR_REMREF(_nddr) do { \
548 (void) nddr_remref(_nddr, 0); \
551 #define NDDR_REMREF_LOCKED(_nddr) \
552 nddr_remref(_nddr, 1)
554 /* define struct prproxy_sols_tree */
555 RB_HEAD(prproxy_sols_tree
, nd6_prproxy_soltgt
);
558 decl_lck_mtx_data(, ndpr_lock
);
559 u_int32_t ndpr_refcount
; /* reference count */
560 u_int32_t ndpr_debug
; /* see ifa_debug flags */
561 struct ifnet
*ndpr_ifp
;
562 struct rtentry
*ndpr_rt
;
563 LIST_ENTRY(nd_prefix
) ndpr_entry
;
564 struct sockaddr_in6 ndpr_prefix
; /* prefix */
565 struct in6_addr ndpr_mask
; /* netmask derived from the prefix */
566 struct in6_addr ndpr_addr
; /* address that is derived from the prefix */
567 u_int32_t ndpr_vltime
; /* advertised valid lifetime */
568 u_int32_t ndpr_pltime
; /* advertised preferred lifetime */
569 time_t ndpr_preferred
; /* preferred time of the prefix */
570 time_t ndpr_expire
; /* expiration time of the prefix */
571 time_t ndpr_lastupdate
; /* reception time of last advertisement */
572 struct prf_ra ndpr_flags
;
573 u_int32_t ndpr_stateflags
; /* actual state flags */
574 /* list of routers that advertise the prefix: */
575 LIST_HEAD(pr_rtrhead
, nd_pfxrouter
) ndpr_advrtrs
;
577 int ndpr_addrcnt
; /* reference counter from addresses */
578 u_int32_t ndpr_allmulti_cnt
; /* total all-multi reqs */
579 u_int32_t ndpr_prproxy_sols_cnt
; /* total # of proxied NS */
580 struct prproxy_sols_tree ndpr_prproxy_sols
; /* tree of proxied NS */
581 void (*ndpr_trace
) /* callback fn for tracing refs */
582 (struct nd_prefix
*, int);
585 #define ndpr_next ndpr_entry.le_next
587 #define ndpr_raf ndpr_flags
588 #define ndpr_raf_onlink ndpr_flags.onlink
589 #define ndpr_raf_auto ndpr_flags.autonomous
590 #define ndpr_raf_router ndpr_flags.router
592 * We keep expired prefix for certain amount of time, for validation purposes.
593 * 1800s = MaxRtrAdvInterval
595 #define NDPR_KEEP_EXPIRED (1800 * 2)
597 #define NDPR_LOCK_ASSERT_HELD(_ndpr) \
598 lck_mtx_assert(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_OWNED)
600 #define NDPR_LOCK_ASSERT_NOTHELD(_ndpr) \
601 lck_mtx_assert(&(_ndpr)->ndpr_lock, LCK_MTX_ASSERT_NOTOWNED)
603 #define NDPR_LOCK(_ndpr) \
604 lck_mtx_lock(&(_ndpr)->ndpr_lock)
606 #define NDPR_LOCK_SPIN(_ndpr) \
607 lck_mtx_lock_spin(&(_ndpr)->ndpr_lock)
609 #define NDPR_CONVERT_LOCK(_ndpr) do { \
610 NDPR_LOCK_ASSERT_HELD(_ndpr); \
611 lck_mtx_convert_spin(&(_ndpr)->ndpr_lock); \
614 #define NDPR_UNLOCK(_ndpr) \
615 lck_mtx_unlock(&(_ndpr)->ndpr_lock)
617 #define NDPR_ADDREF(_ndpr) \
618 ndpr_addref(_ndpr, 0)
620 #define NDPR_ADDREF_LOCKED(_ndpr) \
621 ndpr_addref(_ndpr, 1)
623 #define NDPR_REMREF(_ndpr) do { \
624 (void) ndpr_remref(_ndpr, 0); \
627 #define NDPR_REMREF_LOCKED(_ndpr) \
628 ndpr_remref(_ndpr, 1)
631 * Message format for use in obtaining information about prefixes
632 * from inet6 sysctl function
634 struct inet6_ndpr_msghdr
{
635 u_short inpm_msglen
; /* to skip over non-understood messages */
636 u_char inpm_version
; /* future binary compatibility */
637 u_char inpm_type
; /* message type */
638 struct in6_addr inpm_prefix
;
640 u_int32_t prm_pltime
;
641 u_int32_t prm_expire
;
642 u_int32_t prm_preferred
;
643 struct in6_prflags prm_flags
;
644 u_short prm_index
; /* index for associated ifp */
645 u_char prm_plen
; /* length of prefix in bits */
648 #define prm_raf_onlink prm_flags.prf_ra.onlink
649 #define prm_raf_auto prm_flags.prf_ra.autonomous
651 #define prm_statef_onlink prm_flags.prf_state.onlink
653 #define prm_rrf_decrvalid prm_flags.prf_rr.decrvalid
654 #define prm_rrf_decrprefd prm_flags.prf_rr.decrprefd
656 #define ifpr2ndpr(ifpr) ((struct nd_prefix *)(ifpr))
657 #define ndpr2ifpr(ndpr) ((struct ifprefix *)(ndpr))
659 struct nd_pfxrouter
{
660 LIST_ENTRY(nd_pfxrouter
) pfr_entry
;
661 #define pfr_next pfr_entry.le_next
662 struct nd_defrouter
*router
;
665 LIST_HEAD(nd_prhead
, nd_prefix
);
667 struct nd_prefix_list
{
668 struct nd_prefix_list
*next
;
671 #endif /* XNU_KERNEL_PRIVATE */
674 /* ND6 kernel event subclass value */
675 #define KEV_ND6_SUBCLASS 7
676 /* ND6 kernel event action type */
678 /* ND6 RA L2 source address length */
679 #define ND6_ROUTER_LL_SIZE 64
681 struct nd6_ra_prefix
{
682 struct sockaddr_in6 prefix
;
683 struct prf_ra raflags
;
695 /* ND6 router advertisement valid bits */
696 #define KEV_ND6_DATA_VALID_MTU (0x1 << 0)
697 #define KEV_ND6_DATA_VALID_PREFIX (0x1 << 1)
699 struct kev_nd6_ra_data
{
700 u_int8_t lladdr
[ND6_ROUTER_LL_SIZE
];
703 u_int32_t list_index
;
704 u_int32_t list_length
;
706 struct nd6_ra_prefix prefix
;
711 #if defined(XNU_KERNEL_PRIVATE)
713 extern int nd6_prune
;
714 extern int nd6_delay
;
715 extern int nd6_umaxtries
;
716 extern int nd6_mmaxtries
;
717 extern int nd6_useloopback
;
718 extern int nd6_accept_6to4
;
719 extern int nd6_maxnudhint
;
720 extern int nd6_gctimer
;
721 extern struct llinfo_nd6 llinfo_nd6
;
722 extern struct nd_ifinfo
*nd_ifinfo
;
723 extern struct nd_drhead nd_defrouter
;
724 extern struct nd_prhead nd_prefix
;
725 extern int nd6_debug
;
726 extern size_t nd_ifinfo_indexlim
;
727 extern int nd6_onlink_ns_rfc4861
;
728 extern int nd6_optimistic_dad
;
730 #define nd6log(x) do { if (nd6_debug >= 1) log x; } while (0)
731 #define nd6log2(x) do { if (nd6_debug >= 2) log x; } while (0)
733 #define ND6_OPTIMISTIC_DAD_LINKLOCAL (1 << 0)
734 #define ND6_OPTIMISTIC_DAD_AUTOCONF (1 << 1)
735 #define ND6_OPTIMISTIC_DAD_TEMPORARY (1 << 2)
736 #define ND6_OPTIMISTIC_DAD_DYNAMIC (1 << 3)
739 extern int nd6_defifindex
;
740 extern int ip6_desync_factor
; /* seconds */
741 /* ND6_INFINITE_LIFETIME does not apply to temporary addresses */
742 extern u_int32_t ip6_temp_preferred_lifetime
; /* seconds */
743 extern u_int32_t ip6_temp_valid_lifetime
; /* seconds */
744 extern int ip6_temp_regen_advance
; /* seconds */
747 struct nd_opt_hdr
*nd_opt_array
[8]; /* max = target address list */
749 struct nd_opt_hdr
*zero
;
750 struct nd_opt_hdr
*src_lladdr
;
751 struct nd_opt_hdr
*tgt_lladdr
;
752 struct nd_opt_prefix_info
*pi_beg
; /* multiple opts, start */
753 struct nd_opt_rd_hdr
*rh
;
754 struct nd_opt_mtu
*mtu
;
755 struct nd_opt_hdr
*search
; /* multiple opts */
756 struct nd_opt_hdr
*last
; /* multiple opts */
758 struct nd_opt_prefix_info
*pi_end
;/* multiple opts, end */
761 #define nd_opts_src_lladdr nd_opt_each.src_lladdr
762 #define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr
763 #define nd_opts_pi nd_opt_each.pi_beg
764 #define nd_opts_pi_end nd_opt_each.pi_end
765 #define nd_opts_rh nd_opt_each.rh
766 #define nd_opts_mtu nd_opt_each.mtu
767 #define nd_opts_search nd_opt_each.search
768 #define nd_opts_last nd_opt_each.last
769 #define nd_opts_done nd_opt_each.done
771 /* XXX: need nd6_var.h?? */
773 extern void nd6_init(void);
774 extern int nd6_ifattach(struct ifnet
*);
775 extern int nd6_is_addr_neighbor(struct sockaddr_in6
*, struct ifnet
*, int);
776 extern void nd6_option_init(void *, int, union nd_opts
*);
777 extern struct nd_opt_hdr
*nd6_option(union nd_opts
*);
778 extern int nd6_options(union nd_opts
*);
779 extern struct rtentry
*nd6_lookup(struct in6_addr
*, int, struct ifnet
*, int);
780 extern void nd6_setmtu(struct ifnet
*);
781 extern void nd6_timer(void *);
782 extern void nd6_purge(struct ifnet
*);
783 extern void nd6_free(struct rtentry
*);
784 extern void nd6_nud_hint(struct rtentry
*, struct in6_addr
*, int);
785 extern int nd6_resolve(struct ifnet
*, struct rtentry
*,
786 struct mbuf
*, struct sockaddr
*, u_char
*);
787 extern void nd6_rtrequest(int, struct rtentry
*, struct sockaddr
*);
788 extern int nd6_ioctl(u_long
, caddr_t
, struct ifnet
*);
789 extern void nd6_cache_lladdr(struct ifnet
*, struct in6_addr
*,
790 char *, int, int, int);
791 extern int nd6_output(struct ifnet
*, struct ifnet
*, struct mbuf
*,
792 struct sockaddr_in6
*, struct rtentry
*, struct flowadv
*);
793 extern int nd6_storelladdr(struct ifnet
*, struct rtentry
*, struct mbuf
*,
794 struct sockaddr
*, u_char
*);
795 extern int nd6_need_cache(struct ifnet
*);
796 extern void nd6_drain(void *);
797 extern void nd6_post_msg(u_int32_t
, struct nd_prefix_list
*, u_int32_t
, u_int32_t
, char *, u_int32_t
);
798 extern int nd6_setifinfo(struct ifnet
*, u_int32_t
, u_int32_t
);
801 extern void nd6_nbr_init(void);
802 extern void nd6_na_input(struct mbuf
*, int, int);
803 extern void nd6_na_output(struct ifnet
*, const struct in6_addr
*,
804 const struct in6_addr
*, u_int32_t
, int, struct sockaddr
*);
805 extern void nd6_ns_input(struct mbuf
*, int, int);
806 extern void nd6_ns_output(struct ifnet
*, const struct in6_addr
*,
807 const struct in6_addr
*, struct llinfo_nd6
*, int);
808 extern caddr_t
nd6_ifptomac(struct ifnet
*);
809 extern void nd6_dad_start(struct ifaddr
*, int *);
810 extern void nd6_dad_stop(struct ifaddr
*);
811 extern void nd6_dad_duplicated(struct ifaddr
*, boolean_t
);
812 extern void nd6_llreach_alloc(struct rtentry
*, struct ifnet
*, void *,
813 unsigned int, boolean_t
);
814 extern void nd6_llreach_set_reachable(struct ifnet
*, void *, unsigned int);
815 extern void nd6_llreach_use(struct llinfo_nd6
*);
816 extern void nd6_alt_node_addr_decompose(struct ifnet
*, struct sockaddr
*,
817 struct sockaddr_dl
*, struct sockaddr_in6
*);
818 extern void nd6_alt_node_present(struct ifnet
*, struct sockaddr_in6
*,
819 struct sockaddr_dl
*, int32_t, int, int);
820 extern void nd6_alt_node_absent(struct ifnet
*, struct sockaddr_in6
*);
823 extern void nd6_rtr_init(void);
824 extern void nd6_rs_input(struct mbuf
*, int, int);
825 extern void nd6_ra_input(struct mbuf
*, int, int);
826 extern void prelist_del(struct nd_prefix
*);
827 extern void defrouter_select(struct ifnet
*);
828 extern void defrouter_reset(void);
829 extern int defrtrlist_ioctl(u_long
, caddr_t
);
830 extern void defrtrlist_del(struct nd_defrouter
*);
831 extern int defrtrlist_add_static(struct nd_defrouter
*);
832 extern int defrtrlist_del_static(struct nd_defrouter
*);
833 extern void prelist_remove(struct nd_prefix
*);
834 extern int prelist_update(struct nd_prefix
*, struct nd_defrouter
*,
836 extern int nd6_prelist_add(struct nd_prefix
*, struct nd_defrouter
*,
837 struct nd_prefix
**, boolean_t
);
838 extern int nd6_prefix_onlink(struct nd_prefix
*);
839 extern int nd6_prefix_onlink_scoped(struct nd_prefix
*, unsigned int);
840 extern int nd6_prefix_offlink(struct nd_prefix
*);
841 extern void pfxlist_onlink_check(void);
842 extern struct nd_defrouter
*defrouter_lookup(struct in6_addr
*, struct ifnet
*);
843 extern struct nd_prefix
*nd6_prefix_lookup(struct nd_prefix
*);
844 extern int in6_init_prefix_ltimes(struct nd_prefix
*ndpr
);
845 extern void rt6_flush(struct in6_addr
*, struct ifnet
*);
846 extern int nd6_setdefaultiface(int);
847 extern int in6_tmpifadd(const struct in6_ifaddr
*, int, int);
848 extern void nddr_addref(struct nd_defrouter
*, int);
849 extern struct nd_defrouter
*nddr_remref(struct nd_defrouter
*, int);
850 extern void ndpr_addref(struct nd_prefix
*, int);
851 extern struct nd_prefix
*ndpr_remref(struct nd_prefix
*, int);
855 extern u_int32_t nd6_prproxy
;
856 extern void nd6_prproxy_init(void);
857 extern int nd6_if_prproxy(struct ifnet
*, boolean_t
);
858 extern void nd6_prproxy_prelist_update(struct nd_prefix
*, struct nd_prefix
*);
859 extern boolean_t
nd6_prproxy_ifaddr(struct in6_ifaddr
*);
860 extern boolean_t
nd6_prproxy_isours(struct mbuf
*, struct ip6_hdr
*,
861 struct route_in6
*, unsigned int);
862 extern void nd6_prproxy_ns_output(struct ifnet
*, struct in6_addr
*,
863 struct in6_addr
*, struct llinfo_nd6
*);
864 extern void nd6_prproxy_ns_input(struct ifnet
*, struct in6_addr
*,
865 char *, int, struct in6_addr
*, struct in6_addr
*);
866 extern void nd6_prproxy_na_input(struct ifnet
*, struct in6_addr
*,
867 struct in6_addr
*, struct in6_addr
*, int);
868 extern void nd6_prproxy_sols_reap(struct nd_prefix
*);
869 extern void nd6_prproxy_sols_prune(struct nd_prefix
*, u_int32_t
);
870 #endif /* XNU_KERNEL_PRIVATE */
875 @function nd6_lookup_ipv6
876 @discussion This function will check the routing table for a cached
877 neighbor discovery entry or trigger an neighbor discovery query
878 to resolve the IPv6 address to a link-layer address.
880 nd entries are stored in the routing table. This function will
881 lookup the IPv6 destination in the routing table. If the
882 destination requires forwarding to a gateway, the route of the
883 gateway will be looked up. The route entry is inspected to
884 determine if the link layer destination address is known. If
885 unknown, neighbor discovery will be used to resolve the entry.
886 @param interface The interface the packet is being sent on.
887 @param ip6_dest The IPv6 destination of the packet.
888 @param ll_dest On output, the link-layer destination.
889 @param ll_dest_len The length of the buffer for ll_dest.
890 @param hint Any routing hint passed down from the protocol.
891 @param packet The packet being transmitted.
892 @result May return an error such as EHOSTDOWN or ENETUNREACH. If
893 this function returns EJUSTRETURN, the packet has been queued
894 and will be sent when the address is resolved. If any other
895 value is returned, the caller is responsible for disposing of
898 extern errno_t
nd6_lookup_ipv6(ifnet_t interface
,
899 const struct sockaddr_in6
*ip6_dest
, struct sockaddr_dl
*ll_dest
,
900 size_t ll_dest_len
, route_t hint
, mbuf_t packet
);
903 #endif /* _NETINET6_ND6_H_ */