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>
59 #include <netinet/tcp.h>
60 #include <netinet/tcp_timer.h>
61 #include <netinet/tcp_var.h>
62 #include <netinet/udp.h>
63 #include <netinet/udp_var.h>
64 #include <netinet/ip_encap.h>
67 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
70 static struct pr_usrreqs nousrreqs;
73 #include <netinet6/ipsec.h>
74 #include <netinet6/ah.h>
76 #include <netinet6/esp.h>
78 #include <netinet6/ipcomp.h>
82 #include <netipsec/ipsec.h>
83 #endif /* FAST_IPSEC */
86 #include <netipx/ipx_ip.h>
90 #include <netinet/in_pcb.h>
91 #include <netinet/sctp_pcb.h>
92 #include <netinet/sctp.h>
93 #include <netinet/sctp_var.h>
97 #include <net/pfvar.h>
98 #include <net/if_pfsync.h>
102 #include <netinet/ip_carp.h>
105 extern struct domain inetdomain;
107 /* Spacer for loadable protocols. */
108 #define IPPROTOSPACER \
110 .pr_domain = &inetdomain, \
111 .pr_protocol = PROTO_SPACER, \
112 .pr_usrreqs = &nousrreqs \
115 struct protosw inetsw[] = {
118 .pr_domain = &inetdomain,
119 .pr_protocol = IPPROTO_IP,
121 .pr_slowtimo = ip_slowtimo,
122 .pr_drain = ip_drain,
123 .pr_usrreqs = &nousrreqs
126 .pr_type = SOCK_DGRAM,
127 .pr_domain = &inetdomain,
128 .pr_protocol = IPPROTO_UDP,
129 .pr_flags = PR_ATOMIC|PR_ADDR,
130 .pr_input = udp_input,
131 .pr_ctlinput = udp_ctlinput,
132 .pr_ctloutput = ip_ctloutput,
134 .pr_usrreqs = &udp_usrreqs
137 .pr_type = SOCK_STREAM,
138 .pr_domain = &inetdomain,
139 .pr_protocol = IPPROTO_TCP,
140 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
141 .pr_input = tcp_input,
142 .pr_ctlinput = tcp_ctlinput,
143 .pr_ctloutput = tcp_ctloutput,
145 .pr_slowtimo = tcp_slowtimo,
146 .pr_drain = tcp_drain,
147 .pr_usrreqs = &tcp_usrreqs
151 .pr_type = SOCK_DGRAM,
152 .pr_domain = &inetdomain,
153 .pr_protocol = IPPROTO_SCTP,
154 .pr_flags = PR_WANTRCVD,
155 .pr_input = sctp_input,
156 .pr_ctlinput = sctp_ctlinput,
157 .pr_ctloutput = sctp_ctloutput,
158 .pr_init = sctp_init,
159 .pr_drain = sctp_drain,
160 .pr_usrreqs = &sctp_usrreqs
163 .pr_type = SOCK_SEQPACKET,
164 .pr_domain = &inetdomain,
165 .pr_protocol = IPPROTO_SCTP,
166 .pr_flags = PR_WANTRCVD,
167 .pr_input = sctp_input,
168 .pr_ctlinput = sctp_ctlinput,
169 .pr_ctloutput = sctp_ctloutput,
170 .pr_drain = sctp_drain,
171 .pr_usrreqs = &sctp_usrreqs
175 .pr_type = SOCK_STREAM,
176 .pr_domain = &inetdomain,
177 .pr_protocol = IPPROTO_SCTP,
178 .pr_flags = PR_WANTRCVD,
179 .pr_input = sctp_input,
180 .pr_ctlinput = sctp_ctlinput,
181 .pr_ctloutput = sctp_ctloutput,
182 .pr_drain = sctp_drain,
183 .pr_usrreqs = &sctp_usrreqs
188 .pr_domain = &inetdomain,
189 .pr_protocol = IPPROTO_RAW,
190 .pr_flags = PR_ATOMIC|PR_ADDR,
191 .pr_input = rip_input,
192 .pr_ctlinput = rip_ctlinput,
193 .pr_ctloutput = rip_ctloutput,
194 .pr_usrreqs = &rip_usrreqs
198 .pr_domain = &inetdomain,
199 .pr_protocol = IPPROTO_ICMP,
200 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
201 .pr_input = icmp_input,
202 .pr_ctloutput = rip_ctloutput,
203 .pr_usrreqs = &rip_usrreqs
207 .pr_domain = &inetdomain,
208 .pr_protocol = IPPROTO_IGMP,
209 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
210 .pr_input = igmp_input,
211 .pr_ctloutput = rip_ctloutput,
212 .pr_init = igmp_init,
213 .pr_fasttimo = igmp_fasttimo,
214 .pr_slowtimo = igmp_slowtimo,
215 .pr_usrreqs = &rip_usrreqs
219 .pr_domain = &inetdomain,
220 .pr_protocol = IPPROTO_RSVP,
221 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
222 .pr_input = rsvp_input,
223 .pr_ctloutput = rip_ctloutput,
224 .pr_usrreqs = &rip_usrreqs
229 .pr_domain = &inetdomain,
230 .pr_protocol = IPPROTO_AH,
231 .pr_flags = PR_ATOMIC|PR_ADDR,
232 .pr_input = ah4_input,
233 .pr_usrreqs = &nousrreqs
238 .pr_domain = &inetdomain,
239 .pr_protocol = IPPROTO_ESP,
240 .pr_flags = PR_ATOMIC|PR_ADDR,
241 .pr_input = esp4_input,
242 .pr_usrreqs = &nousrreqs
247 .pr_domain = &inetdomain,
248 .pr_protocol = IPPROTO_IPCOMP,
249 .pr_flags = PR_ATOMIC|PR_ADDR,
250 .pr_input = ipcomp4_input,
251 .pr_usrreqs = &nousrreqs
257 .pr_domain = &inetdomain,
258 .pr_protocol = IPPROTO_AH,
259 .pr_flags = PR_ATOMIC|PR_ADDR,
260 .pr_input = ah4_input,
261 .pr_ctlinput = ah4_ctlinput,
262 .pr_usrreqs = &nousrreqs
266 .pr_domain = &inetdomain,
267 .pr_protocol = IPPROTO_ESP,
268 .pr_flags = PR_ATOMIC|PR_ADDR,
269 .pr_input = esp4_input,
270 .pr_ctlinput = esp4_ctlinput,
271 .pr_usrreqs = &nousrreqs
275 .pr_domain = &inetdomain,
276 .pr_protocol = IPPROTO_IPCOMP,
277 .pr_flags = PR_ATOMIC|PR_ADDR,
278 .pr_input = ipcomp4_input,
279 .pr_usrreqs = &nousrreqs
281 #endif /* FAST_IPSEC */
284 .pr_domain = &inetdomain,
285 .pr_protocol = IPPROTO_IPV4,
286 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
287 .pr_input = encap4_input,
288 .pr_ctloutput = rip_ctloutput,
289 .pr_init = encap_init,
290 .pr_usrreqs = &rip_usrreqs
294 .pr_domain = &inetdomain,
295 .pr_protocol = IPPROTO_MOBILE,
296 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
297 .pr_input = encap4_input,
298 .pr_ctloutput = rip_ctloutput,
299 .pr_init = encap_init,
300 .pr_usrreqs = &rip_usrreqs
304 .pr_domain = &inetdomain,
305 .pr_protocol = IPPROTO_ETHERIP,
306 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
307 .pr_input = encap4_input,
308 .pr_ctloutput = rip_ctloutput,
309 .pr_init = encap_init,
310 .pr_usrreqs = &rip_usrreqs
314 .pr_domain = &inetdomain,
315 .pr_protocol = IPPROTO_GRE,
316 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
317 .pr_input = encap4_input,
318 .pr_ctloutput = rip_ctloutput,
319 .pr_init = encap_init,
320 .pr_usrreqs = &rip_usrreqs
325 .pr_domain = &inetdomain,
326 .pr_protocol = IPPROTO_IPV6,
327 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
328 .pr_input = encap4_input,
329 .pr_ctloutput = rip_ctloutput,
330 .pr_init = encap_init,
331 .pr_usrreqs = &rip_usrreqs
337 .pr_domain = &inetdomain,
338 .pr_protocol = IPPROTO_IDP,
339 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
340 .pr_input = ipxip_input,
341 .pr_ctlinput = ipxip_ctlinput,
342 .pr_usrreqs = &rip_usrreqs
347 .pr_domain = &inetdomain,
348 .pr_protocol = IPPROTO_PIM,
349 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
350 .pr_input = encap4_input,
351 .pr_ctloutput = rip_ctloutput,
352 .pr_usrreqs = &rip_usrreqs
357 .pr_domain = &inetdomain,
358 .pr_protocol = IPPROTO_PFSYNC,
359 .pr_flags = PR_ATOMIC|PR_ADDR,
360 .pr_input = pfsync_input,
361 .pr_ctloutput = rip_ctloutput,
362 .pr_usrreqs = &rip_usrreqs
364 #endif /* DEV_PFSYNC */
368 .pr_domain = &inetdomain,
369 .pr_protocol = IPPROTO_CARP,
370 .pr_flags = PR_ATOMIC|PR_ADDR,
371 .pr_input = carp_input,
372 .pr_output = (pr_output_t*)rip_output,
373 .pr_ctloutput = rip_ctloutput,
374 .pr_usrreqs = &rip_usrreqs
376 #endif /* DEV_CARP */
377 /* Spacer n-times for loadable protocols. */
389 .pr_domain = &inetdomain,
390 .pr_flags = PR_ATOMIC|PR_ADDR,
391 .pr_input = rip_input,
392 .pr_ctloutput = rip_ctloutput,
394 .pr_usrreqs = &rip_usrreqs
398 extern int in_inithead(void **, int);
400 struct domain inetdomain = {
401 .dom_family = AF_INET,
402 .dom_name = "internet",
403 .dom_protosw = inetsw,
404 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
405 .dom_rtattach = in_inithead,
407 .dom_maxrtkey = sizeof(struct sockaddr_in)
412 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
415 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
416 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
417 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
418 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
420 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
422 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
424 /* XXX no protocol # to use, pick something "reserved" */
425 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
426 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
427 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
428 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
429 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
432 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
434 #endif /* !FAST_IPSEC */
435 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
437 SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC");
440 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");