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