]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/protosw.h
xnu-344.23.tar.gz
[apple/xnu.git] / bsd / sys / protosw.h
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) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
23 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 /*
25 * Copyright (c) 1982, 1986, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 *
56 * @(#)protosw.h 8.1 (Berkeley) 6/2/93
57 * $FreeBSD: src/sys/sys/protosw.h,v 1.28.2.2 2001/07/03 11:02:01 ume Exp $
58 */
59
60 #ifndef _SYS_PROTOSW_H_
61 #define _SYS_PROTOSW_H_
62
63 /* Forward declare these structures referenced from prototypes below. */
64 struct mbuf;
65 struct proc;
66 struct sockaddr;
67 struct socket;
68 struct sockopt;
69
70 /*#ifdef _KERNEL*/
71 /*
72 * Protocol switch table.
73 *
74 * Each protocol has a handle initializing one of these structures,
75 * which is used for protocol-protocol and system-protocol communication.
76 *
77 * A protocol is called through the pr_init entry before any other.
78 * Thereafter it is called every 200ms through the pr_fasttimo entry and
79 * every 500ms through the pr_slowtimo for timer based actions.
80 * The system will call the pr_drain entry if it is low on space and
81 * this should throw away any non-critical data.
82 *
83 * Protocols pass data between themselves as chains of mbufs using
84 * the pr_input and pr_output hooks. Pr_input passes data up (towards
85 * the users) and pr_output passes it down (towards the interfaces); control
86 * information passes up and down on pr_ctlinput and pr_ctloutput.
87 * The protocol is responsible for the space occupied by any the
88 * arguments to these entries and must dispose it.
89 *
90 * The userreq routine interfaces protocols to the system and is
91 * described below.
92 */
93
94 #include <sys/appleapiopts.h>
95 #include <sys/socketvar.h>
96 #include <sys/queue.h>
97
98 #ifdef __APPLE_API_UNSTABLE
99 struct protosw {
100 short pr_type; /* socket type used for */
101 struct domain *pr_domain; /* domain protocol a member of */
102 short pr_protocol; /* protocol number */
103 unsigned int pr_flags; /* see below */
104 /* protocol-protocol hooks */
105 void (*pr_input) __P((struct mbuf *, int len));
106 /* input to protocol (from below) */
107 int (*pr_output) __P((struct mbuf *m, struct socket *so));
108 /* output to protocol (from above) */
109 void (*pr_ctlinput)__P((int, struct sockaddr *, void *));
110 /* control input (from below) */
111 int (*pr_ctloutput)__P((struct socket *, struct sockopt *));
112 /* control output (from above) */
113 /* user-protocol hook */
114 void *pr_ousrreq;
115 /* utility hooks */
116 void (*pr_init) __P((void)); /* initialization hook */
117 void (*pr_fasttimo) __P((void));
118 /* fast timeout (200ms) */
119 void (*pr_slowtimo) __P((void));
120 /* slow timeout (500ms) */
121 void (*pr_drain) __P((void));
122 /* flush any excess space possible */
123 #if __APPLE__
124 int (*pr_sysctl)(); /* sysctl for protocol */
125 #endif
126 struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */
127 #if __APPLE__
128 /* Implant hooks */
129 TAILQ_HEAD(pr_sfilter, NFDescriptor) pr_sfilter;
130 struct protosw *pr_next; /* Chain for domain */
131 u_long reserved[4]; /* Padding for future use */
132 #endif
133 };
134
135 #define PR_SLOWHZ 2 /* 2 slow timeouts per second */
136 #define PR_FASTHZ 5 /* 5 fast timeouts per second */
137
138 /*
139 * Values for pr_flags.
140 * PR_ADDR requires PR_ATOMIC;
141 * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
142 * PR_IMPLOPCL means that the protocol allows sendto without prior connect,
143 * and the protocol understands the MSG_EOF flag. The first property is
144 * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed
145 * anyhow).
146 */
147 #define PR_ATOMIC 0x01 /* exchange atomic messages only */
148 #define PR_ADDR 0x02 /* addresses given with messages */
149 #define PR_CONNREQUIRED 0x04 /* connection required by protocol */
150 #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
151 #define PR_RIGHTS 0x10 /* passes capabilities */
152 #define PR_IMPLOPCL 0x20 /* implied open/close */
153 #define PR_LASTHDR 0x40 /* enforce ipsec policy; last header */
154
155 /*
156 * The arguments to usrreq are:
157 * (*protosw[].pr_usrreq)(up, req, m, nam, opt);
158 * where up is a (struct socket *), req is one of these requests,
159 * m is a optional mbuf chain containing a message,
160 * nam is an optional mbuf chain containing an address,
161 * and opt is a pointer to a socketopt structure or nil.
162 * The protocol is responsible for disposal of the mbuf chain m,
163 * the caller is responsible for any space held by nam and opt.
164 * A non-zero return from usrreq gives an
165 * UNIX error number which should be passed to higher level software.
166 */
167 #define PRU_ATTACH 0 /* attach protocol to up */
168 #define PRU_DETACH 1 /* detach protocol from up */
169 #define PRU_BIND 2 /* bind socket to address */
170 #define PRU_LISTEN 3 /* listen for connection */
171 #define PRU_CONNECT 4 /* establish connection to peer */
172 #define PRU_ACCEPT 5 /* accept connection from peer */
173 #define PRU_DISCONNECT 6 /* disconnect from peer */
174 #define PRU_SHUTDOWN 7 /* won't send any more data */
175 #define PRU_RCVD 8 /* have taken data; more room now */
176 #define PRU_SEND 9 /* send this data */
177 #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */
178 #define PRU_CONTROL 11 /* control operations on protocol */
179 #define PRU_SENSE 12 /* return status into m */
180 #define PRU_RCVOOB 13 /* retrieve out of band data */
181 #define PRU_SENDOOB 14 /* send out of band data */
182 #define PRU_SOCKADDR 15 /* fetch socket's address */
183 #define PRU_PEERADDR 16 /* fetch peer's address */
184 #define PRU_CONNECT2 17 /* connect two sockets */
185 /* begin for protocols internal use */
186 #define PRU_FASTTIMO 18 /* 200ms timeout */
187 #define PRU_SLOWTIMO 19 /* 500ms timeout */
188 #define PRU_PROTORCV 20 /* receive from below */
189 #define PRU_PROTOSEND 21 /* send to below */
190 /* end for protocol's internal use */
191 #define PRU_SEND_EOF 22 /* send and close */
192 #define PRU_NREQ 22
193
194 #ifdef PRUREQUESTS
195 char *prurequests[] = {
196 "ATTACH", "DETACH", "BIND", "LISTEN",
197 "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
198 "RCVD", "SEND", "ABORT", "CONTROL",
199 "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
200 "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
201 "PROTORCV", "PROTOSEND",
202 "SEND_EOF",
203 };
204 #endif
205
206 #ifdef KERNEL /* users shouldn't see this decl */
207
208 struct ifnet;
209 struct stat;
210 struct ucred;
211 struct uio;
212
213 /*
214 * If the ordering here looks odd, that's because it's alphabetical.
215 * Having this structure separated out from the main protoswitch is allegedly
216 * a big (12 cycles per call) lose on high-end CPUs. We will eventually
217 * migrate this stuff back into the main structure.
218 */
219 struct pr_usrreqs {
220 int (*pru_abort) __P((struct socket *so));
221 int (*pru_accept) __P((struct socket *so, struct sockaddr **nam));
222 int (*pru_attach) __P((struct socket *so, int proto,
223 struct proc *p));
224 int (*pru_bind) __P((struct socket *so, struct sockaddr *nam,
225 struct proc *p));
226 int (*pru_connect) __P((struct socket *so, struct sockaddr *nam,
227 struct proc *p));
228 int (*pru_connect2) __P((struct socket *so1, struct socket *so2));
229 int (*pru_control) __P((struct socket *so, u_long cmd, caddr_t data,
230 struct ifnet *ifp, struct proc *p));
231 int (*pru_detach) __P((struct socket *so));
232 int (*pru_disconnect) __P((struct socket *so));
233 int (*pru_listen) __P((struct socket *so, struct proc *p));
234 int (*pru_peeraddr) __P((struct socket *so,
235 struct sockaddr **nam));
236 int (*pru_rcvd) __P((struct socket *so, int flags));
237 int (*pru_rcvoob) __P((struct socket *so, struct mbuf *m,
238 int flags));
239 int (*pru_send) __P((struct socket *so, int flags, struct mbuf *m,
240 struct sockaddr *addr, struct mbuf *control,
241 struct proc *p));
242 #define PRUS_OOB 0x1
243 #define PRUS_EOF 0x2
244 #define PRUS_MORETOCOME 0x4
245 int (*pru_sense) __P((struct socket *so, struct stat *sb));
246 int (*pru_shutdown) __P((struct socket *so));
247 int (*pru_sockaddr) __P((struct socket *so,
248 struct sockaddr **nam));
249
250 /*
251 * These three added later, so they are out of order. They are used
252 * for shortcutting (fast path input/output) in some protocols.
253 * XXX - that's a lie, they are not implemented yet
254 * Rather than calling sosend() etc. directly, calls are made
255 * through these entry points. For protocols which still use
256 * the generic code, these just point to those routines.
257 */
258 int (*pru_sosend) __P((struct socket *so, struct sockaddr *addr,
259 struct uio *uio, struct mbuf *top,
260 struct mbuf *control, int flags));
261 int (*pru_soreceive) __P((struct socket *so,
262 struct sockaddr **paddr,
263 struct uio *uio, struct mbuf **mp0,
264 struct mbuf **controlp, int *flagsp));
265 int (*pru_sopoll) __P((struct socket *so, int events,
266 struct ucred *cred, void *));
267 };
268
269 extern int pru_abort_notsupp(struct socket *so);
270 extern int pru_accept_notsupp(struct socket *so, struct sockaddr **nam);
271 extern int pru_attach_notsupp(struct socket *so, int proto,
272 struct proc *p);
273 extern int pru_bind_notsupp(struct socket *so, struct sockaddr *nam,
274 struct proc *p);
275 extern int pru_connect_notsupp(struct socket *so, struct sockaddr *nam,
276 struct proc *p);
277 extern int pru_connect2_notsupp(struct socket *so1, struct socket *so2);
278 extern int pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
279 struct ifnet *ifp, struct proc *p);
280 extern int pru_detach_notsupp(struct socket *so);
281 extern int pru_disconnect_notsupp(struct socket *so);
282 extern int pru_listen_notsupp(struct socket *so, struct proc *p);
283 extern int pru_peeraddr_notsupp(struct socket *so,
284 struct sockaddr **nam);
285 extern int pru_rcvd_notsupp(struct socket *so, int flags);
286 extern int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m,
287 int flags);
288 extern int pru_send_notsupp(struct socket *so, int flags, struct mbuf *m,
289 struct sockaddr *addr, struct mbuf *control,
290 struct proc *p);
291 extern int pru_sense_null(struct socket *so, struct stat *sb);
292 extern int pru_shutdown_notsupp(struct socket *so);
293 extern int pru_sockaddr_notsupp(struct socket *so,
294 struct sockaddr **nam);
295 extern int pru_sosend_notsupp(struct socket *so, struct sockaddr *addr,
296 struct uio *uio, struct mbuf *top,
297 struct mbuf *control, int flags);
298 extern int pru_soreceive_notsupp(struct socket *so,
299 struct sockaddr **paddr,
300 struct uio *uio, struct mbuf **mp0,
301 struct mbuf **controlp, int *flagsp);
302 extern int pru_sopoll_notsupp(struct socket *so, int events,
303 struct ucred *cred);
304
305
306 #endif /* KERNEL */
307
308 /*
309 * The arguments to the ctlinput routine are
310 * (*protosw[].pr_ctlinput)(cmd, sa, arg);
311 * where cmd is one of the commands below, sa is a pointer to a sockaddr,
312 * and arg is a `void *' argument used within a protocol family.
313 */
314 #define PRC_IFDOWN 0 /* interface transition */
315 #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
316 #define PRC_IFUP 2 /* interface has come back up */
317 #define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
318 #define PRC_QUENCH 4 /* some one said to slow down */
319 #define PRC_MSGSIZE 5 /* message size forced drop */
320 #define PRC_HOSTDEAD 6 /* host appears to be down */
321 #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
322 #define PRC_UNREACH_NET 8 /* no route to network */
323 #define PRC_UNREACH_HOST 9 /* no route to host */
324 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
325 #define PRC_UNREACH_PORT 11 /* bad port # */
326 /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
327 #define PRC_UNREACH_SRCFAIL 13 /* source route failed */
328 #define PRC_REDIRECT_NET 14 /* net routing redirect */
329 #define PRC_REDIRECT_HOST 15 /* host routing redirect */
330 #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
331 #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
332 #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
333 #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
334 #define PRC_PARAMPROB 20 /* header incorrect */
335 #define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */
336
337 #define PRC_NCMDS 22
338
339 #define PRC_IS_REDIRECT(cmd) \
340 ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
341
342 #ifdef PRCREQUESTS
343 char *prcrequests[] = {
344 "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2",
345 "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
346 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
347 "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
348 "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
349 "PARAMPROB", "ADMIN-UNREACH"
350 };
351 #endif
352
353 /*
354 * The arguments to ctloutput are:
355 * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p);
356 * req is one of the actions listed below, so is a (struct socket *),
357 * level is an indication of which protocol layer the option is intended.
358 * optname is a protocol dependent socket option request,
359 * optval is a pointer to a mbuf-chain pointer, for value-return results.
360 * The protocol is responsible for disposal of the mbuf chain *optval
361 * if supplied,
362 * the caller is responsible for any space held by *optval, when returned.
363 * A non-zero return from usrreq gives an
364 * UNIX error number which should be passed to higher level software.
365 */
366 #define PRCO_GETOPT 0
367 #define PRCO_SETOPT 1
368
369 #define PRCO_NCMDS 2
370
371 #ifdef PRCOREQUESTS
372 char *prcorequests[] = {
373 "GETOPT", "SETOPT",
374 };
375 #endif
376
377 #ifdef KERNEL
378 void pfctlinput __P((int, struct sockaddr *));
379 void pfctlinput2 __P((int, struct sockaddr *, void *));
380 struct protosw *pffindproto __P((int family, int protocol, int type));
381 struct protosw *pffindtype __P((int family, int type));
382
383 extern int net_add_proto(struct protosw *, struct domain *);
384 extern int net_del_proto(int, int, struct domain *);
385
386 /* Temp hack to link static domains together */
387
388 #define LINK_PROTOS(psw) \
389 static void link_ ## psw ## _protos() \
390 { \
391 int i; \
392 \
393 for (i=0; i < ((sizeof(psw)/sizeof(psw[0])) - 1); i++) \
394 psw[i].pr_next = &psw[i + 1]; \
395 }
396
397 #endif
398 #endif /* __APPLE_API_UNSTABLE */
399 #endif /* !_SYS_PROTOSW_H_ */