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