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>
49 #include <sys/protosw.h>
50 #include <sys/queue.h>
51 #include <sys/sysctl.h>
54 #include <net/route.h>
56 #include <net/radix_mpath.h>
59 #include <netinet/in.h>
60 #include <netinet/in_systm.h>
61 #include <netinet/ip.h>
62 #include <netinet/ip_var.h>
63 #include <netinet/ip_icmp.h>
64 #include <netinet/igmp_var.h>
65 #include <netinet/tcp.h>
66 #include <netinet/tcp_timer.h>
67 #include <netinet/tcp_var.h>
68 #include <netinet/udp.h>
69 #include <netinet/udp_var.h>
70 #include <netinet/ip_encap.h>
73 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
76 static struct pr_usrreqs nousrreqs;
79 #include <netipsec/ipsec.h>
83 #include <netinet/in_pcb.h>
84 #include <netinet/sctp_pcb.h>
85 #include <netinet/sctp.h>
86 #include <netinet/sctp_var.h>
90 #include <net/pfvar.h>
91 #include <net/if_pfsync.h>
95 #include <netinet/ip_carp.h>
98 extern struct domain inetdomain;
100 /* Spacer for loadable protocols. */
101 #define IPPROTOSPACER \
103 .pr_domain = &inetdomain, \
104 .pr_protocol = PROTO_SPACER, \
105 .pr_usrreqs = &nousrreqs \
108 struct protosw inetsw[] = {
111 .pr_domain = &inetdomain,
112 .pr_protocol = IPPROTO_IP,
114 .pr_slowtimo = ip_slowtimo,
115 .pr_drain = ip_drain,
116 .pr_usrreqs = &nousrreqs
119 .pr_type = SOCK_DGRAM,
120 .pr_domain = &inetdomain,
121 .pr_protocol = IPPROTO_UDP,
122 .pr_flags = PR_ATOMIC|PR_ADDR,
123 .pr_input = udp_input,
124 .pr_ctlinput = udp_ctlinput,
125 .pr_ctloutput = ip_ctloutput,
127 .pr_usrreqs = &udp_usrreqs
130 .pr_type = SOCK_STREAM,
131 .pr_domain = &inetdomain,
132 .pr_protocol = IPPROTO_TCP,
133 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
134 .pr_input = tcp_input,
135 .pr_ctlinput = tcp_ctlinput,
136 .pr_ctloutput = tcp_ctloutput,
138 .pr_slowtimo = tcp_slowtimo,
139 .pr_drain = tcp_drain,
140 .pr_usrreqs = &tcp_usrreqs
144 .pr_type = SOCK_DGRAM,
145 .pr_domain = &inetdomain,
146 .pr_protocol = IPPROTO_SCTP,
147 .pr_flags = PR_WANTRCVD,
148 .pr_input = sctp_input,
149 .pr_ctlinput = sctp_ctlinput,
150 .pr_ctloutput = sctp_ctloutput,
151 .pr_init = sctp_init,
152 .pr_drain = sctp_drain,
153 .pr_usrreqs = &sctp_usrreqs
156 .pr_type = SOCK_SEQPACKET,
157 .pr_domain = &inetdomain,
158 .pr_protocol = IPPROTO_SCTP,
159 .pr_flags = PR_WANTRCVD,
160 .pr_input = sctp_input,
161 .pr_ctlinput = sctp_ctlinput,
162 .pr_ctloutput = sctp_ctloutput,
163 .pr_drain = sctp_drain,
164 .pr_usrreqs = &sctp_usrreqs
168 .pr_type = SOCK_STREAM,
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
181 .pr_domain = &inetdomain,
182 .pr_protocol = IPPROTO_RAW,
183 .pr_flags = PR_ATOMIC|PR_ADDR,
184 .pr_input = rip_input,
185 .pr_ctlinput = rip_ctlinput,
186 .pr_ctloutput = rip_ctloutput,
187 .pr_usrreqs = &rip_usrreqs
191 .pr_domain = &inetdomain,
192 .pr_protocol = IPPROTO_ICMP,
193 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
194 .pr_input = icmp_input,
195 .pr_ctloutput = rip_ctloutput,
196 .pr_usrreqs = &rip_usrreqs
200 .pr_domain = &inetdomain,
201 .pr_protocol = IPPROTO_IGMP,
202 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
203 .pr_input = igmp_input,
204 .pr_ctloutput = rip_ctloutput,
205 .pr_init = igmp_init,
206 .pr_fasttimo = igmp_fasttimo,
207 .pr_slowtimo = igmp_slowtimo,
208 .pr_usrreqs = &rip_usrreqs
212 .pr_domain = &inetdomain,
213 .pr_protocol = IPPROTO_RSVP,
214 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
215 .pr_input = rsvp_input,
216 .pr_ctloutput = rip_ctloutput,
217 .pr_usrreqs = &rip_usrreqs
222 .pr_domain = &inetdomain,
223 .pr_protocol = IPPROTO_AH,
224 .pr_flags = PR_ATOMIC|PR_ADDR,
225 .pr_input = ah4_input,
226 .pr_ctlinput = ah4_ctlinput,
227 .pr_usrreqs = &nousrreqs
231 .pr_domain = &inetdomain,
232 .pr_protocol = IPPROTO_ESP,
233 .pr_flags = PR_ATOMIC|PR_ADDR,
234 .pr_input = esp4_input,
235 .pr_ctlinput = esp4_ctlinput,
236 .pr_usrreqs = &nousrreqs
240 .pr_domain = &inetdomain,
241 .pr_protocol = IPPROTO_IPCOMP,
242 .pr_flags = PR_ATOMIC|PR_ADDR,
243 .pr_input = ipcomp4_input,
244 .pr_usrreqs = &nousrreqs
249 .pr_domain = &inetdomain,
250 .pr_protocol = IPPROTO_IPV4,
251 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
252 .pr_input = encap4_input,
253 .pr_ctloutput = rip_ctloutput,
254 .pr_init = encap_init,
255 .pr_usrreqs = &rip_usrreqs
259 .pr_domain = &inetdomain,
260 .pr_protocol = IPPROTO_MOBILE,
261 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
262 .pr_input = encap4_input,
263 .pr_ctloutput = rip_ctloutput,
264 .pr_init = encap_init,
265 .pr_usrreqs = &rip_usrreqs
269 .pr_domain = &inetdomain,
270 .pr_protocol = IPPROTO_ETHERIP,
271 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
272 .pr_input = encap4_input,
273 .pr_ctloutput = rip_ctloutput,
274 .pr_init = encap_init,
275 .pr_usrreqs = &rip_usrreqs
279 .pr_domain = &inetdomain,
280 .pr_protocol = IPPROTO_GRE,
281 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
282 .pr_input = encap4_input,
283 .pr_ctloutput = rip_ctloutput,
284 .pr_init = encap_init,
285 .pr_usrreqs = &rip_usrreqs
290 .pr_domain = &inetdomain,
291 .pr_protocol = IPPROTO_IPV6,
292 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
293 .pr_input = encap4_input,
294 .pr_ctloutput = rip_ctloutput,
295 .pr_init = encap_init,
296 .pr_usrreqs = &rip_usrreqs
301 .pr_domain = &inetdomain,
302 .pr_protocol = IPPROTO_PIM,
303 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
304 .pr_input = encap4_input,
305 .pr_ctloutput = rip_ctloutput,
306 .pr_usrreqs = &rip_usrreqs
311 .pr_domain = &inetdomain,
312 .pr_protocol = IPPROTO_PFSYNC,
313 .pr_flags = PR_ATOMIC|PR_ADDR,
314 .pr_input = pfsync_input,
315 .pr_ctloutput = rip_ctloutput,
316 .pr_usrreqs = &rip_usrreqs
318 #endif /* DEV_PFSYNC */
322 .pr_domain = &inetdomain,
323 .pr_protocol = IPPROTO_CARP,
324 .pr_flags = PR_ATOMIC|PR_ADDR,
325 .pr_input = carp_input,
326 .pr_output = (pr_output_t*)rip_output,
327 .pr_ctloutput = rip_ctloutput,
328 .pr_usrreqs = &rip_usrreqs
330 #endif /* DEV_CARP */
331 /* Spacer n-times for loadable protocols. */
343 .pr_domain = &inetdomain,
344 .pr_flags = PR_ATOMIC|PR_ADDR,
345 .pr_input = rip_input,
346 .pr_ctloutput = rip_ctloutput,
348 .pr_usrreqs = &rip_usrreqs
352 extern int in_inithead(void **, int);
354 struct domain inetdomain = {
355 .dom_family = AF_INET,
356 .dom_name = "internet",
357 .dom_protosw = inetsw,
358 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
360 .dom_rtattach = rn4_mpath_inithead,
362 .dom_rtattach = in_inithead,
365 .dom_maxrtkey = sizeof(struct sockaddr_in)
370 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
373 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
374 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
375 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
376 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
378 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
380 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
382 /* XXX no protocol # to use, pick something "reserved" */
383 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
384 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
385 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
386 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
387 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
389 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
391 SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC");
394 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");