xref: /illumos-gate/usr/src/uts/common/sys/protosw.h (revision b4203d75)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1991 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #ifndef _SYS_PROTOSW_H
41*7c478bd9Sstevel@tonic-gate #define	_SYS_PROTOSW_H
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
44*7c478bd9Sstevel@tonic-gate extern "C" {
45*7c478bd9Sstevel@tonic-gate #endif
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate /*
48*7c478bd9Sstevel@tonic-gate  * Protocol switch table.
49*7c478bd9Sstevel@tonic-gate  *
50*7c478bd9Sstevel@tonic-gate  * Each protocol has a handle initializing one of these structures,
51*7c478bd9Sstevel@tonic-gate  * which is used for protocol-protocol and system-protocol communication.
52*7c478bd9Sstevel@tonic-gate  *
53*7c478bd9Sstevel@tonic-gate  * A protocol is called through the pr_init entry before any other.
54*7c478bd9Sstevel@tonic-gate  * Thereafter it is called every 200ms through the pr_fasttimo entry and
55*7c478bd9Sstevel@tonic-gate  * every 500ms through the pr_slowtimo for timer based actions.
56*7c478bd9Sstevel@tonic-gate  * The system will call the pr_drain entry if it is low on space and
57*7c478bd9Sstevel@tonic-gate  * this should throw away any non-critical data.
58*7c478bd9Sstevel@tonic-gate  *
59*7c478bd9Sstevel@tonic-gate  * Protocols pass data between themselves as chains of mbufs using
60*7c478bd9Sstevel@tonic-gate  * the pr_input and pr_output hooks.  Pr_input passes data up (towards
61*7c478bd9Sstevel@tonic-gate  * UNIX) and pr_output passes it down (towards the imps); control
62*7c478bd9Sstevel@tonic-gate  * information passes up and down on pr_ctlinput and pr_ctloutput.
63*7c478bd9Sstevel@tonic-gate  * The protocol is responsible for the space occupied by any the
64*7c478bd9Sstevel@tonic-gate  * arguments to these entries and must dispose it.
65*7c478bd9Sstevel@tonic-gate  *
66*7c478bd9Sstevel@tonic-gate  * The userreq routine interfaces protocols to the system and is
67*7c478bd9Sstevel@tonic-gate  * described below.
68*7c478bd9Sstevel@tonic-gate  */
69*7c478bd9Sstevel@tonic-gate struct protosw {
70*7c478bd9Sstevel@tonic-gate 	short	pr_type;		/* socket type used for */
71*7c478bd9Sstevel@tonic-gate 	struct	domain *pr_domain;	/* domain protocol a member of */
72*7c478bd9Sstevel@tonic-gate 	short	pr_protocol;		/* protocol number */
73*7c478bd9Sstevel@tonic-gate 	short	pr_flags;		/* see below */
74*7c478bd9Sstevel@tonic-gate /* protocol-protocol hooks */
75*7c478bd9Sstevel@tonic-gate 	int	(*pr_input)();		/* input to protocol (from below) */
76*7c478bd9Sstevel@tonic-gate 	int	(*pr_output)();		/* output to protocol (from above) */
77*7c478bd9Sstevel@tonic-gate 	int	(*pr_ctlinput)();	/* control input (from below) */
78*7c478bd9Sstevel@tonic-gate 	int	(*pr_ctloutput)();	/* control output (from above) */
79*7c478bd9Sstevel@tonic-gate /* user-protocol hook */
80*7c478bd9Sstevel@tonic-gate 	int	(*pr_usrreq)();		/* user request: see list below */
81*7c478bd9Sstevel@tonic-gate /* utility hooks */
82*7c478bd9Sstevel@tonic-gate 	int	(*pr_init)();		/* initialization hook */
83*7c478bd9Sstevel@tonic-gate 	int	(*pr_fasttimo)();	/* fast timeout (200ms) */
84*7c478bd9Sstevel@tonic-gate 	int	(*pr_slowtimo)();	/* slow timeout (500ms) */
85*7c478bd9Sstevel@tonic-gate 	int	(*pr_drain)();		/* flush any excess space possible */
86*7c478bd9Sstevel@tonic-gate };
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate #define	PR_SLOWHZ	2		/* 2 slow timeouts per second */
89*7c478bd9Sstevel@tonic-gate #define	PR_FASTHZ	5		/* 5 fast timeouts per second */
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate /*
92*7c478bd9Sstevel@tonic-gate  * Values for pr_flags
93*7c478bd9Sstevel@tonic-gate  */
94*7c478bd9Sstevel@tonic-gate #define	PR_ATOMIC	0x01		/* exchange atomic messages only */
95*7c478bd9Sstevel@tonic-gate #define	PR_ADDR		0x02		/* addresses given with messages */
96*7c478bd9Sstevel@tonic-gate /* in the current implementation, PR_ADDR needs PR_ATOMIC to work */
97*7c478bd9Sstevel@tonic-gate #define	PR_CONNREQUIRED	0x04		/* connection required by protocol */
98*7c478bd9Sstevel@tonic-gate #define	PR_WANTRCVD	0x08		/* want PRU_RCVD calls */
99*7c478bd9Sstevel@tonic-gate #define	PR_RIGHTS	0x10		/* passes capabilities */
100*7c478bd9Sstevel@tonic-gate #define	PR_OOB_ADDR	0x20		/* addresses given with OOB data */
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate /*
103*7c478bd9Sstevel@tonic-gate  * The arguments to usrreq are:
104*7c478bd9Sstevel@tonic-gate  *	(*protosw[].pr_usrreq)(up, req, m, nam, opt);
105*7c478bd9Sstevel@tonic-gate  * where up is a (struct socket *), req is one of these requests,
106*7c478bd9Sstevel@tonic-gate  * m is a optional mbuf chain containing a message,
107*7c478bd9Sstevel@tonic-gate  * nam is an optional mbuf chain containing an address,
108*7c478bd9Sstevel@tonic-gate  * and opt is a pointer to a socketopt structure or nil.
109*7c478bd9Sstevel@tonic-gate  * The protocol is responsible for disposal of the mbuf chain m,
110*7c478bd9Sstevel@tonic-gate  * the caller is responsible for any space held by nam and opt.
111*7c478bd9Sstevel@tonic-gate  * A non-zero return from usrreq gives an
112*7c478bd9Sstevel@tonic-gate  * UNIX error number which should be passed to higher level software.
113*7c478bd9Sstevel@tonic-gate  */
114*7c478bd9Sstevel@tonic-gate #define	PRU_ATTACH		0	/* attach protocol to up */
115*7c478bd9Sstevel@tonic-gate #define	PRU_DETACH		1	/* detach protocol from up */
116*7c478bd9Sstevel@tonic-gate #define	PRU_BIND		2	/* bind socket to address */
117*7c478bd9Sstevel@tonic-gate #define	PRU_LISTEN		3	/* listen for connection */
118*7c478bd9Sstevel@tonic-gate #define	PRU_CONNECT		4	/* establish connection to peer */
119*7c478bd9Sstevel@tonic-gate #define	PRU_ACCEPT		5	/* accept connection from peer */
120*7c478bd9Sstevel@tonic-gate #define	PRU_DISCONNECT		6	/* disconnect from peer */
121*7c478bd9Sstevel@tonic-gate #define	PRU_SHUTDOWN		7	/* won't send any more data */
122*7c478bd9Sstevel@tonic-gate #define	PRU_RCVD		8	/* have taken data; more room now */
123*7c478bd9Sstevel@tonic-gate #define	PRU_SEND		9	/* send this data */
124*7c478bd9Sstevel@tonic-gate #define	PRU_ABORT		10	/* abort (fast DISCONNECT, DETATCH) */
125*7c478bd9Sstevel@tonic-gate #define	PRU_CONTROL		11	/* control operations on protocol */
126*7c478bd9Sstevel@tonic-gate #define	PRU_SENSE		12	/* return status into m */
127*7c478bd9Sstevel@tonic-gate #define	PRU_RCVOOB		13	/* retrieve out of band data */
128*7c478bd9Sstevel@tonic-gate #define	PRU_SENDOOB		14	/* send out of band data */
129*7c478bd9Sstevel@tonic-gate #define	PRU_SOCKADDR		15	/* fetch socket's address */
130*7c478bd9Sstevel@tonic-gate #define	PRU_PEERADDR		16	/* fetch peer's address */
131*7c478bd9Sstevel@tonic-gate #define	PRU_CONNECT2		17	/* connect two sockets */
132*7c478bd9Sstevel@tonic-gate /* begin for protocols internal use */
133*7c478bd9Sstevel@tonic-gate #define	PRU_FASTTIMO		18	/* 200ms timeout */
134*7c478bd9Sstevel@tonic-gate #define	PRU_SLOWTIMO		19	/* 500ms timeout */
135*7c478bd9Sstevel@tonic-gate #define	PRU_PROTORCV		20	/* receive from below */
136*7c478bd9Sstevel@tonic-gate #define	PRU_PROTOSEND		21	/* send to below */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate #define	PRU_NREQ		21
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate #ifdef PRUREQUESTS
141*7c478bd9Sstevel@tonic-gate char *prurequests[] = {
142*7c478bd9Sstevel@tonic-gate 	"ATTACH",	"DETACH",	"BIND",		"LISTEN",
143*7c478bd9Sstevel@tonic-gate 	"CONNECT",	"ACCEPT",	"DISCONNECT",	"SHUTDOWN",
144*7c478bd9Sstevel@tonic-gate 	"RCVD",		"SEND",		"ABORT",	"CONTROL",
145*7c478bd9Sstevel@tonic-gate 	"SENSE",	"RCVOOB",	"SENDOOB",	"SOCKADDR",
146*7c478bd9Sstevel@tonic-gate 	"PEERADDR",	"CONNECT2",	"FASTTIMO",	"SLOWTIMO",
147*7c478bd9Sstevel@tonic-gate 	"PROTORCV",	"PROTOSEND",
148*7c478bd9Sstevel@tonic-gate };
149*7c478bd9Sstevel@tonic-gate #endif
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate /*
152*7c478bd9Sstevel@tonic-gate  * The arguments to the ctlinput routine are
153*7c478bd9Sstevel@tonic-gate  *	(*protosw[].pr_ctlinput)(cmd, arg);
154*7c478bd9Sstevel@tonic-gate  * where cmd is one of the commands below, and arg is
155*7c478bd9Sstevel@tonic-gate  * an optional argument (caddr_t).
156*7c478bd9Sstevel@tonic-gate  *
157*7c478bd9Sstevel@tonic-gate  * N.B. The IMP code, in particular, pressumes the values
158*7c478bd9Sstevel@tonic-gate  *	of some of the commands; change with extreme care.
159*7c478bd9Sstevel@tonic-gate  * TODO:
160*7c478bd9Sstevel@tonic-gate  *	spread out codes so new ICMP codes can be
161*7c478bd9Sstevel@tonic-gate  *	accomodated more easily
162*7c478bd9Sstevel@tonic-gate  */
163*7c478bd9Sstevel@tonic-gate #define	PRC_IFDOWN		0	/* interface transition */
164*7c478bd9Sstevel@tonic-gate #define	PRC_ROUTEDEAD		1	/* select new route if possible */
165*7c478bd9Sstevel@tonic-gate #define	PRC_QUENCH		4	/* some said to slow down */
166*7c478bd9Sstevel@tonic-gate #define	PRC_MSGSIZE		5	/* message size forced drop */
167*7c478bd9Sstevel@tonic-gate #define	PRC_HOSTDEAD		6	/* normally from IMP */
168*7c478bd9Sstevel@tonic-gate #define	PRC_HOSTUNREACH		7	/* ditto */
169*7c478bd9Sstevel@tonic-gate #define	PRC_UNREACH_NET		8	/* no route to network */
170*7c478bd9Sstevel@tonic-gate #define	PRC_UNREACH_HOST	9	/* no route to host */
171*7c478bd9Sstevel@tonic-gate #define	PRC_UNREACH_PROTOCOL	10	/* dst says bad protocol */
172*7c478bd9Sstevel@tonic-gate #define	PRC_UNREACH_PORT	11	/* bad port # */
173*7c478bd9Sstevel@tonic-gate #define	PRC_UNREACH_NEEDFRAG	12	/* IP_DF caused drop */
174*7c478bd9Sstevel@tonic-gate #define	PRC_UNREACH_SRCFAIL	13	/* source route failed */
175*7c478bd9Sstevel@tonic-gate #define	PRC_REDIRECT_NET	14	/* net routing redirect */
176*7c478bd9Sstevel@tonic-gate #define	PRC_REDIRECT_HOST	15	/* host routing redirect */
177*7c478bd9Sstevel@tonic-gate #define	PRC_REDIRECT_TOSNET	16	/* redirect for type of service & net */
178*7c478bd9Sstevel@tonic-gate #define	PRC_REDIRECT_TOSHOST	17	/* redirect for tos & host */
179*7c478bd9Sstevel@tonic-gate #define	PRC_TIMXCEED_INTRANS	18	/* packet lifetime expired in transit */
180*7c478bd9Sstevel@tonic-gate #define	PRC_TIMXCEED_REASS	19	/* lifetime expired on reass q */
181*7c478bd9Sstevel@tonic-gate #define	PRC_PARAMPROB		20	/* header incorrect */
182*7c478bd9Sstevel@tonic-gate #define	PRC_GWDOWN		21	/* gateway down */
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate #define	PRC_NCMDS		22
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate #ifdef PRCREQUESTS
187*7c478bd9Sstevel@tonic-gate char	*prcrequests[] = {
188*7c478bd9Sstevel@tonic-gate 	"IFDOWN", "ROUTEDEAD", "#2", "#3",
189*7c478bd9Sstevel@tonic-gate 	"QUENCH", "MSGSIZE", "HOSTDEAD", "HOSTUNREACH",
190*7c478bd9Sstevel@tonic-gate 	"NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
191*7c478bd9Sstevel@tonic-gate 	"FRAG-UNREACH", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
192*7c478bd9Sstevel@tonic-gate 	"TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
193*7c478bd9Sstevel@tonic-gate 	"PARAMPROB"
194*7c478bd9Sstevel@tonic-gate };
195*7c478bd9Sstevel@tonic-gate #endif
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate /*
198*7c478bd9Sstevel@tonic-gate  * The arguments to ctloutput are:
199*7c478bd9Sstevel@tonic-gate  *	(*protosw[].pr_ctloutput)(req, so, level, optname, optval);
200*7c478bd9Sstevel@tonic-gate  * req is one of the actions listed below, so is a (struct socket *),
201*7c478bd9Sstevel@tonic-gate  * level is an indication of which protocol layer the option is intended.
202*7c478bd9Sstevel@tonic-gate  * optname is a protocol dependent socket option request,
203*7c478bd9Sstevel@tonic-gate  * optval is a pointer to a mbuf-chain pointer, for value-return results.
204*7c478bd9Sstevel@tonic-gate  * The protocol is responsible for disposal of the mbuf chain *optval
205*7c478bd9Sstevel@tonic-gate  * if supplied,
206*7c478bd9Sstevel@tonic-gate  * the caller is responsible for any space held by *optval, when returned.
207*7c478bd9Sstevel@tonic-gate  * A non-zero return from usrreq gives an
208*7c478bd9Sstevel@tonic-gate  * UNIX error number which should be passed to higher level software.
209*7c478bd9Sstevel@tonic-gate  */
210*7c478bd9Sstevel@tonic-gate #define	PRCO_GETOPT	0
211*7c478bd9Sstevel@tonic-gate #define	PRCO_SETOPT	1
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate #define	PRCO_NCMDS	2
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate #ifdef PRCOREQUESTS
216*7c478bd9Sstevel@tonic-gate char	*prcorequests[] = {
217*7c478bd9Sstevel@tonic-gate 	"GETOPT", "SETOPT",
218*7c478bd9Sstevel@tonic-gate };
219*7c478bd9Sstevel@tonic-gate #endif
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
222*7c478bd9Sstevel@tonic-gate extern	struct protosw *pffindproto(), *pffindtype();
223*7c478bd9Sstevel@tonic-gate #endif
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
226*7c478bd9Sstevel@tonic-gate }
227*7c478bd9Sstevel@tonic-gate #endif
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_PROTOSW_H */
230