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