in_proto.c revision 1.47.2.3 1 /* $NetBSD: in_proto.c,v 1.47.2.3 2001/11/14 19:17:45 nathanw 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. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
65 */
66
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.47.2.3 2001/11/14 19:17:45 nathanw Exp $");
69
70 #include "opt_mrouting.h"
71 #include "opt_eon.h" /* ISO CLNL over IP */
72 #include "opt_iso.h" /* ISO TP tunneled over IP */
73 #include "opt_ns.h" /* NSIP: XNS tunneled over IP */
74 #include "opt_inet.h"
75 #include "opt_ipsec.h"
76
77 #include <sys/param.h>
78 #include <sys/socket.h>
79 #include <sys/protosw.h>
80 #include <sys/domain.h>
81 #include <sys/mbuf.h>
82
83 #include <net/if.h>
84 #include <net/radix.h>
85 #include <net/route.h>
86
87 #include <netinet/in.h>
88 #include <netinet/in_systm.h>
89 #include <netinet/ip.h>
90 #include <netinet/ip_var.h>
91 #include <netinet/ip_icmp.h>
92 #include <netinet/in_pcb.h>
93
94 #ifdef INET6
95 #ifndef INET
96 #include <netinet/in.h>
97 #endif
98 #include <netinet/ip6.h>
99 #endif
100
101 #include <netinet/igmp_var.h>
102 #include <netinet/tcp.h>
103 #include <netinet/tcp_fsm.h>
104 #include <netinet/tcp_seq.h>
105 #include <netinet/tcp_timer.h>
106 #include <netinet/tcp_var.h>
107 #include <netinet/tcpip.h>
108 #include <netinet/tcp_debug.h>
109 #include <netinet/udp.h>
110 #include <netinet/udp_var.h>
111 #include <netinet/ip_encap.h>
112 /*
113 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
114 */
115
116 #ifdef IPSEC
117 #include <netinet6/ah.h>
118 #ifdef IPSEC_ESP
119 #include <netinet6/esp.h>
120 #endif
121 #include <netinet6/ipcomp.h>
122 #endif /* IPSEC */
123
124 #include "gif.h"
125 #if NGIF > 0
126 #include <netinet/in_gif.h>
127 #endif
128
129 #ifdef NSIP
130 #include <netns/ns_var.h>
131 #include <netns/idp_var.h>
132 #endif /* NSIP */
133
134 #ifdef TPIP
135 #include <netiso/tp_param.h>
136 #include <netiso/tp_var.h>
137 #endif /* TPIP */
138
139 #ifdef EON
140 #include <netiso/eonvar.h>
141 #endif /* EON */
142
143 #include "ipip.h"
144 #if NIPIP > 0 || defined(MROUTING)
145 #include <netinet/ip_ipip.h>
146 #endif /* NIPIP > 0 || MROUTING */
147
148 #include "gre.h"
149 #if NGRE > 0
150 #include <netinet/ip_gre.h>
151 #endif
152
153 #include "stf.h"
154 #if NSTF > 0
155 #include <net/if_stf.h>
156 #endif
157
158 extern struct domain inetdomain;
159
160 struct protosw inetsw[] = {
161 { 0, &inetdomain, 0, 0,
162 0, ip_output, 0, 0,
163 0,
164 ip_init, 0, ip_slowtimo, ip_drain, ip_sysctl
165 },
166 { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR,
167 udp_input, 0, udp_ctlinput, ip_ctloutput,
168 udp_usrreq,
169 udp_init, 0, 0, 0, udp_sysctl
170 },
171 { SOCK_STREAM, &inetdomain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS,
172 tcp_input, 0, tcp_ctlinput, tcp_ctloutput,
173 tcp_usrreq,
174 tcp_init, 0, tcp_slowtimo, tcp_drain, tcp_sysctl
175 },
176 { SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR,
177 rip_input, rip_output, 0, rip_ctloutput,
178 rip_usrreq,
179 0, 0, 0, 0,
180 },
181 { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
182 icmp_input, rip_output, 0, rip_ctloutput,
183 rip_usrreq,
184 icmp_init, 0, 0, 0, icmp_sysctl
185 },
186 #ifdef IPSEC
187 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR,
188 ah4_input, 0, ah4_ctlinput, 0,
189 0,
190 0, 0, 0, 0, ipsec_sysctl
191 },
192 #ifdef IPSEC_ESP
193 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR,
194 esp4_input, 0, esp4_ctlinput, 0,
195 0,
196 0, 0, 0, 0, ipsec_sysctl
197 },
198 #endif
199 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
200 ipcomp4_input, 0, 0, 0,
201 0,
202 0, 0, 0, 0, ipsec_sysctl
203 },
204 #endif /* IPSEC */
205 { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
206 encap4_input, rip_output, 0, rip_ctloutput,
207 rip_usrreq, /*XXX*/
208 encap_init, 0, 0, 0,
209 },
210 #ifdef INET6
211 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
212 encap4_input, rip_output, 0, rip_ctloutput,
213 rip_usrreq, /*XXX*/
214 0, 0, 0, 0,
215 },
216 #endif /* INET6 */
217 #if NGRE > 0
218 { SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
219 gre_input, rip_output, 0, rip_ctloutput,
220 rip_usrreq,
221 0, 0, 0, 0,
222 },
223 { SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
224 gre_mobile_input, rip_output, 0, rip_ctloutput,
225 rip_usrreq,
226 0, 0, 0, 0,
227 },
228 #endif /* NGRE > 0 */
229 { SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
230 igmp_input, rip_output, 0, rip_ctloutput,
231 rip_usrreq,
232 igmp_init, igmp_fasttimo, igmp_slowtimo, 0,
233 },
234 #ifdef TPIP
235 { SOCK_SEQPACKET,&inetdomain, IPPROTO_TP, PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_LASTHDR|PR_ABRTACPTDIS,
236 tpip_input, 0, tpip_ctlinput, tp_ctloutput,
237 tp_usrreq,
238 tp_init, 0, tp_slowtimo, tp_drain,
239 },
240 #endif /* TPIP */
241 #ifdef ISO
242 /* EON (ISO CLNL over IP) */
243 #ifdef EON
244 { SOCK_RAW, &inetdomain, IPPROTO_EON, PR_LASTHDR,
245 eoninput, 0, eonctlinput, 0,
246 0,
247 eonprotoinit, 0, 0, 0,
248 },
249 #else
250 { SOCK_RAW, &inetdomain, IPPROTO_EON, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
251 encap4_input, rip_output, 0, rip_ctloutput,
252 rip_usrreq, /*XXX*/
253 0, 0, 0, 0,
254 },
255 #endif /* EON */
256 #endif /* ISO */
257 #ifdef NSIP
258 { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
259 idpip_input, NULL, nsip_ctlinput, 0,
260 rip_usrreq,
261 0, 0, 0, 0,
262 },
263 #endif /* NSIP */
264 /* raw wildcard */
265 { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR,
266 rip_input, rip_output, 0, rip_ctloutput,
267 rip_usrreq,
268 rip_init, 0, 0, 0,
269 },
270 };
271
272 #if NIPIP > 0
273 struct protosw ipip_protosw =
274 { SOCK_RAW, &inetdomain, IPPROTO_IPIP, PR_ATOMIC|PR_ADDR,
275 ipip_input, rip_output, 0, rip_ctloutput,
276 rip_usrreq, /* XXX */
277 0, 0, 0, 0,
278 };
279 #endif /* NIPIP */
280
281 #if NGIF > 0
282 struct protosw in_gif_protosw =
283 { SOCK_RAW, &inetdomain, 0/*IPPROTO_IPV[46]*/, PR_ATOMIC|PR_ADDR,
284 in_gif_input, rip_output, 0, rip_ctloutput,
285 rip_usrreq,
286 0, 0, 0, 0,
287 };
288 #endif /*NGIF*/
289
290 #if NSTF > 0
291 struct protosw in_stf_protosw =
292 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR,
293 in_stf_input, rip_output, 0, rip_ctloutput,
294 rip_usrreq,
295 0, 0, 0, 0
296 };
297 #endif /*NSTF*/
298
299 struct domain inetdomain =
300 { PF_INET, "internet", 0, 0, 0,
301 inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
302 rn_inithead, 32, sizeof(struct sockaddr_in) };
303
304 u_char ip_protox[IPPROTO_MAX];
305
306 int icmperrppslim = 100; /* 100pps */
307