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 <netipsec/ipsec.h>
77 #include <netinet/in_pcb.h>
78 #include <netinet/sctp_pcb.h>
79 #include <netinet/sctp.h>
80 #include <netinet/sctp_var.h>
84 #include <net/pfvar.h>
85 #include <net/if_pfsync.h>
89 #include <netinet/ip_carp.h>
92 extern struct domain inetdomain;
94 /* Spacer for loadable protocols. */
95 #define IPPROTOSPACER \
97 .pr_domain = &inetdomain, \
98 .pr_protocol = PROTO_SPACER, \
99 .pr_usrreqs = &nousrreqs \
102 struct protosw inetsw[] = {
105 .pr_domain = &inetdomain,
106 .pr_protocol = IPPROTO_IP,
108 .pr_slowtimo = ip_slowtimo,
109 .pr_drain = ip_drain,
110 .pr_usrreqs = &nousrreqs
113 .pr_type = SOCK_DGRAM,
114 .pr_domain = &inetdomain,
115 .pr_protocol = IPPROTO_UDP,
116 .pr_flags = PR_ATOMIC|PR_ADDR,
117 .pr_input = udp_input,
118 .pr_ctlinput = udp_ctlinput,
119 .pr_ctloutput = ip_ctloutput,
121 .pr_usrreqs = &udp_usrreqs
124 .pr_type = SOCK_STREAM,
125 .pr_domain = &inetdomain,
126 .pr_protocol = IPPROTO_TCP,
127 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
128 .pr_input = tcp_input,
129 .pr_ctlinput = tcp_ctlinput,
130 .pr_ctloutput = tcp_ctloutput,
132 .pr_slowtimo = tcp_slowtimo,
133 .pr_drain = tcp_drain,
134 .pr_usrreqs = &tcp_usrreqs
138 .pr_type = SOCK_DGRAM,
139 .pr_domain = &inetdomain,
140 .pr_protocol = IPPROTO_SCTP,
141 .pr_flags = PR_WANTRCVD,
142 .pr_input = sctp_input,
143 .pr_ctlinput = sctp_ctlinput,
144 .pr_ctloutput = sctp_ctloutput,
145 .pr_init = sctp_init,
146 .pr_drain = sctp_drain,
147 .pr_usrreqs = &sctp_usrreqs
150 .pr_type = SOCK_SEQPACKET,
151 .pr_domain = &inetdomain,
152 .pr_protocol = IPPROTO_SCTP,
153 .pr_flags = PR_WANTRCVD,
154 .pr_input = sctp_input,
155 .pr_ctlinput = sctp_ctlinput,
156 .pr_ctloutput = sctp_ctloutput,
157 .pr_drain = sctp_drain,
158 .pr_usrreqs = &sctp_usrreqs
162 .pr_type = SOCK_STREAM,
163 .pr_domain = &inetdomain,
164 .pr_protocol = IPPROTO_SCTP,
165 .pr_flags = PR_WANTRCVD,
166 .pr_input = sctp_input,
167 .pr_ctlinput = sctp_ctlinput,
168 .pr_ctloutput = sctp_ctloutput,
169 .pr_drain = sctp_drain,
170 .pr_usrreqs = &sctp_usrreqs
175 .pr_domain = &inetdomain,
176 .pr_protocol = IPPROTO_RAW,
177 .pr_flags = PR_ATOMIC|PR_ADDR,
178 .pr_input = rip_input,
179 .pr_ctlinput = rip_ctlinput,
180 .pr_ctloutput = rip_ctloutput,
181 .pr_usrreqs = &rip_usrreqs
185 .pr_domain = &inetdomain,
186 .pr_protocol = IPPROTO_ICMP,
187 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
188 .pr_input = icmp_input,
189 .pr_ctloutput = rip_ctloutput,
190 .pr_usrreqs = &rip_usrreqs
194 .pr_domain = &inetdomain,
195 .pr_protocol = IPPROTO_IGMP,
196 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
197 .pr_input = igmp_input,
198 .pr_ctloutput = rip_ctloutput,
199 .pr_init = igmp_init,
200 .pr_fasttimo = igmp_fasttimo,
201 .pr_slowtimo = igmp_slowtimo,
202 .pr_usrreqs = &rip_usrreqs
206 .pr_domain = &inetdomain,
207 .pr_protocol = IPPROTO_RSVP,
208 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
209 .pr_input = rsvp_input,
210 .pr_ctloutput = rip_ctloutput,
211 .pr_usrreqs = &rip_usrreqs
216 .pr_domain = &inetdomain,
217 .pr_protocol = IPPROTO_AH,
218 .pr_flags = PR_ATOMIC|PR_ADDR,
219 .pr_input = ah4_input,
220 .pr_ctlinput = ah4_ctlinput,
221 .pr_usrreqs = &nousrreqs
225 .pr_domain = &inetdomain,
226 .pr_protocol = IPPROTO_ESP,
227 .pr_flags = PR_ATOMIC|PR_ADDR,
228 .pr_input = esp4_input,
229 .pr_ctlinput = esp4_ctlinput,
230 .pr_usrreqs = &nousrreqs
234 .pr_domain = &inetdomain,
235 .pr_protocol = IPPROTO_IPCOMP,
236 .pr_flags = PR_ATOMIC|PR_ADDR,
237 .pr_input = ipcomp4_input,
238 .pr_usrreqs = &nousrreqs
243 .pr_domain = &inetdomain,
244 .pr_protocol = IPPROTO_IPV4,
245 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
246 .pr_input = encap4_input,
247 .pr_ctloutput = rip_ctloutput,
248 .pr_init = encap_init,
249 .pr_usrreqs = &rip_usrreqs
253 .pr_domain = &inetdomain,
254 .pr_protocol = IPPROTO_MOBILE,
255 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
256 .pr_input = encap4_input,
257 .pr_ctloutput = rip_ctloutput,
258 .pr_init = encap_init,
259 .pr_usrreqs = &rip_usrreqs
263 .pr_domain = &inetdomain,
264 .pr_protocol = IPPROTO_ETHERIP,
265 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
266 .pr_input = encap4_input,
267 .pr_ctloutput = rip_ctloutput,
268 .pr_init = encap_init,
269 .pr_usrreqs = &rip_usrreqs
273 .pr_domain = &inetdomain,
274 .pr_protocol = IPPROTO_GRE,
275 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
276 .pr_input = encap4_input,
277 .pr_ctloutput = rip_ctloutput,
278 .pr_init = encap_init,
279 .pr_usrreqs = &rip_usrreqs
284 .pr_domain = &inetdomain,
285 .pr_protocol = IPPROTO_IPV6,
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
295 .pr_domain = &inetdomain,
296 .pr_protocol = IPPROTO_PIM,
297 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
298 .pr_input = encap4_input,
299 .pr_ctloutput = rip_ctloutput,
300 .pr_usrreqs = &rip_usrreqs
305 .pr_domain = &inetdomain,
306 .pr_protocol = IPPROTO_PFSYNC,
307 .pr_flags = PR_ATOMIC|PR_ADDR,
308 .pr_input = pfsync_input,
309 .pr_ctloutput = rip_ctloutput,
310 .pr_usrreqs = &rip_usrreqs
312 #endif /* DEV_PFSYNC */
316 .pr_domain = &inetdomain,
317 .pr_protocol = IPPROTO_CARP,
318 .pr_flags = PR_ATOMIC|PR_ADDR,
319 .pr_input = carp_input,
320 .pr_output = (pr_output_t*)rip_output,
321 .pr_ctloutput = rip_ctloutput,
322 .pr_usrreqs = &rip_usrreqs
324 #endif /* DEV_CARP */
325 /* Spacer n-times for loadable protocols. */
337 .pr_domain = &inetdomain,
338 .pr_flags = PR_ATOMIC|PR_ADDR,
339 .pr_input = rip_input,
340 .pr_ctloutput = rip_ctloutput,
342 .pr_usrreqs = &rip_usrreqs
346 extern int in_inithead(void **, int);
348 struct domain inetdomain = {
349 .dom_family = AF_INET,
350 .dom_name = "internet",
351 .dom_protosw = inetsw,
352 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
353 .dom_rtattach = in_inithead,
355 .dom_maxrtkey = sizeof(struct sockaddr_in)
360 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
363 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
364 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
365 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
366 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
368 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
370 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
372 /* XXX no protocol # to use, pick something "reserved" */
373 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
374 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
375 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
376 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
377 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
379 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
381 SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC");
384 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");