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
34 #include "opt_mrouting.h"
35 #include "opt_ipsec.h"
36 #include "opt_inet6.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/socket.h>
45 #include <sys/domain.h>
46 #include <sys/protosw.h>
47 #include <sys/queue.h>
48 #include <sys/sysctl.h>
51 #include <net/route.h>
53 #include <netinet/in.h>
54 #include <netinet/in_systm.h>
55 #include <netinet/ip.h>
56 #include <netinet/ip_var.h>
57 #include <netinet/ip_icmp.h>
58 #include <netinet/igmp_var.h>
60 #include <netinet/pim_var.h>
62 #include <netinet/tcp.h>
63 #include <netinet/tcp_timer.h>
64 #include <netinet/tcp_var.h>
65 #include <netinet/udp.h>
66 #include <netinet/udp_var.h>
67 #include <netinet/ip_encap.h>
70 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
73 static struct pr_usrreqs nousrreqs;
76 #include <netinet6/ipsec.h>
77 #include <netinet6/ah.h>
79 #include <netinet6/esp.h>
81 #include <netinet6/ipcomp.h>
85 #include <netipsec/ipsec.h>
86 #endif /* FAST_IPSEC */
89 #include <netipx/ipx_ip.h>
93 #include <netinet/in_pcb.h>
94 #include <netinet/sctp_pcb.h>
95 #include <netinet/sctp.h>
96 #include <netinet/sctp_var.h>
100 #include <net/pfvar.h>
101 #include <net/if_pfsync.h>
105 #include <netinet/ip_carp.h>
108 extern struct domain inetdomain;
110 /* Spacer for loadable protocols. */
111 #define IPPROTOSPACER \
113 .pr_domain = &inetdomain, \
114 .pr_protocol = PROTO_SPACER, \
115 .pr_usrreqs = &nousrreqs \
118 struct protosw inetsw[] = {
121 .pr_domain = &inetdomain,
122 .pr_protocol = IPPROTO_IP,
124 .pr_slowtimo = ip_slowtimo,
125 .pr_drain = ip_drain,
126 .pr_usrreqs = &nousrreqs
129 .pr_type = SOCK_DGRAM,
130 .pr_domain = &inetdomain,
131 .pr_protocol = IPPROTO_UDP,
132 .pr_flags = PR_ATOMIC|PR_ADDR,
133 .pr_input = udp_input,
134 .pr_ctlinput = udp_ctlinput,
135 .pr_ctloutput = ip_ctloutput,
137 .pr_usrreqs = &udp_usrreqs
140 .pr_type = SOCK_STREAM,
141 .pr_domain = &inetdomain,
142 .pr_protocol = IPPROTO_TCP,
143 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
144 .pr_input = tcp_input,
145 .pr_ctlinput = tcp_ctlinput,
146 .pr_ctloutput = tcp_ctloutput,
148 .pr_slowtimo = tcp_slowtimo,
149 .pr_drain = tcp_drain,
150 .pr_usrreqs = &tcp_usrreqs
154 .pr_type = SOCK_DGRAM,
155 .pr_domain = &inetdomain,
156 .pr_protocol = IPPROTO_SCTP,
157 .pr_flags = PR_WANTRCVD,
158 .pr_input = sctp_input,
159 .pr_ctlinput = sctp_ctlinput,
160 .pr_ctloutput = sctp_ctloutput,
161 .pr_init = sctp_init,
162 .pr_drain = sctp_drain,
163 .pr_usrreqs = &sctp_usrreqs
166 .pr_type = SOCK_SEQPACKET,
167 .pr_domain = &inetdomain,
168 .pr_protocol = IPPROTO_SCTP,
169 .pr_flags = PR_WANTRCVD,
170 .pr_input = sctp_input,
171 .pr_ctlinput = sctp_ctlinput,
172 .pr_ctloutput = sctp_ctloutput,
173 .pr_drain = sctp_drain,
174 .pr_usrreqs = &sctp_usrreqs
178 .pr_type = SOCK_STREAM,
179 .pr_domain = &inetdomain,
180 .pr_protocol = IPPROTO_SCTP,
181 .pr_flags = PR_WANTRCVD,
182 .pr_input = sctp_input,
183 .pr_ctlinput = sctp_ctlinput,
184 .pr_ctloutput = sctp_ctloutput,
185 .pr_drain = sctp_drain,
186 .pr_usrreqs = &sctp_usrreqs
191 .pr_domain = &inetdomain,
192 .pr_protocol = IPPROTO_RAW,
193 .pr_flags = PR_ATOMIC|PR_ADDR,
194 .pr_input = rip_input,
195 .pr_ctlinput = rip_ctlinput,
196 .pr_ctloutput = rip_ctloutput,
197 .pr_usrreqs = &rip_usrreqs
201 .pr_domain = &inetdomain,
202 .pr_protocol = IPPROTO_ICMP,
203 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
204 .pr_input = icmp_input,
205 .pr_ctloutput = rip_ctloutput,
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_init = igmp_init,
216 .pr_fasttimo = igmp_fasttimo,
217 .pr_slowtimo = igmp_slowtimo,
218 .pr_usrreqs = &rip_usrreqs
222 .pr_domain = &inetdomain,
223 .pr_protocol = IPPROTO_RSVP,
224 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
225 .pr_input = rsvp_input,
226 .pr_ctloutput = rip_ctloutput,
227 .pr_usrreqs = &rip_usrreqs
232 .pr_domain = &inetdomain,
233 .pr_protocol = IPPROTO_AH,
234 .pr_flags = PR_ATOMIC|PR_ADDR,
235 .pr_input = ah4_input,
236 .pr_usrreqs = &nousrreqs
241 .pr_domain = &inetdomain,
242 .pr_protocol = IPPROTO_ESP,
243 .pr_flags = PR_ATOMIC|PR_ADDR,
244 .pr_input = esp4_input,
245 .pr_usrreqs = &nousrreqs
250 .pr_domain = &inetdomain,
251 .pr_protocol = IPPROTO_IPCOMP,
252 .pr_flags = PR_ATOMIC|PR_ADDR,
253 .pr_input = ipcomp4_input,
254 .pr_usrreqs = &nousrreqs
260 .pr_domain = &inetdomain,
261 .pr_protocol = IPPROTO_AH,
262 .pr_flags = PR_ATOMIC|PR_ADDR,
263 .pr_input = ah4_input,
264 .pr_ctlinput = ah4_ctlinput,
265 .pr_usrreqs = &nousrreqs
269 .pr_domain = &inetdomain,
270 .pr_protocol = IPPROTO_ESP,
271 .pr_flags = PR_ATOMIC|PR_ADDR,
272 .pr_input = esp4_input,
273 .pr_ctlinput = esp4_ctlinput,
274 .pr_usrreqs = &nousrreqs
278 .pr_domain = &inetdomain,
279 .pr_protocol = IPPROTO_IPCOMP,
280 .pr_flags = PR_ATOMIC|PR_ADDR,
281 .pr_input = ipcomp4_input,
282 .pr_usrreqs = &nousrreqs
284 #endif /* FAST_IPSEC */
287 .pr_domain = &inetdomain,
288 .pr_protocol = IPPROTO_IPV4,
289 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
290 .pr_input = encap4_input,
291 .pr_ctloutput = rip_ctloutput,
292 .pr_init = encap_init,
293 .pr_usrreqs = &rip_usrreqs
297 .pr_domain = &inetdomain,
298 .pr_protocol = IPPROTO_MOBILE,
299 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
300 .pr_input = encap4_input,
301 .pr_ctloutput = rip_ctloutput,
302 .pr_init = encap_init,
303 .pr_usrreqs = &rip_usrreqs
307 .pr_domain = &inetdomain,
308 .pr_protocol = IPPROTO_ETHERIP,
309 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
310 .pr_input = encap4_input,
311 .pr_ctloutput = rip_ctloutput,
312 .pr_init = encap_init,
313 .pr_usrreqs = &rip_usrreqs
317 .pr_domain = &inetdomain,
318 .pr_protocol = IPPROTO_GRE,
319 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
320 .pr_input = encap4_input,
321 .pr_ctloutput = rip_ctloutput,
322 .pr_init = encap_init,
323 .pr_usrreqs = &rip_usrreqs
328 .pr_domain = &inetdomain,
329 .pr_protocol = IPPROTO_IPV6,
330 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
331 .pr_input = encap4_input,
332 .pr_ctloutput = rip_ctloutput,
333 .pr_init = encap_init,
334 .pr_usrreqs = &rip_usrreqs
340 .pr_domain = &inetdomain,
341 .pr_protocol = IPPROTO_IDP,
342 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
343 .pr_input = ipxip_input,
344 .pr_ctlinput = ipxip_ctlinput,
345 .pr_usrreqs = &rip_usrreqs
351 .pr_domain = &inetdomain,
352 .pr_protocol = IPPROTO_PIM,
353 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
354 .pr_input = pim_input,
355 .pr_ctloutput = rip_ctloutput,
356 .pr_usrreqs = &rip_usrreqs
362 .pr_domain = &inetdomain,
363 .pr_protocol = IPPROTO_PFSYNC,
364 .pr_flags = PR_ATOMIC|PR_ADDR,
365 .pr_input = pfsync_input,
366 .pr_ctloutput = rip_ctloutput,
367 .pr_usrreqs = &rip_usrreqs
369 #endif /* DEV_PFSYNC */
373 .pr_domain = &inetdomain,
374 .pr_protocol = IPPROTO_CARP,
375 .pr_flags = PR_ATOMIC|PR_ADDR,
376 .pr_input = carp_input,
377 .pr_output = (pr_output_t*)rip_output,
378 .pr_ctloutput = rip_ctloutput,
379 .pr_usrreqs = &rip_usrreqs
381 #endif /* DEV_CARP */
382 /* Spacer n-times for loadable protocols. */
394 .pr_domain = &inetdomain,
395 .pr_flags = PR_ATOMIC|PR_ADDR,
396 .pr_input = rip_input,
397 .pr_ctloutput = rip_ctloutput,
399 .pr_usrreqs = &rip_usrreqs
403 extern int in_inithead(void **, int);
405 struct domain inetdomain = {
406 .dom_family = AF_INET,
407 .dom_name = "internet",
408 .dom_protosw = inetsw,
409 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
410 .dom_rtattach = in_inithead,
412 .dom_maxrtkey = sizeof(struct sockaddr_in)
417 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
420 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
421 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
422 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
423 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
425 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
427 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
429 /* XXX no protocol # to use, pick something "reserved" */
430 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
431 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
432 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
433 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
434 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
437 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
439 #endif /* !FAST_IPSEC */
440 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
442 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
445 SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC");
448 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");