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