2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include "opt_mrouting.h"
38 #include "opt_ipsec.h"
40 #include "opt_inet6.h"
42 #include "opt_mpath.h"
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/malloc.h>
48 #include <sys/socket.h>
49 #include <sys/domain.h>
51 #include <sys/protosw.h>
52 #include <sys/queue.h>
53 #include <sys/sysctl.h>
56 * While this file provides the domain and protocol switch tables for IPv4, it
57 * also provides the sysctl node declarations for net.inet.* often shared with
58 * IPv6 for common features or by upper layer protocols. In case of no IPv4
59 * support compile out everything but these sysctl nodes.
63 #include <net/if_var.h>
64 #include <net/route.h>
66 #include <net/radix_mpath.h>
71 #if defined(INET) || defined(INET6)
72 #include <netinet/in.h>
76 #include <netinet/in_systm.h>
77 #include <netinet/in_var.h>
78 #include <netinet/ip.h>
79 #include <netinet/ip_var.h>
80 #include <netinet/ip_icmp.h>
81 #include <netinet/igmp_var.h>
82 #include <netinet/tcp.h>
83 #include <netinet/tcp_timer.h>
84 #include <netinet/tcp_var.h>
85 #include <netinet/udp.h>
86 #include <netinet/udp_var.h>
87 #include <netinet/ip_encap.h>
90 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
93 static struct pr_usrreqs nousrreqs;
96 #include <netinet/in_pcb.h>
97 #include <netinet/sctp_pcb.h>
98 #include <netinet/sctp.h>
99 #include <netinet/sctp_var.h>
102 FEATURE(inet, "Internet Protocol version 4");
104 extern struct domain inetdomain;
106 /* Spacer for loadable protocols. */
107 #define IPPROTOSPACER \
109 .pr_domain = &inetdomain, \
110 .pr_protocol = PROTO_SPACER, \
111 .pr_usrreqs = &nousrreqs \
114 struct protosw inetsw[] = {
117 .pr_domain = &inetdomain,
118 .pr_protocol = IPPROTO_IP,
120 .pr_slowtimo = ip_slowtimo,
121 .pr_drain = ip_drain,
122 .pr_usrreqs = &nousrreqs
125 .pr_type = SOCK_DGRAM,
126 .pr_domain = &inetdomain,
127 .pr_protocol = IPPROTO_UDP,
128 .pr_flags = PR_ATOMIC|PR_ADDR,
129 .pr_input = udp_input,
130 .pr_ctlinput = udp_ctlinput,
131 .pr_ctloutput = udp_ctloutput,
133 .pr_usrreqs = &udp_usrreqs
136 .pr_type = SOCK_STREAM,
137 .pr_domain = &inetdomain,
138 .pr_protocol = IPPROTO_TCP,
139 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
140 .pr_input = tcp_input,
141 .pr_ctlinput = tcp_ctlinput,
142 .pr_ctloutput = tcp_ctloutput,
144 .pr_slowtimo = tcp_slowtimo,
145 .pr_drain = tcp_drain,
146 .pr_usrreqs = &tcp_usrreqs
150 .pr_type = SOCK_SEQPACKET,
151 .pr_domain = &inetdomain,
152 .pr_protocol = IPPROTO_SCTP,
153 .pr_flags = PR_WANTRCVD|PR_LASTHDR,
154 .pr_input = sctp_input,
155 .pr_ctlinput = sctp_ctlinput,
156 .pr_ctloutput = sctp_ctloutput,
157 .pr_init = sctp_init,
158 .pr_drain = sctp_drain,
159 .pr_usrreqs = &sctp_usrreqs
162 .pr_type = SOCK_STREAM,
163 .pr_domain = &inetdomain,
164 .pr_protocol = IPPROTO_SCTP,
165 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LASTHDR,
166 .pr_input = sctp_input,
167 .pr_ctlinput = sctp_ctlinput,
168 .pr_ctloutput = sctp_ctloutput,
169 .pr_drain = sctp_drain,
170 .pr_usrreqs = &sctp_usrreqs
174 .pr_type = SOCK_DGRAM,
175 .pr_domain = &inetdomain,
176 .pr_protocol = IPPROTO_UDPLITE,
177 .pr_flags = PR_ATOMIC|PR_ADDR,
178 .pr_input = udp_input,
179 .pr_ctlinput = udplite_ctlinput,
180 .pr_ctloutput = udp_ctloutput,
181 .pr_init = udplite_init,
182 .pr_usrreqs = &udp_usrreqs
186 .pr_domain = &inetdomain,
187 .pr_protocol = IPPROTO_RAW,
188 .pr_flags = PR_ATOMIC|PR_ADDR,
189 .pr_input = rip_input,
190 .pr_ctlinput = rip_ctlinput,
191 .pr_ctloutput = rip_ctloutput,
192 .pr_usrreqs = &rip_usrreqs
196 .pr_domain = &inetdomain,
197 .pr_protocol = IPPROTO_ICMP,
198 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
199 .pr_input = icmp_input,
200 .pr_ctloutput = rip_ctloutput,
201 .pr_usrreqs = &rip_usrreqs
205 .pr_domain = &inetdomain,
206 .pr_protocol = IPPROTO_IGMP,
207 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
208 .pr_input = igmp_input,
209 .pr_ctloutput = rip_ctloutput,
210 .pr_fasttimo = igmp_fasttimo,
211 .pr_slowtimo = igmp_slowtimo,
212 .pr_usrreqs = &rip_usrreqs
216 .pr_domain = &inetdomain,
217 .pr_protocol = IPPROTO_RSVP,
218 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
219 .pr_input = rsvp_input,
220 .pr_ctloutput = rip_ctloutput,
221 .pr_usrreqs = &rip_usrreqs
225 .pr_domain = &inetdomain,
226 .pr_protocol = IPPROTO_IPV4,
227 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
228 .pr_input = encap4_input,
229 .pr_ctloutput = rip_ctloutput,
230 .pr_init = encap_init,
231 .pr_usrreqs = &rip_usrreqs
235 .pr_domain = &inetdomain,
236 .pr_protocol = IPPROTO_MOBILE,
237 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
238 .pr_input = encap4_input,
239 .pr_ctloutput = rip_ctloutput,
240 .pr_init = encap_init,
241 .pr_usrreqs = &rip_usrreqs
245 .pr_domain = &inetdomain,
246 .pr_protocol = IPPROTO_ETHERIP,
247 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
248 .pr_input = encap4_input,
249 .pr_ctloutput = rip_ctloutput,
250 .pr_init = encap_init,
251 .pr_usrreqs = &rip_usrreqs
255 .pr_domain = &inetdomain,
256 .pr_protocol = IPPROTO_GRE,
257 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
258 .pr_input = encap4_input,
259 .pr_ctloutput = rip_ctloutput,
260 .pr_init = encap_init,
261 .pr_usrreqs = &rip_usrreqs
266 .pr_domain = &inetdomain,
267 .pr_protocol = IPPROTO_IPV6,
268 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
269 .pr_input = encap4_input,
270 .pr_ctloutput = rip_ctloutput,
271 .pr_init = encap_init,
272 .pr_usrreqs = &rip_usrreqs
277 .pr_domain = &inetdomain,
278 .pr_protocol = IPPROTO_PIM,
279 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
280 .pr_input = encap4_input,
281 .pr_ctloutput = rip_ctloutput,
282 .pr_usrreqs = &rip_usrreqs
284 /* Spacer n-times for loadable protocols. */
296 .pr_domain = &inetdomain,
297 .pr_flags = PR_ATOMIC|PR_ADDR,
298 .pr_input = rip_input,
299 .pr_ctloutput = rip_ctloutput,
301 .pr_usrreqs = &rip_usrreqs
305 extern int in_inithead(void **, int);
306 extern int in_detachhead(void **, int);
308 struct domain inetdomain = {
309 .dom_family = AF_INET,
310 .dom_name = "internet",
311 .dom_protosw = inetsw,
312 .dom_protoswNPROTOSW = &inetsw[nitems(inetsw)],
314 .dom_rtattach = rn4_mpath_inithead,
316 .dom_rtattach = in_inithead,
319 .dom_rtdetach = in_detachhead,
321 .dom_ifattach = in_domifattach,
322 .dom_ifdetach = in_domifdetach
325 VNET_DOMAIN_SET(inet);
328 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
331 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
332 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
333 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
334 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
336 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
338 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
339 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
340 /* XXX no protocol # to use, pick something "reserved" */
341 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
342 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
343 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
344 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
345 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
347 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
348 SYSCTL_NODE(_net_inet, OID_AUTO, accf, CTLFLAG_RW, 0,