1 /*-
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
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 * 4. 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.
16 *
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.
28 *
29 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
30 */
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34
35 #include "opt_ipx.h"
36 #include "opt_mrouting.h"
37 #include "opt_ipsec.h"
38 #include "opt_inet6.h"
39 #include "opt_pf.h"
40 #include "opt_carp.h"
41 #include "opt_sctp.h"
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/socket.h>
47 #include <sys/domain.h>
48 #include <sys/protosw.h>
49 #include <sys/queue.h>
50 #include <sys/sysctl.h>
51
52 #include <net/if.h>
53 #include <net/route.h>
54
55 #include <netinet/in.h>
56 #include <netinet/in_systm.h>
57 #include <netinet/ip.h>
58 #include <netinet/ip_var.h>
59 #include <netinet/ip_icmp.h>
60 #include <netinet/igmp_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>
67
68 /*
69 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
70 */
71
72 static struct pr_usrreqs nousrreqs;
73
74 #ifdef IPSEC
75 #include <netipsec/ipsec.h>
76 #endif /* IPSEC */
77
78 #ifdef SCTP
79 #include <netinet/in_pcb.h>
80 #include <netinet/sctp_pcb.h>
81 #include <netinet/sctp.h>
82 #include <netinet/sctp_var.h>
83 #endif /* SCTP */
84
85 #ifdef DEV_PFSYNC
86 #include <net/pfvar.h>
87 #include <net/if_pfsync.h>
88 #endif
89
90 #ifdef DEV_CARP
91 #include <netinet/ip_carp.h>
92 #endif
93
94 FEATURE(inet, "Internet Protocol version 4");
95
96 extern struct domain inetdomain;
97
98 /* Spacer for loadable protocols. */
99 #define IPPROTOSPACER \
100 { \
101 .pr_domain = &inetdomain, \
102 .pr_protocol = PROTO_SPACER, \
103 .pr_usrreqs = &nousrreqs \
104 }
105
106 struct protosw inetsw[] = {
107 {
108 .pr_type = 0,
109 .pr_domain = &inetdomain,
110 .pr_protocol = IPPROTO_IP,
111 .pr_init = ip_init,
112 .pr_slowtimo = ip_slowtimo,
113 .pr_drain = ip_drain,
114 .pr_usrreqs = &nousrreqs
115 },
116 {
117 .pr_type = SOCK_DGRAM,
118 .pr_domain = &inetdomain,
119 .pr_protocol = IPPROTO_UDP,
120 .pr_flags = PR_ATOMIC|PR_ADDR,
121 .pr_input = udp_input,
122 .pr_ctlinput = udp_ctlinput,
123 .pr_ctloutput = ip_ctloutput,
124 .pr_init = udp_init,
125 .pr_usrreqs = &udp_usrreqs
126 },
127 {
128 .pr_type = SOCK_STREAM,
129 .pr_domain = &inetdomain,
130 .pr_protocol = IPPROTO_TCP,
131 .pr_flags = PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
132 .pr_input = tcp_input,
133 .pr_ctlinput = tcp_ctlinput,
134 .pr_ctloutput = tcp_ctloutput,
135 .pr_init = tcp_init,
136 .pr_slowtimo = tcp_slowtimo,
137 .pr_drain = tcp_drain,
138 .pr_usrreqs = &tcp_usrreqs
139 },
140 #ifdef SCTP
141 {
142 .pr_type = SOCK_DGRAM,
143 .pr_domain = &inetdomain,
144 .pr_protocol = IPPROTO_SCTP,
145 .pr_flags = PR_WANTRCVD,
146 .pr_input = sctp_input,
147 .pr_ctlinput = sctp_ctlinput,
148 .pr_ctloutput = sctp_ctloutput,
149 .pr_init = sctp_init,
150 .pr_drain = sctp_drain,
151 .pr_usrreqs = &sctp_usrreqs
152 },
153 {
154 .pr_type = SOCK_SEQPACKET,
155 .pr_domain = &inetdomain,
156 .pr_protocol = IPPROTO_SCTP,
157 .pr_flags = PR_WANTRCVD,
158 .pr_input = sctp_input,
159 .pr_ctlinput = sctp_ctlinput,
160 .pr_ctloutput = sctp_ctloutput,
161 .pr_drain = sctp_drain,
162 .pr_usrreqs = &sctp_usrreqs
163 },
164
165 {
166 .pr_type = SOCK_STREAM,
167 .pr_domain = &inetdomain,
168 .pr_protocol = IPPROTO_SCTP,
169 .pr_flags = PR_WANTRCVD,
170 .pr_input = sctp_input,
171 .pr_ctlinput = sctp_ctlinput,
172 .pr_ctloutput = sctp_ctloutput,
173 .pr_drain = sctp_drain,
174 .pr_usrreqs = &sctp_usrreqs
175 },
176 #endif /* SCTP */
177 {
178 .pr_type = SOCK_RAW,
179 .pr_domain = &inetdomain,
180 .pr_protocol = IPPROTO_RAW,
181 .pr_flags = PR_ATOMIC|PR_ADDR,
182 .pr_input = rip_input,
183 .pr_ctlinput = rip_ctlinput,
184 .pr_ctloutput = rip_ctloutput,
185 .pr_usrreqs = &rip_usrreqs
186 },
187 {
188 .pr_type = SOCK_RAW,
189 .pr_domain = &inetdomain,
190 .pr_protocol = IPPROTO_ICMP,
191 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
192 .pr_input = icmp_input,
193 .pr_ctloutput = rip_ctloutput,
194 .pr_usrreqs = &rip_usrreqs
195 },
196 {
197 .pr_type = SOCK_RAW,
198 .pr_domain = &inetdomain,
199 .pr_protocol = IPPROTO_IGMP,
200 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
201 .pr_input = igmp_input,
202 .pr_ctloutput = rip_ctloutput,
203 .pr_init = igmp_init,
204 .pr_fasttimo = igmp_fasttimo,
205 .pr_slowtimo = igmp_slowtimo,
206 .pr_usrreqs = &rip_usrreqs
207 },
208 {
209 .pr_type = SOCK_RAW,
210 .pr_domain = &inetdomain,
211 .pr_protocol = IPPROTO_RSVP,
212 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
213 .pr_input = rsvp_input,
214 .pr_ctloutput = rip_ctloutput,
215 .pr_usrreqs = &rip_usrreqs
216 },
217 #ifdef IPSEC
218 {
219 .pr_type = SOCK_RAW,
220 .pr_domain = &inetdomain,
221 .pr_protocol = IPPROTO_AH,
222 .pr_flags = PR_ATOMIC|PR_ADDR,
223 .pr_input = ah4_input,
224 .pr_ctlinput = ah4_ctlinput,
225 .pr_usrreqs = &nousrreqs
226 },
227 {
228 .pr_type = SOCK_RAW,
229 .pr_domain = &inetdomain,
230 .pr_protocol = IPPROTO_ESP,
231 .pr_flags = PR_ATOMIC|PR_ADDR,
232 .pr_input = esp4_input,
233 .pr_ctlinput = esp4_ctlinput,
234 .pr_usrreqs = &nousrreqs
235 },
236 {
237 .pr_type = SOCK_RAW,
238 .pr_domain = &inetdomain,
239 .pr_protocol = IPPROTO_IPCOMP,
240 .pr_flags = PR_ATOMIC|PR_ADDR,
241 .pr_input = ipcomp4_input,
242 .pr_usrreqs = &nousrreqs
243 },
244 #endif /* IPSEC */
245 {
246 .pr_type = SOCK_RAW,
247 .pr_domain = &inetdomain,
248 .pr_protocol = IPPROTO_IPV4,
249 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
250 .pr_input = encap4_input,
251 .pr_ctloutput = rip_ctloutput,
252 .pr_init = encap_init,
253 .pr_usrreqs = &rip_usrreqs
254 },
255 {
256 .pr_type = SOCK_RAW,
257 .pr_domain = &inetdomain,
258 .pr_protocol = IPPROTO_MOBILE,
259 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
260 .pr_input = encap4_input,
261 .pr_ctloutput = rip_ctloutput,
262 .pr_init = encap_init,
263 .pr_usrreqs = &rip_usrreqs
264 },
265 {
266 .pr_type = SOCK_RAW,
267 .pr_domain = &inetdomain,
268 .pr_protocol = IPPROTO_ETHERIP,
269 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
270 .pr_input = encap4_input,
271 .pr_ctloutput = rip_ctloutput,
272 .pr_init = encap_init,
273 .pr_usrreqs = &rip_usrreqs
274 },
275 {
276 .pr_type = SOCK_RAW,
277 .pr_domain = &inetdomain,
278 .pr_protocol = IPPROTO_GRE,
279 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
280 .pr_input = encap4_input,
281 .pr_ctloutput = rip_ctloutput,
282 .pr_init = encap_init,
283 .pr_usrreqs = &rip_usrreqs
284 },
285 # ifdef INET6
286 {
287 .pr_type = SOCK_RAW,
288 .pr_domain = &inetdomain,
289 .pr_protocol = IPPROTO_IPV6,
290 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
291 .pr_input = encap4_input,
292 .pr_ctloutput = rip_ctloutput,
293 .pr_init = encap_init,
294 .pr_usrreqs = &rip_usrreqs
295 },
296 #endif
297 {
298 .pr_type = SOCK_RAW,
299 .pr_domain = &inetdomain,
300 .pr_protocol = IPPROTO_PIM,
301 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
302 .pr_input = encap4_input,
303 .pr_ctloutput = rip_ctloutput,
304 .pr_usrreqs = &rip_usrreqs
305 },
306 #ifdef DEV_PFSYNC
307 {
308 .pr_type = SOCK_RAW,
309 .pr_domain = &inetdomain,
310 .pr_protocol = IPPROTO_PFSYNC,
311 .pr_flags = PR_ATOMIC|PR_ADDR,
312 .pr_input = pfsync_input,
313 .pr_ctloutput = rip_ctloutput,
314 .pr_usrreqs = &rip_usrreqs
315 },
316 #endif /* DEV_PFSYNC */
317 #ifdef DEV_CARP
318 {
319 .pr_type = SOCK_RAW,
320 .pr_domain = &inetdomain,
321 .pr_protocol = IPPROTO_CARP,
322 .pr_flags = PR_ATOMIC|PR_ADDR,
323 .pr_input = carp_input,
324 .pr_output = (pr_output_t*)rip_output,
325 .pr_ctloutput = rip_ctloutput,
326 .pr_usrreqs = &rip_usrreqs
327 },
328 #endif /* DEV_CARP */
329 /* Spacer n-times for loadable protocols. */
330 IPPROTOSPACER,
331 IPPROTOSPACER,
332 IPPROTOSPACER,
333 IPPROTOSPACER,
334 IPPROTOSPACER,
335 IPPROTOSPACER,
336 IPPROTOSPACER,
337 IPPROTOSPACER,
338 /* raw wildcard */
339 {
340 .pr_type = SOCK_RAW,
341 .pr_domain = &inetdomain,
342 .pr_flags = PR_ATOMIC|PR_ADDR,
343 .pr_input = rip_input,
344 .pr_ctloutput = rip_ctloutput,
345 .pr_init = rip_init,
346 .pr_usrreqs = &rip_usrreqs
347 },
348 };
349
350 extern int in_inithead(void **, int);
351
352 struct domain inetdomain = {
353 .dom_family = AF_INET,
354 .dom_name = "internet",
355 .dom_protosw = inetsw,
356 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
357 .dom_rtattach = in_inithead,
358 .dom_rtoffset = 32,
359 .dom_maxrtkey = sizeof(struct sockaddr_in)
360 };
361
362 DOMAIN_SET(inet);
363
364 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
365 "Internet Family");
366
367 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
368 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
369 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
370 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
371 #ifdef SCTP
372 SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW, 0, "SCTP");
373 #endif
374 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
375 #ifdef IPSEC
376 /* XXX no protocol # to use, pick something "reserved" */
377 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
378 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
379 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
380 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
381 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
382 #endif /* IPSEC */
383 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
384 #ifdef DEV_PFSYNC
385 SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC");
386 #endif
387 #ifdef DEV_CARP
388 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");
389 #endif
Cache object: be801a46c045536a6c2d03359c10b57d
|