xref: /freebsd/sys/netinet/in_proto.c (revision 63f9a4cb2684a303e3eb2ffed39c03a2e2b28ae0)
1 /*
2  * Copyright (c) 1982, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
16  *
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
27  * SUCH DAMAGE.
28  *
29  *	@(#)in_proto.c	8.2 (Berkeley) 2/9/95
30  * $FreeBSD$
31  */
32 
33 #include "opt_ipx.h"
34 #include "opt_mrouting.h"
35 #include "opt_ipsec.h"
36 #include "opt_inet6.h"
37 #include "opt_pf.h"
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/socket.h>
43 #include <sys/domain.h>
44 #include <sys/protosw.h>
45 #include <sys/queue.h>
46 #include <sys/sysctl.h>
47 
48 #include <net/if.h>
49 #include <net/route.h>
50 
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/ip.h>
54 #include <netinet/ip_var.h>
55 #include <netinet/ip_icmp.h>
56 #include <netinet/igmp_var.h>
57 #ifdef PIM
58 #include <netinet/pim_var.h>
59 #endif
60 #include <netinet/tcp.h>
61 #include <netinet/tcp_timer.h>
62 #include <netinet/tcp_var.h>
63 #include <netinet/udp.h>
64 #include <netinet/udp_var.h>
65 #include <netinet/ip_encap.h>
66 
67 /*
68  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
69  */
70 
71 #ifdef IPSEC
72 #include <netinet6/ipsec.h>
73 #include <netinet6/ah.h>
74 #ifdef IPSEC_ESP
75 #include <netinet6/esp.h>
76 #endif
77 #include <netinet6/ipcomp.h>
78 #endif /* IPSEC */
79 
80 #ifdef FAST_IPSEC
81 #include <netipsec/ipsec.h>
82 #endif /* FAST_IPSEC */
83 
84 #ifdef IPXIP
85 #include <netipx/ipx_ip.h>
86 #endif
87 
88 #ifdef DEV_PFSYNC
89 #include <net/pfvar.h>
90 #include <net/if_pfsync.h>
91 #endif
92 
93 extern	struct domain inetdomain;
94 
95 /* Spacer for loadable protocols. */
96 #define IPPROTOSPACER   \
97 { 0,		&inetdomain,	PROTO_SPACER,	0,	\
98   NULL,		NULL,		NULL,		NULL,	\
99   NULL,							\
100   NULL,		NULL,		NULL,		NULL,	\
101   &nousrreqs						\
102 }
103 
104 struct protosw inetsw[] = {
105 { 0,		&inetdomain,	0,		0,
106   0,		0,		0,		0,
107   0,
108   ip_init,	0,		ip_slowtimo,	ip_drain,
109   &nousrreqs
110 },
111 { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
112   udp_input,	0,		udp_ctlinput,	ip_ctloutput,
113   0,
114   udp_init,	0,		0,		0,
115   &udp_usrreqs
116 },
117 { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,
118 	PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
119   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
120   0,
121   tcp_init,	0,		tcp_slowtimo,	tcp_drain,
122   &tcp_usrreqs
123 },
124 { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
125   rip_input,	0,		rip_ctlinput,	rip_ctloutput,
126   0,
127   0,		0,		0,		0,
128   &rip_usrreqs
129 },
130 { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
131   icmp_input,	0,		0,		rip_ctloutput,
132   0,
133   0,		0,		0,		0,
134   &rip_usrreqs
135 },
136 { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
137   igmp_input,	0,		0,		rip_ctloutput,
138   0,
139   igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,
140   &rip_usrreqs
141 },
142 { SOCK_RAW,	&inetdomain,	IPPROTO_RSVP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
143   rsvp_input,	0,		0,		rip_ctloutput,
144   0,
145   0,		0,		0,		0,
146   &rip_usrreqs
147 },
148 #ifdef IPSEC
149 { SOCK_RAW,	&inetdomain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
150   ah4_input,	0,		0,		0,
151   0,
152   0,		0,		0,		0,
153   &nousrreqs
154 },
155 #ifdef IPSEC_ESP
156 { SOCK_RAW,	&inetdomain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
157   esp4_input,	0,		0,		0,
158   0,
159   0,		0,		0,		0,
160   &nousrreqs
161 },
162 #endif
163 { SOCK_RAW,	&inetdomain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
164   ipcomp4_input, 0,		0,		0,
165   0,
166   0,		0,		0,		0,
167   &nousrreqs
168 },
169 #endif /* IPSEC */
170 #ifdef FAST_IPSEC
171 { SOCK_RAW,	&inetdomain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
172   ah4_input,	0,		ah4_ctlinput,	0,
173   0,
174   0,		0,		0,		0,
175   &nousrreqs
176 },
177 { SOCK_RAW,	&inetdomain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
178   esp4_input,	0,		esp4_ctlinput,	0,
179   0,
180   0,		0,		0,		0,
181   &nousrreqs
182 },
183 { SOCK_RAW,	&inetdomain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
184   ipcomp4_input,	0,		0,		0,
185   0,
186   0,		0,		0,		0,
187   &nousrreqs
188 },
189 #endif /* FAST_IPSEC */
190 { SOCK_RAW,	&inetdomain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
191   encap4_input,	0,		0,		rip_ctloutput,
192   0,
193   encap_init,		0,		0,		0,
194   &rip_usrreqs
195 },
196 { SOCK_RAW,	&inetdomain,	IPPROTO_MOBILE,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
197   encap4_input,	0,		0,		rip_ctloutput,
198   0,
199   encap_init,	0,		0,		0,
200   &rip_usrreqs
201 },
202 { SOCK_RAW,	&inetdomain,	IPPROTO_GRE,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
203   encap4_input,	0,		0,		rip_ctloutput,
204   0,
205   encap_init,	0,		0,		0,
206   &rip_usrreqs
207 },
208 # ifdef INET6
209 { SOCK_RAW,	&inetdomain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
210   encap4_input,	0,		0,		rip_ctloutput,
211   0,
212   encap_init,	0,		0,		0,
213   &rip_usrreqs
214 },
215 #endif
216 #ifdef IPXIP
217 { SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
218   ipxip_input,	0,		ipxip_ctlinput,	0,
219   0,
220   0,		0,		0,		0,
221   &rip_usrreqs
222 },
223 #endif
224 #ifdef PIM
225 { SOCK_RAW,	&inetdomain,	IPPROTO_PIM,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
226   pim_input,	0,		0,		rip_ctloutput,
227   0,
228   0,		0,		0,		0,
229   &rip_usrreqs
230 },
231 #endif	/* PIM */
232 #ifdef DEV_PFSYNC
233 { SOCK_RAW,	&inetdomain,	IPPROTO_PFSYNC,	PR_ATOMIC|PR_ADDR,
234   pfsync_input,	0,		0,		rip_ctloutput,
235   0,
236   0,		0,		0,		0,
237   &rip_usrreqs
238 },
239 #endif	/* DEV_PFSYNC */
240 /* Spacer n-times for loadable protocols. */
241 IPPROTOSPACER,
242 IPPROTOSPACER,
243 IPPROTOSPACER,
244 IPPROTOSPACER,
245 IPPROTOSPACER,
246 IPPROTOSPACER,
247 IPPROTOSPACER,
248 IPPROTOSPACER,
249 /* raw wildcard */
250 { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR,
251   rip_input,	0,		0,		rip_ctloutput,
252   0,
253   rip_init,	0,		0,		0,
254   &rip_usrreqs
255 },
256 };
257 
258 extern int in_inithead(void **, int);
259 
260 struct domain inetdomain =
261     { AF_INET, "internet", 0, 0, 0,
262       inetsw,
263       &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
264       in_inithead, 32, sizeof(struct sockaddr_in)
265     };
266 
267 DOMAIN_SET(inet);
268 
269 SYSCTL_NODE(_net,      PF_INET,		inet,	CTLFLAG_RW, 0,
270 	"Internet Family");
271 
272 SYSCTL_NODE(_net_inet, IPPROTO_IP,	ip,	CTLFLAG_RW, 0,	"IP");
273 SYSCTL_NODE(_net_inet, IPPROTO_ICMP,	icmp,	CTLFLAG_RW, 0,	"ICMP");
274 SYSCTL_NODE(_net_inet, IPPROTO_UDP,	udp,	CTLFLAG_RW, 0,	"UDP");
275 SYSCTL_NODE(_net_inet, IPPROTO_TCP,	tcp,	CTLFLAG_RW, 0,	"TCP");
276 SYSCTL_NODE(_net_inet, IPPROTO_IGMP,	igmp,	CTLFLAG_RW, 0,	"IGMP");
277 #ifdef FAST_IPSEC
278 /* XXX no protocol # to use, pick something "reserved" */
279 SYSCTL_NODE(_net_inet, 253,		ipsec,	CTLFLAG_RW, 0,	"IPSEC");
280 SYSCTL_NODE(_net_inet, IPPROTO_AH,	ah,	CTLFLAG_RW, 0,	"AH");
281 SYSCTL_NODE(_net_inet, IPPROTO_ESP,	esp,	CTLFLAG_RW, 0,	"ESP");
282 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP,	ipcomp,	CTLFLAG_RW, 0,	"IPCOMP");
283 SYSCTL_NODE(_net_inet, IPPROTO_IPIP,	ipip,	CTLFLAG_RW, 0,	"IPIP");
284 #else
285 #ifdef IPSEC
286 SYSCTL_NODE(_net_inet, IPPROTO_AH,	ipsec,	CTLFLAG_RW, 0,	"IPSEC");
287 #endif /* IPSEC */
288 #endif /* !FAST_IPSEC */
289 SYSCTL_NODE(_net_inet, IPPROTO_RAW,	raw,	CTLFLAG_RW, 0,	"RAW");
290 #ifdef PIM
291 SYSCTL_NODE(_net_inet, IPPROTO_PIM,    pim,    CTLFLAG_RW, 0,  "PIM");
292 #endif
293