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