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_inet6.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>
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>
58 #include <netinet/pim_var.h>
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>
67 #include <netinet/ip_divert.h>
71 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
74 #include <net/netisr.h> /* for cpu0_soport */
77 #include <netinet/ip_carp.h>
80 extern struct domain inetdomain
;
81 static struct pr_usrreqs nousrreqs
;
83 struct protosw inetsw
[] = {
86 .pr_domain
= &inetdomain
,
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
,
106 .pr_ctlinput
= udp_ctlinput
,
107 .pr_ctloutput
= udp_ctloutput
,
109 .pr_ctlport
= udp_ctlport
,
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
,
123 .pr_ctlinput
= tcp_ctlinput
,
124 .pr_ctloutmsg
= tcp_ctloutmsg
,
125 .pr_ctloutput
= tcp_ctloutput
,
127 .pr_ctlport
= tcp_ctlport
,
129 .pr_drain
= tcp_drain
,
130 .pr_usrreqs
= &tcp_usrreqs
134 .pr_domain
= &inetdomain
,
135 .pr_protocol
= IPPROTO_RAW
,
136 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
138 .pr_input
= rip_input
,
141 .pr_ctloutput
= rip_ctloutput
,
144 .pr_usrreqs
= &rip_usrreqs
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
,
155 .pr_ctloutput
= rip_ctloutput
,
157 .pr_usrreqs
= &rip_usrreqs
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
,
168 .pr_ctloutput
= rip_ctloutput
,
170 .pr_init
= igmp_init
,
172 .pr_usrreqs
= &rip_usrreqs
176 .pr_domain
= &inetdomain
,
177 .pr_protocol
= IPPROTO_RSVP
,
178 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
180 .pr_input
= rsvp_input
,
183 .pr_ctloutput
= rip_ctloutput
,
185 .pr_usrreqs
= &rip_usrreqs
189 .pr_domain
= &inetdomain
,
190 .pr_protocol
= IPPROTO_IPV4
,
191 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
192 .pr_input
= encap4_input
,
195 .pr_ctloutput
= rip_ctloutput
,
198 .pr_init
= encap_init
,
199 .pr_usrreqs
= &rip_usrreqs
203 .pr_domain
= &inetdomain
,
204 .pr_protocol
= IPPROTO_MOBILE
,
205 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
207 .pr_input
= encap4_input
,
210 .pr_ctloutput
= rip_ctloutput
,
213 .pr_init
= encap_init
,
214 .pr_usrreqs
= &rip_usrreqs
218 .pr_domain
= &inetdomain
,
219 .pr_protocol
= IPPROTO_GRE
,
220 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
222 .pr_input
= encap4_input
,
225 .pr_ctloutput
= rip_ctloutput
,
228 .pr_init
= encap_init
,
229 .pr_usrreqs
= &rip_usrreqs
234 .pr_domain
= &inetdomain
,
235 .pr_protocol
= IPPROTO_IPV6
,
236 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
238 .pr_input
= encap4_input
,
241 .pr_ctloutput
= rip_ctloutput
,
244 .pr_init
= encap_init
,
245 .pr_usrreqs
= &rip_usrreqs
251 .pr_domain
= &inetdomain
,
252 .pr_protocol
= IPPROTO_DIVERT
,
253 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
255 .pr_input
= div_input
,
258 .pr_ctloutput
= ip_ctloutput
,
262 .pr_usrreqs
= &div_usrreqs
268 .pr_domain
= &inetdomain
,
269 .pr_protocol
= IPPROTO_PIM
,
270 .pr_flags
= PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
272 .pr_input
= pim_input
,
275 .pr_ctloutput
= rip_ctloutput
,
278 .pr_usrreqs
= &rip_usrreqs
284 .pr_domain
= &inetdomain
,
285 .pr_protocol
= IPPROTO_PFSYNC
,
286 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
288 .pr_input
= pfsync_input
,
291 .pr_ctloutput
= rip_ctloutput
,
294 .pr_usrreqs
= &rip_usrreqs
300 .pr_domain
= &inetdomain
,
302 .pr_flags
= PR_ATOMIC
|PR_ADDR
,
304 .pr_input
= rip_input
,
307 .pr_ctloutput
= rip_ctloutput
,
311 .pr_usrreqs
= &rip_usrreqs
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
332 inetdomain_init(void)
337 struct domain inetdomain
= {
338 .dom_family
= AF_INET
,
339 .dom_name
= "internet",
340 .dom_init
= inetdomain_init
,
341 .dom_externalize
= 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
,
352 .dom_if_down
= in_if_down
357 SYSCTL_NODE(_net
, PF_INET
, inet
, CTLFLAG_RW
, 0,
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");
367 SYSCTL_NODE(_net_inet
, IPPROTO_DIVERT
, divert
, CTLFLAG_RW
, 0, "DIVERT");
370 SYSCTL_NODE(_net_inet
, IPPROTO_PIM
, pim
, CTLFLAG_RW
, 0, "PIM");
373 SYSCTL_NODE(_net_inet
, IPPROTO_CARP
, carp
, CTLFLAG_RW
, 0, "CARP");