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