xref: /openbsd/sys/netinet6/in6_proto.c (revision a6445c1d)
1 /*	$OpenBSD: in6_proto.c,v 1.75 2014/08/27 14:04:16 florian Exp $	*/
2 /*	$KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun 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  *	@(#)in_proto.c	8.1 (Berkeley) 6/10/93
62  */
63 
64 #include <sys/param.h>
65 #include <sys/socket.h>
66 #include <sys/protosw.h>
67 #include <sys/kernel.h>
68 #include <sys/domain.h>
69 #include <sys/mbuf.h>
70 
71 #include <net/if.h>
72 #include <net/radix.h>
73 #ifndef SMALL_KERNEL
74 #include <net/radix_mpath.h>
75 #endif
76 #include <net/route.h>
77 
78 #include <netinet/in.h>
79 #include <netinet/ip.h>
80 #include <netinet/ip_var.h>
81 #include <netinet/in_pcb.h>
82 #include <netinet/ip6.h>
83 #include <netinet6/ip6_var.h>
84 #include <netinet/icmp6.h>
85 
86 #include <netinet/tcp.h>
87 #include <netinet/tcp_timer.h>
88 #include <netinet/tcp_var.h>
89 #include <netinet/udp.h>
90 #include <netinet/udp_var.h>
91 #include <netinet/ip_ipsp.h>
92 #include <netinet/ip_ah.h>
93 #include <netinet/ip_esp.h>
94 #include <netinet/ip_ipip.h>
95 
96 #ifdef PIM
97 #include <netinet6/pim6_var.h>
98 #endif
99 
100 #include <netinet6/in6_var.h>
101 #include <netinet6/nd6.h>
102 #include <netinet6/ip6protosw.h>
103 
104 #include "gif.h"
105 #if NGIF > 0
106 #include <netinet/ip_ether.h>
107 #include <netinet6/in6_gif.h>
108 #endif
109 
110 #include "carp.h"
111 #if NCARP > 0
112 #include <netinet/ip_carp.h>
113 #endif
114 
115 #include "pf.h"
116 #if NPF > 0
117 #include <netinet6/ip6_divert.h>
118 #endif
119 
120 /*
121  * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
122  */
123 u_char ip6_protox[IPPROTO_MAX];
124 
125 struct ip6protosw inet6sw[] = {
126 { 0,		&inet6domain,	IPPROTO_IPV6,	0,
127   0,		0,		0,		0,
128   0,
129   ip6_init,	0,		frag6_slowtimo,	frag6_drain,
130   ip6_sysctl,
131 },
132 { SOCK_DGRAM,	&inet6domain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR|PR_SPLICE,
133   udp6_input,	0,		udp6_ctlinput,	ip6_ctloutput,
134   udp_usrreq,	0,
135   0,		0,		0,
136   udp_sysctl,
137 },
138 { SOCK_STREAM,	&inet6domain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS|PR_SPLICE,
139   tcp6_input,	0,		tcp6_ctlinput,	tcp_ctloutput,
140   tcp_usrreq,
141 #ifdef INET	/* don't call initialization and timeout routines twice */
142   0,		0,		0,		0,
143 #else
144   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	0,
145 #endif
146   tcp_sysctl,
147 },
148 { SOCK_RAW,	&inet6domain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
149   rip6_input,	rip6_output,	rip6_ctlinput,	rip6_ctloutput,
150   rip6_usrreq,
151   0,		0,		0,		0,		rip6_sysctl
152 },
153 { SOCK_RAW,	&inet6domain,	IPPROTO_ICMPV6,	PR_ATOMIC|PR_ADDR,
154   icmp6_input,	rip6_output,	rip6_ctlinput,	rip6_ctloutput,
155   rip6_usrreq,
156   icmp6_init,	icmp6_fasttimo,	0,		0,
157   icmp6_sysctl,
158 },
159 { SOCK_RAW,	&inet6domain,	IPPROTO_DSTOPTS,PR_ATOMIC|PR_ADDR,
160   dest6_input,	0,	 	0,		0,
161   0,
162   0,		0,		0,		0,
163 },
164 { SOCK_RAW,	&inet6domain,	IPPROTO_ROUTING,PR_ATOMIC|PR_ADDR,
165   route6_input,	0,	 	0,		0,
166   0,
167   0,		0,		0,		0,
168 },
169 { SOCK_RAW,	&inet6domain,	IPPROTO_FRAGMENT,PR_ATOMIC|PR_ADDR,
170   frag6_input,	0,	 	0,		0,
171   0,
172   0,		0,		0,		0,
173 },
174 #ifdef IPSEC
175 { SOCK_RAW,	&inet6domain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
176   ah6_input,	rip6_output, 	0,		rip6_ctloutput,
177   rip6_usrreq,
178   0,		0,		0,		0,
179   ah_sysctl,
180 },
181 { SOCK_RAW,	&inet6domain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
182   esp6_input,	rip6_output,	0,		rip6_ctloutput,
183   rip6_usrreq,
184   0,		0,		0,		0,
185   esp_sysctl,
186 },
187 { SOCK_RAW,	&inet6domain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
188   ipcomp6_input, rip6_output,	0,		rip6_ctloutput,
189   rip6_usrreq,
190   0,		0,		0,		0,
191   ipcomp_sysctl,
192 },
193 #endif /* IPSEC */
194 #if NGIF > 0
195 { SOCK_RAW,	&inet6domain,	IPPROTO_ETHERIP,PR_ATOMIC|PR_ADDR,
196   etherip_input6, rip6_output,	0,		rip6_ctloutput,
197   rip6_usrreq,
198   0,		0,		0,		0,		etherip_sysctl
199 },
200 { SOCK_RAW,	&inet6domain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR,
201   in6_gif_input, rip6_output,	0,		rip6_ctloutput,
202   rip6_usrreq,	/* XXX */
203   0,		0,		0,		0,
204 },
205 #ifdef INET
206 { SOCK_RAW,	&inet6domain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR,
207   in6_gif_input, rip6_output, 	0,		rip6_ctloutput,
208   rip6_usrreq,	/* XXX */
209   0,		0,		0,		0,
210 },
211 #endif /* INET */
212 #else /* NGIF */
213 { SOCK_RAW,	&inet6domain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR,
214   ip4_input6,	rip6_output,	0,		rip6_ctloutput,
215   rip6_usrreq,	/* XXX */
216   0,		0,		0,		0,		ipip_sysctl
217 },
218 #ifdef INET
219 { SOCK_RAW,	&inet6domain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR,
220   ip4_input6,	rip6_output,	0,		rip6_ctloutput,
221   rip6_usrreq,	/* XXX */
222   0,		0,		0,		0,
223 },
224 #endif /* INET */
225 #endif /* GIF */
226 #ifdef PIM
227 { SOCK_RAW,	&inet6domain,	IPPROTO_PIM,	PR_ATOMIC|PR_ADDR,
228   pim6_input,	rip6_output,	0,		rip6_ctloutput,
229   rip6_usrreq,
230   0,		0,		0,		0,		pim6_sysctl
231 },
232 #endif /* PIM */
233 #if NCARP > 0
234 { SOCK_RAW,	&inet6domain,	IPPROTO_CARP,	PR_ATOMIC|PR_ADDR,
235   carp6_proto_input,	rip6_output,	0,	rip6_ctloutput,
236   rip6_usrreq,
237   0,		0,		0,		0,		carp_sysctl
238 },
239 #endif /* NCARP */
240 #if NPF > 0
241 { SOCK_RAW,	&inet6domain,	IPPROTO_DIVERT,	PR_ATOMIC|PR_ADDR,
242   divert6_input,	0,		0,	rip6_ctloutput,
243   divert6_usrreq,
244   divert6_init,	0,		0,		0,		divert6_sysctl
245 },
246 #endif /* NPF > 0 */
247 /* raw wildcard */
248 { SOCK_RAW,	&inet6domain,	0,		PR_ATOMIC|PR_ADDR,
249   rip6_input,	rip6_output,	0,		rip6_ctloutput,
250   rip6_usrreq,	rip6_init,
251   0,		0,		0,
252 },
253 };
254 
255 struct domain inet6domain =
256     { AF_INET6, "internet6", 0, 0, 0,
257       (struct protosw *)inet6sw,
258       (struct protosw *)&inet6sw[nitems(inet6sw)], 0,
259 #ifndef SMALL_KERNEL
260       rn_mpath_inithead,
261 #else
262       rn_inithead,
263 #endif
264       offsetof(struct sockaddr_in6, sin6_addr) << 3,
265       sizeof(struct sockaddr_in6),
266       in6_domifattach, in6_domifdetach, };
267 
268 /*
269  * Internet configuration info
270  */
271 int	ip6_forwarding = 0;	/* no forwarding unless sysctl'd to enable */
272 int	ip6_mforwarding = 0;	/* no multicast forwarding unless ... */
273 int	ip6_multipath = 0;	/* no using multipath routes unless ... */
274 int	ip6_sendredirects = 1;
275 int	ip6_defhlim = IPV6_DEFHLIM;
276 int	ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
277 int	ip6_maxfragpackets = 200;
278 int	ip6_maxfrags = 200;
279 int	ip6_log_interval = 5;
280 int	ip6_hdrnestlimit = 10;	/* appropriate? */
281 int	ip6_dad_count = 1;	/* DupAddrDetectionTransmits */
282 int	ip6_dad_pending;	/* number of currently running DADs */
283 int	ip6_auto_flowlabel = 1;
284 int	ip6_use_deprecated = 1;	/* allow deprecated addr (RFC2462 5.5.4) */
285 int	ip6_rr_prune = 5;	/* router renumbering prefix
286 				 * walk list every 5 sec.    */
287 int	ip6_mcast_pmtu = 0;	/* enable pMTU discovery for multicast? */
288 const int ip6_v6only = 1;
289 int	ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */
290 int	ip6_maxifprefixes = 16; /* Max acceptable prefixes via RA per IF */
291 int	ip6_maxifdefrouters = 16; /* Max acceptable def routers via RA */
292 int	ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */
293 time_t	ip6_log_time = (time_t)0L;
294 
295 /* raw IP6 parameters */
296 /*
297  * Nominal space allocated to a raw ip socket.
298  */
299 #define	RIPV6SNDQ	8192
300 #define	RIPV6RCVQ	8192
301 
302 u_long	rip6_sendspace = RIPV6SNDQ;
303 u_long	rip6_recvspace = RIPV6RCVQ;
304 
305 /* ICMPV6 parameters */
306 int	icmp6_redirtimeout = 10 * 60;	/* 10 minutes */
307 int	icmp6errppslim = 100;		/* 100pps */
308 int	ip6_mtudisc_timeout = IPMTUDISCTIMEOUT;
309