]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/dlil.h
xnu-1504.9.37.tar.gz
[apple/xnu.git] / bsd / net / dlil.h
1 /*
2 * Copyright (c) 2009 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) 1999 Apple Computer, Inc.
30 *
31 * Data Link Inteface Layer
32 * Author: Ted Walker
33 */
34 #ifndef DLIL_H
35 #define DLIL_H
36 #ifdef KERNEL
37
38 #include <sys/kernel_types.h>
39 #include <net/kpi_interface.h>
40
41 enum {
42 BPF_TAP_DISABLE,
43 BPF_TAP_INPUT,
44 BPF_TAP_OUTPUT,
45 BPF_TAP_INPUT_OUTPUT
46 };
47
48 /* Ethernet specific types */
49 #define DLIL_DESC_ETYPE2 4
50 #define DLIL_DESC_SAP 5
51 #define DLIL_DESC_SNAP 6
52 /*
53 * DLIL_DESC_ETYPE2 - native_type must point to 2 byte ethernet raw protocol,
54 * variants.native_type_length must be set to 2
55 * DLIL_DESC_SAP - native_type must point to 3 byte SAP protocol
56 * variants.native_type_length must be set to 3
57 * DLIL_DESC_SNAP - native_type must point to 5 byte SNAP protocol
58 * variants.native_type_length must be set to 5
59 *
60 * All protocols must be in Network byte order.
61 *
62 * Future interface families may define more protocol types they know about.
63 * The type implies the offset and context of the protocol data at native_type.
64 * The length of the protocol data specified at native_type must be set in
65 * variants.native_type_length.
66 */
67
68 #ifdef KERNEL_PRIVATE
69
70 #include <net/if.h>
71 #include <net/if_var.h>
72 #include <sys/kern_event.h>
73 #include <kern/thread.h>
74 #include <kern/locks.h>
75
76 #if __STDC__
77
78 struct ifnet;
79 struct mbuf;
80 struct ether_header;
81 struct sockaddr_dl;
82
83 #endif
84
85 #ifdef BSD_KERNEL_PRIVATE
86 struct ifnet_stat_increment_param;
87 struct iff_filter;
88
89 struct dlil_threading_info {
90 mbuf_t mbuf_head; /* start of mbuf list from if */
91 mbuf_t mbuf_tail;
92 u_int32_t mbuf_count;
93 boolean_t net_affinity; /* affinity set is available */
94 u_int32_t input_waiting; /* DLIL condition of thread */
95 struct thread *input_thread; /* thread data for this input */
96 struct thread *workloop_thread; /* current workloop thread */
97 u_int32_t tag; /* current affinity tag */
98 lck_mtx_t *input_lck;
99 lck_grp_t *lck_grp; /* lock group (for lock stats) */
100 char input_name[32];
101 #if IFNET_INPUT_SANITY_CHK
102 u_int32_t input_wake_cnt; /* number of times the thread was awaken with packets to process */
103 u_long input_mbuf_cnt; /* total number of mbuf packets processed by this thread */
104 #endif
105 };
106
107 /*
108 The following are shared with kpi_protocol.c so that it may wakeup
109 the input thread to run through packets queued for protocol input.
110 */
111 #define DLIL_INPUT_RUNNING 0x80000000
112 #define DLIL_INPUT_WAITING 0x40000000
113 #define DLIL_PROTO_REGISTER 0x20000000
114 #define DLIL_PROTO_WAITING 0x10000000
115 #define DLIL_INPUT_TERMINATE 0x08000000
116
117 void dlil_init(void);
118
119 errno_t dlil_set_bpf_tap(ifnet_t ifp, bpf_tap_mode mode,
120 bpf_packet_func callback);
121
122 /*
123 * Send arp internal bypasses the check for
124 * IPv4LL.
125 */
126 errno_t
127 dlil_send_arp_internal(
128 ifnet_t ifp,
129 u_int16_t arpop,
130 const struct sockaddr_dl* sender_hw,
131 const struct sockaddr* sender_proto,
132 const struct sockaddr_dl* target_hw,
133 const struct sockaddr* target_proto);
134
135 int
136 dlil_output(
137 ifnet_t ifp,
138 protocol_family_t proto_family,
139 mbuf_t packetlist,
140 void *route,
141 const struct sockaddr *dest,
142 int raw);
143
144 errno_t
145 dlil_resolve_multi(
146 struct ifnet *ifp,
147 const struct sockaddr *proto_addr,
148 struct sockaddr *ll_addr,
149 size_t ll_len);
150
151 errno_t
152 dlil_send_arp(
153 ifnet_t ifp,
154 u_int16_t arpop,
155 const struct sockaddr_dl* sender_hw,
156 const struct sockaddr* sender_proto,
157 const struct sockaddr_dl* target_hw,
158 const struct sockaddr* target_proto);
159
160 int dlil_attach_filter(ifnet_t ifp, const struct iff_filter *if_filter,
161 interface_filter_t *filter_ref);
162 void dlil_detach_filter(interface_filter_t filter);
163 int dlil_detach_protocol(ifnet_t ifp, u_int32_t protocol);
164 extern void dlil_proto_unplumb_all(ifnet_t);
165
166 #endif /* BSD_KERNEL_PRIVATE */
167
168 void
169 dlil_post_msg(struct ifnet *ifp,u_int32_t event_subclass, u_int32_t event_code,
170 struct net_event_data *event_data, u_int32_t event_data_len);
171
172 /*
173 * dlil_if_acquire is obsolete. Use ifnet_allocate.
174 */
175
176 int dlil_if_acquire(u_int32_t family, const void *uniqueid, size_t uniqueid_len,
177 struct ifnet **ifp);
178
179
180 /*
181 * dlil_if_release is obsolete. The equivalent is called automatically when
182 * an interface is detached.
183 */
184
185 void dlil_if_release(struct ifnet *ifp);
186
187 #if IFNET_ROUTE_REFCNT
188 extern u_int32_t ifnet_aggressive_drainers;
189 #endif /* IFNET_ROUTE_REFCNT */
190
191 #endif /* KERNEL_PRIVATE */
192 #endif /* KERNEL */
193 #endif /* DLIL_H */