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