]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/protosw.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
23 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
25 * Copyright (c) 1982, 1986, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
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.
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
56 * @(#)protosw.h 8.1 (Berkeley) 6/2/93
60 * Protocol switch table.
62 * Each protocol has a handle initializing one of these structures,
63 * which is used for protocol-protocol and system-protocol communication.
65 * A protocol is called through the pr_init entry before any other.
66 * Thereafter it is called every 200ms through the pr_fasttimo entry and
67 * every 500ms through the pr_slowtimo for timer based actions.
68 * The system will call the pr_drain entry if it is low on space and
69 * this should throw away any non-critical data.
71 * Protocols pass data between themselves as chains of mbufs using
72 * the pr_input and pr_output hooks. Pr_input passes data up (towards
73 * UNIX) and pr_output passes it down (towards the imps); control
74 * information passes up and down on pr_ctlinput and pr_ctloutput.
75 * The protocol is responsible for the space occupied by any the
76 * arguments to these entries and must dispose it.
78 * The userreq routine interfaces protocols to the system and is
82 #ifndef _SYS_PROTOSW_H_
83 #define _SYS_PROTOSW_H_
85 #include <sys/socketvar.h>
86 #include <sys/queue.h>
89 short pr_type
; /* socket type used for */
90 struct domain
*pr_domain
; /* domain protocol a member of */
91 short pr_protocol
; /* protocol number */
92 unsigned int pr_flags
; /* see below */
93 /* protocol-protocol hooks */
94 void (*pr_input
) __P((struct mbuf
*, int len
));
95 /* input to protocol (from below) */
96 int (*pr_output
) __P((struct mbuf
*m
, struct socket
*so
));
97 /* output to protocol (from above) */
98 void (*pr_ctlinput
)__P((int, struct sockaddr
*, void *));
99 /* control input (from below) */
100 int (*pr_ctloutput
)__P((struct socket
*, struct sockopt
*));
101 /* control output (from above) */
102 /* user-protocol hook */
105 void (*pr_init
) __P((void)); /* initialization hook */
106 void (*pr_fasttimo
) __P((void));
107 /* fast timeout (200ms) */
108 void (*pr_slowtimo
) __P((void));
109 /* slow timeout (500ms) */
110 void (*pr_drain
) __P((void));
111 /* flush any excess space possible */
113 int (*pr_sysctl
)(); /* sysctl for protocol */
115 struct pr_usrreqs
*pr_usrreqs
; /* supersedes pr_usrreq() */
117 TAILQ_HEAD(pr_sfilter
, NFDescriptor
) pr_sfilter
;
118 struct protosw
*pr_next
; /* Chain for domain */
119 u_long reserved
[4]; /* Padding for future use */
122 #define PR_SLOWHZ 2 /* 2 slow timeouts per second */
123 #define PR_FASTHZ 5 /* 5 fast timeouts per second */
126 * Values for pr_flags.
127 * PR_ADDR requires PR_ATOMIC;
128 * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
130 #define PR_ATOMIC 0x01 /* exchange atomic messages only */
131 #define PR_ADDR 0x02 /* addresses given with messages */
132 #define PR_CONNREQUIRED 0x04 /* connection required by protocol */
133 #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
134 #define PR_RIGHTS 0x10 /* passes capabilities */
135 #define PR_IMPLOPCL 0x20 /* implied open/close */
138 * The arguments to usrreq are:
139 * (*protosw[].pr_usrreq)(up, req, m, nam, opt);
140 * where up is a (struct socket *), req is one of these requests,
141 * m is a optional mbuf chain containing a message,
142 * nam is an optional mbuf chain containing an address,
143 * and opt is a pointer to a socketopt structure or nil.
144 * The protocol is responsible for disposal of the mbuf chain m,
145 * the caller is responsible for any space held by nam and opt.
146 * A non-zero return from usrreq gives an
147 * UNIX error number which should be passed to higher level software.
149 #define PRU_ATTACH 0 /* attach protocol to up */
150 #define PRU_DETACH 1 /* detach protocol from up */
151 #define PRU_BIND 2 /* bind socket to address */
152 #define PRU_LISTEN 3 /* listen for connection */
153 #define PRU_CONNECT 4 /* establish connection to peer */
154 #define PRU_ACCEPT 5 /* accept connection from peer */
155 #define PRU_DISCONNECT 6 /* disconnect from peer */
156 #define PRU_SHUTDOWN 7 /* won't send any more data */
157 #define PRU_RCVD 8 /* have taken data; more room now */
158 #define PRU_SEND 9 /* send this data */
159 #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */
160 #define PRU_CONTROL 11 /* control operations on protocol */
161 #define PRU_SENSE 12 /* return status into m */
162 #define PRU_RCVOOB 13 /* retrieve out of band data */
163 #define PRU_SENDOOB 14 /* send out of band data */
164 #define PRU_SOCKADDR 15 /* fetch socket's address */
165 #define PRU_PEERADDR 16 /* fetch peer's address */
166 #define PRU_CONNECT2 17 /* connect two sockets */
167 /* begin for protocols internal use */
168 #define PRU_FASTTIMO 18 /* 200ms timeout */
169 #define PRU_SLOWTIMO 19 /* 500ms timeout */
170 #define PRU_PROTORCV 20 /* receive from below */
171 #define PRU_PROTOSEND 21 /* send to below */
172 /* end for protocol's internal use */
173 #define PRU_SEND_EOF 22 /* send and close */
177 char *prurequests
[] = {
178 "ATTACH", "DETACH", "BIND", "LISTEN",
179 "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
180 "RCVD", "SEND", "ABORT", "CONTROL",
181 "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
182 "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
183 "PROTORCV", "PROTOSEND",
188 #ifdef KERNEL /* users shouldn't see this decl */
196 * If the ordering here looks odd, that's because it's alphabetical.
197 * Having this structure separated out from the main protoswitch is allegedly
198 * a big (12 cycles per call) lose on high-end CPUs. We will eventually
199 * migrate this stuff back into the main structure.
202 int (*pru_abort
) __P((struct socket
*so
));
203 int (*pru_accept
) __P((struct socket
*so
, struct sockaddr
**nam
));
204 int (*pru_attach
) __P((struct socket
*so
, int proto
,
206 int (*pru_bind
) __P((struct socket
*so
, struct sockaddr
*nam
,
208 int (*pru_connect
) __P((struct socket
*so
, struct sockaddr
*nam
,
210 int (*pru_connect2
) __P((struct socket
*so1
, struct socket
*so2
));
211 int (*pru_control
) __P((struct socket
*so
, u_long cmd
, caddr_t data
,
212 struct ifnet
*ifp
, struct proc
*p
));
213 int (*pru_detach
) __P((struct socket
*so
));
214 int (*pru_disconnect
) __P((struct socket
*so
));
215 int (*pru_listen
) __P((struct socket
*so
, struct proc
*p
));
216 int (*pru_peeraddr
) __P((struct socket
*so
,
217 struct sockaddr
**nam
));
218 int (*pru_rcvd
) __P((struct socket
*so
, int flags
));
219 int (*pru_rcvoob
) __P((struct socket
*so
, struct mbuf
*m
,
221 int (*pru_send
) __P((struct socket
*so
, int flags
, struct mbuf
*m
,
222 struct sockaddr
*addr
, struct mbuf
*control
,
226 #define PRUS_MORETOCOME 0x4
227 int (*pru_sense
) __P((struct socket
*so
, struct stat
*sb
));
228 int (*pru_shutdown
) __P((struct socket
*so
));
229 int (*pru_sockaddr
) __P((struct socket
*so
,
230 struct sockaddr
**nam
));
233 * These three added later, so they are out of order. They are used
234 * for shortcutting (fast path input/output) in some protocols.
235 * XXX - that's a lie, they are not implemented yet
236 * Rather than calling sosend() etc. directly, calls are made
237 * through these entry points. For protocols which still use
238 * the generic code, these just point to those routines.
240 int (*pru_sosend
) __P((struct socket
*so
, struct sockaddr
*addr
,
241 struct uio
*uio
, struct mbuf
*top
,
242 struct mbuf
*control
, int flags
));
243 int (*pru_soreceive
) __P((struct socket
*so
,
244 struct sockaddr
**paddr
,
245 struct uio
*uio
, struct mbuf
**mp0
,
246 struct mbuf
**controlp
, int *flagsp
));
247 int (*pru_sopoll
) __P((struct socket
*so
, int events
,
248 struct ucred
*cred
, void *));
252 extern int pru_abort_notsupp(struct socket
*so
);
253 extern int pru_accept_notsupp(struct socket
*so
, struct sockaddr
**nam
);
254 extern int pru_attach_notsupp(struct socket
*so
, int proto
,
256 extern int pru_bind_notsupp(struct socket
*so
, struct sockaddr
*nam
,
258 extern int pru_connect_notsupp(struct socket
*so
, struct sockaddr
*nam
,
260 extern int pru_connect2_notsupp(struct socket
*so1
, struct socket
*so2
);
261 extern int pru_control_notsupp(struct socket
*so
, u_long cmd
, caddr_t data
,
262 struct ifnet
*ifp
, struct proc
*p
);
263 extern int pru_detach_notsupp(struct socket
*so
);
264 extern int pru_disconnect_notsupp(struct socket
*so
);
265 extern int pru_listen_notsupp(struct socket
*so
, struct proc
*p
);
266 extern int pru_peeraddr_notsupp(struct socket
*so
,
267 struct sockaddr
**nam
);
268 extern int pru_rcvd_notsupp(struct socket
*so
, int flags
);
269 extern int pru_rcvoob_notsupp(struct socket
*so
, struct mbuf
*m
,
271 extern int pru_send_notsupp(struct socket
*so
, int flags
, struct mbuf
*m
,
272 struct sockaddr
*addr
, struct mbuf
*control
,
274 extern int pru_sense_null(struct socket
*so
, struct stat
*sb
);
275 extern int pru_shutdown_notsupp(struct socket
*so
);
276 extern int pru_sockaddr_notsupp(struct socket
*so
,
277 struct sockaddr
**nam
);
278 extern int pru_sosend_notsupp(struct socket
*so
, struct sockaddr
*addr
,
279 struct uio
*uio
, struct mbuf
*top
,
280 struct mbuf
*control
, int flags
);
281 extern int pru_soreceive_notsupp(struct socket
*so
,
282 struct sockaddr
**paddr
,
283 struct uio
*uio
, struct mbuf
**mp0
,
284 struct mbuf
**controlp
, int *flagsp
);
285 extern int pru_sopoll_notsupp(struct socket
*so
, int events
,
292 * The arguments to the ctlinput routine are
293 * (*protosw[].pr_ctlinput)(cmd, sa, arg);
294 * where cmd is one of the commands below, sa is a pointer to a sockaddr,
295 * and arg is a `void *' argument used within a protocol family.
297 #define PRC_IFDOWN 0 /* interface transition */
298 #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
299 #define PRC_IFUP 2 /* interface has come back up */
300 #define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
301 #define PRC_QUENCH 4 /* some one said to slow down */
302 #define PRC_MSGSIZE 5 /* message size forced drop */
303 #define PRC_HOSTDEAD 6 /* host appears to be down */
304 #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
305 #define PRC_UNREACH_NET 8 /* no route to network */
306 #define PRC_UNREACH_HOST 9 /* no route to host */
307 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
308 #define PRC_UNREACH_PORT 11 /* bad port # */
309 /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
310 #define PRC_UNREACH_SRCFAIL 13 /* source route failed */
311 #define PRC_REDIRECT_NET 14 /* net routing redirect */
312 #define PRC_REDIRECT_HOST 15 /* host routing redirect */
313 #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
314 #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
315 #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
316 #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
317 #define PRC_PARAMPROB 20 /* header incorrect */
321 #define PRC_IS_REDIRECT(cmd) \
322 ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
325 char *prcrequests
[] = {
326 "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2",
327 "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
328 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
329 "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
330 "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
336 * The arguments to ctloutput are:
337 * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p);
338 * req is one of the actions listed below, so is a (struct socket *),
339 * level is an indication of which protocol layer the option is intended.
340 * optname is a protocol dependent socket option request,
341 * optval is a pointer to a mbuf-chain pointer, for value-return results.
342 * The protocol is responsible for disposal of the mbuf chain *optval
344 * the caller is responsible for any space held by *optval, when returned.
345 * A non-zero return from usrreq gives an
346 * UNIX error number which should be passed to higher level software.
348 #define PRCO_GETOPT 0
349 #define PRCO_SETOPT 1
354 char *prcorequests
[] = {
360 void pfctlinput
__P((int, struct sockaddr
*));
361 struct protosw
*pffindproto
__P((int family
, int protocol
, int type
));
362 struct protosw
*pffindtype
__P((int family
, int type
));
364 extern int net_add_proto(struct protosw
*, struct domain
*);
365 extern int net_del_proto(int, int, struct domain
*);
367 /* Temp hack to link static domains together */
369 #define LINK_PROTOS(psw) \
370 static void link_ ## psw ## _protos() \
374 for (i=0; i < ((sizeof(psw)/sizeof(psw[0])) - 1); i++) \
375 psw[i].pr_next = &psw[i + 1]; \
379 #endif /* !_SYS_PROTOSW_H_ */