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: stable/11/sys/netinet6/in6_proto.c 364161 2020-08-12 12:07:15Z 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>
81295126Sglebius#include <sys/malloc.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>
88257176Sglebius#include <net/if_var.h>
8953541Sshin#include <net/radix.h>
9053541Sshin#include <net/route.h>
91178167Sqingli#ifdef RADIX_MPATH
92178167Sqingli#include <net/radix_mpath.h>
93178167Sqingli#endif
9453541Sshin
9553541Sshin#include <netinet/in.h>
9653541Sshin#include <netinet/in_systm.h>
9753541Sshin#include <netinet/in_var.h>
9862587Sitojun#include <netinet/ip_encap.h>
9953541Sshin#include <netinet/ip.h>
10053541Sshin#include <netinet/ip_var.h>
10162587Sitojun#include <netinet/ip6.h>
10253541Sshin#include <netinet6/ip6_var.h>
10362587Sitojun#include <netinet/icmp6.h>
10453541Sshin
10553541Sshin#include <netinet/tcp.h>
10653541Sshin#include <netinet/tcp_timer.h>
10753541Sshin#include <netinet/tcp_var.h>
10853541Sshin#include <netinet/udp.h>
10953541Sshin#include <netinet/udp_var.h>
11053541Sshin#include <netinet6/tcp6_var.h>
11178064Sume#include <netinet6/raw_ip6.h>
11253541Sshin#include <netinet6/udp6_var.h>
11353541Sshin#include <netinet6/pim6_var.h>
11453541Sshin#include <netinet6/nd6.h>
11553541Sshin
116163953Srrs#ifdef SCTP
117163953Srrs#include <netinet/in_pcb.h>
118163953Srrs#include <netinet/sctp_pcb.h>
119163953Srrs#include <netinet/sctp.h>
120163953Srrs#include <netinet/sctp_var.h>
121163953Srrs#include <netinet6/sctp6_var.h>
122163953Srrs#endif /* SCTP */
123163953Srrs
12453541Sshin#include <netinet6/ip6protosw.h>
12553541Sshin
12653541Sshin/*
12753541Sshin * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
12853541Sshin */
129222272SbzFEATURE(inet6, "Internet Protocol version 6");
13053541Sshin
13162587Sitojunextern	struct domain inet6domain;
132148917Sobrienstatic	struct pr_usrreqs nousrreqs;
13353541Sshin
13478064Sume#define PR_LISTEN	0
13578064Sume#define PR_ABRTACPTDIS	0
13678064Sume
137211115Sbz/* Spacer for loadable protocols. */
138211115Sbz#define IP6PROTOSPACER   			\
139211115Sbz{						\
140211115Sbz	.pr_domain =		&inet6domain,	\
141211115Sbz	.pr_protocol =		PROTO_SPACER,	\
142211115Sbz	.pr_usrreqs =		&nousrreqs	\
143211115Sbz}
144211115Sbz
145269699Skevlostruct protosw inet6sw[] = {
146152242Sru{
147152242Sru	.pr_type =		0,
148152242Sru	.pr_domain =		&inet6domain,
149152242Sru	.pr_protocol =		IPPROTO_IPV6,
150152242Sru	.pr_init =		ip6_init,
151152242Sru	.pr_slowtimo =		frag6_slowtimo,
152152242Sru	.pr_drain =		frag6_drain,
153152242Sru	.pr_usrreqs =		&nousrreqs,
15453541Sshin},
155152242Sru{
156152242Sru	.pr_type =		SOCK_DGRAM,
157152242Sru	.pr_domain =		&inet6domain,
158152242Sru	.pr_protocol =		IPPROTO_UDP,
159152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
160152242Sru	.pr_input =		udp6_input,
161152242Sru	.pr_ctlinput =		udp6_ctlinput,
162152242Sru	.pr_ctloutput =		ip6_ctloutput,
163220881Sbz#ifndef INET	/* Do not call initialization twice. */
164220881Sbz	.pr_init =		udp_init,
165220881Sbz#endif
166152242Sru	.pr_usrreqs =		&udp6_usrreqs,
16754263Sshin},
168152242Sru{
169152242Sru	.pr_type =		SOCK_STREAM,
170152242Sru	.pr_domain =		&inet6domain,
171152242Sru	.pr_protocol =		IPPROTO_TCP,
172152242Sru	.pr_flags =		PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
173152242Sru	.pr_input =		tcp6_input,
174152242Sru	.pr_ctlinput =		tcp6_ctlinput,
175152242Sru	.pr_ctloutput =		tcp_ctloutput,
176152242Sru#ifndef INET	/* don't call initialization and timeout routines twice */
177152242Sru	.pr_init =		tcp_init,
178152242Sru	.pr_slowtimo =		tcp_slowtimo,
17955679Sshin#endif
180152242Sru	.pr_drain =		tcp_drain,
181152242Sru	.pr_usrreqs =		&tcp6_usrreqs,
18255679Sshin},
183163953Srrs#ifdef SCTP
184171260Sdelphij{
185223963Stuexen	.pr_type =		SOCK_SEQPACKET,
186223963Stuexen	.pr_domain =		&inet6domain,
187223963Stuexen	.pr_protocol =		IPPROTO_SCTP,
188315514Sae	.pr_flags =		PR_WANTRCVD|PR_LASTHDR,
189223963Stuexen	.pr_input =		sctp6_input,
190223963Stuexen	.pr_ctlinput =		sctp6_ctlinput,
191223963Stuexen	.pr_ctloutput =	sctp_ctloutput,
192223963Stuexen	.pr_drain =		sctp_drain,
193220881Sbz#ifndef INET	/* Do not call initialization twice. */
194223963Stuexen	.pr_init =		sctp_init,
195220881Sbz#endif
196223963Stuexen	.pr_usrreqs =		&sctp6_usrreqs
197163953Srrs},
198152242Sru{
199223963Stuexen	.pr_type =		SOCK_STREAM,
200223963Stuexen	.pr_domain =		&inet6domain,
201223963Stuexen	.pr_protocol =		IPPROTO_SCTP,
202315514Sae	.pr_flags =		PR_CONNREQUIRED|PR_WANTRCVD|PR_LASTHDR,
203223963Stuexen	.pr_input =		sctp6_input,
204264213Skevlo	.pr_ctlinput =		sctp6_ctlinput,
205223963Stuexen	.pr_ctloutput =		sctp_ctloutput,
206223963Stuexen	.pr_drain =		sctp_drain,
207223963Stuexen	.pr_usrreqs =		&sctp6_usrreqs
208163953Srrs},
209163953Srrs#endif /* SCTP */
210163953Srrs{
211264212Skevlo	.pr_type =		SOCK_DGRAM,
212264212Skevlo	.pr_domain =		&inet6domain,
213264212Skevlo	.pr_protocol =		IPPROTO_UDPLITE,
214264212Skevlo	.pr_flags =		PR_ATOMIC|PR_ADDR,
215264212Skevlo	.pr_input =		udp6_input,
216264212Skevlo	.pr_ctlinput =		udplite6_ctlinput,
217264212Skevlo	.pr_ctloutput =		udp_ctloutput,
218264212Skevlo#ifndef INET	/* Do not call initialization twice. */
219264212Skevlo	.pr_init =		udplite_init,
220264212Skevlo#endif
221264212Skevlo	.pr_usrreqs =		&udp6_usrreqs,
222264212Skevlo},
223264212Skevlo{
224152242Sru	.pr_type =		SOCK_RAW,
225152242Sru	.pr_domain =		&inet6domain,
226152242Sru	.pr_protocol =		IPPROTO_RAW,
227152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
228152242Sru	.pr_input =		rip6_input,
229270008Skevlo	.pr_output =		rip6_output,
230152242Sru	.pr_ctlinput =		rip6_ctlinput,
231152242Sru	.pr_ctloutput =		rip6_ctloutput,
232220881Sbz#ifndef INET	/* Do not call initialization twice. */
233220881Sbz	.pr_init =		rip_init,
234220881Sbz#endif
235152242Sru	.pr_usrreqs =		&rip6_usrreqs
23653541Sshin},
237152242Sru{
238152242Sru	.pr_type =		SOCK_RAW,
239152242Sru	.pr_domain =		&inet6domain,
240152242Sru	.pr_protocol =		IPPROTO_ICMPV6,
241152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
242152242Sru	.pr_input =		icmp6_input,
243270008Skevlo	.pr_output =		rip6_output,
244152242Sru	.pr_ctlinput =		rip6_ctlinput,
245152242Sru	.pr_ctloutput =		rip6_ctloutput,
246152242Sru	.pr_fasttimo =		icmp6_fasttimo,
247191672Sbms	.pr_slowtimo =		icmp6_slowtimo,
248152242Sru	.pr_usrreqs =		&rip6_usrreqs
24953541Sshin},
250152242Sru{
251152242Sru	.pr_type =		SOCK_RAW,
252152242Sru	.pr_domain =		&inet6domain,
253152242Sru	.pr_protocol =		IPPROTO_DSTOPTS,
254152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
255152242Sru	.pr_input =		dest6_input,
256152242Sru	.pr_usrreqs =		&nousrreqs
25753541Sshin},
258152242Sru{
259152242Sru	.pr_type =		SOCK_RAW,
260152242Sru	.pr_domain =		&inet6domain,
261152242Sru	.pr_protocol =		IPPROTO_ROUTING,
262152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
263152242Sru	.pr_input =		route6_input,
264152242Sru	.pr_usrreqs =		&nousrreqs
26553541Sshin},
266152242Sru{
267152242Sru	.pr_type =		SOCK_RAW,
268152242Sru	.pr_domain =		&inet6domain,
269152242Sru	.pr_protocol =		IPPROTO_FRAGMENT,
270152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
271152242Sru	.pr_input =		frag6_input,
272152242Sru	.pr_usrreqs =		&nousrreqs
27353541Sshin},
27462587Sitojun#ifdef INET
275152242Sru{
276152242Sru	.pr_type =		SOCK_RAW,
277152242Sru	.pr_domain =		&inet6domain,
278152242Sru	.pr_protocol =		IPPROTO_IPV4,
279152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
280152242Sru	.pr_input =		encap6_input,
281270008Skevlo	.pr_output =		rip6_output,
282152242Sru	.pr_ctloutput =		rip6_ctloutput,
283152242Sru	.pr_usrreqs =		&rip6_usrreqs
28453541Sshin},
28595023Ssuz#endif /* INET */
286152242Sru{
287152242Sru	.pr_type =		SOCK_RAW,
288152242Sru	.pr_domain =		&inet6domain,
289152242Sru	.pr_protocol =		IPPROTO_IPV6,
290152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
291152242Sru	.pr_input =		encap6_input,
292270008Skevlo	.pr_output =		rip6_output,
293152242Sru	.pr_ctloutput =		rip6_ctloutput,
294152242Sru	.pr_usrreqs =		&rip6_usrreqs
29553541Sshin},
296152242Sru{
297152242Sru	.pr_type =		SOCK_RAW,
298152242Sru	.pr_domain =		&inet6domain,
299274246Sae	.pr_protocol =		IPPROTO_GRE,
300274246Sae	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
301274246Sae	.pr_input =		encap6_input,
302274246Sae	.pr_output =		rip6_output,
303274246Sae	.pr_ctloutput =		rip6_ctloutput,
304274246Sae	.pr_usrreqs =		&rip6_usrreqs
305274246Sae},
306274246Sae{
307274246Sae	.pr_type =		SOCK_RAW,
308274246Sae	.pr_domain =		&inet6domain,
309152242Sru	.pr_protocol =		IPPROTO_PIM,
310152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
311166938Sbms	.pr_input =		encap6_input,
312270008Skevlo	.pr_output =		rip6_output,
313152242Sru	.pr_ctloutput =		rip6_ctloutput,
314152242Sru	.pr_usrreqs =		&rip6_usrreqs
31556722Sshin},
316211115Sbz/* Spacer n-times for loadable protocols. */
317211115SbzIP6PROTOSPACER,
318211115SbzIP6PROTOSPACER,
319211115SbzIP6PROTOSPACER,
320211115SbzIP6PROTOSPACER,
321211115SbzIP6PROTOSPACER,
322211115SbzIP6PROTOSPACER,
323211115SbzIP6PROTOSPACER,
324211115SbzIP6PROTOSPACER,
32553541Sshin/* raw wildcard */
326152242Sru{
327152242Sru	.pr_type =		SOCK_RAW,
328152242Sru	.pr_domain =		&inet6domain,
329152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
330152242Sru	.pr_input =		rip6_input,
331270008Skevlo	.pr_output =		rip6_output,
332152242Sru	.pr_ctloutput =		rip6_ctloutput,
333152242Sru	.pr_usrreqs =		&rip6_usrreqs
33453541Sshin},
33553541Sshin};
33653541Sshin
337175162Sobrienextern int in6_inithead(void **, int);
338193731Szec#ifdef VIMAGE
339193731Szecextern int in6_detachhead(void **, int);
340193731Szec#endif
34162587Sitojun
342152242Srustruct domain inet6domain = {
343152242Sru	.dom_family =		AF_INET6,
344152242Sru	.dom_name =		"internet6",
345152242Sru	.dom_protosw =		(struct protosw *)inet6sw,
346298354Spfg	.dom_protoswNPROTOSW =	(struct protosw *)&inet6sw[nitems(inet6sw)],
347178167Sqingli#ifdef RADIX_MPATH
348178167Sqingli	.dom_rtattach =		rn6_mpath_inithead,
349178167Sqingli#else
350152242Sru	.dom_rtattach =		in6_inithead,
351178167Sqingli#endif
352193731Szec#ifdef VIMAGE
353193731Szec	.dom_rtdetach =		in6_detachhead,
354193731Szec#endif
355152242Sru	.dom_ifattach =		in6_domifattach,
356274175Smelifaro	.dom_ifdetach =		in6_domifdetach,
357274175Smelifaro	.dom_ifmtu    =		in6_domifmtu
358152242Sru};
35953541Sshin
360195837SrwatsonVNET_DOMAIN_SET(inet6);
36153541Sshin
36253541Sshin/*
36353541Sshin * Internet configuration info
36453541Sshin */
365207369Sbz#ifndef	IPV6FORWARDING
366207369Sbz#ifdef GATEWAY6
367207369Sbz#define	IPV6FORWARDING	1	/* forward IP6 packets not for us */
368207369Sbz#else
369207369Sbz#define	IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
370207369Sbz#endif /* GATEWAY6 */
371207369Sbz#endif /* !IPV6FORWARDING */
37253541Sshin
373207369Sbz#ifndef	IPV6_SENDREDIRECTS
374207369Sbz#define	IPV6_SENDREDIRECTS	1
375207369Sbz#endif
376207369Sbz
377207369SbzVNET_DEFINE(int, ip6_forwarding) = IPV6FORWARDING;	/* act as router? */
378207369SbzVNET_DEFINE(int, ip6_sendredirects) = IPV6_SENDREDIRECTS;
379207369SbzVNET_DEFINE(int, ip6_defhlim) = IPV6_DEFHLIM;
380207369SbzVNET_DEFINE(int, ip6_defmcasthlim) = IPV6_DEFAULT_MULTICAST_HOPS;
381207369SbzVNET_DEFINE(int, ip6_accept_rtadv) = 0;
382222728ShrsVNET_DEFINE(int, ip6_no_radr) = 0;
383222728ShrsVNET_DEFINE(int, ip6_norbit_raif) = 0;
384225521ShrsVNET_DEFINE(int, ip6_rfc6204w3) = 0;
385207369SbzVNET_DEFINE(int, ip6_maxfragpackets);	/* initialized in frag6.c:frag6_init() */
386337797Sjtlint ip6_maxfrags;		/* initialized in frag6.c:frag6_init() */
387337799SjtlVNET_DEFINE(int, ip6_maxfragbucketsize);/* initialized in frag6.c:frag6_init() */
388337798SjtlVNET_DEFINE(int, ip6_maxfragsperpacket); /* initialized in frag6.c:frag6_init() */
389207369SbzVNET_DEFINE(int, ip6_log_interval) = 5;
390207369SbzVNET_DEFINE(int, ip6_hdrnestlimit) = 15;/* How many header options will we
391207369Sbz					 * process? */
392207369SbzVNET_DEFINE(int, ip6_dad_count) = 1;	/* DupAddrDetectionTransmits */
393207369SbzVNET_DEFINE(int, ip6_auto_flowlabel) = 1;
394207369SbzVNET_DEFINE(int, ip6_use_deprecated) = 1;/* allow deprecated addr
395207369Sbz					 * (RFC2462 5.5.4) */
396207369SbzVNET_DEFINE(int, ip6_rr_prune) = 5;	/* router renumbering prefix
397207369Sbz					 * walk list every 5 sec. */
398207369SbzVNET_DEFINE(int, ip6_mcast_pmtu) = 0;	/* enable pMTU discovery for multicast? */
399207369SbzVNET_DEFINE(int, ip6_v6only) = 1;
400207369Sbz
401207369SbzVNET_DEFINE(time_t, ip6_log_time) = (time_t)0L;
402207369Sbz#ifdef IPSTEALTH
403207369SbzVNET_DEFINE(int, ip6stealth) = 0;
404207369Sbz#endif
405207369SbzVNET_DEFINE(int, nd6_onlink_ns_rfc4861) = 0;/* allow 'on-link' nd6 NS
406207369Sbz					     * (RFC 4861) */
407207369Sbz
40853541Sshin/* icmp6 */
40953541Sshin/*
41053541Sshin * BSDI4 defines these variables in in_proto.c...
41153541Sshin * XXX: what if we don't define INET? Should we define pmtu6_expire
41253541Sshin * or so? (jinmei@kame.net 19990310)
41353541Sshin */
414207369SbzVNET_DEFINE(int, pmtu_expire) = 60*10;
415207369SbzVNET_DEFINE(int, pmtu_probe) = 60*2;
41653541Sshin
41753541Sshin/* ICMPV6 parameters */
418207369SbzVNET_DEFINE(int, icmp6_rediraccept) = 1;/* accept and process redirects */
419207369SbzVNET_DEFINE(int, icmp6_redirtimeout) = 10 * 60;	/* 10 minutes */
420207369SbzVNET_DEFINE(int, icmp6errppslim) = 100;		/* 100pps */
421169664Sjinmei/* control how to respond to NI queries */
422207369SbzVNET_DEFINE(int, icmp6_nodeinfo) =
423207369Sbz    (ICMP6_NODEINFO_FQDNOK|ICMP6_NODEINFO_NODEADDROK);
424250251ShrsVNET_DEFINE(int, icmp6_nodeinfo_oldmcprefix) = 1;
42553541Sshin
42653541Sshin/*
42753541Sshin * sysctl related items.
42853541Sshin */
42953541SshinSYSCTL_NODE(_net,	PF_INET6,	inet6,	CTLFLAG_RW,	0,
43053541Sshin	"Internet6 Family");
43153541Sshin
43253541Sshin/* net.inet6 */
43353541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_IPV6,	ip6,	CTLFLAG_RW, 0,	"IP6");
43453541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_ICMPV6,	icmp6,	CTLFLAG_RW, 0,	"ICMP6");
43553541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_UDP,	udp6,	CTLFLAG_RW, 0,	"UDP6");
43653541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_TCP,	tcp6,	CTLFLAG_RW, 0,	"TCP6");
437163953Srrs#ifdef SCTP
438163953SrrsSYSCTL_NODE(_net_inet6,	IPPROTO_SCTP,	sctp6,	CTLFLAG_RW, 0,	"SCTP6");
439163953Srrs#endif
440315514Sae#if defined(IPSEC) || defined(IPSEC_SUPPORT)
44153541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_ESP,	ipsec6,	CTLFLAG_RW, 0,	"IPSEC6");
442171167Sgnn#endif /* IPSEC */
44353541Sshin
44453541Sshin/* net.inet6.ip6 */
44553541Sshinstatic int
44678064Sumesysctl_ip6_temppltime(SYSCTL_HANDLER_ARGS)
44753541Sshin{
448299827Smarkj	int error, val;
44953541Sshin
450299827Smarkj	val = V_ip6_temp_preferred_lifetime;
451299827Smarkj	error = sysctl_handle_int(oidp, &val, 0, req);
452299827Smarkj	if (error != 0 || !req->newptr)
45353541Sshin		return (error);
454299827Smarkj	if (val < V_ip6_desync_factor + V_ip6_temp_regen_advance)
455120856Sume		return (EINVAL);
456299827Smarkj	V_ip6_temp_preferred_lifetime = val;
457299827Smarkj	return (0);
45853541Sshin}
45953541Sshin
46062587Sitojunstatic int
46178064Sumesysctl_ip6_tempvltime(SYSCTL_HANDLER_ARGS)
46262587Sitojun{
463299827Smarkj	int error, val;
46462587Sitojun
465299827Smarkj	val = V_ip6_temp_valid_lifetime;
466299827Smarkj	error = sysctl_handle_int(oidp, &val, 0, req);
467299827Smarkj	if (error != 0 || !req->newptr)
46862587Sitojun		return (error);
469299827Smarkj	if (val < V_ip6_temp_preferred_lifetime)
470120856Sume		return (EINVAL);
471299827Smarkj	V_ip6_temp_valid_lifetime = val;
472299827Smarkj	return (0);
47362587Sitojun}
47462587Sitojun
475337799Sjtlstatic int
476337799Sjtlsysctl_ip6_maxfragpackets(SYSCTL_HANDLER_ARGS)
477337799Sjtl{
478337799Sjtl	int error, val;
479337799Sjtl
480337799Sjtl	val = V_ip6_maxfragpackets;
481337799Sjtl	error = sysctl_handle_int(oidp, &val, 0, req);
482337799Sjtl	if (error != 0 || !req->newptr)
483337799Sjtl		return (error);
484337799Sjtl	V_ip6_maxfragpackets = val;
485337799Sjtl	frag6_set_bucketsize();
486337799Sjtl	return (0);
487337799Sjtl}
488337799Sjtl
489274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_FORWARDING, forwarding,
490299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_forwarding), 0,
491313118Smarkj	"Enable forwarding of IPv6 packets between interfaces");
492274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_SENDREDIRECTS, redirect,
493299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_sendredirects), 0,
494313118Smarkj	"Send ICMPv6 redirects for unforwardable IPv6 packets");
495299827SmarkjSYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFHLIM, hlim,
496299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_defhlim), 0,
497313118Smarkj	"Default hop limit to use for outgoing IPv6 packets");
498253085SaeSYSCTL_VNET_PCPUSTAT(_net_inet6_ip6, IPV6CTL_STATS, stats, struct ip6stat,
499299827Smarkj	ip6stat,
500299827Smarkj	"IP6 statistics (struct ip6stat, netinet6/ip6_var.h)");
501337799SjtlSYSCTL_PROC(_net_inet6_ip6, IPV6CTL_MAXFRAGPACKETS, maxfragpackets,
502337799Sjtl	CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW, NULL, 0,
503337799Sjtl	sysctl_ip6_maxfragpackets, "I",
504313118Smarkj	"Default maximum number of outstanding fragmented IPv6 packets. "
505313118Smarkj	"A value of 0 means no fragmented packets will be accepted, while a "
506313118Smarkj	"a value of -1 means no limit");
507274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV, accept_rtadv,
508274225Sglebius	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_accept_rtadv), 0,
509299827Smarkj	"Default value of per-interface flag for accepting ICMPv6 RA messages");
510274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_NO_RADR, no_radr,
511274225Sglebius	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_no_radr), 0,
512222728Shrs	"Default value of per-interface flag to control whether routers "
513222728Shrs	"sending ICMPv6 RA messages on that interface are added into the "
514299827Smarkj	"default router list");
515274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_NORBIT_RAIF, norbit_raif,
516274225Sglebius	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_norbit_raif), 0,
517299827Smarkj	"Always set clear the R flag in ICMPv6 NA messages when accepting RA "
518299827Smarkj	"on the interface");
519274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_RFC6204W3, rfc6204w3,
520274225Sglebius	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_rfc6204w3), 0,
521225521Shrs	"Accept the default router list from ICMPv6 RA messages even "
522299827Smarkj	"when packet forwarding is enabled");
523274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_LOG_INTERVAL, log_interval,
524299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_log_interval), 0,
525299827Smarkj	"Frequency in seconds at which to log IPv6 forwarding errors");
526274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_HDRNESTLIMIT, hdrnestlimit,
527299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_hdrnestlimit), 0,
528313118Smarkj	"Default maximum number of IPv6 extension headers permitted on "
529313118Smarkj	"incoming IPv6 packets, 0 for no artificial limit");
530274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_DAD_COUNT, dad_count,
531299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_dad_count), 0,
532299827Smarkj	"Number of ICMPv6 NS messages sent during duplicate address detection");
533274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_AUTO_FLOWLABEL, auto_flowlabel,
534299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_auto_flowlabel), 0,
535299827Smarkj	"Provide an IPv6 flowlabel in outbound packets");
536274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFMCASTHLIM, defmcasthlim,
537299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_defmcasthlim), 0,
538313118Smarkj	"Default hop limit for IPv6 multicast packets originating from this "
539313118Smarkj	"node");
540195699SrwatsonSYSCTL_STRING(_net_inet6_ip6, IPV6CTL_KAME_VERSION, kame_version,
541299827Smarkj	CTLFLAG_RD, __KAME_VERSION, 0,
542299827Smarkj	"KAME version string");
543274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_USE_DEPRECATED, use_deprecated,
544299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_use_deprecated), 0,
545299827Smarkj	"Allow the use of addresses whose preferred lifetimes have expired");
546274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_RR_PRUNE, rr_prune,
547299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_rr_prune), 0,
548299827Smarkj	""); /* XXX unused */
549274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_USETEMPADDR, use_tempaddr,
550299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_use_tempaddr), 0,
551299827Smarkj	"Create RFC3041 temporary addresses for autoconfigured addresses");
552274225SglebiusSYSCTL_PROC(_net_inet6_ip6, IPV6CTL_TEMPPLTIME, temppltime,
553274225Sglebius	CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW,
554299827Smarkj	NULL, 0, sysctl_ip6_temppltime, "I",
555299827Smarkj	"Maximum preferred lifetime for temporary addresses");
556274225SglebiusSYSCTL_PROC(_net_inet6_ip6, IPV6CTL_TEMPVLTIME, tempvltime,
557274225Sglebius	CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW,
558299827Smarkj	NULL, 0, sysctl_ip6_tempvltime, "I",
559299827Smarkj	"Maximum valid lifetime for temporary addresses");
560274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_V6ONLY, v6only,
561299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_v6only), 0,
562299827Smarkj	"Restrict AF_INET6 sockets to IPv6 addresses only");
563274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_AUTO_LINKLOCAL, auto_linklocal,
564274225Sglebius	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_auto_linklocal), 0,
565299827Smarkj	"Default value of per-interface flag for automatically adding an IPv6 "
566299827Smarkj	"link-local address to interfaces when attached");
567253085SaeSYSCTL_VNET_PCPUSTAT(_net_inet6_ip6, IPV6CTL_RIP6STATS, rip6stats,
568274225Sglebius	struct rip6stat, rip6stat,
569274225Sglebius	"Raw IP6 statistics (struct rip6stat, netinet6/raw_ip6.h)");
570274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_PREFER_TEMPADDR, prefer_tempaddr,
571299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_prefer_tempaddr), 0,
572299827Smarkj	"Prefer RFC3041 temporary addresses in source address selection");
573274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_USE_DEFAULTZONE, use_defaultzone,
574299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_use_defzone), 0,
575299827Smarkj	"Use the default scope zone when none is specified");
576274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGS, maxfrags,
577337797Sjtl	CTLFLAG_RW, &ip6_maxfrags, 0,
578337797Sjtl	"Maximum allowed number of outstanding IPv6 packet fragments. "
579337797Sjtl	"A value of 0 means no fragmented packets will be accepted, while a "
580337797Sjtl	"a value of -1 means no limit");
581337799SjtlSYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGBUCKETSIZE, maxfragbucketsize,
582337799Sjtl	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_maxfragbucketsize), 0,
583337799Sjtl	"Maximum number of reassembly queues per hash bucket");
584337798SjtlSYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGSPERPACKET, maxfragsperpacket,
585337798Sjtl	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_maxfragsperpacket), 0,
586337798Sjtl	"Maximum allowed number of fragments per packet");
587274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_MCAST_PMTU, mcast_pmtu,
588299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_mcast_pmtu), 0,
589299827Smarkj	"Enable path MTU discovery for multicast packets");
590148921Ssuz#ifdef IPSTEALTH
591274225SglebiusSYSCTL_INT(_net_inet6_ip6, IPV6CTL_STEALTH, stealth, CTLFLAG_VNET | CTLFLAG_RW,
592299827Smarkj	&VNET_NAME(ip6stealth), 0,
593299827Smarkj	"Forward IPv6 packets without decrementing their TTL");
594148921Ssuz#endif
59553541Sshin
59653541Sshin/* net.inet6.icmp6 */
597274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRACCEPT, rediraccept,
598299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(icmp6_rediraccept), 0,
599299827Smarkj	"Accept ICMPv6 redirect messages");
600274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRTIMEOUT, redirtimeout,
601299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(icmp6_redirtimeout), 0,
602299827Smarkj	""); /* XXX unused */
603253085SaeSYSCTL_VNET_PCPUSTAT(_net_inet6_icmp6, ICMPV6CTL_STATS, stats,
604274225Sglebius	struct icmp6stat, icmp6stat,
605274225Sglebius	"ICMPv6 statistics (struct icmp6stat, netinet/icmp6.h)");
606274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PRUNE, nd6_prune,
607299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(nd6_prune), 0,
608299827Smarkj	"Frequency in seconds of checks for expired prefixes and routers");
609274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DELAY, nd6_delay,
610299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(nd6_delay), 0,
611299827Smarkj	"Delay in seconds before probing for reachability");
612274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_UMAXTRIES, nd6_umaxtries,
613299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(nd6_umaxtries), 0,
614299827Smarkj	"Number of ICMPv6 NS messages sent during reachability detection");
615274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MMAXTRIES, nd6_mmaxtries,
616299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(nd6_mmaxtries), 0,
617299827Smarkj	"Number of ICMPv6 NS messages sent during address resolution");
618274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_USELOOPBACK, nd6_useloopback,
619299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(nd6_useloopback), 0,
620299827Smarkj	"Create a loopback route when configuring an IPv6 address");
621274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO, nodeinfo,
622299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(icmp6_nodeinfo), 0,
623364161Sae	"Mask of enabled RFC4620 node information query types");
624274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO_OLDMCPREFIX,
625274225Sglebius	nodeinfo_oldmcprefix, CTLFLAG_VNET | CTLFLAG_RW,
626299827Smarkj	&VNET_NAME(icmp6_nodeinfo_oldmcprefix), 0,
627299827Smarkj	"Join old IPv6 NI group address in draft-ietf-ipngwg-icmp-name-lookup "
628299827Smarkj	"for compatibility with KAME implementation");
629274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ERRPPSLIMIT, errppslimit,
630299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(icmp6errppslim), 0,
631299827Smarkj	"Maximum number of ICMPv6 error messages per second");
632274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MAXNUDHINT, nd6_maxnudhint,
633299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(nd6_maxnudhint), 0,
634299827Smarkj	""); /* XXX unused */
635274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DEBUG, nd6_debug,
636299827Smarkj	CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(nd6_debug), 0,
637299827Smarkj	"Log NDP debug messages");
638274225SglebiusSYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_ONLINKNSRFC4861,
639274225Sglebius	nd6_onlink_ns_rfc4861, CTLFLAG_VNET | CTLFLAG_RW,
640274225Sglebius	&VNET_NAME(nd6_onlink_ns_rfc4861), 0,
641299827Smarkj	"Accept 'on-link' ICMPv6 NS messages in compliance with RFC 4861");
642