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 * 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
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_ipsec.h"
36 #include "opt_inet6.h"
40 #include <sys/param.h>
41 #include <sys/kernel.h>
42 #include <sys/socket.h>
43 #include <sys/domain.h>
44 #include <sys/protosw.h>
45 #include <sys/queue.h>
46 #include <sys/sysctl.h>
49 #include <net/route.h>
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/in_pcb.h>
54 #include <netinet/ip.h>
55 #include <netinet/ip_var.h>
56 #include <netinet/ip_icmp.h>
57 #include <netinet/igmp_var.h>
59 #include <netinet/pim_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>
68 #include <netinet/ip_divert.h>
72 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
76 #include <netinet6/ipsec.h>
77 #include <netinet6/ah.h>
79 #include <netinet6/esp.h>
81 #include <netinet6/ipcomp.h>
85 #include <netproto/ipsec/ipsec.h>
86 #endif /* FAST_IPSEC */
89 #include <netinet/sctp_pcb.h>
90 #include <netinet/sctp.h>
91 #include <netinet/sctp_var.h>
94 #include <net/netisr.h> /* for cpu0_soport */
97 #include <netinet/ip_carp.h>
100 extern struct domain inetdomain;
101 static struct pr_usrreqs nousrreqs;
103 struct protosw inetsw[] = {
106 .pr_domain = &inetdomain,
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|PR_MPSAFE|
123 PR_ASYNC_SEND|PR_ASEND_HOLDTD,
125 .pr_initport = udp_initport,
126 .pr_input = udp_input,
128 .pr_ctlinput = udp_ctlinput,
129 .pr_ctloutput = udp_ctloutput,
131 .pr_ctlport = udp_ctlport,
133 .pr_usrreqs = &udp_usrreqs
136 .pr_type = SOCK_STREAM,
137 .pr_domain = &inetdomain,
138 .pr_protocol = IPPROTO_TCP,
139 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_MPSAFE|
140 PR_ASYNC_SEND|PR_ASYNC_RCVD|PR_ACONN_HOLDTD,
142 .pr_initport = tcp_initport,
143 .pr_input = tcp_input,
145 .pr_ctlinput = tcp_ctlinput,
146 .pr_ctloutput = tcp_ctloutput,
148 .pr_ctlport = tcp_ctlport,
152 .pr_drain = tcp_drain,
153 .pr_usrreqs = &tcp_usrreqs
157 * Order is very important here, we add the good one in
158 * in this postion so it maps to the right ip_protox[]
159 * postion for SCTP. Don't move the one above below
160 * this one or IPv6/4 compatability will break
163 .pr_type = SOCK_DGRAM,
164 .pr_domain = &inetdomain,
165 .pr_protocol = IPPROTO_SCTP,
166 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
168 .pr_input = sctp_input,
170 .pr_ctlinput = sctp_ctlinput,
171 .pr_ctloutput = sctp_ctloutput,
173 .pr_ctlport = cpu0_ctlport,
174 .pr_init = sctp_init,
175 .pr_drain = sctp_drain,
176 .pr_usrreqs = &sctp_usrreqs
179 .pr_type = SOCK_SEQPACKET,
180 .pr_domain = &inetdomain,
181 .pr_protocol = IPPROTO_SCTP,
182 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
184 .pr_input = sctp_input,
186 .pr_ctlinput = sctp_ctlinput,
187 .pr_ctloutput = sctp_ctloutput,
189 .pr_ctlport = cpu0_ctlport,
190 .pr_drain = sctp_drain,
191 .pr_usrreqs = &sctp_usrreqs
195 .pr_type = SOCK_STREAM,
196 .pr_domain = &inetdomain,
197 .pr_protocol = IPPROTO_SCTP,
198 .pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD,
200 .pr_input = sctp_input,
202 .pr_ctlinput = sctp_ctlinput,
203 .pr_ctloutput = sctp_ctloutput,
205 .pr_ctlport = cpu0_ctlport,
206 .pr_drain = sctp_drain,
207 .pr_usrreqs = &sctp_usrreqs
212 .pr_domain = &inetdomain,
213 .pr_protocol = IPPROTO_RAW,
214 .pr_flags = PR_ATOMIC|PR_ADDR,
216 .pr_input = rip_input,
218 .pr_ctlinput = rip_ctlinput,
219 .pr_ctloutput = rip_ctloutput,
221 .pr_ctlport = cpu0_ctlport,
222 .pr_usrreqs = &rip_usrreqs
226 .pr_domain = &inetdomain,
227 .pr_protocol = IPPROTO_ICMP,
228 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
230 .pr_input = icmp_input,
233 .pr_ctloutput = rip_ctloutput,
235 .pr_usrreqs = &rip_usrreqs
239 .pr_domain = &inetdomain,
240 .pr_protocol = IPPROTO_IGMP,
241 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
243 .pr_input = igmp_input,
246 .pr_ctloutput = rip_ctloutput,
248 .pr_init = igmp_init,
249 .pr_fasttimo = igmp_fasttimo,
250 .pr_slowtimo = igmp_slowtimo,
252 .pr_usrreqs = &rip_usrreqs
256 .pr_domain = &inetdomain,
257 .pr_protocol = IPPROTO_RSVP,
258 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
260 .pr_input = rsvp_input,
263 .pr_ctloutput = rip_ctloutput,
265 .pr_usrreqs = &rip_usrreqs
270 .pr_domain = &inetdomain,
271 .pr_protocol = IPPROTO_AH,
272 .pr_flags = PR_ATOMIC|PR_ADDR,
274 .pr_input = ah4_input,
277 .pr_ctloutput = NULL,
280 .pr_usrreqs = &nousrreqs
285 .pr_domain = &inetdomain,
286 .pr_protocol = IPPROTO_ESP,
287 .pr_flags = PR_ATOMIC|PR_ADDR,
289 .pr_input = esp4_input,
292 .pr_ctloutput = NULL,
295 .pr_usrreqs = &nousrreqs
300 .pr_domain = &inetdomain,
301 .pr_protocol = IPPROTO_IPCOMP,
302 .pr_flags = PR_ATOMIC|PR_ADDR,
304 .pr_input = ipcomp4_input,
307 .pr_ctloutput = NULL,
310 .pr_usrreqs = &nousrreqs
316 .pr_domain = &inetdomain,
317 .pr_protocol = IPPROTO_AH,
318 .pr_flags = PR_ATOMIC|PR_ADDR,
320 .pr_input = ipsec4_common_input,
323 .pr_ctloutput = NULL,
326 .pr_usrreqs = &nousrreqs
330 .pr_domain = &inetdomain,
331 .pr_protocol = IPPROTO_ESP,
332 .pr_flags = PR_ATOMIC|PR_ADDR,
334 .pr_input = ipsec4_common_input,
337 .pr_ctloutput = NULL,
340 .pr_usrreqs = &nousrreqs
344 .pr_domain = &inetdomain,
345 .pr_protocol = IPPROTO_IPCOMP,
346 .pr_flags = PR_ATOMIC|PR_ADDR,
348 .pr_input = ipsec4_common_input,
351 .pr_ctloutput = NULL,
354 .pr_usrreqs = &nousrreqs
356 #endif /* FAST_IPSEC */
359 .pr_domain = &inetdomain,
360 .pr_protocol = IPPROTO_IPV4,
361 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
362 .pr_input = encap4_input,
365 .pr_ctloutput = rip_ctloutput,
368 .pr_init = encap_init,
369 .pr_usrreqs = &rip_usrreqs
373 .pr_domain = &inetdomain,
374 .pr_protocol = IPPROTO_MOBILE,
375 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
377 .pr_input = encap4_input,
380 .pr_ctloutput = rip_ctloutput,
383 .pr_init = encap_init,
384 .pr_usrreqs = &rip_usrreqs
388 .pr_domain = &inetdomain,
389 .pr_protocol = IPPROTO_GRE,
390 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
392 .pr_input = encap4_input,
395 .pr_ctloutput = rip_ctloutput,
398 .pr_init = encap_init,
399 .pr_usrreqs = &rip_usrreqs
404 .pr_domain = &inetdomain,
405 .pr_protocol = IPPROTO_IPV6,
406 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
408 .pr_input = encap4_input,
411 .pr_ctloutput = rip_ctloutput,
414 .pr_init = encap_init,
415 .pr_usrreqs = &rip_usrreqs
421 .pr_domain = &inetdomain,
422 .pr_protocol = IPPROTO_DIVERT,
423 .pr_flags = PR_ATOMIC|PR_ADDR,
425 .pr_input = div_input,
428 .pr_ctloutput = ip_ctloutput,
432 .pr_usrreqs = &div_usrreqs
438 .pr_domain = &inetdomain,
439 .pr_protocol = IPPROTO_PIM,
440 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
442 .pr_input = pim_input,
445 .pr_ctloutput = rip_ctloutput,
448 .pr_usrreqs = &rip_usrreqs
454 .pr_domain = &inetdomain,
455 .pr_protocol = IPPROTO_PFSYNC,
456 .pr_flags = PR_ATOMIC|PR_ADDR,
458 .pr_input = pfsync_input,
461 .pr_ctloutput = rip_ctloutput,
464 .pr_usrreqs = &rip_usrreqs
470 .pr_domain = &inetdomain,
472 .pr_flags = PR_ATOMIC|PR_ADDR,
474 .pr_input = rip_input,
477 .pr_ctloutput = rip_ctloutput,
481 .pr_usrreqs = &rip_usrreqs
486 .pr_domain = &inetdomain,
487 .pr_protocol = IPPROTO_CARP,
488 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
490 .pr_input = carp_proto_input,
491 .pr_output = rip_output,
492 .pr_ctlinput = carp_proto_ctlinput,
493 .pr_ctloutput = rip_ctloutput,
495 .pr_ctlport = cpu0_ctlport,
496 .pr_usrreqs = &rip_usrreqs
502 inetdomain_init(void)
507 struct domain inetdomain = {
508 AF_INET, "internet", inetdomain_init, NULL, NULL,
509 inetsw, &inetsw[NELEM(inetsw)],
510 SLIST_ENTRY_INITIALIZER,
511 in_inithead, 32, sizeof(struct sockaddr_in),
516 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
519 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
520 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
521 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
522 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
523 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
525 /* XXX no protocol # to use, pick something "reserved" */
526 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
527 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
528 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
529 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
530 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
533 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
535 #endif /* !FAST_IPSEC */
536 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
538 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
541 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
544 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");