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