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