xref: /original-bsd/sys/sys/protosw.h (revision 95a66346)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted provided
6  * that: (1) source distributions retain this entire copyright notice and
7  * comment, and (2) distributions including binaries display the following
8  * acknowledgement:  ``This product includes software developed by the
9  * University of California, Berkeley and its contributors'' in the
10  * documentation or other materials provided with the distribution and in
11  * all advertising materials mentioning features or use of this software.
12  * Neither the name of the University nor the names of its contributors may
13  * be used to endorse or promote products derived from this software without
14  * specific prior written permission.
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
16  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  *	@(#)protosw.h	7.6 (Berkeley) 6/28/90
20  */
21 
22 /*
23  * Protocol switch table.
24  *
25  * Each protocol has a handle initializing one of these structures,
26  * which is used for protocol-protocol and system-protocol communication.
27  *
28  * A protocol is called through the pr_init entry before any other.
29  * Thereafter it is called every 200ms through the pr_fasttimo entry and
30  * every 500ms through the pr_slowtimo for timer based actions.
31  * The system will call the pr_drain entry if it is low on space and
32  * this should throw away any non-critical data.
33  *
34  * Protocols pass data between themselves as chains of mbufs using
35  * the pr_input and pr_output hooks.  Pr_input passes data up (towards
36  * UNIX) and pr_output passes it down (towards the imps); control
37  * information passes up and down on pr_ctlinput and pr_ctloutput.
38  * The protocol is responsible for the space occupied by any the
39  * arguments to these entries and must dispose it.
40  *
41  * The userreq routine interfaces protocols to the system and is
42  * described below.
43  */
44 struct protosw {
45 	short	pr_type;		/* socket type used for */
46 	struct	domain *pr_domain;	/* domain protocol a member of */
47 	short	pr_protocol;		/* protocol number */
48 	short	pr_flags;		/* see below */
49 /* protocol-protocol hooks */
50 	int	(*pr_input)();		/* input to protocol (from below) */
51 	int	(*pr_output)();		/* output to protocol (from above) */
52 	int	(*pr_ctlinput)();	/* control input (from below) */
53 	int	(*pr_ctloutput)();	/* control output (from above) */
54 /* user-protocol hook */
55 	int	(*pr_usrreq)();		/* user request: see list below */
56 /* utility hooks */
57 	int	(*pr_init)();		/* initialization hook */
58 	int	(*pr_fasttimo)();	/* fast timeout (200ms) */
59 	int	(*pr_slowtimo)();	/* slow timeout (500ms) */
60 	int	(*pr_drain)();		/* flush any excess space possible */
61 };
62 
63 #define	PR_SLOWHZ	2		/* 2 slow timeouts per second */
64 #define	PR_FASTHZ	5		/* 5 fast timeouts per second */
65 
66 /*
67  * Values for pr_flags.
68  * PR_ADDR requires PR_ATOMIC;
69  * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
70  */
71 #define	PR_ATOMIC	0x01		/* exchange atomic messages only */
72 #define	PR_ADDR		0x02		/* addresses given with messages */
73 #define	PR_CONNREQUIRED	0x04		/* connection required by protocol */
74 #define	PR_WANTRCVD	0x08		/* want PRU_RCVD calls */
75 #define	PR_RIGHTS	0x10		/* passes capabilities */
76 
77 /*
78  * The arguments to usrreq are:
79  *	(*protosw[].pr_usrreq)(up, req, m, nam, opt);
80  * where up is a (struct socket *), req is one of these requests,
81  * m is a optional mbuf chain containing a message,
82  * nam is an optional mbuf chain containing an address,
83  * and opt is a pointer to a socketopt structure or nil.
84  * The protocol is responsible for disposal of the mbuf chain m,
85  * the caller is responsible for any space held by nam and opt.
86  * A non-zero return from usrreq gives an
87  * UNIX error number which should be passed to higher level software.
88  */
89 #define	PRU_ATTACH		0	/* attach protocol to up */
90 #define	PRU_DETACH		1	/* detach protocol from up */
91 #define	PRU_BIND		2	/* bind socket to address */
92 #define	PRU_LISTEN		3	/* listen for connection */
93 #define	PRU_CONNECT		4	/* establish connection to peer */
94 #define	PRU_ACCEPT		5	/* accept connection from peer */
95 #define	PRU_DISCONNECT		6	/* disconnect from peer */
96 #define	PRU_SHUTDOWN		7	/* won't send any more data */
97 #define	PRU_RCVD		8	/* have taken data; more room now */
98 #define	PRU_SEND		9	/* send this data */
99 #define	PRU_ABORT		10	/* abort (fast DISCONNECT, DETATCH) */
100 #define	PRU_CONTROL		11	/* control operations on protocol */
101 #define	PRU_SENSE		12	/* return status into m */
102 #define	PRU_RCVOOB		13	/* retrieve out of band data */
103 #define	PRU_SENDOOB		14	/* send out of band data */
104 #define	PRU_SOCKADDR		15	/* fetch socket's address */
105 #define	PRU_PEERADDR		16	/* fetch peer's address */
106 #define	PRU_CONNECT2		17	/* connect two sockets */
107 /* begin for protocols internal use */
108 #define	PRU_FASTTIMO		18	/* 200ms timeout */
109 #define	PRU_SLOWTIMO		19	/* 500ms timeout */
110 #define	PRU_PROTORCV		20	/* receive from below */
111 #define	PRU_PROTOSEND		21	/* send to below */
112 
113 #define	PRU_NREQ		21
114 
115 #ifdef PRUREQUESTS
116 char *prurequests[] = {
117 	"ATTACH",	"DETACH",	"BIND",		"LISTEN",
118 	"CONNECT",	"ACCEPT",	"DISCONNECT",	"SHUTDOWN",
119 	"RCVD",		"SEND",		"ABORT",	"CONTROL",
120 	"SENSE",	"RCVOOB",	"SENDOOB",	"SOCKADDR",
121 	"PEERADDR",	"CONNECT2",	"FASTTIMO",	"SLOWTIMO",
122 	"PROTORCV",	"PROTOSEND",
123 };
124 #endif
125 
126 /*
127  * The arguments to the ctlinput routine are
128  *	(*protosw[].pr_ctlinput)(cmd, sa, arg);
129  * where cmd is one of the commands below, sa is a pointer to a sockaddr,
130  * and arg is an optional caddr_t argument used within a protocol family.
131  */
132 #define	PRC_IFDOWN		0	/* interface transition */
133 #define	PRC_ROUTEDEAD		1	/* select new route if possible ??? */
134 #define	PRC_QUENCH2		3	/* DEC congestion bit says slow down */
135 #define	PRC_QUENCH		4	/* some one said to slow down */
136 #define	PRC_MSGSIZE		5	/* message size forced drop */
137 #define	PRC_HOSTDEAD		6	/* host appears to be down */
138 #define	PRC_HOSTUNREACH		7	/* deprecated (use PRC_UNREACH_HOST) */
139 #define	PRC_UNREACH_NET		8	/* no route to network */
140 #define	PRC_UNREACH_HOST	9	/* no route to host */
141 #define	PRC_UNREACH_PROTOCOL	10	/* dst says bad protocol */
142 #define	PRC_UNREACH_PORT	11	/* bad port # */
143 /* was	PRC_UNREACH_NEEDFRAG	12	   (use PRC_MSGSIZE) */
144 #define	PRC_UNREACH_SRCFAIL	13	/* source route failed */
145 #define	PRC_REDIRECT_NET	14	/* net routing redirect */
146 #define	PRC_REDIRECT_HOST	15	/* host routing redirect */
147 #define	PRC_REDIRECT_TOSNET	16	/* redirect for type of service & net */
148 #define	PRC_REDIRECT_TOSHOST	17	/* redirect for tos & host */
149 #define	PRC_TIMXCEED_INTRANS	18	/* packet lifetime expired in transit */
150 #define	PRC_TIMXCEED_REASS	19	/* lifetime expired on reass q */
151 #define	PRC_PARAMPROB		20	/* header incorrect */
152 
153 #define	PRC_NCMDS		21
154 
155 #define	PRC_IS_REDIRECT(cmd)	\
156 	((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
157 
158 #ifdef PRCREQUESTS
159 char	*prcrequests[] = {
160 	"IFDOWN", "ROUTEDEAD", "#2", "DEC-BIT-QUENCH2",
161 	"QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
162 	"NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
163 	"#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
164 	"TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
165 	"PARAMPROB"
166 };
167 #endif
168 
169 /*
170  * The arguments to ctloutput are:
171  *	(*protosw[].pr_ctloutput)(req, so, level, optname, optval);
172  * req is one of the actions listed below, so is a (struct socket *),
173  * level is an indication of which protocol layer the option is intended.
174  * optname is a protocol dependent socket option request,
175  * optval is a pointer to a mbuf-chain pointer, for value-return results.
176  * The protocol is responsible for disposal of the mbuf chain *optval
177  * if supplied,
178  * the caller is responsible for any space held by *optval, when returned.
179  * A non-zero return from usrreq gives an
180  * UNIX error number which should be passed to higher level software.
181  */
182 #define	PRCO_GETOPT	0
183 #define	PRCO_SETOPT	1
184 
185 #define	PRCO_NCMDS	2
186 
187 #ifdef PRCOREQUESTS
188 char	*prcorequests[] = {
189 	"GETOPT", "SETOPT",
190 };
191 #endif
192 
193 #ifdef KERNEL
194 extern	struct protosw *pffindproto(), *pffindtype();
195 #endif
196