]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/kext_net.h
60fbe95cea27599778fc64b11e5afb8ec87134ac
[apple/xnu.git] / bsd / net / kext_net.h
1 /*
2 * Copyright (c) 1999-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31 /*
32 * Support for socket filter kernel extensions
33 */
34
35 #ifndef NET_KEXT_NET_H
36 #define NET_KEXT_NET_H
37
38 #include <sys/appleapiopts.h>
39
40 #include <sys/queue.h>
41 #include <sys/cdefs.h>
42
43 #ifdef BSD_KERNEL_PRIVATE
44
45 #include <sys/kpi_socketfilter.h>
46
47 /*
48 * Internal implementation bits
49 */
50
51 struct socket_filter;
52
53 #define SFEF_DETACHUSEZERO 0x1 // Detach when use reaches zero
54 #define SFEF_UNREGISTERING 0x2 // Remove due to unregister
55
56 struct socket_filter_entry {
57 struct socket_filter_entry *sfe_next_onsocket;
58 struct socket_filter_entry *sfe_next_onfilter;
59
60 struct socket_filter *sfe_filter;
61 struct socket *sfe_socket;
62 void *sfe_cookie;
63
64 u_int32_t sfe_flags;
65 };
66
67 #define SFF_DETACHING 0x1
68
69 struct socket_filter {
70 TAILQ_ENTRY(socket_filter) sf_protosw_next;
71 TAILQ_ENTRY(socket_filter) sf_global_next;
72 struct socket_filter_entry *sf_entry_head;
73
74 struct protosw *sf_proto;
75 struct sflt_filter sf_filter;
76 u_int32_t sf_flags;
77 u_int32_t sf_usecount;
78 };
79
80 TAILQ_HEAD(socket_filter_list, socket_filter);
81
82 /* Private, internal implementation functions */
83 void sflt_init(void);
84 void sflt_initsock(struct socket *so);
85 void sflt_termsock(struct socket *so);
86 void sflt_use(struct socket *so);
87 void sflt_unuse(struct socket *so);
88 void sflt_notify(struct socket *so, sflt_event_t event, void *param);
89 int sflt_data_in(struct socket *so, const struct sockaddr *from, mbuf_t *data,
90 mbuf_t *control, sflt_data_flag_t flags, int *filtered);
91 int sflt_attach_private(struct socket *so, struct socket_filter *filter, sflt_handle handle, int locked);
92
93 #endif /* BSD_KERNEL_PRIVATE */
94
95 #define NFF_BEFORE 0x01
96 #define NFF_AFTER 0x02
97
98 #define NKE_OK 0
99 #define NKE_REMOVE -1
100
101 /*
102 * Interface structure for inserting an installed socket NKE into an
103 * existing socket.
104 * 'handle' is the NKE to be inserted, 'where' is an insertion point,
105 * and flags dictate the position of the to-be-inserted NKE relative to
106 * the 'where' NKE. If the latter is NULL, the flags indicate "first"
107 * or "last"
108 */
109 #if __DARWIN_ALIGN_POWER
110 #pragma options align=power
111 #endif
112
113 struct so_nke
114 { unsigned int nke_handle;
115 unsigned int nke_where;
116 int nke_flags; /* NFF_BEFORE, NFF_AFTER: net/kext_net.h */
117 unsigned long reserved[4]; /* for future use */
118 };
119
120 #if __DARWIN_ALIGN_POWER
121 #pragma options align=reset
122 #endif
123
124 #endif /* NET_KEXT_NET_H */
125