in6_proto.c revision 211115
1139826Simp/*-
253541Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
353541Sshin * All rights reserved.
453541Sshin *
553541Sshin * Redistribution and use in source and binary forms, with or without
653541Sshin * modification, are permitted provided that the following conditions
753541Sshin * are met:
853541Sshin * 1. Redistributions of source code must retain the above copyright
953541Sshin *    notice, this list of conditions and the following disclaimer.
1053541Sshin * 2. Redistributions in binary form must reproduce the above copyright
1153541Sshin *    notice, this list of conditions and the following disclaimer in the
1253541Sshin *    documentation and/or other materials provided with the distribution.
1353541Sshin * 3. Neither the name of the project nor the names of its contributors
1453541Sshin *    may be used to endorse or promote products derived from this software
1553541Sshin *    without specific prior written permission.
1653541Sshin *
1753541Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1853541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1953541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2053541Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2153541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2253541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2353541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2453541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2553541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2653541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2753541Sshin * SUCH DAMAGE.
28174510Sobrien *
29174510Sobrien *	$KAME: in6_proto.c,v 1.91 2001/05/27 13:28:35 itojun Exp $
3053541Sshin */
3153541Sshin
32139826Simp/*-
3353541Sshin * Copyright (c) 1982, 1986, 1993
3453541Sshin *	The Regents of the University of California.  All rights reserved.
3553541Sshin *
3653541Sshin * Redistribution and use in source and binary forms, with or without
3753541Sshin * modification, are permitted provided that the following conditions
3853541Sshin * are met:
3953541Sshin * 1. Redistributions of source code must retain the above copyright
4053541Sshin *    notice, this list of conditions and the following disclaimer.
4153541Sshin * 2. Redistributions in binary form must reproduce the above copyright
4253541Sshin *    notice, this list of conditions and the following disclaimer in the
4353541Sshin *    documentation and/or other materials provided with the distribution.
4453541Sshin * 4. Neither the name of the University nor the names of its contributors
4553541Sshin *    may be used to endorse or promote products derived from this software
4653541Sshin *    without specific prior written permission.
4753541Sshin *
4853541Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
4953541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5053541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5153541Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5253541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5353541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5453541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5553541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5653541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5753541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5853541Sshin * SUCH DAMAGE.
5953541Sshin *
6053541Sshin *	@(#)in_proto.c	8.1 (Berkeley) 6/10/93
6153541Sshin */
6253541Sshin
63174510Sobrien#include <sys/cdefs.h>
64174510Sobrien__FBSDID("$FreeBSD: head/sys/netinet6/in6_proto.c 211115 2010-08-09 19:53:24Z bz $");
65174510Sobrien
6655679Sshin#include "opt_inet.h"
6762587Sitojun#include "opt_inet6.h"
6855009Sshin#include "opt_ipsec.h"
69148921Ssuz#include "opt_ipstealth.h"
70142215Sglebius#include "opt_carp.h"
71163953Srrs#include "opt_sctp.h"
72178167Sqingli#include "opt_mpath.h"
73207828Skmacy#include "opt_route.h"
7455009Sshin
7553541Sshin#include <sys/param.h>
7653541Sshin#include <sys/socket.h>
7753541Sshin#include <sys/socketvar.h>
78185895Szec#include <sys/proc.h>
7953541Sshin#include <sys/protosw.h>
80194368Sbz#include <sys/jail.h>
8153541Sshin#include <sys/kernel.h>
8253541Sshin#include <sys/domain.h>
8353541Sshin#include <sys/mbuf.h>
8453541Sshin#include <sys/systm.h>
8553541Sshin#include <sys/sysctl.h>
8653541Sshin
8753541Sshin#include <net/if.h>
8853541Sshin#include <net/radix.h>
8953541Sshin#include <net/route.h>
90178167Sqingli#ifdef RADIX_MPATH
91178167Sqingli#include <net/radix_mpath.h>
92178167Sqingli#endif
9353541Sshin
9453541Sshin#include <netinet/in.h>
9553541Sshin#include <netinet/in_systm.h>
9653541Sshin#include <netinet/in_var.h>
9762587Sitojun#include <netinet/ip_encap.h>
9853541Sshin#include <netinet/ip.h>
9953541Sshin#include <netinet/ip_var.h>
10062587Sitojun#include <netinet/ip6.h>
10153541Sshin#include <netinet6/ip6_var.h>
10262587Sitojun#include <netinet/icmp6.h>
10353541Sshin
10453541Sshin#include <netinet/tcp.h>
10553541Sshin#include <netinet/tcp_timer.h>
10653541Sshin#include <netinet/tcp_var.h>
10753541Sshin#include <netinet/udp.h>
10853541Sshin#include <netinet/udp_var.h>
10953541Sshin#include <netinet6/tcp6_var.h>
11078064Sume#include <netinet6/raw_ip6.h>
11153541Sshin#include <netinet6/udp6_var.h>
11253541Sshin#include <netinet6/pim6_var.h>
11353541Sshin#include <netinet6/nd6.h>
11453541Sshin
115142215Sglebius#ifdef DEV_CARP
116142215Sglebius#include <netinet/ip_carp.h>
117142215Sglebius#endif
118142215Sglebius
119163953Srrs#ifdef SCTP
120163953Srrs#include <netinet/in_pcb.h>
121163953Srrs#include <netinet/sctp_pcb.h>
122163953Srrs#include <netinet/sctp.h>
123163953Srrs#include <netinet/sctp_var.h>
124163953Srrs#include <netinet6/sctp6_var.h>
125163953Srrs#endif /* SCTP */
126163953Srrs
127171167Sgnn#ifdef IPSEC
128171133Sgnn#include <netipsec/ipsec.h>
129105199Ssam#include <netipsec/ipsec6.h>
130171167Sgnn#endif /* IPSEC */
131105199Ssam
13253541Sshin#include <netinet6/ip6protosw.h>
13353541Sshin
134207828Skmacy#ifdef FLOWTABLE
135207828Skmacy#include <net/flowtable.h>
136207828Skmacy#endif
137207828Skmacy
13853541Sshin/*
13953541Sshin * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
14053541Sshin */
14153541Sshin
14262587Sitojunextern	struct domain inet6domain;
143148917Sobrienstatic	struct pr_usrreqs nousrreqs;
14453541Sshin
14578064Sume#define PR_LISTEN	0
14678064Sume#define PR_ABRTACPTDIS	0
14778064Sume
148211115Sbz/* Spacer for loadable protocols. */
149211115Sbz#define IP6PROTOSPACER   			\
150211115Sbz{						\
151211115Sbz	.pr_domain =		&inet6domain,	\
152211115Sbz	.pr_protocol =		PROTO_SPACER,	\
153211115Sbz	.pr_usrreqs =		&nousrreqs	\
154211115Sbz}
155211115Sbz
15653541Sshinstruct ip6protosw inet6sw[] = {
157152242Sru{
158152242Sru	.pr_type =		0,
159152242Sru	.pr_domain =		&inet6domain,
160152242Sru	.pr_protocol =		IPPROTO_IPV6,
161152242Sru	.pr_init =		ip6_init,
162193731Szec#ifdef VIMAGE
163193731Szec	.pr_destroy =		ip6_destroy,
164193731Szec#endif
165152242Sru	.pr_slowtimo =		frag6_slowtimo,
166152242Sru	.pr_drain =		frag6_drain,
167152242Sru	.pr_usrreqs =		&nousrreqs,
16853541Sshin},
169152242Sru{
170152242Sru	.pr_type =		SOCK_DGRAM,
171152242Sru	.pr_domain =		&inet6domain,
172152242Sru	.pr_protocol =		IPPROTO_UDP,
173152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
174152242Sru	.pr_input =		udp6_input,
175152242Sru	.pr_ctlinput =		udp6_ctlinput,
176152242Sru	.pr_ctloutput =		ip6_ctloutput,
177152242Sru	.pr_usrreqs =		&udp6_usrreqs,
17854263Sshin},
179152242Sru{
180152242Sru	.pr_type =		SOCK_STREAM,
181152242Sru	.pr_domain =		&inet6domain,
182152242Sru	.pr_protocol =		IPPROTO_TCP,
183152242Sru	.pr_flags =		PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
184152242Sru	.pr_input =		tcp6_input,
185152242Sru	.pr_ctlinput =		tcp6_ctlinput,
186152242Sru	.pr_ctloutput =		tcp_ctloutput,
187152242Sru#ifndef INET	/* don't call initialization and timeout routines twice */
188152242Sru	.pr_init =		tcp_init,
189152242Sru	.pr_slowtimo =		tcp_slowtimo,
19055679Sshin#endif
191152242Sru	.pr_drain =		tcp_drain,
192152242Sru	.pr_usrreqs =		&tcp6_usrreqs,
19355679Sshin},
194163953Srrs#ifdef SCTP
195171260Sdelphij{
196171260Sdelphij	.pr_type =	SOCK_DGRAM,
197171260Sdelphij	.pr_domain =	&inet6domain,
198171260Sdelphij        .pr_protocol =	IPPROTO_SCTP,
199171260Sdelphij        .pr_flags =	PR_WANTRCVD,
200171260Sdelphij        .pr_input =	sctp6_input,
201171260Sdelphij        .pr_ctlinput =  sctp6_ctlinput,
202163953Srrs        .pr_ctloutput = sctp_ctloutput,
203171260Sdelphij        .pr_drain =	sctp_drain,
204171260Sdelphij        .pr_usrreqs =	&sctp6_usrreqs
205163953Srrs},
206152242Sru{
207171260Sdelphij	.pr_type =	SOCK_SEQPACKET,
208171260Sdelphij	.pr_domain =	&inet6domain,
209171260Sdelphij        .pr_protocol =	IPPROTO_SCTP,
210171260Sdelphij        .pr_flags =	PR_WANTRCVD,
211171260Sdelphij        .pr_input =	sctp6_input,
212171260Sdelphij        .pr_ctlinput =  sctp6_ctlinput,
213163953Srrs        .pr_ctloutput = sctp_ctloutput,
214171260Sdelphij        .pr_drain =	sctp_drain,
215171260Sdelphij        .pr_usrreqs =	&sctp6_usrreqs
216163953Srrs},
217163953Srrs
218171260Sdelphij{
219171260Sdelphij	.pr_type =	SOCK_STREAM,
220171260Sdelphij	.pr_domain =	&inet6domain,
221171260Sdelphij        .pr_protocol =	IPPROTO_SCTP,
222171260Sdelphij        .pr_flags =	PR_WANTRCVD,
223171260Sdelphij        .pr_input =	sctp6_input,
224171260Sdelphij        .pr_ctlinput =  sctp6_ctlinput,
225163953Srrs        .pr_ctloutput = sctp_ctloutput,
226171260Sdelphij        .pr_drain =	sctp_drain,
227171260Sdelphij        .pr_usrreqs =	&sctp6_usrreqs
228163953Srrs},
229163953Srrs#endif /* SCTP */
230163953Srrs{
231152242Sru	.pr_type =		SOCK_RAW,
232152242Sru	.pr_domain =		&inet6domain,
233152242Sru	.pr_protocol =		IPPROTO_RAW,
234152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
235152242Sru	.pr_input =		rip6_input,
236152242Sru	.pr_output =		rip6_output,
237152242Sru	.pr_ctlinput =		rip6_ctlinput,
238152242Sru	.pr_ctloutput =		rip6_ctloutput,
239152242Sru	.pr_usrreqs =		&rip6_usrreqs
24053541Sshin},
241152242Sru{
242152242Sru	.pr_type =		SOCK_RAW,
243152242Sru	.pr_domain =		&inet6domain,
244152242Sru	.pr_protocol =		IPPROTO_ICMPV6,
245152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
246152242Sru	.pr_input =		icmp6_input,
247152242Sru	.pr_output =		rip6_output,
248152242Sru	.pr_ctlinput =		rip6_ctlinput,
249152242Sru	.pr_ctloutput =		rip6_ctloutput,
250152242Sru	.pr_fasttimo =		icmp6_fasttimo,
251191672Sbms	.pr_slowtimo =		icmp6_slowtimo,
252152242Sru	.pr_usrreqs =		&rip6_usrreqs
25353541Sshin},
254152242Sru{
255152242Sru	.pr_type =		SOCK_RAW,
256152242Sru	.pr_domain =		&inet6domain,
257152242Sru	.pr_protocol =		IPPROTO_DSTOPTS,
258152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
259152242Sru	.pr_input =		dest6_input,
260152242Sru	.pr_usrreqs =		&nousrreqs
26153541Sshin},
262152242Sru{
263152242Sru	.pr_type =		SOCK_RAW,
264152242Sru	.pr_domain =		&inet6domain,
265152242Sru	.pr_protocol =		IPPROTO_ROUTING,
266152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
267152242Sru	.pr_input =		route6_input,
268152242Sru	.pr_usrreqs =		&nousrreqs
26953541Sshin},
270152242Sru{
271152242Sru	.pr_type =		SOCK_RAW,
272152242Sru	.pr_domain =		&inet6domain,
273152242Sru	.pr_protocol =		IPPROTO_FRAGMENT,
274152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
275152242Sru	.pr_input =		frag6_input,
276152242Sru	.pr_usrreqs =		&nousrreqs
27753541Sshin},
278171167Sgnn#ifdef IPSEC
279152242Sru{
280152242Sru	.pr_type =		SOCK_RAW,
281152242Sru	.pr_domain =		&inet6domain,
282152242Sru	.pr_protocol =		IPPROTO_AH,
283152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
284171133Sgnn	.pr_input =		ipsec6_common_input,
285152242Sru	.pr_usrreqs =		&nousrreqs,
28653541Sshin},
287152242Sru{
288152242Sru	.pr_type =		SOCK_RAW,
289152242Sru	.pr_domain =		&inet6domain,
290152242Sru	.pr_protocol =		IPPROTO_ESP,
291152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
292171133Sgnn        .pr_input =		ipsec6_common_input,
293152242Sru	.pr_ctlinput =		esp6_ctlinput,
294152242Sru	.pr_usrreqs =		&nousrreqs,
29553541Sshin},
296152242Sru{
297152242Sru	.pr_type =		SOCK_RAW,
298152242Sru	.pr_domain =		&inet6domain,
299152242Sru	.pr_protocol =		IPPROTO_IPCOMP,
300152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
301171133Sgnn        .pr_input =		ipsec6_common_input,
302152242Sru	.pr_usrreqs =		&nousrreqs,
30362587Sitojun},
304171167Sgnn#endif /* IPSEC */
30562587Sitojun#ifdef INET
306152242Sru{
307152242Sru	.pr_type =		SOCK_RAW,
308152242Sru	.pr_domain =		&inet6domain,
309152242Sru	.pr_protocol =		IPPROTO_IPV4,
310152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
311152242Sru	.pr_input =		encap6_input,
312152242Sru	.pr_output =		rip6_output,
313152242Sru	.pr_ctloutput =		rip6_ctloutput,
314152242Sru	.pr_init =		encap_init,
315152242Sru	.pr_usrreqs =		&rip6_usrreqs
31653541Sshin},
31795023Ssuz#endif /* INET */
318152242Sru{
319152242Sru	.pr_type =		SOCK_RAW,
320152242Sru	.pr_domain =		&inet6domain,
321152242Sru	.pr_protocol =		IPPROTO_IPV6,
322152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
323152242Sru	.pr_input =		encap6_input,
324152242Sru	.pr_output =		rip6_output,
325152242Sru	.pr_ctloutput =		rip6_ctloutput,
326152242Sru	.pr_init =		encap_init,
327152242Sru	.pr_usrreqs =		&rip6_usrreqs
32853541Sshin},
329152242Sru{
330152242Sru	.pr_type =		SOCK_RAW,
331152242Sru	.pr_domain =		&inet6domain,
332152242Sru	.pr_protocol =		IPPROTO_PIM,
333152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
334166938Sbms	.pr_input =		encap6_input,
335152242Sru	.pr_output =		rip6_output,
336152242Sru	.pr_ctloutput =		rip6_ctloutput,
337152242Sru	.pr_usrreqs =		&rip6_usrreqs
33856722Sshin},
339142215Sglebius#ifdef DEV_CARP
340152242Sru{
341152242Sru	.pr_type =		SOCK_RAW,
342152242Sru	.pr_domain =		&inet6domain,
343152242Sru	.pr_protocol =		IPPROTO_CARP,
344152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
345152242Sru	.pr_input =		carp6_input,
346152242Sru	.pr_output =		rip6_output,
347152242Sru	.pr_ctloutput =		rip6_ctloutput,
348152242Sru	.pr_usrreqs =		&rip6_usrreqs
349142215Sglebius},
350142215Sglebius#endif /* DEV_CARP */
351211115Sbz/* Spacer n-times for loadable protocols. */
352211115SbzIP6PROTOSPACER,
353211115SbzIP6PROTOSPACER,
354211115SbzIP6PROTOSPACER,
355211115SbzIP6PROTOSPACER,
356211115SbzIP6PROTOSPACER,
357211115SbzIP6PROTOSPACER,
358211115SbzIP6PROTOSPACER,
359211115SbzIP6PROTOSPACER,
36053541Sshin/* raw wildcard */
361152242Sru{
362152242Sru	.pr_type =		SOCK_RAW,
363152242Sru	.pr_domain =		&inet6domain,
364152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
365152242Sru	.pr_input =		rip6_input,
366152242Sru	.pr_output =		rip6_output,
367152242Sru	.pr_ctloutput =		rip6_ctloutput,
368152242Sru	.pr_usrreqs =		&rip6_usrreqs
36953541Sshin},
37053541Sshin};
37153541Sshin
372175162Sobrienextern int in6_inithead(void **, int);
373193731Szec#ifdef VIMAGE
374193731Szecextern int in6_detachhead(void **, int);
375193731Szec#endif
37662587Sitojun
377152242Srustruct domain inet6domain = {
378152242Sru	.dom_family =		AF_INET6,
379152242Sru	.dom_name =		"internet6",
380152242Sru	.dom_protosw =		(struct protosw *)inet6sw,
381152242Sru	.dom_protoswNPROTOSW =	(struct protosw *)
382152242Sru				&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])],
383178167Sqingli#ifdef RADIX_MPATH
384178167Sqingli	.dom_rtattach =		rn6_mpath_inithead,
385178167Sqingli#else
386152242Sru	.dom_rtattach =		in6_inithead,
387178167Sqingli#endif
388193731Szec#ifdef VIMAGE
389193731Szec	.dom_rtdetach =		in6_detachhead,
390193731Szec#endif
391152242Sru	.dom_rtoffset =		offsetof(struct sockaddr_in6, sin6_addr) << 3,
392152242Sru	.dom_maxrtkey =		sizeof(struct sockaddr_in6),
393152242Sru	.dom_ifattach =		in6_domifattach,
394152242Sru	.dom_ifdetach =		in6_domifdetach
395152242Sru};
39653541Sshin
397195837SrwatsonVNET_DOMAIN_SET(inet6);
39853541Sshin
39953541Sshin/*
40053541Sshin * Internet configuration info
40153541Sshin */
402207369Sbz#ifndef	IPV6FORWARDING
403207369Sbz#ifdef GATEWAY6
404207369Sbz#define	IPV6FORWARDING	1	/* forward IP6 packets not for us */
405207369Sbz#else
406207369Sbz#define	IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
407207369Sbz#endif /* GATEWAY6 */
408207369Sbz#endif /* !IPV6FORWARDING */
40953541Sshin
410207369Sbz#ifndef	IPV6_SENDREDIRECTS
411207369Sbz#define	IPV6_SENDREDIRECTS	1
412207369Sbz#endif
413207369Sbz
414207369SbzVNET_DEFINE(int, ip6_forwarding) = IPV6FORWARDING;	/* act as router? */
415207369SbzVNET_DEFINE(int, ip6_sendredirects) = IPV6_SENDREDIRECTS;
416207369SbzVNET_DEFINE(int, ip6_defhlim) = IPV6_DEFHLIM;
417207369SbzVNET_DEFINE(int, ip6_defmcasthlim) = IPV6_DEFAULT_MULTICAST_HOPS;
418207369SbzVNET_DEFINE(int, ip6_accept_rtadv) = 0;
419207369SbzVNET_DEFINE(int, ip6_maxfragpackets);	/* initialized in frag6.c:frag6_init() */
420207369SbzVNET_DEFINE(int, ip6_maxfrags);		/* initialized in frag6.c:frag6_init() */
421207369SbzVNET_DEFINE(int, ip6_log_interval) = 5;
422207369SbzVNET_DEFINE(int, ip6_hdrnestlimit) = 15;/* How many header options will we
423207369Sbz					 * process? */
424207369SbzVNET_DEFINE(int, ip6_dad_count) = 1;	/* DupAddrDetectionTransmits */
425207369SbzVNET_DEFINE(int, ip6_auto_flowlabel) = 1;
426207369SbzVNET_DEFINE(int, ip6_use_deprecated) = 1;/* allow deprecated addr
427207369Sbz					 * (RFC2462 5.5.4) */
428207369SbzVNET_DEFINE(int, ip6_rr_prune) = 5;	/* router renumbering prefix
429207369Sbz					 * walk list every 5 sec. */
430207369SbzVNET_DEFINE(int, ip6_mcast_pmtu) = 0;	/* enable pMTU discovery for multicast? */
431207369SbzVNET_DEFINE(int, ip6_v6only) = 1;
432207369Sbz
433207369SbzVNET_DEFINE(int, ip6_keepfaith) = 0;
434207369SbzVNET_DEFINE(time_t, ip6_log_time) = (time_t)0L;
435207369Sbz#ifdef IPSTEALTH
436207369SbzVNET_DEFINE(int, ip6stealth) = 0;
437207369Sbz#endif
438207369SbzVNET_DEFINE(int, nd6_onlink_ns_rfc4861) = 0;/* allow 'on-link' nd6 NS
439207369Sbz					     * (RFC 4861) */
440207369Sbz
44153541Sshin/* icmp6 */
44253541Sshin/*
44353541Sshin * BSDI4 defines these variables in in_proto.c...
44453541Sshin * XXX: what if we don't define INET? Should we define pmtu6_expire
44553541Sshin * or so? (jinmei@kame.net 19990310)
44653541Sshin */
447207369SbzVNET_DEFINE(int, pmtu_expire) = 60*10;
448207369SbzVNET_DEFINE(int, pmtu_probe) = 60*2;
44953541Sshin
45053541Sshin/* raw IP6 parameters */
45153541Sshin/*
45253541Sshin * Nominal space allocated to a raw ip socket.
45353541Sshin */
454207369Sbz#define	RIPV6SNDQ	8192
455207369Sbz#define	RIPV6RCVQ	8192
45653541Sshin
457207369SbzVNET_DEFINE(u_long, rip6_sendspace) = RIPV6SNDQ;
458207369SbzVNET_DEFINE(u_long, rip6_recvspace) = RIPV6RCVQ;
459207369Sbz
46053541Sshin/* ICMPV6 parameters */
461207369SbzVNET_DEFINE(int, icmp6_rediraccept) = 1;/* accept and process redirects */
462207369SbzVNET_DEFINE(int, icmp6_redirtimeout) = 10 * 60;	/* 10 minutes */
463207369SbzVNET_DEFINE(int, icmp6errppslim) = 100;		/* 100pps */
464169664Sjinmei/* control how to respond to NI queries */
465207369SbzVNET_DEFINE(int, icmp6_nodeinfo) =
466207369Sbz    (ICMP6_NODEINFO_FQDNOK|ICMP6_NODEINFO_NODEADDROK);
46753541Sshin
46853541Sshin/* UDP on IP6 parameters */
469207369SbzVNET_DEFINE(int, udp6_sendspace) = 9216;/* really max datagram size */
470207369SbzVNET_DEFINE(int, udp6_recvspace) = 40 * (1024 + sizeof(struct sockaddr_in6));
471207369Sbz					/* 40 1K datagrams */
47253541Sshin
47353541Sshin/*
47453541Sshin * sysctl related items.
47553541Sshin */
47653541SshinSYSCTL_NODE(_net,	PF_INET6,	inet6,	CTLFLAG_RW,	0,
47753541Sshin	"Internet6 Family");
47853541Sshin
47953541Sshin/* net.inet6 */
48053541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_IPV6,	ip6,	CTLFLAG_RW, 0,	"IP6");
48153541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_ICMPV6,	icmp6,	CTLFLAG_RW, 0,	"ICMP6");
48253541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_UDP,	udp6,	CTLFLAG_RW, 0,	"UDP6");
48353541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_TCP,	tcp6,	CTLFLAG_RW, 0,	"TCP6");
484163953Srrs#ifdef SCTP
485163953SrrsSYSCTL_NODE(_net_inet6,	IPPROTO_SCTP,	sctp6,	CTLFLAG_RW, 0,	"SCTP6");
486163953Srrs#endif
487171167Sgnn#ifdef IPSEC
48853541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_ESP,	ipsec6,	CTLFLAG_RW, 0,	"IPSEC6");
489171167Sgnn#endif /* IPSEC */
49053541Sshin
49153541Sshin/* net.inet6.ip6 */
49253541Sshinstatic int
49378064Sumesysctl_ip6_temppltime(SYSCTL_HANDLER_ARGS)
49453541Sshin{
49553541Sshin	int error = 0;
49678064Sume	int old;
49753541Sshin
498195814Sbz	VNET_SYSCTL_ARG(req, arg1);
499191688Szec
50053541Sshin	error = SYSCTL_OUT(req, arg1, sizeof(int));
50153541Sshin	if (error || !req->newptr)
50253541Sshin		return (error);
503181803Sbz	old = V_ip6_temp_preferred_lifetime;
50453541Sshin	error = SYSCTL_IN(req, arg1, sizeof(int));
505181803Sbz	if (V_ip6_temp_preferred_lifetime <
506181803Sbz	    V_ip6_desync_factor + V_ip6_temp_regen_advance) {
507181803Sbz		V_ip6_temp_preferred_lifetime = old;
508120856Sume		return (EINVAL);
50953541Sshin	}
510120856Sume	return (error);
51153541Sshin}
51253541Sshin
51362587Sitojunstatic int
51478064Sumesysctl_ip6_tempvltime(SYSCTL_HANDLER_ARGS)
51562587Sitojun{
51678064Sume	int error = 0;
51778064Sume	int old;
51862587Sitojun
519195814Sbz	VNET_SYSCTL_ARG(req, arg1);
520191688Szec
52178064Sume	error = SYSCTL_OUT(req, arg1, sizeof(int));
52278064Sume	if (error || !req->newptr)
52362587Sitojun		return (error);
524181803Sbz	old = V_ip6_temp_valid_lifetime;
52578064Sume	error = SYSCTL_IN(req, arg1, sizeof(int));
526181803Sbz	if (V_ip6_temp_valid_lifetime < V_ip6_temp_preferred_lifetime) {
527181803Sbz		V_ip6_temp_preferred_lifetime = old;
528120856Sume		return (EINVAL);
52978064Sume	}
530120856Sume	return (error);
53162587Sitojun}
53262587Sitojun
533195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_FORWARDING, forwarding, CTLFLAG_RW,
534195699Srwatson	&VNET_NAME(ip6_forwarding), 0, "");
535195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_SENDREDIRECTS, redirect, CTLFLAG_RW,
536195699Srwatson	&VNET_NAME(ip6_sendredirects), 0, "");
537195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_DEFHLIM, hlim, CTLFLAG_RW,
538195699Srwatson	&VNET_NAME(ip6_defhlim), 0, "");
539195699SrwatsonSYSCTL_VNET_STRUCT(_net_inet6_ip6, IPV6CTL_STATS, stats, CTLFLAG_RD,
540195699Srwatson	&VNET_NAME(ip6stat), ip6stat, "");
541195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGPACKETS, maxfragpackets,
542195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_maxfragpackets), 0, "");
543195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV, accept_rtadv,
544197138Shrs	CTLFLAG_RW, &VNET_NAME(ip6_accept_rtadv), 0,
545197138Shrs	"Default value of per-interface flag for accepting ICMPv6 Router"
546197138Shrs	"Advertisement messages");
547195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_KEEPFAITH, keepfaith, CTLFLAG_RW,
548195699Srwatson	&VNET_NAME(ip6_keepfaith), 0, "");
549195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_LOG_INTERVAL, log_interval,
550195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_log_interval), 0, "");
551195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_HDRNESTLIMIT, hdrnestlimit,
552195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_hdrnestlimit), 0, "");
553195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_DAD_COUNT, dad_count, CTLFLAG_RW,
554195699Srwatson	&VNET_NAME(ip6_dad_count), 0, "");
555195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_AUTO_FLOWLABEL, auto_flowlabel,
556195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_auto_flowlabel), 0, "");
557195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_DEFMCASTHLIM, defmcasthlim,
558195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_defmcasthlim), 0, "");
559195699SrwatsonSYSCTL_STRING(_net_inet6_ip6, IPV6CTL_KAME_VERSION, kame_version,
560195699Srwatson	CTLFLAG_RD, __KAME_VERSION, 0, "");
561195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_USE_DEPRECATED, use_deprecated,
562195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_use_deprecated), 0, "");
563195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_RR_PRUNE, rr_prune, CTLFLAG_RW,
564195699Srwatson	&VNET_NAME(ip6_rr_prune), 0, "");
565195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_USETEMPADDR, use_tempaddr,
566195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_use_tempaddr), 0, "");
567195699SrwatsonSYSCTL_VNET_PROC(_net_inet6_ip6, IPV6CTL_TEMPPLTIME, temppltime,
568195699Srwatson	CTLTYPE_INT|CTLFLAG_RW, &VNET_NAME(ip6_temp_preferred_lifetime), 0,
569183550Szec   	sysctl_ip6_temppltime, "I", "");
570195699SrwatsonSYSCTL_VNET_PROC(_net_inet6_ip6, IPV6CTL_TEMPVLTIME, tempvltime,
571195699Srwatson	CTLTYPE_INT|CTLFLAG_RW, &VNET_NAME(ip6_temp_valid_lifetime), 0,
572183550Szec   	sysctl_ip6_tempvltime, "I", "");
573195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_V6ONLY, v6only,	CTLFLAG_RW,
574195699Srwatson	&VNET_NAME(ip6_v6only), 0, "");
575195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_AUTO_LINKLOCAL, auto_linklocal,
576197138Shrs	CTLFLAG_RW, &VNET_NAME(ip6_auto_linklocal), 0,
577197138Shrs	"Default value of per-interface flag for automatically adding an IPv6"
578197138Shrs	" link-local address to interfaces when attached");
579195699SrwatsonSYSCTL_VNET_STRUCT(_net_inet6_ip6, IPV6CTL_RIP6STATS, rip6stats, CTLFLAG_RD,
580195699Srwatson	&VNET_NAME(rip6stat), rip6stat, "");
581195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_PREFER_TEMPADDR, prefer_tempaddr,
582195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_prefer_tempaddr), 0, "");
583195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_USE_DEFAULTZONE, use_defaultzone,
584195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_use_defzone), 0,"");
585195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGS, maxfrags, CTLFLAG_RW,
586195699Srwatson	&VNET_NAME(ip6_maxfrags), 0, "");
587195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_MCAST_PMTU, mcast_pmtu, CTLFLAG_RW,
588195699Srwatson	&VNET_NAME(ip6_mcast_pmtu), 0, "");
589148921Ssuz#ifdef IPSTEALTH
590195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_STEALTH, stealth, CTLFLAG_RW,
591195699Srwatson	&VNET_NAME(ip6stealth), 0, "");
592148921Ssuz#endif
59353541Sshin
594207828Skmacy#ifdef FLOWTABLE
595207828SkmacyVNET_DEFINE(int, ip6_output_flowtable_size) = 2048;
596207828SkmacyVNET_DEFINE(struct flowtable *, ip6_ft);
597207828Skmacy#define	V_ip6_output_flowtable_size	VNET(ip6_output_flowtable_size)
598207828Skmacy
599207828SkmacySYSCTL_VNET_INT(_net_inet6_ip6, OID_AUTO, output_flowtable_size, CTLFLAG_RDTUN,
600207828Skmacy    &VNET_NAME(ip6_output_flowtable_size), 2048,
601207828Skmacy    "number of entries in the per-cpu output flow caches");
602207828Skmacy#endif
603207828Skmacy
60453541Sshin/* net.inet6.icmp6 */
605195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRACCEPT, rediraccept,
606195699Srwatson	CTLFLAG_RW, &VNET_NAME(icmp6_rediraccept), 0, "");
607195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRTIMEOUT, redirtimeout,
608195699Srwatson	CTLFLAG_RW, &VNET_NAME(icmp6_redirtimeout), 0, "");
609195699SrwatsonSYSCTL_VNET_STRUCT(_net_inet6_icmp6, ICMPV6CTL_STATS, stats, CTLFLAG_RD,
610195699Srwatson	&VNET_NAME(icmp6stat), icmp6stat, "");
611195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PRUNE, nd6_prune, CTLFLAG_RW,
612195699Srwatson	&VNET_NAME(nd6_prune), 0, "");
613195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DELAY, nd6_delay, CTLFLAG_RW,
614195699Srwatson	&VNET_NAME(nd6_delay), 0, "");
615195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_UMAXTRIES, nd6_umaxtries,
616195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_umaxtries), 0, "");
617195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MMAXTRIES, nd6_mmaxtries,
618195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_mmaxtries), 0, "");
619195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_USELOOPBACK, nd6_useloopback,
620195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_useloopback), 0, "");
621195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO, nodeinfo, CTLFLAG_RW,
622195699Srwatson	&VNET_NAME(icmp6_nodeinfo), 0, "");
623195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ERRPPSLIMIT, errppslimit,
624195699Srwatson	CTLFLAG_RW, &VNET_NAME(icmp6errppslim), 0, "");
625195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MAXNUDHINT, nd6_maxnudhint,
626195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_maxnudhint), 0, "");
627195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DEBUG, nd6_debug, CTLFLAG_RW,
628195699Srwatson	&VNET_NAME(nd6_debug), 0, "");
629195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_ONLINKNSRFC4861,
630195699Srwatson	nd6_onlink_ns_rfc4861, CTLFLAG_RW, &VNET_NAME(nd6_onlink_ns_rfc4861),
631195699Srwatson	0, "Accept 'on-link' nd6 NS in compliance with RFC 4861.");
632