Home | History | Annotate | Line # | Download | only in netinet6
in6_proto.c revision 1.9
      1 /*	$NetBSD: in6_proto.c,v 1.9 1999/12/13 15:17:22 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 
    473 #ifdef TCP6
    474 /* TCP on IP6 parameters */
    475 int	tcp6_sendspace = 1024 * 8;
    476 int	tcp6_recvspace = 1024 * 8;
    477 int 	tcp6_mssdflt = TCP6_MSS;
    478 int 	tcp6_rttdflt = TCP6TV_SRTTDFLT / PR_SLOWHZ;
    479 int	tcp6_do_rfc1323 = 1;
    480 int	tcp6_conntimeo = TCP6TV_KEEP_INIT;	/* initial connection timeout */
    481 int	tcp6_43maxseg = 0;
    482 int	tcp6_pmtu = 0;
    483 
    484 /*
    485  * Parameters for keepalive option.
    486  * Connections for which SO_KEEPALIVE is set will be probed
    487  * after being idle for a time of tcp6_keepidle (in units of PR_SLOWHZ).
    488  * Starting at that time, the connection is probed at intervals
    489  * of tcp6_keepintvl (same units) until a response is received
    490  * or until tcp6_keepcnt probes have been made, at which time
    491  * the connection is dropped.  Note that a tcp6_keepidle value
    492  * under 2 hours is nonconformant with RFC-1122, Internet Host Requirements.
    493  */
    494 int	tcp6_keepidle = TCP6TV_KEEP_IDLE;	/* time before probing idle */
    495 int	tcp6_keepintvl = TCP6TV_KEEPINTVL;	/* interval betwn idle probes */
    496 int	tcp6_keepcnt = TCP6TV_KEEPCNT;		/* max idle probes */
    497 int	tcp6_maxpersistidle = TCP6TV_KEEP_IDLE;	/* max idle time in persist */
    498 
    499 #ifndef INET_SERVER
    500 #define	TCP6_LISTEN_HASH_SIZE	17
    501 #define	TCP6_CONN_HASH_SIZE	97
    502 #define	TCP6_SYN_HASH_SIZE	293
    503 #define	TCP6_SYN_BUCKET_SIZE	35
    504 #else
    505 #define	TCP6_LISTEN_HASH_SIZE	97
    506 #define	TCP6_CONN_HASH_SIZE	9973
    507 #define	TCP6_SYN_HASH_SIZE	997
    508 #define	TCP6_SYN_BUCKET_SIZE	35
    509 #endif
    510 int	tcp6_listen_hash_size = TCP6_LISTEN_HASH_SIZE;
    511 int	tcp6_conn_hash_size = TCP6_CONN_HASH_SIZE;
    512 struct	tcp6_hash_list tcp6_listen_hash[TCP6_LISTEN_HASH_SIZE],
    513 	tcp6_conn_hash[TCP6_CONN_HASH_SIZE];
    514 
    515 int	tcp6_syn_cache_size = TCP6_SYN_HASH_SIZE;
    516 int	tcp6_syn_cache_limit = TCP6_SYN_HASH_SIZE*TCP6_SYN_BUCKET_SIZE;
    517 int	tcp6_syn_bucket_limit = 3*TCP6_SYN_BUCKET_SIZE;
    518 struct	syn_cache_head6 tcp6_syn_cache[TCP6_SYN_HASH_SIZE];
    519 struct	syn_cache_head6 *tcp6_syn_cache_first;
    520 int	tcp6_syn_cache_interval = 8;	/* runs timer every 4 seconds */
    521 int	tcp6_syn_cache_timeo = TCP6TV_KEEP_INIT;
    522 
    523 /*
    524  * Parameters for computing a desirable data segment size
    525  * given an upper bound (either interface MTU, or peer's MSS option)_.
    526  * As applications tend to use a buffer size that is a multiple
    527  * of kilobytes, try for something that divides evenly. However,
    528  * do not round down too much.
    529  *
    530  * Round segment size down to a multiple of TCP6_ROUNDSIZE if this
    531  * does not result in lowering by more than (size/TCP6_ROUNDFRAC).
    532  * For example, round 536 to 512.  Older versions of the system
    533  * effectively used MCLBYTES (1K or 2K) as TCP6_ROUNDSIZE, with
    534  * a value of 1 for TCP6_ROUNDFRAC (eliminating its effect).
    535  * We round to a multiple of 256 for SLIP.
    536  */
    537 #ifndef	TCP6_ROUNDSIZE
    538 #define	TCP6_ROUNDSIZE	256	/* round to multiple of 256 */
    539 #endif
    540 #ifndef	TCP6_ROUNDFRAC
    541 #define	TCP6_ROUNDFRAC	10	/* round down at most N/10, or 10% */
    542 #endif
    543 
    544 int	tcp6_roundsize = TCP6_ROUNDSIZE;
    545 int	tcp6_roundfrac = TCP6_ROUNDFRAC;
    546 #endif /*TCP6*/
    547 
    548 /* UDP on IP6 parameters */
    549 int	udp6_sendspace = 9216;		/* really max datagram size */
    550 int	udp6_recvspace = 40 * (1024 + sizeof(struct sockaddr_in6));
    551 					/* 40 1K datagrams */
    552 
    553 #ifdef __FreeBSD__
    554 /*
    555  * sysctl related items.
    556  */
    557 SYSCTL_NODE(_net,	PF_INET6,	inet6,	CTLFLAG_RW,	0,
    558 	"Internet6 Family");
    559 
    560 /* net.inet6 */
    561 SYSCTL_NODE(_net_inet6,	IPPROTO_IPV6,	ip6,	CTLFLAG_RW, 0,	"IP6");
    562 SYSCTL_NODE(_net_inet6,	IPPROTO_ICMPV6,	icmp6,	CTLFLAG_RW, 0,	"ICMP6");
    563 SYSCTL_NODE(_net_inet6,	IPPROTO_UDP,	udp6,	CTLFLAG_RW, 0,	"UDP6");
    564 SYSCTL_NODE(_net_inet6,	IPPROTO_TCP,	tcp6,	CTLFLAG_RW, 0,	"TCP6");
    565 #ifdef IPSEC
    566 SYSCTL_NODE(_net_inet6,	IPPROTO_ESP,	ipsec6,	CTLFLAG_RW, 0,	"IPSEC6");
    567 #endif /* IPSEC */
    568 
    569 /* net.inet6.ip6 */
    570 static int
    571 sysctl_ip6_forwarding SYSCTL_HANDLER_ARGS
    572 {
    573 	int error = 0;
    574 	int old_ip6_forwarding;
    575 	int changed;
    576 
    577 	error = SYSCTL_OUT(req, arg1, sizeof(int));
    578 	if (error || !req->newptr)
    579 		return (error);
    580 	old_ip6_forwarding = ip6_forwarding;
    581 	error = SYSCTL_IN(req, arg1, sizeof(int));
    582 	if (error != 0)
    583 		return (error);
    584 	changed = (ip6_forwarding ? 1 : 0) ^ (old_ip6_forwarding ? 1 : 0);
    585 	if (changed == 0)
    586 		return (error);
    587 	if (ip6_forwarding != 0) {	/* host becomes router */
    588 		int s = splnet();
    589 		struct nd_prefix *pr, *next;
    590 
    591 		for (pr = nd_prefix.lh_first; pr; pr = next) {
    592 			next = pr->ndpr_next;
    593 			if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
    594 				in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr);
    595 			prelist_remove(pr);
    596 		}
    597 		splx(s);
    598 	} else {			/* router becomes host */
    599 		struct socket so;
    600 
    601 		/* XXX: init dummy so */
    602 		bzero(&so, sizeof(so));
    603 		while(!LIST_EMPTY(&rr_prefix))
    604 			delete_each_prefix(&so, LIST_FIRST(&rr_prefix),
    605 					   PR_ORIG_KERNEL);
    606 	}
    607 
    608 	return (error);
    609 }
    610 
    611 SYSCTL_OID(_net_inet6_ip6, IPV6CTL_FORWARDING, forwarding,
    612 	   CTLTYPE_INT|CTLFLAG_RW, &ip6_forwarding, 0, sysctl_ip6_forwarding,
    613 	   "I", "");
    614 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_SENDREDIRECTS,
    615 	redirect, CTLFLAG_RW,		&ip6_sendredirects,	0, "");
    616 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFHLIM,
    617 	hlim, CTLFLAG_RW,		&ip6_defhlim,	0, "");
    618 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGPACKETS,
    619 	maxfragpackets, CTLFLAG_RW,	&ip6_maxfragpackets,	0, "");
    620 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV,
    621 	accept_rtadv, CTLFLAG_RW,	&ip6_accept_rtadv,	0, "");
    622 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_KEEPFAITH,
    623 	keepfaith, CTLFLAG_RW,		&ip6_keepfaith,	0, "");
    624 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_LOG_INTERVAL,
    625 	log_interval, CTLFLAG_RW,	&ip6_log_interval,	0, "");
    626 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_HDRNESTLIMIT,
    627 	hdrnestlimit, CTLFLAG_RW,	&ip6_hdrnestlimit,	0, "");
    628 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DAD_COUNT,
    629 	dad_count, CTLFLAG_RW,	&ip6_dad_count,	0, "");
    630 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_AUTO_FLOWLABEL,
    631 	auto_flowlabel, CTLFLAG_RW,	&ip6_auto_flowlabel,	0, "");
    632 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFMCASTHLIM,
    633 	defmcasthlim, CTLFLAG_RW,	&ip6_defmcasthlim,	0, "");
    634 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_GIF_HLIM,
    635 	gifhlim, CTLFLAG_RW,	&ip6_gif_hlim,			0, "");
    636 SYSCTL_STRING(_net_inet6_ip6, IPV6CTL_KAME_VERSION,
    637 	kame_version, CTLFLAG_RD,	__KAME_VERSION,		0, "");
    638 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_USE_DEPRECATED,
    639 	use_deprecated, CTLFLAG_RW,	&ip6_use_deprecated,	0, "");
    640 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_RR_PRUNE,
    641 	rr_prune, CTLFLAG_RW,	&ip6_rr_prune,			0, "");
    642 
    643 /* net.inet6.icmp6 */
    644 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRACCEPT,
    645 	rediraccept, CTLFLAG_RW,	&icmp6_rediraccept,	0, "");
    646 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRTIMEOUT,
    647 	redirtimeout, CTLFLAG_RW,	&icmp6_redirtimeout,	0, "");
    648 SYSCTL_STRUCT(_net_inet6_icmp6, ICMPV6CTL_STATS, stats, CTLFLAG_RD,
    649 	&icmp6stat, icmp6stat, "");
    650 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ERRRATELIMIT,
    651 	errratelimit, CTLFLAG_RW,	&icmp6errratelim,	0, "");
    652 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PRUNE,
    653 	nd6_prune, CTLFLAG_RW,		&nd6_prune,	0, "");
    654 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DELAY,
    655 	nd6_delay, CTLFLAG_RW,		&nd6_delay,	0, "");
    656 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_UMAXTRIES,
    657 	nd6_umaxtries, CTLFLAG_RW,	&nd6_umaxtries,	0, "");
    658 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MMAXTRIES,
    659 	nd6_mmaxtries, CTLFLAG_RW,	&nd6_mmaxtries,	0, "");
    660 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_USELOOPBACK,
    661 	nd6_useloopback, CTLFLAG_RW,	&nd6_useloopback, 0, "");
    662 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PROXYALL,
    663 	nd6_proxyall, CTLFLAG_RW,	&nd6_proxyall, 0, "");
    664 
    665 #if __FreeBSD__ < 3
    666 /* net.inet6.udp6 */
    667 SYSCTL_INT(_net_inet6_udp6, UDP6CTL_SENDMAX,
    668 	sendmax, CTLFLAG_RW,	&udp6_sendspace,	0, "");
    669 SYSCTL_INT(_net_inet6_udp6, UDP6CTL_RECVSPACE,
    670 	recvspace, CTLFLAG_RW,	&udp6_recvspace,	0, "");
    671 
    672 /* net.inet6.tcp6 */
    673 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_MSSDFLT,
    674 	mssdflt, CTLFLAG_RW,	&tcp6_mssdflt, 0, "");
    675 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_DO_RFC1323,
    676 	do_rfc1323, CTLFLAG_RW,	&tcp6_do_rfc1323, 0, "");
    677 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_KEEPIDLE,
    678 	keepidle, CTLFLAG_RW,	&tcp6_keepidle, 0, "");
    679 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_KEEPINTVL,
    680 	keepintvl, CTLFLAG_RW,	&tcp6_keepintvl, 0, "");
    681 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_KEEPCNT,
    682 	keepcnt, CTLFLAG_RW,	&tcp6_keepcnt, 0, "");
    683 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_MAXPERSISTIDLE,
    684 	maxpersistidle, CTLFLAG_RW,	&tcp6_maxpersistidle, 0, "");
    685 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SENDSPACE,
    686 	sendspace, CTLFLAG_RW,	&tcp6_sendspace, 0, "");
    687 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_RECVSPACE,
    688 	recvspace, CTLFLAG_RW,	&tcp6_recvspace, 0, "");
    689 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_CONNTIMEO,
    690 	conntimeo, CTLFLAG_RW,	&tcp6_conntimeo, 0, "");
    691 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_PMTU,
    692 	pmtu, CTLFLAG_RW,	&tcp6_pmtu, 0, "");
    693 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_PMTU_EXPIRE,
    694 	pmtu_expire, CTLFLAG_RW,	&pmtu_expire, 0, "");
    695 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_PMTU_PROBE,
    696 	pmtu_probe, CTLFLAG_RW,	&pmtu_probe, 0, "");
    697 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_43MAXSEG,
    698 	pmtu_43maxseg, CTLFLAG_RW,	&tcp6_43maxseg, 0, "");
    699 SYSCTL_STRUCT(_net_inet6_tcp6, TCP6CTL_STATS, stats, CTLFLAG_RD,
    700 	&tcp6stat, tcp6stat, "");
    701 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SYN_CACHE_LIMIT,
    702 	syn_cache_limit, CTLFLAG_RW,	&tcp6_syn_cache_limit, 0, "");
    703 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SYN_BUCKET_LIMIT,
    704 	syn_bucket_limit, CTLFLAG_RW,	&tcp6_syn_bucket_limit, 0, "");
    705 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SYN_CACHE_INTER,
    706 	syn_cache_interval, CTLFLAG_RW, &tcp6_syn_cache_interval, 0, "");
    707 #endif /* !(defined(__FreeBSD__) && __FreeBSD__ >= 3) */
    708 
    709 #endif /* __FreeBSD__ */
    710