1 /*-
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
30 * $FreeBSD: releng/6.4/sys/netinet/in_proto.c 153984 2006-01-03 08:15:33Z thompsa $
31 */
32
33 #include "opt_ipx.h"
34 #include "opt_mrouting.h"
35 #include "opt_ipsec.h"
36 #include "opt_inet6.h"
37 #include "opt_pf.h"
38 #include "opt_carp.h"
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/socket.h>
44 #include <sys/domain.h>
45 #include <sys/protosw.h>
46 #include <sys/queue.h>
47 #include <sys/sysctl.h>
48
49 #include <net/if.h>
50 #include <net/route.h>
51
52 #include <netinet/in.h>
53 #include <netinet/in_systm.h>
54 #include <netinet/ip.h>
55 #include <netinet/ip_var.h>
56 #include <netinet/ip_icmp.h>
57 #include <netinet/igmp_var.h>
58 #ifdef PIM
59 #include <netinet/pim_var.h>
60 #endif
61 #include <netinet/tcp.h>
62 #include <netinet/tcp_timer.h>
63 #include <netinet/tcp_var.h>
64 #include <netinet/udp.h>
65 #include <netinet/udp_var.h>
66 #include <netinet/ip_encap.h>
67
68 /*
69 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
70 */
71
72 #ifdef IPSEC
73 #include <netinet6/ipsec.h>
74 #include <netinet6/ah.h>
75 #ifdef IPSEC_ESP
76 #include <netinet6/esp.h>
77 #endif
78 #include <netinet6/ipcomp.h>
79 #endif /* IPSEC */
80
81 #ifdef FAST_IPSEC
82 #include <netipsec/ipsec.h>
83 #endif /* FAST_IPSEC */
84
85 #ifdef IPXIP
86 #include <netipx/ipx_ip.h>
87 #endif
88
89 #ifdef DEV_PFSYNC
90 #include <net/pfvar.h>
91 #include <net/if_pfsync.h>
92 #endif
93
94 #ifdef DEV_CARP
95 #include <netinet/ip_carp.h>
96 #endif
97
98 extern struct domain inetdomain;
99
100 /* Spacer for loadable protocols. */
101 #define IPPROTOSPACER \
102 { \
103 .pr_domain = &inetdomain, \
104 .pr_protocol = PROTO_SPACER, \
105 .pr_usrreqs = &nousrreqs \
106 }
107
108 struct protosw inetsw[] = {
109 {
110 .pr_type = 0,
111 .pr_domain = &inetdomain,
112 .pr_protocol = IPPROTO_IP,
113 .pr_init = ip_init,
114 .pr_slowtimo = ip_slowtimo,
115 .pr_drain = ip_drain,
116 .pr_usrreqs = &nousrreqs
117 },
118 {
119 .pr_type = SOCK_DGRAM,
120 .pr_domain = &inetdomain,
121 .pr_protocol = IPPROTO_UDP,
122 .pr_flags = PR_ATOMIC|PR_ADDR,
123 .pr_input = udp_input,
124 .pr_ctlinput = udp_ctlinput,
125 .pr_ctloutput = ip_ctloutput,
126 .pr_init = udp_init,
127 .pr_usrreqs = &udp_usrreqs
128 },
129 {
130 .pr_type = SOCK_STREAM,
131 .pr_domain = &inetdomain,
132 .pr_protocol = IPPROTO_TCP,
133 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
134 .pr_input = tcp_input,
135 .pr_ctlinput = tcp_ctlinput,
136 .pr_ctloutput = tcp_ctloutput,
137 .pr_init = tcp_init,
138 .pr_slowtimo = tcp_slowtimo,
139 .pr_drain = tcp_drain,
140 .pr_usrreqs = &tcp_usrreqs
141 },
142 {
143 .pr_type = SOCK_RAW,
144 .pr_domain = &inetdomain,
145 .pr_protocol = IPPROTO_RAW,
146 .pr_flags = PR_ATOMIC|PR_ADDR,
147 .pr_input = rip_input,
148 .pr_ctlinput = rip_ctlinput,
149 .pr_ctloutput = rip_ctloutput,
150 .pr_usrreqs = &rip_usrreqs
151 },
152 {
153 .pr_type = SOCK_RAW,
154 .pr_domain = &inetdomain,
155 .pr_protocol = IPPROTO_ICMP,
156 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
157 .pr_input = icmp_input,
158 .pr_ctloutput = rip_ctloutput,
159 .pr_usrreqs = &rip_usrreqs
160 },
161 {
162 .pr_type = SOCK_RAW,
163 .pr_domain = &inetdomain,
164 .pr_protocol = IPPROTO_IGMP,
165 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
166 .pr_input = igmp_input,
167 .pr_ctloutput = rip_ctloutput,
168 .pr_init = igmp_init,
169 .pr_fasttimo = igmp_fasttimo,
170 .pr_slowtimo = igmp_slowtimo,
171 .pr_usrreqs = &rip_usrreqs
172 },
173 {
174 .pr_type = SOCK_RAW,
175 .pr_domain = &inetdomain,
176 .pr_protocol = IPPROTO_RSVP,
177 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
178 .pr_input = rsvp_input,
179 .pr_ctloutput = rip_ctloutput,
180 .pr_usrreqs = &rip_usrreqs
181 },
182 #ifdef IPSEC
183 {
184 .pr_type = SOCK_RAW,
185 .pr_domain = &inetdomain,
186 .pr_protocol = IPPROTO_AH,
187 .pr_flags = PR_ATOMIC|PR_ADDR,
188 .pr_input = ah4_input,
189 .pr_usrreqs = &nousrreqs
190 },
191 #ifdef IPSEC_ESP
192 {
193 .pr_type = SOCK_RAW,
194 .pr_domain = &inetdomain,
195 .pr_protocol = IPPROTO_ESP,
196 .pr_flags = PR_ATOMIC|PR_ADDR,
197 .pr_input = esp4_input,
198 .pr_usrreqs = &nousrreqs
199 },
200 #endif
201 {
202 .pr_type = SOCK_RAW,
203 .pr_domain = &inetdomain,
204 .pr_protocol = IPPROTO_IPCOMP,
205 .pr_flags = PR_ATOMIC|PR_ADDR,
206 .pr_input = ipcomp4_input,
207 .pr_usrreqs = &nousrreqs
208 },
209 #endif /* IPSEC */
210 #ifdef FAST_IPSEC
211 {
212 .pr_type = SOCK_RAW,
213 .pr_domain = &inetdomain,
214 .pr_protocol = IPPROTO_AH,
215 .pr_flags = PR_ATOMIC|PR_ADDR,
216 .pr_input = ah4_input,
217 .pr_ctlinput = ah4_ctlinput,
218 .pr_usrreqs = &nousrreqs
219 },
220 {
221 .pr_type = SOCK_RAW,
222 .pr_domain = &inetdomain,
223 .pr_protocol = IPPROTO_ESP,
224 .pr_flags = PR_ATOMIC|PR_ADDR,
225 .pr_input = esp4_input,
226 .pr_ctlinput = esp4_ctlinput,
227 .pr_usrreqs = &nousrreqs
228 },
229 {
230 .pr_type = SOCK_RAW,
231 .pr_domain = &inetdomain,
232 .pr_protocol = IPPROTO_IPCOMP,
233 .pr_flags = PR_ATOMIC|PR_ADDR,
234 .pr_input = ipcomp4_input,
235 .pr_usrreqs = &nousrreqs
236 },
237 #endif /* FAST_IPSEC */
238 {
239 .pr_type = SOCK_RAW,
240 .pr_domain = &inetdomain,
241 .pr_protocol = IPPROTO_IPV4,
242 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
243 .pr_input = encap4_input,
244 .pr_ctloutput = rip_ctloutput,
245 .pr_init = encap_init,
246 .pr_usrreqs = &rip_usrreqs
247 },
248 {
249 .pr_type = SOCK_RAW,
250 .pr_domain = &inetdomain,
251 .pr_protocol = IPPROTO_MOBILE,
252 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
253 .pr_input = encap4_input,
254 .pr_ctloutput = rip_ctloutput,
255 .pr_init = encap_init,
256 .pr_usrreqs = &rip_usrreqs
257 },
258 {
259 .pr_type = SOCK_RAW,
260 .pr_domain = &inetdomain,
261 .pr_protocol = IPPROTO_ETHERIP,
262 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
263 .pr_input = encap4_input,
264 .pr_ctloutput = rip_ctloutput,
265 .pr_init = encap_init,
266 .pr_usrreqs = &rip_usrreqs
267 },
268 {
269 .pr_type = SOCK_RAW,
270 .pr_domain = &inetdomain,
271 .pr_protocol = IPPROTO_GRE,
272 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
273 .pr_input = encap4_input,
274 .pr_ctloutput = rip_ctloutput,
275 .pr_init = encap_init,
276 .pr_usrreqs = &rip_usrreqs
277 },
278 # ifdef INET6
279 {
280 .pr_type = SOCK_RAW,
281 .pr_domain = &inetdomain,
282 .pr_protocol = IPPROTO_IPV6,
283 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
284 .pr_input = encap4_input,
285 .pr_ctloutput = rip_ctloutput,
286 .pr_init = encap_init,
287 .pr_usrreqs = &rip_usrreqs
288 },
289 #endif
290 #ifdef IPXIP
291 {
292 .pr_type = SOCK_RAW,
293 .pr_domain = &inetdomain,
294 .pr_protocol = IPPROTO_IDP,
295 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
296 .pr_input = ipxip_input,
297 .pr_ctlinput = ipxip_ctlinput,
298 .pr_usrreqs = &rip_usrreqs
299 },
300 #endif
301 #ifdef PIM
302 {
303 .pr_type = SOCK_RAW,
304 .pr_domain = &inetdomain,
305 .pr_protocol = IPPROTO_PIM,
306 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
307 .pr_input = pim_input,
308 .pr_ctloutput = rip_ctloutput,
309 .pr_usrreqs = &rip_usrreqs
310 },
311 #endif /* PIM */
312 #ifdef DEV_PFSYNC
313 {
314 .pr_type = SOCK_RAW,
315 .pr_domain = &inetdomain,
316 .pr_protocol = IPPROTO_PFSYNC,
317 .pr_flags = PR_ATOMIC|PR_ADDR,
318 .pr_input = pfsync_input,
319 .pr_ctloutput = rip_ctloutput,
320 .pr_usrreqs = &rip_usrreqs
321 },
322 #endif /* DEV_PFSYNC */
323 #ifdef DEV_CARP
324 {
325 .pr_type = SOCK_RAW,
326 .pr_domain = &inetdomain,
327 .pr_protocol = IPPROTO_CARP,
328 .pr_flags = PR_ATOMIC|PR_ADDR,
329 .pr_input = carp_input,
330 .pr_output = (pr_output_t*)rip_output,
331 .pr_ctloutput = rip_ctloutput,
332 .pr_usrreqs = &rip_usrreqs
333 },
334 #endif /* DEV_CARP */
335 /* Spacer n-times for loadable protocols. */
336 IPPROTOSPACER,
337 IPPROTOSPACER,
338 IPPROTOSPACER,
339 IPPROTOSPACER,
340 IPPROTOSPACER,
341 IPPROTOSPACER,
342 IPPROTOSPACER,
343 IPPROTOSPACER,
344 /* raw wildcard */
345 {
346 .pr_type = SOCK_RAW,
347 .pr_domain = &inetdomain,
348 .pr_flags = PR_ATOMIC|PR_ADDR,
349 .pr_input = rip_input,
350 .pr_ctloutput = rip_ctloutput,
351 .pr_init = rip_init,
352 .pr_usrreqs = &rip_usrreqs
353 },
354 };
355
356 extern int in_inithead(void **, int);
357
358 struct domain inetdomain = {
359 .dom_family = AF_INET,
360 .dom_name = "internet",
361 .dom_protosw = inetsw,
362 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
363 .dom_rtattach = in_inithead,
364 .dom_rtoffset = 32,
365 .dom_maxrtkey = sizeof(struct sockaddr_in)
366 };
367
368 DOMAIN_SET(inet);
369
370 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
371 "Internet Family");
372
373 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
374 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
375 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
376 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
377 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
378 #ifdef FAST_IPSEC
379 /* XXX no protocol # to use, pick something "reserved" */
380 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
381 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
382 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
383 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
384 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
385 #else
386 #ifdef IPSEC
387 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
388 #endif /* IPSEC */
389 #endif /* !FAST_IPSEC */
390 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
391 #ifdef PIM
392 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
393 #endif
394 #ifdef DEV_PFSYNC
395 SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC");
396 #endif
397 #ifdef DEV_CARP
398 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");
399 #endif
Cache object: 0f4dcf580fe57ae25c6367a7f9e039e5
|