xref: /freebsd/sys/netinet/in_proto.c (revision a64729f5077d77e13b9497cb33ecb3c82e606ee8)
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 
32 #include <sys/cdefs.h>
33 #include "opt_mrouting.h"
34 #include "opt_ipsec.h"
35 #include "opt_inet.h"
36 #include "opt_inet6.h"
37 #include "opt_sctp.h"
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/malloc.h>
43 #include <sys/socket.h>
44 #include <sys/domain.h>
45 #include <sys/proc.h>
46 #include <sys/protosw.h>
47 #include <sys/queue.h>
48 #include <sys/sysctl.h>
49 
50 #include <net/if.h>
51 #include <net/if_var.h>
52 #include <netinet/in.h>
53 #include <netinet/in_var.h>
54 
55 /*
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.
60  */
61 #ifdef INET
62 /* netinet/raw_ip.c */
63 extern struct protosw rip_protosw;
64 /* netinet/udp_usrreq.c */
65 extern struct protosw udp_protosw, udplite_protosw;
66 /* netinet/tcp_usrreq.c */
67 extern struct protosw tcp_protosw;
68 /* netinet/sctp_usrreq.c */
69 extern struct protosw sctp_seqpacket_protosw, sctp_stream_protosw;
70 
71 FEATURE(inet, "Internet Protocol version 4");
72 
73 struct domain inetdomain = {
74 	.dom_family =		AF_INET,
75 	.dom_name =		"internet",
76 	.dom_rtattach =		in_inithead,
77 #ifdef VIMAGE
78 	.dom_rtdetach =		in_detachhead,
79 #endif
80 	.dom_ifattach =		in_domifattach,
81 	.dom_ifdetach =		in_domifdetach,
82 	.dom_nprotosw =		14,
83 	.dom_protosw = {
84 		&tcp_protosw,
85 		&udp_protosw,
86 #ifdef SCTP
87 		&sctp_seqpacket_protosw,
88 		&sctp_stream_protosw,
89 #else
90 		NULL, NULL,
91 #endif
92 		&udplite_protosw,
93 		&rip_protosw,
94 		/* Spacer 8 times for loadable protocols. XXXGL: why 8? */
95 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
96 	},
97 };
98 
99 DOMAIN_SET(inet);
100 #endif /* INET */
101 
102 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
103     "Internet Family");
104 
105 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
106     "IP");
107 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
108     "ICMP");
109 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
110     "UDP");
111 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
112     "TCP");
113 #if defined(SCTP) || defined(SCTP_SUPPORT)
114 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
115     "SCTP");
116 #endif
117 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
118     "IGMP");
119 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
120 /* XXX no protocol # to use, pick something "reserved" */
121 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
122     "IPSEC");
123 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
124     "AH");
125 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
126     "ESP");
127 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
128     "IPCOMP");
129 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
130     "IPIP");
131 #endif /* IPSEC */
132 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
133     "RAW");
134 SYSCTL_NODE(_net_inet, OID_AUTO, accf, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
135     "Accept filters");
136