xref: /openbsd-src/sys/netinet/in_proto.c (revision 2b0358df1d88d06ef4139321dd05bd5e05d91eaf)
1 /*	$OpenBSD: in_proto.c,v 1.48 2008/05/06 08:47:35 markus 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/route.h>
108 #include <net/radix.h>
109 #ifndef SMALL_KERNEL
110 #include <net/radix_mpath.h>
111 #endif
112 
113 #include <netinet/in.h>
114 #include <netinet/in_systm.h>
115 #include <netinet/ip.h>
116 #include <netinet/ip_var.h>
117 #include <netinet/ip_icmp.h>
118 #include <netinet/in_pcb.h>
119 
120 #ifdef INET6
121 #ifndef INET
122 #include <netinet/in.h>
123 #endif
124 #include <netinet/ip6.h>
125 #endif
126 
127 #include <netinet/igmp_var.h>
128 #ifdef PIM
129 #include <netinet/pim_var.h>
130 #endif
131 #include <netinet/tcp.h>
132 #include <netinet/tcp_timer.h>
133 #include <netinet/tcp_var.h>
134 #include <netinet/udp.h>
135 #include <netinet/udp_var.h>
136 
137 /*
138  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
139  */
140 
141 #include "gif.h"
142 #if NGIF > 0
143 #include <netinet/in_gif.h>
144 #endif
145 
146 #ifdef INET6
147 #include <netinet6/ip6_var.h>
148 #endif /* INET6 */
149 
150 #ifdef IPSEC
151 #include <netinet/ip_ipsp.h>
152 #include <netinet/ip_ether.h>
153 #endif
154 
155 #include <netinet/ip_ipip.h>
156 
157 #include "gre.h"
158 #if NGRE > 0
159 #include <netinet/ip_gre.h>
160 #include <net/if_gre.h>
161 #endif
162 
163 #include "carp.h"
164 #if NCARP > 0
165 #include <netinet/ip_carp.h>
166 #endif
167 
168 #include "pfsync.h"
169 #if NPFSYNC > 0
170 #include <net/pfvar.h>
171 #include <net/if_pfsync.h>
172 #endif
173 
174 extern	struct domain inetdomain;
175 
176 struct protosw inetsw[] = {
177 { 0,		&inetdomain,	0,		0,
178   0,		ip_output,	0,		0,
179   0,
180   ip_init,	0,		ip_slowtimo,	ip_drain,	ip_sysctl
181 },
182 { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
183   udp_input,	0,		udp_ctlinput,	ip_ctloutput,
184   udp_usrreq,
185   udp_init,	0,		0,		0,		udp_sysctl
186 },
187 { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS,
188   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
189   tcp_usrreq,
190   tcp_init,	0,		tcp_slowtimo,	0,		tcp_sysctl
191 },
192 { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
193   rip_input,	rip_output,	0,		rip_ctloutput,
194   rip_usrreq,
195   0,		0,		0,		0,
196 },
197 { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR,
198   icmp_input,	rip_output,	0,		rip_ctloutput,
199   rip_usrreq,
200   icmp_init,	0,		0,		0,		icmp_sysctl
201 },
202 #if NGIF > 0
203 { SOCK_RAW,	&inetdomain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR,
204   in_gif_input,	rip_output, 	0,		rip_ctloutput,
205   rip_usrreq,
206   0,		0,		0,		0,		ipip_sysctl
207 },
208 #ifdef INET6
209 { SOCK_RAW,	&inetdomain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR,
210   in_gif_input,	rip_output,	 0,		0,
211   rip_usrreq,	/*XXX*/
212   0,		0,		0,		0,
213 },
214 #endif /* INET6 */
215 #else /* NGIF */
216 { SOCK_RAW,	&inetdomain,	IPPROTO_IPIP,	PR_ATOMIC|PR_ADDR,
217   ip4_input,	rip_output,	0,		rip_ctloutput,
218   rip_usrreq,
219   0,		0,		0,		0,		ipip_sysctl
220 },
221 #ifdef INET6
222 { SOCK_RAW,	&inetdomain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR,
223   ip4_input,	rip_output, 	0,		rip_ctloutput,
224   rip_usrreq,	/*XXX*/
225   0,		0,		0,		0,
226 },
227 #endif /* INET6 */
228 #endif /*NGIF*/
229 { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR,
230   igmp_input,	rip_output,	0,		rip_ctloutput,
231   rip_usrreq,
232   igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,		igmp_sysctl
233 },
234 #ifdef PIM
235 { SOCK_RAW,	&inetdomain,	IPPROTO_PIM,	PR_ATOMIC|PR_ADDR,
236   pim_input,	rip_output,	0,		rip_ctloutput,
237   rip_usrreq,
238   0,		0,		0,		0,		pim_sysctl
239 },
240 #endif /* PIM */
241 #ifdef IPSEC
242 { SOCK_RAW,   &inetdomain,    IPPROTO_AH,     PR_ATOMIC|PR_ADDR,
243   ah4_input,   rip_output,    ah4_ctlinput,   rip_ctloutput,
244   rip_usrreq,
245   0,          0,              0,              0,		ah_sysctl
246 },
247 { SOCK_RAW,   &inetdomain,    IPPROTO_ESP,    PR_ATOMIC|PR_ADDR,
248   esp4_input,  rip_output,    esp4_ctlinput,  rip_ctloutput,
249   rip_usrreq,
250   0,          0,              0,              0,		esp_sysctl
251 },
252 { SOCK_RAW,   &inetdomain,    IPPROTO_ETHERIP, PR_ATOMIC|PR_ADDR,
253   etherip_input,  rip_output, 0,              rip_ctloutput,
254   rip_usrreq,
255   0,          0,              0,              0,		etherip_sysctl
256 },
257 { SOCK_RAW,   &inetdomain,    IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
258   ipcomp4_input,  rip_output, 0,              rip_ctloutput,
259   rip_usrreq,
260   0,          0,              0,              0,                ipcomp_sysctl
261 },
262 #endif /* IPSEC */
263 #if NGRE > 0
264 { SOCK_RAW,     &inetdomain,    IPPROTO_GRE,    PR_ATOMIC|PR_ADDR,
265   gre_input,    rip_output,     0,              rip_ctloutput,
266   rip_usrreq,
267   0,            0,              0,             0,		gre_sysctl
268 },
269 { SOCK_RAW,     &inetdomain,    IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR,
270   gre_mobile_input,     rip_output,     0,              rip_ctloutput,
271   rip_usrreq,
272   0,            0,              0,              0,		ipmobile_sysctl
273 },
274 #endif /* NGRE > 0 */
275 #if NCARP > 0
276 { SOCK_RAW,	&inetdomain,	IPPROTO_CARP,	PR_ATOMIC|PR_ADDR,
277   carp_proto_input,	rip_output,	0,		rip_ctloutput,
278   rip_usrreq,
279   0,		0,		0,		0,		carp_sysctl
280 },
281 #endif /* NCARP > 0 */
282 #if NPFSYNC > 0
283 { SOCK_RAW,	&inetdomain,	IPPROTO_PFSYNC,	PR_ATOMIC|PR_ADDR,
284   pfsync_input,	rip_output,	0,		rip_ctloutput,
285   rip_usrreq,
286   0,		0,		0,		0,		pfsync_sysctl
287 },
288 #endif /* NPFSYNC > 0 */
289 /* raw wildcard */
290 { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR,
291   rip_input,	rip_output,	0,		rip_ctloutput,
292   rip_usrreq,
293   rip_init,	0,		0,		0,
294 },
295 };
296 
297 struct domain inetdomain =
298     { AF_INET, "internet", 0, 0, 0,
299       inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
300 #ifndef SMALL_KERNEL
301       rn_mpath_inithead,
302 #else
303       rn_inithead,
304 #endif
305       32, sizeof(struct sockaddr_in) };
306 
307 #ifdef notyet /* XXXX */
308 #include "hy.h"
309 #if NHY > 0
310 /*
311  * HYPERchannel protocol family: raw interface.
312  */
313 int	rhy_output();
314 extern	struct domain hydomain;
315 
316 struct protosw hysw[] = {
317 { SOCK_RAW,	&hydomain,	0,		PR_ATOMIC|PR_ADDR,
318   0,		rhy_output,	0,		0,
319   rip_usrreq,
320   0,		0,		0,		0,
321 },
322 };
323 
324 struct domain hydomain =
325     { AF_HYLINK, "hy", 0, 0, 0, hysw, &hysw[sizeof (hysw)/sizeof(hysw[0])] };
326 #endif
327 #endif
328