protosw.h revision 82824
1249259Sdim/*- 2249259Sdim * Copyright (c) 1982, 1986, 1993 3249259Sdim * The Regents of the University of California. All rights reserved. 4249259Sdim * 5249259Sdim * Redistribution and use in source and binary forms, with or without 6249259Sdim * modification, are permitted provided that the following conditions 7249259Sdim * are met: 8249259Sdim * 1. Redistributions of source code must retain the above copyright 9249259Sdim * notice, this list of conditions and the following disclaimer. 10249259Sdim * 2. Redistributions in binary form must reproduce the above copyright 11249259Sdim * notice, this list of conditions and the following disclaimer in the 12249259Sdim * documentation and/or other materials provided with the distribution. 13249259Sdim * 3. All advertising materials mentioning features or use of this software 14249259Sdim * must display the following acknowledgement: 15249259Sdim * This product includes software developed by the University of 16263509Sdim * California, Berkeley and its contributors. 17249259Sdim * 4. Neither the name of the University nor the names of its contributors 18249259Sdim * may be used to endorse or promote products derived from this software 19263509Sdim * without specific prior written permission. 20263509Sdim * 21263509Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22263509Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23249259Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24249259Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25249259Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26263509Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27249259Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28249259Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29249259Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30249259Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31249259Sdim * SUCH DAMAGE. 32249259Sdim * 33249259Sdim * @(#)protosw.h 8.1 (Berkeley) 6/2/93 34249259Sdim * $FreeBSD: head/sys/sys/protosw.h 82824 2001-09-02 20:36:19Z julian $ 35249259Sdim */ 36249259Sdim 37249259Sdim#ifndef _SYS_PROTOSW_H_ 38249259Sdim#define _SYS_PROTOSW_H_ 39249259Sdim 40249259Sdim/* 41249259Sdim * For pfil_head structure. 42249259Sdim */ 43249259Sdim#include <net/pfil.h> 44249259Sdim 45249259Sdim/* Forward declare these structures referenced from prototypes below. */ 46249259Sdimstruct mbuf; 47249259Sdimstruct proc; 48249259Sdimstruct sockaddr; 49249259Sdimstruct socket; 50249259Sdimstruct sockopt; 51249259Sdim 52249259Sdim/*#ifdef _KERNEL*/ 53249259Sdim/* 54249259Sdim * Protocol switch table. 55249259Sdim * 56249259Sdim * Each protocol has a handle initializing one of these structures, 57249259Sdim * which is used for protocol-protocol and system-protocol communication. 58249259Sdim * 59249259Sdim * A protocol is called through the pr_init entry before any other. 60249259Sdim * Thereafter it is called every 200ms through the pr_fasttimo entry and 61249259Sdim * every 500ms through the pr_slowtimo for timer based actions. 62249259Sdim * The system will call the pr_drain entry if it is low on space and 63249259Sdim * this should throw away any non-critical data. 64249259Sdim * 65249259Sdim * Protocols pass data between themselves as chains of mbufs using 66249259Sdim * the pr_input and pr_output hooks. Pr_input passes data up (towards 67249259Sdim * the users) and pr_output passes it down (towards the interfaces); control 68249259Sdim * information passes up and down on pr_ctlinput and pr_ctloutput. 69249259Sdim * The protocol is responsible for the space occupied by any the 70249259Sdim * arguments to these entries and must dispose it. 71249259Sdim * 72263509Sdim * In retrospect, it would be a lot nicer to use an interface 73263509Sdim * similar to the vnode VOP interface. 74263509Sdim */ 75263509Sdim/* USE THESE FOR YOUR PROTOTYPES ! */ 76263509Sdimtypedef void pr_input_t (struct mbuf *, int); 77263509Sdimtypedef int pr_input6_t (struct mbuf **, int*, int); /* XXX FIX THIS */ 78249259Sdimtypedef void pr_in_input_t (struct mbuf *, int, int); /* XXX FIX THIS */ 79249259Sdimtypedef int pr_output_t (struct mbuf *, struct socket *); 80249259Sdimtypedef int pr_in_output_t (struct mbuf *, struct socket *, struct sockaddr *); 81249259Sdimtypedef void pr_ctlinput_t (int, struct sockaddr *, void *); 82263509Sdimtypedef int pr_ctloutput_t (struct socket *, struct sockopt *); 83263509Sdimtypedef void pr_init_t (void); 84263509Sdimtypedef void pr_fasttimo_t (void); 85249259Sdimtypedef void pr_slowtimo_t (void); 86249259Sdimtypedef void pr_drain_t (void); 87249259Sdim 88263509Sdimtypedef int pr_usrreq_t(struct socket *, int, struct mbuf *, 89249259Sdim struct mbuf *, struct mbuf *, struct proc *); 90249259Sdim 91249259Sdimstruct protosw { 92249259Sdim short pr_type; /* socket type used for */ 93249259Sdim struct domain *pr_domain; /* domain protocol a member of */ 94249259Sdim short pr_protocol; /* protocol number */ 95249259Sdim short pr_flags; /* see below */ 96249259Sdim/* protocol-protocol hooks */ 97263509Sdim pr_input_t *pr_input; /* input to protocol (from below) */ 98249259Sdim pr_output_t *pr_output; /* output to protocol (from above) */ 99263509Sdim pr_ctlinput_t *pr_ctlinput; /* control input (from below) */ 100263509Sdim pr_ctloutput_t *pr_ctloutput; /* control output (from above) */ 101263509Sdim/* user-protocol hook */ 102249259Sdim pr_usrreq_t *pr_ousrreq; 103263509Sdim/* utility hooks */ 104263509Sdim pr_init_t *pr_init; 105263509Sdim pr_fasttimo_t *pr_fasttimo; /* fast timeout (200ms) */ 106249259Sdim pr_slowtimo_t *pr_slowtimo; /* slow timeout (500ms) */ 107249259Sdim pr_drain_t *pr_drain; /* flush any excess space possible */ 108263509Sdim 109249259Sdim struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */ 110249259Sdim struct pfil_head pr_pfh; 111249259Sdim}; 112249259Sdim/*#endif*/ 113249259Sdim 114249259Sdim#define PR_SLOWHZ 2 /* 2 slow timeouts per second */ 115249259Sdim#define PR_FASTHZ 5 /* 5 fast timeouts per second */ 116249259Sdim 117249259Sdim/* 118249259Sdim * Values for pr_flags. 119249259Sdim * PR_ADDR requires PR_ATOMIC; 120249259Sdim * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. 121249259Sdim * PR_IMPLOPCL means that the protocol allows sendto without prior connect, 122249259Sdim * and the protocol understands the MSG_EOF flag. The first property is 123249259Sdim * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed 124249259Sdim * anyhow). 125249259Sdim */ 126249259Sdim#define PR_ATOMIC 0x01 /* exchange atomic messages only */ 127249259Sdim#define PR_ADDR 0x02 /* addresses given with messages */ 128249259Sdim#define PR_CONNREQUIRED 0x04 /* connection required by protocol */ 129249259Sdim#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ 130249259Sdim#define PR_RIGHTS 0x10 /* passes capabilities */ 131249259Sdim#define PR_IMPLOPCL 0x20 /* implied open/close */ 132249259Sdim#define PR_LASTHDR 0x40 /* enforce ipsec policy; last header */ 133249259Sdim 134249259Sdim/* 135249259Sdim * The arguments to usrreq are: 136249259Sdim * (*protosw[].pr_usrreq)(up, req, m, nam, opt); 137249259Sdim * where up is a (struct socket *), req is one of these requests, 138249259Sdim * m is a optional mbuf chain containing a message, 139249259Sdim * nam is an optional mbuf chain containing an address, 140249259Sdim * and opt is a pointer to a socketopt structure or nil. 141249259Sdim * The protocol is responsible for disposal of the mbuf chain m, 142249259Sdim * the caller is responsible for any space held by nam and opt. 143249259Sdim * A non-zero return from usrreq gives an 144249259Sdim * UNIX error number which should be passed to higher level software. 145249259Sdim */ 146249259Sdim#define PRU_ATTACH 0 /* attach protocol to up */ 147249259Sdim#define PRU_DETACH 1 /* detach protocol from up */ 148249259Sdim#define PRU_BIND 2 /* bind socket to address */ 149249259Sdim#define PRU_LISTEN 3 /* listen for connection */ 150249259Sdim#define PRU_CONNECT 4 /* establish connection to peer */ 151249259Sdim#define PRU_ACCEPT 5 /* accept connection from peer */ 152249259Sdim#define PRU_DISCONNECT 6 /* disconnect from peer */ 153249259Sdim#define PRU_SHUTDOWN 7 /* won't send any more data */ 154249259Sdim#define PRU_RCVD 8 /* have taken data; more room now */ 155249259Sdim#define PRU_SEND 9 /* send this data */ 156249259Sdim#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ 157249259Sdim#define PRU_CONTROL 11 /* control operations on protocol */ 158249259Sdim#define PRU_SENSE 12 /* return status into m */ 159249259Sdim#define PRU_RCVOOB 13 /* retrieve out of band data */ 160249259Sdim#define PRU_SENDOOB 14 /* send out of band data */ 161249259Sdim#define PRU_SOCKADDR 15 /* fetch socket's address */ 162249259Sdim#define PRU_PEERADDR 16 /* fetch peer's address */ 163249259Sdim#define PRU_CONNECT2 17 /* connect two sockets */ 164249259Sdim/* begin for protocols internal use */ 165249259Sdim#define PRU_FASTTIMO 18 /* 200ms timeout */ 166249259Sdim#define PRU_SLOWTIMO 19 /* 500ms timeout */ 167249259Sdim#define PRU_PROTORCV 20 /* receive from below */ 168249259Sdim#define PRU_PROTOSEND 21 /* send to below */ 169249259Sdim/* end for protocol's internal use */ 170249259Sdim#define PRU_SEND_EOF 22 /* send and close */ 171249259Sdim#define PRU_NREQ 22 172249259Sdim 173249259Sdim#ifdef PRUREQUESTS 174249259Sdimchar *prurequests[] = { 175249259Sdim "ATTACH", "DETACH", "BIND", "LISTEN", 176249259Sdim "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", 177249259Sdim "RCVD", "SEND", "ABORT", "CONTROL", 178249259Sdim "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", 179249259Sdim "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", 180249259Sdim "PROTORCV", "PROTOSEND", 181249259Sdim "SEND_EOF", 182249259Sdim}; 183249259Sdim#endif 184249259Sdim 185249259Sdim#ifdef _KERNEL /* users shouldn't see this decl */ 186249259Sdim 187249259Sdimstruct ifnet; 188249259Sdimstruct stat; 189249259Sdimstruct ucred; 190249259Sdimstruct uio; 191249259Sdim 192249259Sdim/* 193249259Sdim * If the ordering here looks odd, that's because it's alphabetical. 194249259Sdim * Having this structure separated out from the main protoswitch is allegedly 195249259Sdim * a big (12 cycles per call) lose on high-end CPUs. We will eventually 196249259Sdim * migrate this stuff back into the main structure. 197249259Sdim */ 198263509Sdimstruct pr_usrreqs { 199263509Sdim int (*pru_abort) __P((struct socket *so)); 200249259Sdim int (*pru_accept) __P((struct socket *so, struct sockaddr **nam)); 201249259Sdim int (*pru_attach) __P((struct socket *so, int proto, 202249259Sdim struct proc *p)); 203249259Sdim int (*pru_bind) __P((struct socket *so, struct sockaddr *nam, 204249259Sdim struct proc *p)); 205249259Sdim int (*pru_connect) __P((struct socket *so, struct sockaddr *nam, 206249259Sdim struct proc *p)); 207249259Sdim int (*pru_connect2) __P((struct socket *so1, struct socket *so2)); 208249259Sdim int (*pru_control) __P((struct socket *so, u_long cmd, caddr_t data, 209263509Sdim struct ifnet *ifp, struct proc *p)); 210263509Sdim int (*pru_detach) __P((struct socket *so)); 211263509Sdim int (*pru_disconnect) __P((struct socket *so)); 212249259Sdim int (*pru_listen) __P((struct socket *so, struct proc *p)); 213249259Sdim int (*pru_peeraddr) __P((struct socket *so, 214263509Sdim struct sockaddr **nam)); 215249259Sdim int (*pru_rcvd) __P((struct socket *so, int flags)); 216249259Sdim int (*pru_rcvoob) __P((struct socket *so, struct mbuf *m, 217249259Sdim int flags)); 218249259Sdim int (*pru_send) __P((struct socket *so, int flags, struct mbuf *m, 219249259Sdim struct sockaddr *addr, struct mbuf *control, 220249259Sdim struct proc *p)); 221249259Sdim#define PRUS_OOB 0x1 222249259Sdim#define PRUS_EOF 0x2 223263509Sdim#define PRUS_MORETOCOME 0x4 224263509Sdim int (*pru_sense) __P((struct socket *so, struct stat *sb)); 225263509Sdim int (*pru_shutdown) __P((struct socket *so)); 226263509Sdim int (*pru_sockaddr) __P((struct socket *so, 227263509Sdim struct sockaddr **nam)); 228263509Sdim 229263509Sdim /* 230263509Sdim * These three added later, so they are out of order. They are used 231263509Sdim * for shortcutting (fast path input/output) in some protocols. 232263509Sdim * XXX - that's a lie, they are not implemented yet 233263509Sdim * Rather than calling sosend() etc. directly, calls are made 234263509Sdim * through these entry points. For protocols which still use 235263509Sdim * the generic code, these just point to those routines. 236263509Sdim */ 237263509Sdim int (*pru_sosend) __P((struct socket *so, struct sockaddr *addr, 238263509Sdim struct uio *uio, struct mbuf *top, 239263509Sdim struct mbuf *control, int flags, 240263509Sdim struct proc *p)); 241263509Sdim int (*pru_soreceive) __P((struct socket *so, 242263509Sdim struct sockaddr **paddr, 243263509Sdim struct uio *uio, struct mbuf **mp0, 244263509Sdim struct mbuf **controlp, int *flagsp)); 245263509Sdim int (*pru_sopoll) __P((struct socket *so, int events, 246263509Sdim struct ucred *cred, struct proc *p)); 247263509Sdim}; 248263509Sdim 249263509Sdimint pru_accept_notsupp __P((struct socket *so, struct sockaddr **nam)); 250263509Sdimint pru_connect_notsupp __P((struct socket *so, struct sockaddr *nam, 251263509Sdim struct proc *p)); 252263509Sdimint pru_connect2_notsupp __P((struct socket *so1, struct socket *so2)); 253263509Sdimint pru_control_notsupp __P((struct socket *so, u_long cmd, caddr_t data, 254263509Sdim struct ifnet *ifp, struct proc *p)); 255263509Sdimint pru_listen_notsupp __P((struct socket *so, struct proc *p)); 256263509Sdimint pru_rcvd_notsupp __P((struct socket *so, int flags)); 257263509Sdimint pru_rcvoob_notsupp __P((struct socket *so, struct mbuf *m, int flags)); 258263509Sdimint pru_sense_null __P((struct socket *so, struct stat *sb)); 259263509Sdim 260263509Sdim#endif /* _KERNEL */ 261263509Sdim 262263509Sdim/* 263263509Sdim * The arguments to the ctlinput routine are 264263509Sdim * (*protosw[].pr_ctlinput)(cmd, sa, arg); 265263509Sdim * where cmd is one of the commands below, sa is a pointer to a sockaddr, 266263509Sdim * and arg is a `void *' argument used within a protocol family. 267263509Sdim */ 268263509Sdim#define PRC_IFDOWN 0 /* interface transition */ 269263509Sdim#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ 270263509Sdim#define PRC_IFUP 2 /* interface has come back up */ 271263509Sdim#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ 272263509Sdim#define PRC_QUENCH 4 /* some one said to slow down */ 273263509Sdim#define PRC_MSGSIZE 5 /* message size forced drop */ 274263509Sdim#define PRC_HOSTDEAD 6 /* host appears to be down */ 275263509Sdim#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ 276263509Sdim#define PRC_UNREACH_NET 8 /* no route to network */ 277263509Sdim#define PRC_UNREACH_HOST 9 /* no route to host */ 278263509Sdim#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ 279263509Sdim#define PRC_UNREACH_PORT 11 /* bad port # */ 280263509Sdim/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ 281263509Sdim#define PRC_UNREACH_SRCFAIL 13 /* source route failed */ 282263509Sdim#define PRC_REDIRECT_NET 14 /* net routing redirect */ 283263509Sdim#define PRC_REDIRECT_HOST 15 /* host routing redirect */ 284263509Sdim#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ 285263509Sdim#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ 286263509Sdim#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ 287263509Sdim#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ 288263509Sdim#define PRC_PARAMPROB 20 /* header incorrect */ 289263509Sdim#define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */ 290263509Sdim 291263509Sdim#define PRC_NCMDS 22 292263509Sdim 293263509Sdim#define PRC_IS_REDIRECT(cmd) \ 294263509Sdim ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) 295263509Sdim 296263509Sdim#ifdef PRCREQUESTS 297263509Sdimchar *prcrequests[] = { 298263509Sdim "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2", 299263509Sdim "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", 300263509Sdim "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", 301263509Sdim "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", 302263509Sdim "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", 303263509Sdim "PARAMPROB", "ADMIN-UNREACH" 304263509Sdim}; 305263509Sdim#endif 306263509Sdim 307263509Sdim/* 308263509Sdim * The arguments to ctloutput are: 309263509Sdim * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p); 310263509Sdim * req is one of the actions listed below, so is a (struct socket *), 311263509Sdim * level is an indication of which protocol layer the option is intended. 312263509Sdim * optname is a protocol dependent socket option request, 313263509Sdim * optval is a pointer to a mbuf-chain pointer, for value-return results. 314263509Sdim * The protocol is responsible for disposal of the mbuf chain *optval 315263509Sdim * if supplied, 316263509Sdim * the caller is responsible for any space held by *optval, when returned. 317263509Sdim * A non-zero return from usrreq gives an 318263509Sdim * UNIX error number which should be passed to higher level software. 319263509Sdim */ 320263509Sdim#define PRCO_GETOPT 0 321263509Sdim#define PRCO_SETOPT 1 322263509Sdim 323263509Sdim#define PRCO_NCMDS 2 324263509Sdim 325263509Sdim#ifdef PRCOREQUESTS 326263509Sdimchar *prcorequests[] = { 327263509Sdim "GETOPT", "SETOPT", 328263509Sdim}; 329263509Sdim#endif 330263509Sdim 331263509Sdim#ifdef _KERNEL 332263509Sdimvoid pfctlinput __P((int, struct sockaddr *)); 333263509Sdimvoid pfctlinput2 __P((int, struct sockaddr *, void *)); 334263509Sdimstruct protosw *pffindproto __P((int family, int protocol, int type)); 335263509Sdimstruct protosw *pffindtype __P((int family, int type)); 336263509Sdim#endif 337263509Sdim 338263509Sdim#endif 339263509Sdim