]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/netinet/in_proto.c
OpenSSL: Merge OpenSSL 1.1.1p
[FreeBSD/FreeBSD.git] / sys / netinet / in_proto.c
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 static struct pr_usrreqs nousrreqs;
90
91 #ifdef SCTP
92 #include <netinet/in_pcb.h>
93 #include <netinet/sctp_pcb.h>
94 #include <netinet/sctp.h>
95 #include <netinet/sctp_var.h>
96 #endif
97
98 FEATURE(inet, "Internet Protocol version 4");
99
100 extern  struct domain inetdomain;
101
102 /* Spacer for loadable protocols. */
103 #define IPPROTOSPACER                           \
104 {                                               \
105         .pr_domain =            &inetdomain,    \
106         .pr_protocol =          PROTO_SPACER,   \
107         .pr_usrreqs =           &nousrreqs      \
108 }
109
110 struct protosw inetsw[] = {
111 {
112         .pr_type =              0,
113         .pr_domain =            &inetdomain,
114         .pr_protocol =          IPPROTO_IP,
115         .pr_flags =             PR_CAPATTACH,
116         .pr_slowtimo =          ip_slowtimo,
117         .pr_drain =             ip_drain,
118         .pr_usrreqs =           &nousrreqs
119 },
120 {
121         .pr_type =              SOCK_DGRAM,
122         .pr_domain =            &inetdomain,
123         .pr_protocol =          IPPROTO_UDP,
124         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_CAPATTACH,
125         .pr_input =             udp_input,
126         .pr_ctlinput =          udp_ctlinput,
127         .pr_ctloutput =         udp_ctloutput,
128         .pr_usrreqs =           &udp_usrreqs
129 },
130 {
131         .pr_type =              SOCK_STREAM,
132         .pr_domain =            &inetdomain,
133         .pr_protocol =          IPPROTO_TCP,
134         .pr_flags =             PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD|
135                                     PR_CAPATTACH,
136         .pr_input =             tcp_input,
137         .pr_ctlinput =          tcp_ctlinput,
138         .pr_ctloutput =         tcp_ctloutput,
139         .pr_slowtimo =          tcp_slowtimo,
140         .pr_drain =             tcp_drain,
141         .pr_usrreqs =           &tcp_usrreqs
142 },
143 #ifdef SCTP
144 {
145         .pr_type =              SOCK_SEQPACKET,
146         .pr_domain =            &inetdomain,
147         .pr_protocol =          IPPROTO_SCTP,
148         .pr_flags =             PR_WANTRCVD|PR_LASTHDR,
149         .pr_input =             sctp_input,
150         .pr_ctlinput =          sctp_ctlinput,
151         .pr_ctloutput =         sctp_ctloutput,
152         .pr_drain =             sctp_drain,
153         .pr_usrreqs =           &sctp_usrreqs
154 },
155 {
156         .pr_type =              SOCK_STREAM,
157         .pr_domain =            &inetdomain,
158         .pr_protocol =          IPPROTO_SCTP,
159         .pr_flags =             PR_CONNREQUIRED|PR_WANTRCVD|PR_LASTHDR,
160         .pr_input =             sctp_input,
161         .pr_ctlinput =          sctp_ctlinput,
162         .pr_ctloutput =         sctp_ctloutput,
163         .pr_drain =             NULL, /* Covered by the SOCK_SEQPACKET entry. */
164         .pr_usrreqs =           &sctp_usrreqs
165 },
166 #endif /* SCTP */
167 {
168         .pr_type =              SOCK_DGRAM,
169         .pr_domain =            &inetdomain,
170         .pr_protocol =          IPPROTO_UDPLITE,
171         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_CAPATTACH,
172         .pr_input =             udp_input,
173         .pr_ctlinput =          udplite_ctlinput,
174         .pr_ctloutput =         udp_ctloutput,
175         .pr_usrreqs =           &udp_usrreqs
176 },
177 {
178         .pr_type =              SOCK_RAW,
179         .pr_domain =            &inetdomain,
180         .pr_protocol =          IPPROTO_RAW,
181         .pr_flags =             PR_ATOMIC|PR_ADDR,
182         .pr_input =             rip_input,
183         .pr_ctlinput =          rip_ctlinput,
184         .pr_ctloutput =         rip_ctloutput,
185         .pr_usrreqs =           &rip_usrreqs
186 },
187 {
188         .pr_type =              SOCK_RAW,
189         .pr_domain =            &inetdomain,
190         .pr_protocol =          IPPROTO_ICMP,
191         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_LASTHDR,
192         .pr_input =             icmp_input,
193         .pr_ctloutput =         rip_ctloutput,
194         .pr_usrreqs =           &rip_usrreqs
195 },
196 {
197         .pr_type =              SOCK_RAW,
198         .pr_domain =            &inetdomain,
199         .pr_protocol =          IPPROTO_IGMP,
200         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_LASTHDR,
201         .pr_input =             igmp_input,
202         .pr_ctloutput =         rip_ctloutput,
203         .pr_fasttimo =          igmp_fasttimo,
204         .pr_slowtimo =          igmp_slowtimo,
205         .pr_usrreqs =           &rip_usrreqs
206 },
207 {
208         .pr_type =              SOCK_RAW,
209         .pr_domain =            &inetdomain,
210         .pr_protocol =          IPPROTO_RSVP,
211         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_LASTHDR,
212         .pr_input =             rsvp_input,
213         .pr_ctloutput =         rip_ctloutput,
214         .pr_usrreqs =           &rip_usrreqs
215 },
216 {
217         .pr_type =              SOCK_RAW,
218         .pr_domain =            &inetdomain,
219         .pr_protocol =          IPPROTO_IPV4,
220         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_LASTHDR,
221         .pr_input =             encap4_input,
222         .pr_ctloutput =         rip_ctloutput,
223         .pr_usrreqs =           &rip_usrreqs
224 },
225 {
226         .pr_type =              SOCK_RAW,
227         .pr_domain =            &inetdomain,
228         .pr_protocol =          IPPROTO_MOBILE,
229         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_LASTHDR,
230         .pr_input =             encap4_input,
231         .pr_ctloutput =         rip_ctloutput,
232         .pr_usrreqs =           &rip_usrreqs
233 },
234 {
235         .pr_type =              SOCK_RAW,
236         .pr_domain =            &inetdomain,
237         .pr_protocol =          IPPROTO_ETHERIP,
238         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_LASTHDR,
239         .pr_input =             encap4_input,
240         .pr_ctloutput =         rip_ctloutput,
241         .pr_usrreqs =           &rip_usrreqs
242 },
243 {
244         .pr_type =              SOCK_RAW,
245         .pr_domain =            &inetdomain,
246         .pr_protocol =          IPPROTO_GRE,
247         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_LASTHDR,
248         .pr_input =             encap4_input,
249         .pr_ctloutput =         rip_ctloutput,
250         .pr_usrreqs =           &rip_usrreqs
251 },
252 # ifdef INET6
253 {
254         .pr_type =              SOCK_RAW,
255         .pr_domain =            &inetdomain,
256         .pr_protocol =          IPPROTO_IPV6,
257         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_LASTHDR,
258         .pr_input =             encap4_input,
259         .pr_ctloutput =         rip_ctloutput,
260         .pr_usrreqs =           &rip_usrreqs
261 },
262 #endif
263 {
264         .pr_type =              SOCK_RAW,
265         .pr_domain =            &inetdomain,
266         .pr_protocol =          IPPROTO_PIM,
267         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_LASTHDR,
268         .pr_input =             encap4_input,
269         .pr_ctloutput =         rip_ctloutput,
270         .pr_usrreqs =           &rip_usrreqs
271 },
272 /* Spacer n-times for loadable protocols. */
273 IPPROTOSPACER,
274 IPPROTOSPACER,
275 IPPROTOSPACER,
276 IPPROTOSPACER,
277 IPPROTOSPACER,
278 IPPROTOSPACER,
279 IPPROTOSPACER,
280 IPPROTOSPACER,
281 /* raw wildcard */
282 {
283         .pr_type =              SOCK_RAW,
284         .pr_domain =            &inetdomain,
285         .pr_flags =             PR_ATOMIC|PR_ADDR,
286         .pr_input =             rip_input,
287         .pr_ctloutput =         rip_ctloutput,
288         .pr_usrreqs =           &rip_usrreqs
289 },
290 };
291
292 struct domain inetdomain = {
293         .dom_family =           AF_INET,
294         .dom_name =             "internet",
295         .dom_protosw =          inetsw,
296         .dom_protoswNPROTOSW =  &inetsw[nitems(inetsw)],
297         .dom_rtattach =         in_inithead,
298 #ifdef VIMAGE
299         .dom_rtdetach =         in_detachhead,
300 #endif
301         .dom_ifattach =         in_domifattach,
302         .dom_ifdetach =         in_domifdetach
303 };
304
305 DOMAIN_SET(inet);
306 #endif /* INET */
307
308 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
309     "Internet Family");
310
311 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
312     "IP");
313 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
314     "ICMP");
315 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
316     "UDP");
317 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
318     "TCP");
319 #if defined(SCTP) || defined(SCTP_SUPPORT)
320 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
321     "SCTP");
322 #endif
323 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
324     "IGMP");
325 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
326 /* XXX no protocol # to use, pick something "reserved" */
327 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
328     "IPSEC");
329 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
330     "AH");
331 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
332     "ESP");
333 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
334     "IPCOMP");
335 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
336     "IPIP");
337 #endif /* IPSEC */
338 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
339     "RAW");
340 SYSCTL_NODE(_net_inet, OID_AUTO, accf, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
341     "Accept filters");