kernel: Clean up the warning flags a bit.
[dragonfly.git] / sys / netinet / in_proto.c
blob8f2372ed1807aff574ee95c0c06a7f65f6d7f884
1 /*
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
7 * are met:
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 * 3. 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
27 * SUCH DAMAGE.
29 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
30 * $FreeBSD: src/sys/netinet/in_proto.c,v 1.53.2.7 2003/08/24 08:24:38 hsu Exp $
33 #include "opt_ipdivert.h"
34 #include "opt_mrouting.h"
35 #include "opt_inet6.h"
36 #include "opt_carp.h"
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/socket.h>
41 #include <sys/domain.h>
42 #include <sys/protosw.h>
43 #include <sys/queue.h>
44 #include <sys/sysctl.h>
46 #include <net/if.h>
47 #include <net/route.h>
49 #include <netinet/in.h>
50 #include <netinet/in_systm.h>
51 #include <netinet/in_pcb.h>
52 #include <netinet/ip.h>
53 #include <netinet/ip_var.h>
54 #include <netinet/ip_icmp.h>
55 #include <netinet/igmp_var.h>
56 #ifdef PIM
57 #include <netinet/pim_var.h>
58 #endif
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>
65 #ifdef IPDIVERT
66 #include <netinet/ip_divert.h>
67 #endif
70 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
73 #include <net/netisr.h> /* for cpu0_soport */
75 #ifdef CARP
76 #include <netinet/ip_carp.h>
77 #endif
79 extern struct domain inetdomain;
80 static struct pr_usrreqs nousrreqs;
82 struct protosw inetsw[] = {
84 .pr_type = 0,
85 .pr_domain = &inetdomain,
86 .pr_protocol = 0,
87 .pr_flags = 0,
89 .pr_ctlport = NULL,
91 .pr_init = ip_init,
92 .pr_drain = ip_drain,
93 .pr_usrreqs = &nousrreqs
96 .pr_type = SOCK_DGRAM,
97 .pr_domain = &inetdomain,
98 .pr_protocol = IPPROTO_UDP,
99 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE|
100 PR_ASYNC_SEND|PR_ASEND_HOLDTD|PR_ACONN_HOLDTD,
102 .pr_initport = udp_initport,
103 .pr_input = udp_input,
104 .pr_output = NULL,
105 .pr_ctlinput = udp_ctlinput,
106 .pr_ctloutput = udp_ctloutput,
108 .pr_ctlport = udp_ctlport,
109 .pr_init = udp_init,
110 .pr_usrreqs = &udp_usrreqs
113 .pr_type = SOCK_STREAM,
114 .pr_domain = &inetdomain,
115 .pr_protocol = IPPROTO_TCP,
116 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_MPSAFE|
117 PR_ASYNC_SEND|PR_ASYNC_RCVD|PR_ACONN_HOLDTD,
119 .pr_initport = tcp_initport,
120 .pr_input = tcp_input,
121 .pr_output = NULL,
122 .pr_ctlinput = tcp_ctlinput,
123 .pr_ctloutmsg = tcp_ctloutmsg,
124 .pr_ctloutput = tcp_ctloutput,
126 .pr_ctlport = tcp_ctlport,
127 .pr_init = tcp_init,
128 .pr_drain = tcp_drain,
129 .pr_usrreqs = &tcp_usrreqs
132 .pr_type = SOCK_RAW,
133 .pr_domain = &inetdomain,
134 .pr_protocol = IPPROTO_RAW,
135 .pr_flags = PR_ATOMIC|PR_ADDR,
137 .pr_input = rip_input,
138 .pr_output = NULL,
139 .pr_ctlinput = rip_ctlinput,
140 .pr_ctloutput = rip_ctloutput,
142 .pr_ctlport = cpu0_ctlport,
143 .pr_usrreqs = &rip_usrreqs
146 .pr_type = SOCK_RAW,
147 .pr_domain = &inetdomain,
148 .pr_protocol = IPPROTO_ICMP,
149 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
151 .pr_input = icmp_input,
152 .pr_output = NULL,
153 .pr_ctlinput = NULL,
154 .pr_ctloutput = rip_ctloutput,
156 .pr_usrreqs = &rip_usrreqs
159 .pr_type = SOCK_RAW,
160 .pr_domain = &inetdomain,
161 .pr_protocol = IPPROTO_IGMP,
162 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
164 .pr_input = igmp_input,
165 .pr_output = NULL,
166 .pr_ctlinput = NULL,
167 .pr_ctloutput = rip_ctloutput,
169 .pr_init = igmp_init,
170 .pr_drain = NULL,
171 .pr_usrreqs = &rip_usrreqs
174 .pr_type = SOCK_RAW,
175 .pr_domain = &inetdomain,
176 .pr_protocol = IPPROTO_RSVP,
177 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
179 .pr_input = rsvp_input,
180 .pr_output = NULL,
181 .pr_ctlinput = NULL,
182 .pr_ctloutput = rip_ctloutput,
184 .pr_usrreqs = &rip_usrreqs
187 .pr_type = SOCK_RAW,
188 .pr_domain = &inetdomain,
189 .pr_protocol = IPPROTO_IPV4,
190 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
191 .pr_input = encap4_input,
192 .pr_output = NULL,
193 .pr_ctlinput = NULL,
194 .pr_ctloutput = rip_ctloutput,
196 .pr_ctlport = NULL,
197 .pr_init = encap_init,
198 .pr_usrreqs = &rip_usrreqs
201 .pr_type = SOCK_RAW,
202 .pr_domain = &inetdomain,
203 .pr_protocol = IPPROTO_MOBILE,
204 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
206 .pr_input = encap4_input,
207 .pr_output = NULL,
208 .pr_ctlinput = NULL,
209 .pr_ctloutput = rip_ctloutput,
211 .pr_ctlport = NULL,
212 .pr_init = encap_init,
213 .pr_usrreqs = &rip_usrreqs
216 .pr_type = SOCK_RAW,
217 .pr_domain = &inetdomain,
218 .pr_protocol = IPPROTO_GRE,
219 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
221 .pr_input = encap4_input,
222 .pr_output = NULL,
223 .pr_ctlinput = NULL,
224 .pr_ctloutput = rip_ctloutput,
226 .pr_ctlport = NULL,
227 .pr_init = encap_init,
228 .pr_usrreqs = &rip_usrreqs
230 #ifdef INET6
232 .pr_type = SOCK_RAW,
233 .pr_domain = &inetdomain,
234 .pr_protocol = IPPROTO_IPV6,
235 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
237 .pr_input = encap4_input,
238 .pr_output = NULL,
239 .pr_ctlinput = NULL,
240 .pr_ctloutput = rip_ctloutput,
242 .pr_ctlport = NULL,
243 .pr_init = encap_init,
244 .pr_usrreqs = &rip_usrreqs
246 #endif
247 #ifdef IPDIVERT
249 .pr_type = SOCK_RAW,
250 .pr_domain = &inetdomain,
251 .pr_protocol = IPPROTO_DIVERT,
252 .pr_flags = PR_ATOMIC|PR_ADDR,
254 .pr_input = div_input,
255 .pr_output = NULL,
256 .pr_ctlinput = NULL,
257 .pr_ctloutput = ip_ctloutput,
259 .pr_ctlport = NULL,
260 .pr_init = div_init,
261 .pr_usrreqs = &div_usrreqs
263 #endif
264 #ifdef PIM
266 .pr_type = SOCK_RAW,
267 .pr_domain = &inetdomain,
268 .pr_protocol = IPPROTO_PIM,
269 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
271 .pr_input = pim_input,
272 .pr_output = NULL,
273 .pr_ctlinput = NULL,
274 .pr_ctloutput = rip_ctloutput,
276 .pr_ctlport = NULL,
277 .pr_usrreqs = &rip_usrreqs
279 #endif
280 #ifdef NPFSYNC
282 .pr_type = SOCK_RAW,
283 .pr_domain = &inetdomain,
284 .pr_protocol = IPPROTO_PFSYNC,
285 .pr_flags = PR_ATOMIC|PR_ADDR,
287 .pr_input = pfsync_input,
288 .pr_output = NULL,
289 .pr_ctlinput = NULL,
290 .pr_ctloutput = rip_ctloutput,
292 .pr_ctlport = NULL,
293 .pr_usrreqs = &rip_usrreqs
295 #endif /* NPFSYNC */
297 /* raw wildcard */
298 .pr_type = SOCK_RAW,
299 .pr_domain = &inetdomain,
300 .pr_protocol = 0,
301 .pr_flags = PR_ATOMIC|PR_ADDR,
303 .pr_input = rip_input,
304 .pr_output = NULL,
305 .pr_ctlinput = NULL,
306 .pr_ctloutput = rip_ctloutput,
308 .pr_init = rip_init,
309 .pr_ctlport = NULL,
310 .pr_usrreqs = &rip_usrreqs
312 #ifdef CARP
314 .pr_type = SOCK_RAW,
315 .pr_domain = &inetdomain,
316 .pr_protocol = IPPROTO_CARP,
317 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
319 .pr_input = carp_proto_input,
320 .pr_output = rip_output,
321 .pr_ctlinput = carp_proto_ctlinput,
322 .pr_ctloutput = rip_ctloutput,
324 .pr_ctlport = cpu0_ctlport,
325 .pr_usrreqs = &rip_usrreqs
327 #endif
330 static void
331 inetdomain_init(void)
333 in_pcbglobalinit();
336 struct domain inetdomain = {
337 .dom_family = AF_INET,
338 .dom_name = "internet",
339 .dom_init = inetdomain_init,
340 .dom_externalize = NULL,
341 .dom_dispose = NULL,
342 .dom_protosw = inetsw,
343 .dom_protoswNPROTOSW = &inetsw[NELEM(inetsw)],
344 .dom_next = SLIST_ENTRY_INITIALIZER,
345 .dom_rtattach = in_inithead,
346 .dom_rtoffset = 32,
347 .dom_maxrtkey = sizeof(struct sockaddr_in),
348 .dom_ifattach = NULL,
349 .dom_ifdetach = NULL
352 DOMAIN_SET(inet);
354 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
355 "Internet Family");
357 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
358 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
359 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
360 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
361 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
362 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
363 #ifdef IPDIVERT
364 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
365 #endif
366 #ifdef PIM
367 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
368 #endif
369 #ifdef CARP
370 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");
371 #endif