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