drm/i915: Update to Linux 4.2
[dragonfly.git] / sys / netinet / in_proto.c
blobc3a262cab6b75057e55f0d69bd8c94409c308a19
1 /*
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
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 * 3. 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.
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.
29 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
30 * $FreeBSD: src/sys/netinet/in_proto.c,v 1.53.2.7 2003/08/24 08:24:38 hsu Exp $
33 #include "opt_ipdivert.h"
34 #include "opt_mrouting.h"
35 #include "opt_ipsec.h"
36 #include "opt_inet6.h"
37 #include "opt_carp.h"
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/socket.h>
42 #include <sys/domain.h>
43 #include <sys/protosw.h>
44 #include <sys/queue.h>
45 #include <sys/sysctl.h>
47 #include <net/if.h>
48 #include <net/route.h>
50 #include <netinet/in.h>
51 #include <netinet/in_systm.h>
52 #include <netinet/in_pcb.h>
53 #include <netinet/ip.h>
54 #include <netinet/ip_var.h>
55 #include <netinet/ip_icmp.h>
56 #include <netinet/igmp_var.h>
57 #ifdef PIM
58 #include <netinet/pim_var.h>
59 #endif
60 #include <netinet/tcp.h>
61 #include <netinet/tcp_timer.h>
62 #include <netinet/tcp_var.h>
63 #include <netinet/udp.h>
64 #include <netinet/udp_var.h>
65 #include <netinet/ip_encap.h>
66 #ifdef IPDIVERT
67 #include <netinet/ip_divert.h>
68 #endif
71 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
74 #ifdef IPSEC
75 #include <netinet6/ipsec.h>
76 #include <netinet6/ah.h>
77 #ifdef IPSEC_ESP
78 #include <netinet6/esp.h>
79 #endif
80 #include <netinet6/ipcomp.h>
81 #endif /* IPSEC */
83 #ifdef FAST_IPSEC
84 #include <netproto/ipsec/ipsec.h>
85 #endif /* FAST_IPSEC */
87 #include <net/netisr.h> /* for cpu0_soport */
89 #ifdef CARP
90 #include <netinet/ip_carp.h>
91 #endif
93 extern struct domain inetdomain;
94 static struct pr_usrreqs nousrreqs;
96 struct protosw inetsw[] = {
98 .pr_type = 0,
99 .pr_domain = &inetdomain,
100 .pr_protocol = 0,
101 .pr_flags = 0,
103 .pr_ctlport = NULL,
105 .pr_init = ip_init,
106 .pr_fasttimo = NULL,
107 .pr_slowtimo = ip_slowtimo,
108 .pr_drain = ip_drain,
109 .pr_usrreqs = &nousrreqs
112 .pr_type = SOCK_DGRAM,
113 .pr_domain = &inetdomain,
114 .pr_protocol = IPPROTO_UDP,
115 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE|
116 PR_ASYNC_SEND|PR_ASEND_HOLDTD|PR_ACONN_HOLDTD,
118 .pr_initport = udp_initport,
119 .pr_input = udp_input,
120 .pr_output = NULL,
121 .pr_ctlinput = udp_ctlinput,
122 .pr_ctloutput = udp_ctloutput,
124 .pr_ctlport = udp_ctlport,
125 .pr_init = udp_init,
126 .pr_usrreqs = &udp_usrreqs
129 .pr_type = SOCK_STREAM,
130 .pr_domain = &inetdomain,
131 .pr_protocol = IPPROTO_TCP,
132 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_MPSAFE|
133 PR_ASYNC_SEND|PR_ASYNC_RCVD|PR_ACONN_HOLDTD,
135 .pr_initport = tcp_initport,
136 .pr_input = tcp_input,
137 .pr_output = NULL,
138 .pr_ctlinput = tcp_ctlinput,
139 .pr_ctloutput = tcp_ctloutput,
141 .pr_ctlport = tcp_ctlport,
142 .pr_init = tcp_init,
143 .pr_fasttimo = NULL,
144 .pr_slowtimo = NULL,
145 .pr_drain = tcp_drain,
146 .pr_usrreqs = &tcp_usrreqs
149 .pr_type = SOCK_RAW,
150 .pr_domain = &inetdomain,
151 .pr_protocol = IPPROTO_RAW,
152 .pr_flags = PR_ATOMIC|PR_ADDR,
154 .pr_input = rip_input,
155 .pr_output = NULL,
156 .pr_ctlinput = rip_ctlinput,
157 .pr_ctloutput = rip_ctloutput,
159 .pr_ctlport = cpu0_ctlport,
160 .pr_usrreqs = &rip_usrreqs
163 .pr_type = SOCK_RAW,
164 .pr_domain = &inetdomain,
165 .pr_protocol = IPPROTO_ICMP,
166 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
168 .pr_input = icmp_input,
169 .pr_output = NULL,
170 .pr_ctlinput = NULL,
171 .pr_ctloutput = rip_ctloutput,
173 .pr_usrreqs = &rip_usrreqs
176 .pr_type = SOCK_RAW,
177 .pr_domain = &inetdomain,
178 .pr_protocol = IPPROTO_IGMP,
179 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
181 .pr_input = igmp_input,
182 .pr_output = NULL,
183 .pr_ctlinput = NULL,
184 .pr_ctloutput = rip_ctloutput,
186 .pr_init = igmp_init,
187 .pr_fasttimo = igmp_fasttimo,
188 .pr_slowtimo = igmp_slowtimo,
189 .pr_drain = NULL,
190 .pr_usrreqs = &rip_usrreqs
193 .pr_type = SOCK_RAW,
194 .pr_domain = &inetdomain,
195 .pr_protocol = IPPROTO_RSVP,
196 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
198 .pr_input = rsvp_input,
199 .pr_output = NULL,
200 .pr_ctlinput = NULL,
201 .pr_ctloutput = rip_ctloutput,
203 .pr_usrreqs = &rip_usrreqs
205 #ifdef IPSEC
207 .pr_type = SOCK_RAW,
208 .pr_domain = &inetdomain,
209 .pr_protocol = IPPROTO_AH,
210 .pr_flags = PR_ATOMIC|PR_ADDR,
212 .pr_input = ah4_input,
213 .pr_output = NULL,
214 .pr_ctlinput = NULL,
215 .pr_ctloutput = NULL,
217 .pr_ctlport = NULL,
218 .pr_usrreqs = &nousrreqs
220 #ifdef IPSEC_ESP
222 .pr_type = SOCK_RAW,
223 .pr_domain = &inetdomain,
224 .pr_protocol = IPPROTO_ESP,
225 .pr_flags = PR_ATOMIC|PR_ADDR,
227 .pr_input = esp4_input,
228 .pr_output = NULL,
229 .pr_ctlinput = NULL,
230 .pr_ctloutput = NULL,
232 .pr_ctlport = NULL,
233 .pr_usrreqs = &nousrreqs
235 #endif
237 .pr_type = SOCK_RAW,
238 .pr_domain = &inetdomain,
239 .pr_protocol = IPPROTO_IPCOMP,
240 .pr_flags = PR_ATOMIC|PR_ADDR,
242 .pr_input = ipcomp4_input,
243 .pr_output = 0,
244 .pr_ctlinput = NULL,
245 .pr_ctloutput = NULL,
247 .pr_ctlport = NULL,
248 .pr_usrreqs = &nousrreqs
250 #endif /* IPSEC */
251 #ifdef FAST_IPSEC
253 .pr_type = SOCK_RAW,
254 .pr_domain = &inetdomain,
255 .pr_protocol = IPPROTO_AH,
256 .pr_flags = PR_ATOMIC|PR_ADDR,
258 .pr_input = ipsec4_common_input,
259 .pr_output = NULL,
260 .pr_ctlinput = NULL,
261 .pr_ctloutput = NULL,
263 .pr_ctlport = NULL,
264 .pr_usrreqs = &nousrreqs
267 .pr_type = SOCK_RAW,
268 .pr_domain = &inetdomain,
269 .pr_protocol = IPPROTO_ESP,
270 .pr_flags = PR_ATOMIC|PR_ADDR,
272 .pr_input = ipsec4_common_input,
273 .pr_output = NULL,
274 .pr_ctlinput = NULL,
275 .pr_ctloutput = NULL,
277 .pr_ctlport = NULL,
278 .pr_usrreqs = &nousrreqs
281 .pr_type = SOCK_RAW,
282 .pr_domain = &inetdomain,
283 .pr_protocol = IPPROTO_IPCOMP,
284 .pr_flags = PR_ATOMIC|PR_ADDR,
286 .pr_input = ipsec4_common_input,
287 .pr_output = NULL,
288 .pr_ctlinput = NULL,
289 .pr_ctloutput = NULL,
291 .pr_ctlport = NULL,
292 .pr_usrreqs = &nousrreqs
294 #endif /* FAST_IPSEC */
296 .pr_type = SOCK_RAW,
297 .pr_domain = &inetdomain,
298 .pr_protocol = IPPROTO_IPV4,
299 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
300 .pr_input = encap4_input,
301 .pr_output = NULL,
302 .pr_ctlinput = NULL,
303 .pr_ctloutput = rip_ctloutput,
305 .pr_ctlport = NULL,
306 .pr_init = encap_init,
307 .pr_usrreqs = &rip_usrreqs
310 .pr_type = SOCK_RAW,
311 .pr_domain = &inetdomain,
312 .pr_protocol = IPPROTO_MOBILE,
313 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
315 .pr_input = encap4_input,
316 .pr_output = NULL,
317 .pr_ctlinput = NULL,
318 .pr_ctloutput = rip_ctloutput,
320 .pr_ctlport = NULL,
321 .pr_init = encap_init,
322 .pr_usrreqs = &rip_usrreqs
325 .pr_type = SOCK_RAW,
326 .pr_domain = &inetdomain,
327 .pr_protocol = IPPROTO_GRE,
328 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
330 .pr_input = encap4_input,
331 .pr_output = NULL,
332 .pr_ctlinput = NULL,
333 .pr_ctloutput = rip_ctloutput,
335 .pr_ctlport = NULL,
336 .pr_init = encap_init,
337 .pr_usrreqs = &rip_usrreqs
339 #ifdef INET6
341 .pr_type = SOCK_RAW,
342 .pr_domain = &inetdomain,
343 .pr_protocol = IPPROTO_IPV6,
344 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
346 .pr_input = encap4_input,
347 .pr_output = NULL,
348 .pr_ctlinput = NULL,
349 .pr_ctloutput = rip_ctloutput,
351 .pr_ctlport = NULL,
352 .pr_init = encap_init,
353 .pr_usrreqs = &rip_usrreqs
355 #endif
356 #ifdef IPDIVERT
358 .pr_type = SOCK_RAW,
359 .pr_domain = &inetdomain,
360 .pr_protocol = IPPROTO_DIVERT,
361 .pr_flags = PR_ATOMIC|PR_ADDR,
363 .pr_input = div_input,
364 .pr_output = NULL,
365 .pr_ctlinput = NULL,
366 .pr_ctloutput = ip_ctloutput,
368 .pr_ctlport = NULL,
369 .pr_init = div_init,
370 .pr_usrreqs = &div_usrreqs
372 #endif
373 #ifdef PIM
375 .pr_type = SOCK_RAW,
376 .pr_domain = &inetdomain,
377 .pr_protocol = IPPROTO_PIM,
378 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
380 .pr_input = pim_input,
381 .pr_output = NULL,
382 .pr_ctlinput = NULL,
383 .pr_ctloutput = rip_ctloutput,
385 .pr_ctlport = NULL,
386 .pr_usrreqs = &rip_usrreqs
388 #endif
389 #ifdef NPFSYNC
391 .pr_type = SOCK_RAW,
392 .pr_domain = &inetdomain,
393 .pr_protocol = IPPROTO_PFSYNC,
394 .pr_flags = PR_ATOMIC|PR_ADDR,
396 .pr_input = pfsync_input,
397 .pr_output = NULL,
398 .pr_ctlinput = NULL,
399 .pr_ctloutput = rip_ctloutput,
401 .pr_ctlport = NULL,
402 .pr_usrreqs = &rip_usrreqs
404 #endif /* NPFSYNC */
406 /* raw wildcard */
407 .pr_type = SOCK_RAW,
408 .pr_domain = &inetdomain,
409 .pr_protocol = 0,
410 .pr_flags = PR_ATOMIC|PR_ADDR,
412 .pr_input = rip_input,
413 .pr_output = NULL,
414 .pr_ctlinput = NULL,
415 .pr_ctloutput = rip_ctloutput,
417 .pr_init = rip_init,
418 .pr_ctlport = NULL,
419 .pr_usrreqs = &rip_usrreqs
421 #ifdef CARP
423 .pr_type = SOCK_RAW,
424 .pr_domain = &inetdomain,
425 .pr_protocol = IPPROTO_CARP,
426 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
428 .pr_input = carp_proto_input,
429 .pr_output = rip_output,
430 .pr_ctlinput = carp_proto_ctlinput,
431 .pr_ctloutput = rip_ctloutput,
433 .pr_ctlport = cpu0_ctlport,
434 .pr_usrreqs = &rip_usrreqs
436 #endif
439 static void
440 inetdomain_init(void)
442 in_pcbglobalinit();
445 struct domain inetdomain = {
446 AF_INET, "internet", inetdomain_init, NULL, NULL,
447 inetsw, &inetsw[NELEM(inetsw)],
448 SLIST_ENTRY_INITIALIZER,
449 in_inithead, 32, sizeof(struct sockaddr_in),
452 DOMAIN_SET(inet);
454 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
455 "Internet Family");
457 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
458 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
459 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
460 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
461 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
462 #ifdef FAST_IPSEC
463 /* XXX no protocol # to use, pick something "reserved" */
464 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
465 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
466 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
467 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
468 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
469 #else
470 #ifdef IPSEC
471 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
472 #endif /* IPSEC */
473 #endif /* !FAST_IPSEC */
474 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
475 #ifdef IPDIVERT
476 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
477 #endif
478 #ifdef PIM
479 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
480 #endif
481 #ifdef CARP
482 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");
483 #endif