protosw.h revision 72638
1652Sjkh/*- 233473Sscrappy * Copyright (c) 1982, 1986, 1993 3139825Simp * The Regents of the University of California. All rights reserved. 4139825Simp * 5139825Simp * Redistribution and use in source and binary forms, with or without 6162588Snetchild * modification, are permitted provided that the following conditions 733473Sscrappy * are met: 8652Sjkh * 1. Redistributions of source code must retain the above copyright 9652Sjkh * notice, this list of conditions and the following disclaimer. 10652Sjkh * 2. Redistributions in binary form must reproduce the above copyright 11652Sjkh * notice, this list of conditions and the following disclaimer in the 12652Sjkh * documentation and/or other materials provided with the distribution. 13652Sjkh * 3. All advertising materials mentioning features or use of this software 1433473Sscrappy * must display the following acknowledgement: 1533473Sscrappy * This product includes software developed by the University of 1633473Sscrappy * California, Berkeley and its contributors. 1733473Sscrappy * 4. Neither the name of the University nor the names of its contributors 18652Sjkh * may be used to endorse or promote products derived from this software 1933473Sscrappy * without specific prior written permission. 2033473Sscrappy * 2133473Sscrappy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2233473Sscrappy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2333473Sscrappy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2433473Sscrappy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2533473Sscrappy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2633473Sscrappy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2733473Sscrappy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2833473Sscrappy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2933473Sscrappy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3033473Sscrappy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3150734Speter * SUCH DAMAGE. 3250734Speter * 33652Sjkh * @(#)protosw.h 8.1 (Berkeley) 6/2/93 34652Sjkh * $FreeBSD: head/sys/sys/protosw.h 72638 2001-02-18 09:34:55Z phk $ 35162588Snetchild */ 36162588Snetchild 37162588Snetchild#ifndef _SYS_PROTOSW_H_ 38162588Snetchild#define _SYS_PROTOSW_H_ 39162588Snetchild 40162588Snetchild/* 4150906Sdfr * For pfil_head structure. 4250906Sdfr */ 4365335Scg#include <net/pfil.h> 44652Sjkh 4565335Scg/* Forward declare these structures referenced from prototypes below. */ 4613765Smppstruct mbuf; 47652Sjkhstruct proc; 48652Sjkhstruct sockaddr; 49652Sjkhstruct socket; 503256Sswallacestruct sockopt; 5130866Smarkm 5230866Smarkm/*#ifdef _KERNEL*/ 5365335Scg/* 5482033Sgreid * Protocol switch table. 5530866Smarkm * 5630866Smarkm * Each protocol has a handle initializing one of these structures, 5782033Sgreid * which is used for protocol-protocol and system-protocol communication. 5830866Smarkm * 5930866Smarkm * A protocol is called through the pr_init entry before any other. 60652Sjkh * Thereafter it is called every 200ms through the pr_fasttimo entry and 61652Sjkh * every 500ms through the pr_slowtimo for timer based actions. 6233530Sscrappy * The system will call the pr_drain entry if it is low on space and 6333530Sscrappy * this should throw away any non-critical data. 6433530Sscrappy * 6533530Sscrappy * Protocols pass data between themselves as chains of mbufs using 6633530Sscrappy * the pr_input and pr_output hooks. Pr_input passes data up (towards 6733530Sscrappy * the users) and pr_output passes it down (towards the interfaces); control 6833530Sscrappy * information passes up and down on pr_ctlinput and pr_ctloutput. 6933530Sscrappy * The protocol is responsible for the space occupied by any the 7033530Sscrappy * arguments to these entries and must dispose it. 7133530Sscrappy * 7233530Sscrappy * In retrospect, it would be a lot nicer to use an interface 7333530Sscrappy * similar to the vnode VOP interface. 7433530Sscrappy */ 7533530Sscrappystruct protosw { 7633530Sscrappy short pr_type; /* socket type used for */ 7733530Sscrappy struct domain *pr_domain; /* domain protocol a member of */ 7833530Sscrappy short pr_protocol; /* protocol number */ 7933530Sscrappy short pr_flags; /* see below */ 8033530Sscrappy/* protocol-protocol hooks */ 8133530Sscrappy void (*pr_input) __P((struct mbuf *, int len)); 8233530Sscrappy /* input to protocol (from below) */ 8333530Sscrappy int (*pr_output) __P((struct mbuf *m, struct socket *so)); 8433530Sscrappy /* output to protocol (from above) */ 8533530Sscrappy void (*pr_ctlinput)__P((int, struct sockaddr *, void *)); 8633530Sscrappy /* control input (from below) */ 8733530Sscrappy int (*pr_ctloutput)__P((struct socket *, struct sockopt *)); 8833530Sscrappy /* control output (from above) */ 8933530Sscrappy/* user-protocol hook */ 9033530Sscrappy void *pr_ousrreq; 9133530Sscrappy/* utility hooks */ 9233530Sscrappy void (*pr_init) __P((void)); /* initialization hook */ 9333530Sscrappy void (*pr_fasttimo) __P((void)); 9433530Sscrappy /* fast timeout (200ms) */ 9533530Sscrappy void (*pr_slowtimo) __P((void)); 9633530Sscrappy /* slow timeout (500ms) */ 9733530Sscrappy void (*pr_drain) __P((void)); 9833530Sscrappy /* flush any excess space possible */ 9933530Sscrappy struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */ 10082033Sgreid struct pfil_head pr_pfh; 10145240Skato}; 10262947Stanimura/*#endif*/ 10362947Stanimura 10433530Sscrappy#define PR_SLOWHZ 2 /* 2 slow timeouts per second */ 10533473Sscrappy#define PR_FASTHZ 5 /* 5 fast timeouts per second */ 106114181Smbr 10733473Sscrappy/* 10833473Sscrappy * Values for pr_flags. 10933473Sscrappy * PR_ADDR requires PR_ATOMIC; 110652Sjkh * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. 111652Sjkh * PR_IMPLOPCL means that the protocol allows sendto without prior connect, 11233473Sscrappy * and the protocol understands the MSG_EOF flag. The first property is 11333473Sscrappy * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed 11433473Sscrappy * anyhow). 11533473Sscrappy */ 11633473Sscrappy#define PR_ATOMIC 0x01 /* exchange atomic messages only */ 117652Sjkh#define PR_ADDR 0x02 /* addresses given with messages */ 118652Sjkh#define PR_CONNREQUIRED 0x04 /* connection required by protocol */ 11933473Sscrappy#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ 12033473Sscrappy#define PR_RIGHTS 0x10 /* passes capabilities */ 12133473Sscrappy#define PR_IMPLOPCL 0x20 /* implied open/close */ 12233473Sscrappy 12333473Sscrappy/* 12433473Sscrappy * The arguments to usrreq are: 12533473Sscrappy * (*protosw[].pr_usrreq)(up, req, m, nam, opt); 12633473Sscrappy * where up is a (struct socket *), req is one of these requests, 12733473Sscrappy * m is a optional mbuf chain containing a message, 12833473Sscrappy * nam is an optional mbuf chain containing an address, 12933473Sscrappy * and opt is a pointer to a socketopt structure or nil. 13033473Sscrappy * The protocol is responsible for disposal of the mbuf chain m, 13133473Sscrappy * the caller is responsible for any space held by nam and opt. 13265335Scg * A non-zero return from usrreq gives an 13333473Sscrappy * UNIX error number which should be passed to higher level software. 13433473Sscrappy */ 13533473Sscrappy#define PRU_ATTACH 0 /* attach protocol to up */ 13633473Sscrappy#define PRU_DETACH 1 /* detach protocol from up */ 13733473Sscrappy#define PRU_BIND 2 /* bind socket to address */ 13833473Sscrappy#define PRU_LISTEN 3 /* listen for connection */ 13933473Sscrappy#define PRU_CONNECT 4 /* establish connection to peer */ 14033473Sscrappy#define PRU_ACCEPT 5 /* accept connection from peer */ 14133473Sscrappy#define PRU_DISCONNECT 6 /* disconnect from peer */ 142652Sjkh#define PRU_SHUTDOWN 7 /* won't send any more data */ 14330866Smarkm#define PRU_RCVD 8 /* have taken data; more room now */ 14433473Sscrappy#define PRU_SEND 9 /* send this data */ 14533473Sscrappy#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ 14633473Sscrappy#define PRU_CONTROL 11 /* control operations on protocol */ 14733473Sscrappy#define PRU_SENSE 12 /* return status into m */ 14833473Sscrappy#define PRU_RCVOOB 13 /* retrieve out of band data */ 14933473Sscrappy#define PRU_SENDOOB 14 /* send out of band data */ 15081891Ssobomax#define PRU_SOCKADDR 15 /* fetch socket's address */ 15181891Ssobomax#define PRU_PEERADDR 16 /* fetch peer's address */ 15281891Ssobomax#define PRU_CONNECT2 17 /* connect two sockets */ 15381891Ssobomax/* begin for protocols internal use */ 15481891Ssobomax#define PRU_FASTTIMO 18 /* 200ms timeout */ 15581891Ssobomax#define PRU_SLOWTIMO 19 /* 500ms timeout */ 15681891Ssobomax#define PRU_PROTORCV 20 /* receive from below */ 15733473Sscrappy#define PRU_PROTOSEND 21 /* send to below */ 15833473Sscrappy/* end for protocol's internal use */ 15981891Ssobomax#define PRU_SEND_EOF 22 /* send and close */ 16081891Ssobomax#define PRU_NREQ 22 16181891Ssobomax 16281891Ssobomax#ifdef PRUREQUESTS 16381891Ssobomaxchar *prurequests[] = { 16481891Ssobomax "ATTACH", "DETACH", "BIND", "LISTEN", 16581891Ssobomax "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", 16681891Ssobomax "RCVD", "SEND", "ABORT", "CONTROL", 16781891Ssobomax "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", 16881891Ssobomax "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", 16981891Ssobomax "PROTORCV", "PROTOSEND", 17081891Ssobomax "SEND_EOF", 17181891Ssobomax}; 17281891Ssobomax#endif 173114181Smbr 17465335Scg#ifdef _KERNEL /* users shouldn't see this decl */ 17581891Ssobomax 17681891Ssobomaxstruct ifnet; 17781891Ssobomaxstruct stat; 17865335Scgstruct ucred; 17981891Ssobomaxstruct uio; 18081891Ssobomax 18181891Ssobomax/* 18281891Ssobomax * If the ordering here looks odd, that's because it's alphabetical. 183148605Snetchild * Having this structure separated out from the main protoswitch is allegedly 184148605Snetchild * a big (12 cycles per call) lose on high-end CPUs. We will eventually 185148605Snetchild * migrate this stuff back into the main structure. 186148605Snetchild */ 18733473Sscrappystruct pr_usrreqs { 188193886Sariff int (*pru_abort) __P((struct socket *so)); 189193886Sariff int (*pru_accept) __P((struct socket *so, struct sockaddr **nam)); 190193886Sariff int (*pru_attach) __P((struct socket *so, int proto, 191193886Sariff struct proc *p)); 192193886Sariff int (*pru_bind) __P((struct socket *so, struct sockaddr *nam, 193193886Sariff struct proc *p)); 194193886Sariff int (*pru_connect) __P((struct socket *so, struct sockaddr *nam, 195193886Sariff struct proc *p)); 196193886Sariff int (*pru_connect2) __P((struct socket *so1, struct socket *so2)); 197193886Sariff int (*pru_control) __P((struct socket *so, u_long cmd, caddr_t data, 198193886Sariff struct ifnet *ifp, struct proc *p)); 199193886Sariff int (*pru_detach) __P((struct socket *so)); 200193886Sariff int (*pru_disconnect) __P((struct socket *so)); 201193886Sariff int (*pru_listen) __P((struct socket *so, struct proc *p)); 202193886Sariff int (*pru_peeraddr) __P((struct socket *so, 203193886Sariff struct sockaddr **nam)); 204193886Sariff int (*pru_rcvd) __P((struct socket *so, int flags)); 205193886Sariff int (*pru_rcvoob) __P((struct socket *so, struct mbuf *m, 206193886Sariff int flags)); 207193886Sariff int (*pru_send) __P((struct socket *so, int flags, struct mbuf *m, 208193886Sariff struct sockaddr *addr, struct mbuf *control, 209193886Sariff struct proc *p)); 210193886Sariff#define PRUS_OOB 0x1 211193886Sariff#define PRUS_EOF 0x2 212193886Sariff#define PRUS_MORETOCOME 0x4 213193886Sariff int (*pru_sense) __P((struct socket *so, struct stat *sb)); 214193886Sariff int (*pru_shutdown) __P((struct socket *so)); 215193886Sariff int (*pru_sockaddr) __P((struct socket *so, 216193886Sariff struct sockaddr **nam)); 21781891Ssobomax 21833473Sscrappy /* 21933473Sscrappy * These three added later, so they are out of order. They are used 22033473Sscrappy * for shortcutting (fast path input/output) in some protocols. 22133473Sscrappy * XXX - that's a lie, they are not implemented yet 22281891Ssobomax * Rather than calling sosend() etc. directly, calls are made 22333473Sscrappy * through these entry points. For protocols which still use 22433473Sscrappy * the generic code, these just point to those routines. 22533473Sscrappy */ 22633473Sscrappy int (*pru_sosend) __P((struct socket *so, struct sockaddr *addr, 22733473Sscrappy struct uio *uio, struct mbuf *top, 22833473Sscrappy struct mbuf *control, int flags, 22933473Sscrappy struct proc *p)); 23033473Sscrappy int (*pru_soreceive) __P((struct socket *so, 23181891Ssobomax struct sockaddr **paddr, 23233473Sscrappy struct uio *uio, struct mbuf **mp0, 23333473Sscrappy struct mbuf **controlp, int *flagsp)); 23433473Sscrappy int (*pru_sopoll) __P((struct socket *so, int events, 23533473Sscrappy struct ucred *cred, struct proc *p)); 23633473Sscrappy}; 23733473Sscrappy 23833473Sscrappyint pru_accept_notsupp __P((struct socket *so, struct sockaddr **nam)); 23933473Sscrappyint pru_connect_notsupp __P((struct socket *so, struct sockaddr *nam, 24033473Sscrappy struct proc *p)); 24133473Sscrappyint pru_connect2_notsupp __P((struct socket *so1, struct socket *so2)); 24233473Sscrappyint pru_control_notsupp __P((struct socket *so, u_long cmd, caddr_t data, 24333473Sscrappy struct ifnet *ifp, struct proc *p)); 24433473Sscrappyint pru_listen_notsupp __P((struct socket *so, struct proc *p)); 24533473Sscrappyint pru_rcvd_notsupp __P((struct socket *so, int flags)); 24633473Sscrappyint pru_rcvoob_notsupp __P((struct socket *so, struct mbuf *m, int flags)); 24733473Sscrappyint pru_sense_null __P((struct socket *so, struct stat *sb)); 24833473Sscrappy 24933473Sscrappy#endif /* _KERNEL */ 25033473Sscrappy 25133473Sscrappy/* 25233473Sscrappy * The arguments to the ctlinput routine are 25333473Sscrappy * (*protosw[].pr_ctlinput)(cmd, sa, arg); 25433473Sscrappy * where cmd is one of the commands below, sa is a pointer to a sockaddr, 25533473Sscrappy * and arg is a `void *' argument used within a protocol family. 25633473Sscrappy */ 25733473Sscrappy#define PRC_IFDOWN 0 /* interface transition */ 25833473Sscrappy#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ 25933473Sscrappy#define PRC_IFUP 2 /* interface has come back up */ 26033473Sscrappy#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ 26133473Sscrappy#define PRC_QUENCH 4 /* some one said to slow down */ 26233473Sscrappy#define PRC_MSGSIZE 5 /* message size forced drop */ 26333473Sscrappy#define PRC_HOSTDEAD 6 /* host appears to be down */ 26433473Sscrappy#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ 26533473Sscrappy#define PRC_UNREACH_NET 8 /* no route to network */ 26633473Sscrappy#define PRC_UNREACH_HOST 9 /* no route to host */ 26733473Sscrappy#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ 26833473Sscrappy#define PRC_UNREACH_PORT 11 /* bad port # */ 26933473Sscrappy/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ 27033473Sscrappy#define PRC_UNREACH_SRCFAIL 13 /* source route failed */ 27133473Sscrappy#define PRC_REDIRECT_NET 14 /* net routing redirect */ 27233473Sscrappy#define PRC_REDIRECT_HOST 15 /* host routing redirect */ 27333473Sscrappy#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ 27433473Sscrappy#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ 27533473Sscrappy#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ 27633473Sscrappy#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ 27733473Sscrappy#define PRC_PARAMPROB 20 /* header incorrect */ 27833473Sscrappy#define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */ 27933473Sscrappy 28033473Sscrappy#define PRC_NCMDS 22 28133473Sscrappy 28233473Sscrappy#define PRC_IS_REDIRECT(cmd) \ 28333473Sscrappy ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) 28433473Sscrappy 28533473Sscrappy#ifdef PRCREQUESTS 28633473Sscrappychar *prcrequests[] = { 28733473Sscrappy "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2", 28833473Sscrappy "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", 28933473Sscrappy "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", 29033473Sscrappy "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", 29133473Sscrappy "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", 29233473Sscrappy "PARAMPROB", "ADMIN-UNREACH" 29333473Sscrappy}; 29433473Sscrappy#endif 29533473Sscrappy 29633473Sscrappy/* 29733473Sscrappy * The arguments to ctloutput are: 29833473Sscrappy * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p); 29933473Sscrappy * req is one of the actions listed below, so is a (struct socket *), 30033473Sscrappy * level is an indication of which protocol layer the option is intended. 30133473Sscrappy * optname is a protocol dependent socket option request, 30233473Sscrappy * optval is a pointer to a mbuf-chain pointer, for value-return results. 30333473Sscrappy * The protocol is responsible for disposal of the mbuf chain *optval 30433473Sscrappy * if supplied, 30533473Sscrappy * the caller is responsible for any space held by *optval, when returned. 30633473Sscrappy * A non-zero return from usrreq gives an 30733473Sscrappy * UNIX error number which should be passed to higher level software. 30833473Sscrappy */ 30933473Sscrappy#define PRCO_GETOPT 0 31033473Sscrappy#define PRCO_SETOPT 1 311652Sjkh 312652Sjkh#define PRCO_NCMDS 2 313652Sjkh 314223662Savg#ifdef PRCOREQUESTS 31533473Sscrappychar *prcorequests[] = { 31633473Sscrappy "GETOPT", "SETOPT", 31733473Sscrappy}; 31833473Sscrappy#endif 31933473Sscrappy 32033473Sscrappy#ifdef _KERNEL 32133473Sscrappyvoid pfctlinput __P((int, struct sockaddr *)); 32233473Sscrappystruct protosw *pffindproto __P((int family, int protocol, int type)); 32333473Sscrappystruct protosw *pffindtype __P((int family, int type)); 32433473Sscrappy#endif 32533473Sscrappy 32633473Sscrappy#endif 32733473Sscrappy