in_proto.c revision 1.69.2.4 1 1.69.2.4 yamt /* $NetBSD: in_proto.c,v 1.69.2.4 2007/10/27 11:36:07 yamt Exp $ */
2 1.32 itojun
3 1.32 itojun /*
4 1.32 itojun * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 1.32 itojun * All rights reserved.
6 1.56 itojun *
7 1.32 itojun * Redistribution and use in source and binary forms, with or without
8 1.32 itojun * modification, are permitted provided that the following conditions
9 1.32 itojun * are met:
10 1.32 itojun * 1. Redistributions of source code must retain the above copyright
11 1.32 itojun * notice, this list of conditions and the following disclaimer.
12 1.32 itojun * 2. Redistributions in binary form must reproduce the above copyright
13 1.32 itojun * notice, this list of conditions and the following disclaimer in the
14 1.32 itojun * documentation and/or other materials provided with the distribution.
15 1.32 itojun * 3. Neither the name of the project nor the names of its contributors
16 1.32 itojun * may be used to endorse or promote products derived from this software
17 1.32 itojun * without specific prior written permission.
18 1.56 itojun *
19 1.32 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 1.32 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.32 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.32 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 1.32 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.32 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.32 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.32 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.32 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.32 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.32 itojun * SUCH DAMAGE.
30 1.32 itojun */
31 1.9 cgd
32 1.1 cgd /*
33 1.8 mycroft * Copyright (c) 1982, 1986, 1993
34 1.8 mycroft * The Regents of the University of California. All rights reserved.
35 1.1 cgd *
36 1.1 cgd * Redistribution and use in source and binary forms, with or without
37 1.1 cgd * modification, are permitted provided that the following conditions
38 1.1 cgd * are met:
39 1.1 cgd * 1. Redistributions of source code must retain the above copyright
40 1.1 cgd * notice, this list of conditions and the following disclaimer.
41 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 cgd * notice, this list of conditions and the following disclaimer in the
43 1.1 cgd * documentation and/or other materials provided with the distribution.
44 1.59 agc * 3. Neither the name of the University nor the names of its contributors
45 1.1 cgd * may be used to endorse or promote products derived from this software
46 1.1 cgd * without specific prior written permission.
47 1.1 cgd *
48 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 1.1 cgd * SUCH DAMAGE.
59 1.1 cgd *
60 1.18 thorpej * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
61 1.1 cgd */
62 1.51 lukem
63 1.51 lukem #include <sys/cdefs.h>
64 1.69.2.4 yamt __KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.69.2.4 2007/10/27 11:36:07 yamt Exp $");
65 1.19 scottr
66 1.19 scottr #include "opt_mrouting.h"
67 1.22 jonathan #include "opt_eon.h" /* ISO CLNL over IP */
68 1.22 jonathan #include "opt_iso.h" /* ISO TP tunneled over IP */
69 1.32 itojun #include "opt_inet.h"
70 1.33 thorpej #include "opt_ipsec.h"
71 1.65 manu #include "opt_pim.h"
72 1.1 cgd
73 1.5 mycroft #include <sys/param.h>
74 1.5 mycroft #include <sys/socket.h>
75 1.5 mycroft #include <sys/protosw.h>
76 1.5 mycroft #include <sys/domain.h>
77 1.5 mycroft #include <sys/mbuf.h>
78 1.1 cgd
79 1.8 mycroft #include <net/if.h>
80 1.8 mycroft #include <net/radix.h>
81 1.8 mycroft #include <net/route.h>
82 1.8 mycroft
83 1.5 mycroft #include <netinet/in.h>
84 1.5 mycroft #include <netinet/in_systm.h>
85 1.8 mycroft #include <netinet/ip.h>
86 1.8 mycroft #include <netinet/ip_var.h>
87 1.8 mycroft #include <netinet/ip_icmp.h>
88 1.69.2.2 yamt #include <netinet/in_ifattach.h>
89 1.8 mycroft #include <netinet/in_pcb.h>
90 1.69 yamt #include <netinet/in_proto.h>
91 1.32 itojun
92 1.32 itojun #ifdef INET6
93 1.32 itojun #ifndef INET
94 1.32 itojun #include <netinet/in.h>
95 1.32 itojun #endif
96 1.32 itojun #include <netinet/ip6.h>
97 1.32 itojun #endif
98 1.32 itojun
99 1.8 mycroft #include <netinet/igmp_var.h>
100 1.65 manu #ifdef PIM
101 1.65 manu #include <netinet/pim_var.h>
102 1.65 manu #endif
103 1.8 mycroft #include <netinet/tcp.h>
104 1.8 mycroft #include <netinet/tcp_fsm.h>
105 1.8 mycroft #include <netinet/tcp_seq.h>
106 1.8 mycroft #include <netinet/tcp_timer.h>
107 1.8 mycroft #include <netinet/tcp_var.h>
108 1.8 mycroft #include <netinet/tcpip.h>
109 1.8 mycroft #include <netinet/tcp_debug.h>
110 1.8 mycroft #include <netinet/udp.h>
111 1.8 mycroft #include <netinet/udp_var.h>
112 1.39 itojun #include <netinet/ip_encap.h>
113 1.69.2.2 yamt
114 1.1 cgd /*
115 1.1 cgd * TCP/IP protocol family: IP, ICMP, UDP, TCP.
116 1.1 cgd */
117 1.1 cgd
118 1.32 itojun #ifdef IPSEC
119 1.58 itojun #include <netinet6/ipsec.h>
120 1.32 itojun #include <netinet6/ah.h>
121 1.32 itojun #ifdef IPSEC_ESP
122 1.32 itojun #include <netinet6/esp.h>
123 1.32 itojun #endif
124 1.32 itojun #include <netinet6/ipcomp.h>
125 1.32 itojun #endif /* IPSEC */
126 1.32 itojun
127 1.61 jonathan #ifdef FAST_IPSEC
128 1.61 jonathan #include <netipsec/ipsec.h>
129 1.61 jonathan #include <netipsec/key.h>
130 1.61 jonathan #endif /* FAST_IPSEC */
131 1.61 jonathan
132 1.1 cgd #ifdef TPIP
133 1.13 christos #include <netiso/tp_param.h>
134 1.13 christos #include <netiso/tp_var.h>
135 1.11 mycroft #endif /* TPIP */
136 1.1 cgd
137 1.1 cgd #ifdef EON
138 1.13 christos #include <netiso/eonvar.h>
139 1.8 mycroft #endif /* EON */
140 1.1 cgd
141 1.69.2.1 yamt #include "carp.h"
142 1.69.2.1 yamt #if NCARP > 0
143 1.69.2.1 yamt #include <netinet/ip_carp.h>
144 1.69.2.1 yamt #endif
145 1.69.2.1 yamt
146 1.69.2.2 yamt #include "etherip.h"
147 1.69.2.2 yamt #if NETHERIP > 0
148 1.69.2.2 yamt #include <netinet/ip_etherip.h>
149 1.69.2.2 yamt #endif
150 1.67 kim
151 1.66 matt DOMAIN_DEFINE(inetdomain); /* forward declare and add to link set */
152 1.66 matt
153 1.63 matt const struct protosw inetsw[] = {
154 1.69.2.3 yamt { .pr_domain = &inetdomain,
155 1.69.2.3 yamt .pr_init = ip_init,
156 1.69.2.3 yamt .pr_output = ip_output,
157 1.69.2.3 yamt .pr_slowtimo = ip_slowtimo,
158 1.69.2.3 yamt .pr_drain = ip_drain,
159 1.69.2.3 yamt },
160 1.69.2.3 yamt { .pr_type = SOCK_DGRAM,
161 1.69.2.3 yamt .pr_domain = &inetdomain,
162 1.69.2.3 yamt .pr_protocol = IPPROTO_UDP,
163 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
164 1.69.2.3 yamt .pr_input = udp_input,
165 1.69.2.3 yamt .pr_ctlinput = udp_ctlinput,
166 1.69.2.3 yamt .pr_ctloutput = udp_ctloutput,
167 1.69.2.3 yamt .pr_usrreq = udp_usrreq,
168 1.69.2.3 yamt .pr_init = udp_init,
169 1.69.2.3 yamt },
170 1.69.2.3 yamt { .pr_type = SOCK_STREAM,
171 1.69.2.3 yamt .pr_domain = &inetdomain,
172 1.69.2.3 yamt .pr_protocol = IPPROTO_TCP,
173 1.69.2.3 yamt .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
174 1.69.2.3 yamt .pr_input = tcp_input,
175 1.69.2.3 yamt .pr_ctlinput = tcp_ctlinput,
176 1.69.2.3 yamt .pr_ctloutput = tcp_ctloutput,
177 1.69.2.3 yamt .pr_usrreq = tcp_usrreq,
178 1.69.2.3 yamt .pr_init = tcp_init,
179 1.69.2.3 yamt .pr_slowtimo = tcp_slowtimo,
180 1.69.2.3 yamt .pr_drain = tcp_drain,
181 1.69.2.3 yamt },
182 1.69.2.3 yamt { .pr_type = SOCK_RAW,
183 1.69.2.3 yamt .pr_domain = &inetdomain,
184 1.69.2.3 yamt .pr_protocol = IPPROTO_RAW,
185 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
186 1.69.2.3 yamt .pr_input = rip_input,
187 1.69.2.3 yamt .pr_output = rip_output,
188 1.69.2.3 yamt .pr_ctlinput = rip_ctlinput,
189 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
190 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
191 1.69.2.3 yamt },
192 1.69.2.3 yamt { .pr_type = SOCK_RAW,
193 1.69.2.3 yamt .pr_domain = &inetdomain,
194 1.69.2.3 yamt .pr_protocol = IPPROTO_ICMP,
195 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
196 1.69.2.3 yamt .pr_input = icmp_input,
197 1.69.2.3 yamt .pr_output = rip_output,
198 1.69.2.3 yamt .pr_ctlinput = rip_ctlinput,
199 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
200 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
201 1.69.2.3 yamt .pr_init = icmp_init,
202 1.69.2.3 yamt },
203 1.69.2.3 yamt #ifdef GATEWAY
204 1.69.2.3 yamt { .pr_domain = &inetdomain,
205 1.69.2.3 yamt .pr_protocol = IPPROTO_IP,
206 1.69.2.3 yamt .pr_slowtimo = ipflow_slowtimo,
207 1.8 mycroft },
208 1.69.2.3 yamt #endif /* GATEWAY */
209 1.32 itojun #ifdef IPSEC
210 1.69.2.3 yamt { .pr_type = SOCK_RAW,
211 1.69.2.3 yamt .pr_domain = &inetdomain,
212 1.69.2.3 yamt .pr_protocol = IPPROTO_AH,
213 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR,
214 1.69.2.3 yamt .pr_input = ah4_input,
215 1.69.2.3 yamt .pr_ctlinput = ah4_ctlinput,
216 1.32 itojun },
217 1.32 itojun #ifdef IPSEC_ESP
218 1.69.2.3 yamt { .pr_type = SOCK_RAW,
219 1.69.2.3 yamt .pr_domain = &inetdomain,
220 1.69.2.3 yamt .pr_protocol = IPPROTO_ESP,
221 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR,
222 1.69.2.3 yamt .pr_input = esp4_input,
223 1.69.2.3 yamt .pr_ctlinput = esp4_ctlinput,
224 1.69.2.3 yamt },
225 1.69.2.3 yamt #endif /* IPSEC_ESP */
226 1.69.2.3 yamt { .pr_type = SOCK_RAW,
227 1.69.2.3 yamt .pr_domain = &inetdomain,
228 1.69.2.3 yamt .pr_protocol = IPPROTO_IPCOMP,
229 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR,
230 1.69.2.3 yamt .pr_input = ipcomp4_input,
231 1.32 itojun },
232 1.32 itojun #endif /* IPSEC */
233 1.61 jonathan #ifdef FAST_IPSEC
234 1.69.2.3 yamt { .pr_type = SOCK_RAW,
235 1.69.2.3 yamt .pr_domain = &inetdomain,
236 1.69.2.3 yamt .pr_protocol = IPPROTO_AH,
237 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR,
238 1.69.2.3 yamt .pr_input = ipsec4_common_input,
239 1.69.2.3 yamt .pr_ctlinput = ah4_ctlinput,
240 1.69.2.3 yamt },
241 1.69.2.3 yamt { .pr_type = SOCK_RAW,
242 1.69.2.3 yamt .pr_domain = &inetdomain,
243 1.69.2.3 yamt .pr_protocol = IPPROTO_ESP,
244 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR,
245 1.69.2.3 yamt .pr_input = ipsec4_common_input,
246 1.69.2.3 yamt .pr_ctlinput = esp4_ctlinput,
247 1.69.2.3 yamt },
248 1.69.2.3 yamt { .pr_type = SOCK_RAW,
249 1.69.2.3 yamt .pr_domain = &inetdomain,
250 1.69.2.3 yamt .pr_protocol = IPPROTO_IPCOMP,
251 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR,
252 1.69.2.3 yamt .pr_input = ipsec4_common_input,
253 1.61 jonathan },
254 1.61 jonathan #endif /* FAST_IPSEC */
255 1.69.2.3 yamt { .pr_type = SOCK_RAW,
256 1.69.2.3 yamt .pr_domain = &inetdomain,
257 1.69.2.3 yamt .pr_protocol = IPPROTO_IPV4,
258 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
259 1.69.2.3 yamt .pr_input = encap4_input,
260 1.69.2.3 yamt .pr_output = rip_output,
261 1.69.2.3 yamt .pr_ctlinput = rip_ctlinput,
262 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
263 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
264 1.69.2.3 yamt .pr_init = encap_init,
265 1.32 itojun },
266 1.32 itojun #ifdef INET6
267 1.69.2.3 yamt { .pr_type = SOCK_RAW,
268 1.69.2.3 yamt .pr_domain = &inetdomain,
269 1.69.2.3 yamt .pr_protocol = IPPROTO_IPV6,
270 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
271 1.69.2.3 yamt .pr_input = encap4_input,
272 1.69.2.3 yamt .pr_output = rip_output,
273 1.69.2.3 yamt .pr_ctlinput = rip_ctlinput,
274 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
275 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
276 1.69.2.3 yamt .pr_init = encap_init,
277 1.32 itojun },
278 1.32 itojun #endif /* INET6 */
279 1.69.2.2 yamt #if NETHERIP > 0
280 1.69.2.3 yamt { .pr_type = SOCK_RAW,
281 1.69.2.3 yamt .pr_domain = &inetdomain,
282 1.69.2.3 yamt .pr_protocol = IPPROTO_ETHERIP,
283 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
284 1.69.2.3 yamt .pr_input = ip_etherip_input,
285 1.69.2.3 yamt .pr_output = rip_output,
286 1.69.2.3 yamt .pr_ctlinput = rip_ctlinput,
287 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
288 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
289 1.67 kim },
290 1.69.2.3 yamt #endif /* NETHERIP > 0 */
291 1.69.2.1 yamt #if NCARP > 0
292 1.69.2.3 yamt { .pr_type = SOCK_RAW,
293 1.69.2.3 yamt .pr_domain = &inetdomain,
294 1.69.2.3 yamt .pr_protocol = IPPROTO_CARP,
295 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR,
296 1.69.2.3 yamt .pr_input = carp_proto_input,
297 1.69.2.3 yamt .pr_output = rip_output,
298 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
299 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
300 1.69.2.1 yamt },
301 1.69.2.3 yamt #endif /* NCARP > 0 */
302 1.69.2.3 yamt { .pr_type = SOCK_RAW,
303 1.69.2.3 yamt .pr_domain = &inetdomain,
304 1.69.2.3 yamt .pr_protocol = IPPROTO_IGMP,
305 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
306 1.69.2.3 yamt .pr_input = igmp_input,
307 1.69.2.3 yamt .pr_output = rip_output,
308 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
309 1.69.2.3 yamt .pr_ctlinput = rip_ctlinput,
310 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
311 1.69.2.3 yamt .pr_fasttimo = igmp_fasttimo,
312 1.69.2.3 yamt .pr_slowtimo = igmp_slowtimo,
313 1.1 cgd },
314 1.65 manu #ifdef PIM
315 1.69.2.3 yamt { .pr_type = SOCK_RAW,
316 1.69.2.3 yamt .pr_domain = &inetdomain,
317 1.69.2.3 yamt .pr_protocol = IPPROTO_PIM,
318 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
319 1.69.2.3 yamt .pr_input = pim_input,
320 1.69.2.3 yamt .pr_output = rip_output,
321 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
322 1.69.2.3 yamt .pr_ctlinput = rip_ctlinput,
323 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
324 1.65 manu },
325 1.65 manu #endif /* PIM */
326 1.1 cgd #ifdef TPIP
327 1.69.2.3 yamt { .pr_type = SOCK_SEQPACKET,
328 1.69.2.3 yamt .pr_domain = &inetdomain,
329 1.69.2.3 yamt .pr_protocol = IPPROTO_TP,
330 1.69.2.3 yamt .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_LASTHDR|PR_ABRTACPTDIS,
331 1.69.2.3 yamt .pr_input = tpip_input,
332 1.69.2.3 yamt .pr_ctloutput = tp_ctloutput,
333 1.69.2.3 yamt .pr_ctlinput = tpip_ctlinput,
334 1.69.2.3 yamt .pr_usrreq = tp_usrreq,
335 1.69.2.3 yamt .pr_init = tp_init,
336 1.69.2.3 yamt .pr_slowtimo = tp_slowtimo,
337 1.69.2.3 yamt .pr_drain = tp_drain,
338 1.1 cgd },
339 1.11 mycroft #endif /* TPIP */
340 1.45 itojun #ifdef ISO
341 1.1 cgd /* EON (ISO CLNL over IP) */
342 1.1 cgd #ifdef EON
343 1.69.2.3 yamt { .pr_type = SOCK_RAW,
344 1.69.2.3 yamt .pr_domain = &inetdomain,
345 1.69.2.3 yamt .pr_protocol = IPPROTO_EON,
346 1.69.2.3 yamt .pr_flags = PR_LASTHDR,
347 1.69.2.3 yamt .pr_input = eoninput,
348 1.69.2.3 yamt .pr_ctlinput = eonctlinput,
349 1.69.2.3 yamt .pr_init = eonprotoinit,
350 1.4 hpeyerl },
351 1.45 itojun #else
352 1.69.2.3 yamt { .pr_type = SOCK_RAW,
353 1.69.2.3 yamt .pr_domain = &inetdomain,
354 1.69.2.3 yamt .pr_protocol = IPPROTO_EON,
355 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
356 1.69.2.3 yamt .pr_input = encap4_input,
357 1.69.2.3 yamt .pr_output = rip_output,
358 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
359 1.69.2.3 yamt .pr_ctlinput = rip_ctlinput,
360 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
361 1.69.2.3 yamt .pr_init = encap_init,
362 1.45 itojun },
363 1.11 mycroft #endif /* EON */
364 1.45 itojun #endif /* ISO */
365 1.11 mycroft /* raw wildcard */
366 1.69.2.3 yamt { .pr_type = SOCK_RAW,
367 1.69.2.3 yamt .pr_domain = &inetdomain,
368 1.69.2.3 yamt .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
369 1.69.2.3 yamt .pr_input = rip_input,
370 1.69.2.3 yamt .pr_output = rip_output,
371 1.69.2.3 yamt .pr_ctloutput = rip_ctloutput,
372 1.69.2.3 yamt .pr_ctlinput = rip_ctlinput,
373 1.69.2.3 yamt .pr_usrreq = rip_usrreq,
374 1.69.2.3 yamt .pr_init = rip_init,
375 1.1 cgd },
376 1.1 cgd };
377 1.1 cgd
378 1.69.2.2 yamt extern struct ifqueue ipintrq;
379 1.69.2.2 yamt
380 1.69.2.4 yamt const struct sockaddr_in in_any = {
381 1.69.2.4 yamt .sin_len = sizeof(struct sockaddr_in)
382 1.69.2.4 yamt , .sin_family = AF_INET
383 1.69.2.4 yamt , .sin_port = 0
384 1.69.2.4 yamt , .sin_addr = {.s_addr = 0 /* INADDR_ANY */}
385 1.69.2.4 yamt };
386 1.69.2.4 yamt
387 1.69.2.2 yamt struct domain inetdomain = {
388 1.69.2.2 yamt .dom_family = PF_INET, .dom_name = "internet", .dom_init = NULL,
389 1.69.2.2 yamt .dom_externalize = NULL, .dom_dispose = NULL,
390 1.69.2.2 yamt .dom_protosw = inetsw,
391 1.69.2.3 yamt .dom_protoswNPROTOSW = &inetsw[__arraycount(inetsw)],
392 1.69.2.2 yamt .dom_rtattach = rn_inithead,
393 1.69.2.2 yamt .dom_rtoffset = 32, .dom_maxrtkey = sizeof(struct sockaddr_in),
394 1.69.2.2 yamt #ifdef IPSELSRC
395 1.69.2.2 yamt .dom_ifattach = in_domifattach,
396 1.69.2.2 yamt .dom_ifdetach = in_domifdetach,
397 1.69.2.2 yamt #else
398 1.69.2.2 yamt .dom_ifattach = NULL,
399 1.69.2.2 yamt .dom_ifdetach = NULL,
400 1.69.2.2 yamt #endif
401 1.69.2.2 yamt .dom_ifqueues = { &ipintrq, NULL },
402 1.69.2.2 yamt .dom_link = { NULL },
403 1.69.2.2 yamt .dom_mowner = MOWNER_INIT("",""),
404 1.69.2.3 yamt .dom_sa_cmpofs = offsetof(struct sockaddr_in, sin_addr),
405 1.69.2.3 yamt .dom_sa_cmplen = sizeof(struct in_addr),
406 1.69.2.4 yamt .dom_sa_any = (const struct sockaddr *)&in_any,
407 1.69.2.4 yamt .dom_sockaddr_const_addr = sockaddr_in_const_addr,
408 1.69.2.4 yamt .dom_sockaddr_addr = sockaddr_in_addr,
409 1.69.2.3 yamt .dom_rtcache = LIST_HEAD_INITIALIZER(inetdomain.dom_rtcache)
410 1.69.2.2 yamt };
411 1.38 darrenr
412 1.38 darrenr u_char ip_protox[IPPROTO_MAX];
413 1.36 thorpej
414 1.40 itojun int icmperrppslim = 100; /* 100pps */
415 1.69.2.3 yamt
416 1.69.2.4 yamt static void
417 1.69.2.4 yamt sockaddr_in_addrlen(const struct sockaddr *sa, socklen_t *slenp)
418 1.69.2.4 yamt {
419 1.69.2.4 yamt socklen_t slen;
420 1.69.2.4 yamt
421 1.69.2.4 yamt if (slenp == NULL)
422 1.69.2.4 yamt return;
423 1.69.2.4 yamt
424 1.69.2.4 yamt slen = sockaddr_getlen(sa);
425 1.69.2.4 yamt *slenp = (socklen_t)MIN(sizeof(struct in_addr),
426 1.69.2.4 yamt slen - MIN(slen, offsetof(struct sockaddr_in, sin_addr)));
427 1.69.2.4 yamt }
428 1.69.2.4 yamt
429 1.69.2.4 yamt const void *
430 1.69.2.4 yamt sockaddr_in_const_addr(const struct sockaddr *sa, socklen_t *slenp)
431 1.69.2.4 yamt {
432 1.69.2.4 yamt const struct sockaddr_in *sin;
433 1.69.2.4 yamt
434 1.69.2.4 yamt sockaddr_in_addrlen(sa, slenp);
435 1.69.2.4 yamt sin = (const struct sockaddr_in *)sa;
436 1.69.2.4 yamt return &sin->sin_addr;
437 1.69.2.4 yamt }
438 1.69.2.4 yamt
439 1.69.2.4 yamt void *
440 1.69.2.4 yamt sockaddr_in_addr(struct sockaddr *sa, socklen_t *slenp)
441 1.69.2.4 yamt {
442 1.69.2.4 yamt struct sockaddr_in *sin;
443 1.69.2.4 yamt
444 1.69.2.4 yamt sockaddr_in_addrlen(sa, slenp);
445 1.69.2.4 yamt sin = (struct sockaddr_in *)sa;
446 1.69.2.4 yamt return &sin->sin_addr;
447 1.69.2.4 yamt }
448 1.69.2.4 yamt
449 1.69.2.3 yamt int
450 1.69.2.3 yamt sockaddr_in_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2)
451 1.69.2.3 yamt {
452 1.69.2.3 yamt uint_fast8_t len;
453 1.69.2.3 yamt const uint_fast8_t addrofs = offsetof(struct sockaddr_in, sin_addr),
454 1.69.2.3 yamt addrend = addrofs + sizeof(struct in_addr);
455 1.69.2.3 yamt int rc;
456 1.69.2.3 yamt const struct sockaddr_in *sin1, *sin2;
457 1.69.2.3 yamt
458 1.69.2.3 yamt sin1 = satocsin(sa1);
459 1.69.2.3 yamt sin2 = satocsin(sa2);
460 1.69.2.3 yamt
461 1.69.2.3 yamt len = MIN(addrend, MIN(sin1->sin_len, sin2->sin_len));
462 1.69.2.3 yamt
463 1.69.2.3 yamt if (len > addrofs &&
464 1.69.2.3 yamt (rc = memcmp(&sin1->sin_addr, &sin2->sin_addr,
465 1.69.2.3 yamt len - addrofs)) != 0)
466 1.69.2.3 yamt return rc;
467 1.69.2.3 yamt
468 1.69.2.3 yamt return sin1->sin_len - sin2->sin_len;
469 1.69.2.3 yamt }
470