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: releng/10.3/sys/netinet6/in6_proto.c 284066 2015-06-06 12:44:42Z ae $");
65174510Sobrien
6655679Sshin#include "opt_inet.h"
6762587Sitojun#include "opt_inet6.h"
6855009Sshin#include "opt_ipsec.h"
69148921Ssuz#include "opt_ipstealth.h"
70163953Srrs#include "opt_sctp.h"
71178167Sqingli#include "opt_mpath.h"
72207828Skmacy#include "opt_route.h"
7355009Sshin
7453541Sshin#include <sys/param.h>
7553541Sshin#include <sys/socket.h>
7653541Sshin#include <sys/socketvar.h>
77185895Szec#include <sys/proc.h>
7853541Sshin#include <sys/protosw.h>
79194368Sbz#include <sys/jail.h>
8053541Sshin#include <sys/kernel.h>
8153541Sshin#include <sys/domain.h>
8253541Sshin#include <sys/mbuf.h>
8353541Sshin#include <sys/systm.h>
8453541Sshin#include <sys/sysctl.h>
8553541Sshin
8653541Sshin#include <net/if.h>
8753541Sshin#include <net/radix.h>
8853541Sshin#include <net/route.h>
89178167Sqingli#ifdef RADIX_MPATH
90178167Sqingli#include <net/radix_mpath.h>
91178167Sqingli#endif
9253541Sshin
9353541Sshin#include <netinet/in.h>
9453541Sshin#include <netinet/in_systm.h>
9553541Sshin#include <netinet/in_var.h>
9662587Sitojun#include <netinet/ip_encap.h>
9753541Sshin#include <netinet/ip.h>
9853541Sshin#include <netinet/ip_var.h>
9962587Sitojun#include <netinet/ip6.h>
10053541Sshin#include <netinet6/ip6_var.h>
10162587Sitojun#include <netinet/icmp6.h>
10253541Sshin
10353541Sshin#include <netinet/tcp.h>
10453541Sshin#include <netinet/tcp_timer.h>
10553541Sshin#include <netinet/tcp_var.h>
10653541Sshin#include <netinet/udp.h>
10753541Sshin#include <netinet/udp_var.h>
10853541Sshin#include <netinet6/tcp6_var.h>
10978064Sume#include <netinet6/raw_ip6.h>
11053541Sshin#include <netinet6/udp6_var.h>
11153541Sshin#include <netinet6/pim6_var.h>
11253541Sshin#include <netinet6/nd6.h>
11353541Sshin
114163953Srrs#ifdef SCTP
115163953Srrs#include <netinet/in_pcb.h>
116163953Srrs#include <netinet/sctp_pcb.h>
117163953Srrs#include <netinet/sctp.h>
118163953Srrs#include <netinet/sctp_var.h>
119163953Srrs#include <netinet6/sctp6_var.h>
120163953Srrs#endif /* SCTP */
121163953Srrs
122171167Sgnn#ifdef IPSEC
123171133Sgnn#include <netipsec/ipsec.h>
124105199Ssam#include <netipsec/ipsec6.h>
125171167Sgnn#endif /* IPSEC */
126105199Ssam
12753541Sshin#include <netinet6/ip6protosw.h>
12853541Sshin
12953541Sshin/*
13053541Sshin * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
13153541Sshin */
132222272SbzFEATURE(inet6, "Internet Protocol version 6");
13353541Sshin
13462587Sitojunextern	struct domain inet6domain;
135148917Sobrienstatic	struct pr_usrreqs nousrreqs;
13653541Sshin
13778064Sume#define PR_LISTEN	0
13878064Sume#define PR_ABRTACPTDIS	0
13978064Sume
140211115Sbz/* Spacer for loadable protocols. */
141211115Sbz#define IP6PROTOSPACER   			\
142211115Sbz{						\
143211115Sbz	.pr_domain =		&inet6domain,	\
144211115Sbz	.pr_protocol =		PROTO_SPACER,	\
145211115Sbz	.pr_usrreqs =		&nousrreqs	\
146211115Sbz}
147211115Sbz
14853541Sshinstruct ip6protosw inet6sw[] = {
149152242Sru{
150152242Sru	.pr_type =		0,
151152242Sru	.pr_domain =		&inet6domain,
152152242Sru	.pr_protocol =		IPPROTO_IPV6,
153152242Sru	.pr_init =		ip6_init,
154193731Szec#ifdef VIMAGE
155193731Szec	.pr_destroy =		ip6_destroy,
156193731Szec#endif
157152242Sru	.pr_slowtimo =		frag6_slowtimo,
158152242Sru	.pr_drain =		frag6_drain,
159152242Sru	.pr_usrreqs =		&nousrreqs,
16053541Sshin},
161152242Sru{
162152242Sru	.pr_type =		SOCK_DGRAM,
163152242Sru	.pr_domain =		&inet6domain,
164152242Sru	.pr_protocol =		IPPROTO_UDP,
165152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
166152242Sru	.pr_input =		udp6_input,
167152242Sru	.pr_ctlinput =		udp6_ctlinput,
168152242Sru	.pr_ctloutput =		ip6_ctloutput,
169220881Sbz#ifndef INET	/* Do not call initialization twice. */
170220881Sbz	.pr_init =		udp_init,
171220881Sbz#endif
172152242Sru	.pr_usrreqs =		&udp6_usrreqs,
17354263Sshin},
174152242Sru{
175152242Sru	.pr_type =		SOCK_STREAM,
176152242Sru	.pr_domain =		&inet6domain,
177152242Sru	.pr_protocol =		IPPROTO_TCP,
178152242Sru	.pr_flags =		PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
179152242Sru	.pr_input =		tcp6_input,
180152242Sru	.pr_ctlinput =		tcp6_ctlinput,
181152242Sru	.pr_ctloutput =		tcp_ctloutput,
182152242Sru#ifndef INET	/* don't call initialization and timeout routines twice */
183152242Sru	.pr_init =		tcp_init,
184152242Sru	.pr_slowtimo =		tcp_slowtimo,
18555679Sshin#endif
186152242Sru	.pr_drain =		tcp_drain,
187152242Sru	.pr_usrreqs =		&tcp6_usrreqs,
18855679Sshin},
189163953Srrs#ifdef SCTP
190171260Sdelphij{
191223963Stuexen	.pr_type =		SOCK_SEQPACKET,
192223963Stuexen	.pr_domain =		&inet6domain,
193223963Stuexen	.pr_protocol =		IPPROTO_SCTP,
194223963Stuexen	.pr_flags =		PR_WANTRCVD,
195223963Stuexen	.pr_input =		sctp6_input,
196223963Stuexen	.pr_ctlinput =		sctp6_ctlinput,
197223963Stuexen	.pr_ctloutput =	sctp_ctloutput,
198223963Stuexen	.pr_drain =		sctp_drain,
199220881Sbz#ifndef INET	/* Do not call initialization twice. */
200223963Stuexen	.pr_init =		sctp_init,
201220881Sbz#endif
202223963Stuexen	.pr_usrreqs =		&sctp6_usrreqs
203163953Srrs},
204152242Sru{
205223963Stuexen	.pr_type =		SOCK_STREAM,
206223963Stuexen	.pr_domain =		&inet6domain,
207223963Stuexen	.pr_protocol =		IPPROTO_SCTP,
208223963Stuexen	.pr_flags =		PR_WANTRCVD,
209223963Stuexen	.pr_input =		sctp6_input,
210265946Skevlo	.pr_ctlinput =		sctp6_ctlinput,
211223963Stuexen	.pr_ctloutput =		sctp_ctloutput,
212223963Stuexen	.pr_drain =		sctp_drain,
213223963Stuexen	.pr_usrreqs =		&sctp6_usrreqs
214163953Srrs},
215163953Srrs#endif /* SCTP */
216163953Srrs{
217265946Skevlo	.pr_type =		SOCK_DGRAM,
218265946Skevlo	.pr_domain =		&inet6domain,
219265946Skevlo	.pr_protocol =		IPPROTO_UDPLITE,
220265946Skevlo	.pr_flags =		PR_ATOMIC|PR_ADDR,
221265946Skevlo	.pr_input =		udp6_input,
222265946Skevlo	.pr_ctlinput =		udplite6_ctlinput,
223265946Skevlo	.pr_ctloutput =		udp_ctloutput,
224265946Skevlo#ifndef INET	/* Do not call initialization twice. */
225265946Skevlo	.pr_init =		udplite_init,
226265946Skevlo#endif
227265946Skevlo	.pr_usrreqs =		&udp6_usrreqs,
228265946Skevlo},
229265946Skevlo{
230152242Sru	.pr_type =		SOCK_RAW,
231152242Sru	.pr_domain =		&inet6domain,
232152242Sru	.pr_protocol =		IPPROTO_RAW,
233152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
234152242Sru	.pr_input =		rip6_input,
235152242Sru	.pr_output =		rip6_output,
236152242Sru	.pr_ctlinput =		rip6_ctlinput,
237152242Sru	.pr_ctloutput =		rip6_ctloutput,
238220881Sbz#ifndef INET	/* Do not call initialization twice. */
239220881Sbz	.pr_init =		rip_init,
240220881Sbz#endif
241152242Sru	.pr_usrreqs =		&rip6_usrreqs
24253541Sshin},
243152242Sru{
244152242Sru	.pr_type =		SOCK_RAW,
245152242Sru	.pr_domain =		&inet6domain,
246152242Sru	.pr_protocol =		IPPROTO_ICMPV6,
247152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
248152242Sru	.pr_input =		icmp6_input,
249152242Sru	.pr_output =		rip6_output,
250152242Sru	.pr_ctlinput =		rip6_ctlinput,
251152242Sru	.pr_ctloutput =		rip6_ctloutput,
252152242Sru	.pr_fasttimo =		icmp6_fasttimo,
253191672Sbms	.pr_slowtimo =		icmp6_slowtimo,
254152242Sru	.pr_usrreqs =		&rip6_usrreqs
25553541Sshin},
256152242Sru{
257152242Sru	.pr_type =		SOCK_RAW,
258152242Sru	.pr_domain =		&inet6domain,
259152242Sru	.pr_protocol =		IPPROTO_DSTOPTS,
260152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
261152242Sru	.pr_input =		dest6_input,
262152242Sru	.pr_usrreqs =		&nousrreqs
26353541Sshin},
264152242Sru{
265152242Sru	.pr_type =		SOCK_RAW,
266152242Sru	.pr_domain =		&inet6domain,
267152242Sru	.pr_protocol =		IPPROTO_ROUTING,
268152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
269152242Sru	.pr_input =		route6_input,
270152242Sru	.pr_usrreqs =		&nousrreqs
27153541Sshin},
272152242Sru{
273152242Sru	.pr_type =		SOCK_RAW,
274152242Sru	.pr_domain =		&inet6domain,
275152242Sru	.pr_protocol =		IPPROTO_FRAGMENT,
276152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
277152242Sru	.pr_input =		frag6_input,
278152242Sru	.pr_usrreqs =		&nousrreqs
27953541Sshin},
280171167Sgnn#ifdef IPSEC
281152242Sru{
282152242Sru	.pr_type =		SOCK_RAW,
283152242Sru	.pr_domain =		&inet6domain,
284152242Sru	.pr_protocol =		IPPROTO_AH,
285152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
286171133Sgnn	.pr_input =		ipsec6_common_input,
287152242Sru	.pr_usrreqs =		&nousrreqs,
28853541Sshin},
289152242Sru{
290152242Sru	.pr_type =		SOCK_RAW,
291152242Sru	.pr_domain =		&inet6domain,
292152242Sru	.pr_protocol =		IPPROTO_ESP,
293152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
294171133Sgnn        .pr_input =		ipsec6_common_input,
295152242Sru	.pr_ctlinput =		esp6_ctlinput,
296152242Sru	.pr_usrreqs =		&nousrreqs,
29753541Sshin},
298152242Sru{
299152242Sru	.pr_type =		SOCK_RAW,
300152242Sru	.pr_domain =		&inet6domain,
301152242Sru	.pr_protocol =		IPPROTO_IPCOMP,
302152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
303171133Sgnn        .pr_input =		ipsec6_common_input,
304152242Sru	.pr_usrreqs =		&nousrreqs,
30562587Sitojun},
306171167Sgnn#endif /* IPSEC */
30762587Sitojun#ifdef INET
308152242Sru{
309152242Sru	.pr_type =		SOCK_RAW,
310152242Sru	.pr_domain =		&inet6domain,
311152242Sru	.pr_protocol =		IPPROTO_IPV4,
312152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
313152242Sru	.pr_input =		encap6_input,
314152242Sru	.pr_output =		rip6_output,
315152242Sru	.pr_ctloutput =		rip6_ctloutput,
316152242Sru	.pr_init =		encap_init,
317152242Sru	.pr_usrreqs =		&rip6_usrreqs
31853541Sshin},
31995023Ssuz#endif /* INET */
320152242Sru{
321152242Sru	.pr_type =		SOCK_RAW,
322152242Sru	.pr_domain =		&inet6domain,
323152242Sru	.pr_protocol =		IPPROTO_IPV6,
324152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
325152242Sru	.pr_input =		encap6_input,
326152242Sru	.pr_output =		rip6_output,
327152242Sru	.pr_ctloutput =		rip6_ctloutput,
328152242Sru	.pr_init =		encap_init,
329152242Sru	.pr_usrreqs =		&rip6_usrreqs
33053541Sshin},
331152242Sru{
332152242Sru	.pr_type =		SOCK_RAW,
333152242Sru	.pr_domain =		&inet6domain,
334284066Sae	.pr_protocol =		IPPROTO_GRE,
335284066Sae	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
336284066Sae	.pr_input =		encap6_input,
337284066Sae	.pr_output =		rip6_output,
338284066Sae	.pr_ctloutput =		rip6_ctloutput,
339284066Sae	.pr_init =		encap_init,
340284066Sae	.pr_usrreqs =		&rip6_usrreqs
341284066Sae},
342284066Sae{
343284066Sae	.pr_type =		SOCK_RAW,
344284066Sae	.pr_domain =		&inet6domain,
345152242Sru	.pr_protocol =		IPPROTO_PIM,
346152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
347166938Sbms	.pr_input =		encap6_input,
348152242Sru	.pr_output =		rip6_output,
349152242Sru	.pr_ctloutput =		rip6_ctloutput,
350152242Sru	.pr_usrreqs =		&rip6_usrreqs
35156722Sshin},
352211115Sbz/* Spacer n-times for loadable protocols. */
353211115SbzIP6PROTOSPACER,
354211115SbzIP6PROTOSPACER,
355211115SbzIP6PROTOSPACER,
356211115SbzIP6PROTOSPACER,
357211115SbzIP6PROTOSPACER,
358211115SbzIP6PROTOSPACER,
359211115SbzIP6PROTOSPACER,
360211115SbzIP6PROTOSPACER,
36153541Sshin/* raw wildcard */
362152242Sru{
363152242Sru	.pr_type =		SOCK_RAW,
364152242Sru	.pr_domain =		&inet6domain,
365152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
366152242Sru	.pr_input =		rip6_input,
367152242Sru	.pr_output =		rip6_output,
368152242Sru	.pr_ctloutput =		rip6_ctloutput,
369152242Sru	.pr_usrreqs =		&rip6_usrreqs
37053541Sshin},
37153541Sshin};
37253541Sshin
373175162Sobrienextern int in6_inithead(void **, int);
374193731Szec#ifdef VIMAGE
375193731Szecextern int in6_detachhead(void **, int);
376193731Szec#endif
37762587Sitojun
378152242Srustruct domain inet6domain = {
379152242Sru	.dom_family =		AF_INET6,
380152242Sru	.dom_name =		"internet6",
381152242Sru	.dom_protosw =		(struct protosw *)inet6sw,
382152242Sru	.dom_protoswNPROTOSW =	(struct protosw *)
383152242Sru				&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])],
384178167Sqingli#ifdef RADIX_MPATH
385178167Sqingli	.dom_rtattach =		rn6_mpath_inithead,
386178167Sqingli#else
387152242Sru	.dom_rtattach =		in6_inithead,
388178167Sqingli#endif
389193731Szec#ifdef VIMAGE
390193731Szec	.dom_rtdetach =		in6_detachhead,
391193731Szec#endif
392152242Sru	.dom_rtoffset =		offsetof(struct sockaddr_in6, sin6_addr) << 3,
393152242Sru	.dom_maxrtkey =		sizeof(struct sockaddr_in6),
394152242Sru	.dom_ifattach =		in6_domifattach,
395152242Sru	.dom_ifdetach =		in6_domifdetach
396152242Sru};
39753541Sshin
398195837SrwatsonVNET_DOMAIN_SET(inet6);
39953541Sshin
40053541Sshin/*
40153541Sshin * Internet configuration info
40253541Sshin */
403207369Sbz#ifndef	IPV6FORWARDING
404207369Sbz#ifdef GATEWAY6
405207369Sbz#define	IPV6FORWARDING	1	/* forward IP6 packets not for us */
406207369Sbz#else
407207369Sbz#define	IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
408207369Sbz#endif /* GATEWAY6 */
409207369Sbz#endif /* !IPV6FORWARDING */
41053541Sshin
411207369Sbz#ifndef	IPV6_SENDREDIRECTS
412207369Sbz#define	IPV6_SENDREDIRECTS	1
413207369Sbz#endif
414207369Sbz
415207369SbzVNET_DEFINE(int, ip6_forwarding) = IPV6FORWARDING;	/* act as router? */
416207369SbzVNET_DEFINE(int, ip6_sendredirects) = IPV6_SENDREDIRECTS;
417207369SbzVNET_DEFINE(int, ip6_defhlim) = IPV6_DEFHLIM;
418207369SbzVNET_DEFINE(int, ip6_defmcasthlim) = IPV6_DEFAULT_MULTICAST_HOPS;
419207369SbzVNET_DEFINE(int, ip6_accept_rtadv) = 0;
420222728ShrsVNET_DEFINE(int, ip6_no_radr) = 0;
421222728ShrsVNET_DEFINE(int, ip6_norbit_raif) = 0;
422225521ShrsVNET_DEFINE(int, ip6_rfc6204w3) = 0;
423207369SbzVNET_DEFINE(int, ip6_maxfragpackets);	/* initialized in frag6.c:frag6_init() */
424207369SbzVNET_DEFINE(int, ip6_maxfrags);		/* initialized in frag6.c:frag6_init() */
425207369SbzVNET_DEFINE(int, ip6_log_interval) = 5;
426207369SbzVNET_DEFINE(int, ip6_hdrnestlimit) = 15;/* How many header options will we
427207369Sbz					 * process? */
428207369SbzVNET_DEFINE(int, ip6_dad_count) = 1;	/* DupAddrDetectionTransmits */
429207369SbzVNET_DEFINE(int, ip6_auto_flowlabel) = 1;
430207369SbzVNET_DEFINE(int, ip6_use_deprecated) = 1;/* allow deprecated addr
431207369Sbz					 * (RFC2462 5.5.4) */
432207369SbzVNET_DEFINE(int, ip6_rr_prune) = 5;	/* router renumbering prefix
433207369Sbz					 * walk list every 5 sec. */
434207369SbzVNET_DEFINE(int, ip6_mcast_pmtu) = 0;	/* enable pMTU discovery for multicast? */
435207369SbzVNET_DEFINE(int, ip6_v6only) = 1;
436207369Sbz
437207369SbzVNET_DEFINE(int, ip6_keepfaith) = 0;
438207369SbzVNET_DEFINE(time_t, ip6_log_time) = (time_t)0L;
439207369Sbz#ifdef IPSTEALTH
440207369SbzVNET_DEFINE(int, ip6stealth) = 0;
441207369Sbz#endif
442207369SbzVNET_DEFINE(int, nd6_onlink_ns_rfc4861) = 0;/* allow 'on-link' nd6 NS
443207369Sbz					     * (RFC 4861) */
444207369Sbz
44553541Sshin/* icmp6 */
44653541Sshin/*
44753541Sshin * BSDI4 defines these variables in in_proto.c...
44853541Sshin * XXX: what if we don't define INET? Should we define pmtu6_expire
44953541Sshin * or so? (jinmei@kame.net 19990310)
45053541Sshin */
451207369SbzVNET_DEFINE(int, pmtu_expire) = 60*10;
452207369SbzVNET_DEFINE(int, pmtu_probe) = 60*2;
45353541Sshin
45453541Sshin/* ICMPV6 parameters */
455207369SbzVNET_DEFINE(int, icmp6_rediraccept) = 1;/* accept and process redirects */
456207369SbzVNET_DEFINE(int, icmp6_redirtimeout) = 10 * 60;	/* 10 minutes */
457207369SbzVNET_DEFINE(int, icmp6errppslim) = 100;		/* 100pps */
458169664Sjinmei/* control how to respond to NI queries */
459207369SbzVNET_DEFINE(int, icmp6_nodeinfo) =
460207369Sbz    (ICMP6_NODEINFO_FQDNOK|ICMP6_NODEINFO_NODEADDROK);
461250251ShrsVNET_DEFINE(int, icmp6_nodeinfo_oldmcprefix) = 1;
46253541Sshin
46353541Sshin/*
46453541Sshin * sysctl related items.
46553541Sshin */
46653541SshinSYSCTL_NODE(_net,	PF_INET6,	inet6,	CTLFLAG_RW,	0,
46753541Sshin	"Internet6 Family");
46853541Sshin
46953541Sshin/* net.inet6 */
47053541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_IPV6,	ip6,	CTLFLAG_RW, 0,	"IP6");
47153541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_ICMPV6,	icmp6,	CTLFLAG_RW, 0,	"ICMP6");
47253541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_UDP,	udp6,	CTLFLAG_RW, 0,	"UDP6");
47353541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_TCP,	tcp6,	CTLFLAG_RW, 0,	"TCP6");
474163953Srrs#ifdef SCTP
475163953SrrsSYSCTL_NODE(_net_inet6,	IPPROTO_SCTP,	sctp6,	CTLFLAG_RW, 0,	"SCTP6");
476163953Srrs#endif
477171167Sgnn#ifdef IPSEC
47853541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_ESP,	ipsec6,	CTLFLAG_RW, 0,	"IPSEC6");
479171167Sgnn#endif /* IPSEC */
48053541Sshin
48153541Sshin/* net.inet6.ip6 */
48253541Sshinstatic int
48378064Sumesysctl_ip6_temppltime(SYSCTL_HANDLER_ARGS)
48453541Sshin{
48553541Sshin	int error = 0;
48678064Sume	int old;
48753541Sshin
48853541Sshin	error = SYSCTL_OUT(req, arg1, sizeof(int));
48953541Sshin	if (error || !req->newptr)
49053541Sshin		return (error);
491181803Sbz	old = V_ip6_temp_preferred_lifetime;
49253541Sshin	error = SYSCTL_IN(req, arg1, sizeof(int));
493181803Sbz	if (V_ip6_temp_preferred_lifetime <
494181803Sbz	    V_ip6_desync_factor + V_ip6_temp_regen_advance) {
495181803Sbz		V_ip6_temp_preferred_lifetime = old;
496120856Sume		return (EINVAL);
49753541Sshin	}
498120856Sume	return (error);
49953541Sshin}
50053541Sshin
50162587Sitojunstatic int
50278064Sumesysctl_ip6_tempvltime(SYSCTL_HANDLER_ARGS)
50362587Sitojun{
50478064Sume	int error = 0;
50578064Sume	int old;
50662587Sitojun
50778064Sume	error = SYSCTL_OUT(req, arg1, sizeof(int));
50878064Sume	if (error || !req->newptr)
50962587Sitojun		return (error);
510181803Sbz	old = V_ip6_temp_valid_lifetime;
51178064Sume	error = SYSCTL_IN(req, arg1, sizeof(int));
512181803Sbz	if (V_ip6_temp_valid_lifetime < V_ip6_temp_preferred_lifetime) {
513181803Sbz		V_ip6_temp_preferred_lifetime = old;
514120856Sume		return (EINVAL);
51578064Sume	}
516120856Sume	return (error);
51762587Sitojun}
51862587Sitojun
519195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_FORWARDING, forwarding, CTLFLAG_RW,
520195699Srwatson	&VNET_NAME(ip6_forwarding), 0, "");
521195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_SENDREDIRECTS, redirect, CTLFLAG_RW,
522195699Srwatson	&VNET_NAME(ip6_sendredirects), 0, "");
523195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_DEFHLIM, hlim, CTLFLAG_RW,
524195699Srwatson	&VNET_NAME(ip6_defhlim), 0, "");
525253085SaeSYSCTL_VNET_PCPUSTAT(_net_inet6_ip6, IPV6CTL_STATS, stats, struct ip6stat,
526253085Sae    ip6stat, "IP6 statistics (struct ip6stat, netinet6/ip6_var.h)");
527195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGPACKETS, maxfragpackets,
528195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_maxfragpackets), 0, "");
529195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV, accept_rtadv,
530197138Shrs	CTLFLAG_RW, &VNET_NAME(ip6_accept_rtadv), 0,
531197138Shrs	"Default value of per-interface flag for accepting ICMPv6 Router"
532197138Shrs	"Advertisement messages");
533222728ShrsSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_NO_RADR, no_radr,
534222728Shrs	CTLFLAG_RW, &VNET_NAME(ip6_no_radr), 0,
535222728Shrs	"Default value of per-interface flag to control whether routers "
536222728Shrs	"sending ICMPv6 RA messages on that interface are added into the "
537222728Shrs	"default router list.");
538222728ShrsSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_NORBIT_RAIF, norbit_raif, CTLFLAG_RW,
539222728Shrs	&VNET_NAME(ip6_norbit_raif), 0,
540222728Shrs	"Always set 0 to R flag in ICMPv6 NA messages when accepting RA"
541222728Shrs	" on the interface.");
542225521ShrsSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_RFC6204W3, rfc6204w3,
543225521Shrs	CTLFLAG_RW, &VNET_NAME(ip6_rfc6204w3), 0,
544225521Shrs	"Accept the default router list from ICMPv6 RA messages even "
545225521Shrs	"when packet forwarding enabled.");
546195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_KEEPFAITH, keepfaith, CTLFLAG_RW,
547195699Srwatson	&VNET_NAME(ip6_keepfaith), 0, "");
548195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_LOG_INTERVAL, log_interval,
549195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_log_interval), 0, "");
550195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_HDRNESTLIMIT, hdrnestlimit,
551195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_hdrnestlimit), 0, "");
552195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_DAD_COUNT, dad_count, CTLFLAG_RW,
553195699Srwatson	&VNET_NAME(ip6_dad_count), 0, "");
554195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_AUTO_FLOWLABEL, auto_flowlabel,
555195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_auto_flowlabel), 0, "");
556195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_DEFMCASTHLIM, defmcasthlim,
557195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_defmcasthlim), 0, "");
558195699SrwatsonSYSCTL_STRING(_net_inet6_ip6, IPV6CTL_KAME_VERSION, kame_version,
559195699Srwatson	CTLFLAG_RD, __KAME_VERSION, 0, "");
560195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_USE_DEPRECATED, use_deprecated,
561195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_use_deprecated), 0, "");
562195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_RR_PRUNE, rr_prune, CTLFLAG_RW,
563195699Srwatson	&VNET_NAME(ip6_rr_prune), 0, "");
564195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_USETEMPADDR, use_tempaddr,
565195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_use_tempaddr), 0, "");
566195699SrwatsonSYSCTL_VNET_PROC(_net_inet6_ip6, IPV6CTL_TEMPPLTIME, temppltime,
567195699Srwatson	CTLTYPE_INT|CTLFLAG_RW, &VNET_NAME(ip6_temp_preferred_lifetime), 0,
568183550Szec   	sysctl_ip6_temppltime, "I", "");
569195699SrwatsonSYSCTL_VNET_PROC(_net_inet6_ip6, IPV6CTL_TEMPVLTIME, tempvltime,
570195699Srwatson	CTLTYPE_INT|CTLFLAG_RW, &VNET_NAME(ip6_temp_valid_lifetime), 0,
571183550Szec   	sysctl_ip6_tempvltime, "I", "");
572195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_V6ONLY, v6only,	CTLFLAG_RW,
573195699Srwatson	&VNET_NAME(ip6_v6only), 0, "");
574195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_AUTO_LINKLOCAL, auto_linklocal,
575197138Shrs	CTLFLAG_RW, &VNET_NAME(ip6_auto_linklocal), 0,
576197138Shrs	"Default value of per-interface flag for automatically adding an IPv6"
577197138Shrs	" link-local address to interfaces when attached");
578253085SaeSYSCTL_VNET_PCPUSTAT(_net_inet6_ip6, IPV6CTL_RIP6STATS, rip6stats,
579253085Sae    struct rip6stat, rip6stat,
580253085Sae    "Raw IP6 statistics (struct rip6stat, netinet6/raw_ip6.h)");
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
59453541Sshin/* net.inet6.icmp6 */
595195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRACCEPT, rediraccept,
596195699Srwatson	CTLFLAG_RW, &VNET_NAME(icmp6_rediraccept), 0, "");
597195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRTIMEOUT, redirtimeout,
598195699Srwatson	CTLFLAG_RW, &VNET_NAME(icmp6_redirtimeout), 0, "");
599253085SaeSYSCTL_VNET_PCPUSTAT(_net_inet6_icmp6, ICMPV6CTL_STATS, stats,
600253085Sae    struct icmp6stat, icmp6stat,
601253085Sae    "ICMPv6 statistics (struct icmp6stat, netinet/icmp6.h)");
602195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PRUNE, nd6_prune, CTLFLAG_RW,
603195699Srwatson	&VNET_NAME(nd6_prune), 0, "");
604195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DELAY, nd6_delay, CTLFLAG_RW,
605195699Srwatson	&VNET_NAME(nd6_delay), 0, "");
606195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_UMAXTRIES, nd6_umaxtries,
607195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_umaxtries), 0, "");
608195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MMAXTRIES, nd6_mmaxtries,
609195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_mmaxtries), 0, "");
610195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_USELOOPBACK, nd6_useloopback,
611195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_useloopback), 0, "");
612195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO, nodeinfo, CTLFLAG_RW,
613195699Srwatson	&VNET_NAME(icmp6_nodeinfo), 0, "");
614250251ShrsSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO_OLDMCPREFIX,
615250251Shrs	nodeinfo_oldmcprefix, CTLFLAG_RW,
616250251Shrs	&VNET_NAME(icmp6_nodeinfo_oldmcprefix), 0,
617250251Shrs	"Join old IPv6 NI group address in draft-ietf-ipngwg-icmp-name-lookup"
618250251Shrs	" for compatibility with KAME implememtation.");
619195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ERRPPSLIMIT, errppslimit,
620195699Srwatson	CTLFLAG_RW, &VNET_NAME(icmp6errppslim), 0, "");
621195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MAXNUDHINT, nd6_maxnudhint,
622195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_maxnudhint), 0, "");
623195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DEBUG, nd6_debug, CTLFLAG_RW,
624195699Srwatson	&VNET_NAME(nd6_debug), 0, "");
625195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_ONLINKNSRFC4861,
626195699Srwatson	nd6_onlink_ns_rfc4861, CTLFLAG_RW, &VNET_NAME(nd6_onlink_ns_rfc4861),
627195699Srwatson	0, "Accept 'on-link' nd6 NS in compliance with RFC 4861.");
628