]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39236c6e | 2 | * Copyright (c) 1999-2013 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
39236c6e | 5 | * |
2d21ac55 A |
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. | |
39236c6e | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
39236c6e | 17 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
39236c6e | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b | 27 | */ |
1c79356b | 28 | #ifndef DLIL_H |
39236c6e | 29 | #define DLIL_H |
91447636 | 30 | #ifdef KERNEL |
2d21ac55 | 31 | |
91447636 A |
32 | #include <sys/kernel_types.h> |
33 | #include <net/kpi_interface.h> | |
1c79356b | 34 | |
1c79356b A |
35 | enum { |
36 | BPF_TAP_DISABLE, | |
37 | BPF_TAP_INPUT, | |
38 | BPF_TAP_OUTPUT, | |
39 | BPF_TAP_INPUT_OUTPUT | |
40 | }; | |
41 | ||
7b1edb79 A |
42 | /* |
43 | * DLIL_DESC_ETYPE2 - native_type must point to 2 byte ethernet raw protocol, | |
44 | * variants.native_type_length must be set to 2 | |
45 | * DLIL_DESC_SAP - native_type must point to 3 byte SAP protocol | |
46 | * variants.native_type_length must be set to 3 | |
47 | * DLIL_DESC_SNAP - native_type must point to 5 byte SNAP protocol | |
48 | * variants.native_type_length must be set to 5 | |
49 | * | |
50 | * All protocols must be in Network byte order. | |
51 | * | |
52 | * Future interface families may define more protocol types they know about. | |
53 | * The type implies the offset and context of the protocol data at native_type. | |
54 | * The length of the protocol data specified at native_type must be set in | |
55 | * variants.native_type_length. | |
56 | */ | |
316670eb | 57 | /* Ethernet specific types */ |
39236c6e A |
58 | #define DLIL_DESC_ETYPE2 4 |
59 | #define DLIL_DESC_SAP 5 | |
60 | #define DLIL_DESC_SNAP 6 | |
1c79356b | 61 | |
91447636 | 62 | #ifdef KERNEL_PRIVATE |
2d21ac55 A |
63 | #include <net/if.h> |
64 | #include <net/if_var.h> | |
316670eb A |
65 | #include <net/classq/classq.h> |
66 | #include <net/flowadv.h> | |
2d21ac55 A |
67 | #include <sys/kern_event.h> |
68 | #include <kern/thread.h> | |
69 | #include <kern/locks.h> | |
1c79356b | 70 | |
316670eb A |
71 | #ifdef BSD_KERNEL_PRIVATE |
72 | /* Operations on timespecs. */ | |
73 | #define net_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_nsec = 0 | |
74 | ||
75 | #define net_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) | |
76 | ||
77 | #define net_timercmp(tvp, uvp, cmp) \ | |
78 | (((tvp)->tv_sec == (uvp)->tv_sec) ? \ | |
39236c6e A |
79 | ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ |
80 | ((tvp)->tv_sec cmp (uvp)->tv_sec)) | |
316670eb A |
81 | |
82 | #define net_timeradd(tvp, uvp, vvp) do { \ | |
83 | (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ | |
84 | (vvp)->tv_nsec = (tvp)->tv_nsec + (uvp)->tv_nsec; \ | |
39236c6e | 85 | if ((vvp)->tv_nsec >= (long)NSEC_PER_SEC) { \ |
316670eb A |
86 | (vvp)->tv_sec++; \ |
87 | (vvp)->tv_nsec -= NSEC_PER_SEC; \ | |
88 | } \ | |
89 | } while (0) | |
90 | ||
91 | #define net_timersub(tvp, uvp, vvp) do { \ | |
92 | (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ | |
93 | (vvp)->tv_nsec = (tvp)->tv_nsec - (uvp)->tv_nsec; \ | |
94 | if ((vvp)->tv_nsec < 0) { \ | |
95 | (vvp)->tv_sec--; \ | |
96 | (vvp)->tv_nsec += NSEC_PER_SEC; \ | |
97 | } \ | |
98 | } while (0) | |
99 | ||
100 | #define net_timernsec(tvp, nsp) do { \ | |
101 | *(nsp) = (tvp)->tv_nsec; \ | |
102 | if ((tvp)->tv_sec > 0) \ | |
39236c6e | 103 | *(nsp) += ((tvp)->tv_sec * (integer_t)NSEC_PER_SEC); \ |
316670eb A |
104 | } while (0) |
105 | ||
106 | #define net_nsectimer(nsp, tvp) do { \ | |
107 | u_int64_t __nsp = *(nsp); \ | |
108 | net_timerclear(tvp); \ | |
109 | while ((__nsp) >= NSEC_PER_SEC) { \ | |
110 | (tvp)->tv_sec++; \ | |
111 | (__nsp) -= NSEC_PER_SEC; \ | |
112 | } \ | |
113 | (tvp)->tv_nsec = (__nsp); \ | |
114 | } while (0) | |
1c79356b | 115 | |
2d21ac55 A |
116 | struct ifnet; |
117 | struct mbuf; | |
118 | struct ether_header; | |
119 | struct sockaddr_dl; | |
2d21ac55 | 120 | struct iff_filter; |
91447636 | 121 | |
6d2010ae A |
122 | #define DLIL_THREADNAME_LEN 32 |
123 | ||
316670eb A |
124 | /* |
125 | * DLIL input thread info | |
126 | */ | |
2d21ac55 | 127 | struct dlil_threading_info { |
6d2010ae A |
128 | decl_lck_mtx_data(, input_lck); |
129 | lck_grp_t *lck_grp; /* lock group (for lock stats) */ | |
6d2010ae | 130 | u_int32_t input_waiting; /* DLIL condition of thread */ |
316670eb A |
131 | u_int32_t wtot; /* # of wakeup requests */ |
132 | char input_name[DLIL_THREADNAME_LEN]; /* name storage */ | |
133 | struct ifnet *ifp; /* pointer to interface */ | |
134 | class_queue_t rcvq_pkts; /* queue of pkts */ | |
135 | struct ifnet_stat_increment_param stats; /* incremental statistics */ | |
136 | /* | |
137 | * Thread affinity (workloop and DLIL threads). | |
138 | */ | |
139 | boolean_t net_affinity; /* affinity set is available */ | |
140 | struct thread *input_thr; /* input thread */ | |
141 | struct thread *wloop_thr; /* workloop thread */ | |
142 | struct thread *poll_thr; /* poll thread */ | |
143 | u_int32_t tag; /* affinity tag */ | |
144 | /* | |
145 | * Opportunistic polling. | |
146 | */ | |
147 | ifnet_model_t mode; /* current mode */ | |
148 | struct pktcntr tstats; /* incremental polling statistics */ | |
149 | struct if_rxpoll_stats pstats; /* polling statistics */ | |
150 | #define rxpoll_offreq pstats.ifi_poll_off_req | |
151 | #define rxpoll_offerr pstats.ifi_poll_off_err | |
152 | #define rxpoll_onreq pstats.ifi_poll_on_req | |
153 | #define rxpoll_onerr pstats.ifi_poll_on_err | |
154 | #define rxpoll_wavg pstats.ifi_poll_wakeups_avg | |
155 | #define rxpoll_wlowat pstats.ifi_poll_wakeups_lowat | |
156 | #define rxpoll_whiwat pstats.ifi_poll_wakeups_hiwat | |
157 | #define rxpoll_pavg pstats.ifi_poll_packets_avg | |
158 | #define rxpoll_pmin pstats.ifi_poll_packets_min | |
159 | #define rxpoll_pmax pstats.ifi_poll_packets_max | |
160 | #define rxpoll_plowat pstats.ifi_poll_packets_lowat | |
161 | #define rxpoll_phiwat pstats.ifi_poll_packets_hiwat | |
162 | #define rxpoll_bavg pstats.ifi_poll_bytes_avg | |
163 | #define rxpoll_bmin pstats.ifi_poll_bytes_min | |
164 | #define rxpoll_bmax pstats.ifi_poll_bytes_max | |
165 | #define rxpoll_blowat pstats.ifi_poll_bytes_lowat | |
166 | #define rxpoll_bhiwat pstats.ifi_poll_bytes_hiwat | |
39236c6e A |
167 | #define rxpoll_plim pstats.ifi_poll_packets_limit |
168 | #define rxpoll_ival pstats.ifi_poll_interval_time | |
316670eb A |
169 | struct pktcntr sstats; /* packets and bytes per sampling */ |
170 | struct timespec mode_holdtime; /* mode holdtime in nsec */ | |
171 | struct timespec mode_lasttime; /* last mode change time in nsec */ | |
172 | struct timespec sample_holdtime; /* sampling holdtime in nsec */ | |
173 | struct timespec sample_lasttime; /* last sampling time in nsec */ | |
174 | struct timespec dbg_lasttime; /* last debug message time in nsec */ | |
2d21ac55 | 175 | #if IFNET_INPUT_SANITY_CHK |
316670eb A |
176 | /* |
177 | * For debugging. | |
178 | */ | |
179 | u_int64_t input_mbuf_cnt; /* total # of packets processed */ | |
2d21ac55 A |
180 | #endif |
181 | }; | |
1c79356b | 182 | |
316670eb A |
183 | /* |
184 | * DLIL input thread info (for main/loopback input thread) | |
185 | */ | |
186 | struct dlil_main_threading_info { | |
187 | struct dlil_threading_info inp; | |
188 | class_queue_t lo_rcvq_pkts; /* queue of lo0 pkts */ | |
189 | }; | |
190 | ||
2d21ac55 | 191 | /* |
6d2010ae A |
192 | * The following are shared with kpi_protocol.c so that it may wakeup |
193 | * the input thread to run through packets queued for protocol input. | |
2d21ac55 A |
194 | */ |
195 | #define DLIL_INPUT_RUNNING 0x80000000 | |
196 | #define DLIL_INPUT_WAITING 0x40000000 | |
197 | #define DLIL_PROTO_REGISTER 0x20000000 | |
198 | #define DLIL_PROTO_WAITING 0x10000000 | |
199 | #define DLIL_INPUT_TERMINATE 0x08000000 | |
1c79356b | 200 | |
39236c6e A |
201 | /* |
202 | * Flags for dlil_attach_filter() | |
203 | */ | |
204 | #define DLIL_IFF_TSO 0x01 /* Interface filter supports TSO */ | |
205 | ||
206 | extern int dlil_verbose; | |
207 | extern uint32_t hwcksum_dbg; | |
208 | extern uint32_t hwcksum_tx; | |
209 | extern uint32_t hwcksum_rx; | |
210 | extern struct dlil_threading_info *dlil_main_input_thread; | |
316670eb | 211 | |
6d2010ae | 212 | extern void dlil_init(void); |
1c79356b | 213 | |
316670eb A |
214 | extern errno_t ifp_if_ioctl(struct ifnet *, unsigned long, void *); |
215 | ||
6d2010ae | 216 | extern errno_t dlil_set_bpf_tap(ifnet_t, bpf_tap_mode, bpf_packet_func); |
91447636 A |
217 | |
218 | /* | |
6d2010ae | 219 | * Send arp internal bypasses the check for IPv4LL. |
91447636 | 220 | */ |
6d2010ae A |
221 | extern errno_t dlil_send_arp_internal(ifnet_t, u_int16_t, |
222 | const struct sockaddr_dl *, const struct sockaddr *, | |
223 | const struct sockaddr_dl *, const struct sockaddr *); | |
1c79356b | 224 | |
316670eb | 225 | /* |
39236c6e A |
226 | * The following constants are used with the net_thread_mark_apply and |
227 | * net_thread_is_unmarked functions to control the bits in the uu_network_marks | |
228 | * field of the uthread structure. | |
316670eb A |
229 | */ |
230 | #define NET_THREAD_HELD_PF 0x1 /* thread is holding PF lock */ | |
39236c6e A |
231 | #define NET_THREAD_HELD_DOMAIN 0x2 /* thread is holding domain_proto_mtx */ |
232 | #define NET_THREAD_CKREQ_LLADDR 0x4 /* thread reqs MACF check for LLADDR */ | |
233 | ||
234 | /* | |
235 | * net_thread_marks_t is a pointer to a phantom structure type used for | |
236 | * manipulating the uthread:uu_network_marks field. As an example... | |
237 | * | |
238 | * static const u_int32_t bits = NET_THREAD_CKREQ_LLADDR; | |
239 | * struct uthread *uth = get_bsdthread_info(current_thread()); | |
240 | * | |
241 | * net_thread_marks_t marks = net_thread_marks_push(bits); | |
242 | * VERIFY((uth->uu_network_marks & NET_THREAD_CKREQ_LLADDR) != 0); | |
243 | * net_thread_marks_pop(marks); | |
244 | * | |
245 | * The net_thread_marks_push() function returns an encoding of the bits | |
246 | * that were changed from zero to one in the uu_network_marks field. When | |
247 | * the net_thread_marks_pop() function later processes that value, it | |
248 | * resets the bits to their previous value. | |
249 | * | |
250 | * The net_thread_unmarks_push() and net_thread_unmarks_pop() functions | |
251 | * are similar to net_thread_marks_push() and net_thread_marks_pop() except | |
252 | * they clear the marks bits in the guarded section rather than set them. | |
253 | * | |
254 | * The net_thread_is_marked() and net_thread_is_unmarked() functions return | |
255 | * the subset of the bits that are currently set or cleared (respectively) | |
256 | * in the uthread:uu_network_marks field. | |
257 | * | |
258 | * Finally, the value of the net_thread_marks_none constant is provided for | |
259 | * comparing for equality with the value returned when no bits in the marks | |
260 | * field are changed by the push. | |
261 | * | |
262 | * It is not significant that a value of type net_thread_marks_t may | |
263 | * compare as equal to the NULL pointer. | |
264 | */ | |
265 | struct net_thread_marks; | |
266 | typedef const struct net_thread_marks *net_thread_marks_t; | |
267 | ||
268 | extern const net_thread_marks_t net_thread_marks_none; | |
316670eb | 269 | |
39236c6e A |
270 | extern net_thread_marks_t net_thread_marks_push(u_int32_t); |
271 | extern net_thread_marks_t net_thread_unmarks_push(u_int32_t); | |
272 | extern void net_thread_marks_pop(net_thread_marks_t); | |
273 | extern void net_thread_unmarks_pop(net_thread_marks_t); | |
274 | extern u_int32_t net_thread_is_marked(u_int32_t); | |
275 | extern u_int32_t net_thread_is_unmarked(u_int32_t); | |
316670eb | 276 | |
6d2010ae | 277 | extern int dlil_output(ifnet_t, protocol_family_t, mbuf_t, void *, |
316670eb | 278 | const struct sockaddr *, int, struct flowadv *); |
1c79356b | 279 | |
6d2010ae | 280 | extern void dlil_input_packet_list(struct ifnet *, struct mbuf *); |
316670eb A |
281 | extern void dlil_input_packet_list_extended(struct ifnet *, struct mbuf *, |
282 | u_int32_t, ifnet_model_t); | |
9bccf70c | 283 | |
6d2010ae A |
284 | extern errno_t dlil_resolve_multi(struct ifnet *, |
285 | const struct sockaddr *, struct sockaddr *, size_t); | |
286 | ||
287 | extern errno_t dlil_send_arp(ifnet_t, u_int16_t, const struct sockaddr_dl *, | |
288 | const struct sockaddr *, const struct sockaddr_dl *, | |
316670eb | 289 | const struct sockaddr *, u_int32_t); |
9bccf70c | 290 | |
6d2010ae | 291 | extern int dlil_attach_filter(ifnet_t, const struct iff_filter *, |
39236c6e | 292 | interface_filter_t *, u_int32_t); |
6d2010ae | 293 | extern void dlil_detach_filter(interface_filter_t); |
9bccf70c | 294 | |
6d2010ae A |
295 | extern void dlil_proto_unplumb_all(ifnet_t); |
296 | ||
297 | extern void dlil_post_msg(struct ifnet *, u_int32_t, u_int32_t, | |
298 | struct net_event_data *, u_int32_t); | |
299 | ||
316670eb A |
300 | extern int dlil_alloc_local_stats(struct ifnet *); |
301 | ||
6d2010ae A |
302 | /* |
303 | * dlil_if_acquire is obsolete. Use ifnet_allocate. | |
304 | */ | |
305 | extern int dlil_if_acquire(u_int32_t, const void *, size_t, struct ifnet **); | |
306 | /* | |
2d21ac55 A |
307 | * dlil_if_release is obsolete. The equivalent is called automatically when |
308 | * an interface is detached. | |
309 | */ | |
6d2010ae | 310 | extern void dlil_if_release(struct ifnet *ifp); |
9bccf70c | 311 | |
d1ecb069 | 312 | extern u_int32_t ifnet_aggressive_drainers; |
6d2010ae A |
313 | |
314 | extern errno_t dlil_if_ref(struct ifnet *); | |
315 | extern errno_t dlil_if_free(struct ifnet *); | |
d1ecb069 | 316 | |
316670eb A |
317 | extern void dlil_node_present(struct ifnet *, struct sockaddr *, int32_t, int, |
318 | int, u_int8_t[48]); | |
319 | extern void dlil_node_absent(struct ifnet *, struct sockaddr *); | |
320 | ||
39236c6e A |
321 | extern const void *dlil_ifaddr_bytes(const struct sockaddr_dl *, size_t *, |
322 | kauth_cred_t *); | |
323 | ||
324 | extern void dlil_report_issues(struct ifnet *, u_int8_t[DLIL_MODIDLEN], | |
325 | u_int8_t[DLIL_MODARGLEN]); | |
326 | ||
327 | #define PROTO_HASH_SLOTS 4 | |
328 | ||
329 | extern int proto_hash_value(u_int32_t); | |
330 | ||
331 | extern const char *dlil_kev_dl_code_str(u_int32_t); | |
332 | ||
333 | extern errno_t dlil_rxpoll_set_params(struct ifnet *, | |
334 | struct ifnet_poll_params *, boolean_t); | |
335 | extern errno_t dlil_rxpoll_get_params(struct ifnet *, | |
336 | struct ifnet_poll_params *); | |
337 | ||
316670eb | 338 | #endif /* BSD_KERNEL_PRIVATE */ |
91447636 A |
339 | #endif /* KERNEL_PRIVATE */ |
340 | #endif /* KERNEL */ | |
1c79356b | 341 | #endif /* DLIL_H */ |