]>
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) 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 | */ | |
58 | ||
59 | /* | |
60 | * Protocol switch table. | |
61 | * | |
62 | * Each protocol has a handle initializing one of these structures, | |
63 | * which is used for protocol-protocol and system-protocol communication. | |
64 | * | |
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. | |
70 | * | |
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. | |
77 | * | |
78 | * The userreq routine interfaces protocols to the system and is | |
79 | * described below. | |
80 | */ | |
81 | ||
82 | #ifndef _SYS_PROTOSW_H_ | |
83 | #define _SYS_PROTOSW_H_ | |
84 | ||
85 | #include <sys/socketvar.h> | |
86 | #include <sys/queue.h> | |
87 | ||
88 | struct protosw { | |
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 */ | |
103 | void *pr_ousrreq; | |
104 | /* utility hooks */ | |
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 */ | |
112 | ||
113 | int (*pr_sysctl)(); /* sysctl for protocol */ | |
114 | ||
115 | struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */ | |
116 | /* Implant hooks */ | |
117 | TAILQ_HEAD(pr_sfilter, NFDescriptor) pr_sfilter; | |
118 | struct protosw *pr_next; /* Chain for domain */ | |
119 | }; | |
120 | ||
121 | #define PR_SLOWHZ 2 /* 2 slow timeouts per second */ | |
122 | #define PR_FASTHZ 5 /* 5 fast timeouts per second */ | |
123 | ||
124 | /* | |
125 | * Values for pr_flags. | |
126 | * PR_ADDR requires PR_ATOMIC; | |
127 | * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. | |
128 | */ | |
129 | #define PR_ATOMIC 0x01 /* exchange atomic messages only */ | |
130 | #define PR_ADDR 0x02 /* addresses given with messages */ | |
131 | #define PR_CONNREQUIRED 0x04 /* connection required by protocol */ | |
132 | #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ | |
133 | #define PR_RIGHTS 0x10 /* passes capabilities */ | |
134 | #define PR_IMPLOPCL 0x20 /* implied open/close */ | |
135 | ||
136 | /* | |
137 | * The arguments to usrreq are: | |
138 | * (*protosw[].pr_usrreq)(up, req, m, nam, opt); | |
139 | * where up is a (struct socket *), req is one of these requests, | |
140 | * m is a optional mbuf chain containing a message, | |
141 | * nam is an optional mbuf chain containing an address, | |
142 | * and opt is a pointer to a socketopt structure or nil. | |
143 | * The protocol is responsible for disposal of the mbuf chain m, | |
144 | * the caller is responsible for any space held by nam and opt. | |
145 | * A non-zero return from usrreq gives an | |
146 | * UNIX error number which should be passed to higher level software. | |
147 | */ | |
148 | #define PRU_ATTACH 0 /* attach protocol to up */ | |
149 | #define PRU_DETACH 1 /* detach protocol from up */ | |
150 | #define PRU_BIND 2 /* bind socket to address */ | |
151 | #define PRU_LISTEN 3 /* listen for connection */ | |
152 | #define PRU_CONNECT 4 /* establish connection to peer */ | |
153 | #define PRU_ACCEPT 5 /* accept connection from peer */ | |
154 | #define PRU_DISCONNECT 6 /* disconnect from peer */ | |
155 | #define PRU_SHUTDOWN 7 /* won't send any more data */ | |
156 | #define PRU_RCVD 8 /* have taken data; more room now */ | |
157 | #define PRU_SEND 9 /* send this data */ | |
158 | #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ | |
159 | #define PRU_CONTROL 11 /* control operations on protocol */ | |
160 | #define PRU_SENSE 12 /* return status into m */ | |
161 | #define PRU_RCVOOB 13 /* retrieve out of band data */ | |
162 | #define PRU_SENDOOB 14 /* send out of band data */ | |
163 | #define PRU_SOCKADDR 15 /* fetch socket's address */ | |
164 | #define PRU_PEERADDR 16 /* fetch peer's address */ | |
165 | #define PRU_CONNECT2 17 /* connect two sockets */ | |
166 | /* begin for protocols internal use */ | |
167 | #define PRU_FASTTIMO 18 /* 200ms timeout */ | |
168 | #define PRU_SLOWTIMO 19 /* 500ms timeout */ | |
169 | #define PRU_PROTORCV 20 /* receive from below */ | |
170 | #define PRU_PROTOSEND 21 /* send to below */ | |
171 | /* end for protocol's internal use */ | |
172 | #define PRU_SEND_EOF 22 /* send and close */ | |
173 | #define PRU_NREQ 22 | |
174 | ||
175 | #ifdef PRUREQUESTS | |
176 | char *prurequests[] = { | |
177 | "ATTACH", "DETACH", "BIND", "LISTEN", | |
178 | "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", | |
179 | "RCVD", "SEND", "ABORT", "CONTROL", | |
180 | "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", | |
181 | "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", | |
182 | "PROTORCV", "PROTOSEND", | |
183 | "SEND_EOF", | |
184 | }; | |
185 | #endif | |
186 | ||
187 | #ifdef KERNEL /* users shouldn't see this decl */ | |
188 | ||
189 | struct ifnet; | |
190 | struct stat; | |
191 | struct ucred; | |
192 | struct uio; | |
193 | ||
194 | /* | |
195 | * If the ordering here looks odd, that's because it's alphabetical. | |
196 | * Having this structure separated out from the main protoswitch is allegedly | |
197 | * a big (12 cycles per call) lose on high-end CPUs. We will eventually | |
198 | * migrate this stuff back into the main structure. | |
199 | */ | |
200 | struct pr_usrreqs { | |
201 | int (*pru_abort) __P((struct socket *so)); | |
202 | int (*pru_accept) __P((struct socket *so, struct sockaddr **nam)); | |
203 | int (*pru_attach) __P((struct socket *so, int proto, | |
204 | struct proc *p)); | |
205 | int (*pru_bind) __P((struct socket *so, struct sockaddr *nam, | |
206 | struct proc *p)); | |
207 | int (*pru_connect) __P((struct socket *so, struct sockaddr *nam, | |
208 | struct proc *p)); | |
209 | int (*pru_connect2) __P((struct socket *so1, struct socket *so2)); | |
210 | int (*pru_control) __P((struct socket *so, u_long cmd, caddr_t data, | |
211 | struct ifnet *ifp, struct proc *p)); | |
212 | int (*pru_detach) __P((struct socket *so)); | |
213 | int (*pru_disconnect) __P((struct socket *so)); | |
214 | int (*pru_listen) __P((struct socket *so, struct proc *p)); | |
215 | int (*pru_peeraddr) __P((struct socket *so, | |
216 | struct sockaddr **nam)); | |
217 | int (*pru_rcvd) __P((struct socket *so, int flags)); | |
218 | int (*pru_rcvoob) __P((struct socket *so, struct mbuf *m, | |
219 | int flags)); | |
220 | int (*pru_send) __P((struct socket *so, int flags, struct mbuf *m, | |
221 | struct sockaddr *addr, struct mbuf *control, | |
222 | struct proc *p)); | |
223 | #define PRUS_OOB 0x1 | |
224 | #define PRUS_EOF 0x2 | |
225 | #define PRUS_MORETOCOME 0x4 | |
226 | int (*pru_sense) __P((struct socket *so, struct stat *sb)); | |
227 | int (*pru_shutdown) __P((struct socket *so)); | |
228 | int (*pru_sockaddr) __P((struct socket *so, | |
229 | struct sockaddr **nam)); | |
230 | ||
231 | /* | |
232 | * These three added later, so they are out of order. They are used | |
233 | * for shortcutting (fast path input/output) in some protocols. | |
234 | * XXX - that's a lie, they are not implemented yet | |
235 | * Rather than calling sosend() etc. directly, calls are made | |
236 | * through these entry points. For protocols which still use | |
237 | * the generic code, these just point to those routines. | |
238 | */ | |
239 | int (*pru_sosend) __P((struct socket *so, struct sockaddr *addr, | |
240 | struct uio *uio, struct mbuf *top, | |
241 | struct mbuf *control, int flags)); | |
242 | int (*pru_soreceive) __P((struct socket *so, | |
243 | struct sockaddr **paddr, | |
244 | struct uio *uio, struct mbuf **mp0, | |
245 | struct mbuf **controlp, int *flagsp)); | |
246 | int (*pru_sopoll) __P((struct socket *so, int events, | |
247 | struct ucred *cred)); | |
248 | }; | |
249 | ||
250 | ||
251 | extern int pru_abort_notsupp(struct socket *so); | |
252 | extern int pru_accept_notsupp(struct socket *so, struct sockaddr **nam); | |
253 | extern int pru_attach_notsupp(struct socket *so, int proto, | |
254 | struct proc *p); | |
255 | extern int pru_bind_notsupp(struct socket *so, struct sockaddr *nam, | |
256 | struct proc *p); | |
257 | extern int pru_connect_notsupp(struct socket *so, struct sockaddr *nam, | |
258 | struct proc *p); | |
259 | extern int pru_connect2_notsupp(struct socket *so1, struct socket *so2); | |
260 | extern int pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data, | |
261 | struct ifnet *ifp, struct proc *p); | |
262 | extern int pru_detach_notsupp(struct socket *so); | |
263 | extern int pru_disconnect_notsupp(struct socket *so); | |
264 | extern int pru_listen_notsupp(struct socket *so, struct proc *p); | |
265 | extern int pru_peeraddr_notsupp(struct socket *so, | |
266 | struct sockaddr **nam); | |
267 | extern int pru_rcvd_notsupp(struct socket *so, int flags); | |
268 | extern int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, | |
269 | int flags); | |
270 | extern int pru_send_notsupp(struct socket *so, int flags, struct mbuf *m, | |
271 | struct sockaddr *addr, struct mbuf *control, | |
272 | struct proc *p); | |
273 | extern int pru_sense_null(struct socket *so, struct stat *sb); | |
274 | extern int pru_shutdown_notsupp(struct socket *so); | |
275 | extern int pru_sockaddr_notsupp(struct socket *so, | |
276 | struct sockaddr **nam); | |
277 | extern int pru_sosend_notsupp(struct socket *so, struct sockaddr *addr, | |
278 | struct uio *uio, struct mbuf *top, | |
279 | struct mbuf *control, int flags); | |
280 | extern int pru_soreceive_notsupp(struct socket *so, | |
281 | struct sockaddr **paddr, | |
282 | struct uio *uio, struct mbuf **mp0, | |
283 | struct mbuf **controlp, int *flagsp); | |
284 | extern int pru_sopoll_notsupp(struct socket *so, int events, | |
285 | struct ucred *cred); | |
286 | ||
287 | ||
288 | #endif /* KERNEL */ | |
289 | ||
290 | /* | |
291 | * The arguments to the ctlinput routine are | |
292 | * (*protosw[].pr_ctlinput)(cmd, sa, arg); | |
293 | * where cmd is one of the commands below, sa is a pointer to a sockaddr, | |
294 | * and arg is a `void *' argument used within a protocol family. | |
295 | */ | |
296 | #define PRC_IFDOWN 0 /* interface transition */ | |
297 | #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ | |
298 | #define PRC_IFUP 2 /* interface has come back up */ | |
299 | #define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ | |
300 | #define PRC_QUENCH 4 /* some one said to slow down */ | |
301 | #define PRC_MSGSIZE 5 /* message size forced drop */ | |
302 | #define PRC_HOSTDEAD 6 /* host appears to be down */ | |
303 | #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ | |
304 | #define PRC_UNREACH_NET 8 /* no route to network */ | |
305 | #define PRC_UNREACH_HOST 9 /* no route to host */ | |
306 | #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ | |
307 | #define PRC_UNREACH_PORT 11 /* bad port # */ | |
308 | /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ | |
309 | #define PRC_UNREACH_SRCFAIL 13 /* source route failed */ | |
310 | #define PRC_REDIRECT_NET 14 /* net routing redirect */ | |
311 | #define PRC_REDIRECT_HOST 15 /* host routing redirect */ | |
312 | #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ | |
313 | #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ | |
314 | #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ | |
315 | #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ | |
316 | #define PRC_PARAMPROB 20 /* header incorrect */ | |
317 | ||
318 | #define PRC_NCMDS 21 | |
319 | ||
320 | #define PRC_IS_REDIRECT(cmd) \ | |
321 | ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) | |
322 | ||
323 | #ifdef PRCREQUESTS | |
324 | char *prcrequests[] = { | |
325 | "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2", | |
326 | "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", | |
327 | "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", | |
328 | "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", | |
329 | "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", | |
330 | "PARAMPROB" | |
331 | }; | |
332 | #endif | |
333 | ||
334 | /* | |
335 | * The arguments to ctloutput are: | |
336 | * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p); | |
337 | * req is one of the actions listed below, so is a (struct socket *), | |
338 | * level is an indication of which protocol layer the option is intended. | |
339 | * optname is a protocol dependent socket option request, | |
340 | * optval is a pointer to a mbuf-chain pointer, for value-return results. | |
341 | * The protocol is responsible for disposal of the mbuf chain *optval | |
342 | * if supplied, | |
343 | * the caller is responsible for any space held by *optval, when returned. | |
344 | * A non-zero return from usrreq gives an | |
345 | * UNIX error number which should be passed to higher level software. | |
346 | */ | |
347 | #define PRCO_GETOPT 0 | |
348 | #define PRCO_SETOPT 1 | |
349 | ||
350 | #define PRCO_NCMDS 2 | |
351 | ||
352 | #ifdef PRCOREQUESTS | |
353 | char *prcorequests[] = { | |
354 | "GETOPT", "SETOPT", | |
355 | }; | |
356 | #endif | |
357 | ||
358 | #ifdef KERNEL | |
359 | void pfctlinput __P((int, struct sockaddr *)); | |
360 | struct protosw *pffindproto __P((int family, int protocol, int type)); | |
361 | struct protosw *pffindtype __P((int family, int type)); | |
362 | ||
363 | extern int net_add_proto(struct protosw *, struct domain *); | |
364 | extern int net_del_proto(int, int, struct domain *); | |
365 | ||
366 | /* Temp hack to link static domains together */ | |
367 | ||
368 | #define LINK_PROTOS(psw) \ | |
369 | static void link_ ## psw ## _protos() \ | |
370 | { \ | |
371 | int i; \ | |
372 | \ | |
373 | for (i=0; i < ((sizeof(psw)/sizeof(psw[0])) - 1); i++) \ | |
374 | psw[i].pr_next = &psw[i + 1]; \ | |
375 | } | |
376 | ||
377 | #endif | |
378 | #endif /* !_SYS_PROTOSW_H_ */ |