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
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
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 $
35 * $DragonFly: src/sys/netinet/in_proto.c,v 1.17 2008/10/27 02:56:30 sephe Exp $
38 #include "opt_ipdivert.h"
40 #include "opt_mrouting.h"
41 #include "opt_ipsec.h"
42 #include "opt_inet6.h"
46 #include <sys/param.h>
47 #include <sys/kernel.h>
48 #include <sys/socket.h>
49 #include <sys/domain.h>
50 #include <sys/protosw.h>
51 #include <sys/queue.h>
52 #include <sys/sysctl.h>
55 #include <net/route.h>
57 #include <netinet/in.h>
58 #include <netinet/in_systm.h>
59 #include <netinet/ip.h>
60 #include <netinet/ip_var.h>
61 #include <netinet/ip_icmp.h>
62 #include <netinet/igmp_var.h>
64 #include <netinet/pim_var.h>
66 #include <netinet/tcp.h>
67 #include <netinet/tcp_timer.h>
68 #include <netinet/tcp_var.h>
69 #include <netinet/udp.h>
70 #include <netinet/udp_var.h>
71 #include <netinet/ip_encap.h>
73 #include <netinet/ip_divert.h>
77 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
81 #include <netinet6/ipsec.h>
82 #include <netinet6/ah.h>
84 #include <netinet6/esp.h>
86 #include <netinet6/ipcomp.h>
90 #include <netproto/ipsec/ipsec.h>
91 #endif /* FAST_IPSEC */
94 #include <netproto/ipx/ipx_ip.h>
99 #include <netns/ns_if.h>
103 #include <netinet/in_pcb.h>
104 #include <netinet/sctp_pcb.h>
105 #include <netinet/sctp.h>
106 #include <netinet/sctp_var.h>
109 #include <net/netisr.h> /* for cpu0_soport */
112 #include <netinet/ip_carp.h>
115 extern struct domain inetdomain;
116 static struct pr_usrreqs nousrreqs;
118 struct protosw inetsw[] = {
121 .pr_domain = &inetdomain,
129 .pr_slowtimo = ip_slowtimo,
130 .pr_drain = ip_drain,
131 .pr_usrreqs = &nousrreqs
134 .pr_type = SOCK_DGRAM,
135 .pr_domain = &inetdomain,
136 .pr_protocol = IPPROTO_UDP,
137 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
139 .pr_input = udp_input,
141 .pr_ctlinput = udp_ctlinput,
142 .pr_ctloutput = ip_ctloutput,
144 .pr_ctlport = udp_ctlport,
146 .pr_usrreqs = &udp_usrreqs
149 .pr_type = SOCK_STREAM,
150 .pr_domain = &inetdomain,
151 .pr_protocol = IPPROTO_TCP,
152 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD|PR_MPSAFE,
154 .pr_input = tcp_input,
156 .pr_ctlinput = tcp_ctlinput,
157 .pr_ctloutput = tcp_ctloutput,
159 .pr_ctlport = tcp_ctlport,
162 .pr_slowtimo = tcp_slowtimo,
163 .pr_drain = tcp_drain,
164 .pr_usrreqs = &tcp_usrreqs
168 * Order is very important here, we add the good one in
169 * in this postion so it maps to the right ip_protox[]
170 * postion for SCTP. Don't move the one above below
171 * this one or IPv6/4 compatability will break
174 .pr_type = SOCK_DGRAM,
175 .pr_domain = &inetdomain,
176 .pr_protocol = IPPROTO_SCTP,
177 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
179 .pr_input = sctp_input,
181 .pr_ctlinput = sctp_ctlinput,
182 .pr_ctloutput = sctp_ctloutput,
184 .pr_ctlport = cpu0_ctlport,
185 .pr_init = sctp_init,
186 .pr_drain = sctp_drain,
187 .pr_usrreqs = &sctp_usrreqs
190 .pr_type = SOCK_SEQPACKET,
191 .pr_domain = &inetdomain,
192 .pr_protocol = IPPROTO_SCTP,
193 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
195 .pr_input = sctp_input,
197 .pr_ctlinput = sctp_ctlinput,
198 .pr_ctloutput = sctp_ctloutput,
200 .pr_ctlport = cpu0_ctlport,
201 .pr_drain = sctp_drain,
202 .pr_usrreqs = &sctp_usrreqs
206 .pr_type = SOCK_STREAM,
207 .pr_domain = &inetdomain,
208 .pr_protocol = IPPROTO_SCTP,
209 .pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD,
211 .pr_input = sctp_input,
213 .pr_ctlinput = sctp_ctlinput,
214 .pr_ctloutput = sctp_ctloutput,
216 .pr_ctlport = cpu0_ctlport,
217 .pr_drain = sctp_drain,
218 .pr_usrreqs = &sctp_usrreqs
223 .pr_domain = &inetdomain,
224 .pr_protocol = IPPROTO_RAW,
225 .pr_flags = PR_ATOMIC|PR_ADDR,
227 .pr_input = rip_input,
229 .pr_ctlinput = rip_ctlinput,
230 .pr_ctloutput = rip_ctloutput,
232 .pr_ctlport = cpu0_ctlport,
233 .pr_usrreqs = &rip_usrreqs
237 .pr_domain = &inetdomain,
238 .pr_protocol = IPPROTO_ICMP,
239 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
241 .pr_input = icmp_input,
244 .pr_ctloutput = rip_ctloutput,
246 .pr_usrreqs = &rip_usrreqs
250 .pr_domain = &inetdomain,
251 .pr_protocol = IPPROTO_IGMP,
252 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
254 .pr_input = igmp_input,
257 .pr_ctloutput = rip_ctloutput,
259 .pr_init = igmp_init,
260 .pr_fasttimo = igmp_fasttimo,
261 .pr_slowtimo = igmp_slowtimo,
263 .pr_usrreqs = &rip_usrreqs
267 .pr_domain = &inetdomain,
268 .pr_protocol = IPPROTO_RSVP,
269 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
271 .pr_input = rsvp_input,
274 .pr_ctloutput = rip_ctloutput,
276 .pr_usrreqs = &rip_usrreqs
281 .pr_domain = &inetdomain,
282 .pr_protocol = IPPROTO_AH,
283 .pr_flags = PR_ATOMIC|PR_ADDR,
285 .pr_input = ah4_input,
288 .pr_ctloutput = NULL,
291 .pr_usrreqs = &nousrreqs
296 .pr_domain = &inetdomain,
297 .pr_protocol = IPPROTO_ESP,
298 .pr_flags = PR_ATOMIC|PR_ADDR,
300 .pr_input = esp4_input,
303 .pr_ctloutput = NULL,
306 .pr_usrreqs = &nousrreqs
311 .pr_domain = &inetdomain,
312 .pr_protocol = IPPROTO_IPCOMP,
313 .pr_flags = PR_ATOMIC|PR_ADDR,
315 .pr_input = ipcomp4_input,
318 .pr_ctloutput = NULL,
321 .pr_usrreqs = &nousrreqs
327 .pr_domain = &inetdomain,
328 .pr_protocol = IPPROTO_AH,
329 .pr_flags = PR_ATOMIC|PR_ADDR,
331 .pr_input = ipsec4_common_input,
334 .pr_ctloutput = NULL,
337 .pr_usrreqs = &nousrreqs
341 .pr_domain = &inetdomain,
342 .pr_protocol = IPPROTO_ESP,
343 .pr_flags = PR_ATOMIC|PR_ADDR,
345 .pr_input = ipsec4_common_input,
348 .pr_ctloutput = NULL,
351 .pr_usrreqs = &nousrreqs
355 .pr_domain = &inetdomain,
356 .pr_protocol = IPPROTO_IPCOMP,
357 .pr_flags = PR_ATOMIC|PR_ADDR,
359 .pr_input = ipsec4_common_input,
362 .pr_ctloutput = NULL,
365 .pr_usrreqs = &nousrreqs
367 #endif /* FAST_IPSEC */
370 .pr_domain = &inetdomain,
371 .pr_protocol = IPPROTO_IPV4,
372 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
373 .pr_input = encap4_input,
376 .pr_ctloutput = rip_ctloutput,
379 .pr_init = encap_init,
380 .pr_usrreqs = &rip_usrreqs
384 .pr_domain = &inetdomain,
385 .pr_protocol = IPPROTO_MOBILE,
386 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
388 .pr_input = encap4_input,
391 .pr_ctloutput = rip_ctloutput,
394 .pr_init = encap_init,
395 .pr_usrreqs = &rip_usrreqs
399 .pr_domain = &inetdomain,
400 .pr_protocol = IPPROTO_GRE,
401 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
403 .pr_input = encap4_input,
406 .pr_ctloutput = rip_ctloutput,
409 .pr_init = encap_init,
410 .pr_usrreqs = &rip_usrreqs
415 .pr_domain = &inetdomain,
416 .pr_protocol = IPPROTO_IPV6,
417 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
419 .pr_input = encap4_input,
422 .pr_ctloutput = rip_ctloutput,
425 .pr_init = encap_init,
426 .pr_usrreqs = &rip_usrreqs
432 .pr_domain = &inetdomain,
433 .pr_protocol = IPPROTO_DIVERT,
434 .pr_flags = PR_ATOMIC|PR_ADDR,
436 .pr_input = div_input,
439 .pr_ctloutput = ip_ctloutput,
443 .pr_usrreqs = &div_usrreqs
449 .pr_domain = &inetdomain,
450 .pr_protocol = IPPROTO_IDP,
451 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
453 .pr_input = ipxip_input,
455 .pr_ctlinput = ipxip_ctlinput,
456 .pr_ctloutput = NULL,
458 .pr_ctlport = cpu0_ctlport,
459 .pr_usrreqs = &rip_usrreqs
465 .pr_domain = &inetdomain,
466 .pr_protocol = IPPROTO_IDP,
467 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
469 .pr_input = idpip_input,
471 .pr_ctlinput = nsip_ctlinput,
472 .pr_ctloutput = NULL,
474 .pr_ctlport = cpu0_ctlport,
475 .pr_usrreqs = &rip_usrreqs
481 .pr_domain = &inetdomain,
482 .pr_protocol = IPPROTO_PIM,
483 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
485 .pr_input = pim_input,
488 .pr_ctloutput = rip_ctloutput,
491 .pr_usrreqs = &rip_usrreqs
497 .pr_domain = &inetdomain,
498 .pr_protocol = IPPROTO_PFSYNC,
499 .pr_flags = PR_ATOMIC|PR_ADDR,
501 .pr_input = pfsync_input,
504 .pr_ctloutput = rip_ctloutput,
507 .pr_usrreqs = &rip_usrreqs
513 .pr_domain = &inetdomain,
515 .pr_flags = PR_ATOMIC|PR_ADDR,
517 .pr_input = rip_input,
520 .pr_ctloutput = rip_ctloutput,
524 .pr_usrreqs = &rip_usrreqs
529 .pr_domain = &inetdomain,
530 .pr_protocol = IPPROTO_CARP,
531 .pr_flags = PR_ATOMIC|PR_ADDR,
533 .pr_input = carp_input,
534 .pr_output = rip_output,
536 .pr_ctloutput = rip_ctloutput,
539 .pr_usrreqs = &rip_usrreqs
544 struct domain inetdomain = {
545 AF_INET, "internet", NULL, NULL, NULL,
546 inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
547 SLIST_ENTRY_INITIALIZER,
548 in_inithead, 32, sizeof(struct sockaddr_in),
553 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
556 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
557 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
558 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
559 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
560 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
562 /* XXX no protocol # to use, pick something "reserved" */
563 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
564 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
565 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
566 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
567 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
570 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
572 #endif /* !FAST_IPSEC */
573 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
575 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
578 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
581 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");