Home | History | Annotate | Line # | Download | only in netinet6
in6_proto.c revision 1.14
      1 /*	$NetBSD: in6_proto.c,v 1.14 2000/02/14 19:45:50 thorpej 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 #include "opt_inet.h"
     68 #include "opt_ipsec.h"
     69 
     70 #include <sys/param.h>
     71 #include <sys/socket.h>
     72 #include <sys/protosw.h>
     73 #include <sys/kernel.h>
     74 #include <sys/domain.h>
     75 #include <sys/mbuf.h>
     76 
     77 #include <net/if.h>
     78 #include <net/radix.h>
     79 #include <net/route.h>
     80 
     81 #include <netinet/in.h>
     82 #include <netinet/in_systm.h>
     83 #include <netinet/in_var.h>
     84 #ifndef TCP6
     85 #include <netinet/ip.h>
     86 #include <netinet/ip_var.h>
     87 #endif
     88 #ifndef TCP6
     89 #include <netinet/in_pcb.h>
     90 #endif
     91 #include <netinet/ip6.h>
     92 #include <netinet6/ip6_var.h>
     93 #include <netinet/icmp6.h>
     94 #include <netinet6/in6_pcb.h>
     95 
     96 #ifndef TCP6
     97 #include <netinet/tcp.h>
     98 #include <netinet/tcp_fsm.h>
     99 #include <netinet/tcp_seq.h>
    100 #include <netinet/tcp_timer.h>
    101 #include <netinet/tcp_var.h>
    102 #include <netinet/tcpip.h>
    103 #include <netinet/tcp_debug.h>
    104 #else
    105 #include <netinet6/tcp6.h>
    106 #include <netinet6/tcp6_fsm.h>
    107 #include <netinet6/tcp6_seq.h>
    108 #include <netinet6/tcp6_timer.h>
    109 #include <netinet6/tcp6_var.h>
    110 #endif
    111 
    112 #include <netinet6/udp6.h>
    113 #include <netinet6/udp6_var.h>
    114 
    115 #include <netinet6/pim6_var.h>
    116 
    117 #include <netinet6/nd6.h>
    118 
    119 
    120 #ifdef IPSEC
    121 #include <netinet6/ipsec.h>
    122 #include <netinet6/ah.h>
    123 #ifdef IPSEC_ESP
    124 #include <netinet6/esp.h>
    125 #endif
    126 #include <netinet6/ipcomp.h>
    127 #endif /*IPSEC*/
    128 
    129 #include <netinet6/ip6protosw.h>
    130 
    131 #include "gif.h"
    132 #if NGIF > 0
    133 #include <netinet6/in6_gif.h>
    134 #endif
    135 
    136 #include <net/net_osdep.h>
    137 
    138 #define	offsetof(type, member)	((size_t)(&((type *)0)->member))
    139 
    140 /*
    141  * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
    142  */
    143 
    144 extern	struct domain inet6domain;
    145 
    146 struct ip6protosw inet6sw[] = {
    147 { 0,		&inet6domain,	IPPROTO_IPV6,	0,
    148   0,		0,		0,		0,
    149   0,
    150   ip6_init,	0,		frag6_slowtimo,	frag6_drain,
    151   ip6_sysctl,
    152 },
    153 { SOCK_DGRAM,	&inet6domain,	IPPROTO_UDP,	PR_ATOMIC | PR_ADDR,
    154   udp6_input,	0,		udp6_ctlinput,	ip6_ctloutput,
    155   udp6_usrreq,	udp6_init,
    156   0,		0,		0,
    157   udp6_sysctl,
    158 },
    159 #ifdef TCP6
    160 { SOCK_STREAM,	&inet6domain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
    161   tcp6_input,	0,		tcp6_ctlinput,	tcp6_ctloutput,
    162   tcp6_usrreq,
    163   tcp6_init,	tcp6_fasttimo,	tcp6_slowtimo,	tcp6_drain,
    164   tcp6_sysctl,
    165 },
    166 #else
    167 { SOCK_STREAM,	&inet6domain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
    168   tcp6_input,	0,		tcp6_ctlinput,	tcp_ctloutput,
    169   tcp_usrreq,
    170 #ifdef INET	/* don't call timeout routines twice */
    171   tcp_init,	0,		0,		tcp_drain,
    172 #else
    173   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
    174 #endif
    175   tcp_sysctl,
    176 },
    177 #endif /*TCP6*/
    178 { SOCK_RAW,	&inet6domain,	IPPROTO_RAW,	PR_ATOMIC | PR_ADDR,
    179   rip6_input,	rip6_output,	0,		rip6_ctloutput,
    180   rip6_usrreq,
    181   0,		0,		0,		0,
    182 },
    183 { SOCK_RAW,	&inet6domain,	IPPROTO_ICMPV6,	PR_ATOMIC | PR_ADDR,
    184   icmp6_input,	rip6_output,	0,		rip6_ctloutput,
    185   rip6_usrreq,
    186   icmp6_init,	icmp6_fasttimo,	0,		0,
    187   icmp6_sysctl,
    188 },
    189 { SOCK_RAW,	&inet6domain,	IPPROTO_DSTOPTS,PR_ATOMIC|PR_ADDR,
    190   dest6_input,	0,	 	0,		0,
    191   0,
    192   0,		0,		0,		0,
    193 },
    194 { SOCK_RAW,	&inet6domain,	IPPROTO_ROUTING,PR_ATOMIC|PR_ADDR,
    195   route6_input,	0,	 	0,		0,
    196   0,
    197   0,		0,		0,		0,
    198 },
    199 { SOCK_RAW,	&inet6domain,	IPPROTO_FRAGMENT,PR_ATOMIC|PR_ADDR,
    200   frag6_input,	0,	 	0,		0,
    201   0,
    202   0,		0,		0,		0,
    203 },
    204 #ifdef IPSEC
    205 { SOCK_RAW,	&inet6domain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
    206   ah6_input,	0,	 	0,		0,
    207   0,
    208   0,		0,		0,		0,
    209   ipsec6_sysctl,
    210 },
    211 #ifdef IPSEC_ESP
    212 { SOCK_RAW,	&inet6domain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
    213   esp6_input,	0,	 	0,		0,
    214   0,
    215   0,		0,		0,		0,
    216   ipsec6_sysctl,
    217 },
    218 #endif
    219 { SOCK_RAW,	&inet6domain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
    220   ipcomp6_input, 0,	 	0,		0,
    221   0,
    222   0,		0,		0,		0,
    223   ipsec6_sysctl,
    224 },
    225 #endif /* IPSEC */
    226 #if NGIF > 0
    227 { SOCK_RAW,	&inet6domain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR,
    228   in6_gif_input,0,	 	0,		0,
    229   0,
    230   0,		0,		0,		0,
    231 },
    232 #ifdef INET6
    233 { SOCK_RAW,	&inet6domain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR,
    234   in6_gif_input,0,	 	0,		0,
    235   0,
    236   0,		0,		0,		0,
    237 },
    238 #endif /* INET6 */
    239 #endif /* GIF */
    240 { SOCK_RAW,     &inet6domain,	IPPROTO_PIM,	PR_ATOMIC|PR_ADDR,
    241   pim6_input,    rip6_output,	0,              rip6_ctloutput,
    242   rip6_usrreq,
    243   0,            0,              0,              0,
    244 },
    245 /* raw wildcard */
    246 { SOCK_RAW,	&inet6domain,	0,		PR_ATOMIC | PR_ADDR,
    247   rip6_input,	rip6_output,	0,		rip6_ctloutput,
    248   rip6_usrreq, rip6_init,
    249   0,		0,		0,
    250 },
    251 };
    252 
    253 struct domain inet6domain =
    254     { AF_INET6, "internet6", 0, 0, 0,
    255       (struct protosw *)inet6sw,
    256       (struct protosw *)&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])], 0,
    257       rn_inithead,
    258       offsetof(struct sockaddr_in6, sin6_addr) << 3,
    259       sizeof(struct sockaddr_in6) };
    260 
    261 /*
    262  * Internet configuration info
    263  */
    264 #ifndef	IPV6FORWARDING
    265 #ifdef GATEWAY6
    266 #define	IPV6FORWARDING	1	/* forward IP6 packets not for us */
    267 #else
    268 #define	IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
    269 #endif /* GATEWAY6 */
    270 #endif /* !IPV6FORWARDING */
    271 
    272 #ifndef	IPV6_SENDREDIRECTS
    273 #define	IPV6_SENDREDIRECTS	1
    274 #endif
    275 
    276 int	ip6_forwarding = IPV6FORWARDING;	/* act as router? */
    277 int	ip6_sendredirects = IPV6_SENDREDIRECTS;
    278 int	ip6_defhlim = IPV6_DEFHLIM;
    279 int	ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
    280 int	ip6_accept_rtadv = 0;	/* "IPV6FORWARDING ? 0 : 1" is dangerous */
    281 int	ip6_maxfragpackets = 200;
    282 int	ip6_log_interval = 5;
    283 int	ip6_hdrnestlimit = 50;	/* appropriate? */
    284 int	ip6_dad_count = 1;	/* DupAddrDetectionTransmits */
    285 u_int32_t ip6_flow_seq;
    286 int	ip6_auto_flowlabel = 1;
    287 #if NGIF > 0
    288 int	ip6_gif_hlim = GIF_HLIM;
    289 #else
    290 int	ip6_gif_hlim = 0;
    291 #endif
    292 int	ip6_use_deprecated = 1;	/* allow deprecated addr (RFC2462 5.5.4) */
    293 int	ip6_rr_prune = 5;	/* router renumbering prefix
    294 				 * walk list every 5 sec.    */
    295 #ifndef INET6_BINDV6ONLY
    296 int	ip6_bindv6only = 1;
    297 #endif
    298 
    299 u_int32_t ip6_id = 0UL;
    300 int	ip6_keepfaith = 0;
    301 time_t	ip6_log_time = (time_t)0L;
    302 
    303 /* icmp6 */
    304 /*
    305  * BSDI4 defines these variables in in_proto.c...
    306  * XXX: what if we don't define INET? Should we define pmtu6_expire
    307  * or so? (jinmei (at) kame.net 19990310)
    308  */
    309 int pmtu_expire = 60*10;
    310 int pmtu_probe = 60*2;
    311 
    312 /* raw IP6 parameters */
    313 /*
    314  * Nominal space allocated to a raw ip socket.
    315  */
    316 #define	RIPV6SNDQ	8192
    317 #define	RIPV6RCVQ	8192
    318 
    319 u_long	rip6_sendspace = RIPV6SNDQ;
    320 u_long	rip6_recvspace = RIPV6RCVQ;
    321 
    322 /* ICMPV6 parameters */
    323 int	icmp6_rediraccept = 1;		/* accept and process redirects */
    324 int	icmp6_redirtimeout = 10 * 60;	/* 10 minutes */
    325 struct timeval icmp6errratelim = { 0, 1000 }; /* 1000usec = 1msec */
    326 int	icmp6_nodeinfo = 1;		/* enable/disable NI response */
    327 
    328 #ifdef TCP6
    329 /* TCP on IP6 parameters */
    330 int	tcp6_sendspace = 1024 * 8;
    331 int	tcp6_recvspace = 1024 * 8;
    332 int 	tcp6_mssdflt = TCP6_MSS;
    333 int 	tcp6_rttdflt = TCP6TV_SRTTDFLT / PR_SLOWHZ;
    334 int	tcp6_do_rfc1323 = 1;
    335 int	tcp6_conntimeo = TCP6TV_KEEP_INIT;	/* initial connection timeout */
    336 int	tcp6_43maxseg = 0;
    337 int	tcp6_pmtu = 0;
    338 
    339 /*
    340  * Parameters for keepalive option.
    341  * Connections for which SO_KEEPALIVE is set will be probed
    342  * after being idle for a time of tcp6_keepidle (in units of PR_SLOWHZ).
    343  * Starting at that time, the connection is probed at intervals
    344  * of tcp6_keepintvl (same units) until a response is received
    345  * or until tcp6_keepcnt probes have been made, at which time
    346  * the connection is dropped.  Note that a tcp6_keepidle value
    347  * under 2 hours is nonconformant with RFC-1122, Internet Host Requirements.
    348  */
    349 int	tcp6_keepidle = TCP6TV_KEEP_IDLE;	/* time before probing idle */
    350 int	tcp6_keepintvl = TCP6TV_KEEPINTVL;	/* interval betwn idle probes */
    351 int	tcp6_keepcnt = TCP6TV_KEEPCNT;		/* max idle probes */
    352 int	tcp6_maxpersistidle = TCP6TV_KEEP_IDLE;	/* max idle time in persist */
    353 
    354 #ifndef INET_SERVER
    355 #define	TCP6_LISTEN_HASH_SIZE	17
    356 #define	TCP6_CONN_HASH_SIZE	97
    357 #define	TCP6_SYN_HASH_SIZE	293
    358 #define	TCP6_SYN_BUCKET_SIZE	35
    359 #else
    360 #define	TCP6_LISTEN_HASH_SIZE	97
    361 #define	TCP6_CONN_HASH_SIZE	9973
    362 #define	TCP6_SYN_HASH_SIZE	997
    363 #define	TCP6_SYN_BUCKET_SIZE	35
    364 #endif
    365 int	tcp6_listen_hash_size = TCP6_LISTEN_HASH_SIZE;
    366 int	tcp6_conn_hash_size = TCP6_CONN_HASH_SIZE;
    367 struct	tcp6_hash_list tcp6_listen_hash[TCP6_LISTEN_HASH_SIZE],
    368 	tcp6_conn_hash[TCP6_CONN_HASH_SIZE];
    369 
    370 int	tcp6_syn_cache_size = TCP6_SYN_HASH_SIZE;
    371 int	tcp6_syn_cache_limit = TCP6_SYN_HASH_SIZE*TCP6_SYN_BUCKET_SIZE;
    372 int	tcp6_syn_bucket_limit = 3*TCP6_SYN_BUCKET_SIZE;
    373 struct	syn_cache_head6 tcp6_syn_cache[TCP6_SYN_HASH_SIZE];
    374 struct	syn_cache_head6 *tcp6_syn_cache_first;
    375 int	tcp6_syn_cache_interval = 8;	/* runs timer every 4 seconds */
    376 int	tcp6_syn_cache_timeo = TCP6TV_KEEP_INIT;
    377 
    378 /*
    379  * Parameters for computing a desirable data segment size
    380  * given an upper bound (either interface MTU, or peer's MSS option)_.
    381  * As applications tend to use a buffer size that is a multiple
    382  * of kilobytes, try for something that divides evenly. However,
    383  * do not round down too much.
    384  *
    385  * Round segment size down to a multiple of TCP6_ROUNDSIZE if this
    386  * does not result in lowering by more than (size/TCP6_ROUNDFRAC).
    387  * For example, round 536 to 512.  Older versions of the system
    388  * effectively used MCLBYTES (1K or 2K) as TCP6_ROUNDSIZE, with
    389  * a value of 1 for TCP6_ROUNDFRAC (eliminating its effect).
    390  * We round to a multiple of 256 for SLIP.
    391  */
    392 #ifndef	TCP6_ROUNDSIZE
    393 #define	TCP6_ROUNDSIZE	256	/* round to multiple of 256 */
    394 #endif
    395 #ifndef	TCP6_ROUNDFRAC
    396 #define	TCP6_ROUNDFRAC	10	/* round down at most N/10, or 10% */
    397 #endif
    398 
    399 int	tcp6_roundsize = TCP6_ROUNDSIZE;
    400 int	tcp6_roundfrac = TCP6_ROUNDFRAC;
    401 #endif /*TCP6*/
    402 
    403 /* UDP on IP6 parameters */
    404 int	udp6_sendspace = 9216;		/* really max datagram size */
    405 int	udp6_recvspace = 40 * (1024 + sizeof(struct sockaddr_in6));
    406 					/* 40 1K datagrams */
    407