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