1 /* $OpenBSD: in_proto.c,v 1.99 2022/08/15 09:11:38 mvs Exp $ */
2 /* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */
3
4 /*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 /*
34 * Copyright (c) 1982, 1986, 1993
35 * The Regents of the University of California. All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
62 *
63 * NRL grants permission for redistribution and use in source and binary
64 * forms, with or without modification, of the software and documentation
65 * created at NRL provided that the following conditions are met:
66 *
67 * 1. Redistributions of source code must retain the above copyright
68 * notice, this list of conditions and the following disclaimer.
69 * 2. Redistributions in binary form must reproduce the above copyright
70 * notice, this list of conditions and the following disclaimer in the
71 * documentation and/or other materials provided with the distribution.
72 * 3. All advertising materials mentioning features or use of this software
73 * must display the following acknowledgements:
74 * This product includes software developed by the University of
75 * California, Berkeley and its contributors.
76 * This product includes software developed at the Information
77 * Technology Division, US Naval Research Laboratory.
78 * 4. Neither the name of the NRL nor the names of its contributors
79 * may be used to endorse or promote products derived from this software
80 * without specific prior written permission.
81 *
82 * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
83 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
84 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
85 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NRL OR
86 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
87 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
88 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
89 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
91 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
92 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
93 *
94 * The views and conclusions contained in the software and documentation
95 * are those of the authors and should not be interpreted as representing
96 * official policies, either expressed or implied, of the US Naval
97 * Research Laboratory (NRL).
98 */
99
100 #include <sys/param.h>
101 #include <sys/socket.h>
102 #include <sys/protosw.h>
103 #include <sys/domain.h>
104 #include <sys/mbuf.h>
105
106 #include <net/if.h>
107 #include <net/if_var.h>
108 #include <net/route.h>
109 #include <net/rtable.h>
110
111 #include <netinet/in.h>
112 #include <netinet/ip.h>
113 #include <netinet/ip_var.h>
114 #include <netinet/ip_icmp.h>
115 #include <netinet/in_pcb.h>
116
117 #ifdef INET6
118 #include <netinet/ip6.h>
119 #endif
120
121 #include <netinet/igmp_var.h>
122 #include <netinet/tcp.h>
123 #include <netinet/tcp_timer.h>
124 #include <netinet/tcp_var.h>
125 #include <netinet/udp.h>
126 #include <netinet/udp_var.h>
127
128 /*
129 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
130 */
131
132 #include "gif.h"
133 #if NGIF > 0
134 #include <net/if_gif.h>
135 #endif
136
137 #ifdef INET6
138 #include <netinet6/ip6_var.h>
139 #endif /* INET6 */
140
141 #ifdef IPSEC
142 #include <netinet/ip_ipsp.h>
143 #endif
144
145 #include <netinet/ip_ether.h>
146 #include <netinet/ip_ipip.h>
147
148 #include "gre.h"
149 #if NGRE > 0
150 #include <netinet/ip_gre.h>
151 #include <net/if_gre.h>
152 #endif
153
154 #include "carp.h"
155 #if NCARP > 0
156 #include <netinet/ip_carp.h>
157 #endif
158
159 #include "pfsync.h"
160 #if NPFSYNC > 0
161 #include <net/pfvar.h>
162 #include <net/if_pfsync.h>
163 #endif
164
165 #include "pf.h"
166 #if NPF > 0
167 #include <netinet/ip_divert.h>
168 #endif
169
170 #include "etherip.h"
171 #if NETHERIP > 0
172 #include <net/if_etherip.h>
173 #endif
174
175 u_char ip_protox[IPPROTO_MAX];
176
177 const struct protosw inetsw[] = {
178 {
179 .pr_domain = &inetdomain,
180 .pr_init = ip_init,
181 .pr_slowtimo = ip_slowtimo,
182 .pr_sysctl = ip_sysctl
183 },
184 {
185 .pr_type = SOCK_DGRAM,
186 .pr_domain = &inetdomain,
187 .pr_protocol = IPPROTO_UDP,
188 .pr_flags = PR_ATOMIC|PR_ADDR|PR_SPLICE,
189 .pr_input = udp_input,
190 .pr_ctlinput = udp_ctlinput,
191 .pr_ctloutput = ip_ctloutput,
192 .pr_usrreqs = &udp_usrreqs,
193 .pr_init = udp_init,
194 .pr_sysctl = udp_sysctl
195 },
196 {
197 .pr_type = SOCK_STREAM,
198 .pr_domain = &inetdomain,
199 .pr_protocol = IPPROTO_TCP,
200 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS|PR_SPLICE,
201 .pr_input = tcp_input,
202 .pr_ctlinput = tcp_ctlinput,
203 .pr_ctloutput = tcp_ctloutput,
204 .pr_usrreqs = &tcp_usrreqs,
205 .pr_init = tcp_init,
206 .pr_slowtimo = tcp_slowtimo,
207 .pr_sysctl = tcp_sysctl
208 },
209 {
210 .pr_type = SOCK_RAW,
211 .pr_domain = &inetdomain,
212 .pr_protocol = IPPROTO_RAW,
213 .pr_flags = PR_ATOMIC|PR_ADDR,
214 .pr_input = rip_input,
215 .pr_ctloutput = rip_ctloutput,
216 .pr_usrreqs = &rip_usrreqs,
217 },
218 {
219 .pr_type = SOCK_RAW,
220 .pr_domain = &inetdomain,
221 .pr_protocol = IPPROTO_ICMP,
222 .pr_flags = PR_ATOMIC|PR_ADDR,
223 .pr_input = icmp_input,
224 .pr_ctloutput = rip_ctloutput,
225 .pr_usrreqs = &rip_usrreqs,
226 .pr_init = icmp_init,
227 .pr_sysctl = icmp_sysctl
228 },
229 {
230 .pr_type = SOCK_RAW,
231 .pr_domain = &inetdomain,
232 .pr_protocol = IPPROTO_IPV4,
233 .pr_flags = PR_ATOMIC|PR_ADDR,
234 #if NGIF > 0
235 .pr_input = in_gif_input,
236 #else
237 .pr_input = ipip_input,
238 #endif
239 .pr_ctloutput = rip_ctloutput,
240 .pr_usrreqs = &rip_usrreqs,
241 .pr_sysctl = ipip_sysctl,
242 .pr_init = ipip_init
243 },
244 #ifdef INET6
245 {
246 .pr_type = SOCK_RAW,
247 .pr_domain = &inetdomain,
248 .pr_protocol = IPPROTO_IPV6,
249 .pr_flags = PR_ATOMIC|PR_ADDR,
250 #if NGIF > 0
251 .pr_input = in_gif_input,
252 #else
253 .pr_input = ipip_input,
254 #endif
255 .pr_ctloutput = rip_ctloutput,
256 .pr_usrreqs = &rip_usrreqs, /* XXX */
257 },
258 #endif
259 #if defined(MPLS) && NGIF > 0
260 {
261 .pr_type = SOCK_RAW,
262 .pr_domain = &inetdomain,
263 .pr_protocol = IPPROTO_MPLS,
264 .pr_flags = PR_ATOMIC|PR_ADDR,
265 .pr_input = in_gif_input,
266 .pr_usrreqs = &rip_usrreqs,
267 },
268 #endif /* MPLS && GIF */
269 {
270 .pr_type = SOCK_RAW,
271 .pr_domain = &inetdomain,
272 .pr_protocol = IPPROTO_IGMP,
273 .pr_flags = PR_ATOMIC|PR_ADDR,
274 .pr_input = igmp_input,
275 .pr_ctloutput = rip_ctloutput,
276 .pr_usrreqs = &rip_usrreqs,
277 .pr_init = igmp_init,
278 .pr_fasttimo = igmp_fasttimo,
279 .pr_slowtimo = igmp_slowtimo,
280 .pr_sysctl = igmp_sysctl
281 },
282 #ifdef IPSEC
283 {
284 .pr_type = SOCK_RAW,
285 .pr_domain = &inetdomain,
286 .pr_protocol = IPPROTO_AH,
287 .pr_flags = PR_ATOMIC|PR_ADDR,
288 .pr_input = ah46_input,
289 .pr_ctlinput = ah4_ctlinput,
290 .pr_ctloutput = rip_ctloutput,
291 .pr_usrreqs = &rip_usrreqs,
292 .pr_sysctl = ah_sysctl
293 },
294 {
295 .pr_type = SOCK_RAW,
296 .pr_domain = &inetdomain,
297 .pr_protocol = IPPROTO_ESP,
298 .pr_flags = PR_ATOMIC|PR_ADDR,
299 .pr_input = esp46_input,
300 .pr_ctlinput = esp4_ctlinput,
301 .pr_ctloutput = rip_ctloutput,
302 .pr_usrreqs = &rip_usrreqs,
303 .pr_sysctl = esp_sysctl
304 },
305 {
306 .pr_type = SOCK_RAW,
307 .pr_domain = &inetdomain,
308 .pr_protocol = IPPROTO_IPCOMP,
309 .pr_flags = PR_ATOMIC|PR_ADDR,
310 .pr_input = ipcomp46_input,
311 .pr_ctloutput = rip_ctloutput,
312 .pr_usrreqs = &rip_usrreqs,
313 .pr_sysctl = ipcomp_sysctl
314 },
315 #endif /* IPSEC */
316 #if NGRE > 0
317 {
318 .pr_type = SOCK_RAW,
319 .pr_domain = &inetdomain,
320 .pr_protocol = IPPROTO_GRE,
321 .pr_flags = PR_ATOMIC|PR_ADDR,
322 .pr_input = gre_input,
323 .pr_ctloutput = rip_ctloutput,
324 .pr_usrreqs = &gre_usrreqs,
325 .pr_sysctl = gre_sysctl
326 },
327 #endif /* NGRE > 0 */
328 #if NCARP > 0
329 {
330 .pr_type = SOCK_RAW,
331 .pr_domain = &inetdomain,
332 .pr_protocol = IPPROTO_CARP,
333 .pr_flags = PR_ATOMIC|PR_ADDR,
334 .pr_input = carp_proto_input,
335 .pr_ctloutput = rip_ctloutput,
336 .pr_usrreqs = &rip_usrreqs,
337 .pr_sysctl = carp_sysctl
338 },
339 #endif /* NCARP > 0 */
340 #if NPFSYNC > 0
341 {
342 .pr_type = SOCK_RAW,
343 .pr_domain = &inetdomain,
344 .pr_protocol = IPPROTO_PFSYNC,
345 .pr_flags = PR_ATOMIC|PR_ADDR,
346 .pr_input = pfsync_input,
347 .pr_ctloutput = rip_ctloutput,
348 .pr_usrreqs = &rip_usrreqs,
349 .pr_sysctl = pfsync_sysctl
350 },
351 #endif /* NPFSYNC > 0 */
352 #if NPF > 0
353 {
354 .pr_type = SOCK_RAW,
355 .pr_domain = &inetdomain,
356 .pr_protocol = IPPROTO_DIVERT,
357 .pr_flags = PR_ATOMIC|PR_ADDR,
358 .pr_ctloutput = rip_ctloutput,
359 .pr_usrreqs = &divert_usrreqs,
360 .pr_init = divert_init,
361 .pr_sysctl = divert_sysctl
362 },
363 #endif /* NPF > 0 */
364 #if NETHERIP > 0
365 {
366 .pr_type = SOCK_RAW,
367 .pr_domain = &inetdomain,
368 .pr_protocol = IPPROTO_ETHERIP,
369 .pr_flags = PR_ATOMIC|PR_ADDR,
370 .pr_input = ip_etherip_input,
371 .pr_ctloutput = rip_ctloutput,
372 .pr_usrreqs = &rip_usrreqs,
373 .pr_sysctl = etherip_sysctl
374 },
375 #endif /* NETHERIP */
376 {
377 /* raw wildcard */
378 .pr_type = SOCK_RAW,
379 .pr_domain = &inetdomain,
380 .pr_flags = PR_ATOMIC|PR_ADDR,
381 .pr_input = rip_input,
382 .pr_ctloutput = rip_ctloutput,
383 .pr_usrreqs = &rip_usrreqs,
384 .pr_init = rip_init
385 }
386 };
387
388 const struct domain inetdomain = {
389 .dom_family = AF_INET,
390 .dom_name = "internet",
391 .dom_init = in_init,
392 .dom_protosw = inetsw,
393 .dom_protoswNPROTOSW = &inetsw[nitems(inetsw)],
394 .dom_sasize = sizeof(struct sockaddr_in),
395 .dom_rtoffset = offsetof(struct sockaddr_in, sin_addr),
396 .dom_maxplen = 32
397 };
Cache object: bf8ee0fd3077878a64ce966d221dbff9
|