xref: /csrg-svn/sys/kern/uipc_proto.c (revision 6585)
1 /*	uipc_proto.c	4.20	82/04/24	*/
2 
3 #include "../h/param.h"
4 #include "../h/socket.h"
5 #include "../h/protosw.h"
6 #include "../h/mbuf.h"
7 #include "../net/in.h"
8 #include "../net/in_systm.h"
9 
10 /*
11  * Protocol configuration table and routines to search it.
12  *
13  * SHOULD INCLUDE A HEADER FILE GIVING DESIRED PROTOCOLS
14  */
15 
16 /*
17  * Local protocol handler.
18  */
19 int	piusrreq();
20 
21 /*
22  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
23  */
24 int	ip_output();
25 int	ip_init(),ip_slowtimo(),ip_drain();
26 int	icmp_input();
27 int	udp_input(),udp_ctlinput();
28 int	udp_usrreq();
29 int	udp_init();
30 int	tcp_input(),tcp_ctlinput();
31 int	tcp_usrreq();
32 int	tcp_init(),tcp_fasttimo(),tcp_slowtimo(),tcp_drain();
33 int	rip_input(),rip_output();
34 
35 /*
36  * IMP protocol family: raw interface
37  */
38 #include "imp.h"
39 #if NIMP > 0
40 int	rimp_output();
41 #endif
42 
43 /*
44  * PUP-I protocol family: raw interface
45  */
46 #include "pup.h"
47 #if NPUP > 0
48 int	rpup_output();
49 #endif
50 
51 /*
52  * Sundries.
53 */
54 int	raw_init(),raw_usrreq(),raw_input(),raw_ctlinput();
55 
56 struct protosw protosw[] = {
57 { SOCK_STREAM,	PF_UNIX,	0,		PR_CONNREQUIRED,
58   0,		0,		0,		0,
59   piusrreq,
60   0,		0,		0,		0,
61 },
62 { SOCK_DGRAM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
63   0,		0,		0,		0,
64   piusrreq,
65   0,		0,		0,		0,
66 },
67 { SOCK_RDM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
68   0,		0,		0,		0,
69   piusrreq,
70   0,		0,		0,		0,
71 },
72 { SOCK_RAW,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
73   0,		0,		0,		0,
74   piusrreq,
75   0,		0,		0,		0,
76 },
77 { 0,		0,		0,		0,
78   0,		ip_output,	0,		0,
79   0,
80   ip_init,	0,		ip_slowtimo,	ip_drain,
81 },
82 { 0,		PF_INET,	IPPROTO_ICMP,	0,
83   icmp_input,	0,		0,		0,
84   0,
85   0,		0,		0,		0,
86 },
87 { SOCK_DGRAM,	PF_INET,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
88   udp_input,	0,		udp_ctlinput,	0,
89   udp_usrreq,
90   udp_init,	0,		0,		0,
91 },
92 { SOCK_STREAM,	PF_INET,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD,
93   tcp_input,	0,		tcp_ctlinput,	0,
94   tcp_usrreq,
95   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
96 },
97 { 0,		0,		0,		0,
98   raw_input,	0,		raw_ctlinput,	0,
99   raw_usrreq,
100   raw_init,	0,		0,		0,
101 },
102 { SOCK_RAW,	PF_INET,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
103   rip_input,	rip_output,	0,	0,
104   raw_usrreq,
105   0,		0,		0,		0,
106 }
107 #if NIMP > 0
108 ,
109 { SOCK_RAW,	PF_IMPLINK,	0,		PR_ATOMIC|PR_ADDR,
110   0,		rimp_output,	0,		0,
111   raw_usrreq,
112   0,		0,		0,		0,
113 }
114 #endif
115 #if NPUP > 0
116 ,
117 { SOCK_RAW,	PF_PUP,		0,		PR_ATOMIC|PR_ADDR,
118   0,		rpup_output,	0,		0,
119   raw_usrreq,
120   0,		0,		0,		0,
121 }
122 #endif
123 };
124 
125 #define	NPROTOSW	(sizeof(protosw) / sizeof(protosw[0]))
126 
127 struct	protosw *protoswLAST = &protosw[NPROTOSW-1];
128 
129 /*
130  * Operations on protocol table and protocol families.
131  */
132 
133 /*
134  * Initialize all protocols.
135  */
136 pfinit()
137 {
138 	register struct protosw *pr;
139 
140 COUNT(PFINIT);
141 	for (pr = protoswLAST; pr >= protosw; pr--)
142 		if (pr->pr_init)
143 			(*pr->pr_init)();
144 }
145 
146 /*
147  * Find a standard protocol in a protocol family
148  * of a specific type.
149  */
150 struct protosw *
151 pffindtype(family, type)
152 	int family, type;
153 {
154 	register struct protosw *pr;
155 
156 COUNT(PFFINDTYPE);
157 	if (family == 0)
158 		return (0);
159 	for (pr = protosw; pr <= protoswLAST; pr++)
160 		if (pr->pr_family == family && pr->pr_type == type)
161 			return (pr);
162 	return (0);
163 }
164 
165 /*
166  * Find a specified protocol in a specified protocol family.
167  */
168 struct protosw *
169 pffindproto(family, protocol)
170 	int family, protocol;
171 {
172 	register struct protosw *pr;
173 
174 COUNT(PFFINDPROTO);
175 	if (family == 0)
176 		return (0);
177 	for (pr = protosw; pr <= protoswLAST; pr++)
178 		if (pr->pr_family == family && pr->pr_protocol == protocol)
179 			return (pr);
180 	return (0);
181 }
182 
183 pfctlinput(cmd, arg)
184 	int cmd;
185 	caddr_t arg;
186 {
187 	register struct protosw *pr;
188 COUNT(PFCTLINPUT);
189 
190 	for (pr = protosw; pr <= protoswLAST; pr++)
191 		if (pr->pr_ctlinput)
192 			(*pr->pr_ctlinput)(cmd, arg);
193 }
194 
195 /*
196  * Slow timeout on all protocols.
197  */
198 pfslowtimo()
199 {
200 	register struct protosw *pr;
201 
202 COUNT(PFSLOWTIMO);
203 	for (pr = protoswLAST; pr >= protosw; pr--)
204 		if (pr->pr_slowtimo)
205 			(*pr->pr_slowtimo)();
206 }
207 
208 pffasttimo()
209 {
210 	register struct protosw *pr;
211 
212 COUNT(PFSLOWTIMO);
213 	for (pr = protoswLAST; pr >= protosw; pr--)
214 		if (pr->pr_fasttimo)
215 			(*pr->pr_fasttimo)();
216 }
217