FreeBSD/Linux Kernel Cross Reference
sys/sys/protosw.h
1 /* $NetBSD: protosw.h,v 1.31 2003/12/04 19:38:25 atatat Exp $ */
2
3 /*-
4 * Copyright (c) 1982, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)protosw.h 8.1 (Berkeley) 6/2/93
32 */
33
34 #ifndef _SYS_PROTOSW_H_
35 #define _SYS_PROTOSW_H_
36
37 /*
38 * Protocol switch table.
39 *
40 * Each protocol has a handle initializing one of these structures,
41 * which is used for protocol-protocol and system-protocol communication.
42 *
43 * A protocol is called through the pr_init entry before any other.
44 * Thereafter it is called every 200ms through the pr_fasttimo entry and
45 * every 500ms through the pr_slowtimo for timer based actions.
46 * The system will call the pr_drain entry if it is low on space and
47 * this should throw away any non-critical data.
48 *
49 * Protocols pass data between themselves as chains of mbufs using
50 * the pr_input and pr_output hooks. Pr_input passes data up (towards
51 * UNIX) and pr_output passes it down (towards the imps); control
52 * information passes up and down on pr_ctlinput and pr_ctloutput.
53 * The protocol is responsible for the space occupied by any the
54 * arguments to these entries and must dispose it.
55 *
56 * The userreq routine interfaces protocols to the system and is
57 * described below.
58 */
59
60 struct mbuf;
61 struct sockaddr;
62 struct socket;
63 struct domain;
64 struct proc;
65
66 struct protosw {
67 int pr_type; /* socket type used for */
68 struct domain *pr_domain; /* domain protocol a member of */
69 short pr_protocol; /* protocol number */
70 short pr_flags; /* see below */
71
72 /* protocol-protocol hooks */
73 void (*pr_input) /* input to protocol (from below) */
74 __P((struct mbuf *, ...));
75 int (*pr_output) /* output to protocol (from above) */
76 __P((struct mbuf *, ...));
77 void *(*pr_ctlinput) /* control input (from below) */
78 __P((int, struct sockaddr *, void *));
79 int (*pr_ctloutput) /* control output (from above) */
80 __P((int, struct socket *, int, int, struct mbuf **));
81
82 /* user-protocol hook */
83 int (*pr_usrreq) /* user request: see list below */
84 __P((struct socket *, int, struct mbuf *,
85 struct mbuf *, struct mbuf *, struct proc *));
86
87 /* utility hooks */
88 void (*pr_init) /* initialization hook */
89 __P((void));
90
91 void (*pr_fasttimo) /* fast timeout (200ms) */
92 __P((void));
93 void (*pr_slowtimo) /* slow timeout (500ms) */
94 __P((void));
95 void (*pr_drain) /* flush any excess space possible */
96 __P((void));
97 int *pr_wassysctl; /* @@@ was sysctl for protocol, now obsolete */
98 };
99
100 #define PR_SLOWHZ 2 /* 2 slow timeouts per second */
101 #define PR_FASTHZ 5 /* 5 fast timeouts per second */
102
103 /*
104 * Values for pr_flags.
105 * PR_ADDR requires PR_ATOMIC;
106 * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
107 */
108 #define PR_ATOMIC 0x01 /* exchange atomic messages only */
109 #define PR_ADDR 0x02 /* addresses given with messages */
110 #define PR_CONNREQUIRED 0x04 /* connection required by protocol */
111 #define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
112 #define PR_RIGHTS 0x10 /* passes capabilities */
113 #define PR_LISTEN 0x20 /* supports listen(2) and accept(2) */
114 #define PR_LASTHDR 0x40 /* enforce ipsec policy; last header */
115 #define PR_ABRTACPTDIS 0x80 /* abort on accept(2) to disconnected
116 socket */
117
118 /*
119 * The arguments to usrreq are:
120 * (*protosw[].pr_usrreq)(up, req, m, nam, opt, p);
121 * where up is a (struct socket *), req is one of these requests,
122 * m is a optional mbuf chain containing a message,
123 * nam is an optional mbuf chain containing an address,
124 * opt is a pointer to a socketopt structure or nil,
125 * and p is a pointer to the process requesting the action (if any).
126 * The protocol is responsible for disposal of the mbuf chain m,
127 * the caller is responsible for any space held by nam and opt.
128 * A non-zero return from usrreq gives an
129 * UNIX error number which should be passed to higher level software.
130 */
131 #define PRU_ATTACH 0 /* attach protocol to up */
132 #define PRU_DETACH 1 /* detach protocol from up */
133 #define PRU_BIND 2 /* bind socket to address */
134 #define PRU_LISTEN 3 /* listen for connection */
135 #define PRU_CONNECT 4 /* establish connection to peer */
136 #define PRU_ACCEPT 5 /* accept connection from peer */
137 #define PRU_DISCONNECT 6 /* disconnect from peer */
138 #define PRU_SHUTDOWN 7 /* won't send any more data */
139 #define PRU_RCVD 8 /* have taken data; more room now */
140 #define PRU_SEND 9 /* send this data */
141 #define PRU_ABORT 10 /* abort (fast DISCONNECT, DETACH) */
142 #define PRU_CONTROL 11 /* control operations on protocol */
143 #define PRU_SENSE 12 /* return status into m */
144 #define PRU_RCVOOB 13 /* retrieve out of band data */
145 #define PRU_SENDOOB 14 /* send out of band data */
146 #define PRU_SOCKADDR 15 /* fetch socket's address */
147 #define PRU_PEERADDR 16 /* fetch peer's address */
148 #define PRU_CONNECT2 17 /* connect two sockets */
149 /* begin for protocols internal use */
150 #define PRU_FASTTIMO 18 /* 200ms timeout */
151 #define PRU_SLOWTIMO 19 /* 500ms timeout */
152 #define PRU_PROTORCV 20 /* receive from below */
153 #define PRU_PROTOSEND 21 /* send to below */
154 #define PRU_PURGEIF 22 /* purge specified if */
155
156 #define PRU_NREQ 23
157
158 #ifdef PRUREQUESTS
159 char *prurequests[] = {
160 "ATTACH", "DETACH", "BIND", "LISTEN",
161 "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
162 "RCVD", "SEND", "ABORT", "CONTROL",
163 "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
164 "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
165 "PROTORCV", "PROTOSEND", "PURGEIF",
166 };
167 #endif
168
169 /*
170 * The arguments to the ctlinput routine are
171 * (*protosw[].pr_ctlinput)(cmd, sa, arg);
172 * where cmd is one of the commands below, sa is a pointer to a sockaddr,
173 * and arg is an optional caddr_t argument used within a protocol family.
174 */
175 #define PRC_IFDOWN 0 /* interface transition */
176 #define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
177 #define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
178 #define PRC_QUENCH 4 /* some one said to slow down */
179 #define PRC_MSGSIZE 5 /* message size forced drop */
180 #define PRC_HOSTDEAD 6 /* host appears to be down */
181 #define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
182 #define PRC_UNREACH_NET 8 /* no route to network */
183 #define PRC_UNREACH_HOST 9 /* no route to host */
184 #define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
185 #define PRC_UNREACH_PORT 11 /* bad port # */
186 /* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
187 #define PRC_UNREACH_SRCFAIL 13 /* source route failed */
188 #define PRC_REDIRECT_NET 14 /* net routing redirect */
189 #define PRC_REDIRECT_HOST 15 /* host routing redirect */
190 #define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
191 #define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
192 #define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
193 #define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
194 #define PRC_PARAMPROB 20 /* header incorrect */
195
196 #define PRC_NCMDS 21
197
198 #define PRC_IS_REDIRECT(cmd) \
199 ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
200
201 #ifdef PRCREQUESTS
202 char *prcrequests[] = {
203 "IFDOWN", "ROUTEDEAD", "#2", "DEC-BIT-QUENCH2",
204 "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
205 "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
206 "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
207 "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
208 "PARAMPROB"
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
237 /*
238 * Monotonically increasing time values for slow and fast timers.
239 */
240 extern u_int pfslowtimo_now;
241 extern u_int pffasttimo_now;
242
243 #define PRT_SLOW_ARM(t, nticks) (t) = (pfslowtimo_now + (nticks))
244 #define PRT_FAST_ARM(t, nticks) (t) = (pffasttimo_now + (nticks))
245
246 #define PRT_SLOW_DISARM(t) (t) = 0
247 #define PRT_FAST_DISARM(t) (t) = 0
248
249 #define PRT_SLOW_ISARMED(t) ((t) != 0)
250 #define PRT_FAST_ISARMED(t) ((t) != 0)
251
252 #define PRT_SLOW_ISEXPIRED(t) (PRT_SLOW_ISARMED((t)) && (t) <= pfslowtimo_now)
253 #define PRT_FAST_ISEXPIRED(t) (PRT_FAST_ISARMED((t)) && (t) <= pffasttimo_now)
254
255 struct sockaddr;
256 struct protosw *pffindproto __P((int, int, int));
257 struct protosw *pffindtype __P((int, int));
258 struct domain *pffinddomain __P((int));
259 extern struct protosw inetsw[];
260 void pfctlinput __P((int, struct sockaddr *));
261 void pfctlinput2 __P((int, struct sockaddr *, void *));
262 #endif /* _KERNEL */
263
264 #endif /* !_SYS_PROTOSW_H_ */
Cache object: 4bb85f6e345136c9ae70527c031f19b1
|