Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /*- |
2 | * Copyright (c) 1982, 1986 The Regents of the University of California. | |
3 | * 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 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
01e1b05c | 33 | * from: @(#)protosw.h 7.8 (Berkeley) 4/28/91 |
fde1aeb2 | 34 | * $Id: protosw.h,v 1.4 1993/11/18 00:12:34 wollman Exp $ |
15637ed4 RG |
35 | */ |
36 | ||
bcdc7290 GW |
37 | #ifndef _SYS_PROTOSW_H_ |
38 | #define _SYS_PROTOSW_H_ 1 | |
39 | ||
fde1aeb2 GW |
40 | struct mbuf; /* forward declarations */ |
41 | struct socket; | |
42 | ||
15637ed4 RG |
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 | |
fde1aeb2 | 57 | * UNIX) and pr_output passes it down (towards the interfaces); control |
15637ed4 RG |
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. | |
fde1aeb2 GW |
64 | * |
65 | * Beware that protocol families may make puns of this structure with | |
66 | * pr_{ctl,}{in,out}put routines having prototypes appropriate for that | |
67 | * protocol's conventions. (See, for example, netinet/in_var.h.) | |
15637ed4 RG |
68 | */ |
69 | struct protosw { | |
70 | short pr_type; /* socket type used for */ | |
71 | struct domain *pr_domain; /* domain protocol a member of */ | |
72 | short pr_protocol; /* protocol number */ | |
73 | short pr_flags; /* see below */ | |
74 | /* protocol-protocol hooks */ | |
75 | int (*pr_input)(); /* input to protocol (from below) */ | |
76 | int (*pr_output)(); /* output to protocol (from above) */ | |
fde1aeb2 GW |
77 | void (*pr_ctlinput)(); /* control input (from below) */ |
78 | int (*pr_ctloutput)(int, struct socket *, int, int, | |
79 | struct mbuf **); | |
80 | /* control output (from above) */ | |
15637ed4 | 81 | /* user-protocol hook */ |
fde1aeb2 GW |
82 | int (*pr_usrreq)(struct socket *, int, struct mbuf *, |
83 | struct mbuf *, struct mbuf *, struct mbuf *); | |
84 | /* user request: see list below */ | |
15637ed4 | 85 | /* utility hooks */ |
fde1aeb2 GW |
86 | void (*pr_init)(void); /* initialization hook */ |
87 | void (*pr_fasttimo)(void); /* fast timeout (200ms) */ | |
88 | void (*pr_slowtimo)(void); /* slow timeout (500ms) */ | |
89 | void (*pr_drain)(void); /* flush any excess space possible */ | |
15637ed4 RG |
90 | }; |
91 | ||
92 | #define PR_SLOWHZ 2 /* 2 slow timeouts per second */ | |
93 | #define PR_FASTHZ 5 /* 5 fast timeouts per second */ | |
94 | ||
95 | /* | |
96 | * Values for pr_flags. | |
97 | * PR_ADDR requires PR_ATOMIC; | |
98 | * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. | |
99 | */ | |
100 | #define PR_ATOMIC 0x01 /* exchange atomic messages only */ | |
101 | #define PR_ADDR 0x02 /* addresses given with messages */ | |
102 | #define PR_CONNREQUIRED 0x04 /* connection required by protocol */ | |
103 | #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ | |
104 | #define PR_RIGHTS 0x10 /* passes capabilities */ | |
105 | ||
106 | /* | |
107 | * The arguments to usrreq are: | |
108 | * (*protosw[].pr_usrreq)(up, req, m, nam, opt); | |
109 | * where up is a (struct socket *), req is one of these requests, | |
110 | * m is a optional mbuf chain containing a message, | |
111 | * nam is an optional mbuf chain containing an address, | |
112 | * and opt is a pointer to a socketopt structure or nil. | |
113 | * The protocol is responsible for disposal of the mbuf chain m, | |
114 | * the caller is responsible for any space held by nam and opt. | |
115 | * A non-zero return from usrreq gives an | |
116 | * UNIX error number which should be passed to higher level software. | |
117 | */ | |
118 | #define PRU_ATTACH 0 /* attach protocol to up */ | |
119 | #define PRU_DETACH 1 /* detach protocol from up */ | |
120 | #define PRU_BIND 2 /* bind socket to address */ | |
121 | #define PRU_LISTEN 3 /* listen for connection */ | |
122 | #define PRU_CONNECT 4 /* establish connection to peer */ | |
123 | #define PRU_ACCEPT 5 /* accept connection from peer */ | |
124 | #define PRU_DISCONNECT 6 /* disconnect from peer */ | |
125 | #define PRU_SHUTDOWN 7 /* won't send any more data */ | |
126 | #define PRU_RCVD 8 /* have taken data; more room now */ | |
127 | #define PRU_SEND 9 /* send this data */ | |
128 | #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ | |
129 | #define PRU_CONTROL 11 /* control operations on protocol */ | |
130 | #define PRU_SENSE 12 /* return status into m */ | |
131 | #define PRU_RCVOOB 13 /* retrieve out of band data */ | |
132 | #define PRU_SENDOOB 14 /* send out of band data */ | |
133 | #define PRU_SOCKADDR 15 /* fetch socket's address */ | |
134 | #define PRU_PEERADDR 16 /* fetch peer's address */ | |
135 | #define PRU_CONNECT2 17 /* connect two sockets */ | |
136 | /* begin for protocols internal use */ | |
137 | #define PRU_FASTTIMO 18 /* 200ms timeout */ | |
138 | #define PRU_SLOWTIMO 19 /* 500ms timeout */ | |
139 | #define PRU_PROTORCV 20 /* receive from below */ | |
140 | #define PRU_PROTOSEND 21 /* send to below */ | |
141 | ||
142 | #define PRU_NREQ 21 | |
143 | ||
144 | #ifdef PRUREQUESTS | |
145 | char *prurequests[] = { | |
146 | "ATTACH", "DETACH", "BIND", "LISTEN", | |
147 | "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", | |
148 | "RCVD", "SEND", "ABORT", "CONTROL", | |
149 | "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", | |
150 | "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", | |
151 | "PROTORCV", "PROTOSEND", | |
152 | }; | |
153 | #endif | |
154 | ||
155 | /* | |
156 | * The arguments to the ctlinput routine are | |
157 | * (*protosw[].pr_ctlinput)(cmd, sa, arg); | |
158 | * where cmd is one of the commands below, sa is a pointer to a sockaddr, | |
159 | * and arg is an optional caddr_t argument used within a protocol family. | |
160 | */ | |
161 | #define PRC_IFDOWN 0 /* interface transition */ | |
162 | #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ | |
163 | #define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ | |
164 | #define PRC_QUENCH 4 /* some one said to slow down */ | |
165 | #define PRC_MSGSIZE 5 /* message size forced drop */ | |
166 | #define PRC_HOSTDEAD 6 /* host appears to be down */ | |
167 | #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ | |
168 | #define PRC_UNREACH_NET 8 /* no route to network */ | |
169 | #define PRC_UNREACH_HOST 9 /* no route to host */ | |
170 | #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ | |
171 | #define PRC_UNREACH_PORT 11 /* bad port # */ | |
172 | /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ | |
173 | #define PRC_UNREACH_SRCFAIL 13 /* source route failed */ | |
ed36ec52 GW |
174 | #define PRC_UNREACH_NETUNKNOWN 14 /* network unknown */ |
175 | #define PRC_UNREACH_HOSTUNKNOWN 15 /* host unknown */ | |
176 | #define PRC_UNREACH_ISOLATED 16 /* source host is isolated */ | |
177 | #define PRC_UNREACH_NETADMIN 17 /* communication administratively */ | |
178 | #define PRC_UNREACH_HOSTADMIN 18 /* prohibited with net/host */ | |
179 | #define PRC_UNREACH_TOSNET 19 /* net unreachable with this TOS */ | |
180 | #define PRC_UNREACH_TOSHOST 20 /* host unreachable with this TOS */ | |
15637ed4 | 181 | |
ed36ec52 GW |
182 | #define PRC_REDIRECT_NET 21 /* net routing redirect */ |
183 | #define PRC_REDIRECT_HOST 22 /* host routing redirect */ | |
184 | #define PRC_REDIRECT_TOSNET 23 /* redirect for type of service & net */ | |
185 | #define PRC_REDIRECT_TOSHOST 24 /* redirect for tos & host */ | |
186 | #define PRC_TIMXCEED_INTRANS 25 /* packet lifetime expired in transit */ | |
187 | #define PRC_TIMXCEED_REASS 26 /* lifetime expired on reass q */ | |
188 | #define PRC_PARAMPROB 27 /* header incorrect */ | |
189 | #define PRC_OPTION_MISSING 28 /* required option missing */ | |
190 | #define PRC_MTUCHANGED 29 /* lower layer MTU has changed */ | |
191 | ||
192 | #define PRC_NCMDS 30 | |
15637ed4 RG |
193 | |
194 | #define PRC_IS_REDIRECT(cmd) \ | |
195 | ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) | |
ed36ec52 GW |
196 | #define PRC_IS_UNREACH(cmd) \ |
197 | ((cmd) >= PRC_UNREACH_NET && (cmd) <= PRC_UNREACH_TOSHOST) | |
15637ed4 RG |
198 | |
199 | #ifdef PRCREQUESTS | |
200 | char *prcrequests[] = { | |
201 | "IFDOWN", "ROUTEDEAD", "#2", "DEC-BIT-QUENCH2", | |
202 | "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", | |
203 | "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", | |
ed36ec52 GW |
204 | "#12", "SRCFAIL-UNREACH", "NET-UNKNOWN", "HOST-UNKNOWN", |
205 | "HOST-ISOLATED", "NET-ADMIN-UNREACH", "HOST-ADMIN-UNREACH", | |
206 | "TOSNET-UNREACH", "TOSHOST-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", | |
15637ed4 | 207 | "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", |
ed36ec52 | 208 | "PARAMPROB", "OPTION-MISSING", "MTU-CHANGED" |
15637ed4 RG |
209 | }; |
210 | #endif | |
211 | ||
212 | /* | |
213 | * The arguments to ctloutput are: | |
214 | * (*protosw[].pr_ctloutput)(req, so, level, optname, optval); | |
215 | * req is one of the actions listed below, so is a (struct socket *), | |
216 | * level is an indication of which protocol layer the option is intended. | |
217 | * optname is a protocol dependent socket option request, | |
218 | * optval is a pointer to a mbuf-chain pointer, for value-return results. | |
219 | * The protocol is responsible for disposal of the mbuf chain *optval | |
220 | * if supplied, | |
221 | * the caller is responsible for any space held by *optval, when returned. | |
222 | * A non-zero return from usrreq gives an | |
223 | * UNIX error number which should be passed to higher level software. | |
224 | */ | |
225 | #define PRCO_GETOPT 0 | |
226 | #define PRCO_SETOPT 1 | |
227 | ||
228 | #define PRCO_NCMDS 2 | |
229 | ||
230 | #ifdef PRCOREQUESTS | |
231 | char *prcorequests[] = { | |
232 | "GETOPT", "SETOPT", | |
233 | }; | |
234 | #endif | |
235 | ||
236 | #ifdef KERNEL | |
fde1aeb2 GW |
237 | extern void domaininit(void); |
238 | extern struct protosw *pffindtype(int, int); | |
239 | extern struct protosw *pffindproto(int, int, int); | |
240 | struct sockaddr; | |
241 | extern void pfctlinput(int, struct sockaddr *); | |
242 | #endif /* KERNEL */ | |
bcdc7290 | 243 | #endif /* _SYS_PROTOSW_H_ */ |