xref: /freebsd/sys/netinet/in_proto.c (revision 08aba0aec7b7f676ccc3f7886f59f277d668d5b4)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1986, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
18  *
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
29  * SUCH DAMAGE.
30  *
31  *	@(#)in_proto.c	8.2 (Berkeley) 2/9/95
32  */
33 
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
36 
37 #include "opt_mrouting.h"
38 #include "opt_ipsec.h"
39 #include "opt_inet.h"
40 #include "opt_inet6.h"
41 #include "opt_sctp.h"
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/malloc.h>
47 #include <sys/socket.h>
48 #include <sys/domain.h>
49 #include <sys/proc.h>
50 #include <sys/protosw.h>
51 #include <sys/queue.h>
52 #include <sys/sysctl.h>
53 
54 /*
55  * While this file provides the domain and protocol switch tables for IPv4, it
56  * also provides the sysctl node declarations for net.inet.* often shared with
57  * IPv6 for common features or by upper layer protocols.  In case of no IPv4
58  * support compile out everything but these sysctl nodes.
59  */
60 #ifdef INET
61 #include <net/if.h>
62 #include <net/if_var.h>
63 #include <net/route.h>
64 #include <net/vnet.h>
65 #endif /* INET */
66 
67 #if defined(INET) || defined(INET6)
68 #include <netinet/in.h>
69 #endif
70 
71 #ifdef INET
72 #include <netinet/in_systm.h>
73 #include <netinet/in_var.h>
74 #include <netinet/ip.h>
75 #include <netinet/ip_var.h>
76 #include <netinet/ip_icmp.h>
77 #include <netinet/igmp_var.h>
78 #include <netinet/tcp.h>
79 #include <netinet/tcp_timer.h>
80 #include <netinet/tcp_var.h>
81 #include <netinet/udp.h>
82 #include <netinet/udp_var.h>
83 #include <netinet/ip_encap.h>
84 
85 /*
86  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
87  */
88 
89 #ifdef SCTP
90 #include <netinet/in_pcb.h>
91 #include <netinet/sctp_pcb.h>
92 #include <netinet/sctp.h>
93 #include <netinet/sctp_var.h>
94 #endif
95 
96 /* netinet/raw_ip.c */
97 extern struct protosw rip_protosw, rsvp_protosw, rawipv4_protosw,
98     rawipv6_protosw, mobile_protosw, etherip_protosw, icmp_protosw,
99     igmp_protosw, gre_protosw, pim_protosw, ripwild_protosw;
100 /* netinet/udp_usrreq.c */
101 extern struct protosw udp_protosw, udplite_protosw;
102 
103 FEATURE(inet, "Internet Protocol version 4");
104 
105 struct domain inetdomain = {
106 	.dom_family =		AF_INET,
107 	.dom_name =		"internet",
108 	.dom_rtattach =		in_inithead,
109 #ifdef VIMAGE
110 	.dom_rtdetach =		in_detachhead,
111 #endif
112 	.dom_ifattach =		in_domifattach,
113 	.dom_ifdetach =		in_domifdetach,
114 	.dom_nprotosw =		24,
115 	.dom_protosw = {
116 		&tcp_protosw,
117 		&udp_protosw,
118 #ifdef SCTP
119 		&sctp_seqpacket_protosw,
120 		&sctp_stream_protosw,
121 #else
122 		NULL, NULL,
123 #endif
124 		&udplite_protosw,
125 		&rip_protosw,
126 		/*
127 		 * XXXGL: it is entirely possible that all below raw-based
128 		 * protosw definitions are not needed.  They could have existed
129 		 * just to define pr_input, pr_drain, pr_*timo or PR_LASTHDR
130 		 * flag, and were never supposed to create a special socket.
131 		 */
132 		&icmp_protosw,
133 		&igmp_protosw,
134 		&rsvp_protosw,
135 		&rawipv4_protosw,
136 		&mobile_protosw,
137 		&etherip_protosw,
138 		&gre_protosw,
139 #ifdef INET6
140 		&rawipv6_protosw,
141 #else
142 		NULL,
143 #endif
144 		&pim_protosw,
145 		/* Spacer 8 times for loadable protocols. XXXGL: why 8? */
146 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
147 		&ripwild_protosw,
148 	},
149 };
150 
151 DOMAIN_SET(inet);
152 #endif /* INET */
153 
154 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
155     "Internet Family");
156 
157 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
158     "IP");
159 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
160     "ICMP");
161 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
162     "UDP");
163 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
164     "TCP");
165 #if defined(SCTP) || defined(SCTP_SUPPORT)
166 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
167     "SCTP");
168 #endif
169 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
170     "IGMP");
171 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
172 /* XXX no protocol # to use, pick something "reserved" */
173 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
174     "IPSEC");
175 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
176     "AH");
177 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
178     "ESP");
179 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
180     "IPCOMP");
181 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
182     "IPIP");
183 #endif /* IPSEC */
184 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
185     "RAW");
186 SYSCTL_NODE(_net_inet, OID_AUTO, accf, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
187     "Accept filters");
188