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