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"
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/socket.h>
47 #include <sys/domain.h>
48 #include <sys/protosw.h>
49 #include <sys/queue.h>
50 #include <sys/sysctl.h>
53 #include <net/route.h>
55 #include <netinet/in.h>
56 #include <netinet/in_systm.h>
57 #include <netinet/ip.h>
58 #include <netinet/ip_var.h>
59 #include <netinet/ip_icmp.h>
60 #include <netinet/igmp_var.h>
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>
69 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
72 static struct pr_usrreqs nousrreqs;
75 #include <netipsec/ipsec.h>
79 #include <netinet/in_pcb.h>
80 #include <netinet/sctp_pcb.h>
81 #include <netinet/sctp.h>
82 #include <netinet/sctp_var.h>
86 #include <net/pfvar.h>
87 #include <net/if_pfsync.h>
91 #include <netinet/ip_carp.h>
94 extern struct domain inetdomain;
96 /* Spacer for loadable protocols. */
97 #define IPPROTOSPACER \
99 .pr_domain = &inetdomain, \
100 .pr_protocol = PROTO_SPACER, \
101 .pr_usrreqs = &nousrreqs \
104 struct protosw inetsw[] = {
107 .pr_domain = &inetdomain,
108 .pr_protocol = IPPROTO_IP,
110 .pr_slowtimo = ip_slowtimo,
111 .pr_drain = ip_drain,
112 .pr_usrreqs = &nousrreqs
115 .pr_type = SOCK_DGRAM,
116 .pr_domain = &inetdomain,
117 .pr_protocol = IPPROTO_UDP,
118 .pr_flags = PR_ATOMIC|PR_ADDR,
119 .pr_input = udp_input,
120 .pr_ctlinput = udp_ctlinput,
121 .pr_ctloutput = ip_ctloutput,
123 .pr_usrreqs = &udp_usrreqs
126 .pr_type = SOCK_STREAM,
127 .pr_domain = &inetdomain,
128 .pr_protocol = IPPROTO_TCP,
129 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
130 .pr_input = tcp_input,
131 .pr_ctlinput = tcp_ctlinput,
132 .pr_ctloutput = tcp_ctloutput,
134 .pr_slowtimo = tcp_slowtimo,
135 .pr_drain = tcp_drain,
136 .pr_usrreqs = &tcp_usrreqs
140 .pr_type = SOCK_DGRAM,
141 .pr_domain = &inetdomain,
142 .pr_protocol = IPPROTO_SCTP,
143 .pr_flags = PR_WANTRCVD,
144 .pr_input = sctp_input,
145 .pr_ctlinput = sctp_ctlinput,
146 .pr_ctloutput = sctp_ctloutput,
147 .pr_init = sctp_init,
148 .pr_drain = sctp_drain,
149 .pr_usrreqs = &sctp_usrreqs
152 .pr_type = SOCK_SEQPACKET,
153 .pr_domain = &inetdomain,
154 .pr_protocol = IPPROTO_SCTP,
155 .pr_flags = PR_WANTRCVD,
156 .pr_input = sctp_input,
157 .pr_ctlinput = sctp_ctlinput,
158 .pr_ctloutput = sctp_ctloutput,
159 .pr_drain = sctp_drain,
160 .pr_usrreqs = &sctp_usrreqs
164 .pr_type = SOCK_STREAM,
165 .pr_domain = &inetdomain,
166 .pr_protocol = IPPROTO_SCTP,
167 .pr_flags = PR_WANTRCVD,
168 .pr_input = sctp_input,
169 .pr_ctlinput = sctp_ctlinput,
170 .pr_ctloutput = sctp_ctloutput,
171 .pr_drain = sctp_drain,
172 .pr_usrreqs = &sctp_usrreqs
177 .pr_domain = &inetdomain,
178 .pr_protocol = IPPROTO_RAW,
179 .pr_flags = PR_ATOMIC|PR_ADDR,
180 .pr_input = rip_input,
181 .pr_ctlinput = rip_ctlinput,
182 .pr_ctloutput = rip_ctloutput,
183 .pr_usrreqs = &rip_usrreqs
187 .pr_domain = &inetdomain,
188 .pr_protocol = IPPROTO_ICMP,
189 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
190 .pr_input = icmp_input,
191 .pr_ctloutput = rip_ctloutput,
192 .pr_usrreqs = &rip_usrreqs
196 .pr_domain = &inetdomain,
197 .pr_protocol = IPPROTO_IGMP,
198 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
199 .pr_input = igmp_input,
200 .pr_ctloutput = rip_ctloutput,
201 .pr_init = igmp_init,
202 .pr_fasttimo = igmp_fasttimo,
203 .pr_slowtimo = igmp_slowtimo,
204 .pr_usrreqs = &rip_usrreqs
208 .pr_domain = &inetdomain,
209 .pr_protocol = IPPROTO_RSVP,
210 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
211 .pr_input = rsvp_input,
212 .pr_ctloutput = rip_ctloutput,
213 .pr_usrreqs = &rip_usrreqs
218 .pr_domain = &inetdomain,
219 .pr_protocol = IPPROTO_AH,
220 .pr_flags = PR_ATOMIC|PR_ADDR,
221 .pr_input = ah4_input,
222 .pr_ctlinput = ah4_ctlinput,
223 .pr_usrreqs = &nousrreqs
227 .pr_domain = &inetdomain,
228 .pr_protocol = IPPROTO_ESP,
229 .pr_flags = PR_ATOMIC|PR_ADDR,
230 .pr_input = esp4_input,
231 .pr_ctlinput = esp4_ctlinput,
232 .pr_usrreqs = &nousrreqs
236 .pr_domain = &inetdomain,
237 .pr_protocol = IPPROTO_IPCOMP,
238 .pr_flags = PR_ATOMIC|PR_ADDR,
239 .pr_input = ipcomp4_input,
240 .pr_usrreqs = &nousrreqs
245 .pr_domain = &inetdomain,
246 .pr_protocol = IPPROTO_IPV4,
247 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
248 .pr_input = encap4_input,
249 .pr_ctloutput = rip_ctloutput,
250 .pr_init = encap_init,
251 .pr_usrreqs = &rip_usrreqs
255 .pr_domain = &inetdomain,
256 .pr_protocol = IPPROTO_MOBILE,
257 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
258 .pr_input = encap4_input,
259 .pr_ctloutput = rip_ctloutput,
260 .pr_init = encap_init,
261 .pr_usrreqs = &rip_usrreqs
265 .pr_domain = &inetdomain,
266 .pr_protocol = IPPROTO_ETHERIP,
267 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
268 .pr_input = encap4_input,
269 .pr_ctloutput = rip_ctloutput,
270 .pr_init = encap_init,
271 .pr_usrreqs = &rip_usrreqs
275 .pr_domain = &inetdomain,
276 .pr_protocol = IPPROTO_GRE,
277 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
278 .pr_input = encap4_input,
279 .pr_ctloutput = rip_ctloutput,
280 .pr_init = encap_init,
281 .pr_usrreqs = &rip_usrreqs
286 .pr_domain = &inetdomain,
287 .pr_protocol = IPPROTO_IPV6,
288 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
289 .pr_input = encap4_input,
290 .pr_ctloutput = rip_ctloutput,
291 .pr_init = encap_init,
292 .pr_usrreqs = &rip_usrreqs
297 .pr_domain = &inetdomain,
298 .pr_protocol = IPPROTO_PIM,
299 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
300 .pr_input = encap4_input,
301 .pr_ctloutput = rip_ctloutput,
302 .pr_usrreqs = &rip_usrreqs
307 .pr_domain = &inetdomain,
308 .pr_protocol = IPPROTO_PFSYNC,
309 .pr_flags = PR_ATOMIC|PR_ADDR,
310 .pr_input = pfsync_input,
311 .pr_ctloutput = rip_ctloutput,
312 .pr_usrreqs = &rip_usrreqs
314 #endif /* DEV_PFSYNC */
318 .pr_domain = &inetdomain,
319 .pr_protocol = IPPROTO_CARP,
320 .pr_flags = PR_ATOMIC|PR_ADDR,
321 .pr_input = carp_input,
322 .pr_output = (pr_output_t*)rip_output,
323 .pr_ctloutput = rip_ctloutput,
324 .pr_usrreqs = &rip_usrreqs
326 #endif /* DEV_CARP */
327 /* Spacer n-times for loadable protocols. */
339 .pr_domain = &inetdomain,
340 .pr_flags = PR_ATOMIC|PR_ADDR,
341 .pr_input = rip_input,
342 .pr_ctloutput = rip_ctloutput,
344 .pr_usrreqs = &rip_usrreqs
348 extern int in_inithead(void **, int);
350 struct domain inetdomain = {
351 .dom_family = AF_INET,
352 .dom_name = "internet",
353 .dom_protosw = inetsw,
354 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
355 .dom_rtattach = in_inithead,
357 .dom_maxrtkey = sizeof(struct sockaddr_in)
362 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
365 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
366 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
367 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
368 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
370 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
372 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
374 /* XXX no protocol # to use, pick something "reserved" */
375 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
376 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
377 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
378 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
379 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
381 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
383 SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC");
386 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");