in_proto.c revision 1.80 1 /* $NetBSD: in_proto.c,v 1.80 2006/12/09 05:33:04 dyoung Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 /*
33 * Copyright (c) 1982, 1986, 1993
34 * The Regents of the University of California. All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
61 */
62
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.80 2006/12/09 05:33:04 dyoung Exp $");
65
66 #include "opt_mrouting.h"
67 #include "opt_eon.h" /* ISO CLNL over IP */
68 #include "opt_iso.h" /* ISO TP tunneled over IP */
69 #include "opt_inet.h"
70 #include "opt_ipsec.h"
71 #include "opt_pim.h"
72
73 #include <sys/param.h>
74 #include <sys/socket.h>
75 #include <sys/protosw.h>
76 #include <sys/domain.h>
77 #include <sys/mbuf.h>
78
79 #include <net/if.h>
80 #include <net/radix.h>
81 #include <net/route.h>
82
83 #include <netinet/in.h>
84 #include <netinet/in_systm.h>
85 #include <netinet/ip.h>
86 #include <netinet/ip_var.h>
87 #include <netinet/ip_icmp.h>
88 #include <netinet/in_ifattach.h>
89 #include <netinet/in_pcb.h>
90 #include <netinet/in_proto.h>
91 #include <netinet/in_route.h>
92
93 #ifdef INET6
94 #ifndef INET
95 #include <netinet/in.h>
96 #endif
97 #include <netinet/ip6.h>
98 #endif
99
100 #include <netinet/igmp_var.h>
101 #ifdef PIM
102 #include <netinet/pim_var.h>
103 #endif
104 #include <netinet/tcp.h>
105 #include <netinet/tcp_fsm.h>
106 #include <netinet/tcp_seq.h>
107 #include <netinet/tcp_timer.h>
108 #include <netinet/tcp_var.h>
109 #include <netinet/tcpip.h>
110 #include <netinet/tcp_debug.h>
111 #include <netinet/udp.h>
112 #include <netinet/udp_var.h>
113 #include <netinet/ip_encap.h>
114
115 /*
116 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
117 */
118
119 #ifdef IPSEC
120 #include <netinet6/ipsec.h>
121 #include <netinet6/ah.h>
122 #ifdef IPSEC_ESP
123 #include <netinet6/esp.h>
124 #endif
125 #include <netinet6/ipcomp.h>
126 #endif /* IPSEC */
127
128 #ifdef FAST_IPSEC
129 #include <netipsec/ipsec.h>
130 #include <netipsec/key.h>
131 #endif /* FAST_IPSEC */
132
133 #ifdef TPIP
134 #include <netiso/tp_param.h>
135 #include <netiso/tp_var.h>
136 #endif /* TPIP */
137
138 #ifdef EON
139 #include <netiso/eonvar.h>
140 #endif /* EON */
141
142 #include "gre.h"
143 #if NGRE > 0
144 #include <netinet/ip_gre.h>
145 #endif
146
147 #include "carp.h"
148 #if NCARP > 0
149 #include <netinet/ip_carp.h>
150 #endif
151
152 #include "etherip.h"
153 #if NETHERIP > 0
154 #include <netinet/ip_etherip.h>
155 #endif
156
157 DOMAIN_DEFINE(inetdomain); /* forward declare and add to link set */
158
159 const struct protosw inetsw[] = {
160 { 0, &inetdomain, 0, 0,
161 0, ip_output, 0, 0,
162 0,
163 ip_init, 0, ip_slowtimo, ip_drain,
164 },
165 { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR|PR_PURGEIF,
166 udp_input, 0, udp_ctlinput, udp_ctloutput,
167 udp_usrreq,
168 udp_init, 0, 0, 0,
169 },
170 { SOCK_STREAM, &inetdomain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
171 tcp_input, 0, tcp_ctlinput, tcp_ctloutput,
172 tcp_usrreq,
173 tcp_init, 0, tcp_slowtimo, tcp_drain,
174 },
175 { SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR|PR_PURGEIF,
176 rip_input, rip_output, rip_ctlinput, rip_ctloutput,
177 rip_usrreq,
178 0, 0, 0, 0,
179 },
180 { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
181 icmp_input, rip_output, rip_ctlinput, rip_ctloutput,
182 rip_usrreq,
183 icmp_init, 0, 0, 0,
184 },
185 #ifdef IPSEC
186 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR,
187 ah4_input, 0, ah4_ctlinput, 0,
188 0,
189 0, 0, 0, 0,
190 },
191 #ifdef IPSEC_ESP
192 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR,
193 esp4_input,
194 0, esp4_ctlinput, 0,
195 0,
196 0, 0, 0, 0,
197 },
198 #endif
199 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
200 ipcomp4_input,
201 0, 0, 0,
202 0,
203 0, 0, 0, 0,
204 },
205 #endif /* IPSEC */
206 #ifdef FAST_IPSEC
207 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR,
208 ipsec4_common_input, 0, ah4_ctlinput, 0,
209 0, 0, 0, 0, 0,
210 },
211 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR,
212 ipsec4_common_input, 0, esp4_ctlinput, 0,
213 0,
214 0, 0, 0, 0,
215 },
216 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
217 ipsec4_common_input, 0, 0, 0,
218 0,
219 0, 0, 0, 0,
220 },
221 #endif /* FAST_IPSEC */
222 { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
223 encap4_input, rip_output, rip_ctlinput, rip_ctloutput,
224 rip_usrreq, /*XXX*/
225 encap_init, 0, 0, 0,
226 },
227 #ifdef INET6
228 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
229 encap4_input, rip_output, rip_ctlinput, rip_ctloutput,
230 rip_usrreq, /*XXX*/
231 encap_init, 0, 0, 0,
232 },
233 #endif /* INET6 */
234 #if NETHERIP > 0
235 { SOCK_RAW, &inetdomain, IPPROTO_ETHERIP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
236 ip_etherip_input, rip_output, rip_ctlinput, rip_ctloutput,
237 rip_usrreq,
238 0, 0, 0, 0,
239 },
240 #endif
241 #if NCARP > 0
242 { SOCK_RAW, &inetdomain, IPPROTO_CARP, PR_ATOMIC|PR_ADDR,
243 carp_proto_input, rip_output, 0, rip_ctloutput,
244 rip_usrreq,
245 0, 0, 0, 0,
246 },
247 #endif
248 #if NGRE > 0
249 { SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
250 gre_input, rip_output, rip_ctlinput, rip_ctloutput,
251 rip_usrreq,
252 0, 0, 0, 0,
253 },
254 { SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
255 gre_mobile_input, rip_output, rip_ctlinput, rip_ctloutput,
256 rip_usrreq,
257 0, 0, 0, 0,
258 },
259 #endif /* NGRE > 0 */
260 { SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
261 igmp_input, rip_output, rip_ctlinput, rip_ctloutput,
262 rip_usrreq,
263 NULL, igmp_fasttimo, igmp_slowtimo, 0,
264 },
265 #ifdef PIM
266 { SOCK_RAW, &inetdomain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
267 pim_input, rip_output, rip_ctlinput, rip_ctloutput,
268 rip_usrreq,
269 NULL, 0, 0, 0,
270 },
271 #endif /* PIM */
272 #ifdef TPIP
273 { SOCK_SEQPACKET,&inetdomain, IPPROTO_TP, PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_LASTHDR|PR_ABRTACPTDIS,
274 tpip_input, 0, tpip_ctlinput, tp_ctloutput,
275 tp_usrreq,
276 tp_init, 0, tp_slowtimo, tp_drain,
277 },
278 #endif /* TPIP */
279 #ifdef ISO
280 /* EON (ISO CLNL over IP) */
281 #ifdef EON
282 { SOCK_RAW, &inetdomain, IPPROTO_EON, PR_LASTHDR,
283 eoninput, 0, eonctlinput, 0,
284 0,
285 eonprotoinit, 0, 0, 0,
286 },
287 #else
288 { SOCK_RAW, &inetdomain, IPPROTO_EON, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
289 encap4_input, rip_output, rip_ctlinput, rip_ctloutput,
290 rip_usrreq, /*XXX*/
291 encap_init, 0, 0, 0,
292 },
293 #endif /* EON */
294 #endif /* ISO */
295 /* raw wildcard */
296 { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
297 rip_input, rip_output, rip_ctlinput, rip_ctloutput,
298 rip_usrreq,
299 rip_init, 0, 0, 0,
300 },
301 };
302
303 extern struct ifqueue ipintrq;
304
305 struct domain inetdomain = {
306 .dom_family = PF_INET, .dom_name = "internet", .dom_init = NULL,
307 .dom_externalize = NULL, .dom_dispose = NULL,
308 .dom_protosw = inetsw,
309 .dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
310 .dom_rtattach = rn_inithead,
311 .dom_rtoffset = 32, .dom_maxrtkey = sizeof(struct sockaddr_in),
312 #ifdef IPSELSRC
313 .dom_ifattach = in_domifattach,
314 .dom_ifdetach = in_domifdetach,
315 #else
316 .dom_ifattach = NULL,
317 .dom_ifdetach = NULL,
318 #endif
319 .dom_ifqueues = { &ipintrq, NULL },
320 .dom_link = { NULL },
321 .dom_mowner = MOWNER_INIT("",""),
322 .dom_rtcache = in_rtcache,
323 .dom_rtflush = in_rtflush,
324 .dom_rtflushall = in_rtflushall
325 };
326
327 u_char ip_protox[IPPROTO_MAX];
328
329 int icmperrppslim = 100; /* 100pps */
330