]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* Copyright (C) 1999 Apple Computer, Inc. */ | |
23 | /* | |
24 | * Support for network filter kernel extensions | |
25 | * Justin C. Walker, 990319 | |
26 | */ | |
27 | #ifndef NET_KEXT_NET_H | |
28 | #define NET_KEXT_NET_H | |
29 | ||
30 | #include <sys/queue.h> | |
31 | #include <sys/socketvar.h> | |
32 | ||
33 | struct mbuf; | |
34 | struct socket; | |
35 | struct uio; | |
36 | struct sockbuf; | |
37 | struct sockaddr; | |
38 | struct kextcb; | |
39 | struct protosw; | |
40 | struct sockif; | |
41 | struct sockutil; | |
42 | struct sockopt; | |
43 | ||
44 | /* | |
45 | * This structure gives access to the functionality of the filter. | |
46 | * The kextcb provides the link from the socket structure. | |
47 | */ | |
48 | struct NFDescriptor | |
49 | { TAILQ_ENTRY(NFDescriptor) nf_next; /* protosw chain */ | |
50 | TAILQ_ENTRY(NFDescriptor) nf_list; /* descriptor list */ | |
51 | unsigned int nf_handle; /* Identifier */ | |
52 | int nf_flags; | |
53 | /* Dispatch for PF_FILTER control */ | |
54 | int (*nf_connect)(); /* Make contact */ | |
55 | void (*nf_disconnect)(); /* Break contact */ | |
56 | int (*nf_read)(); /* Get data from filter */ | |
57 | int (*nf_write)(); /* Send data to filter */ | |
58 | int (*nf_get)(); /* Get filter config */ | |
59 | int (*nf_set)(); /* Set filter config */ | |
60 | /* | |
61 | * Socket function dispatch vectors - copied to kextcb | |
62 | * during socreate() | |
63 | */ | |
64 | struct sockif *nf_soif; /* Socket functions */ | |
65 | struct sockutil *nf_soutil; /* Sockbuf utility functions */ | |
66 | }; | |
67 | ||
68 | #define NFD_GLOBAL 0x01 | |
69 | #define NFD_PROG 0x02 | |
70 | #define NFD_VISIBLE 0x80000000 | |
71 | ||
72 | #define NFF_BEFORE 0x01 | |
73 | #define NFF_AFTER 0x02 | |
74 | ||
75 | #ifdef KERNEL | |
76 | /* How to register: filter, insert location, target protosw, flags */ | |
77 | extern int register_sockfilter(struct NFDescriptor *, | |
78 | struct NFDescriptor *, | |
79 | struct protosw *, int); | |
80 | /* How to unregister: filter, original protosw, flags */ | |
81 | extern int unregister_sockfilter(struct NFDescriptor *, struct protosw *, int); | |
82 | ||
83 | TAILQ_HEAD(nf_list, NFDescriptor); | |
84 | ||
85 | extern struct nf_list nf_list; | |
86 | #endif | |
87 | ||
88 | #define NKE_OK 0 | |
89 | #define NKE_REMOVE -1 | |
90 | ||
91 | /* | |
92 | * Interface structure for inserting an installed socket NKE into an | |
93 | * existing socket. | |
94 | * 'handle' is the NKE to be inserted, 'where' is an insertion point, | |
95 | * and flags dictate the position of the to-be-inserted NKE relative to | |
96 | * the 'where' NKE. If the latter is NULL, the flags indicate "first" | |
97 | * or "last" | |
98 | */ | |
99 | struct so_nke | |
100 | { unsigned int nke_handle; | |
101 | unsigned int nke_where; | |
102 | int nke_flags; /* NFF_BEFORE, NFF_AFTER: net/kext_net.h */ | |
103 | }; | |
104 | ||
105 | /* | |
106 | * sockif: | |
107 | * Contains socket interface: | |
108 | * dispatch vector abstracting the interface between protocols and | |
109 | * the socket layer. | |
110 | * TODO: add sf_sosense() | |
111 | */ | |
112 | struct sockif | |
113 | { int (*sf_soabort)(struct socket *, struct kextcb *); | |
114 | int (*sf_soaccept)(struct socket *, struct sockaddr **, | |
115 | struct kextcb *); | |
116 | int (*sf_sobind)(struct socket *, struct sockaddr *, struct kextcb *); | |
117 | int (*sf_soclose)(struct socket *, struct kextcb *); | |
118 | int (*sf_soconnect)(struct socket *, struct sockaddr *, | |
119 | struct kextcb *); | |
120 | int (*sf_soconnect2)(struct socket *, struct socket *, | |
121 | struct kextcb *); | |
122 | int (*sf_socontrol)(struct socket *, struct sockopt *, | |
123 | struct kextcb *); | |
124 | int (*sf_socreate)(struct socket *, struct protosw *, struct kextcb *); | |
125 | int (*sf_sodisconnect)(struct socket *, struct kextcb *); | |
126 | int (*sf_sofree)(struct socket *, struct kextcb *); | |
127 | int (*sf_sogetopt)(struct socket *, int, int, struct mbuf **, | |
128 | struct kextcb *); | |
129 | int (*sf_sohasoutofband)(struct socket *, struct kextcb *); | |
130 | int (*sf_solisten)(struct socket *, struct kextcb *); | |
131 | int (*sf_soreceive)(struct socket *, struct sockaddr **, struct uio **, | |
132 | struct mbuf **, struct mbuf **, int *, | |
133 | struct kextcb *); | |
134 | int (*sf_sorflush)(struct socket *, struct kextcb *); | |
135 | int (*sf_sosend)(struct socket *, struct sockaddr **, struct uio **, | |
136 | struct mbuf **, struct mbuf **, int *, | |
137 | struct kextcb *); | |
138 | int (*sf_sosetopt)(struct socket *, int, int, struct mbuf *, | |
139 | struct kextcb *); | |
140 | int (*sf_soshutdown)(struct socket *, int, struct kextcb *); | |
141 | /* Calls sorwakeup() */ | |
142 | int (*sf_socantrcvmore)(struct socket *, struct kextcb *); | |
143 | /* Calls sowwakeup() */ | |
144 | int (*sf_socantsendmore)(struct socket *, struct kextcb *); | |
145 | /* Calls soqinsque(), sorwakeup(), sowwakeup() */ | |
146 | int (*sf_soisconnected)(struct socket *, struct kextcb *); | |
147 | int (*sf_soisconnecting)(struct socket *, struct kextcb *); | |
148 | /* Calls sowwakeup(), sorwakeup() */ | |
149 | int (*sf_soisdisconnected)(struct socket *, struct kextcb *); | |
150 | /* Calls sowwakeup(), sorwakeup() */ | |
151 | int (*sf_soisdisconnecting)(struct socket *, struct kextcb *); | |
152 | /* Calls soreserve(), soqinsque(), soqremque(), sorwakeup() */ | |
153 | struct socket *(*sf_sonewconn1)(struct socket *, int, struct kextcb *); | |
154 | int (*sf_soqinsque)(struct socket *, struct socket *, int, | |
155 | struct kextcb *); | |
156 | int (*sf_soqremque)(struct socket *, int, struct kextcb *); | |
157 | int (*sf_soreserve)(struct socket *, u_long, u_long, struct kextcb *); | |
158 | int (*sf_sowakeup)(struct socket *, struct sockbuf *, | |
159 | struct kextcb *); | |
160 | }; | |
161 | ||
162 | ||
163 | /* | |
164 | * sockutil: | |
165 | * Contains the utility functions for socket layer access | |
166 | */ | |
167 | struct sockutil | |
168 | { /* Sleeps if locked */ | |
169 | int (*su_sb_lock)(struct sockbuf *, struct kextcb *); | |
170 | /* Conditionally calls sbappendrecord, Calls sbcompress */ | |
171 | int (*su_sbappend)(struct sockbuf *, struct mbuf *, struct kextcb *); | |
172 | /* Calls sbspace(), sballoc() */ | |
173 | int (*su_sbappendaddr)(struct sockbuf *, struct sockaddr *, | |
174 | struct mbuf *, struct mbuf *, struct kextcb *); | |
175 | /* Calls sbspace(), sballoc() */ | |
176 | int (*su_sbappendcontrol)(struct sockbuf *, struct mbuf *, | |
177 | struct mbuf *, struct kextcb *); | |
178 | /* Calls sballoc(), sbcompress() */ | |
179 | int (*su_sbappendrecord)(struct sockbuf *, struct mbuf *, | |
180 | struct kextcb *); | |
181 | /* Calls sballoc() */ | |
182 | int (*su_sbcompress)(struct sockbuf *, struct mbuf *, struct mbuf *, | |
183 | struct kextcb *); | |
184 | /* Calls sbfree() */ | |
185 | int (*su_sbdrop)(struct sockbuf *, int, struct kextcb *); | |
186 | /* Calls sbfree() */ | |
187 | int (*su_sbdroprecord)(struct sockbuf *, struct kextcb *); | |
188 | /* Calls sbdrop() */ | |
189 | int (*su_sbflush)(struct sockbuf *, struct kextcb *); | |
190 | /* Calls sballoc(), sbcompress() */ | |
191 | int (*su_sbinsertoob)(struct sockbuf *, struct mbuf *, | |
192 | struct kextcb *); | |
193 | /* Calls sbflush() */ | |
194 | int (*su_sbrelease)(struct sockbuf *, struct kextcb *); | |
195 | int (*su_sbreserve)(struct sockbuf *, u_long, struct kextcb *); | |
196 | /* Calls tsleep() */ | |
197 | int (*su_sbwait)(struct sockbuf *, struct kextcb *); | |
198 | }; | |
199 | ||
200 | #endif |