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_inet6.h"
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/socket.h>
41 #include <sys/domain.h>
42 #include <sys/protosw.h>
43 #include <sys/queue.h>
44 #include <sys/sysctl.h>
47 #include <net/route.h>
49 #include <netinet/in.h>
50 #include <netinet/in_systm.h>
51 #include <netinet/in_pcb.h>
52 #include <netinet/ip.h>
53 #include <netinet/ip_var.h>
54 #include <netinet/ip_icmp.h>
55 #include <netinet/igmp_var.h>
57 #include <netinet/pim_var.h>
59 #include <netinet/tcp.h>
60 #include <netinet/tcp_timer.h>
61 #include <netinet/tcp_var.h>
62 #include <netinet/udp.h>
63 #include <netinet/udp_var.h>
64 #include <netinet/ip_encap.h>
66 #include <netinet/ip_divert.h>
70 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
73 #include <net/netisr.h> /* for cpu0_soport */
76 #include <netinet/ip_carp.h>
79 extern struct domain inetdomain;
80 static struct pr_usrreqs nousrreqs;
82 struct protosw inetsw[] = {
85 .pr_domain = &inetdomain,
93 .pr_usrreqs = &nousrreqs
96 .pr_type = SOCK_DGRAM,
97 .pr_domain = &inetdomain,
98 .pr_protocol = IPPROTO_UDP,
99 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE|
100 PR_ASYNC_SEND|PR_ASEND_HOLDTD|PR_ACONN_HOLDTD,
102 .pr_initport = udp_initport,
103 .pr_input = udp_input,
105 .pr_ctlinput = udp_ctlinput,
106 .pr_ctloutput = udp_ctloutput,
108 .pr_ctlport = udp_ctlport,
110 .pr_usrreqs = &udp_usrreqs
113 .pr_type = SOCK_STREAM,
114 .pr_domain = &inetdomain,
115 .pr_protocol = IPPROTO_TCP,
116 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_MPSAFE|
117 PR_ASYNC_SEND|PR_ASYNC_RCVD|PR_ACONN_HOLDTD,
119 .pr_initport = tcp_initport,
120 .pr_input = tcp_input,
122 .pr_ctlinput = tcp_ctlinput,
123 .pr_ctloutmsg = tcp_ctloutmsg,
124 .pr_ctloutput = tcp_ctloutput,
126 .pr_ctlport = tcp_ctlport,
128 .pr_drain = tcp_drain,
129 .pr_usrreqs = &tcp_usrreqs
133 .pr_domain = &inetdomain,
134 .pr_protocol = IPPROTO_RAW,
135 .pr_flags = PR_ATOMIC|PR_ADDR,
137 .pr_input = rip_input,
139 .pr_ctlinput = rip_ctlinput,
140 .pr_ctloutput = rip_ctloutput,
142 .pr_ctlport = cpu0_ctlport,
143 .pr_usrreqs = &rip_usrreqs
147 .pr_domain = &inetdomain,
148 .pr_protocol = IPPROTO_ICMP,
149 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
151 .pr_input = icmp_input,
154 .pr_ctloutput = rip_ctloutput,
156 .pr_usrreqs = &rip_usrreqs
160 .pr_domain = &inetdomain,
161 .pr_protocol = IPPROTO_IGMP,
162 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
164 .pr_input = igmp_input,
167 .pr_ctloutput = rip_ctloutput,
169 .pr_init = igmp_init,
171 .pr_usrreqs = &rip_usrreqs
175 .pr_domain = &inetdomain,
176 .pr_protocol = IPPROTO_RSVP,
177 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
179 .pr_input = rsvp_input,
182 .pr_ctloutput = rip_ctloutput,
184 .pr_usrreqs = &rip_usrreqs
188 .pr_domain = &inetdomain,
189 .pr_protocol = IPPROTO_IPV4,
190 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
191 .pr_input = encap4_input,
194 .pr_ctloutput = rip_ctloutput,
197 .pr_init = encap_init,
198 .pr_usrreqs = &rip_usrreqs
202 .pr_domain = &inetdomain,
203 .pr_protocol = IPPROTO_MOBILE,
204 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
206 .pr_input = encap4_input,
209 .pr_ctloutput = rip_ctloutput,
212 .pr_init = encap_init,
213 .pr_usrreqs = &rip_usrreqs
217 .pr_domain = &inetdomain,
218 .pr_protocol = IPPROTO_GRE,
219 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
221 .pr_input = encap4_input,
224 .pr_ctloutput = rip_ctloutput,
227 .pr_init = encap_init,
228 .pr_usrreqs = &rip_usrreqs
233 .pr_domain = &inetdomain,
234 .pr_protocol = IPPROTO_IPV6,
235 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
237 .pr_input = encap4_input,
240 .pr_ctloutput = rip_ctloutput,
243 .pr_init = encap_init,
244 .pr_usrreqs = &rip_usrreqs
250 .pr_domain = &inetdomain,
251 .pr_protocol = IPPROTO_DIVERT,
252 .pr_flags = PR_ATOMIC|PR_ADDR,
254 .pr_input = div_input,
257 .pr_ctloutput = ip_ctloutput,
261 .pr_usrreqs = &div_usrreqs
267 .pr_domain = &inetdomain,
268 .pr_protocol = IPPROTO_PIM,
269 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
271 .pr_input = pim_input,
274 .pr_ctloutput = rip_ctloutput,
277 .pr_usrreqs = &rip_usrreqs
283 .pr_domain = &inetdomain,
284 .pr_protocol = IPPROTO_PFSYNC,
285 .pr_flags = PR_ATOMIC|PR_ADDR,
287 .pr_input = pfsync_input,
290 .pr_ctloutput = rip_ctloutput,
293 .pr_usrreqs = &rip_usrreqs
299 .pr_domain = &inetdomain,
301 .pr_flags = PR_ATOMIC|PR_ADDR,
303 .pr_input = rip_input,
306 .pr_ctloutput = rip_ctloutput,
310 .pr_usrreqs = &rip_usrreqs
315 .pr_domain = &inetdomain,
316 .pr_protocol = IPPROTO_CARP,
317 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
319 .pr_input = carp_proto_input,
320 .pr_output = rip_output,
321 .pr_ctlinput = carp_proto_ctlinput,
322 .pr_ctloutput = rip_ctloutput,
324 .pr_ctlport = cpu0_ctlport,
325 .pr_usrreqs = &rip_usrreqs
331 inetdomain_init(void)
336 struct domain inetdomain = {
337 .dom_family = AF_INET,
338 .dom_name = "internet",
339 .dom_init = inetdomain_init,
340 .dom_externalize = NULL,
342 .dom_protosw = inetsw,
343 .dom_protoswNPROTOSW = &inetsw[NELEM(inetsw)],
344 .dom_next = SLIST_ENTRY_INITIALIZER,
345 .dom_rtattach = in_inithead,
347 .dom_maxrtkey = sizeof(struct sockaddr_in),
348 .dom_ifattach = NULL,
354 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
357 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
358 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
359 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
360 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
361 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
362 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
364 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
367 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
370 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");