Home | History | Annotate | Line # | Download | only in netinet6
in6_proto.c revision 1.103.4.10
      1 /*	$NetBSD: in6_proto.c,v 1.103.4.10 2017/08/28 17:53:12 skrll Exp $	*/
      2 /*	$KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $	*/
      3 
      4 /*
      5  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. Neither the name of the project nor the names of its contributors
     17  *    may be used to endorse or promote products derived from this software
     18  *    without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  * SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Copyright (c) 1982, 1986, 1993
     35  *	The Regents of the University of California.  All rights reserved.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  * 3. Neither the name of the University nor the names of its contributors
     46  *    may be used to endorse or promote products derived from this software
     47  *    without specific prior written permission.
     48  *
     49  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59  * SUCH DAMAGE.
     60  *
     61  *	@(#)in_proto.c	8.1 (Berkeley) 6/10/93
     62  */
     63 
     64 #include <sys/cdefs.h>
     65 __KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.103.4.10 2017/08/28 17:53:12 skrll Exp $");
     66 
     67 #ifdef _KERNEL_OPT
     68 #include "opt_gateway.h"
     69 #include "opt_inet.h"
     70 #include "opt_ipsec.h"
     71 #include "opt_dccp.h"
     72 #include "opt_sctp.h"
     73 #endif
     74 
     75 #include <sys/param.h>
     76 #include <sys/socket.h>
     77 #include <sys/protosw.h>
     78 #include <sys/kernel.h>
     79 #include <sys/domain.h>
     80 #include <sys/mbuf.h>
     81 
     82 #include <net/if.h>
     83 
     84 #include <netinet/in.h>
     85 #include <netinet/in_systm.h>
     86 #include <netinet/in_var.h>
     87 #include <netinet/ip_encap.h>
     88 #include <netinet/ip.h>
     89 #include <netinet/ip_var.h>
     90 #include <netinet/in_pcb.h>
     91 #include <netinet/ip6.h>
     92 #include <netinet6/ip6_var.h>
     93 #include <netinet/icmp6.h>
     94 #include <netinet6/in6_pcb.h>
     95 
     96 #include <netinet/tcp.h>
     97 #include <netinet/tcp_fsm.h>
     98 #include <netinet/tcp_seq.h>
     99 #include <netinet/tcp_timer.h>
    100 #include <netinet/tcp_var.h>
    101 #include <netinet/tcpip.h>
    102 #include <netinet/tcp_debug.h>
    103 
    104 #include <netinet6/udp6.h>
    105 #include <netinet6/udp6_var.h>
    106 
    107 #ifdef DCCP
    108 #include <netinet/dccp.h>
    109 #include <netinet/dccp_var.h>
    110 #include <netinet6/dccp6_var.h>
    111 #endif
    112 
    113 #ifdef SCTP
    114 #include <netinet/sctp_pcb.h>
    115 #include <netinet/sctp.h>
    116 #include <netinet/sctp_var.h>
    117 #include <netinet6/sctp6_var.h>
    118 #endif
    119 
    120 #include <netinet6/pim6_var.h>
    121 
    122 #ifdef IPSEC
    123 #include <netipsec/ipsec.h>
    124 #include <netipsec/ipsec6.h>
    125 #include <netipsec/key.h>
    126 #endif /* IPSEC */
    127 
    128 
    129 #include "carp.h"
    130 #if NCARP > 0
    131 #include <netinet/ip_carp.h>
    132 #endif
    133 
    134 #include "etherip.h"
    135 #if NETHERIP > 0
    136 #include <netinet6/ip6_etherip.h>
    137 #endif
    138 
    139 #include <netinet6/ip6protosw.h>
    140 
    141 #include <net/net_osdep.h>
    142 
    143 /*
    144  * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
    145  */
    146 
    147 DOMAIN_DEFINE(inet6domain);	/* forward declare and add to link set */
    148 
    149 /* Wrappers to acquire kernel_lock. */
    150 
    151 PR_WRAP_CTLINPUT(rip6_ctlinput)
    152 PR_WRAP_CTLINPUT(encap6_ctlinput)
    153 PR_WRAP_CTLINPUT(udp6_ctlinput)
    154 PR_WRAP_CTLINPUT(tcp6_ctlinput)
    155 
    156 #define	rip6_ctlinput	rip6_ctlinput_wrapper
    157 #define	encap6_ctlinput	encap6_ctlinput_wrapper
    158 #define	udp6_ctlinput	udp6_ctlinput_wrapper
    159 #define	tcp6_ctlinput	tcp6_ctlinput_wrapper
    160 
    161 PR_WRAP_CTLOUTPUT(rip6_ctloutput)
    162 PR_WRAP_CTLOUTPUT(tcp_ctloutput)
    163 PR_WRAP_CTLOUTPUT(udp6_ctloutput)
    164 PR_WRAP_CTLOUTPUT(icmp6_ctloutput)
    165 
    166 #define	rip6_ctloutput	rip6_ctloutput_wrapper
    167 #define	tcp_ctloutput	tcp_ctloutput_wrapper
    168 #define	udp6_ctloutput	udp6_ctloutput_wrapper
    169 #define	icmp6_ctloutput	icmp6_ctloutput_wrapper
    170 
    171 #if defined(DCCP)
    172 PR_WRAP_CTLINPUT(dccp6_ctlinput)
    173 PR_WRAP_CTLOUTPUT(dccp_ctloutput)
    174 
    175 #define dccp6_ctlinput	dccp6_ctlinput_wrapper
    176 #define dccp_ctloutput	dccp_ctloutput_wrapper
    177 #endif
    178 
    179 #if defined(SCTP)
    180 PR_WRAP_CTLINPUT(sctp6_ctlinput)
    181 PR_WRAP_CTLOUTPUT(sctp_ctloutput)
    182 
    183 #define sctp6_ctlinput	sctp6_ctlinput_wrapper
    184 #define sctp_ctloutput	sctp_ctloutput_wrapper
    185 #endif
    186 
    187 #if defined(IPSEC)
    188 
    189 #ifdef IPSEC_RUMPKERNEL
    190 /*
    191  * .pr_input = ipsec6_common_input won't be resolved on loading
    192  * the ipsec shared library. We need a wrapper anyway.
    193  */
    194 static int
    195 ipsec6_common_input_wrapper(struct mbuf **mp, int *offp, int proto)
    196 {
    197 
    198 	if (ipsec_enabled) {
    199 		return ipsec6_common_input(mp, offp, proto);
    200 	} else {
    201 		m_freem(*mp);
    202 		return IPPROTO_DONE;
    203 	}
    204 }
    205 #define	ipsec6_common_input	ipsec6_common_input_wrapper
    206 
    207 /* The ctlinput functions may not be loaded */
    208 #define	IPSEC_WRAP_CTLINPUT(name)			\
    209 static void *						\
    210 name##_wrapper(int a, const struct sockaddr *b, void *c)\
    211 {							\
    212 	void *rv;					\
    213 	KERNEL_LOCK(1, NULL);				\
    214 	if (ipsec_enabled)				\
    215 		rv = name(a, b, c);			\
    216 	else						\
    217 		rv = NULL;				\
    218 	KERNEL_UNLOCK_ONE(NULL);			\
    219 	return rv;					\
    220 }
    221 IPSEC_WRAP_CTLINPUT(ah6_ctlinput)
    222 IPSEC_WRAP_CTLINPUT(esp6_ctlinput)
    223 
    224 #else /* !IPSEC_RUMPKERNEL */
    225 
    226 PR_WRAP_CTLINPUT(ah6_ctlinput)
    227 PR_WRAP_CTLINPUT(esp6_ctlinput)
    228 
    229 #endif /* !IPSEC_RUMPKERNEL */
    230 
    231 #define	ah6_ctlinput	ah6_ctlinput_wrapper
    232 #define	esp6_ctlinput	esp6_ctlinput_wrapper
    233 
    234 #endif /* IPSEC */
    235 
    236 static void
    237 tcp6_init(void)
    238 {
    239 
    240 	icmp6_mtudisc_callback_register(tcp6_mtudisc_callback);
    241 
    242 	tcp_init_common(sizeof(struct ip6_hdr));
    243 }
    244 
    245 const struct ip6protosw inet6sw[] = {
    246 {	.pr_domain = &inet6domain,
    247 	.pr_protocol = IPPROTO_IPV6,
    248 	.pr_init = ip6_init,
    249 	.pr_fasttimo = frag6_fasttimo,
    250 	.pr_slowtimo = frag6_slowtimo,
    251 	.pr_drain = frag6_drainstub,
    252 },
    253 {	.pr_type = SOCK_RAW,
    254 	.pr_domain = &inet6domain,
    255 	.pr_protocol = IPPROTO_ICMPV6,
    256 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    257 	.pr_input = icmp6_input,
    258 	.pr_ctlinput = rip6_ctlinput,
    259 	.pr_ctloutput = icmp6_ctloutput,
    260 	.pr_usrreqs = &rip6_usrreqs,
    261 	.pr_init = icmp6_init,
    262 },
    263 {	.pr_type = SOCK_DGRAM,
    264 	.pr_domain = &inet6domain,
    265 	.pr_protocol = IPPROTO_UDP,
    266 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    267 	.pr_input = udp6_input,
    268 	.pr_ctlinput = udp6_ctlinput,
    269 	.pr_ctloutput = udp6_ctloutput,
    270 	.pr_usrreqs = &udp6_usrreqs,
    271 	.pr_init = udp6_init,
    272 },
    273 {	.pr_type = SOCK_STREAM,
    274 	.pr_domain = &inet6domain,
    275 	.pr_protocol = IPPROTO_TCP,
    276 	.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
    277 	.pr_input = tcp6_input,
    278 	.pr_ctlinput = tcp6_ctlinput,
    279 	.pr_ctloutput = tcp_ctloutput,
    280 	.pr_usrreqs = &tcp_usrreqs,
    281 	.pr_init = tcp6_init,
    282 	.pr_fasttimo = tcp_fasttimo,
    283 	.pr_drain = tcp_drainstub,
    284 },
    285 #ifdef DCCP
    286 {	.pr_type = SOCK_CONN_DGRAM,
    287 	.pr_domain = &inet6domain,
    288 	.pr_protocol = IPPROTO_DCCP,
    289 	.pr_flags = PR_CONNREQUIRED|PR_ATOMIC|PR_LISTEN,
    290 	.pr_input = dccp6_input,
    291 	.pr_ctlinput = dccp6_ctlinput,
    292 	.pr_ctloutput = dccp_ctloutput,
    293 	.pr_usrreqs = &dccp6_usrreqs,
    294 #ifndef INET
    295 	.pr_init = dccp_init,
    296 #endif
    297 },
    298 #endif /* DCCP */
    299 #ifdef SCTP
    300 {	.pr_type = SOCK_DGRAM,
    301 	.pr_domain = &inet6domain,
    302 	.pr_protocol = IPPROTO_SCTP,
    303 	.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
    304 	.pr_input = sctp6_input,
    305 	.pr_ctlinput = sctp6_ctlinput,
    306 	.pr_ctloutput = sctp_ctloutput,
    307 	.pr_usrreqs = &sctp6_usrreqs,
    308 	.pr_drain = sctp_drain,
    309 },
    310 {	.pr_type = SOCK_SEQPACKET,
    311 	.pr_domain = &inet6domain,
    312 	.pr_protocol = IPPROTO_SCTP,
    313 	.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
    314 	.pr_input = sctp6_input,
    315 	.pr_ctlinput = sctp6_ctlinput,
    316 	.pr_ctloutput = sctp_ctloutput,
    317 	.pr_drain = sctp_drain,
    318 },
    319 {	.pr_type = SOCK_STREAM,
    320 	.pr_domain = &inet6domain,
    321 	.pr_protocol = IPPROTO_SCTP,
    322 	.pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD|PR_LISTEN,
    323 	.pr_input = sctp6_input,
    324 	.pr_ctlinput = sctp6_ctlinput,
    325 	.pr_ctloutput = sctp_ctloutput,
    326 	.pr_drain = sctp_drain,
    327 },
    328 #endif /* SCTP */
    329 {	.pr_type = SOCK_RAW,
    330 	.pr_domain = &inet6domain,
    331 	.pr_protocol = IPPROTO_RAW,
    332 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    333 	.pr_input = rip6_input,
    334 	.pr_ctlinput = rip6_ctlinput,
    335 	.pr_ctloutput = rip6_ctloutput,
    336 	.pr_usrreqs = &rip6_usrreqs,
    337 },
    338 #ifdef GATEWAY
    339 {	.pr_domain = &inet6domain,
    340 	.pr_protocol = IPPROTO_IPV6,
    341 	.pr_slowtimo = ip6flow_slowtimo,
    342 	.pr_init = ip6flow_poolinit,
    343 },
    344 #endif /* GATEWAY */
    345 {	.pr_type = SOCK_RAW,
    346 	.pr_domain = &inet6domain,
    347 	.pr_protocol = IPPROTO_DSTOPTS,
    348 	.pr_flags = PR_ATOMIC|PR_ADDR,
    349 	.pr_input = dest6_input,
    350 },
    351 {	.pr_type = SOCK_RAW,
    352 	.pr_domain = &inet6domain,
    353 	.pr_protocol = IPPROTO_ROUTING,
    354 	.pr_flags = PR_ATOMIC|PR_ADDR,
    355 	.pr_input = route6_input,
    356 },
    357 {	.pr_type = SOCK_RAW,
    358 	.pr_domain = &inet6domain,
    359 	.pr_protocol = IPPROTO_FRAGMENT,
    360 	.pr_flags = PR_ATOMIC|PR_ADDR,
    361 	.pr_input = frag6_input,
    362 },
    363 #ifdef IPSEC
    364 {	.pr_type = SOCK_RAW,
    365 	.pr_domain = &inet6domain,
    366 	.pr_protocol = IPPROTO_AH,
    367 	.pr_flags = PR_ATOMIC|PR_ADDR,
    368 	.pr_input = ipsec6_common_input,
    369 	.pr_ctlinput = ah6_ctlinput,
    370 },
    371 {	.pr_type = SOCK_RAW,
    372 	.pr_domain = &inet6domain,
    373 	.pr_protocol = IPPROTO_ESP,
    374 	.pr_flags = PR_ATOMIC|PR_ADDR,
    375 	.pr_input = ipsec6_common_input,
    376 	.pr_ctlinput = esp6_ctlinput,
    377 },
    378 {	.pr_type = SOCK_RAW,
    379 	.pr_domain = &inet6domain,
    380 	.pr_protocol = IPPROTO_IPCOMP,
    381 	.pr_flags = PR_ATOMIC|PR_ADDR,
    382 	.pr_input = ipsec6_common_input,
    383 },
    384 #endif /* IPSEC */
    385 #ifdef INET
    386 {	.pr_type = SOCK_RAW,
    387 	.pr_domain = &inet6domain,
    388 	.pr_protocol = IPPROTO_IPV4,
    389 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    390 	.pr_input = encap6_input,
    391 	.pr_ctlinput = encap6_ctlinput,
    392 	.pr_ctloutput = rip6_ctloutput,
    393 	.pr_usrreqs = &rip6_usrreqs,
    394 	.pr_init = encap_init,
    395 },
    396 #endif
    397 {	.pr_type = SOCK_RAW,
    398 	.pr_domain = &inet6domain,
    399 	.pr_protocol = IPPROTO_IPV6,
    400 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    401 	.pr_input = encap6_input,
    402 	.pr_ctlinput = encap6_ctlinput,
    403 	.pr_ctloutput = rip6_ctloutput,
    404 	.pr_usrreqs = &rip6_usrreqs,
    405 	.pr_init = encap_init,
    406 },
    407 #if NETHERIP > 0
    408 {	.pr_type = SOCK_RAW,
    409 	.pr_domain = &inet6domain,
    410 	.pr_protocol = IPPROTO_ETHERIP,
    411 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    412 	.pr_input = ip6_etherip_input,
    413 	.pr_ctlinput = rip6_ctlinput,
    414 	.pr_ctloutput = rip6_ctloutput,
    415 	.pr_usrreqs = &rip6_usrreqs,
    416 },
    417 #endif
    418 #if NCARP > 0
    419 {	.pr_type = SOCK_RAW,
    420 	.pr_domain = &inet6domain,
    421 	.pr_protocol = IPPROTO_CARP,
    422 	.pr_flags = PR_ATOMIC|PR_ADDR,
    423 	.pr_input = carp6_proto_input,
    424 	.pr_ctloutput = rip6_ctloutput,
    425 	.pr_usrreqs = &rip6_usrreqs,
    426 },
    427 #endif /* NCARP */
    428 {	.pr_type = SOCK_RAW,
    429 	.pr_domain = &inet6domain,
    430 	.pr_protocol = IPPROTO_L2TP,
    431 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    432 	.pr_input = encap6_input,
    433 	.pr_ctlinput = rip6_ctlinput,
    434 	.pr_ctloutput = rip6_ctloutput,
    435 	.pr_usrreqs = &rip6_usrreqs,
    436 	.pr_init = encap_init,
    437 },
    438 {	.pr_type = SOCK_RAW,
    439 	.pr_domain = &inet6domain,
    440 	.pr_protocol = IPPROTO_PIM,
    441 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    442 	.pr_input = pim6_input,
    443 	.pr_ctloutput = rip6_ctloutput,
    444 	.pr_usrreqs = &rip6_usrreqs,
    445 	.pr_init = pim6_init,
    446 },
    447 /* raw wildcard */
    448 {	.pr_type = SOCK_RAW,
    449 	.pr_domain = &inet6domain,
    450 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    451 	.pr_input = rip6_input,
    452 	.pr_ctloutput = rip6_ctloutput,
    453 	.pr_usrreqs = &rip6_usrreqs,
    454 	.pr_init = rip6_init,
    455 },
    456 };
    457 
    458 static const struct sockaddr_in6 in6_any = {
    459 	  .sin6_len = sizeof(in6_any)
    460 	, .sin6_family = AF_INET6
    461 	, .sin6_port = 0
    462 	, .sin6_flowinfo = 0
    463 	, .sin6_addr = IN6ADDR_ANY_INIT
    464 	, .sin6_scope_id = 0
    465 };
    466 
    467 bool in6_present = false;
    468 static void
    469 in6_dom_init(void)
    470 {
    471 
    472 	in6_present = true;
    473 }
    474 
    475 struct domain inet6domain = {
    476 	.dom_family = AF_INET6, .dom_name = "internet6",
    477 	.dom_init = in6_dom_init, .dom_externalize = NULL, .dom_dispose = NULL,
    478 	.dom_protosw = (const struct protosw *)inet6sw,
    479 	.dom_protoswNPROTOSW = (const struct protosw *)&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])],
    480 	.dom_rtattach = rt_inithead,
    481 	.dom_rtoffset = offsetof(struct sockaddr_in6, sin6_addr) << 3,
    482 	.dom_maxrtkey = sizeof(struct ip_pack6),
    483 	.dom_if_up = in6_if_up, .dom_if_down = in6_if_down,
    484 	.dom_ifattach = in6_domifattach, .dom_ifdetach = in6_domifdetach,
    485 	.dom_if_link_state_change = in6_if_link_state_change,
    486 	.dom_ifqueues = { NULL, NULL },
    487 	.dom_link = { NULL },
    488 	.dom_mowner = MOWNER_INIT("",""),
    489 	.dom_sa_cmpofs = offsetof(struct sockaddr_in6, sin6_addr),
    490 	.dom_sa_cmplen = sizeof(struct in6_addr),
    491 	.dom_sa_any = (const struct sockaddr *)&in6_any,
    492 	.dom_sockaddr_externalize = sockaddr_in6_externalize,
    493 	.dom_rtcache = LIST_HEAD_INITIALIZER(inet6domain.dom_rtcache)
    494 };
    495 
    496 #if 0
    497 int
    498 sockaddr_in6_cmp(const struct sockaddr *lsa, const struct sockaddr *rsa)
    499 {
    500 	uint_fast8_t len;
    501 	const uint_fast8_t addrofs = offsetof(struct sockaddr_in6, sin6_addr),
    502 			   addrend = addrofs + sizeof(struct in6_addr);
    503 	int rc;
    504 	const struct sockaddr_in6 *lsin6, *rsin6;
    505 
    506 	lsin6 = satocsin6(lsa);
    507 	rsin6 = satocsin6(rsa);
    508 
    509 	len = MIN(addrend, MIN(lsin6->sin6_len, rsin6->sin6_len));
    510 
    511 	if (len > addrofs &&
    512 	    (rc = memcmp(&lsin6->sin6_addr, &rsin6->sin6_addr,
    513 	                  len - addrofs)) != 0)
    514 		return rc;
    515 
    516 	return lsin6->sin6_len - rsin6->sin6_len;
    517 }
    518 #endif
    519 
    520 /*
    521  * Internet configuration info
    522  */
    523 #ifndef	IPV6FORWARDING
    524 #ifdef GATEWAY6
    525 #define	IPV6FORWARDING	1	/* forward IP6 packets not for us */
    526 #else
    527 #define	IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
    528 #endif /* GATEWAY6 */
    529 #endif /* !IPV6FORWARDING */
    530 
    531 int	ip6_forwarding = IPV6FORWARDING;	/* act as router? */
    532 int	ip6_sendredirects = 1;
    533 int	ip6_defhlim = IPV6_DEFHLIM;
    534 int	ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
    535 int	ip6_accept_rtadv = 0;	/* "IPV6FORWARDING ? 0 : 1" is dangerous */
    536 int	ip6_maxfragpackets = 200;
    537 int	ip6_maxfrags = 200;
    538 int	ip6_log_interval = 5;
    539 int	ip6_hdrnestlimit = 50;	/* appropriate? */
    540 int	ip6_dad_count = 1;	/* DupAddrDetectionTransmits */
    541 int	ip6_auto_flowlabel = 1;
    542 int	ip6_use_deprecated = 1;	/* allow deprecated addr (RFC2462 5.5.4) */
    543 int	ip6_rr_prune = 5;	/* router renumbering prefix
    544 				 * walk list every 5 sec. */
    545 int	ip6_mcast_pmtu = 0;	/* enable pMTU discovery for multicast? */
    546 int	ip6_v6only = 1;
    547 int     ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */
    548 int     ip6_maxifprefixes = 16; /* Max acceptable prefixes via RA per IF */
    549 int     ip6_maxifdefrouters = 16; /* Max acceptable def routers via RA */
    550 int     ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */
    551 
    552 int	ip6_keepfaith = 0;
    553 time_t	ip6_log_time = 0;
    554 int	ip6_rtadv_maxroutes = 100; /* (arbitrary) initial maximum number of
    555                                     * routes via rtadv expected to be
    556                                     * significantly larger than common use.
    557                                     * if you need to count: 3 extra initial
    558                                     * routes, plus 1 per interface after the
    559                                     * first one, then one per non-linklocal
    560                                     * prefix */
    561 
    562 /* icmp6 */
    563 /*
    564  * BSDI4 defines these variables in in_proto.c...
    565  * XXX: what if we don't define INET? Should we define pmtu6_expire
    566  * or so? (jinmei (at) kame.net 19990310)
    567  */
    568 int pmtu_expire = 60*10;
    569 
    570 /* raw IP6 parameters */
    571 /*
    572  * Nominal space allocated to a raw ip socket.
    573  */
    574 #define	RIPV6SNDQ	8192
    575 #define	RIPV6RCVQ	8192
    576 
    577 u_long	rip6_sendspace = RIPV6SNDQ;
    578 u_long	rip6_recvspace = RIPV6RCVQ;
    579 
    580 /* ICMPV6 parameters */
    581 int	icmp6_rediraccept = 1;		/* accept and process redirects */
    582 int	icmp6_redirtimeout = 10 * 60;	/* 10 minutes */
    583 int	icmp6errppslim = 100;		/* 100pps */
    584 int	icmp6_nodeinfo = 1;		/* enable/disable NI response */
    585