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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
34 * $FreeBSD: src/sys/netinet/in_proto.c,v 1.53.2.7 2003/08/24 08:24:38 hsu Exp $
37 #include "opt_ipdivert.h"
39 #include "opt_mrouting.h"
40 #include "opt_ipsec.h"
41 #include "opt_inet6.h"
45 #include <sys/param.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 <netinet/in.h>
57 #include <netinet/in_systm.h>
58 #include <netinet/ip.h>
59 #include <netinet/ip_var.h>
60 #include <netinet/ip_icmp.h>
61 #include <netinet/igmp_var.h>
63 #include <netinet/pim_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>
72 #include <netinet/ip_divert.h>
76 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
80 #include <netinet6/ipsec.h>
81 #include <netinet6/ah.h>
83 #include <netinet6/esp.h>
85 #include <netinet6/ipcomp.h>
89 #include <netproto/ipsec/ipsec.h>
90 #endif /* FAST_IPSEC */
93 #include <netproto/ipx/ipx_ip.h>
97 #include <netinet/in_pcb.h>
98 #include <netinet/sctp_pcb.h>
99 #include <netinet/sctp.h>
100 #include <netinet/sctp_var.h>
103 #include <net/netisr.h> /* for cpu0_soport */
106 #include <netinet/ip_carp.h>
109 extern struct domain inetdomain
;
110 static struct pr_usrreqs nousrreqs
;
112 struct protosw inetsw
[] = {
115 .pr_domain
= &inetdomain
,
123 .pr_slowtimo
= ip_slowtimo
,
124 .pr_drain
= ip_drain
,
125 .pr_usrreqs
= &nousrreqs
128 .pr_type
= SOCK_DGRAM
,
129 .pr_domain
= &inetdomain
,
130 .pr_protocol
= IPPROTO_UDP
,
131 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_MPSAFE
|PR_ASYNC_SEND
,
133 .pr_input
= udp_input
,
135 .pr_ctlinput
= udp_ctlinput
,
136 .pr_ctloutput
= ip_ctloutput
,
138 .pr_ctlport
= udp_ctlport
,
140 .pr_usrreqs
= &udp_usrreqs
143 .pr_type
= SOCK_STREAM
,
144 .pr_domain
= &inetdomain
,
145 .pr_protocol
= IPPROTO_TCP
,
146 .pr_flags
= PR_CONNREQUIRED
|PR_WANTRCVD
|PR_MPSAFE
|PR_ASYNC_SEND
,
148 .pr_input
= tcp_input
,
150 .pr_ctlinput
= tcp_ctlinput
,
151 .pr_ctloutput
= tcp_ctloutput
,
153 .pr_ctlport
= tcp_ctlport
,
157 .pr_drain
= tcp_drain
,
158 .pr_usrreqs
= &tcp_usrreqs
162 * Order is very important here, we add the good one in
163 * in this postion so it maps to the right ip_protox[]
164 * postion for SCTP. Don't move the one above below
165 * this one or IPv6/4 compatability will break
168 .pr_type
= SOCK_DGRAM
,
169 .pr_domain
= &inetdomain
,
170 .pr_protocol
= IPPROTO_SCTP
,
171 .pr_flags
= PR_ADDR_OPT
|PR_WANTRCVD
,
173 .pr_input
= sctp_input
,
175 .pr_ctlinput
= sctp_ctlinput
,
176 .pr_ctloutput
= sctp_ctloutput
,
178 .pr_ctlport
= cpu0_ctlport
,
179 .pr_init
= sctp_init
,
180 .pr_drain
= sctp_drain
,
181 .pr_usrreqs
= &sctp_usrreqs
184 .pr_type
= SOCK_SEQPACKET
,
185 .pr_domain
= &inetdomain
,
186 .pr_protocol
= IPPROTO_SCTP
,
187 .pr_flags
= PR_ADDR_OPT
|PR_WANTRCVD
,
189 .pr_input
= sctp_input
,
191 .pr_ctlinput
= sctp_ctlinput
,
192 .pr_ctloutput
= sctp_ctloutput
,
194 .pr_ctlport
= cpu0_ctlport
,
195 .pr_drain
= sctp_drain
,
196 .pr_usrreqs
= &sctp_usrreqs
200 .pr_type
= SOCK_STREAM
,
201 .pr_domain
= &inetdomain
,
202 .pr_protocol
= IPPROTO_SCTP
,
203 .pr_flags
= PR_CONNREQUIRED
|PR_ADDR_OPT
|PR_WANTRCVD
,
205 .pr_input
= sctp_input
,
207 .pr_ctlinput
= sctp_ctlinput
,
208 .pr_ctloutput
= sctp_ctloutput
,
210 .pr_ctlport
= cpu0_ctlport
,
211 .pr_drain
= sctp_drain
,
212 .pr_usrreqs
= &sctp_usrreqs
217 .pr_domain
= &inetdomain
,
218 .pr_protocol
= IPPROTO_RAW
,
219 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
221 .pr_input
= rip_input
,
223 .pr_ctlinput
= rip_ctlinput
,
224 .pr_ctloutput
= rip_ctloutput
,
226 .pr_ctlport
= cpu0_ctlport
,
227 .pr_usrreqs
= &rip_usrreqs
231 .pr_domain
= &inetdomain
,
232 .pr_protocol
= IPPROTO_ICMP
,
233 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
235 .pr_input
= icmp_input
,
238 .pr_ctloutput
= rip_ctloutput
,
240 .pr_usrreqs
= &rip_usrreqs
244 .pr_domain
= &inetdomain
,
245 .pr_protocol
= IPPROTO_IGMP
,
246 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
248 .pr_input
= igmp_input
,
251 .pr_ctloutput
= rip_ctloutput
,
253 .pr_init
= igmp_init
,
254 .pr_fasttimo
= igmp_fasttimo
,
255 .pr_slowtimo
= igmp_slowtimo
,
257 .pr_usrreqs
= &rip_usrreqs
261 .pr_domain
= &inetdomain
,
262 .pr_protocol
= IPPROTO_RSVP
,
263 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
265 .pr_input
= rsvp_input
,
268 .pr_ctloutput
= rip_ctloutput
,
270 .pr_usrreqs
= &rip_usrreqs
275 .pr_domain
= &inetdomain
,
276 .pr_protocol
= IPPROTO_AH
,
277 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
279 .pr_input
= ah4_input
,
282 .pr_ctloutput
= NULL
,
285 .pr_usrreqs
= &nousrreqs
290 .pr_domain
= &inetdomain
,
291 .pr_protocol
= IPPROTO_ESP
,
292 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
294 .pr_input
= esp4_input
,
297 .pr_ctloutput
= NULL
,
300 .pr_usrreqs
= &nousrreqs
305 .pr_domain
= &inetdomain
,
306 .pr_protocol
= IPPROTO_IPCOMP
,
307 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
309 .pr_input
= ipcomp4_input
,
312 .pr_ctloutput
= NULL
,
315 .pr_usrreqs
= &nousrreqs
321 .pr_domain
= &inetdomain
,
322 .pr_protocol
= IPPROTO_AH
,
323 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
325 .pr_input
= ipsec4_common_input
,
328 .pr_ctloutput
= NULL
,
331 .pr_usrreqs
= &nousrreqs
335 .pr_domain
= &inetdomain
,
336 .pr_protocol
= IPPROTO_ESP
,
337 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
339 .pr_input
= ipsec4_common_input
,
342 .pr_ctloutput
= NULL
,
345 .pr_usrreqs
= &nousrreqs
349 .pr_domain
= &inetdomain
,
350 .pr_protocol
= IPPROTO_IPCOMP
,
351 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
353 .pr_input
= ipsec4_common_input
,
356 .pr_ctloutput
= NULL
,
359 .pr_usrreqs
= &nousrreqs
361 #endif /* FAST_IPSEC */
364 .pr_domain
= &inetdomain
,
365 .pr_protocol
= IPPROTO_IPV4
,
366 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
367 .pr_input
= encap4_input
,
370 .pr_ctloutput
= rip_ctloutput
,
373 .pr_init
= encap_init
,
374 .pr_usrreqs
= &rip_usrreqs
378 .pr_domain
= &inetdomain
,
379 .pr_protocol
= IPPROTO_MOBILE
,
380 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
382 .pr_input
= encap4_input
,
385 .pr_ctloutput
= rip_ctloutput
,
388 .pr_init
= encap_init
,
389 .pr_usrreqs
= &rip_usrreqs
393 .pr_domain
= &inetdomain
,
394 .pr_protocol
= IPPROTO_GRE
,
395 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
397 .pr_input
= encap4_input
,
400 .pr_ctloutput
= rip_ctloutput
,
403 .pr_init
= encap_init
,
404 .pr_usrreqs
= &rip_usrreqs
409 .pr_domain
= &inetdomain
,
410 .pr_protocol
= IPPROTO_IPV6
,
411 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
413 .pr_input
= encap4_input
,
416 .pr_ctloutput
= rip_ctloutput
,
419 .pr_init
= encap_init
,
420 .pr_usrreqs
= &rip_usrreqs
426 .pr_domain
= &inetdomain
,
427 .pr_protocol
= IPPROTO_DIVERT
,
428 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
430 .pr_input
= div_input
,
433 .pr_ctloutput
= ip_ctloutput
,
437 .pr_usrreqs
= &div_usrreqs
443 .pr_domain
= &inetdomain
,
444 .pr_protocol
= IPPROTO_IDP
,
445 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
447 .pr_input
= ipxip_input
,
449 .pr_ctlinput
= ipxip_ctlinput
,
450 .pr_ctloutput
= NULL
,
452 .pr_ctlport
= cpu0_ctlport
,
453 .pr_usrreqs
= &rip_usrreqs
459 .pr_domain
= &inetdomain
,
460 .pr_protocol
= IPPROTO_PIM
,
461 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
463 .pr_input
= pim_input
,
466 .pr_ctloutput
= rip_ctloutput
,
469 .pr_usrreqs
= &rip_usrreqs
475 .pr_domain
= &inetdomain
,
476 .pr_protocol
= IPPROTO_PFSYNC
,
477 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
479 .pr_input
= pfsync_input
,
482 .pr_ctloutput
= rip_ctloutput
,
485 .pr_usrreqs
= &rip_usrreqs
491 .pr_domain
= &inetdomain
,
493 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
495 .pr_input
= rip_input
,
498 .pr_ctloutput
= rip_ctloutput
,
502 .pr_usrreqs
= &rip_usrreqs
507 .pr_domain
= &inetdomain
,
508 .pr_protocol
= IPPROTO_CARP
,
509 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_MPSAFE
,
511 .pr_input
= carp_proto_input
,
512 .pr_output
= rip_output
,
513 .pr_ctlinput
= carp_proto_ctlinput
,
514 .pr_ctloutput
= rip_ctloutput
,
516 .pr_ctlport
= cpu0_ctlport
,
517 .pr_usrreqs
= &rip_usrreqs
522 struct domain inetdomain
= {
523 AF_INET
, "internet", NULL
, NULL
, NULL
,
524 inetsw
, &inetsw
[NELEM(inetsw
)],
525 SLIST_ENTRY_INITIALIZER
,
526 in_inithead
, 32, sizeof(struct sockaddr_in
),
531 SYSCTL_NODE(_net
, PF_INET
, inet
, CTLFLAG_RW
, 0,
534 SYSCTL_NODE(_net_inet
, IPPROTO_IP
, ip
, CTLFLAG_RW
, 0, "IP");
535 SYSCTL_NODE(_net_inet
, IPPROTO_ICMP
, icmp
, CTLFLAG_RW
, 0, "ICMP");
536 SYSCTL_NODE(_net_inet
, IPPROTO_UDP
, udp
, CTLFLAG_RW
, 0, "UDP");
537 SYSCTL_NODE(_net_inet
, IPPROTO_TCP
, tcp
, CTLFLAG_RW
, 0, "TCP");
538 SYSCTL_NODE(_net_inet
, IPPROTO_IGMP
, igmp
, CTLFLAG_RW
, 0, "IGMP");
540 /* XXX no protocol # to use, pick something "reserved" */
541 SYSCTL_NODE(_net_inet
, 253, ipsec
, CTLFLAG_RW
, 0, "IPSEC");
542 SYSCTL_NODE(_net_inet
, IPPROTO_AH
, ah
, CTLFLAG_RW
, 0, "AH");
543 SYSCTL_NODE(_net_inet
, IPPROTO_ESP
, esp
, CTLFLAG_RW
, 0, "ESP");
544 SYSCTL_NODE(_net_inet
, IPPROTO_IPCOMP
, ipcomp
, CTLFLAG_RW
, 0, "IPCOMP");
545 SYSCTL_NODE(_net_inet
, IPPROTO_IPIP
, ipip
, CTLFLAG_RW
, 0, "IPIP");
548 SYSCTL_NODE(_net_inet
, IPPROTO_AH
, ipsec
, CTLFLAG_RW
, 0, "IPSEC");
550 #endif /* !FAST_IPSEC */
551 SYSCTL_NODE(_net_inet
, IPPROTO_RAW
, raw
, CTLFLAG_RW
, 0, "RAW");
553 SYSCTL_NODE(_net_inet
, IPPROTO_DIVERT
, divert
, CTLFLAG_RW
, 0, "DIVERT");
556 SYSCTL_NODE(_net_inet
, IPPROTO_PIM
, pim
, CTLFLAG_RW
, 0, "PIM");
559 SYSCTL_NODE(_net_inet
, IPPROTO_CARP
, carp
, CTLFLAG_RW
, 0, "CARP");