xref: /original-bsd/sys/kern/uipc_proto.c (revision c05f5e42)
1 /*	uipc_proto.c	4.17	82/03/03	*/
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(),icmp_ctlinput();
27 int	icmp_drain();
28 int	udp_input(),udp_ctlinput();
29 int	udp_usrreq();
30 int	udp_init();
31 int	tcp_input(),tcp_ctlinput();
32 int	tcp_usrreq();
33 int	tcp_init(),tcp_fasttimo(),tcp_slowtimo(),tcp_drain();
34 int	rip_input(),rip_output(),rip_ctlinput();
35 int	rip_usrreq(),rip_slowtimo();
36 
37 /*
38  * IMP protocol family: raw interface
39  */
40 #include "imp.h"
41 #if NIMP > 0
42 int	rimp_usrreq(),rimp_output(),rimp_ctlinput();
43 #endif
44 
45 /*
46  * PUP-I protocol family: raw interface
47  */
48 #include "pup.h"
49 #if NPUP > 0
50 int	rpup_output(),rpup_ctlinput();
51 #endif
52 
53 /*
54  * Sundries.
55 */
56 int	raw_init(),raw_usrreq(),raw_input();
57 
58 struct protosw protosw[] = {
59 { SOCK_STREAM,	PF_UNIX,	0,		PR_CONNREQUIRED,
60   0,		0,		0,		0,
61   piusrreq,
62   0,		0,		0,		0,
63 },
64 { SOCK_DGRAM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
65   0,		0,		0,		0,
66   piusrreq,
67   0,		0,		0,		0,
68 },
69 { SOCK_RDM,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
70   0,		0,		0,		0,
71   piusrreq,
72   0,		0,		0,		0,
73 },
74 { SOCK_RAW,	PF_UNIX,	0,		PR_ATOMIC|PR_ADDR,
75   0,		0,		0,		0,
76   piusrreq,
77   0,		0,		0,		0,
78 },
79 { 0,		0,		0,		0,
80   0,		ip_output,	0,		0,
81   0,
82   ip_init,	0,		ip_slowtimo,	ip_drain,
83 },
84 { 0,		0,		IPPROTO_ICMP,	0,
85   icmp_input,	0,		icmp_ctlinput,	0,
86   0,
87   0,		0,		0,		icmp_drain,
88 },
89 { SOCK_DGRAM,	PF_INET,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
90   udp_input,	0,		udp_ctlinput,	0,
91   udp_usrreq,
92   udp_init,	0,		0,		0,
93 },
94 { SOCK_STREAM,	PF_INET,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD,
95   tcp_input,	0,		tcp_ctlinput,	0,
96   tcp_usrreq,
97   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
98 },
99 { 0,		0,		0,		0,
100   raw_input,	0,		0,		0,
101   raw_usrreq,
102   raw_init,	0,		0,		0,
103 },
104 { SOCK_RAW,	PF_INET,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
105   rip_input,	rip_output,	rip_ctlinput,	0,
106   rip_usrreq,
107   0,		0,		0,		0,
108 }
109 #if NIMP > 0
110 ,
111 { SOCK_RAW,	PF_IMPLINK,	0,		PR_ATOMIC|PR_ADDR,
112   0,		rimp_output,	rimp_ctlinput,	0,
113   rimp_usrreq,
114   0,		0,		0,		0,
115 }
116 #endif
117 #if NPUP > 0
118 ,
119 { SOCK_RAW,	PF_PUP,		0,		PR_ATOMIC|PR_ADDR,
120   0,		rpup_output,	rpup_ctlinput,	0,
121   raw_usrreq,
122   0,		0,		0,		0,
123 }
124 #endif
125 };
126 
127 #define	NPROTOSW	(sizeof(protosw) / sizeof(protosw[0]))
128 
129 struct	protosw *protoswLAST = &protosw[NPROTOSW-1];
130 
131 /*
132  * Operations on protocol table and protocol families.
133  */
134 
135 /*
136  * Initialize all protocols.
137  */
138 pfinit()
139 {
140 	register struct protosw *pr;
141 
142 COUNT(PFINIT);
143 	for (pr = protoswLAST; pr >= protosw; pr--)
144 		if (pr->pr_init)
145 			(*pr->pr_init)();
146 }
147 
148 /*
149  * Find a standard protocol in a protocol family
150  * of a specific type.
151  */
152 struct protosw *
153 pffindtype(family, type)
154 	int family, type;
155 {
156 	register struct protosw *pr;
157 
158 COUNT(PFFINDTYPE);
159 	if (family == 0)
160 		return (0);
161 	for (pr = protosw; pr <= protoswLAST; pr++)
162 		if (pr->pr_family == family && pr->pr_type == type)
163 			return (pr);
164 	return (0);
165 }
166 
167 /*
168  * Find a specified protocol in a specified protocol family.
169  */
170 struct protosw *
171 pffindproto(family, protocol)
172 	int family, protocol;
173 {
174 	register struct protosw *pr;
175 
176 COUNT(PFFINDPROTO);
177 	if (family == 0)
178 		return (0);
179 	for (pr = protosw; pr <= protoswLAST; pr++)
180 		if (pr->pr_family == family && pr->pr_protocol == protocol)
181 			return (pr);
182 	return (0);
183 }
184 
185 /*
186  * Slow timeout on all protocols.
187  */
188 pfslowtimo()
189 {
190 	register struct protosw *pr;
191 
192 COUNT(PFSLOWTIMO);
193 	for (pr = protoswLAST; pr >= protosw; pr--)
194 		if (pr->pr_slowtimo)
195 			(*pr->pr_slowtimo)();
196 }
197 
198 pffasttimo()
199 {
200 	register struct protosw *pr;
201 
202 COUNT(PFSLOWTIMO);
203 	for (pr = protoswLAST; pr >= protosw; pr--)
204 		if (pr->pr_fasttimo)
205 			(*pr->pr_fasttimo)();
206 }
207