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. 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
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"
40 #include <sys/param.h>
41 #include <sys/kernel.h>
42 #include <sys/socket.h>
43 #include <sys/domain.h>
44 #include <sys/protosw.h>
45 #include <sys/queue.h>
46 #include <sys/sysctl.h>
49 #include <net/route.h>
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/ip.h>
54 #include <netinet/ip_var.h>
55 #include <netinet/ip_icmp.h>
56 #include <netinet/igmp_var.h>
58 #include <netinet/pim_var.h>
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>
67 #include <netinet/ip_divert.h>
71 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
75 #include <netinet6/ipsec.h>
76 #include <netinet6/ah.h>
78 #include <netinet6/esp.h>
80 #include <netinet6/ipcomp.h>
84 #include <netproto/ipsec/ipsec.h>
85 #endif /* FAST_IPSEC */
88 #include <netinet/in_pcb.h>
89 #include <netinet/sctp_pcb.h>
90 #include <netinet/sctp.h>
91 #include <netinet/sctp_var.h>
94 #include <net/netisr.h> /* for cpu0_soport */
97 #include <netinet/ip_carp.h>
100 extern struct domain inetdomain;
101 static struct pr_usrreqs nousrreqs;
103 struct protosw inetsw[] = {
106 .pr_domain = &inetdomain,
114 .pr_slowtimo = ip_slowtimo,
115 .pr_drain = ip_drain,
116 .pr_usrreqs = &nousrreqs
119 .pr_type = SOCK_DGRAM,
120 .pr_domain = &inetdomain,
121 .pr_protocol = IPPROTO_UDP,
122 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE|
123 PR_ASYNC_SEND|PR_ASEND_HOLDTD,
125 .pr_input = udp_input,
127 .pr_ctlinput = udp_ctlinput,
128 .pr_ctloutput = ip_ctloutput,
130 .pr_ctlport = udp_ctlport,
132 .pr_usrreqs = &udp_usrreqs
135 .pr_type = SOCK_STREAM,
136 .pr_domain = &inetdomain,
137 .pr_protocol = IPPROTO_TCP,
138 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_MPSAFE|
139 PR_ASYNC_SEND|PR_ASYNC_RCVD|PR_ACONN_HOLDTD|
142 .pr_input = tcp_input,
144 .pr_ctlinput = tcp_ctlinput,
145 .pr_ctloutput = tcp_ctloutput,
147 .pr_ctlport = tcp_ctlport,
151 .pr_drain = tcp_drain,
152 .pr_usrreqs = &tcp_usrreqs
156 * Order is very important here, we add the good one in
157 * in this postion so it maps to the right ip_protox[]
158 * postion for SCTP. Don't move the one above below
159 * this one or IPv6/4 compatability will break
162 .pr_type = SOCK_DGRAM,
163 .pr_domain = &inetdomain,
164 .pr_protocol = IPPROTO_SCTP,
165 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
167 .pr_input = sctp_input,
169 .pr_ctlinput = sctp_ctlinput,
170 .pr_ctloutput = sctp_ctloutput,
172 .pr_ctlport = cpu0_ctlport,
173 .pr_init = sctp_init,
174 .pr_drain = sctp_drain,
175 .pr_usrreqs = &sctp_usrreqs
178 .pr_type = SOCK_SEQPACKET,
179 .pr_domain = &inetdomain,
180 .pr_protocol = IPPROTO_SCTP,
181 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
183 .pr_input = sctp_input,
185 .pr_ctlinput = sctp_ctlinput,
186 .pr_ctloutput = sctp_ctloutput,
188 .pr_ctlport = cpu0_ctlport,
189 .pr_drain = sctp_drain,
190 .pr_usrreqs = &sctp_usrreqs
194 .pr_type = SOCK_STREAM,
195 .pr_domain = &inetdomain,
196 .pr_protocol = IPPROTO_SCTP,
197 .pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD,
199 .pr_input = sctp_input,
201 .pr_ctlinput = sctp_ctlinput,
202 .pr_ctloutput = sctp_ctloutput,
204 .pr_ctlport = cpu0_ctlport,
205 .pr_drain = sctp_drain,
206 .pr_usrreqs = &sctp_usrreqs
211 .pr_domain = &inetdomain,
212 .pr_protocol = IPPROTO_RAW,
213 .pr_flags = PR_ATOMIC|PR_ADDR,
215 .pr_input = rip_input,
217 .pr_ctlinput = rip_ctlinput,
218 .pr_ctloutput = rip_ctloutput,
220 .pr_ctlport = cpu0_ctlport,
221 .pr_usrreqs = &rip_usrreqs
225 .pr_domain = &inetdomain,
226 .pr_protocol = IPPROTO_ICMP,
227 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
229 .pr_input = icmp_input,
232 .pr_ctloutput = rip_ctloutput,
234 .pr_usrreqs = &rip_usrreqs
238 .pr_domain = &inetdomain,
239 .pr_protocol = IPPROTO_IGMP,
240 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
242 .pr_input = igmp_input,
245 .pr_ctloutput = rip_ctloutput,
247 .pr_init = igmp_init,
248 .pr_fasttimo = igmp_fasttimo,
249 .pr_slowtimo = igmp_slowtimo,
251 .pr_usrreqs = &rip_usrreqs
255 .pr_domain = &inetdomain,
256 .pr_protocol = IPPROTO_RSVP,
257 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
259 .pr_input = rsvp_input,
262 .pr_ctloutput = rip_ctloutput,
264 .pr_usrreqs = &rip_usrreqs
269 .pr_domain = &inetdomain,
270 .pr_protocol = IPPROTO_AH,
271 .pr_flags = PR_ATOMIC|PR_ADDR,
273 .pr_input = ah4_input,
276 .pr_ctloutput = NULL,
279 .pr_usrreqs = &nousrreqs
284 .pr_domain = &inetdomain,
285 .pr_protocol = IPPROTO_ESP,
286 .pr_flags = PR_ATOMIC|PR_ADDR,
288 .pr_input = esp4_input,
291 .pr_ctloutput = NULL,
294 .pr_usrreqs = &nousrreqs
299 .pr_domain = &inetdomain,
300 .pr_protocol = IPPROTO_IPCOMP,
301 .pr_flags = PR_ATOMIC|PR_ADDR,
303 .pr_input = ipcomp4_input,
306 .pr_ctloutput = NULL,
309 .pr_usrreqs = &nousrreqs
315 .pr_domain = &inetdomain,
316 .pr_protocol = IPPROTO_AH,
317 .pr_flags = PR_ATOMIC|PR_ADDR,
319 .pr_input = ipsec4_common_input,
322 .pr_ctloutput = NULL,
325 .pr_usrreqs = &nousrreqs
329 .pr_domain = &inetdomain,
330 .pr_protocol = IPPROTO_ESP,
331 .pr_flags = PR_ATOMIC|PR_ADDR,
333 .pr_input = ipsec4_common_input,
336 .pr_ctloutput = NULL,
339 .pr_usrreqs = &nousrreqs
343 .pr_domain = &inetdomain,
344 .pr_protocol = IPPROTO_IPCOMP,
345 .pr_flags = PR_ATOMIC|PR_ADDR,
347 .pr_input = ipsec4_common_input,
350 .pr_ctloutput = NULL,
353 .pr_usrreqs = &nousrreqs
355 #endif /* FAST_IPSEC */
358 .pr_domain = &inetdomain,
359 .pr_protocol = IPPROTO_IPV4,
360 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
361 .pr_input = encap4_input,
364 .pr_ctloutput = rip_ctloutput,
367 .pr_init = encap_init,
368 .pr_usrreqs = &rip_usrreqs
372 .pr_domain = &inetdomain,
373 .pr_protocol = IPPROTO_MOBILE,
374 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
376 .pr_input = encap4_input,
379 .pr_ctloutput = rip_ctloutput,
382 .pr_init = encap_init,
383 .pr_usrreqs = &rip_usrreqs
387 .pr_domain = &inetdomain,
388 .pr_protocol = IPPROTO_GRE,
389 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
391 .pr_input = encap4_input,
394 .pr_ctloutput = rip_ctloutput,
397 .pr_init = encap_init,
398 .pr_usrreqs = &rip_usrreqs
403 .pr_domain = &inetdomain,
404 .pr_protocol = IPPROTO_IPV6,
405 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
407 .pr_input = encap4_input,
410 .pr_ctloutput = rip_ctloutput,
413 .pr_init = encap_init,
414 .pr_usrreqs = &rip_usrreqs
420 .pr_domain = &inetdomain,
421 .pr_protocol = IPPROTO_DIVERT,
422 .pr_flags = PR_ATOMIC|PR_ADDR,
424 .pr_input = div_input,
427 .pr_ctloutput = ip_ctloutput,
431 .pr_usrreqs = &div_usrreqs
437 .pr_domain = &inetdomain,
438 .pr_protocol = IPPROTO_PIM,
439 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
441 .pr_input = pim_input,
444 .pr_ctloutput = rip_ctloutput,
447 .pr_usrreqs = &rip_usrreqs
453 .pr_domain = &inetdomain,
454 .pr_protocol = IPPROTO_PFSYNC,
455 .pr_flags = PR_ATOMIC|PR_ADDR,
457 .pr_input = pfsync_input,
460 .pr_ctloutput = rip_ctloutput,
463 .pr_usrreqs = &rip_usrreqs
469 .pr_domain = &inetdomain,
471 .pr_flags = PR_ATOMIC|PR_ADDR,
473 .pr_input = rip_input,
476 .pr_ctloutput = rip_ctloutput,
480 .pr_usrreqs = &rip_usrreqs
485 .pr_domain = &inetdomain,
486 .pr_protocol = IPPROTO_CARP,
487 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
489 .pr_input = carp_proto_input,
490 .pr_output = rip_output,
491 .pr_ctlinput = carp_proto_ctlinput,
492 .pr_ctloutput = rip_ctloutput,
494 .pr_ctlport = cpu0_ctlport,
495 .pr_usrreqs = &rip_usrreqs
500 struct domain inetdomain = {
501 AF_INET, "internet", NULL, NULL, NULL,
502 inetsw, &inetsw[NELEM(inetsw)],
503 SLIST_ENTRY_INITIALIZER,
504 in_inithead, 32, sizeof(struct sockaddr_in),
509 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
512 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
513 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
514 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
515 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
516 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
518 /* XXX no protocol # to use, pick something "reserved" */
519 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
520 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
521 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
522 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
523 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
526 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
528 #endif /* !FAST_IPSEC */
529 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
531 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
534 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
537 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");