Home | History | Annotate | Line # | Download | only in netinet6
in6_proto.c revision 1.10
      1 /*	$NetBSD: in6_proto.c,v 1.10 2000/01/02 16:31:18 itojun Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the project nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Copyright (c) 1982, 1986, 1993
     34  *	The Regents of the University of California.  All rights reserved.
     35  *
     36  * Redistribution and use in source and binary forms, with or without
     37  * modification, are permitted provided that the following conditions
     38  * are met:
     39  * 1. Redistributions of source code must retain the above copyright
     40  *    notice, this list of conditions and the following disclaimer.
     41  * 2. Redistributions in binary form must reproduce the above copyright
     42  *    notice, this list of conditions and the following disclaimer in the
     43  *    documentation and/or other materials provided with the distribution.
     44  * 3. All advertising materials mentioning features or use of this software
     45  *    must display the following acknowledgement:
     46  *	This product includes software developed by the University of
     47  *	California, Berkeley and its contributors.
     48  * 4. Neither the name of the University nor the names of its contributors
     49  *    may be used to endorse or promote products derived from this software
     50  *    without specific prior written permission.
     51  *
     52  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  * SUCH DAMAGE.
     63  *
     64  *	@(#)in_proto.c	8.1 (Berkeley) 6/10/93
     65  */
     66 
     67 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__NetBSD__)
     68 #include "opt_inet.h"
     69 #ifdef __NetBSD__	/*XXX*/
     70 #include "opt_ipsec.h"
     71 #endif
     72 #endif
     73 
     74 #include <sys/param.h>
     75 #include <sys/socket.h>
     76 #if defined(__FreeBSD__)
     77 #include <sys/socketvar.h>
     78 #endif
     79 #include <sys/protosw.h>
     80 #include <sys/kernel.h>
     81 #include <sys/domain.h>
     82 #include <sys/mbuf.h>
     83 #ifdef __FreeBSD__
     84 #include <sys/systm.h>
     85 #include <sys/sysctl.h>
     86 #endif
     87 
     88 #include <net/if.h>
     89 #include <net/radix.h>
     90 #include <net/route.h>
     91 
     92 #include <netinet/in.h>
     93 #include <netinet/in_systm.h>
     94 #include <netinet/in_var.h>
     95 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || (defined(__NetBSD__) && !defined(TCP6)) || defined(__OpenBSD__) || (defined(__bsdi__) && _BSDI_VERSION >= 199802)
     96 #include <netinet/ip.h>
     97 #include <netinet/ip_var.h>
     98 #endif
     99 #if (defined(__NetBSD__) && !defined(TCP6)) || defined(__OpenBSD__) || (defined(__bsdi__) && _BSDI_VERSION >= 199802)
    100 #include <netinet/in_pcb.h>
    101 #endif
    102 #include <netinet6/ip6.h>
    103 #include <netinet6/ip6_var.h>
    104 #include <netinet6/icmp6.h>
    105 #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(__OpenBSD__) && !(defined(__bsdi__) && _BSDI_VERSION >= 199802)
    106 #include <netinet6/in6_pcb.h>
    107 #endif
    108 
    109 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__OpenBSD__) || (defined(__bsdi__) && _BSDI_VERSION >= 199802)
    110 #include <netinet/tcp.h>
    111 #include <netinet/tcp_timer.h>
    112 #include <netinet/tcp_var.h>
    113 #include <netinet/udp.h>
    114 #include <netinet/udp_var.h>
    115 #else
    116 #if defined(__NetBSD__) && !defined(TCP6)
    117 #include <netinet/tcp.h>
    118 #include <netinet/tcp_fsm.h>
    119 #include <netinet/tcp_seq.h>
    120 #include <netinet/tcp_timer.h>
    121 #include <netinet/tcp_var.h>
    122 #include <netinet/tcpip.h>
    123 #include <netinet/tcp_debug.h>
    124 #else
    125 #include <netinet6/tcp6.h>
    126 #include <netinet6/tcp6_fsm.h>
    127 #include <netinet6/tcp6_seq.h>
    128 #include <netinet6/tcp6_timer.h>
    129 #include <netinet6/tcp6_var.h>
    130 #endif
    131 #endif
    132 
    133 #if !defined(__OpenBSD__) && !(defined(__bsdi__) && _BSDI_VERSION >= 199802)
    134 #include <netinet6/udp6.h>
    135 #include <netinet6/udp6_var.h>
    136 #endif
    137 
    138 #include <netinet6/pim6_var.h>
    139 
    140 #include <netinet6/nd6.h>
    141 #ifdef __FreeBSD__
    142 #include <netinet6/in6_prefix.h>
    143 #endif
    144 
    145 #ifdef __OpenBSD__ /*KAME IPSEC*/
    146 #undef IPSEC
    147 #endif
    148 
    149 #ifdef IPSEC
    150 #include <netinet6/ipsec.h>
    151 #include <netinet6/ah.h>
    152 #ifdef IPSEC_ESP
    153 #include <netinet6/esp.h>
    154 #endif
    155 #include <netinet6/ipcomp.h>
    156 #endif /*IPSEC*/
    157 
    158 #include <netinet6/ip6protosw.h>
    159 
    160 #include "gif.h"
    161 #if NGIF > 0
    162 #include <netinet6/in6_gif.h>
    163 #endif
    164 
    165 #include <net/net_osdep.h>
    166 
    167 #define	offsetof(type, member)	((size_t)(&((type *)0)->member))
    168 
    169 /*
    170  * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
    171  */
    172 
    173 extern	struct domain inet6domain;
    174 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    175 static struct pr_usrreqs nousrreqs;
    176 #endif
    177 
    178 struct ip6protosw inet6sw[] = {
    179 { 0,		&inet6domain,	IPPROTO_IPV6,	0,
    180   0,		0,		0,		0,
    181   0,
    182   ip6_init,	0,		frag6_slowtimo,	frag6_drain,
    183 #ifndef __FreeBSD__
    184   ip6_sysctl,
    185 #else
    186 # if __FreeBSD__ >= 3
    187   &nousrreqs,
    188 # endif
    189 #endif
    190 },
    191 { SOCK_DGRAM,	&inet6domain,	IPPROTO_UDP,	PR_ATOMIC | PR_ADDR,
    192   udp6_input,	0,		udp6_ctlinput,	ip6_ctloutput,
    193 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    194  0, 0,
    195 #elif defined(HAVE_NRL_INPCB)
    196  udp6_usrreq,	0,
    197 #else
    198  udp6_usrreq,	udp6_init,
    199 #endif
    200   0,		0,		0,
    201 #ifndef __FreeBSD__
    202 #ifdef HAVE_NRL_INPCB
    203   udp_sysctl,
    204 #else
    205   udp6_sysctl,
    206 #endif
    207 #else
    208 # if __FreeBSD__ >= 3
    209   &udp6_usrreqs,
    210 # endif
    211 #endif
    212 },
    213 #ifdef TCP6
    214 { SOCK_STREAM,	&inet6domain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
    215   tcp6_input,	0,		tcp6_ctlinput,	tcp6_ctloutput,
    216   tcp6_usrreq,
    217   tcp6_init,	tcp6_fasttimo,	tcp6_slowtimo,	tcp6_drain,
    218 #ifndef __FreeBSD__
    219   tcp6_sysctl,
    220 #else
    221 # if __FreeBSD__ >= 3
    222   &tcp6_usrreqs,
    223 # endif
    224 #endif
    225 },
    226 #else
    227 { SOCK_STREAM,	&inet6domain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
    228   tcp6_input,	0,		tcp6_ctlinput,	tcp_ctloutput,
    229 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    230   0,
    231 #elif defined(HAVE_NRL_INPCB)
    232   tcp6_usrreq,
    233 #else
    234   tcp_usrreq,
    235 #endif
    236 #ifdef INET	/* don't call timeout routines twice */
    237   tcp_init,	0,		0,		tcp_drain,
    238 #else
    239   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
    240 #endif
    241 #ifndef __FreeBSD__
    242   tcp_sysctl,
    243 #else
    244 # if __FreeBSD__ >= 3
    245   &tcp6_usrreqs,
    246 # endif
    247 #endif
    248 },
    249 #endif /*TCP6*/
    250 { SOCK_RAW,	&inet6domain,	IPPROTO_RAW,	PR_ATOMIC | PR_ADDR,
    251   rip6_input,	rip6_output,	0,		rip6_ctloutput,
    252 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    253   0,
    254 #else
    255   rip6_usrreq,
    256 #endif
    257   0,		0,		0,		0,
    258 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    259   &rip6_usrreqs
    260 #endif
    261 },
    262 { SOCK_RAW,	&inet6domain,	IPPROTO_ICMPV6,	PR_ATOMIC | PR_ADDR,
    263   icmp6_input,	rip6_output,	0,		rip6_ctloutput,
    264 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    265   0,
    266 #else
    267   rip6_usrreq,
    268 #endif
    269   icmp6_init,	icmp6_fasttimo,	0,		0,
    270 #ifndef __FreeBSD__
    271   icmp6_sysctl,
    272 #else
    273 # if __FreeBSD__ >= 3
    274   &rip6_usrreqs
    275 # endif
    276 #endif
    277 },
    278 { SOCK_RAW,	&inet6domain,	IPPROTO_DSTOPTS,PR_ATOMIC|PR_ADDR,
    279   dest6_input,	0,	 	0,		0,
    280   0,
    281   0,		0,		0,		0,
    282 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    283   &nousrreqs
    284 #endif
    285 },
    286 { SOCK_RAW,	&inet6domain,	IPPROTO_ROUTING,PR_ATOMIC|PR_ADDR,
    287   route6_input,	0,	 	0,		0,
    288   0,
    289   0,		0,		0,		0,
    290 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    291   &nousrreqs
    292 #endif
    293 },
    294 { SOCK_RAW,	&inet6domain,	IPPROTO_FRAGMENT,PR_ATOMIC|PR_ADDR,
    295   frag6_input,	0,	 	0,		0,
    296   0,
    297   0,		0,		0,		0,
    298 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    299   &nousrreqs
    300 #endif
    301 },
    302 #ifdef IPSEC
    303 { SOCK_RAW,	&inet6domain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
    304   ah6_input,	0,	 	0,		0,
    305   0,
    306   0,		0,		0,		0,
    307 #ifndef __FreeBSD__
    308   ipsec6_sysctl,
    309 #else
    310 # if __FreeBSD__ >= 3
    311   &nousrreqs,
    312 # endif
    313 #endif
    314 },
    315 #ifdef IPSEC_ESP
    316 { SOCK_RAW,	&inet6domain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
    317   esp6_input,	0,	 	0,		0,
    318   0,
    319   0,		0,		0,		0,
    320 #ifndef __FreeBSD__
    321   ipsec6_sysctl,
    322 #else
    323 # if __FreeBSD__ >= 3
    324   &nousrreqs,
    325 # endif
    326 #endif
    327 },
    328 #endif
    329 { SOCK_RAW,	&inet6domain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
    330   ipcomp6_input, 0,	 	0,		0,
    331   0,
    332   0,		0,		0,		0,
    333 #ifndef __FreeBSD__
    334   ipsec6_sysctl,
    335 #else
    336 # if __FreeBSD__ >= 3
    337   &nousrreqs,
    338 # endif
    339 #endif
    340 },
    341 #endif /* IPSEC */
    342 #if NGIF > 0
    343 { SOCK_RAW,	&inet6domain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR,
    344   in6_gif_input,0,	 	0,		0,
    345   0,
    346   0,		0,		0,		0,
    347 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    348   &nousrreqs
    349 #endif
    350 },
    351 #ifdef INET6
    352 { SOCK_RAW,	&inet6domain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR,
    353   in6_gif_input,0,	 	0,		0,
    354   0,
    355   0,		0,		0,		0,
    356 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    357   &nousrreqs
    358 #endif
    359 },
    360 #endif /* INET6 */
    361 #endif /* GIF */
    362 { SOCK_RAW,     &inet6domain,	IPPROTO_PIM,	PR_ATOMIC|PR_ADDR,
    363   pim6_input,    rip6_output,	0,              rip6_ctloutput,
    364 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    365   0,
    366 #else
    367   rip6_usrreq,
    368 #endif
    369   0,            0,              0,              0,
    370 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    371   &rip6_usrreqs
    372 # endif
    373 },
    374 /* raw wildcard */
    375 { SOCK_RAW,	&inet6domain,	0,		PR_ATOMIC | PR_ADDR,
    376   rip6_input,	rip6_output,	0,		rip6_ctloutput,
    377 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    378   0, 0,
    379 #else
    380   rip6_usrreq, rip6_init,
    381 #endif
    382   0,		0,		0,
    383 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
    384   &rip6_usrreqs
    385 #endif
    386 },
    387 };
    388 
    389 #ifdef __FreeBSD__
    390 extern int in6_inithead __P((void **, int));
    391 #endif
    392 
    393 struct domain inet6domain =
    394     { AF_INET6, "internet6", 0, 0, 0,
    395       (struct protosw *)inet6sw,
    396       (struct protosw *)&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])], 0,
    397 #ifdef __FreeBSD__
    398       in6_inithead,
    399 #else
    400       rn_inithead,
    401 #endif
    402       offsetof(struct sockaddr_in6, sin6_addr) << 3,
    403       sizeof(struct sockaddr_in6) };
    404 
    405 #ifdef __FreeBSD__
    406 DOMAIN_SET(inet6);
    407 #endif
    408 
    409 /*
    410  * Internet configuration info
    411  */
    412 #ifndef	IPV6FORWARDING
    413 #ifdef GATEWAY6
    414 #define	IPV6FORWARDING	1	/* forward IP6 packets not for us */
    415 #else
    416 #define	IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
    417 #endif /* GATEWAY6 */
    418 #endif /* !IPV6FORWARDING */
    419 
    420 #ifndef	IPV6_SENDREDIRECTS
    421 #define	IPV6_SENDREDIRECTS	1
    422 #endif
    423 
    424 int	ip6_forwarding = IPV6FORWARDING;	/* act as router? */
    425 int	ip6_sendredirects = IPV6_SENDREDIRECTS;
    426 int	ip6_defhlim = IPV6_DEFHLIM;
    427 int	ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
    428 int	ip6_accept_rtadv = 0;	/* "IPV6FORWARDING ? 0 : 1" is dangerous */
    429 int	ip6_maxfragpackets = 200;
    430 int	ip6_log_interval = 5;
    431 int	ip6_hdrnestlimit = 50;	/* appropriate? */
    432 int	ip6_dad_count = 1;	/* DupAddrDetectionTransmits */
    433 u_int32_t ip6_flow_seq;
    434 int	ip6_auto_flowlabel = 1;
    435 #if NGIF > 0
    436 int	ip6_gif_hlim = GIF_HLIM;
    437 #else
    438 int	ip6_gif_hlim = 0;
    439 #endif
    440 int	ip6_use_deprecated = 1;	/* allow deprecated addr (RFC2462 5.5.4) */
    441 int	ip6_rr_prune = 5;	/* router renumbering prefix
    442 				 * walk list every 5 sec.    */
    443 u_int32_t ip6_id = 0UL;
    444 int	ip6_keepfaith = 0;
    445 time_t	ip6_log_time = (time_t)0L;
    446 
    447 /* icmp6 */
    448 #ifndef __bsdi__
    449 /*
    450  * BSDI4 defines these variables in in_proto.c...
    451  * XXX: what if we don't define INET? Should we define pmtu6_expire
    452  * or so? (jinmei (at) kame.net 19990310)
    453  */
    454 int pmtu_expire = 60*10;
    455 int pmtu_probe = 60*2;
    456 #endif
    457 
    458 /* raw IP6 parameters */
    459 /*
    460  * Nominal space allocated to a raw ip socket.
    461  */
    462 #define	RIPV6SNDQ	8192
    463 #define	RIPV6RCVQ	8192
    464 
    465 u_long	rip6_sendspace = RIPV6SNDQ;
    466 u_long	rip6_recvspace = RIPV6RCVQ;
    467 
    468 /* ICMPV6 parameters */
    469 int	icmp6_rediraccept = 1;		/* accept and process redirects */
    470 int	icmp6_redirtimeout = 10 * 60;	/* 10 minutes */
    471 u_int	icmp6errratelim = 1000;		/* 1000usec = 1msec */
    472 int	icmp6_nodeinfo = 1;		/* enable/disable NI response */
    473 
    474 #ifdef TCP6
    475 /* TCP on IP6 parameters */
    476 int	tcp6_sendspace = 1024 * 8;
    477 int	tcp6_recvspace = 1024 * 8;
    478 int 	tcp6_mssdflt = TCP6_MSS;
    479 int 	tcp6_rttdflt = TCP6TV_SRTTDFLT / PR_SLOWHZ;
    480 int	tcp6_do_rfc1323 = 1;
    481 int	tcp6_conntimeo = TCP6TV_KEEP_INIT;	/* initial connection timeout */
    482 int	tcp6_43maxseg = 0;
    483 int	tcp6_pmtu = 0;
    484 
    485 /*
    486  * Parameters for keepalive option.
    487  * Connections for which SO_KEEPALIVE is set will be probed
    488  * after being idle for a time of tcp6_keepidle (in units of PR_SLOWHZ).
    489  * Starting at that time, the connection is probed at intervals
    490  * of tcp6_keepintvl (same units) until a response is received
    491  * or until tcp6_keepcnt probes have been made, at which time
    492  * the connection is dropped.  Note that a tcp6_keepidle value
    493  * under 2 hours is nonconformant with RFC-1122, Internet Host Requirements.
    494  */
    495 int	tcp6_keepidle = TCP6TV_KEEP_IDLE;	/* time before probing idle */
    496 int	tcp6_keepintvl = TCP6TV_KEEPINTVL;	/* interval betwn idle probes */
    497 int	tcp6_keepcnt = TCP6TV_KEEPCNT;		/* max idle probes */
    498 int	tcp6_maxpersistidle = TCP6TV_KEEP_IDLE;	/* max idle time in persist */
    499 
    500 #ifndef INET_SERVER
    501 #define	TCP6_LISTEN_HASH_SIZE	17
    502 #define	TCP6_CONN_HASH_SIZE	97
    503 #define	TCP6_SYN_HASH_SIZE	293
    504 #define	TCP6_SYN_BUCKET_SIZE	35
    505 #else
    506 #define	TCP6_LISTEN_HASH_SIZE	97
    507 #define	TCP6_CONN_HASH_SIZE	9973
    508 #define	TCP6_SYN_HASH_SIZE	997
    509 #define	TCP6_SYN_BUCKET_SIZE	35
    510 #endif
    511 int	tcp6_listen_hash_size = TCP6_LISTEN_HASH_SIZE;
    512 int	tcp6_conn_hash_size = TCP6_CONN_HASH_SIZE;
    513 struct	tcp6_hash_list tcp6_listen_hash[TCP6_LISTEN_HASH_SIZE],
    514 	tcp6_conn_hash[TCP6_CONN_HASH_SIZE];
    515 
    516 int	tcp6_syn_cache_size = TCP6_SYN_HASH_SIZE;
    517 int	tcp6_syn_cache_limit = TCP6_SYN_HASH_SIZE*TCP6_SYN_BUCKET_SIZE;
    518 int	tcp6_syn_bucket_limit = 3*TCP6_SYN_BUCKET_SIZE;
    519 struct	syn_cache_head6 tcp6_syn_cache[TCP6_SYN_HASH_SIZE];
    520 struct	syn_cache_head6 *tcp6_syn_cache_first;
    521 int	tcp6_syn_cache_interval = 8;	/* runs timer every 4 seconds */
    522 int	tcp6_syn_cache_timeo = TCP6TV_KEEP_INIT;
    523 
    524 /*
    525  * Parameters for computing a desirable data segment size
    526  * given an upper bound (either interface MTU, or peer's MSS option)_.
    527  * As applications tend to use a buffer size that is a multiple
    528  * of kilobytes, try for something that divides evenly. However,
    529  * do not round down too much.
    530  *
    531  * Round segment size down to a multiple of TCP6_ROUNDSIZE if this
    532  * does not result in lowering by more than (size/TCP6_ROUNDFRAC).
    533  * For example, round 536 to 512.  Older versions of the system
    534  * effectively used MCLBYTES (1K or 2K) as TCP6_ROUNDSIZE, with
    535  * a value of 1 for TCP6_ROUNDFRAC (eliminating its effect).
    536  * We round to a multiple of 256 for SLIP.
    537  */
    538 #ifndef	TCP6_ROUNDSIZE
    539 #define	TCP6_ROUNDSIZE	256	/* round to multiple of 256 */
    540 #endif
    541 #ifndef	TCP6_ROUNDFRAC
    542 #define	TCP6_ROUNDFRAC	10	/* round down at most N/10, or 10% */
    543 #endif
    544 
    545 int	tcp6_roundsize = TCP6_ROUNDSIZE;
    546 int	tcp6_roundfrac = TCP6_ROUNDFRAC;
    547 #endif /*TCP6*/
    548 
    549 /* UDP on IP6 parameters */
    550 int	udp6_sendspace = 9216;		/* really max datagram size */
    551 int	udp6_recvspace = 40 * (1024 + sizeof(struct sockaddr_in6));
    552 					/* 40 1K datagrams */
    553 
    554 #ifdef __FreeBSD__
    555 /*
    556  * sysctl related items.
    557  */
    558 SYSCTL_NODE(_net,	PF_INET6,	inet6,	CTLFLAG_RW,	0,
    559 	"Internet6 Family");
    560 
    561 /* net.inet6 */
    562 SYSCTL_NODE(_net_inet6,	IPPROTO_IPV6,	ip6,	CTLFLAG_RW, 0,	"IP6");
    563 SYSCTL_NODE(_net_inet6,	IPPROTO_ICMPV6,	icmp6,	CTLFLAG_RW, 0,	"ICMP6");
    564 SYSCTL_NODE(_net_inet6,	IPPROTO_UDP,	udp6,	CTLFLAG_RW, 0,	"UDP6");
    565 SYSCTL_NODE(_net_inet6,	IPPROTO_TCP,	tcp6,	CTLFLAG_RW, 0,	"TCP6");
    566 #ifdef IPSEC
    567 SYSCTL_NODE(_net_inet6,	IPPROTO_ESP,	ipsec6,	CTLFLAG_RW, 0,	"IPSEC6");
    568 #endif /* IPSEC */
    569 
    570 /* net.inet6.ip6 */
    571 static int
    572 sysctl_ip6_forwarding SYSCTL_HANDLER_ARGS
    573 {
    574 	int error = 0;
    575 	int old_ip6_forwarding;
    576 	int changed;
    577 
    578 	error = SYSCTL_OUT(req, arg1, sizeof(int));
    579 	if (error || !req->newptr)
    580 		return (error);
    581 	old_ip6_forwarding = ip6_forwarding;
    582 	error = SYSCTL_IN(req, arg1, sizeof(int));
    583 	if (error != 0)
    584 		return (error);
    585 	changed = (ip6_forwarding ? 1 : 0) ^ (old_ip6_forwarding ? 1 : 0);
    586 	if (changed == 0)
    587 		return (error);
    588 	if (ip6_forwarding != 0) {	/* host becomes router */
    589 		int s = splnet();
    590 		struct nd_prefix *pr, *next;
    591 
    592 		for (pr = nd_prefix.lh_first; pr; pr = next) {
    593 			next = pr->ndpr_next;
    594 			if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
    595 				in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr);
    596 			prelist_remove(pr);
    597 		}
    598 		splx(s);
    599 	} else {			/* router becomes host */
    600 		struct socket so;
    601 
    602 		/* XXX: init dummy so */
    603 		bzero(&so, sizeof(so));
    604 		while(!LIST_EMPTY(&rr_prefix))
    605 			delete_each_prefix(&so, LIST_FIRST(&rr_prefix),
    606 					   PR_ORIG_KERNEL);
    607 	}
    608 
    609 	return (error);
    610 }
    611 
    612 SYSCTL_OID(_net_inet6_ip6, IPV6CTL_FORWARDING, forwarding,
    613 	   CTLTYPE_INT|CTLFLAG_RW, &ip6_forwarding, 0, sysctl_ip6_forwarding,
    614 	   "I", "");
    615 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_SENDREDIRECTS,
    616 	redirect, CTLFLAG_RW,		&ip6_sendredirects,	0, "");
    617 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFHLIM,
    618 	hlim, CTLFLAG_RW,		&ip6_defhlim,	0, "");
    619 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGPACKETS,
    620 	maxfragpackets, CTLFLAG_RW,	&ip6_maxfragpackets,	0, "");
    621 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV,
    622 	accept_rtadv, CTLFLAG_RW,	&ip6_accept_rtadv,	0, "");
    623 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_KEEPFAITH,
    624 	keepfaith, CTLFLAG_RW,		&ip6_keepfaith,	0, "");
    625 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_LOG_INTERVAL,
    626 	log_interval, CTLFLAG_RW,	&ip6_log_interval,	0, "");
    627 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_HDRNESTLIMIT,
    628 	hdrnestlimit, CTLFLAG_RW,	&ip6_hdrnestlimit,	0, "");
    629 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DAD_COUNT,
    630 	dad_count, CTLFLAG_RW,	&ip6_dad_count,	0, "");
    631 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_AUTO_FLOWLABEL,
    632 	auto_flowlabel, CTLFLAG_RW,	&ip6_auto_flowlabel,	0, "");
    633 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFMCASTHLIM,
    634 	defmcasthlim, CTLFLAG_RW,	&ip6_defmcasthlim,	0, "");
    635 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_GIF_HLIM,
    636 	gifhlim, CTLFLAG_RW,	&ip6_gif_hlim,			0, "");
    637 SYSCTL_STRING(_net_inet6_ip6, IPV6CTL_KAME_VERSION,
    638 	kame_version, CTLFLAG_RD,	__KAME_VERSION,		0, "");
    639 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_USE_DEPRECATED,
    640 	use_deprecated, CTLFLAG_RW,	&ip6_use_deprecated,	0, "");
    641 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_RR_PRUNE,
    642 	rr_prune, CTLFLAG_RW,	&ip6_rr_prune,			0, "");
    643 
    644 /* net.inet6.icmp6 */
    645 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRACCEPT,
    646 	rediraccept, CTLFLAG_RW,	&icmp6_rediraccept,	0, "");
    647 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRTIMEOUT,
    648 	redirtimeout, CTLFLAG_RW,	&icmp6_redirtimeout,	0, "");
    649 SYSCTL_STRUCT(_net_inet6_icmp6, ICMPV6CTL_STATS, stats, CTLFLAG_RD,
    650 	&icmp6stat, icmp6stat, "");
    651 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ERRRATELIMIT,
    652 	errratelimit, CTLFLAG_RW,	&icmp6errratelim,	0, "");
    653 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PRUNE,
    654 	nd6_prune, CTLFLAG_RW,		&nd6_prune,	0, "");
    655 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DELAY,
    656 	nd6_delay, CTLFLAG_RW,		&nd6_delay,	0, "");
    657 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_UMAXTRIES,
    658 	nd6_umaxtries, CTLFLAG_RW,	&nd6_umaxtries,	0, "");
    659 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MMAXTRIES,
    660 	nd6_mmaxtries, CTLFLAG_RW,	&nd6_mmaxtries,	0, "");
    661 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_USELOOPBACK,
    662 	nd6_useloopback, CTLFLAG_RW,	&nd6_useloopback, 0, "");
    663 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PROXYALL,
    664 	nd6_proxyall, CTLFLAG_RW,	&nd6_proxyall, 0, "");
    665 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO,
    666 	nodeinfo, CTLFLAG_RW,	&icmp6_nodeinfo,	0, "");
    667 
    668 #if __FreeBSD__ < 3
    669 /* net.inet6.udp6 */
    670 SYSCTL_INT(_net_inet6_udp6, UDP6CTL_SENDMAX,
    671 	sendmax, CTLFLAG_RW,	&udp6_sendspace,	0, "");
    672 SYSCTL_INT(_net_inet6_udp6, UDP6CTL_RECVSPACE,
    673 	recvspace, CTLFLAG_RW,	&udp6_recvspace,	0, "");
    674 
    675 /* net.inet6.tcp6 */
    676 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_MSSDFLT,
    677 	mssdflt, CTLFLAG_RW,	&tcp6_mssdflt, 0, "");
    678 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_DO_RFC1323,
    679 	do_rfc1323, CTLFLAG_RW,	&tcp6_do_rfc1323, 0, "");
    680 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_KEEPIDLE,
    681 	keepidle, CTLFLAG_RW,	&tcp6_keepidle, 0, "");
    682 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_KEEPINTVL,
    683 	keepintvl, CTLFLAG_RW,	&tcp6_keepintvl, 0, "");
    684 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_KEEPCNT,
    685 	keepcnt, CTLFLAG_RW,	&tcp6_keepcnt, 0, "");
    686 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_MAXPERSISTIDLE,
    687 	maxpersistidle, CTLFLAG_RW,	&tcp6_maxpersistidle, 0, "");
    688 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SENDSPACE,
    689 	sendspace, CTLFLAG_RW,	&tcp6_sendspace, 0, "");
    690 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_RECVSPACE,
    691 	recvspace, CTLFLAG_RW,	&tcp6_recvspace, 0, "");
    692 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_CONNTIMEO,
    693 	conntimeo, CTLFLAG_RW,	&tcp6_conntimeo, 0, "");
    694 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_PMTU,
    695 	pmtu, CTLFLAG_RW,	&tcp6_pmtu, 0, "");
    696 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_PMTU_EXPIRE,
    697 	pmtu_expire, CTLFLAG_RW,	&pmtu_expire, 0, "");
    698 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_PMTU_PROBE,
    699 	pmtu_probe, CTLFLAG_RW,	&pmtu_probe, 0, "");
    700 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_43MAXSEG,
    701 	pmtu_43maxseg, CTLFLAG_RW,	&tcp6_43maxseg, 0, "");
    702 SYSCTL_STRUCT(_net_inet6_tcp6, TCP6CTL_STATS, stats, CTLFLAG_RD,
    703 	&tcp6stat, tcp6stat, "");
    704 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SYN_CACHE_LIMIT,
    705 	syn_cache_limit, CTLFLAG_RW,	&tcp6_syn_cache_limit, 0, "");
    706 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SYN_BUCKET_LIMIT,
    707 	syn_bucket_limit, CTLFLAG_RW,	&tcp6_syn_bucket_limit, 0, "");
    708 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SYN_CACHE_INTER,
    709 	syn_cache_interval, CTLFLAG_RW, &tcp6_syn_cache_interval, 0, "");
    710 #endif /* !(defined(__FreeBSD__) && __FreeBSD__ >= 3) */
    711 
    712 #endif /* __FreeBSD__ */
    713