2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
29 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
36 #include "opt_mrouting.h"
37 #include "opt_ipsec.h"
38 #include "opt_inet6.h"
42 #include "opt_mpath.h"
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/socket.h>
48 #include <sys/domain.h>
50 #include <sys/protosw.h>
51 #include <sys/queue.h>
52 #include <sys/sysctl.h>
55 #include <net/route.h>
57 #include <net/radix_mpath.h>
61 #include <netinet/in.h>
62 #include <netinet/in_systm.h>
63 #include <netinet/in_var.h>
64 #include <netinet/ip.h>
65 #include <netinet/ip_var.h>
66 #include <netinet/ip_icmp.h>
67 #include <netinet/igmp_var.h>
68 #include <netinet/tcp.h>
69 #include <netinet/tcp_timer.h>
70 #include <netinet/tcp_var.h>
71 #include <netinet/udp.h>
72 #include <netinet/udp_var.h>
73 #include <netinet/ip_encap.h>
76 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
79 static struct pr_usrreqs nousrreqs;
82 #include <netipsec/ipsec.h>
86 #include <netinet/in_pcb.h>
87 #include <netinet/sctp_pcb.h>
88 #include <netinet/sctp.h>
89 #include <netinet/sctp_var.h>
93 #include <net/pfvar.h>
94 #include <net/if_pfsync.h>
98 #include <netinet/ip_carp.h>
101 extern struct domain inetdomain;
103 /* Spacer for loadable protocols. */
104 #define IPPROTOSPACER \
106 .pr_domain = &inetdomain, \
107 .pr_protocol = PROTO_SPACER, \
108 .pr_usrreqs = &nousrreqs \
111 struct protosw inetsw[] = {
114 .pr_domain = &inetdomain,
115 .pr_protocol = IPPROTO_IP,
117 .pr_slowtimo = ip_slowtimo,
118 .pr_drain = ip_drain,
119 .pr_usrreqs = &nousrreqs
122 .pr_type = SOCK_DGRAM,
123 .pr_domain = &inetdomain,
124 .pr_protocol = IPPROTO_UDP,
125 .pr_flags = PR_ATOMIC|PR_ADDR,
126 .pr_input = udp_input,
127 .pr_ctlinput = udp_ctlinput,
128 .pr_ctloutput = udp_ctloutput,
131 .pr_destroy = udp_destroy,
133 .pr_usrreqs = &udp_usrreqs
136 .pr_type = SOCK_STREAM,
137 .pr_domain = &inetdomain,
138 .pr_protocol = IPPROTO_TCP,
139 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
140 .pr_input = tcp_input,
141 .pr_ctlinput = tcp_ctlinput,
142 .pr_ctloutput = tcp_ctloutput,
145 .pr_destroy = tcp_destroy,
147 .pr_slowtimo = tcp_slowtimo,
148 .pr_drain = tcp_drain,
149 .pr_usrreqs = &tcp_usrreqs
153 .pr_type = SOCK_DGRAM,
154 .pr_domain = &inetdomain,
155 .pr_protocol = IPPROTO_SCTP,
156 .pr_flags = PR_WANTRCVD,
157 .pr_input = sctp_input,
158 .pr_ctlinput = sctp_ctlinput,
159 .pr_ctloutput = sctp_ctloutput,
160 .pr_init = sctp_init,
161 .pr_drain = sctp_drain,
162 .pr_usrreqs = &sctp_usrreqs
165 .pr_type = SOCK_SEQPACKET,
166 .pr_domain = &inetdomain,
167 .pr_protocol = IPPROTO_SCTP,
168 .pr_flags = PR_WANTRCVD,
169 .pr_input = sctp_input,
170 .pr_ctlinput = sctp_ctlinput,
171 .pr_ctloutput = sctp_ctloutput,
172 .pr_drain = sctp_drain,
173 .pr_usrreqs = &sctp_usrreqs
177 .pr_type = SOCK_STREAM,
178 .pr_domain = &inetdomain,
179 .pr_protocol = IPPROTO_SCTP,
180 .pr_flags = PR_WANTRCVD,
181 .pr_input = sctp_input,
182 .pr_ctlinput = sctp_ctlinput,
183 .pr_ctloutput = sctp_ctloutput,
184 .pr_drain = sctp_drain,
185 .pr_usrreqs = &sctp_usrreqs
190 .pr_domain = &inetdomain,
191 .pr_protocol = IPPROTO_RAW,
192 .pr_flags = PR_ATOMIC|PR_ADDR,
193 .pr_input = rip_input,
194 .pr_ctlinput = rip_ctlinput,
195 .pr_ctloutput = rip_ctloutput,
196 .pr_usrreqs = &rip_usrreqs
200 .pr_domain = &inetdomain,
201 .pr_protocol = IPPROTO_ICMP,
202 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
203 .pr_input = icmp_input,
204 .pr_ctloutput = rip_ctloutput,
205 .pr_init = icmp_init,
206 .pr_usrreqs = &rip_usrreqs
210 .pr_domain = &inetdomain,
211 .pr_protocol = IPPROTO_IGMP,
212 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
213 .pr_input = igmp_input,
214 .pr_ctloutput = rip_ctloutput,
215 .pr_fasttimo = igmp_fasttimo,
216 .pr_slowtimo = igmp_slowtimo,
217 .pr_usrreqs = &rip_usrreqs
221 .pr_domain = &inetdomain,
222 .pr_protocol = IPPROTO_RSVP,
223 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
224 .pr_input = rsvp_input,
225 .pr_ctloutput = rip_ctloutput,
226 .pr_usrreqs = &rip_usrreqs
231 .pr_domain = &inetdomain,
232 .pr_protocol = IPPROTO_AH,
233 .pr_flags = PR_ATOMIC|PR_ADDR,
234 .pr_input = ah4_input,
235 .pr_ctlinput = ah4_ctlinput,
236 .pr_usrreqs = &nousrreqs
240 .pr_domain = &inetdomain,
241 .pr_protocol = IPPROTO_ESP,
242 .pr_flags = PR_ATOMIC|PR_ADDR,
243 .pr_input = esp4_input,
244 .pr_ctlinput = esp4_ctlinput,
245 .pr_usrreqs = &nousrreqs
249 .pr_domain = &inetdomain,
250 .pr_protocol = IPPROTO_IPCOMP,
251 .pr_flags = PR_ATOMIC|PR_ADDR,
252 .pr_input = ipcomp4_input,
253 .pr_usrreqs = &nousrreqs
258 .pr_domain = &inetdomain,
259 .pr_protocol = IPPROTO_IPV4,
260 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
261 .pr_input = encap4_input,
262 .pr_ctloutput = rip_ctloutput,
263 .pr_init = encap_init,
264 .pr_usrreqs = &rip_usrreqs
268 .pr_domain = &inetdomain,
269 .pr_protocol = IPPROTO_MOBILE,
270 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
271 .pr_input = encap4_input,
272 .pr_ctloutput = rip_ctloutput,
273 .pr_init = encap_init,
274 .pr_usrreqs = &rip_usrreqs
278 .pr_domain = &inetdomain,
279 .pr_protocol = IPPROTO_ETHERIP,
280 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
281 .pr_input = encap4_input,
282 .pr_ctloutput = rip_ctloutput,
283 .pr_init = encap_init,
284 .pr_usrreqs = &rip_usrreqs
288 .pr_domain = &inetdomain,
289 .pr_protocol = IPPROTO_GRE,
290 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
291 .pr_input = encap4_input,
292 .pr_ctloutput = rip_ctloutput,
293 .pr_init = encap_init,
294 .pr_usrreqs = &rip_usrreqs
299 .pr_domain = &inetdomain,
300 .pr_protocol = IPPROTO_IPV6,
301 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
302 .pr_input = encap4_input,
303 .pr_ctloutput = rip_ctloutput,
304 .pr_init = encap_init,
305 .pr_usrreqs = &rip_usrreqs
310 .pr_domain = &inetdomain,
311 .pr_protocol = IPPROTO_PIM,
312 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
313 .pr_input = encap4_input,
314 .pr_ctloutput = rip_ctloutput,
315 .pr_usrreqs = &rip_usrreqs
320 .pr_domain = &inetdomain,
321 .pr_protocol = IPPROTO_PFSYNC,
322 .pr_flags = PR_ATOMIC|PR_ADDR,
323 .pr_input = pfsync_input,
324 .pr_ctloutput = rip_ctloutput,
325 .pr_usrreqs = &rip_usrreqs
327 #endif /* DEV_PFSYNC */
331 .pr_domain = &inetdomain,
332 .pr_protocol = IPPROTO_CARP,
333 .pr_flags = PR_ATOMIC|PR_ADDR,
334 .pr_input = carp_input,
335 .pr_output = (pr_output_t*)rip_output,
336 .pr_ctloutput = rip_ctloutput,
337 .pr_usrreqs = &rip_usrreqs
339 #endif /* DEV_CARP */
340 /* Spacer n-times for loadable protocols. */
352 .pr_domain = &inetdomain,
353 .pr_flags = PR_ATOMIC|PR_ADDR,
354 .pr_input = rip_input,
355 .pr_ctloutput = rip_ctloutput,
358 .pr_destroy = rip_destroy,
360 .pr_usrreqs = &rip_usrreqs
364 extern int in_inithead(void **, int);
365 extern int in_detachhead(void **, int);
367 struct domain inetdomain = {
368 .dom_family = AF_INET,
369 .dom_name = "internet",
370 .dom_protosw = inetsw,
371 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
373 .dom_rtattach = rn4_mpath_inithead,
375 .dom_rtattach = in_inithead,
378 .dom_rtdetach = in_detachhead,
381 .dom_maxrtkey = sizeof(struct sockaddr_in),
382 .dom_ifattach = in_domifattach,
383 .dom_ifdetach = in_domifdetach
386 VNET_DOMAIN_SET(inet);
388 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
391 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
392 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
393 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
394 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
396 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
398 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
400 /* XXX no protocol # to use, pick something "reserved" */
401 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
402 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
403 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
404 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
405 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
407 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
409 SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC");
412 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");