]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/if_llreach.h
xnu-1699.24.8.tar.gz
[apple/xnu.git] / bsd / net / if_llreach.h
1 /*
2 * Copyright (c) 2011 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 #ifndef _NET_IF_LLREACH_H_
30 #define _NET_IF_LLREACH_H_
31
32 #ifdef PRIVATE
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include <sys/types.h>
38
39 /*
40 * Per-interface link-layer reachability information (private).
41 */
42 #define IF_LLREACHINFO_ADDRLEN 64 /* max ll addr len */
43
44 struct if_llreach_info {
45 u_int32_t lri_refcnt; /* reference count */
46 u_int32_t lri_ifindex; /* interface index */
47 u_int64_t lri_expire; /* expiration (calendar) time */
48 u_int32_t lri_probes; /* total # of probes */
49 u_int16_t lri_reserved; /* for future use */
50 u_int16_t lri_proto; /* ll proto */
51 u_int8_t lri_addr[IF_LLREACHINFO_ADDRLEN]; /* ll addr */
52 };
53
54 #ifdef XNU_KERNEL_PRIVATE
55 #include <sys/tree.h>
56 #include <kern/lock.h>
57 #include <net/ethernet.h>
58 #include <netinet/in.h>
59 #if INET6
60 #include <netinet6/in6_var.h>
61 #include <netinet6/nd6.h>
62 #endif /* INET6 */
63
64 /*
65 * Link-layer reachability is based off node constants in RFC4861.
66 */
67 #if INET6
68 #define LL_BASE_REACHABLE REACHABLE_TIME
69 #else
70 #define LL_BASE_REACHABLE 30000 /* msec */
71 #endif /* !INET6 */
72
73 /*
74 * Per-interface link-layer reachability. (Currently only for ARP/Ethernet.)
75 */
76 #define IF_LLREACH_MAXLEN ETHER_ADDR_LEN
77
78 struct if_llreach {
79 decl_lck_mtx_data(, lr_lock);
80 RB_ENTRY(if_llreach) lr_link; /* RB tree links */
81 struct ifnet *lr_ifp; /* back pointer to ifnet */
82 u_int32_t lr_refcnt; /* reference count */
83 u_int32_t lr_reqcnt; /* RB tree request count */
84 u_int32_t lr_debug; /* see ifa_debug flags */
85 u_int32_t lr_probes; /* number of probes so far */
86 u_int64_t lr_basecal; /* base calendar time */
87 u_int64_t lr_baseup; /* base uptime */
88 u_int64_t lr_lastrcvd; /* last-heard-of timestamp */
89 u_int32_t lr_basereachable; /* baseline time */
90 u_int32_t lr_reachable; /* reachable time */
91 struct lr_key_s {
92 u_int16_t proto; /* ll proto */
93 u_int8_t addr[IF_LLREACH_MAXLEN]; /* ll addr */
94 } lr_key;
95 };
96
97 RB_PROTOTYPE_SC_PREV(__private_extern__, ll_reach_tree, if_llreach,
98 ls_link, ifllr_cmp);
99
100 #define IFLR_LOCK_ASSERT_HELD(_iflr) \
101 lck_mtx_assert(&(_iflr)->lr_lock, LCK_MTX_ASSERT_OWNED)
102
103 #define IFLR_LOCK_ASSERT_NOTHELD(_iflr) \
104 lck_mtx_assert(&(_iflr)->lr_lock, LCK_MTX_ASSERT_NOTOWNED)
105
106 #define IFLR_LOCK(_iflr) \
107 lck_mtx_lock(&(_iflr)->lr_lock)
108
109 #define IFLR_LOCK_SPIN(_iflr) \
110 lck_mtx_lock_spin(&(_iflr)->lr_lock)
111
112 #define IFLR_CONVERT_LOCK(_iflr) do { \
113 IFLR_LOCK_ASSERT_HELD(_iflr); \
114 lck_mtx_convert_spin(&(_iflr)->lr_lock); \
115 } while (0)
116
117 #define IFLR_UNLOCK(_iflr) \
118 lck_mtx_unlock(&(_iflr)->lr_lock)
119
120 #define IFLR_ADDREF(_iflr) \
121 iflr_addref(_iflr, 0)
122
123 #define IFLR_ADDREF_LOCKED(_iflr) \
124 iflr_addref(_iflr, 1)
125
126 #define IFLR_REMREF(_iflr) \
127 iflr_remref(_iflr)
128
129 extern void ifnet_llreach_init(void);
130 extern void ifnet_llreach_ifattach(struct ifnet *, boolean_t);
131 extern void ifnet_llreach_ifdetach(struct ifnet *);
132 extern struct if_llreach *ifnet_llreach_alloc(struct ifnet *, u_int16_t, void *,
133 unsigned int, u_int64_t);
134 extern void ifnet_llreach_free(struct if_llreach *);
135 extern int ifnet_llreach_reachable(struct if_llreach *);
136 extern int ifnet_llreach_reachable_delta(struct if_llreach *, u_int64_t);
137 extern void ifnet_llreach_set_reachable(struct ifnet *, u_int16_t, void *,
138 unsigned int);
139 extern u_int64_t ifnet_llreach_up2cal(struct if_llreach *, u_int64_t);
140 extern void ifnet_lr2ri(struct if_llreach *, struct rt_reach_info *);
141 extern void ifnet_lr2lri(struct if_llreach *, struct if_llreach_info *);
142 extern void iflr_addref(struct if_llreach *, int);
143 extern void iflr_remref(struct if_llreach *);
144 #endif /* XNU_KERNEL_PRIVATE */
145
146 #ifdef __cplusplus
147 }
148 #endif
149 #endif /* PRIVATE */
150 #endif /* !_NET_IF_LLREACH_H_ */