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 $
37 #include "opt_ipdivert.h"
39 #include "opt_mrouting.h"
40 #include "opt_ipsec.h"
41 #include "opt_inet6.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>
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>
63 #include <netinet/pim_var.h>
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>
72 #include <netinet/ip_divert.h>
76 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
80 #include <netinet6/ipsec.h>
81 #include <netinet6/ah.h>
83 #include <netinet6/esp.h>
85 #include <netinet6/ipcomp.h>
89 #include <netproto/ipsec/ipsec.h>
90 #endif /* FAST_IPSEC */
93 #include <netproto/ipx/ipx_ip.h>
97 #include <netinet/in_pcb.h>
98 #include <netinet/sctp_pcb.h>
99 #include <netinet/sctp.h>
100 #include <netinet/sctp_var.h>
103 #include <net/netisr.h> /* for cpu0_soport */
106 #include <netinet/ip_carp.h>
109 extern struct domain inetdomain;
110 static struct pr_usrreqs nousrreqs;
112 struct protosw inetsw[] = {
115 .pr_domain = &inetdomain,
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,
135 .pr_ctlinput = udp_ctlinput,
136 .pr_ctloutput = ip_ctloutput,
138 .pr_ctlport = udp_ctlport,
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|
147 PR_MPSAFE|PR_ASYNC_SEND|PR_ASYNC_RCVD,
149 .pr_input = tcp_input,
151 .pr_ctlinput = tcp_ctlinput,
152 .pr_ctloutput = tcp_ctloutput,
154 .pr_ctlport = tcp_ctlport,
158 .pr_drain = tcp_drain,
159 .pr_usrreqs = &tcp_usrreqs
163 * Order is very important here, we add the good one in
164 * in this postion so it maps to the right ip_protox[]
165 * postion for SCTP. Don't move the one above below
166 * this one or IPv6/4 compatability will break
169 .pr_type = SOCK_DGRAM,
170 .pr_domain = &inetdomain,
171 .pr_protocol = IPPROTO_SCTP,
172 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
174 .pr_input = sctp_input,
176 .pr_ctlinput = sctp_ctlinput,
177 .pr_ctloutput = sctp_ctloutput,
179 .pr_ctlport = cpu0_ctlport,
180 .pr_init = sctp_init,
181 .pr_drain = sctp_drain,
182 .pr_usrreqs = &sctp_usrreqs
185 .pr_type = SOCK_SEQPACKET,
186 .pr_domain = &inetdomain,
187 .pr_protocol = IPPROTO_SCTP,
188 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
190 .pr_input = sctp_input,
192 .pr_ctlinput = sctp_ctlinput,
193 .pr_ctloutput = sctp_ctloutput,
195 .pr_ctlport = cpu0_ctlport,
196 .pr_drain = sctp_drain,
197 .pr_usrreqs = &sctp_usrreqs
201 .pr_type = SOCK_STREAM,
202 .pr_domain = &inetdomain,
203 .pr_protocol = IPPROTO_SCTP,
204 .pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD,
206 .pr_input = sctp_input,
208 .pr_ctlinput = sctp_ctlinput,
209 .pr_ctloutput = sctp_ctloutput,
211 .pr_ctlport = cpu0_ctlport,
212 .pr_drain = sctp_drain,
213 .pr_usrreqs = &sctp_usrreqs
218 .pr_domain = &inetdomain,
219 .pr_protocol = IPPROTO_RAW,
220 .pr_flags = PR_ATOMIC|PR_ADDR,
222 .pr_input = rip_input,
224 .pr_ctlinput = rip_ctlinput,
225 .pr_ctloutput = rip_ctloutput,
227 .pr_ctlport = cpu0_ctlport,
228 .pr_usrreqs = &rip_usrreqs
232 .pr_domain = &inetdomain,
233 .pr_protocol = IPPROTO_ICMP,
234 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
236 .pr_input = icmp_input,
239 .pr_ctloutput = rip_ctloutput,
241 .pr_usrreqs = &rip_usrreqs
245 .pr_domain = &inetdomain,
246 .pr_protocol = IPPROTO_IGMP,
247 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
249 .pr_input = igmp_input,
252 .pr_ctloutput = rip_ctloutput,
254 .pr_init = igmp_init,
255 .pr_fasttimo = igmp_fasttimo,
256 .pr_slowtimo = igmp_slowtimo,
258 .pr_usrreqs = &rip_usrreqs
262 .pr_domain = &inetdomain,
263 .pr_protocol = IPPROTO_RSVP,
264 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
266 .pr_input = rsvp_input,
269 .pr_ctloutput = rip_ctloutput,
271 .pr_usrreqs = &rip_usrreqs
276 .pr_domain = &inetdomain,
277 .pr_protocol = IPPROTO_AH,
278 .pr_flags = PR_ATOMIC|PR_ADDR,
280 .pr_input = ah4_input,
283 .pr_ctloutput = NULL,
286 .pr_usrreqs = &nousrreqs
291 .pr_domain = &inetdomain,
292 .pr_protocol = IPPROTO_ESP,
293 .pr_flags = PR_ATOMIC|PR_ADDR,
295 .pr_input = esp4_input,
298 .pr_ctloutput = NULL,
301 .pr_usrreqs = &nousrreqs
306 .pr_domain = &inetdomain,
307 .pr_protocol = IPPROTO_IPCOMP,
308 .pr_flags = PR_ATOMIC|PR_ADDR,
310 .pr_input = ipcomp4_input,
313 .pr_ctloutput = NULL,
316 .pr_usrreqs = &nousrreqs
322 .pr_domain = &inetdomain,
323 .pr_protocol = IPPROTO_AH,
324 .pr_flags = PR_ATOMIC|PR_ADDR,
326 .pr_input = ipsec4_common_input,
329 .pr_ctloutput = NULL,
332 .pr_usrreqs = &nousrreqs
336 .pr_domain = &inetdomain,
337 .pr_protocol = IPPROTO_ESP,
338 .pr_flags = PR_ATOMIC|PR_ADDR,
340 .pr_input = ipsec4_common_input,
343 .pr_ctloutput = NULL,
346 .pr_usrreqs = &nousrreqs
350 .pr_domain = &inetdomain,
351 .pr_protocol = IPPROTO_IPCOMP,
352 .pr_flags = PR_ATOMIC|PR_ADDR,
354 .pr_input = ipsec4_common_input,
357 .pr_ctloutput = NULL,
360 .pr_usrreqs = &nousrreqs
362 #endif /* FAST_IPSEC */
365 .pr_domain = &inetdomain,
366 .pr_protocol = IPPROTO_IPV4,
367 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
368 .pr_input = encap4_input,
371 .pr_ctloutput = rip_ctloutput,
374 .pr_init = encap_init,
375 .pr_usrreqs = &rip_usrreqs
379 .pr_domain = &inetdomain,
380 .pr_protocol = IPPROTO_MOBILE,
381 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
383 .pr_input = encap4_input,
386 .pr_ctloutput = rip_ctloutput,
389 .pr_init = encap_init,
390 .pr_usrreqs = &rip_usrreqs
394 .pr_domain = &inetdomain,
395 .pr_protocol = IPPROTO_GRE,
396 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
398 .pr_input = encap4_input,
401 .pr_ctloutput = rip_ctloutput,
404 .pr_init = encap_init,
405 .pr_usrreqs = &rip_usrreqs
410 .pr_domain = &inetdomain,
411 .pr_protocol = IPPROTO_IPV6,
412 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
414 .pr_input = encap4_input,
417 .pr_ctloutput = rip_ctloutput,
420 .pr_init = encap_init,
421 .pr_usrreqs = &rip_usrreqs
427 .pr_domain = &inetdomain,
428 .pr_protocol = IPPROTO_DIVERT,
429 .pr_flags = PR_ATOMIC|PR_ADDR,
431 .pr_input = div_input,
434 .pr_ctloutput = ip_ctloutput,
438 .pr_usrreqs = &div_usrreqs
444 .pr_domain = &inetdomain,
445 .pr_protocol = IPPROTO_IDP,
446 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
448 .pr_input = ipxip_input,
450 .pr_ctlinput = ipxip_ctlinput,
451 .pr_ctloutput = NULL,
453 .pr_ctlport = cpu0_ctlport,
454 .pr_usrreqs = &rip_usrreqs
460 .pr_domain = &inetdomain,
461 .pr_protocol = IPPROTO_PIM,
462 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
464 .pr_input = pim_input,
467 .pr_ctloutput = rip_ctloutput,
470 .pr_usrreqs = &rip_usrreqs
476 .pr_domain = &inetdomain,
477 .pr_protocol = IPPROTO_PFSYNC,
478 .pr_flags = PR_ATOMIC|PR_ADDR,
480 .pr_input = pfsync_input,
483 .pr_ctloutput = rip_ctloutput,
486 .pr_usrreqs = &rip_usrreqs
492 .pr_domain = &inetdomain,
494 .pr_flags = PR_ATOMIC|PR_ADDR,
496 .pr_input = rip_input,
499 .pr_ctloutput = rip_ctloutput,
503 .pr_usrreqs = &rip_usrreqs
508 .pr_domain = &inetdomain,
509 .pr_protocol = IPPROTO_CARP,
510 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
512 .pr_input = carp_proto_input,
513 .pr_output = rip_output,
514 .pr_ctlinput = carp_proto_ctlinput,
515 .pr_ctloutput = rip_ctloutput,
517 .pr_ctlport = cpu0_ctlport,
518 .pr_usrreqs = &rip_usrreqs
523 struct domain inetdomain = {
524 AF_INET, "internet", NULL, NULL, NULL,
525 inetsw, &inetsw[NELEM(inetsw)],
526 SLIST_ENTRY_INITIALIZER,
527 in_inithead, 32, sizeof(struct sockaddr_in),
532 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
535 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
536 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
537 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
538 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
539 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
541 /* XXX no protocol # to use, pick something "reserved" */
542 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
543 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
544 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
545 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
546 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
549 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
551 #endif /* !FAST_IPSEC */
552 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
554 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
557 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
560 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");