arcmsr(4): Use MSI if it is supported by the device.
[dragonfly.git] / sys / netinet / in_proto.c
blobaea13c16debfe802380171365f5ddcaa24a6814b
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
33 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
34 * $FreeBSD: src/sys/netinet/in_proto.c,v 1.53.2.7 2003/08/24 08:24:38 hsu Exp $
37 #include "opt_ipdivert.h"
38 #include "opt_ipx.h"
39 #include "opt_mrouting.h"
40 #include "opt_ipsec.h"
41 #include "opt_inet6.h"
42 #include "opt_sctp.h"
43 #include "opt_carp.h"
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/socket.h>
48 #include <sys/domain.h>
49 #include <sys/protosw.h>
50 #include <sys/queue.h>
51 #include <sys/sysctl.h>
53 #include <net/if.h>
54 #include <net/route.h>
56 #include <netinet/in.h>
57 #include <netinet/in_systm.h>
58 #include <netinet/ip.h>
59 #include <netinet/ip_var.h>
60 #include <netinet/ip_icmp.h>
61 #include <netinet/igmp_var.h>
62 #ifdef PIM
63 #include <netinet/pim_var.h>
64 #endif
65 #include <netinet/tcp.h>
66 #include <netinet/tcp_timer.h>
67 #include <netinet/tcp_var.h>
68 #include <netinet/udp.h>
69 #include <netinet/udp_var.h>
70 #include <netinet/ip_encap.h>
71 #ifdef IPDIVERT
72 #include <netinet/ip_divert.h>
73 #endif
76 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
79 #ifdef IPSEC
80 #include <netinet6/ipsec.h>
81 #include <netinet6/ah.h>
82 #ifdef IPSEC_ESP
83 #include <netinet6/esp.h>
84 #endif
85 #include <netinet6/ipcomp.h>
86 #endif /* IPSEC */
88 #ifdef FAST_IPSEC
89 #include <netproto/ipsec/ipsec.h>
90 #endif /* FAST_IPSEC */
92 #ifdef IPXIP
93 #include <netproto/ipx/ipx_ip.h>
94 #endif
96 #ifdef SCTP
97 #include <netinet/in_pcb.h>
98 #include <netinet/sctp_pcb.h>
99 #include <netinet/sctp.h>
100 #include <netinet/sctp_var.h>
101 #endif /* SCTP */
103 #include <net/netisr.h> /* for cpu0_soport */
105 #ifdef CARP
106 #include <netinet/ip_carp.h>
107 #endif
109 extern struct domain inetdomain;
110 static struct pr_usrreqs nousrreqs;
112 struct protosw inetsw[] = {
114 .pr_type = 0,
115 .pr_domain = &inetdomain,
116 .pr_protocol = 0,
117 .pr_flags = 0,
119 .pr_ctlport = NULL,
121 .pr_init = ip_init,
122 .pr_fasttimo = NULL,
123 .pr_slowtimo = ip_slowtimo,
124 .pr_drain = ip_drain,
125 .pr_usrreqs = &nousrreqs
128 .pr_type = SOCK_DGRAM,
129 .pr_domain = &inetdomain,
130 .pr_protocol = IPPROTO_UDP,
131 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE|PR_ASYNC_SEND,
133 .pr_input = udp_input,
134 .pr_output = NULL,
135 .pr_ctlinput = udp_ctlinput,
136 .pr_ctloutput = ip_ctloutput,
138 .pr_ctlport = udp_ctlport,
139 .pr_init = udp_init,
140 .pr_usrreqs = &udp_usrreqs
143 .pr_type = SOCK_STREAM,
144 .pr_domain = &inetdomain,
145 .pr_protocol = IPPROTO_TCP,
146 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_MPSAFE|PR_ASYNC_SEND,
148 .pr_input = tcp_input,
149 .pr_output = NULL,
150 .pr_ctlinput = tcp_ctlinput,
151 .pr_ctloutput = tcp_ctloutput,
153 .pr_ctlport = tcp_ctlport,
154 .pr_init = tcp_init,
155 .pr_fasttimo = NULL,
156 .pr_slowtimo = NULL,
157 .pr_drain = tcp_drain,
158 .pr_usrreqs = &tcp_usrreqs
160 #ifdef SCTP
162 * Order is very important here, we add the good one in
163 * in this postion so it maps to the right ip_protox[]
164 * postion for SCTP. Don't move the one above below
165 * this one or IPv6/4 compatability will break
168 .pr_type = SOCK_DGRAM,
169 .pr_domain = &inetdomain,
170 .pr_protocol = IPPROTO_SCTP,
171 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
173 .pr_input = sctp_input,
174 .pr_output = NULL,
175 .pr_ctlinput = sctp_ctlinput,
176 .pr_ctloutput = sctp_ctloutput,
178 .pr_ctlport = cpu0_ctlport,
179 .pr_init = sctp_init,
180 .pr_drain = sctp_drain,
181 .pr_usrreqs = &sctp_usrreqs
184 .pr_type = SOCK_SEQPACKET,
185 .pr_domain = &inetdomain,
186 .pr_protocol = IPPROTO_SCTP,
187 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
189 .pr_input = sctp_input,
190 .pr_output = NULL,
191 .pr_ctlinput = sctp_ctlinput,
192 .pr_ctloutput = sctp_ctloutput,
194 .pr_ctlport = cpu0_ctlport,
195 .pr_drain = sctp_drain,
196 .pr_usrreqs = &sctp_usrreqs
200 .pr_type = SOCK_STREAM,
201 .pr_domain = &inetdomain,
202 .pr_protocol = IPPROTO_SCTP,
203 .pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD,
205 .pr_input = sctp_input,
206 .pr_output = NULL,
207 .pr_ctlinput = sctp_ctlinput,
208 .pr_ctloutput = sctp_ctloutput,
210 .pr_ctlport = cpu0_ctlport,
211 .pr_drain = sctp_drain,
212 .pr_usrreqs = &sctp_usrreqs
214 #endif /* SCTP */
216 .pr_type = SOCK_RAW,
217 .pr_domain = &inetdomain,
218 .pr_protocol = IPPROTO_RAW,
219 .pr_flags = PR_ATOMIC|PR_ADDR,
221 .pr_input = rip_input,
222 .pr_output = NULL,
223 .pr_ctlinput = rip_ctlinput,
224 .pr_ctloutput = rip_ctloutput,
226 .pr_ctlport = cpu0_ctlport,
227 .pr_usrreqs = &rip_usrreqs
230 .pr_type = SOCK_RAW,
231 .pr_domain = &inetdomain,
232 .pr_protocol = IPPROTO_ICMP,
233 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
235 .pr_input = icmp_input,
236 .pr_output = NULL,
237 .pr_ctlinput = NULL,
238 .pr_ctloutput = rip_ctloutput,
240 .pr_usrreqs = &rip_usrreqs
243 .pr_type = SOCK_RAW,
244 .pr_domain = &inetdomain,
245 .pr_protocol = IPPROTO_IGMP,
246 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
248 .pr_input = igmp_input,
249 .pr_output = NULL,
250 .pr_ctlinput = NULL,
251 .pr_ctloutput = rip_ctloutput,
253 .pr_init = igmp_init,
254 .pr_fasttimo = igmp_fasttimo,
255 .pr_slowtimo = igmp_slowtimo,
256 .pr_drain = NULL,
257 .pr_usrreqs = &rip_usrreqs
260 .pr_type = SOCK_RAW,
261 .pr_domain = &inetdomain,
262 .pr_protocol = IPPROTO_RSVP,
263 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
265 .pr_input = rsvp_input,
266 .pr_output = NULL,
267 .pr_ctlinput = NULL,
268 .pr_ctloutput = rip_ctloutput,
270 .pr_usrreqs = &rip_usrreqs
272 #ifdef IPSEC
274 .pr_type = SOCK_RAW,
275 .pr_domain = &inetdomain,
276 .pr_protocol = IPPROTO_AH,
277 .pr_flags = PR_ATOMIC|PR_ADDR,
279 .pr_input = ah4_input,
280 .pr_output = NULL,
281 .pr_ctlinput = NULL,
282 .pr_ctloutput = NULL,
284 .pr_ctlport = NULL,
285 .pr_usrreqs = &nousrreqs
287 #ifdef IPSEC_ESP
289 .pr_type = SOCK_RAW,
290 .pr_domain = &inetdomain,
291 .pr_protocol = IPPROTO_ESP,
292 .pr_flags = PR_ATOMIC|PR_ADDR,
294 .pr_input = esp4_input,
295 .pr_output = NULL,
296 .pr_ctlinput = NULL,
297 .pr_ctloutput = NULL,
299 .pr_ctlport = NULL,
300 .pr_usrreqs = &nousrreqs
302 #endif
304 .pr_type = SOCK_RAW,
305 .pr_domain = &inetdomain,
306 .pr_protocol = IPPROTO_IPCOMP,
307 .pr_flags = PR_ATOMIC|PR_ADDR,
309 .pr_input = ipcomp4_input,
310 .pr_output = 0,
311 .pr_ctlinput = NULL,
312 .pr_ctloutput = NULL,
314 .pr_ctlport = NULL,
315 .pr_usrreqs = &nousrreqs
317 #endif /* IPSEC */
318 #ifdef FAST_IPSEC
320 .pr_type = SOCK_RAW,
321 .pr_domain = &inetdomain,
322 .pr_protocol = IPPROTO_AH,
323 .pr_flags = PR_ATOMIC|PR_ADDR,
325 .pr_input = ipsec4_common_input,
326 .pr_output = NULL,
327 .pr_ctlinput = NULL,
328 .pr_ctloutput = NULL,
330 .pr_ctlport = NULL,
331 .pr_usrreqs = &nousrreqs
334 .pr_type = SOCK_RAW,
335 .pr_domain = &inetdomain,
336 .pr_protocol = IPPROTO_ESP,
337 .pr_flags = PR_ATOMIC|PR_ADDR,
339 .pr_input = ipsec4_common_input,
340 .pr_output = NULL
341 .pr_ctlinput = NULL,
342 .pr_ctloutput = NULL,
344 .pr_ctlport = NULL,
345 .pr_usrreqs = &nousrreqs
348 .pr_type = SOCK_RAW,
349 .pr_domain = &inetdomain,
350 .pr_protocol = IPPROTO_IPCOMP,
351 .pr_flags = PR_ATOMIC|PR_ADDR,
353 .pr_input = ipsec4_common_input,
354 .pr_output = NULL,
355 .pr_ctlinput = NULL,
356 .pr_ctloutput = NULL,
358 .pr_ctlport = NULL,
359 .pr_usrreqs = &nousrreqs
361 #endif /* FAST_IPSEC */
363 .pr_type = SOCK_RAW,
364 .pr_domain = &inetdomain,
365 .pr_protocol = IPPROTO_IPV4,
366 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
367 .pr_input = encap4_input,
368 .pr_output = NULL,
369 .pr_ctlinput = NULL,
370 .pr_ctloutput = rip_ctloutput,
372 .pr_ctlport = NULL,
373 .pr_init = encap_init,
374 .pr_usrreqs = &rip_usrreqs
377 .pr_type = SOCK_RAW,
378 .pr_domain = &inetdomain,
379 .pr_protocol = IPPROTO_MOBILE,
380 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
382 .pr_input = encap4_input,
383 .pr_output = NULL,
384 .pr_ctlinput = NULL,
385 .pr_ctloutput = rip_ctloutput,
387 .pr_ctlport = NULL,
388 .pr_init = encap_init,
389 .pr_usrreqs = &rip_usrreqs
392 .pr_type = SOCK_RAW,
393 .pr_domain = &inetdomain,
394 .pr_protocol = IPPROTO_GRE,
395 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
397 .pr_input = encap4_input,
398 .pr_output = NULL,
399 .pr_ctlinput = NULL,
400 .pr_ctloutput = rip_ctloutput,
402 .pr_ctlport = NULL,
403 .pr_init = encap_init,
404 .pr_usrreqs = &rip_usrreqs
406 #ifdef INET6
408 .pr_type = SOCK_RAW,
409 .pr_domain = &inetdomain,
410 .pr_protocol = IPPROTO_IPV6,
411 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
413 .pr_input = encap4_input,
414 .pr_output = NULL,
415 .pr_ctlinput = NULL,
416 .pr_ctloutput = rip_ctloutput,
418 .pr_ctlport = NULL,
419 .pr_init = encap_init,
420 .pr_usrreqs = &rip_usrreqs
422 #endif
423 #ifdef IPDIVERT
425 .pr_type = SOCK_RAW,
426 .pr_domain = &inetdomain,
427 .pr_protocol = IPPROTO_DIVERT,
428 .pr_flags = PR_ATOMIC|PR_ADDR,
430 .pr_input = div_input,
431 .pr_output = NULL,
432 .pr_ctlinput = NULL,
433 .pr_ctloutput = ip_ctloutput,
435 .pr_ctlport = NULL,
436 .pr_init = div_init,
437 .pr_usrreqs = &div_usrreqs
439 #endif
440 #ifdef IPXIP
442 .pr_type = SOCK_RAW,
443 .pr_domain = &inetdomain,
444 .pr_protocol = IPPROTO_IDP,
445 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
447 .pr_input = ipxip_input,
448 .pr_output = NULL,
449 .pr_ctlinput = ipxip_ctlinput,
450 .pr_ctloutput = NULL,
452 .pr_ctlport = cpu0_ctlport,
453 .pr_usrreqs = &rip_usrreqs
455 #endif
456 #ifdef PIM
458 .pr_type = SOCK_RAW,
459 .pr_domain = &inetdomain,
460 .pr_protocol = IPPROTO_PIM,
461 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
463 .pr_input = pim_input,
464 .pr_output = NULL,
465 .pr_ctlinput = NULL,
466 .pr_ctloutput = rip_ctloutput,
468 .pr_ctlport = NULL,
469 .pr_usrreqs = &rip_usrreqs
471 #endif
472 #ifdef NPFSYNC
474 .pr_type = SOCK_RAW,
475 .pr_domain = &inetdomain,
476 .pr_protocol = IPPROTO_PFSYNC,
477 .pr_flags = PR_ATOMIC|PR_ADDR,
479 .pr_input = pfsync_input,
480 .pr_output = NULL,
481 .pr_ctlinput = NULL,
482 .pr_ctloutput = rip_ctloutput,
484 .pr_ctlport = NULL,
485 .pr_usrreqs = &rip_usrreqs
487 #endif /* NPFSYNC */
489 /* raw wildcard */
490 .pr_type = SOCK_RAW,
491 .pr_domain = &inetdomain,
492 .pr_protocol = 0,
493 .pr_flags = PR_ATOMIC|PR_ADDR,
495 .pr_input = rip_input,
496 .pr_output = NULL,
497 .pr_ctlinput = NULL,
498 .pr_ctloutput = rip_ctloutput,
500 .pr_init = rip_init,
501 .pr_ctlport = NULL,
502 .pr_usrreqs = &rip_usrreqs
504 #ifdef CARP
506 .pr_type = SOCK_RAW,
507 .pr_domain = &inetdomain,
508 .pr_protocol = IPPROTO_CARP,
509 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
511 .pr_input = carp_proto_input,
512 .pr_output = rip_output,
513 .pr_ctlinput = carp_proto_ctlinput,
514 .pr_ctloutput = rip_ctloutput,
516 .pr_ctlport = cpu0_ctlport,
517 .pr_usrreqs = &rip_usrreqs
519 #endif
522 struct domain inetdomain = {
523 AF_INET, "internet", NULL, NULL, NULL,
524 inetsw, &inetsw[NELEM(inetsw)],
525 SLIST_ENTRY_INITIALIZER,
526 in_inithead, 32, sizeof(struct sockaddr_in),
529 DOMAIN_SET(inet);
531 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
532 "Internet Family");
534 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
535 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
536 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
537 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
538 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
539 #ifdef FAST_IPSEC
540 /* XXX no protocol # to use, pick something "reserved" */
541 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
542 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
543 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
544 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
545 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
546 #else
547 #ifdef IPSEC
548 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
549 #endif /* IPSEC */
550 #endif /* !FAST_IPSEC */
551 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
552 #ifdef IPDIVERT
553 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
554 #endif
555 #ifdef PIM
556 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
557 #endif
558 #ifdef CARP
559 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");
560 #endif