protosw.h revision 55205
11541Srgrimes/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 3. All advertising materials mentioning features or use of this software 141541Srgrimes * must display the following acknowledgement: 151541Srgrimes * This product includes software developed by the University of 161541Srgrimes * California, Berkeley and its contributors. 171541Srgrimes * 4. Neither the name of the University nor the names of its contributors 181541Srgrimes * may be used to endorse or promote products derived from this software 191541Srgrimes * without specific prior written permission. 201541Srgrimes * 211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311541Srgrimes * SUCH DAMAGE. 321541Srgrimes * 331541Srgrimes * @(#)protosw.h 8.1 (Berkeley) 6/2/93 3450477Speter * $FreeBSD: head/sys/sys/protosw.h 55205 1999-12-29 04:46:21Z peter $ 351541Srgrimes */ 361541Srgrimes 372165Spaul#ifndef _SYS_PROTOSW_H_ 382165Spaul#define _SYS_PROTOSW_H_ 392165Spaul 4023888Swollman/* Forward declare these structures referenced from prototypes below. */ 4112453Sbdestruct mbuf; 4228270Swollmanstruct proc; 4312453Sbdestruct sockaddr; 4412453Sbdestruct socket; 4538482Swollmanstruct sockopt; 4612453Sbde 4755205Speter/*#ifdef _KERNEL*/ 481541Srgrimes/* 491541Srgrimes * Protocol switch table. 501541Srgrimes * 511541Srgrimes * Each protocol has a handle initializing one of these structures, 521541Srgrimes * which is used for protocol-protocol and system-protocol communication. 531541Srgrimes * 541541Srgrimes * A protocol is called through the pr_init entry before any other. 551541Srgrimes * Thereafter it is called every 200ms through the pr_fasttimo entry and 561541Srgrimes * every 500ms through the pr_slowtimo for timer based actions. 571541Srgrimes * The system will call the pr_drain entry if it is low on space and 581541Srgrimes * this should throw away any non-critical data. 591541Srgrimes * 601541Srgrimes * Protocols pass data between themselves as chains of mbufs using 611541Srgrimes * the pr_input and pr_output hooks. Pr_input passes data up (towards 6238482Swollman * the users) and pr_output passes it down (towards the interfaces); control 631541Srgrimes * information passes up and down on pr_ctlinput and pr_ctloutput. 641541Srgrimes * The protocol is responsible for the space occupied by any the 651541Srgrimes * arguments to these entries and must dispose it. 661541Srgrimes * 6738482Swollman * In retrospect, it would be a lot nicer to use an interface 6838482Swollman * similar to the vnode VOP interface. 691541Srgrimes */ 701541Srgrimesstruct protosw { 711541Srgrimes short pr_type; /* socket type used for */ 721541Srgrimes struct domain *pr_domain; /* domain protocol a member of */ 731541Srgrimes short pr_protocol; /* protocol number */ 741541Srgrimes short pr_flags; /* see below */ 751541Srgrimes/* protocol-protocol hooks */ 7612453Sbde void (*pr_input) __P((struct mbuf *, int len)); 7712453Sbde /* input to protocol (from below) */ 7812453Sbde int (*pr_output) __P((struct mbuf *m, struct socket *so)); 7912453Sbde /* output to protocol (from above) */ 8012881Sbde void (*pr_ctlinput)__P((int, struct sockaddr *, void *)); 8112453Sbde /* control input (from below) */ 8238482Swollman int (*pr_ctloutput)__P((struct socket *, struct sockopt *)); 8312453Sbde /* control output (from above) */ 841541Srgrimes/* user-protocol hook */ 8525201Swollman void *pr_ousrreq; 861541Srgrimes/* utility hooks */ 8712453Sbde void (*pr_init) __P((void)); /* initialization hook */ 8812453Sbde void (*pr_fasttimo) __P((void)); 8912453Sbde /* fast timeout (200ms) */ 9012453Sbde void (*pr_slowtimo) __P((void)); 9112453Sbde /* slow timeout (500ms) */ 9212453Sbde void (*pr_drain) __P((void)); 9312453Sbde /* flush any excess space possible */ 9417047Swollman struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */ 951541Srgrimes}; 9628270Swollman/*#endif*/ 971541Srgrimes 981541Srgrimes#define PR_SLOWHZ 2 /* 2 slow timeouts per second */ 991541Srgrimes#define PR_FASTHZ 5 /* 5 fast timeouts per second */ 1001541Srgrimes 1011541Srgrimes/* 1021541Srgrimes * Values for pr_flags. 1031541Srgrimes * PR_ADDR requires PR_ATOMIC; 1041541Srgrimes * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. 1056223Swollman * PR_IMPLOPCL means that the protocol allows sendto without prior connect, 1066223Swollman * and the protocol understands the MSG_EOF flag. The first property is 1076223Swollman * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed 1086223Swollman * anyhow). 1091541Srgrimes */ 1101541Srgrimes#define PR_ATOMIC 0x01 /* exchange atomic messages only */ 1111541Srgrimes#define PR_ADDR 0x02 /* addresses given with messages */ 1121541Srgrimes#define PR_CONNREQUIRED 0x04 /* connection required by protocol */ 1131541Srgrimes#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ 1141541Srgrimes#define PR_RIGHTS 0x10 /* passes capabilities */ 1156223Swollman#define PR_IMPLOPCL 0x20 /* implied open/close */ 1161541Srgrimes 1171541Srgrimes/* 1181541Srgrimes * The arguments to usrreq are: 1191541Srgrimes * (*protosw[].pr_usrreq)(up, req, m, nam, opt); 1201541Srgrimes * where up is a (struct socket *), req is one of these requests, 1211541Srgrimes * m is a optional mbuf chain containing a message, 1221541Srgrimes * nam is an optional mbuf chain containing an address, 1231541Srgrimes * and opt is a pointer to a socketopt structure or nil. 1241541Srgrimes * The protocol is responsible for disposal of the mbuf chain m, 1251541Srgrimes * the caller is responsible for any space held by nam and opt. 1261541Srgrimes * A non-zero return from usrreq gives an 1271541Srgrimes * UNIX error number which should be passed to higher level software. 1281541Srgrimes */ 1291541Srgrimes#define PRU_ATTACH 0 /* attach protocol to up */ 1301541Srgrimes#define PRU_DETACH 1 /* detach protocol from up */ 1311541Srgrimes#define PRU_BIND 2 /* bind socket to address */ 1321541Srgrimes#define PRU_LISTEN 3 /* listen for connection */ 1331541Srgrimes#define PRU_CONNECT 4 /* establish connection to peer */ 1341541Srgrimes#define PRU_ACCEPT 5 /* accept connection from peer */ 1351541Srgrimes#define PRU_DISCONNECT 6 /* disconnect from peer */ 1361541Srgrimes#define PRU_SHUTDOWN 7 /* won't send any more data */ 1371541Srgrimes#define PRU_RCVD 8 /* have taken data; more room now */ 1381541Srgrimes#define PRU_SEND 9 /* send this data */ 1391541Srgrimes#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ 1401541Srgrimes#define PRU_CONTROL 11 /* control operations on protocol */ 1411541Srgrimes#define PRU_SENSE 12 /* return status into m */ 1421541Srgrimes#define PRU_RCVOOB 13 /* retrieve out of band data */ 1431541Srgrimes#define PRU_SENDOOB 14 /* send out of band data */ 1441541Srgrimes#define PRU_SOCKADDR 15 /* fetch socket's address */ 1451541Srgrimes#define PRU_PEERADDR 16 /* fetch peer's address */ 1461541Srgrimes#define PRU_CONNECT2 17 /* connect two sockets */ 1471541Srgrimes/* begin for protocols internal use */ 1481541Srgrimes#define PRU_FASTTIMO 18 /* 200ms timeout */ 1491541Srgrimes#define PRU_SLOWTIMO 19 /* 500ms timeout */ 1501541Srgrimes#define PRU_PROTORCV 20 /* receive from below */ 1511541Srgrimes#define PRU_PROTOSEND 21 /* send to below */ 15217047Swollman/* end for protocol's internal use */ 1536223Swollman#define PRU_SEND_EOF 22 /* send and close */ 1546223Swollman#define PRU_NREQ 22 1551541Srgrimes 1561541Srgrimes#ifdef PRUREQUESTS 1571541Srgrimeschar *prurequests[] = { 1581541Srgrimes "ATTACH", "DETACH", "BIND", "LISTEN", 1591541Srgrimes "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", 1601541Srgrimes "RCVD", "SEND", "ABORT", "CONTROL", 1611541Srgrimes "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", 1621541Srgrimes "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", 1631541Srgrimes "PROTORCV", "PROTOSEND", 1646223Swollman "SEND_EOF", 1651541Srgrimes}; 1661541Srgrimes#endif 1671541Srgrimes 16855205Speter#ifdef _KERNEL /* users shouldn't see this decl */ 16917047Swollman 17032995Sbdestruct ifnet; 17132995Sbdestruct stat; 17232995Sbdestruct ucred; 17332995Sbdestruct uio; 17432995Sbde 1751541Srgrimes/* 17617047Swollman * If the ordering here looks odd, that's because it's alphabetical. 17725201Swollman * Having this structure separated out from the main protoswitch is allegedly 17823888Swollman * a big (12 cycles per call) lose on high-end CPUs. We will eventually 17923888Swollman * migrate this stuff back into the main structure. 18017047Swollman */ 18117047Swollmanstruct pr_usrreqs { 18217047Swollman int (*pru_abort) __P((struct socket *so)); 18328270Swollman int (*pru_accept) __P((struct socket *so, struct sockaddr **nam)); 18425201Swollman int (*pru_attach) __P((struct socket *so, int proto, 18525201Swollman struct proc *p)); 18628270Swollman int (*pru_bind) __P((struct socket *so, struct sockaddr *nam, 18725201Swollman struct proc *p)); 18828270Swollman int (*pru_connect) __P((struct socket *so, struct sockaddr *nam, 18925201Swollman struct proc *p)); 19017047Swollman int (*pru_connect2) __P((struct socket *so1, struct socket *so2)); 19136735Sdfr int (*pru_control) __P((struct socket *so, u_long cmd, caddr_t data, 19225201Swollman struct ifnet *ifp, struct proc *p)); 19317047Swollman int (*pru_detach) __P((struct socket *so)); 19417047Swollman int (*pru_disconnect) __P((struct socket *so)); 19525201Swollman int (*pru_listen) __P((struct socket *so, struct proc *p)); 19628270Swollman int (*pru_peeraddr) __P((struct socket *so, 19728270Swollman struct sockaddr **nam)); 19817047Swollman int (*pru_rcvd) __P((struct socket *so, int flags)); 19917096Swollman int (*pru_rcvoob) __P((struct socket *so, struct mbuf *m, 20017096Swollman int flags)); 20117047Swollman int (*pru_send) __P((struct socket *so, int flags, struct mbuf *m, 20228270Swollman struct sockaddr *addr, struct mbuf *control, 20325201Swollman struct proc *p)); 20417047Swollman#define PRUS_OOB 0x1 20517047Swollman#define PRUS_EOF 0x2 20642902Sfenner#define PRUS_MORETOCOME 0x4 20717047Swollman int (*pru_sense) __P((struct socket *so, struct stat *sb)); 20817047Swollman int (*pru_shutdown) __P((struct socket *so)); 20928270Swollman int (*pru_sockaddr) __P((struct socket *so, 21028270Swollman struct sockaddr **nam)); 21123888Swollman 21223888Swollman /* 21325201Swollman * These three added later, so they are out of order. They are used 21423888Swollman * for shortcutting (fast path input/output) in some protocols. 21523888Swollman * XXX - that's a lie, they are not implemented yet 21625201Swollman * Rather than calling sosend() etc. directly, calls are made 21725201Swollman * through these entry points. For protocols which still use 21825201Swollman * the generic code, these just point to those routines. 21923888Swollman */ 22028270Swollman int (*pru_sosend) __P((struct socket *so, struct sockaddr *addr, 22123888Swollman struct uio *uio, struct mbuf *top, 22228270Swollman struct mbuf *control, int flags, 22328270Swollman struct proc *p)); 22428270Swollman int (*pru_soreceive) __P((struct socket *so, 22528270Swollman struct sockaddr **paddr, 22623888Swollman struct uio *uio, struct mbuf **mp0, 22723888Swollman struct mbuf **controlp, int *flagsp)); 22829350Speter int (*pru_sopoll) __P((struct socket *so, int events, 22929350Speter struct ucred *cred, struct proc *p)); 23017047Swollman}; 23117047Swollman 23228270Swollmanint pru_accept_notsupp __P((struct socket *so, struct sockaddr **nam)); 23328270Swollmanint pru_connect_notsupp __P((struct socket *so, struct sockaddr *nam, 23426096Speter struct proc *p)); 23517096Swollmanint pru_connect2_notsupp __P((struct socket *so1, struct socket *so2)); 23636735Sdfrint pru_control_notsupp __P((struct socket *so, u_long cmd, caddr_t data, 23725201Swollman struct ifnet *ifp, struct proc *p)); 23825201Swollmanint pru_listen_notsupp __P((struct socket *so, struct proc *p)); 23922901Swollmanint pru_rcvd_notsupp __P((struct socket *so, int flags)); 24022901Swollmanint pru_rcvoob_notsupp __P((struct socket *so, struct mbuf *m, int flags)); 24122901Swollmanint pru_sense_null __P((struct socket *so, struct stat *sb)); 24217096Swollman 24355205Speter#endif /* _KERNEL */ 24417047Swollman 24517047Swollman/* 2461541Srgrimes * The arguments to the ctlinput routine are 2471541Srgrimes * (*protosw[].pr_ctlinput)(cmd, sa, arg); 2481541Srgrimes * where cmd is one of the commands below, sa is a pointer to a sockaddr, 24912881Sbde * and arg is a `void *' argument used within a protocol family. 2501541Srgrimes */ 2511541Srgrimes#define PRC_IFDOWN 0 /* interface transition */ 2521541Srgrimes#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ 25322614Swollman#define PRC_IFUP 2 /* interface has come back up */ 2541541Srgrimes#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ 2551541Srgrimes#define PRC_QUENCH 4 /* some one said to slow down */ 2561541Srgrimes#define PRC_MSGSIZE 5 /* message size forced drop */ 2571541Srgrimes#define PRC_HOSTDEAD 6 /* host appears to be down */ 2581541Srgrimes#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ 2591541Srgrimes#define PRC_UNREACH_NET 8 /* no route to network */ 2601541Srgrimes#define PRC_UNREACH_HOST 9 /* no route to host */ 2611541Srgrimes#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ 2621541Srgrimes#define PRC_UNREACH_PORT 11 /* bad port # */ 2631541Srgrimes/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ 2641541Srgrimes#define PRC_UNREACH_SRCFAIL 13 /* source route failed */ 2651541Srgrimes#define PRC_REDIRECT_NET 14 /* net routing redirect */ 2661541Srgrimes#define PRC_REDIRECT_HOST 15 /* host routing redirect */ 2671541Srgrimes#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ 2681541Srgrimes#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ 2691541Srgrimes#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ 2701541Srgrimes#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ 2711541Srgrimes#define PRC_PARAMPROB 20 /* header incorrect */ 2721541Srgrimes 2731541Srgrimes#define PRC_NCMDS 21 2741541Srgrimes 2751541Srgrimes#define PRC_IS_REDIRECT(cmd) \ 2761541Srgrimes ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) 2771541Srgrimes 2781541Srgrimes#ifdef PRCREQUESTS 2791541Srgrimeschar *prcrequests[] = { 28022614Swollman "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2", 2811541Srgrimes "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", 2821541Srgrimes "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", 2831541Srgrimes "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", 2841541Srgrimes "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", 2851541Srgrimes "PARAMPROB" 2861541Srgrimes}; 2871541Srgrimes#endif 2881541Srgrimes 2891541Srgrimes/* 2901541Srgrimes * The arguments to ctloutput are: 29125201Swollman * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p); 2921541Srgrimes * req is one of the actions listed below, so is a (struct socket *), 2931541Srgrimes * level is an indication of which protocol layer the option is intended. 2941541Srgrimes * optname is a protocol dependent socket option request, 2951541Srgrimes * optval is a pointer to a mbuf-chain pointer, for value-return results. 2961541Srgrimes * The protocol is responsible for disposal of the mbuf chain *optval 2971541Srgrimes * if supplied, 2981541Srgrimes * the caller is responsible for any space held by *optval, when returned. 2991541Srgrimes * A non-zero return from usrreq gives an 3001541Srgrimes * UNIX error number which should be passed to higher level software. 3011541Srgrimes */ 3021541Srgrimes#define PRCO_GETOPT 0 3031541Srgrimes#define PRCO_SETOPT 1 3041541Srgrimes 3051541Srgrimes#define PRCO_NCMDS 2 3061541Srgrimes 3071541Srgrimes#ifdef PRCOREQUESTS 3081541Srgrimeschar *prcorequests[] = { 3091541Srgrimes "GETOPT", "SETOPT", 3101541Srgrimes}; 3111541Srgrimes#endif 3121541Srgrimes 31355205Speter#ifdef _KERNEL 31431927Sbdevoid pfctlinput __P((int, struct sockaddr *)); 31512453Sbdestruct protosw *pffindproto __P((int family, int protocol, int type)); 31612453Sbdestruct protosw *pffindtype __P((int family, int type)); 3171541Srgrimes#endif 3182165Spaul 3192165Spaul#endif 320