in6_proto.c revision 223963
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 223963 2011-07-12 19:29:29Z tuexen $");
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
129207828Skmacy#ifdef FLOWTABLE
130207828Skmacy#include <net/flowtable.h>
131207828Skmacy#endif
132207828Skmacy
13353541Sshin/*
13453541Sshin * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
13553541Sshin */
136222272SbzFEATURE(inet6, "Internet Protocol version 6");
13753541Sshin
13862587Sitojunextern	struct domain inet6domain;
139148917Sobrienstatic	struct pr_usrreqs nousrreqs;
14053541Sshin
14178064Sume#define PR_LISTEN	0
14278064Sume#define PR_ABRTACPTDIS	0
14378064Sume
144211115Sbz/* Spacer for loadable protocols. */
145211115Sbz#define IP6PROTOSPACER   			\
146211115Sbz{						\
147211115Sbz	.pr_domain =		&inet6domain,	\
148211115Sbz	.pr_protocol =		PROTO_SPACER,	\
149211115Sbz	.pr_usrreqs =		&nousrreqs	\
150211115Sbz}
151211115Sbz
15253541Sshinstruct ip6protosw inet6sw[] = {
153152242Sru{
154152242Sru	.pr_type =		0,
155152242Sru	.pr_domain =		&inet6domain,
156152242Sru	.pr_protocol =		IPPROTO_IPV6,
157152242Sru	.pr_init =		ip6_init,
158193731Szec#ifdef VIMAGE
159193731Szec	.pr_destroy =		ip6_destroy,
160193731Szec#endif
161152242Sru	.pr_slowtimo =		frag6_slowtimo,
162152242Sru	.pr_drain =		frag6_drain,
163152242Sru	.pr_usrreqs =		&nousrreqs,
16453541Sshin},
165152242Sru{
166152242Sru	.pr_type =		SOCK_DGRAM,
167152242Sru	.pr_domain =		&inet6domain,
168152242Sru	.pr_protocol =		IPPROTO_UDP,
169152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
170152242Sru	.pr_input =		udp6_input,
171152242Sru	.pr_ctlinput =		udp6_ctlinput,
172152242Sru	.pr_ctloutput =		ip6_ctloutput,
173220881Sbz#ifndef INET	/* Do not call initialization twice. */
174220881Sbz	.pr_init =		udp_init,
175220881Sbz#endif
176152242Sru	.pr_usrreqs =		&udp6_usrreqs,
17754263Sshin},
178152242Sru{
179152242Sru	.pr_type =		SOCK_STREAM,
180152242Sru	.pr_domain =		&inet6domain,
181152242Sru	.pr_protocol =		IPPROTO_TCP,
182152242Sru	.pr_flags =		PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
183152242Sru	.pr_input =		tcp6_input,
184152242Sru	.pr_ctlinput =		tcp6_ctlinput,
185152242Sru	.pr_ctloutput =		tcp_ctloutput,
186152242Sru#ifndef INET	/* don't call initialization and timeout routines twice */
187152242Sru	.pr_init =		tcp_init,
188152242Sru	.pr_slowtimo =		tcp_slowtimo,
18955679Sshin#endif
190152242Sru	.pr_drain =		tcp_drain,
191152242Sru	.pr_usrreqs =		&tcp6_usrreqs,
19255679Sshin},
193163953Srrs#ifdef SCTP
194171260Sdelphij{
195223963Stuexen	.pr_type =		SOCK_SEQPACKET,
196223963Stuexen	.pr_domain =		&inet6domain,
197223963Stuexen	.pr_protocol =		IPPROTO_SCTP,
198223963Stuexen	.pr_flags =		PR_WANTRCVD,
199223963Stuexen	.pr_input =		sctp6_input,
200223963Stuexen	.pr_ctlinput =		sctp6_ctlinput,
201223963Stuexen	.pr_ctloutput =	sctp_ctloutput,
202223963Stuexen	.pr_drain =		sctp_drain,
203220881Sbz#ifndef INET	/* Do not call initialization twice. */
204223963Stuexen	.pr_init =		sctp_init,
205220881Sbz#endif
206223963Stuexen	.pr_usrreqs =		&sctp6_usrreqs
207163953Srrs},
208152242Sru{
209223963Stuexen	.pr_type =		SOCK_STREAM,
210223963Stuexen	.pr_domain =		&inet6domain,
211223963Stuexen	.pr_protocol =		IPPROTO_SCTP,
212223963Stuexen	.pr_flags =		PR_WANTRCVD,
213223963Stuexen	.pr_input =		sctp6_input,
214223963Stuexen	.pr_ctlinput =	sctp6_ctlinput,
215223963Stuexen	.pr_ctloutput =		sctp_ctloutput,
216223963Stuexen	.pr_drain =		sctp_drain,
217223963Stuexen	.pr_usrreqs =		&sctp6_usrreqs
218163953Srrs},
219163953Srrs#endif /* SCTP */
220163953Srrs{
221152242Sru	.pr_type =		SOCK_RAW,
222152242Sru	.pr_domain =		&inet6domain,
223152242Sru	.pr_protocol =		IPPROTO_RAW,
224152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
225152242Sru	.pr_input =		rip6_input,
226152242Sru	.pr_output =		rip6_output,
227152242Sru	.pr_ctlinput =		rip6_ctlinput,
228152242Sru	.pr_ctloutput =		rip6_ctloutput,
229220881Sbz#ifndef INET	/* Do not call initialization twice. */
230220881Sbz	.pr_init =		rip_init,
231220881Sbz#endif
232152242Sru	.pr_usrreqs =		&rip6_usrreqs
23353541Sshin},
234152242Sru{
235152242Sru	.pr_type =		SOCK_RAW,
236152242Sru	.pr_domain =		&inet6domain,
237152242Sru	.pr_protocol =		IPPROTO_ICMPV6,
238152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
239152242Sru	.pr_input =		icmp6_input,
240152242Sru	.pr_output =		rip6_output,
241152242Sru	.pr_ctlinput =		rip6_ctlinput,
242152242Sru	.pr_ctloutput =		rip6_ctloutput,
243152242Sru	.pr_fasttimo =		icmp6_fasttimo,
244191672Sbms	.pr_slowtimo =		icmp6_slowtimo,
245152242Sru	.pr_usrreqs =		&rip6_usrreqs
24653541Sshin},
247152242Sru{
248152242Sru	.pr_type =		SOCK_RAW,
249152242Sru	.pr_domain =		&inet6domain,
250152242Sru	.pr_protocol =		IPPROTO_DSTOPTS,
251152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
252152242Sru	.pr_input =		dest6_input,
253152242Sru	.pr_usrreqs =		&nousrreqs
25453541Sshin},
255152242Sru{
256152242Sru	.pr_type =		SOCK_RAW,
257152242Sru	.pr_domain =		&inet6domain,
258152242Sru	.pr_protocol =		IPPROTO_ROUTING,
259152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
260152242Sru	.pr_input =		route6_input,
261152242Sru	.pr_usrreqs =		&nousrreqs
26253541Sshin},
263152242Sru{
264152242Sru	.pr_type =		SOCK_RAW,
265152242Sru	.pr_domain =		&inet6domain,
266152242Sru	.pr_protocol =		IPPROTO_FRAGMENT,
267152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
268152242Sru	.pr_input =		frag6_input,
269152242Sru	.pr_usrreqs =		&nousrreqs
27053541Sshin},
271171167Sgnn#ifdef IPSEC
272152242Sru{
273152242Sru	.pr_type =		SOCK_RAW,
274152242Sru	.pr_domain =		&inet6domain,
275152242Sru	.pr_protocol =		IPPROTO_AH,
276152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
277171133Sgnn	.pr_input =		ipsec6_common_input,
278152242Sru	.pr_usrreqs =		&nousrreqs,
27953541Sshin},
280152242Sru{
281152242Sru	.pr_type =		SOCK_RAW,
282152242Sru	.pr_domain =		&inet6domain,
283152242Sru	.pr_protocol =		IPPROTO_ESP,
284152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
285171133Sgnn        .pr_input =		ipsec6_common_input,
286152242Sru	.pr_ctlinput =		esp6_ctlinput,
287152242Sru	.pr_usrreqs =		&nousrreqs,
28853541Sshin},
289152242Sru{
290152242Sru	.pr_type =		SOCK_RAW,
291152242Sru	.pr_domain =		&inet6domain,
292152242Sru	.pr_protocol =		IPPROTO_IPCOMP,
293152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
294171133Sgnn        .pr_input =		ipsec6_common_input,
295152242Sru	.pr_usrreqs =		&nousrreqs,
29662587Sitojun},
297171167Sgnn#endif /* IPSEC */
29862587Sitojun#ifdef INET
299152242Sru{
300152242Sru	.pr_type =		SOCK_RAW,
301152242Sru	.pr_domain =		&inet6domain,
302152242Sru	.pr_protocol =		IPPROTO_IPV4,
303152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
304152242Sru	.pr_input =		encap6_input,
305152242Sru	.pr_output =		rip6_output,
306152242Sru	.pr_ctloutput =		rip6_ctloutput,
307152242Sru	.pr_init =		encap_init,
308152242Sru	.pr_usrreqs =		&rip6_usrreqs
30953541Sshin},
31095023Ssuz#endif /* INET */
311152242Sru{
312152242Sru	.pr_type =		SOCK_RAW,
313152242Sru	.pr_domain =		&inet6domain,
314152242Sru	.pr_protocol =		IPPROTO_IPV6,
315152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
316152242Sru	.pr_input =		encap6_input,
317152242Sru	.pr_output =		rip6_output,
318152242Sru	.pr_ctloutput =		rip6_ctloutput,
319152242Sru	.pr_init =		encap_init,
320152242Sru	.pr_usrreqs =		&rip6_usrreqs
32153541Sshin},
322152242Sru{
323152242Sru	.pr_type =		SOCK_RAW,
324152242Sru	.pr_domain =		&inet6domain,
325152242Sru	.pr_protocol =		IPPROTO_PIM,
326152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
327166938Sbms	.pr_input =		encap6_input,
328152242Sru	.pr_output =		rip6_output,
329152242Sru	.pr_ctloutput =		rip6_ctloutput,
330152242Sru	.pr_usrreqs =		&rip6_usrreqs
33156722Sshin},
332211115Sbz/* Spacer n-times for loadable protocols. */
333211115SbzIP6PROTOSPACER,
334211115SbzIP6PROTOSPACER,
335211115SbzIP6PROTOSPACER,
336211115SbzIP6PROTOSPACER,
337211115SbzIP6PROTOSPACER,
338211115SbzIP6PROTOSPACER,
339211115SbzIP6PROTOSPACER,
340211115SbzIP6PROTOSPACER,
34153541Sshin/* raw wildcard */
342152242Sru{
343152242Sru	.pr_type =		SOCK_RAW,
344152242Sru	.pr_domain =		&inet6domain,
345152242Sru	.pr_flags =		PR_ATOMIC|PR_ADDR,
346152242Sru	.pr_input =		rip6_input,
347152242Sru	.pr_output =		rip6_output,
348152242Sru	.pr_ctloutput =		rip6_ctloutput,
349152242Sru	.pr_usrreqs =		&rip6_usrreqs
35053541Sshin},
35153541Sshin};
35253541Sshin
353175162Sobrienextern int in6_inithead(void **, int);
354193731Szec#ifdef VIMAGE
355193731Szecextern int in6_detachhead(void **, int);
356193731Szec#endif
35762587Sitojun
358152242Srustruct domain inet6domain = {
359152242Sru	.dom_family =		AF_INET6,
360152242Sru	.dom_name =		"internet6",
361152242Sru	.dom_protosw =		(struct protosw *)inet6sw,
362152242Sru	.dom_protoswNPROTOSW =	(struct protosw *)
363152242Sru				&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])],
364178167Sqingli#ifdef RADIX_MPATH
365178167Sqingli	.dom_rtattach =		rn6_mpath_inithead,
366178167Sqingli#else
367152242Sru	.dom_rtattach =		in6_inithead,
368178167Sqingli#endif
369193731Szec#ifdef VIMAGE
370193731Szec	.dom_rtdetach =		in6_detachhead,
371193731Szec#endif
372152242Sru	.dom_rtoffset =		offsetof(struct sockaddr_in6, sin6_addr) << 3,
373152242Sru	.dom_maxrtkey =		sizeof(struct sockaddr_in6),
374152242Sru	.dom_ifattach =		in6_domifattach,
375152242Sru	.dom_ifdetach =		in6_domifdetach
376152242Sru};
37753541Sshin
378195837SrwatsonVNET_DOMAIN_SET(inet6);
37953541Sshin
38053541Sshin/*
38153541Sshin * Internet configuration info
38253541Sshin */
383207369Sbz#ifndef	IPV6FORWARDING
384207369Sbz#ifdef GATEWAY6
385207369Sbz#define	IPV6FORWARDING	1	/* forward IP6 packets not for us */
386207369Sbz#else
387207369Sbz#define	IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
388207369Sbz#endif /* GATEWAY6 */
389207369Sbz#endif /* !IPV6FORWARDING */
39053541Sshin
391207369Sbz#ifndef	IPV6_SENDREDIRECTS
392207369Sbz#define	IPV6_SENDREDIRECTS	1
393207369Sbz#endif
394207369Sbz
395207369SbzVNET_DEFINE(int, ip6_forwarding) = IPV6FORWARDING;	/* act as router? */
396207369SbzVNET_DEFINE(int, ip6_sendredirects) = IPV6_SENDREDIRECTS;
397207369SbzVNET_DEFINE(int, ip6_defhlim) = IPV6_DEFHLIM;
398207369SbzVNET_DEFINE(int, ip6_defmcasthlim) = IPV6_DEFAULT_MULTICAST_HOPS;
399207369SbzVNET_DEFINE(int, ip6_accept_rtadv) = 0;
400222728ShrsVNET_DEFINE(int, ip6_no_radr) = 0;
401222728ShrsVNET_DEFINE(int, ip6_norbit_raif) = 0;
402207369SbzVNET_DEFINE(int, ip6_maxfragpackets);	/* initialized in frag6.c:frag6_init() */
403207369SbzVNET_DEFINE(int, ip6_maxfrags);		/* initialized in frag6.c:frag6_init() */
404207369SbzVNET_DEFINE(int, ip6_log_interval) = 5;
405207369SbzVNET_DEFINE(int, ip6_hdrnestlimit) = 15;/* How many header options will we
406207369Sbz					 * process? */
407207369SbzVNET_DEFINE(int, ip6_dad_count) = 1;	/* DupAddrDetectionTransmits */
408207369SbzVNET_DEFINE(int, ip6_auto_flowlabel) = 1;
409207369SbzVNET_DEFINE(int, ip6_use_deprecated) = 1;/* allow deprecated addr
410207369Sbz					 * (RFC2462 5.5.4) */
411207369SbzVNET_DEFINE(int, ip6_rr_prune) = 5;	/* router renumbering prefix
412207369Sbz					 * walk list every 5 sec. */
413207369SbzVNET_DEFINE(int, ip6_mcast_pmtu) = 0;	/* enable pMTU discovery for multicast? */
414207369SbzVNET_DEFINE(int, ip6_v6only) = 1;
415207369Sbz
416207369SbzVNET_DEFINE(int, ip6_keepfaith) = 0;
417207369SbzVNET_DEFINE(time_t, ip6_log_time) = (time_t)0L;
418207369Sbz#ifdef IPSTEALTH
419207369SbzVNET_DEFINE(int, ip6stealth) = 0;
420207369Sbz#endif
421207369SbzVNET_DEFINE(int, nd6_onlink_ns_rfc4861) = 0;/* allow 'on-link' nd6 NS
422207369Sbz					     * (RFC 4861) */
423207369Sbz
42453541Sshin/* icmp6 */
42553541Sshin/*
42653541Sshin * BSDI4 defines these variables in in_proto.c...
42753541Sshin * XXX: what if we don't define INET? Should we define pmtu6_expire
42853541Sshin * or so? (jinmei@kame.net 19990310)
42953541Sshin */
430207369SbzVNET_DEFINE(int, pmtu_expire) = 60*10;
431207369SbzVNET_DEFINE(int, pmtu_probe) = 60*2;
43253541Sshin
43353541Sshin/* raw IP6 parameters */
43453541Sshin/*
43553541Sshin * Nominal space allocated to a raw ip socket.
43653541Sshin */
437207369Sbz#define	RIPV6SNDQ	8192
438207369Sbz#define	RIPV6RCVQ	8192
43953541Sshin
440207369SbzVNET_DEFINE(u_long, rip6_sendspace) = RIPV6SNDQ;
441207369SbzVNET_DEFINE(u_long, rip6_recvspace) = RIPV6RCVQ;
442207369Sbz
44353541Sshin/* ICMPV6 parameters */
444207369SbzVNET_DEFINE(int, icmp6_rediraccept) = 1;/* accept and process redirects */
445207369SbzVNET_DEFINE(int, icmp6_redirtimeout) = 10 * 60;	/* 10 minutes */
446207369SbzVNET_DEFINE(int, icmp6errppslim) = 100;		/* 100pps */
447169664Sjinmei/* control how to respond to NI queries */
448207369SbzVNET_DEFINE(int, icmp6_nodeinfo) =
449207369Sbz    (ICMP6_NODEINFO_FQDNOK|ICMP6_NODEINFO_NODEADDROK);
45053541Sshin
45153541Sshin/* UDP on IP6 parameters */
452207369SbzVNET_DEFINE(int, udp6_sendspace) = 9216;/* really max datagram size */
453207369SbzVNET_DEFINE(int, udp6_recvspace) = 40 * (1024 + sizeof(struct sockaddr_in6));
454207369Sbz					/* 40 1K datagrams */
45553541Sshin
45653541Sshin/*
45753541Sshin * sysctl related items.
45853541Sshin */
45953541SshinSYSCTL_NODE(_net,	PF_INET6,	inet6,	CTLFLAG_RW,	0,
46053541Sshin	"Internet6 Family");
46153541Sshin
46253541Sshin/* net.inet6 */
46353541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_IPV6,	ip6,	CTLFLAG_RW, 0,	"IP6");
46453541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_ICMPV6,	icmp6,	CTLFLAG_RW, 0,	"ICMP6");
46553541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_UDP,	udp6,	CTLFLAG_RW, 0,	"UDP6");
46653541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_TCP,	tcp6,	CTLFLAG_RW, 0,	"TCP6");
467163953Srrs#ifdef SCTP
468163953SrrsSYSCTL_NODE(_net_inet6,	IPPROTO_SCTP,	sctp6,	CTLFLAG_RW, 0,	"SCTP6");
469163953Srrs#endif
470171167Sgnn#ifdef IPSEC
47153541SshinSYSCTL_NODE(_net_inet6,	IPPROTO_ESP,	ipsec6,	CTLFLAG_RW, 0,	"IPSEC6");
472171167Sgnn#endif /* IPSEC */
47353541Sshin
47453541Sshin/* net.inet6.ip6 */
47553541Sshinstatic int
47678064Sumesysctl_ip6_temppltime(SYSCTL_HANDLER_ARGS)
47753541Sshin{
47853541Sshin	int error = 0;
47978064Sume	int old;
48053541Sshin
481195814Sbz	VNET_SYSCTL_ARG(req, arg1);
482191688Szec
48353541Sshin	error = SYSCTL_OUT(req, arg1, sizeof(int));
48453541Sshin	if (error || !req->newptr)
48553541Sshin		return (error);
486181803Sbz	old = V_ip6_temp_preferred_lifetime;
48753541Sshin	error = SYSCTL_IN(req, arg1, sizeof(int));
488181803Sbz	if (V_ip6_temp_preferred_lifetime <
489181803Sbz	    V_ip6_desync_factor + V_ip6_temp_regen_advance) {
490181803Sbz		V_ip6_temp_preferred_lifetime = old;
491120856Sume		return (EINVAL);
49253541Sshin	}
493120856Sume	return (error);
49453541Sshin}
49553541Sshin
49662587Sitojunstatic int
49778064Sumesysctl_ip6_tempvltime(SYSCTL_HANDLER_ARGS)
49862587Sitojun{
49978064Sume	int error = 0;
50078064Sume	int old;
50162587Sitojun
502195814Sbz	VNET_SYSCTL_ARG(req, arg1);
503191688Szec
50478064Sume	error = SYSCTL_OUT(req, arg1, sizeof(int));
50578064Sume	if (error || !req->newptr)
50662587Sitojun		return (error);
507181803Sbz	old = V_ip6_temp_valid_lifetime;
50878064Sume	error = SYSCTL_IN(req, arg1, sizeof(int));
509181803Sbz	if (V_ip6_temp_valid_lifetime < V_ip6_temp_preferred_lifetime) {
510181803Sbz		V_ip6_temp_preferred_lifetime = old;
511120856Sume		return (EINVAL);
51278064Sume	}
513120856Sume	return (error);
51462587Sitojun}
51562587Sitojun
516195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_FORWARDING, forwarding, CTLFLAG_RW,
517195699Srwatson	&VNET_NAME(ip6_forwarding), 0, "");
518195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_SENDREDIRECTS, redirect, CTLFLAG_RW,
519195699Srwatson	&VNET_NAME(ip6_sendredirects), 0, "");
520195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_DEFHLIM, hlim, CTLFLAG_RW,
521195699Srwatson	&VNET_NAME(ip6_defhlim), 0, "");
522195699SrwatsonSYSCTL_VNET_STRUCT(_net_inet6_ip6, IPV6CTL_STATS, stats, CTLFLAG_RD,
523195699Srwatson	&VNET_NAME(ip6stat), ip6stat, "");
524195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGPACKETS, maxfragpackets,
525195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_maxfragpackets), 0, "");
526195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV, accept_rtadv,
527197138Shrs	CTLFLAG_RW, &VNET_NAME(ip6_accept_rtadv), 0,
528197138Shrs	"Default value of per-interface flag for accepting ICMPv6 Router"
529197138Shrs	"Advertisement messages");
530222728ShrsSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_NO_RADR, no_radr,
531222728Shrs	CTLFLAG_RW, &VNET_NAME(ip6_no_radr), 0,
532222728Shrs	"Default value of per-interface flag to control whether routers "
533222728Shrs	"sending ICMPv6 RA messages on that interface are added into the "
534222728Shrs	"default router list.");
535222728ShrsSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_NORBIT_RAIF, norbit_raif, CTLFLAG_RW,
536222728Shrs	&VNET_NAME(ip6_norbit_raif), 0,
537222728Shrs	"Always set 0 to R flag in ICMPv6 NA messages when accepting RA"
538222728Shrs	" on the interface.");
539195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_KEEPFAITH, keepfaith, CTLFLAG_RW,
540195699Srwatson	&VNET_NAME(ip6_keepfaith), 0, "");
541195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_LOG_INTERVAL, log_interval,
542195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_log_interval), 0, "");
543195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_HDRNESTLIMIT, hdrnestlimit,
544195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_hdrnestlimit), 0, "");
545195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_DAD_COUNT, dad_count, CTLFLAG_RW,
546195699Srwatson	&VNET_NAME(ip6_dad_count), 0, "");
547195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_AUTO_FLOWLABEL, auto_flowlabel,
548195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_auto_flowlabel), 0, "");
549195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_DEFMCASTHLIM, defmcasthlim,
550195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_defmcasthlim), 0, "");
551195699SrwatsonSYSCTL_STRING(_net_inet6_ip6, IPV6CTL_KAME_VERSION, kame_version,
552195699Srwatson	CTLFLAG_RD, __KAME_VERSION, 0, "");
553195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_USE_DEPRECATED, use_deprecated,
554195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_use_deprecated), 0, "");
555195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_RR_PRUNE, rr_prune, CTLFLAG_RW,
556195699Srwatson	&VNET_NAME(ip6_rr_prune), 0, "");
557195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_USETEMPADDR, use_tempaddr,
558195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_use_tempaddr), 0, "");
559195699SrwatsonSYSCTL_VNET_PROC(_net_inet6_ip6, IPV6CTL_TEMPPLTIME, temppltime,
560195699Srwatson	CTLTYPE_INT|CTLFLAG_RW, &VNET_NAME(ip6_temp_preferred_lifetime), 0,
561183550Szec   	sysctl_ip6_temppltime, "I", "");
562195699SrwatsonSYSCTL_VNET_PROC(_net_inet6_ip6, IPV6CTL_TEMPVLTIME, tempvltime,
563195699Srwatson	CTLTYPE_INT|CTLFLAG_RW, &VNET_NAME(ip6_temp_valid_lifetime), 0,
564183550Szec   	sysctl_ip6_tempvltime, "I", "");
565195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_V6ONLY, v6only,	CTLFLAG_RW,
566195699Srwatson	&VNET_NAME(ip6_v6only), 0, "");
567195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_AUTO_LINKLOCAL, auto_linklocal,
568197138Shrs	CTLFLAG_RW, &VNET_NAME(ip6_auto_linklocal), 0,
569197138Shrs	"Default value of per-interface flag for automatically adding an IPv6"
570197138Shrs	" link-local address to interfaces when attached");
571195699SrwatsonSYSCTL_VNET_STRUCT(_net_inet6_ip6, IPV6CTL_RIP6STATS, rip6stats, CTLFLAG_RD,
572195699Srwatson	&VNET_NAME(rip6stat), rip6stat, "");
573195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_PREFER_TEMPADDR, prefer_tempaddr,
574195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_prefer_tempaddr), 0, "");
575195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_USE_DEFAULTZONE, use_defaultzone,
576195699Srwatson	CTLFLAG_RW, &VNET_NAME(ip6_use_defzone), 0,"");
577195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGS, maxfrags, CTLFLAG_RW,
578195699Srwatson	&VNET_NAME(ip6_maxfrags), 0, "");
579195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_MCAST_PMTU, mcast_pmtu, CTLFLAG_RW,
580195699Srwatson	&VNET_NAME(ip6_mcast_pmtu), 0, "");
581148921Ssuz#ifdef IPSTEALTH
582195699SrwatsonSYSCTL_VNET_INT(_net_inet6_ip6, IPV6CTL_STEALTH, stealth, CTLFLAG_RW,
583195699Srwatson	&VNET_NAME(ip6stealth), 0, "");
584148921Ssuz#endif
58553541Sshin
586207828Skmacy#ifdef FLOWTABLE
587207828SkmacyVNET_DEFINE(int, ip6_output_flowtable_size) = 2048;
588207828SkmacyVNET_DEFINE(struct flowtable *, ip6_ft);
589207828Skmacy#define	V_ip6_output_flowtable_size	VNET(ip6_output_flowtable_size)
590207828Skmacy
591207828SkmacySYSCTL_VNET_INT(_net_inet6_ip6, OID_AUTO, output_flowtable_size, CTLFLAG_RDTUN,
592207828Skmacy    &VNET_NAME(ip6_output_flowtable_size), 2048,
593207828Skmacy    "number of entries in the per-cpu output flow caches");
594207828Skmacy#endif
595207828Skmacy
59653541Sshin/* net.inet6.icmp6 */
597195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRACCEPT, rediraccept,
598195699Srwatson	CTLFLAG_RW, &VNET_NAME(icmp6_rediraccept), 0, "");
599195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRTIMEOUT, redirtimeout,
600195699Srwatson	CTLFLAG_RW, &VNET_NAME(icmp6_redirtimeout), 0, "");
601195699SrwatsonSYSCTL_VNET_STRUCT(_net_inet6_icmp6, ICMPV6CTL_STATS, stats, CTLFLAG_RD,
602195699Srwatson	&VNET_NAME(icmp6stat), icmp6stat, "");
603195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PRUNE, nd6_prune, CTLFLAG_RW,
604195699Srwatson	&VNET_NAME(nd6_prune), 0, "");
605195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DELAY, nd6_delay, CTLFLAG_RW,
606195699Srwatson	&VNET_NAME(nd6_delay), 0, "");
607195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_UMAXTRIES, nd6_umaxtries,
608195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_umaxtries), 0, "");
609195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MMAXTRIES, nd6_mmaxtries,
610195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_mmaxtries), 0, "");
611195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_USELOOPBACK, nd6_useloopback,
612195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_useloopback), 0, "");
613195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO, nodeinfo, CTLFLAG_RW,
614195699Srwatson	&VNET_NAME(icmp6_nodeinfo), 0, "");
615195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ERRPPSLIMIT, errppslimit,
616195699Srwatson	CTLFLAG_RW, &VNET_NAME(icmp6errppslim), 0, "");
617195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MAXNUDHINT, nd6_maxnudhint,
618195699Srwatson	CTLFLAG_RW, &VNET_NAME(nd6_maxnudhint), 0, "");
619195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DEBUG, nd6_debug, CTLFLAG_RW,
620195699Srwatson	&VNET_NAME(nd6_debug), 0, "");
621195699SrwatsonSYSCTL_VNET_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_ONLINKNSRFC4861,
622195699Srwatson	nd6_onlink_ns_rfc4861, CTLFLAG_RW, &VNET_NAME(nd6_onlink_ns_rfc4861),
623195699Srwatson	0, "Accept 'on-link' nd6 NS in compliance with RFC 4861.");
624