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 * 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.
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 * $FreeBSD: src/sys/netinet/in_proto.c,v 1.53.2.7 2003/08/24 08:24:38 hsu Exp $
31 */
32
33 #include "opt_ipdivert.h"
34 #include "opt_ipx.h"
35 #include "opt_mrouting.h"
36 #include "opt_ipsec.h"
37 #include "opt_inet6.h"
38 #include "opt_sctp.h"
39 #include "opt_carp.h"
40
41 #include <sys/param.h>
42 #include <sys/kernel.h>
43 #include <sys/socket.h>
44 #include <sys/domain.h>
45 #include <sys/protosw.h>
46 #include <sys/queue.h>
47 #include <sys/sysctl.h>
48
49 #include <net/if.h>
50 #include <net/route.h>
51
52 #include <netinet/in.h>
53 #include <netinet/in_systm.h>
54 #include <netinet/ip.h>
55 #include <netinet/ip_var.h>
56 #include <netinet/ip_icmp.h>
57 #include <netinet/igmp_var.h>
58 #ifdef PIM
59 #include <netinet/pim_var.h>
60 #endif
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 #ifdef IPDIVERT
68 #include <netinet/ip_divert.h>
69 #endif
70
71 /*
72 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
73 */
74
75 #ifdef IPSEC
76 #include <netinet6/ipsec.h>
77 #include <netinet6/ah.h>
78 #ifdef IPSEC_ESP
79 #include <netinet6/esp.h>
80 #endif
81 #include <netinet6/ipcomp.h>
82 #endif /* IPSEC */
83
84 #ifdef FAST_IPSEC
85 #include <netproto/ipsec/ipsec.h>
86 #endif /* FAST_IPSEC */
87
88 #ifdef IPXIP
89 #include <netproto/ipx/ipx_ip.h>
90 #endif
91
92 #ifdef SCTP
93 #include <netinet/in_pcb.h>
94 #include <netinet/sctp_pcb.h>
95 #include <netinet/sctp.h>
96 #include <netinet/sctp_var.h>
97 #endif /* SCTP */
98
99 #include <net/netisr.h> /* for cpu0_soport */
100
101 #ifdef CARP
102 #include <netinet/ip_carp.h>
103 #endif
104
105 extern struct domain inetdomain;
106 static struct pr_usrreqs nousrreqs;
107
108 struct protosw inetsw[] = {
109 {
110 .pr_type = 0,
111 .pr_domain = &inetdomain,
112 .pr_protocol = 0,
113 .pr_flags = 0,
114
115 .pr_ctlport = NULL,
116
117 .pr_init = ip_init,
118 .pr_fasttimo = NULL,
119 .pr_slowtimo = ip_slowtimo,
120 .pr_drain = ip_drain,
121 .pr_usrreqs = &nousrreqs
122 },
123 {
124 .pr_type = SOCK_DGRAM,
125 .pr_domain = &inetdomain,
126 .pr_protocol = IPPROTO_UDP,
127 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE|
128 PR_ASYNC_SEND|PR_ASEND_HOLDTD,
129
130 .pr_input = udp_input,
131 .pr_output = NULL,
132 .pr_ctlinput = udp_ctlinput,
133 .pr_ctloutput = ip_ctloutput,
134
135 .pr_ctlport = udp_ctlport,
136 .pr_init = udp_init,
137 .pr_usrreqs = &udp_usrreqs
138 },
139 {
140 .pr_type = SOCK_STREAM,
141 .pr_domain = &inetdomain,
142 .pr_protocol = IPPROTO_TCP,
143 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_MPSAFE|
144 PR_ASYNC_SEND|PR_ASYNC_RCVD|PR_ACONN_HOLDTD|
145 PR_RAND_INITPORT,
146
147 .pr_input = tcp_input,
148 .pr_output = NULL,
149 .pr_ctlinput = tcp_ctlinput,
150 .pr_ctloutput = tcp_ctloutput,
151
152 .pr_ctlport = tcp_ctlport,
153 .pr_init = tcp_init,
154 .pr_fasttimo = NULL,
155 .pr_slowtimo = NULL,
156 .pr_drain = tcp_drain,
157 .pr_usrreqs = &tcp_usrreqs
158 },
159 #ifdef SCTP
160 /*
161 * Order is very important here, we add the good one in
162 * in this postion so it maps to the right ip_protox[]
163 * postion for SCTP. Don't move the one above below
164 * this one or IPv6/4 compatability will break
165 */
166 {
167 .pr_type = SOCK_DGRAM,
168 .pr_domain = &inetdomain,
169 .pr_protocol = IPPROTO_SCTP,
170 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
171
172 .pr_input = sctp_input,
173 .pr_output = NULL,
174 .pr_ctlinput = sctp_ctlinput,
175 .pr_ctloutput = sctp_ctloutput,
176
177 .pr_ctlport = cpu0_ctlport,
178 .pr_init = sctp_init,
179 .pr_drain = sctp_drain,
180 .pr_usrreqs = &sctp_usrreqs
181 },
182 {
183 .pr_type = SOCK_SEQPACKET,
184 .pr_domain = &inetdomain,
185 .pr_protocol = IPPROTO_SCTP,
186 .pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
187
188 .pr_input = sctp_input,
189 .pr_output = NULL,
190 .pr_ctlinput = sctp_ctlinput,
191 .pr_ctloutput = sctp_ctloutput,
192
193 .pr_ctlport = cpu0_ctlport,
194 .pr_drain = sctp_drain,
195 .pr_usrreqs = &sctp_usrreqs
196 },
197
198 {
199 .pr_type = SOCK_STREAM,
200 .pr_domain = &inetdomain,
201 .pr_protocol = IPPROTO_SCTP,
202 .pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD,
203
204 .pr_input = sctp_input,
205 .pr_output = NULL,
206 .pr_ctlinput = sctp_ctlinput,
207 .pr_ctloutput = sctp_ctloutput,
208
209 .pr_ctlport = cpu0_ctlport,
210 .pr_drain = sctp_drain,
211 .pr_usrreqs = &sctp_usrreqs
212 },
213 #endif /* SCTP */
214 {
215 .pr_type = SOCK_RAW,
216 .pr_domain = &inetdomain,
217 .pr_protocol = IPPROTO_RAW,
218 .pr_flags = PR_ATOMIC|PR_ADDR,
219
220 .pr_input = rip_input,
221 .pr_output = NULL,
222 .pr_ctlinput = rip_ctlinput,
223 .pr_ctloutput = rip_ctloutput,
224
225 .pr_ctlport = cpu0_ctlport,
226 .pr_usrreqs = &rip_usrreqs
227 },
228 {
229 .pr_type = SOCK_RAW,
230 .pr_domain = &inetdomain,
231 .pr_protocol = IPPROTO_ICMP,
232 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR|PR_MPSAFE,
233
234 .pr_input = icmp_input,
235 .pr_output = NULL,
236 .pr_ctlinput = NULL,
237 .pr_ctloutput = rip_ctloutput,
238
239 .pr_usrreqs = &rip_usrreqs
240 },
241 {
242 .pr_type = SOCK_RAW,
243 .pr_domain = &inetdomain,
244 .pr_protocol = IPPROTO_IGMP,
245 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
246
247 .pr_input = igmp_input,
248 .pr_output = NULL,
249 .pr_ctlinput = NULL,
250 .pr_ctloutput = rip_ctloutput,
251
252 .pr_init = igmp_init,
253 .pr_fasttimo = igmp_fasttimo,
254 .pr_slowtimo = igmp_slowtimo,
255 .pr_drain = NULL,
256 .pr_usrreqs = &rip_usrreqs
257 },
258 {
259 .pr_type = SOCK_RAW,
260 .pr_domain = &inetdomain,
261 .pr_protocol = IPPROTO_RSVP,
262 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
263
264 .pr_input = rsvp_input,
265 .pr_output = NULL,
266 .pr_ctlinput = NULL,
267 .pr_ctloutput = rip_ctloutput,
268
269 .pr_usrreqs = &rip_usrreqs
270 },
271 #ifdef IPSEC
272 {
273 .pr_type = SOCK_RAW,
274 .pr_domain = &inetdomain,
275 .pr_protocol = IPPROTO_AH,
276 .pr_flags = PR_ATOMIC|PR_ADDR,
277
278 .pr_input = ah4_input,
279 .pr_output = NULL,
280 .pr_ctlinput = NULL,
281 .pr_ctloutput = NULL,
282
283 .pr_ctlport = NULL,
284 .pr_usrreqs = &nousrreqs
285 },
286 #ifdef IPSEC_ESP
287 {
288 .pr_type = SOCK_RAW,
289 .pr_domain = &inetdomain,
290 .pr_protocol = IPPROTO_ESP,
291 .pr_flags = PR_ATOMIC|PR_ADDR,
292
293 .pr_input = esp4_input,
294 .pr_output = NULL,
295 .pr_ctlinput = NULL,
296 .pr_ctloutput = NULL,
297
298 .pr_ctlport = NULL,
299 .pr_usrreqs = &nousrreqs
300 },
301 #endif
302 {
303 .pr_type = SOCK_RAW,
304 .pr_domain = &inetdomain,
305 .pr_protocol = IPPROTO_IPCOMP,
306 .pr_flags = PR_ATOMIC|PR_ADDR,
307
308 .pr_input = ipcomp4_input,
309 .pr_output = 0,
310 .pr_ctlinput = NULL,
311 .pr_ctloutput = NULL,
312
313 .pr_ctlport = NULL,
314 .pr_usrreqs = &nousrreqs
315 },
316 #endif /* IPSEC */
317 #ifdef FAST_IPSEC
318 {
319 .pr_type = SOCK_RAW,
320 .pr_domain = &inetdomain,
321 .pr_protocol = IPPROTO_AH,
322 .pr_flags = PR_ATOMIC|PR_ADDR,
323
324 .pr_input = ipsec4_common_input,
325 .pr_output = NULL,
326 .pr_ctlinput = NULL,
327 .pr_ctloutput = NULL,
328
329 .pr_ctlport = NULL,
330 .pr_usrreqs = &nousrreqs
331 },
332 {
333 .pr_type = SOCK_RAW,
334 .pr_domain = &inetdomain,
335 .pr_protocol = IPPROTO_ESP,
336 .pr_flags = PR_ATOMIC|PR_ADDR,
337
338 .pr_input = ipsec4_common_input,
339 .pr_output = NULL,
340 .pr_ctlinput = NULL,
341 .pr_ctloutput = NULL,
342
343 .pr_ctlport = NULL,
344 .pr_usrreqs = &nousrreqs
345 },
346 {
347 .pr_type = SOCK_RAW,
348 .pr_domain = &inetdomain,
349 .pr_protocol = IPPROTO_IPCOMP,
350 .pr_flags = PR_ATOMIC|PR_ADDR,
351
352 .pr_input = ipsec4_common_input,
353 .pr_output = NULL,
354 .pr_ctlinput = NULL,
355 .pr_ctloutput = NULL,
356
357 .pr_ctlport = NULL,
358 .pr_usrreqs = &nousrreqs
359 },
360 #endif /* FAST_IPSEC */
361 {
362 .pr_type = SOCK_RAW,
363 .pr_domain = &inetdomain,
364 .pr_protocol = IPPROTO_IPV4,
365 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
366 .pr_input = encap4_input,
367 .pr_output = NULL,
368 .pr_ctlinput = NULL,
369 .pr_ctloutput = rip_ctloutput,
370
371 .pr_ctlport = NULL,
372 .pr_init = encap_init,
373 .pr_usrreqs = &rip_usrreqs
374 },
375 {
376 .pr_type = SOCK_RAW,
377 .pr_domain = &inetdomain,
378 .pr_protocol = IPPROTO_MOBILE,
379 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
380
381 .pr_input = encap4_input,
382 .pr_output = NULL,
383 .pr_ctlinput = NULL,
384 .pr_ctloutput = rip_ctloutput,
385
386 .pr_ctlport = NULL,
387 .pr_init = encap_init,
388 .pr_usrreqs = &rip_usrreqs
389 },
390 {
391 .pr_type = SOCK_RAW,
392 .pr_domain = &inetdomain,
393 .pr_protocol = IPPROTO_GRE,
394 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
395
396 .pr_input = encap4_input,
397 .pr_output = NULL,
398 .pr_ctlinput = NULL,
399 .pr_ctloutput = rip_ctloutput,
400
401 .pr_ctlport = NULL,
402 .pr_init = encap_init,
403 .pr_usrreqs = &rip_usrreqs
404 },
405 #ifdef INET6
406 {
407 .pr_type = SOCK_RAW,
408 .pr_domain = &inetdomain,
409 .pr_protocol = IPPROTO_IPV6,
410 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
411
412 .pr_input = encap4_input,
413 .pr_output = NULL,
414 .pr_ctlinput = NULL,
415 .pr_ctloutput = rip_ctloutput,
416
417 .pr_ctlport = NULL,
418 .pr_init = encap_init,
419 .pr_usrreqs = &rip_usrreqs
420 },
421 #endif
422 #ifdef IPDIVERT
423 {
424 .pr_type = SOCK_RAW,
425 .pr_domain = &inetdomain,
426 .pr_protocol = IPPROTO_DIVERT,
427 .pr_flags = PR_ATOMIC|PR_ADDR,
428
429 .pr_input = div_input,
430 .pr_output = NULL,
431 .pr_ctlinput = NULL,
432 .pr_ctloutput = ip_ctloutput,
433
434 .pr_ctlport = NULL,
435 .pr_init = div_init,
436 .pr_usrreqs = &div_usrreqs
437 },
438 #endif
439 #ifdef IPXIP
440 {
441 .pr_type = SOCK_RAW,
442 .pr_domain = &inetdomain,
443 .pr_protocol = IPPROTO_IDP,
444 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
445
446 .pr_input = ipxip_input,
447 .pr_output = NULL,
448 .pr_ctlinput = ipxip_ctlinput,
449 .pr_ctloutput = NULL,
450
451 .pr_ctlport = cpu0_ctlport,
452 .pr_usrreqs = &rip_usrreqs
453 },
454 #endif
455 #ifdef PIM
456 {
457 .pr_type = SOCK_RAW,
458 .pr_domain = &inetdomain,
459 .pr_protocol = IPPROTO_PIM,
460 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
461
462 .pr_input = pim_input,
463 .pr_output = NULL,
464 .pr_ctlinput = NULL,
465 .pr_ctloutput = rip_ctloutput,
466
467 .pr_ctlport = NULL,
468 .pr_usrreqs = &rip_usrreqs
469 },
470 #endif
471 #ifdef NPFSYNC
472 {
473 .pr_type = SOCK_RAW,
474 .pr_domain = &inetdomain,
475 .pr_protocol = IPPROTO_PFSYNC,
476 .pr_flags = PR_ATOMIC|PR_ADDR,
477
478 .pr_input = pfsync_input,
479 .pr_output = NULL,
480 .pr_ctlinput = NULL,
481 .pr_ctloutput = rip_ctloutput,
482
483 .pr_ctlport = NULL,
484 .pr_usrreqs = &rip_usrreqs
485 },
486 #endif /* NPFSYNC */
487 {
488 /* raw wildcard */
489 .pr_type = SOCK_RAW,
490 .pr_domain = &inetdomain,
491 .pr_protocol = 0,
492 .pr_flags = PR_ATOMIC|PR_ADDR,
493
494 .pr_input = rip_input,
495 .pr_output = NULL,
496 .pr_ctlinput = NULL,
497 .pr_ctloutput = rip_ctloutput,
498
499 .pr_init = rip_init,
500 .pr_ctlport = NULL,
501 .pr_usrreqs = &rip_usrreqs
502 },
503 #ifdef CARP
504 {
505 .pr_type = SOCK_RAW,
506 .pr_domain = &inetdomain,
507 .pr_protocol = IPPROTO_CARP,
508 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSAFE,
509
510 .pr_input = carp_proto_input,
511 .pr_output = rip_output,
512 .pr_ctlinput = carp_proto_ctlinput,
513 .pr_ctloutput = rip_ctloutput,
514
515 .pr_ctlport = cpu0_ctlport,
516 .pr_usrreqs = &rip_usrreqs
517 },
518 #endif
519 };
520
521 struct domain inetdomain = {
522 AF_INET, "internet", NULL, NULL, NULL,
523 inetsw, &inetsw[NELEM(inetsw)],
524 SLIST_ENTRY_INITIALIZER,
525 in_inithead, 32, sizeof(struct sockaddr_in),
526 };
527
528 DOMAIN_SET(inet);
529
530 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
531 "Internet Family");
532
533 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
534 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
535 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
536 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
537 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
538 #ifdef FAST_IPSEC
539 /* XXX no protocol # to use, pick something "reserved" */
540 SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
541 SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
542 SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
543 SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
544 SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
545 #else
546 #ifdef IPSEC
547 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
548 #endif /* IPSEC */
549 #endif /* !FAST_IPSEC */
550 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
551 #ifdef IPDIVERT
552 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, divert, CTLFLAG_RW, 0, "DIVERT");
553 #endif
554 #ifdef PIM
555 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
556 #endif
557 #ifdef CARP
558 SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP");
559 #endif
Cache object: 85b3ebb345708ed17b596cc55a90011c
|