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