protosw.h revision 83366
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 83366 2001-09-12 08:38:13Z julian $
351541Srgrimes */
361541Srgrimes
372165Spaul#ifndef _SYS_PROTOSW_H_
382165Spaul#define _SYS_PROTOSW_H_
392165Spaul
4064060Sdarrenr/*
4164060Sdarrenr * For pfil_head structure.
4264060Sdarrenr */
4364060Sdarrenr#include <net/pfil.h>
4464060Sdarrenr
4523888Swollman/* Forward declare these structures referenced from prototypes below. */
4612453Sbdestruct mbuf;
4783366Sjulianstruct thread;
4812453Sbdestruct sockaddr;
4912453Sbdestruct socket;
5038482Swollmanstruct sockopt;
5112453Sbde
5255205Speter/*#ifdef _KERNEL*/
531541Srgrimes/*
541541Srgrimes * Protocol switch table.
551541Srgrimes *
561541Srgrimes * Each protocol has a handle initializing one of these structures,
571541Srgrimes * which is used for protocol-protocol and system-protocol communication.
581541Srgrimes *
591541Srgrimes * A protocol is called through the pr_init entry before any other.
601541Srgrimes * Thereafter it is called every 200ms through the pr_fasttimo entry and
611541Srgrimes * every 500ms through the pr_slowtimo for timer based actions.
621541Srgrimes * The system will call the pr_drain entry if it is low on space and
631541Srgrimes * this should throw away any non-critical data.
641541Srgrimes *
651541Srgrimes * Protocols pass data between themselves as chains of mbufs using
661541Srgrimes * the pr_input and pr_output hooks.  Pr_input passes data up (towards
6738482Swollman * the users) and pr_output passes it down (towards the interfaces); control
681541Srgrimes * information passes up and down on pr_ctlinput and pr_ctloutput.
691541Srgrimes * The protocol is responsible for the space occupied by any the
701541Srgrimes * arguments to these entries and must dispose it.
711541Srgrimes *
7238482Swollman * In retrospect, it would be a lot nicer to use an interface
7338482Swollman * similar to the vnode VOP interface.
741541Srgrimes */
7581501Sjulian/* USE THESE FOR YOUR PROTOTYPES ! */
7681501Sjuliantypedef void	pr_input_t (struct mbuf *, int);
7782824Sjuliantypedef int	pr_input6_t (struct mbuf **, int*, int);  /* XXX FIX THIS */
7881501Sjuliantypedef void	pr_in_input_t (struct mbuf *, int, int); /* XXX FIX THIS */
7981501Sjuliantypedef int	pr_output_t (struct mbuf *, struct socket *);
8082824Sjuliantypedef int	pr_in_output_t (struct mbuf *, struct socket *, struct sockaddr *);
8181501Sjuliantypedef void	pr_ctlinput_t (int, struct sockaddr *, void *);
8281501Sjuliantypedef int	pr_ctloutput_t (struct socket *, struct sockopt *);
8381501Sjuliantypedef	void	pr_init_t (void);
8481501Sjuliantypedef	void	pr_fasttimo_t (void);
8581501Sjuliantypedef	void	pr_slowtimo_t (void);
8681501Sjuliantypedef	void	pr_drain_t (void);
8781501Sjulian
8882824Sjuliantypedef int	pr_usrreq_t(struct socket *, int, struct mbuf *,
8983366Sjulian			     struct mbuf *, struct mbuf *, struct thread *);
9081501Sjulian
911541Srgrimesstruct protosw {
921541Srgrimes	short	pr_type;		/* socket type used for */
931541Srgrimes	struct	domain *pr_domain;	/* domain protocol a member of */
941541Srgrimes	short	pr_protocol;		/* protocol number */
951541Srgrimes	short	pr_flags;		/* see below */
961541Srgrimes/* protocol-protocol hooks */
9781501Sjulian	pr_input_t *pr_input;		/* input to protocol (from below) */
9881501Sjulian	pr_output_t *pr_output;		/* output to protocol (from above) */
9981501Sjulian	pr_ctlinput_t *pr_ctlinput;	/* control input (from below) */
10081501Sjulian	pr_ctloutput_t *pr_ctloutput;	/* control output (from above) */
1011541Srgrimes/* user-protocol hook */
10282824Sjulian	pr_usrreq_t	*pr_ousrreq;
1031541Srgrimes/* utility hooks */
10481501Sjulian	pr_init_t *pr_init;
10581501Sjulian	pr_fasttimo_t *pr_fasttimo;	/* fast timeout (200ms) */
10681501Sjulian	pr_slowtimo_t *pr_slowtimo;	/* slow timeout (500ms) */
10781501Sjulian	pr_drain_t *pr_drain;		/* flush any excess space possible */
10881501Sjulian
10917047Swollman	struct	pr_usrreqs *pr_usrreqs;	/* supersedes pr_usrreq() */
11064060Sdarrenr	struct	pfil_head	pr_pfh;
1111541Srgrimes};
11228270Swollman/*#endif*/
1131541Srgrimes
1141541Srgrimes#define	PR_SLOWHZ	2		/* 2 slow timeouts per second */
1151541Srgrimes#define	PR_FASTHZ	5		/* 5 fast timeouts per second */
1161541Srgrimes
1171541Srgrimes/*
1181541Srgrimes * Values for pr_flags.
1191541Srgrimes * PR_ADDR requires PR_ATOMIC;
1201541Srgrimes * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
1216223Swollman * PR_IMPLOPCL means that the protocol allows sendto without prior connect,
1226223Swollman *	and the protocol understands the MSG_EOF flag.  The first property is
1236223Swollman *	is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed
1246223Swollman *	anyhow).
1251541Srgrimes */
1261541Srgrimes#define	PR_ATOMIC	0x01		/* exchange atomic messages only */
1271541Srgrimes#define	PR_ADDR		0x02		/* addresses given with messages */
1281541Srgrimes#define	PR_CONNREQUIRED	0x04		/* connection required by protocol */
1291541Srgrimes#define	PR_WANTRCVD	0x08		/* want PRU_RCVD calls */
1301541Srgrimes#define	PR_RIGHTS	0x10		/* passes capabilities */
1316223Swollman#define PR_IMPLOPCL	0x20		/* implied open/close */
13278064Sume#define	PR_LASTHDR	0x40		/* enforce ipsec policy; last header */
1331541Srgrimes
1341541Srgrimes/*
1351541Srgrimes * The arguments to usrreq are:
1361541Srgrimes *	(*protosw[].pr_usrreq)(up, req, m, nam, opt);
1371541Srgrimes * where up is a (struct socket *), req is one of these requests,
1381541Srgrimes * m is a optional mbuf chain containing a message,
1391541Srgrimes * nam is an optional mbuf chain containing an address,
1401541Srgrimes * and opt is a pointer to a socketopt structure or nil.
1411541Srgrimes * The protocol is responsible for disposal of the mbuf chain m,
1421541Srgrimes * the caller is responsible for any space held by nam and opt.
1431541Srgrimes * A non-zero return from usrreq gives an
1441541Srgrimes * UNIX error number which should be passed to higher level software.
1451541Srgrimes */
1461541Srgrimes#define	PRU_ATTACH		0	/* attach protocol to up */
1471541Srgrimes#define	PRU_DETACH		1	/* detach protocol from up */
1481541Srgrimes#define	PRU_BIND		2	/* bind socket to address */
1491541Srgrimes#define	PRU_LISTEN		3	/* listen for connection */
1501541Srgrimes#define	PRU_CONNECT		4	/* establish connection to peer */
1511541Srgrimes#define	PRU_ACCEPT		5	/* accept connection from peer */
1521541Srgrimes#define	PRU_DISCONNECT		6	/* disconnect from peer */
1531541Srgrimes#define	PRU_SHUTDOWN		7	/* won't send any more data */
1541541Srgrimes#define	PRU_RCVD		8	/* have taken data; more room now */
1551541Srgrimes#define	PRU_SEND		9	/* send this data */
1561541Srgrimes#define	PRU_ABORT		10	/* abort (fast DISCONNECT, DETATCH) */
1571541Srgrimes#define	PRU_CONTROL		11	/* control operations on protocol */
1581541Srgrimes#define	PRU_SENSE		12	/* return status into m */
1591541Srgrimes#define	PRU_RCVOOB		13	/* retrieve out of band data */
1601541Srgrimes#define	PRU_SENDOOB		14	/* send out of band data */
1611541Srgrimes#define	PRU_SOCKADDR		15	/* fetch socket's address */
1621541Srgrimes#define	PRU_PEERADDR		16	/* fetch peer's address */
1631541Srgrimes#define	PRU_CONNECT2		17	/* connect two sockets */
1641541Srgrimes/* begin for protocols internal use */
1651541Srgrimes#define	PRU_FASTTIMO		18	/* 200ms timeout */
1661541Srgrimes#define	PRU_SLOWTIMO		19	/* 500ms timeout */
1671541Srgrimes#define	PRU_PROTORCV		20	/* receive from below */
1681541Srgrimes#define	PRU_PROTOSEND		21	/* send to below */
16917047Swollman/* end for protocol's internal use */
1706223Swollman#define PRU_SEND_EOF		22	/* send and close */
1716223Swollman#define PRU_NREQ		22
1721541Srgrimes
1731541Srgrimes#ifdef PRUREQUESTS
1741541Srgrimeschar *prurequests[] = {
1751541Srgrimes	"ATTACH",	"DETACH",	"BIND",		"LISTEN",
1761541Srgrimes	"CONNECT",	"ACCEPT",	"DISCONNECT",	"SHUTDOWN",
1771541Srgrimes	"RCVD",		"SEND",		"ABORT",	"CONTROL",
1781541Srgrimes	"SENSE",	"RCVOOB",	"SENDOOB",	"SOCKADDR",
1791541Srgrimes	"PEERADDR",	"CONNECT2",	"FASTTIMO",	"SLOWTIMO",
1801541Srgrimes	"PROTORCV",	"PROTOSEND",
1816223Swollman	"SEND_EOF",
1821541Srgrimes};
1831541Srgrimes#endif
1841541Srgrimes
18555205Speter#ifdef	_KERNEL			/* users shouldn't see this decl */
18617047Swollman
18732995Sbdestruct ifnet;
18832995Sbdestruct stat;
18932995Sbdestruct ucred;
19032995Sbdestruct uio;
19132995Sbde
1921541Srgrimes/*
19317047Swollman * If the ordering here looks odd, that's because it's alphabetical.
19425201Swollman * Having this structure separated out from the main protoswitch is allegedly
19523888Swollman * a big (12 cycles per call) lose on high-end CPUs.  We will eventually
19623888Swollman * migrate this stuff back into the main structure.
19717047Swollman */
19817047Swollmanstruct pr_usrreqs {
19917047Swollman	int	(*pru_abort) __P((struct socket *so));
20028270Swollman	int	(*pru_accept) __P((struct socket *so, struct sockaddr **nam));
20125201Swollman	int	(*pru_attach) __P((struct socket *so, int proto,
20283366Sjulian				   struct thread *td));
20328270Swollman	int	(*pru_bind) __P((struct socket *so, struct sockaddr *nam,
20483366Sjulian				 struct thread *td));
20528270Swollman	int	(*pru_connect) __P((struct socket *so, struct sockaddr *nam,
20683366Sjulian				    struct thread *td));
20717047Swollman	int	(*pru_connect2) __P((struct socket *so1, struct socket *so2));
20836735Sdfr	int	(*pru_control) __P((struct socket *so, u_long cmd, caddr_t data,
20983366Sjulian				    struct ifnet *ifp, struct thread *td));
21017047Swollman	int	(*pru_detach) __P((struct socket *so));
21117047Swollman	int	(*pru_disconnect) __P((struct socket *so));
21283366Sjulian	int	(*pru_listen) __P((struct socket *so, struct thread *td));
21328270Swollman	int	(*pru_peeraddr) __P((struct socket *so,
21428270Swollman				     struct sockaddr **nam));
21517047Swollman	int	(*pru_rcvd) __P((struct socket *so, int flags));
21617096Swollman	int	(*pru_rcvoob) __P((struct socket *so, struct mbuf *m,
21717096Swollman				   int flags));
21817047Swollman	int	(*pru_send) __P((struct socket *so, int flags, struct mbuf *m,
21928270Swollman				 struct sockaddr *addr, struct mbuf *control,
22083366Sjulian				 struct thread *td));
22117047Swollman#define	PRUS_OOB	0x1
22217047Swollman#define	PRUS_EOF	0x2
22342902Sfenner#define	PRUS_MORETOCOME	0x4
22417047Swollman	int	(*pru_sense) __P((struct socket *so, struct stat *sb));
22517047Swollman	int	(*pru_shutdown) __P((struct socket *so));
22628270Swollman	int	(*pru_sockaddr) __P((struct socket *so,
22728270Swollman				     struct sockaddr **nam));
22823888Swollman
22923888Swollman	/*
23025201Swollman	 * These three added later, so they are out of order.  They are used
23123888Swollman	 * for shortcutting (fast path input/output) in some protocols.
23223888Swollman	 * XXX - that's a lie, they are not implemented yet
23325201Swollman	 * Rather than calling sosend() etc. directly, calls are made
23425201Swollman	 * through these entry points.  For protocols which still use
23525201Swollman	 * the generic code, these just point to those routines.
23623888Swollman	 */
23728270Swollman	int	(*pru_sosend) __P((struct socket *so, struct sockaddr *addr,
23823888Swollman				   struct uio *uio, struct mbuf *top,
23928270Swollman				   struct mbuf *control, int flags,
24083366Sjulian				   struct thread *td));
24128270Swollman	int	(*pru_soreceive) __P((struct socket *so,
24228270Swollman				      struct sockaddr **paddr,
24323888Swollman				      struct uio *uio, struct mbuf **mp0,
24423888Swollman				      struct mbuf **controlp, int *flagsp));
24529350Speter	int	(*pru_sopoll) __P((struct socket *so, int events,
24683366Sjulian				     struct ucred *cred, struct thread *td));
24717047Swollman};
24817047Swollman
24928270Swollmanint	pru_accept_notsupp __P((struct socket *so, struct sockaddr **nam));
25028270Swollmanint	pru_connect_notsupp __P((struct socket *so, struct sockaddr *nam,
25183366Sjulian				 struct thread *td));
25217096Swollmanint	pru_connect2_notsupp __P((struct socket *so1, struct socket *so2));
25336735Sdfrint	pru_control_notsupp __P((struct socket *so, u_long cmd, caddr_t data,
25483366Sjulian				 struct ifnet *ifp, struct thread *td));
25583366Sjulianint	pru_listen_notsupp __P((struct socket *so, struct thread *td));
25622901Swollmanint	pru_rcvd_notsupp __P((struct socket *so, int flags));
25722901Swollmanint	pru_rcvoob_notsupp __P((struct socket *so, struct mbuf *m, int flags));
25822901Swollmanint	pru_sense_null __P((struct socket *so, struct stat *sb));
25917096Swollman
26055205Speter#endif /* _KERNEL */
26117047Swollman
26217047Swollman/*
2631541Srgrimes * The arguments to the ctlinput routine are
2641541Srgrimes *	(*protosw[].pr_ctlinput)(cmd, sa, arg);
2651541Srgrimes * where cmd is one of the commands below, sa is a pointer to a sockaddr,
26612881Sbde * and arg is a `void *' argument used within a protocol family.
2671541Srgrimes */
2681541Srgrimes#define	PRC_IFDOWN		0	/* interface transition */
2691541Srgrimes#define	PRC_ROUTEDEAD		1	/* select new route if possible ??? */
27022614Swollman#define	PRC_IFUP		2 	/* interface has come back up */
2711541Srgrimes#define	PRC_QUENCH2		3	/* DEC congestion bit says slow down */
2721541Srgrimes#define	PRC_QUENCH		4	/* some one said to slow down */
2731541Srgrimes#define	PRC_MSGSIZE		5	/* message size forced drop */
2741541Srgrimes#define	PRC_HOSTDEAD		6	/* host appears to be down */
2751541Srgrimes#define	PRC_HOSTUNREACH		7	/* deprecated (use PRC_UNREACH_HOST) */
2761541Srgrimes#define	PRC_UNREACH_NET		8	/* no route to network */
2771541Srgrimes#define	PRC_UNREACH_HOST	9	/* no route to host */
2781541Srgrimes#define	PRC_UNREACH_PROTOCOL	10	/* dst says bad protocol */
2791541Srgrimes#define	PRC_UNREACH_PORT	11	/* bad port # */
2801541Srgrimes/* was	PRC_UNREACH_NEEDFRAG	12	   (use PRC_MSGSIZE) */
2811541Srgrimes#define	PRC_UNREACH_SRCFAIL	13	/* source route failed */
2821541Srgrimes#define	PRC_REDIRECT_NET	14	/* net routing redirect */
2831541Srgrimes#define	PRC_REDIRECT_HOST	15	/* host routing redirect */
2841541Srgrimes#define	PRC_REDIRECT_TOSNET	16	/* redirect for type of service & net */
2851541Srgrimes#define	PRC_REDIRECT_TOSHOST	17	/* redirect for tos & host */
2861541Srgrimes#define	PRC_TIMXCEED_INTRANS	18	/* packet lifetime expired in transit */
2871541Srgrimes#define	PRC_TIMXCEED_REASS	19	/* lifetime expired on reass q */
2881541Srgrimes#define	PRC_PARAMPROB		20	/* header incorrect */
28972638Sphk#define	PRC_UNREACH_ADMIN_PROHIB	21	/* packet administrativly prohibited */
2901541Srgrimes
29172638Sphk#define	PRC_NCMDS		22
2921541Srgrimes
2931541Srgrimes#define	PRC_IS_REDIRECT(cmd)	\
2941541Srgrimes	((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
2951541Srgrimes
2961541Srgrimes#ifdef PRCREQUESTS
2971541Srgrimeschar	*prcrequests[] = {
29822614Swollman	"IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2",
2991541Srgrimes	"QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
3001541Srgrimes	"NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
3011541Srgrimes	"#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
3021541Srgrimes	"TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
30372638Sphk	"PARAMPROB", "ADMIN-UNREACH"
3041541Srgrimes};
3051541Srgrimes#endif
3061541Srgrimes
3071541Srgrimes/*
3081541Srgrimes * The arguments to ctloutput are:
30925201Swollman *	(*protosw[].pr_ctloutput)(req, so, level, optname, optval, p);
3101541Srgrimes * req is one of the actions listed below, so is a (struct socket *),
3111541Srgrimes * level is an indication of which protocol layer the option is intended.
3121541Srgrimes * optname is a protocol dependent socket option request,
3131541Srgrimes * optval is a pointer to a mbuf-chain pointer, for value-return results.
3141541Srgrimes * The protocol is responsible for disposal of the mbuf chain *optval
3151541Srgrimes * if supplied,
3161541Srgrimes * the caller is responsible for any space held by *optval, when returned.
3171541Srgrimes * A non-zero return from usrreq gives an
3181541Srgrimes * UNIX error number which should be passed to higher level software.
3191541Srgrimes */
3201541Srgrimes#define	PRCO_GETOPT	0
3211541Srgrimes#define	PRCO_SETOPT	1
3221541Srgrimes
3231541Srgrimes#define	PRCO_NCMDS	2
3241541Srgrimes
3251541Srgrimes#ifdef PRCOREQUESTS
3261541Srgrimeschar	*prcorequests[] = {
3271541Srgrimes	"GETOPT", "SETOPT",
3281541Srgrimes};
3291541Srgrimes#endif
3301541Srgrimes
33155205Speter#ifdef _KERNEL
33231927Sbdevoid	pfctlinput __P((int, struct sockaddr *));
33378064Sumevoid	pfctlinput2 __P((int, struct sockaddr *, void *));
33412453Sbdestruct protosw *pffindproto __P((int family, int protocol, int type));
33512453Sbdestruct protosw *pffindtype __P((int family, int type));
3361541Srgrimes#endif
3372165Spaul
3382165Spaul#endif
339