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 * 4. 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
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
36 #include "opt_mrouting.h"
37 #include "opt_ipsec.h"
39 #include "opt_inet6.h"
41 #include "opt_mpath.h"
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/socket.h>
47 #include <sys/domain.h>
49 #include <sys/protosw.h>
50 #include <sys/queue.h>
51 #include <sys/sysctl.h>
54 * While this file provides the domain and protocol switch tables for IPv4, it
55 * also provides the sysctl node declarations for net.inet.* often shared with
56 * IPv6 for common features or by upper layer protocols. In case of no IPv4
57 * support compile out everything but these sysctl nodes.
61 #include <net/route.h>
63 #include <net/radix_mpath.h>
68 #if defined(INET) || defined(INET6)
69 #include <netinet/in.h>
73 #include <netinet/in_systm.h>
74 #include <netinet/in_var.h>
75 #include <netinet/ip.h>
76 #include <netinet/ip_var.h>
77 #include <netinet/ip_icmp.h>
78 #include <netinet/igmp_var.h>
79 #include <netinet/tcp.h>
80 #include <netinet/tcp_timer.h>
81 #include <netinet/tcp_var.h>
82 #include <netinet/udp.h>
83 #include <netinet/udp_var.h>
84 #include <netinet/ip_encap.h>
87 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
90 static struct pr_usrreqs nousrreqs;
93 #include <netipsec/ipsec.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 FEATURE(inet, "Internet Protocol version 4");
105 extern struct domain inetdomain;
107 /* Spacer for loadable protocols. */
108 #define IPPROTOSPACER \
110 .pr_domain = &inetdomain, \
111 .pr_protocol = PROTO_SPACER, \
112 .pr_usrreqs = &nousrreqs \
115 struct protosw inetsw[] = {
118 .pr_domain = &inetdomain,
119 .pr_protocol = IPPROTO_IP,
122 .pr_destroy = ip_destroy,
124 .pr_slowtimo = ip_slowtimo,
125 .pr_drain = ip_drain,
126 .pr_usrreqs = &nousrreqs
129 .pr_type = SOCK_DGRAM,
130 .pr_domain = &inetdomain,
131 .pr_protocol = IPPROTO_UDP,
132 .pr_flags = PR_ATOMIC|PR_ADDR,
133 .pr_input = udp_input,
134 .pr_ctlinput = udp_ctlinput,
135 .pr_ctloutput = udp_ctloutput,
138 .pr_destroy = udp_destroy,
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_IMPLOPCL|PR_WANTRCVD,
147 .pr_input = tcp_input,
148 .pr_ctlinput = tcp_ctlinput,
149 .pr_ctloutput = tcp_ctloutput,
152 .pr_destroy = tcp_destroy,
154 .pr_slowtimo = tcp_slowtimo,
155 .pr_drain = tcp_drain,
156 .pr_usrreqs = &tcp_usrreqs
160 .pr_type = SOCK_SEQPACKET,
161 .pr_domain = &inetdomain,
162 .pr_protocol = IPPROTO_SCTP,
163 .pr_flags = PR_WANTRCVD,
164 .pr_input = sctp_input,
165 .pr_ctlinput = sctp_ctlinput,
166 .pr_ctloutput = sctp_ctloutput,
167 .pr_init = sctp_init,
169 .pr_destroy = sctp_finish,
171 .pr_drain = sctp_drain,
172 .pr_usrreqs = &sctp_usrreqs
175 .pr_type = SOCK_STREAM,
176 .pr_domain = &inetdomain,
177 .pr_protocol = IPPROTO_SCTP,
178 .pr_flags = PR_WANTRCVD,
179 .pr_input = sctp_input,
180 .pr_ctlinput = sctp_ctlinput,
181 .pr_ctloutput = sctp_ctloutput,
182 .pr_drain = sctp_drain,
183 .pr_usrreqs = &sctp_usrreqs
187 .pr_type = SOCK_DGRAM,
188 .pr_domain = &inetdomain,
189 .pr_protocol = IPPROTO_UDPLITE,
190 .pr_flags = PR_ATOMIC|PR_ADDR,
191 .pr_input = udp_input,
192 .pr_ctlinput = udplite_ctlinput,
193 .pr_ctloutput = udp_ctloutput,
194 .pr_init = udplite_init,
196 .pr_destroy = udplite_destroy,
198 .pr_usrreqs = &udp_usrreqs
202 .pr_domain = &inetdomain,
203 .pr_protocol = IPPROTO_RAW,
204 .pr_flags = PR_ATOMIC|PR_ADDR,
205 .pr_input = rip_input,
206 .pr_ctlinput = rip_ctlinput,
207 .pr_ctloutput = rip_ctloutput,
208 .pr_usrreqs = &rip_usrreqs
212 .pr_domain = &inetdomain,
213 .pr_protocol = IPPROTO_ICMP,
214 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
215 .pr_input = icmp_input,
216 .pr_ctloutput = rip_ctloutput,
217 .pr_usrreqs = &rip_usrreqs
221 .pr_domain = &inetdomain,
222 .pr_protocol = IPPROTO_IGMP,
223 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
224 .pr_input = igmp_input,
225 .pr_ctloutput = rip_ctloutput,
226 .pr_fasttimo = igmp_fasttimo,
227 .pr_slowtimo = igmp_slowtimo,
228 .pr_usrreqs = &rip_usrreqs
232 .pr_domain = &inetdomain,
233 .pr_protocol = IPPROTO_RSVP,
234 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
235 .pr_input = rsvp_input,
236 .pr_ctloutput = rip_ctloutput,
237 .pr_usrreqs = &rip_usrreqs
242 .pr_domain = &inetdomain,
243 .pr_protocol = IPPROTO_AH,
244 .pr_flags = PR_ATOMIC|PR_ADDR,
245 .pr_input = ah4_input,
246 .pr_ctlinput = ah4_ctlinput,
247 .pr_usrreqs = &nousrreqs
251 .pr_domain = &inetdomain,
252 .pr_protocol = IPPROTO_ESP,
253 .pr_flags = PR_ATOMIC|PR_ADDR,
254 .pr_input = esp4_input,
255 .pr_ctlinput = esp4_ctlinput,
256 .pr_usrreqs = &nousrreqs
260 .pr_domain = &inetdomain,
261 .pr_protocol = IPPROTO_IPCOMP,
262 .pr_flags = PR_ATOMIC|PR_ADDR,
263 .pr_input = ipcomp4_input,
264 .pr_usrreqs = &nousrreqs
269 .pr_domain = &inetdomain,
270 .pr_protocol = IPPROTO_IPV4,
271 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
272 .pr_input = encap4_input,
273 .pr_ctloutput = rip_ctloutput,
274 .pr_init = encap_init,
275 .pr_usrreqs = &rip_usrreqs
279 .pr_domain = &inetdomain,
280 .pr_protocol = IPPROTO_MOBILE,
281 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
282 .pr_input = encap4_input,
283 .pr_ctloutput = rip_ctloutput,
284 .pr_init = encap_init,
285 .pr_usrreqs = &rip_usrreqs
289 .pr_domain = &inetdomain,
290 .pr_protocol = IPPROTO_ETHERIP,
291 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
292 .pr_input = encap4_input,
293 .pr_ctloutput = rip_ctloutput,
294 .pr_init = encap_init,
295 .pr_usrreqs = &rip_usrreqs
299 .pr_domain = &inetdomain,
300 .pr_protocol = IPPROTO_GRE,
301 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
302 .pr_input = encap4_input,
303 .pr_ctloutput = rip_ctloutput,
304 .pr_init = encap_init,
305 .pr_usrreqs = &rip_usrreqs
310 .pr_domain = &inetdomain,
311 .pr_protocol = IPPROTO_IPV6,
312 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
313 .pr_input = encap4_input,
314 .pr_ctloutput = rip_ctloutput,
315 .pr_init = encap_init,
316 .pr_usrreqs = &rip_usrreqs
321 .pr_domain = &inetdomain,
322 .pr_protocol = IPPROTO_PIM,
323 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
324 .pr_input = encap4_input,
325 .pr_ctloutput = rip_ctloutput,
326 .pr_usrreqs = &rip_usrreqs
328 /* Spacer n-times for loadable protocols. */
340 .pr_domain = &inetdomain,
341 .pr_flags = PR_ATOMIC|PR_ADDR,
342 .pr_input = rip_input,
343 .pr_ctloutput = rip_ctloutput,
346 .pr_destroy = rip_destroy,
348 .pr_usrreqs = &rip_usrreqs
352 extern int in_inithead(void **, int);
353 extern int in_detachhead(void **, int);
355 struct domain inetdomain = {
356 .dom_family = AF_INET,
357 .dom_name = "internet",
358 .dom_protosw = inetsw,
359 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
361 .dom_rtattach = rn4_mpath_inithead,
363 .dom_rtattach = in_inithead,
366 .dom_rtdetach = in_detachhead,
369 .dom_maxrtkey = sizeof(struct sockaddr_in),
370 .dom_ifattach = in_domifattach,
371 .dom_ifdetach = in_domifdetach
374 VNET_DOMAIN_SET(inet);
377 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
380 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
381 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
382 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
383 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
385 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
387 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
389 /* XXX no protocol # to use, pick something "reserved" */
390 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
391 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
392 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
393 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
394 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
396 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");