FreeBSD/Linux Kernel Cross Reference
sys/sys/protosw.h
1 /* $OpenBSD: protosw.h,v 1.59 2022/11/26 17:52:35 mvs Exp $ */
2 /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */
3
4 /*-
5 * Copyright (c) 1982, 1986, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)protosw.h 8.1 (Berkeley) 6/2/93
33 */
34
35 /*
36 * Protocol switch table.
37 *
38 * Each protocol has a handle initializing one of these structures,
39 * which is used for protocol-protocol and system-protocol communication.
40 *
41 * A protocol is called through the pr_init entry before any other.
42 * Thereafter it is called every 200ms through the pr_fasttimo entry and
43 * every 500ms through the pr_slowtimo for timer based actions.
44 *
45 * Protocols pass data between themselves as chains of mbufs using
46 * the pr_input and pr_send hooks. Pr_input passes data up (towards
47 * UNIX) and pr_send passes it down (towards the imps); control
48 * information passes up and down on pr_ctlinput and pr_ctloutput.
49 * The protocol is responsible for the space occupied by any the
50 * arguments to these entries and must dispose it.
51 *
52 * The userreq routine interfaces protocols to the system and is
53 * described below.
54 */
55
56 #ifndef _SYS_PROTOSW_H_
57 #define _SYS_PROTOSW_H_
58
59 struct mbuf;
60 struct sockaddr;
61 struct socket;
62 struct domain;
63 struct proc;
64 struct stat;
65 struct ifnet;
66
67 struct pr_usrreqs {
68 int (*pru_attach)(struct socket *, int, int);
69 int (*pru_detach)(struct socket *);
70 void (*pru_lock)(struct socket *);
71 void (*pru_unlock)(struct socket *);
72 int (*pru_bind)(struct socket *, struct mbuf *, struct proc *);
73 int (*pru_listen)(struct socket *);
74 int (*pru_connect)(struct socket *, struct mbuf *);
75 int (*pru_accept)(struct socket *, struct mbuf *);
76 int (*pru_disconnect)(struct socket *);
77 int (*pru_shutdown)(struct socket *);
78 void (*pru_rcvd)(struct socket *);
79 int (*pru_send)(struct socket *, struct mbuf *, struct mbuf *,
80 struct mbuf *);
81 void (*pru_abort)(struct socket *);
82 int (*pru_control)(struct socket *, u_long, caddr_t,
83 struct ifnet *);
84 int (*pru_sense)(struct socket *, struct stat *);
85 int (*pru_rcvoob)(struct socket *, struct mbuf *, int);
86 int (*pru_sendoob)(struct socket *, struct mbuf *, struct mbuf *,
87 struct mbuf *);
88 int (*pru_sockaddr)(struct socket *, struct mbuf *);
89 int (*pru_peeraddr)(struct socket *, struct mbuf *);
90 int (*pru_connect2)(struct socket *, struct socket *);
91 };
92
93 struct protosw {
94 short pr_type; /* socket type used for */
95 const struct domain *pr_domain; /* domain protocol a member of */
96 short pr_protocol; /* protocol number */
97 short pr_flags; /* see below */
98
99 /* protocol-protocol hooks */
100 /* input to protocol (from below) */
101 int (*pr_input)(struct mbuf **, int *, int, int);
102 /* control input (from below) */
103 void (*pr_ctlinput)(int, struct sockaddr *, u_int, void *);
104 /* control output (from above) */
105 int (*pr_ctloutput)(int, struct socket *, int, int, struct mbuf *);
106
107 /* user-protocol hooks */
108 const struct pr_usrreqs *pr_usrreqs;
109
110 /* utility hooks */
111 void (*pr_init)(void); /* initialization hook */
112 void (*pr_fasttimo)(void); /* fast timeout (200ms) */
113 void (*pr_slowtimo)(void); /* slow timeout (500ms) */
114 /* sysctl for protocol */
115 int (*pr_sysctl)(int *, u_int, void *, size_t *, void *, size_t);
116 };
117
118 #define PR_SLOWHZ 2 /* 2 slow timeouts per second */
119 #define PR_FASTHZ 5 /* 5 fast timeouts per second */
120
121 /*
122 * Values for pr_flags.
123 * PR_ADDR requires PR_ATOMIC;
124 * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
125 */
126 #define PR_ATOMIC 0x01 /* exchange atomic messages only */
127 #define PR_ADDR 0x02 /* addresses given with messages */
128 #define PR_CONNREQUIRED 0x04 /* connection required by protocol */
129 #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
130 #define PR_RIGHTS 0x10 /* passes capabilities */
131 #define PR_ABRTACPTDIS 0x20 /* abort on accept(2) to disconnected
132 socket */
133 #define PR_SPLICE 0x40 /* socket splicing is possible */
134
135 /*
136 * The arguments to usrreq are:
137 * (*protosw[].pr_usrreq)(up, req, m, nam, opt);
138 * where up is a (struct socket *), req is one of these requests,
139 * m is a optional mbuf chain containing a message,
140 * nam is an optional mbuf chain containing an address,
141 * and opt is a pointer to a socketopt structure or nil.
142 * The protocol is responsible for disposal of the mbuf chain m,
143 * the caller is responsible for any space held by nam and opt.
144 * A non-zero return from usrreq gives an
145 * UNIX error number which should be passed to higher level software.
146 */
147 #define PRU_ATTACH 0 /* attach protocol to up */
148 #define PRU_DETACH 1 /* detach protocol from up */
149 #define PRU_BIND 2 /* bind socket to address */
150 #define PRU_LISTEN 3 /* listen for connection */
151 #define PRU_CONNECT 4 /* establish connection to peer */
152 #define PRU_ACCEPT 5 /* accept connection from peer */
153 #define PRU_DISCONNECT 6 /* disconnect from peer */
154 #define PRU_SHUTDOWN 7 /* won't send any more data */
155 #define PRU_RCVD 8 /* have taken data; more room now */
156 #define PRU_SEND 9 /* send this data */
157 #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETACH) */
158 #define PRU_CONTROL 11 /* control operations on protocol */
159 #define PRU_SENSE 12 /* return status into m */
160 #define PRU_RCVOOB 13 /* retrieve out of band data */
161 #define PRU_SENDOOB 14 /* send out of band data */
162 #define PRU_SOCKADDR 15 /* fetch socket's address */
163 #define PRU_PEERADDR 16 /* fetch peer's address */
164 #define PRU_CONNECT2 17 /* connect two sockets */
165 /* begin for protocols internal use */
166 #define PRU_FASTTIMO 18 /* 200ms timeout */
167 #define PRU_SLOWTIMO 19 /* 500ms timeout */
168 #define PRU_PROTORCV 20 /* receive from below */
169 #define PRU_PROTOSEND 21 /* send to below */
170
171 #define PRU_NREQ 22
172
173 #ifdef PRUREQUESTS
174 const char *prurequests[] = {
175 "ATTACH", "DETACH", "BIND", "LISTEN",
176 "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
177 "RCVD", "SEND", "ABORT", "CONTROL",
178 "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
179 "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
180 "PROTORCV", "PROTOSEND",
181 };
182 #endif
183
184 /*
185 * The arguments to the ctlinput routine are
186 * (*protosw[].pr_ctlinput)(cmd, sa, arg);
187 * where cmd is one of the commands below, sa is a pointer to a sockaddr,
188 * and arg is an optional caddr_t argument used within a protocol family.
189 */
190 #define PRC_IFDOWN 0 /* interface transition */
191 #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
192 #define PRC_MTUINC 2 /* increase in mtu to host */
193 #define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
194 #define PRC_QUENCH 4 /* some one said to slow down */
195 #define PRC_MSGSIZE 5 /* message size forced drop */
196 #define PRC_HOSTDEAD 6 /* host appears to be down */
197 #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
198 #define PRC_UNREACH_NET 8 /* no route to network */
199 #define PRC_UNREACH_HOST 9 /* no route to host */
200 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
201 #define PRC_UNREACH_PORT 11 /* bad port # */
202 /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
203 #define PRC_UNREACH_SRCFAIL 13 /* source route failed */
204 #define PRC_REDIRECT_NET 14 /* net routing redirect */
205 #define PRC_REDIRECT_HOST 15 /* host routing redirect */
206 #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
207 #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
208 #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
209 #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
210 #define PRC_PARAMPROB 20 /* header incorrect */
211
212 #define PRC_NCMDS 21
213
214 #define PRC_IS_REDIRECT(cmd) \
215 ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
216
217 #ifdef PRCREQUESTS
218 char *prcrequests[] = {
219 "IFDOWN", "ROUTEDEAD", "MTUINC", "DEC-BIT-QUENCH2",
220 "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
221 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
222 "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
223 "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
224 "PARAMPROB"
225 };
226 #endif
227
228 /*
229 * The arguments to ctloutput are:
230 * (*protosw[].pr_ctloutput)(req, so, level, optname, optval);
231 * req is one of the actions listed below, so is a (struct socket *),
232 * level is an indication of which protocol layer the option is intended.
233 * optname is a protocol dependent socket option request,
234 * optval is a pointer to a mbuf-chain pointer, for value-return results.
235 * The protocol is responsible for disposal of the mbuf chain *optval
236 * if supplied,
237 * the caller is responsible for any space held by *optval, when returned.
238 * A non-zero return from usrreq gives an
239 * UNIX error number which should be passed to higher level software.
240 */
241 #define PRCO_GETOPT 0
242 #define PRCO_SETOPT 1
243
244 #define PRCO_NCMDS 2
245
246 #ifdef PRCOREQUESTS
247 char *prcorequests[] = {
248 "GETOPT", "SETOPT",
249 };
250 #endif
251
252 #ifdef _KERNEL
253
254 #include <sys/mbuf.h>
255 #include <sys/socketvar.h>
256 #include <sys/systm.h>
257
258 struct ifnet;
259 struct sockaddr;
260 const struct protosw *pffindproto(int, int, int);
261 const struct protosw *pffindtype(int, int);
262 void pfctlinput(int, struct sockaddr *);
263
264 extern u_char ip_protox[];
265 extern const struct protosw inetsw[];
266
267 #ifdef INET6
268 extern u_char ip6_protox[];
269 extern const struct protosw inet6sw[];
270 #endif /* INET6 */
271
272 static inline int
273 pru_attach(struct socket *so, int proto, int wait)
274 {
275 return (*so->so_proto->pr_usrreqs->pru_attach)(so, proto, wait);
276 }
277
278 static inline int
279 pru_detach(struct socket *so)
280 {
281 return (*so->so_proto->pr_usrreqs->pru_detach)(so);
282 }
283
284 static inline void
285 pru_lock(struct socket *so)
286 {
287 (*so->so_proto->pr_usrreqs->pru_lock)(so);
288 }
289
290 static inline void
291 pru_unlock(struct socket *so)
292 {
293 (*so->so_proto->pr_usrreqs->pru_unlock)(so);
294 }
295
296 static inline int
297 pru_bind(struct socket *so, struct mbuf *nam, struct proc *p)
298 {
299 if (so->so_proto->pr_usrreqs->pru_bind)
300 return (*so->so_proto->pr_usrreqs->pru_bind)(so, nam, p);
301 return (EOPNOTSUPP);
302 }
303
304 static inline int
305 pru_listen(struct socket *so)
306 {
307 if (so->so_proto->pr_usrreqs->pru_listen)
308 return (*so->so_proto->pr_usrreqs->pru_listen)(so);
309 return (EOPNOTSUPP);
310 }
311
312 static inline int
313 pru_connect(struct socket *so, struct mbuf *nam)
314 {
315 if (so->so_proto->pr_usrreqs->pru_connect)
316 return (*so->so_proto->pr_usrreqs->pru_connect)(so, nam);
317 return (EOPNOTSUPP);
318 }
319
320 static inline int
321 pru_accept(struct socket *so, struct mbuf *nam)
322 {
323 if (so->so_proto->pr_usrreqs->pru_accept)
324 return (*so->so_proto->pr_usrreqs->pru_accept)(so, nam);
325 return (EOPNOTSUPP);
326 }
327
328 static inline int
329 pru_disconnect(struct socket *so)
330 {
331 if (so->so_proto->pr_usrreqs->pru_disconnect)
332 return (*so->so_proto->pr_usrreqs->pru_disconnect)(so);
333 return (EOPNOTSUPP);
334 }
335
336 static inline int
337 pru_shutdown(struct socket *so)
338 {
339 return (*so->so_proto->pr_usrreqs->pru_shutdown)(so);
340 }
341
342 static inline void
343 pru_rcvd(struct socket *so)
344 {
345 (*so->so_proto->pr_usrreqs->pru_rcvd)(so);
346 }
347
348 static inline int
349 pru_send(struct socket *so, struct mbuf *top, struct mbuf *addr,
350 struct mbuf *control)
351 {
352 return (*so->so_proto->pr_usrreqs->pru_send)(so, top, addr, control);
353 }
354
355 static inline void
356 pru_abort(struct socket *so)
357 {
358 (*so->so_proto->pr_usrreqs->pru_abort)(so);
359 }
360
361 static inline int
362 pru_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp)
363 {
364 if (so->so_proto->pr_usrreqs->pru_control)
365 return (*so->so_proto->pr_usrreqs->pru_control)(so,
366 cmd, data, ifp);
367 return (EOPNOTSUPP);
368 }
369
370 static inline int
371 pru_sense(struct socket *so, struct stat *ub)
372 {
373 if (so->so_proto->pr_usrreqs->pru_sense)
374 return (*so->so_proto->pr_usrreqs->pru_sense)(so, ub);
375 return (0);
376 }
377
378 static inline int
379 pru_rcvoob(struct socket *so, struct mbuf *m, int flags)
380 {
381 if (so->so_proto->pr_usrreqs->pru_rcvoob)
382 return (*so->so_proto->pr_usrreqs->pru_rcvoob)(so, m, flags);
383 return (EOPNOTSUPP);
384 }
385
386 static inline int
387 pru_sendoob(struct socket *so, struct mbuf *top, struct mbuf *addr,
388 struct mbuf *control)
389 {
390 if (so->so_proto->pr_usrreqs->pru_sendoob)
391 return (*so->so_proto->pr_usrreqs->pru_sendoob)(so,
392 top, addr, control);
393 m_freem(top);
394 m_freem(control);
395 return (EOPNOTSUPP);
396 }
397
398 static inline int
399 pru_sockaddr(struct socket *so, struct mbuf *addr)
400 {
401 return (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, addr);
402 }
403
404 static inline int
405 pru_peeraddr(struct socket *so, struct mbuf *addr)
406 {
407 return (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, addr);
408 }
409
410 static inline int
411 pru_connect2(struct socket *so1, struct socket *so2)
412 {
413 if (so1->so_proto->pr_usrreqs->pru_connect2)
414 return (*so1->so_proto->pr_usrreqs->pru_connect2)(so1, so2);
415 return (EOPNOTSUPP);
416 }
417
418 #endif
419
420 #endif /* _SYS_PROTOSW_H_ */
Cache object: 18d1145e771cb41f9762b10c59de1247
|