dhcpcd: update README.DRAGONFLY
[dragonfly.git] / sys / netinet / in_proto.c
blob1d927c556ce17763a895af5a872486ca9d0cfa3c
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/in_var.h>
53 #include <netinet/ip.h>
54 #include <netinet/ip_var.h>
55 #include <netinet/ip_icmp.h>
56 #include <netinet/igmp_var.h>
57 #ifdef PIM
58 #include <netinet/pim_var.h>
59 #endif
60 #include <netinet/tcp.h>
61 #include <netinet/tcp_timer.h>
62 #include <netinet/tcp_var.h>
63 #include <netinet/udp.h>
64 #include <netinet/udp_var.h>
65 #include <netinet/ip_encap.h>
66 #ifdef IPDIVERT
67 #include <netinet/ip_divert.h>
68 #endif
71 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
74 #include <net/netisr.h> /* for cpu0_soport */
76 #ifdef CARP
77 #include <netinet/ip_carp.h>
78 #endif
80 extern struct domain inetdomain;
81 static struct pr_usrreqs nousrreqs;
83 struct protosw inetsw[] = {
85 .pr_type = 0,
86 .pr_domain = &inetdomain,
87 .pr_protocol = 0,
88 .pr_flags = 0,
90 .pr_ctlport = NULL,
92 .pr_init = ip_init,
93 .pr_drain = ip_drain,
94 .pr_usrreqs = &nousrreqs
97 .pr_type = SOCK_DGRAM,
98 .pr_domain = &inetdomain,
99 .pr_protocol = IPPROTO_UDP,
100 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE|
101 PR_ASYNC_SEND|PR_ASEND_HOLDTD|PR_ACONN_HOLDTD,
103 .pr_initport = udp_initport,
104 .pr_input = udp_input,
105 .pr_output = NULL,
106 .pr_ctlinput = udp_ctlinput,
107 .pr_ctloutput = udp_ctloutput,
109 .pr_ctlport = udp_ctlport,
110 .pr_init = udp_init,
111 .pr_usrreqs = &udp_usrreqs
114 .pr_type = SOCK_STREAM,
115 .pr_domain = &inetdomain,
116 .pr_protocol = IPPROTO_TCP,
117 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_MPSAFE|
118 PR_ASYNC_SEND|PR_ASYNC_RCVD|PR_ACONN_HOLDTD,
120 .pr_initport = tcp_initport,
121 .pr_input = tcp_input,
122 .pr_output = NULL,
123 .pr_ctlinput = tcp_ctlinput,
124 .pr_ctloutmsg = tcp_ctloutmsg,
125 .pr_ctloutput = tcp_ctloutput,
127 .pr_ctlport = tcp_ctlport,
128 .pr_init = tcp_init,
129 .pr_drain = tcp_drain,
130 .pr_usrreqs = &tcp_usrreqs
133 .pr_type = SOCK_RAW,
134 .pr_domain = &inetdomain,
135 .pr_protocol = IPPROTO_RAW,
136 .pr_flags = PR_ATOMIC|PR_ADDR,
138 .pr_input = rip_input,
139 .pr_output = NULL,
140 .pr_ctlinput = NULL,
141 .pr_ctloutput = rip_ctloutput,
143 .pr_ctlport = NULL,
144 .pr_usrreqs = &rip_usrreqs
147 .pr_type = SOCK_RAW,
148 .pr_domain = &inetdomain,
149 .pr_protocol = IPPROTO_ICMP,
150 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
152 .pr_input = icmp_input,
153 .pr_output = NULL,
154 .pr_ctlinput = NULL,
155 .pr_ctloutput = rip_ctloutput,
157 .pr_usrreqs = &rip_usrreqs
160 .pr_type = SOCK_RAW,
161 .pr_domain = &inetdomain,
162 .pr_protocol = IPPROTO_IGMP,
163 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
165 .pr_input = igmp_input,
166 .pr_output = NULL,
167 .pr_ctlinput = NULL,
168 .pr_ctloutput = rip_ctloutput,
170 .pr_init = igmp_init,
171 .pr_drain = NULL,
172 .pr_usrreqs = &rip_usrreqs
175 .pr_type = SOCK_RAW,
176 .pr_domain = &inetdomain,
177 .pr_protocol = IPPROTO_RSVP,
178 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
180 .pr_input = rsvp_input,
181 .pr_output = NULL,
182 .pr_ctlinput = NULL,
183 .pr_ctloutput = rip_ctloutput,
185 .pr_usrreqs = &rip_usrreqs
188 .pr_type = SOCK_RAW,
189 .pr_domain = &inetdomain,
190 .pr_protocol = IPPROTO_IPV4,
191 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
192 .pr_input = encap4_input,
193 .pr_output = NULL,
194 .pr_ctlinput = NULL,
195 .pr_ctloutput = rip_ctloutput,
197 .pr_ctlport = NULL,
198 .pr_init = encap_init,
199 .pr_usrreqs = &rip_usrreqs
202 .pr_type = SOCK_RAW,
203 .pr_domain = &inetdomain,
204 .pr_protocol = IPPROTO_MOBILE,
205 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
207 .pr_input = encap4_input,
208 .pr_output = NULL,
209 .pr_ctlinput = NULL,
210 .pr_ctloutput = rip_ctloutput,
212 .pr_ctlport = NULL,
213 .pr_init = encap_init,
214 .pr_usrreqs = &rip_usrreqs
217 .pr_type = SOCK_RAW,
218 .pr_domain = &inetdomain,
219 .pr_protocol = IPPROTO_GRE,
220 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
222 .pr_input = encap4_input,
223 .pr_output = NULL,
224 .pr_ctlinput = NULL,
225 .pr_ctloutput = rip_ctloutput,
227 .pr_ctlport = NULL,
228 .pr_init = encap_init,
229 .pr_usrreqs = &rip_usrreqs
231 #ifdef INET6
233 .pr_type = SOCK_RAW,
234 .pr_domain = &inetdomain,
235 .pr_protocol = IPPROTO_IPV6,
236 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
238 .pr_input = encap4_input,
239 .pr_output = NULL,
240 .pr_ctlinput = NULL,
241 .pr_ctloutput = rip_ctloutput,
243 .pr_ctlport = NULL,
244 .pr_init = encap_init,
245 .pr_usrreqs = &rip_usrreqs
247 #endif
248 #ifdef IPDIVERT
250 .pr_type = SOCK_RAW,
251 .pr_domain = &inetdomain,
252 .pr_protocol = IPPROTO_DIVERT,
253 .pr_flags = PR_ATOMIC|PR_ADDR,
255 .pr_input = div_input,
256 .pr_output = NULL,
257 .pr_ctlinput = NULL,
258 .pr_ctloutput = ip_ctloutput,
260 .pr_ctlport = NULL,
261 .pr_init = div_init,
262 .pr_usrreqs = &div_usrreqs
264 #endif
265 #ifdef PIM
267 .pr_type = SOCK_RAW,
268 .pr_domain = &inetdomain,
269 .pr_protocol = IPPROTO_PIM,
270 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
272 .pr_input = pim_input,
273 .pr_output = NULL,
274 .pr_ctlinput = NULL,
275 .pr_ctloutput = rip_ctloutput,
277 .pr_ctlport = NULL,
278 .pr_usrreqs = &rip_usrreqs
280 #endif
281 #ifdef NPFSYNC
283 .pr_type = SOCK_RAW,
284 .pr_domain = &inetdomain,
285 .pr_protocol = IPPROTO_PFSYNC,
286 .pr_flags = PR_ATOMIC|PR_ADDR,
288 .pr_input = pfsync_input,
289 .pr_output = NULL,
290 .pr_ctlinput = NULL,
291 .pr_ctloutput = rip_ctloutput,
293 .pr_ctlport = NULL,
294 .pr_usrreqs = &rip_usrreqs
296 #endif /* NPFSYNC */
298 /* raw wildcard */
299 .pr_type = SOCK_RAW,
300 .pr_domain = &inetdomain,
301 .pr_protocol = 0,
302 .pr_flags = PR_ATOMIC|PR_ADDR,
304 .pr_input = rip_input,
305 .pr_output = NULL,
306 .pr_ctlinput = NULL,
307 .pr_ctloutput = rip_ctloutput,
309 .pr_init = rip_init,
310 .pr_ctlport = NULL,
311 .pr_usrreqs = &rip_usrreqs
313 #ifdef CARP
315 .pr_type = SOCK_RAW,
316 .pr_domain = &inetdomain,
317 .pr_protocol = IPPROTO_CARP,
318 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
320 .pr_input = carp_proto_input,
321 .pr_output = rip_output,
322 .pr_ctlinput = carp_proto_ctlinput,
323 .pr_ctloutput = rip_ctloutput,
325 .pr_ctlport = cpu0_ctlport,
326 .pr_usrreqs = &rip_usrreqs
328 #endif
331 static void
332 inetdomain_init(void)
334 in_pcbglobalinit();
337 struct domain inetdomain = {
338 .dom_family = AF_INET,
339 .dom_name = "internet",
340 .dom_init = inetdomain_init,
341 .dom_externalize = NULL,
342 .dom_dispose = NULL,
343 .dom_protosw = inetsw,
344 .dom_protoswNPROTOSW = &inetsw[NELEM(inetsw)],
345 .dom_next = SLIST_ENTRY_INITIALIZER,
346 .dom_rtattach = in_inithead,
347 .dom_rtoffset = offsetof(struct sockaddr_in, sin_addr),
348 .dom_maxrtkey = sizeof(struct sockaddr_in),
349 .dom_ifattach = NULL,
350 .dom_ifdetach = NULL,
351 .dom_if_up = NULL,
352 .dom_if_down = in_if_down
355 DOMAIN_SET(inet);
357 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
358 "Internet Family");
360 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
361 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
362 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
363 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
364 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
365 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
366 #ifdef IPDIVERT
367 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
368 #endif
369 #ifdef PIM
370 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
371 #endif
372 #ifdef CARP
373 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");
374 #endif