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