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,
162 .pr_destroy = sctp_finish,
164 .pr_drain = sctp_drain,
165 .pr_usrreqs = &sctp_usrreqs
168 .pr_type = SOCK_SEQPACKET,
169 .pr_domain = &inetdomain,
170 .pr_protocol = IPPROTO_SCTP,
171 .pr_flags = PR_WANTRCVD,
172 .pr_input = sctp_input,
173 .pr_ctlinput = sctp_ctlinput,
174 .pr_ctloutput = sctp_ctloutput,
175 .pr_drain = sctp_drain,
176 .pr_usrreqs = &sctp_usrreqs
180 .pr_type = SOCK_STREAM,
181 .pr_domain = &inetdomain,
182 .pr_protocol = IPPROTO_SCTP,
183 .pr_flags = PR_WANTRCVD,
184 .pr_input = sctp_input,
185 .pr_ctlinput = sctp_ctlinput,
186 .pr_ctloutput = sctp_ctloutput,
187 .pr_drain = sctp_drain,
188 .pr_usrreqs = &sctp_usrreqs
193 .pr_domain = &inetdomain,
194 .pr_protocol = IPPROTO_RAW,
195 .pr_flags = PR_ATOMIC|PR_ADDR,
196 .pr_input = rip_input,
197 .pr_ctlinput = rip_ctlinput,
198 .pr_ctloutput = rip_ctloutput,
199 .pr_usrreqs = &rip_usrreqs
203 .pr_domain = &inetdomain,
204 .pr_protocol = IPPROTO_ICMP,
205 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
206 .pr_input = icmp_input,
207 .pr_ctloutput = rip_ctloutput,
208 .pr_init = icmp_init,
209 .pr_usrreqs = &rip_usrreqs
213 .pr_domain = &inetdomain,
214 .pr_protocol = IPPROTO_IGMP,
215 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
216 .pr_input = igmp_input,
217 .pr_ctloutput = rip_ctloutput,
218 .pr_fasttimo = igmp_fasttimo,
219 .pr_slowtimo = igmp_slowtimo,
220 .pr_usrreqs = &rip_usrreqs
224 .pr_domain = &inetdomain,
225 .pr_protocol = IPPROTO_RSVP,
226 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
227 .pr_input = rsvp_input,
228 .pr_ctloutput = rip_ctloutput,
229 .pr_usrreqs = &rip_usrreqs
234 .pr_domain = &inetdomain,
235 .pr_protocol = IPPROTO_AH,
236 .pr_flags = PR_ATOMIC|PR_ADDR,
237 .pr_input = ah4_input,
238 .pr_ctlinput = ah4_ctlinput,
239 .pr_usrreqs = &nousrreqs
243 .pr_domain = &inetdomain,
244 .pr_protocol = IPPROTO_ESP,
245 .pr_flags = PR_ATOMIC|PR_ADDR,
246 .pr_input = esp4_input,
247 .pr_ctlinput = esp4_ctlinput,
248 .pr_usrreqs = &nousrreqs
252 .pr_domain = &inetdomain,
253 .pr_protocol = IPPROTO_IPCOMP,
254 .pr_flags = PR_ATOMIC|PR_ADDR,
255 .pr_input = ipcomp4_input,
256 .pr_usrreqs = &nousrreqs
261 .pr_domain = &inetdomain,
262 .pr_protocol = IPPROTO_IPV4,
263 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
264 .pr_input = encap4_input,
265 .pr_ctloutput = rip_ctloutput,
266 .pr_init = encap_init,
267 .pr_usrreqs = &rip_usrreqs
271 .pr_domain = &inetdomain,
272 .pr_protocol = IPPROTO_MOBILE,
273 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
274 .pr_input = encap4_input,
275 .pr_ctloutput = rip_ctloutput,
276 .pr_init = encap_init,
277 .pr_usrreqs = &rip_usrreqs
281 .pr_domain = &inetdomain,
282 .pr_protocol = IPPROTO_ETHERIP,
283 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
284 .pr_input = encap4_input,
285 .pr_ctloutput = rip_ctloutput,
286 .pr_init = encap_init,
287 .pr_usrreqs = &rip_usrreqs
291 .pr_domain = &inetdomain,
292 .pr_protocol = IPPROTO_GRE,
293 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
294 .pr_input = encap4_input,
295 .pr_ctloutput = rip_ctloutput,
296 .pr_init = encap_init,
297 .pr_usrreqs = &rip_usrreqs
302 .pr_domain = &inetdomain,
303 .pr_protocol = IPPROTO_IPV6,
304 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
305 .pr_input = encap4_input,
306 .pr_ctloutput = rip_ctloutput,
307 .pr_init = encap_init,
308 .pr_usrreqs = &rip_usrreqs
313 .pr_domain = &inetdomain,
314 .pr_protocol = IPPROTO_PIM,
315 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
316 .pr_input = encap4_input,
317 .pr_ctloutput = rip_ctloutput,
318 .pr_usrreqs = &rip_usrreqs
323 .pr_domain = &inetdomain,
324 .pr_protocol = IPPROTO_PFSYNC,
325 .pr_flags = PR_ATOMIC|PR_ADDR,
326 .pr_input = pfsync_input,
327 .pr_ctloutput = rip_ctloutput,
328 .pr_usrreqs = &rip_usrreqs
330 #endif /* DEV_PFSYNC */
334 .pr_domain = &inetdomain,
335 .pr_protocol = IPPROTO_CARP,
336 .pr_flags = PR_ATOMIC|PR_ADDR,
337 .pr_input = carp_input,
338 .pr_output = (pr_output_t*)rip_output,
339 .pr_ctloutput = rip_ctloutput,
340 .pr_usrreqs = &rip_usrreqs
342 #endif /* DEV_CARP */
343 /* Spacer n-times for loadable protocols. */
355 .pr_domain = &inetdomain,
356 .pr_flags = PR_ATOMIC|PR_ADDR,
357 .pr_input = rip_input,
358 .pr_ctloutput = rip_ctloutput,
361 .pr_destroy = rip_destroy,
363 .pr_usrreqs = &rip_usrreqs
367 extern int in_inithead(void **, int);
368 extern int in_detachhead(void **, int);
370 struct domain inetdomain = {
371 .dom_family = AF_INET,
372 .dom_name = "internet",
373 .dom_protosw = inetsw,
374 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
376 .dom_rtattach = rn4_mpath_inithead,
378 .dom_rtattach = in_inithead,
381 .dom_rtdetach = in_detachhead,
384 .dom_maxrtkey = sizeof(struct sockaddr_in),
385 .dom_ifattach = in_domifattach,
386 .dom_ifdetach = in_domifdetach
389 VNET_DOMAIN_SET(inet);
391 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
394 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
395 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
396 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
397 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
399 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
401 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
403 /* XXX no protocol # to use, pick something "reserved" */
404 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
405 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
406 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
407 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
408 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
410 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
412 SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC");
415 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");