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