Home | History | Annotate | Line # | Download | only in netinet6
in6_proto.c revision 1.119
      1 /*	$NetBSD: in6_proto.c,v 1.119 2017/09/27 10:05:05 ozaki-r 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.119 2017/09/27 10:05:05 ozaki-r 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 #include "opt_net_mpsafe.h"
     74 #endif
     75 
     76 #include <sys/param.h>
     77 #include <sys/socket.h>
     78 #include <sys/protosw.h>
     79 #include <sys/kernel.h>
     80 #include <sys/domain.h>
     81 #include <sys/mbuf.h>
     82 
     83 #include <net/if.h>
     84 
     85 #include <netinet/in.h>
     86 #include <netinet/in_systm.h>
     87 #include <netinet/in_var.h>
     88 #include <netinet/ip_encap.h>
     89 #include <netinet/ip.h>
     90 #include <netinet/ip_var.h>
     91 #include <netinet/in_pcb.h>
     92 #include <netinet/ip6.h>
     93 #include <netinet6/ip6_var.h>
     94 #include <netinet/icmp6.h>
     95 #include <netinet6/in6_pcb.h>
     96 
     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 
    105 #include <netinet6/udp6.h>
    106 #include <netinet6/udp6_var.h>
    107 
    108 #ifdef DCCP
    109 #include <netinet/dccp.h>
    110 #include <netinet/dccp_var.h>
    111 #include <netinet6/dccp6_var.h>
    112 #endif
    113 
    114 #ifdef SCTP
    115 #include <netinet/sctp_pcb.h>
    116 #include <netinet/sctp.h>
    117 #include <netinet/sctp_var.h>
    118 #include <netinet6/sctp6_var.h>
    119 #endif
    120 
    121 #include <netinet6/pim6_var.h>
    122 
    123 #ifdef IPSEC
    124 #include <netipsec/ipsec.h>
    125 #include <netipsec/ipsec6.h>
    126 #include <netipsec/key.h>
    127 #endif /* IPSEC */
    128 
    129 
    130 #include "carp.h"
    131 #if NCARP > 0
    132 #include <netinet/ip_carp.h>
    133 #endif
    134 
    135 #include "etherip.h"
    136 #if NETHERIP > 0
    137 #include <netinet6/ip6_etherip.h>
    138 #endif
    139 
    140 #include <netinet6/ip6protosw.h>
    141 
    142 #include <net/net_osdep.h>
    143 
    144 /*
    145  * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
    146  */
    147 
    148 DOMAIN_DEFINE(inet6domain);	/* forward declare and add to link set */
    149 
    150 /* Wrappers to acquire kernel_lock. */
    151 
    152 PR_WRAP_CTLINPUT(rip6_ctlinput)
    153 PR_WRAP_CTLINPUT(encap6_ctlinput)
    154 PR_WRAP_CTLINPUT(udp6_ctlinput)
    155 PR_WRAP_CTLINPUT(tcp6_ctlinput)
    156 
    157 #define	rip6_ctlinput	rip6_ctlinput_wrapper
    158 #define	encap6_ctlinput	encap6_ctlinput_wrapper
    159 #define	udp6_ctlinput	udp6_ctlinput_wrapper
    160 #define	tcp6_ctlinput	tcp6_ctlinput_wrapper
    161 
    162 PR_WRAP_CTLOUTPUT(rip6_ctloutput)
    163 PR_WRAP_CTLOUTPUT(tcp_ctloutput)
    164 PR_WRAP_CTLOUTPUT(udp6_ctloutput)
    165 PR_WRAP_CTLOUTPUT(icmp6_ctloutput)
    166 
    167 #define	rip6_ctloutput	rip6_ctloutput_wrapper
    168 #define	tcp_ctloutput	tcp_ctloutput_wrapper
    169 #define	udp6_ctloutput	udp6_ctloutput_wrapper
    170 #define	icmp6_ctloutput	icmp6_ctloutput_wrapper
    171 
    172 #if defined(DCCP)
    173 PR_WRAP_CTLINPUT(dccp6_ctlinput)
    174 PR_WRAP_CTLOUTPUT(dccp_ctloutput)
    175 
    176 #define dccp6_ctlinput	dccp6_ctlinput_wrapper
    177 #define dccp_ctloutput	dccp_ctloutput_wrapper
    178 #endif
    179 
    180 #if defined(SCTP)
    181 PR_WRAP_CTLINPUT(sctp6_ctlinput)
    182 PR_WRAP_CTLOUTPUT(sctp_ctloutput)
    183 
    184 #define sctp6_ctlinput	sctp6_ctlinput_wrapper
    185 #define sctp_ctloutput	sctp_ctloutput_wrapper
    186 #endif
    187 
    188 #ifdef NET_MPSAFE
    189 PR_WRAP_INPUT6(udp6_input)
    190 PR_WRAP_INPUT6(tcp6_input)
    191 #ifdef DCCP
    192 PR_WRAP_INPUT6(dccp6_input)
    193 #endif
    194 #ifdef SCTP
    195 PR_WRAP_INPUT6(sctp6_input)
    196 #endif
    197 PR_WRAP_INPUT6(rip6_input)
    198 PR_WRAP_INPUT6(dest6_input)
    199 PR_WRAP_INPUT6(route6_input)
    200 PR_WRAP_INPUT6(frag6_input)
    201 #if NETHERIP > 0
    202 PR_WRAP_INPUT6(ip6_etherip_input)
    203 #endif
    204 #if NPFSYNC > 0
    205 PR_WRAP_INPUT6(pfsync_input)
    206 #endif
    207 PR_WRAP_INPUT6(pim6_input)
    208 
    209 #define	udp6_input		udp6_input_wrapper
    210 #define	tcp6_input		tcp6_input_wrapper
    211 #define	dccp6_input		dccp6_input_wrapper
    212 #define	sctp6_input		sctp6_input_wrapper
    213 #define	rip6_input		rip6_input_wrapper
    214 #define	dest6_input		dest6_input_wrapper
    215 #define	route6_input		route6_input_wrapper
    216 #define	frag6_input		frag6_input_wrapper
    217 #define	ip6_etherip_input	ip6_etherip_input_wrapper
    218 #define	pim6_input		pim6_input_wrapper
    219 #endif
    220 
    221 #if defined(IPSEC)
    222 
    223 #ifdef IPSEC_RUMPKERNEL
    224 /*
    225  * .pr_input = ipsec6_common_input won't be resolved on loading
    226  * the ipsec shared library. We need a wrapper anyway.
    227  */
    228 static int
    229 ipsec6_common_input_wrapper(struct mbuf **mp, int *offp, int proto)
    230 {
    231 
    232 	if (ipsec_enabled) {
    233 		return ipsec6_common_input(mp, offp, proto);
    234 	} else {
    235 		m_freem(*mp);
    236 		return IPPROTO_DONE;
    237 	}
    238 }
    239 #define	ipsec6_common_input	ipsec6_common_input_wrapper
    240 
    241 /* The ctlinput functions may not be loaded */
    242 #define	IPSEC_WRAP_CTLINPUT(name)			\
    243 static void *						\
    244 name##_wrapper(int a, const struct sockaddr *b, void *c)\
    245 {							\
    246 	void *rv;					\
    247 	KERNEL_LOCK(1, NULL);				\
    248 	if (ipsec_enabled)				\
    249 		rv = name(a, b, c);			\
    250 	else						\
    251 		rv = NULL;				\
    252 	KERNEL_UNLOCK_ONE(NULL);			\
    253 	return rv;					\
    254 }
    255 IPSEC_WRAP_CTLINPUT(ah6_ctlinput)
    256 IPSEC_WRAP_CTLINPUT(esp6_ctlinput)
    257 
    258 #else /* !IPSEC_RUMPKERNEL */
    259 
    260 PR_WRAP_CTLINPUT(ah6_ctlinput)
    261 PR_WRAP_CTLINPUT(esp6_ctlinput)
    262 
    263 #endif /* !IPSEC_RUMPKERNEL */
    264 
    265 #define	ah6_ctlinput	ah6_ctlinput_wrapper
    266 #define	esp6_ctlinput	esp6_ctlinput_wrapper
    267 
    268 #endif /* IPSEC */
    269 
    270 static void
    271 tcp6_init(void)
    272 {
    273 
    274 	icmp6_mtudisc_callback_register(tcp6_mtudisc_callback);
    275 
    276 	tcp_init_common(sizeof(struct ip6_hdr));
    277 }
    278 
    279 const struct ip6protosw inet6sw[] = {
    280 {	.pr_domain = &inet6domain,
    281 	.pr_protocol = IPPROTO_IPV6,
    282 	.pr_init = ip6_init,
    283 	.pr_fasttimo = frag6_fasttimo,
    284 	.pr_slowtimo = frag6_slowtimo,
    285 	.pr_drain = frag6_drainstub,
    286 },
    287 {	.pr_type = SOCK_RAW,
    288 	.pr_domain = &inet6domain,
    289 	.pr_protocol = IPPROTO_ICMPV6,
    290 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    291 	.pr_input = icmp6_input,
    292 	.pr_ctlinput = rip6_ctlinput,
    293 	.pr_ctloutput = icmp6_ctloutput,
    294 	.pr_usrreqs = &rip6_usrreqs,
    295 	.pr_init = icmp6_init,
    296 },
    297 {	.pr_type = SOCK_DGRAM,
    298 	.pr_domain = &inet6domain,
    299 	.pr_protocol = IPPROTO_UDP,
    300 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    301 	.pr_input = udp6_input,
    302 	.pr_ctlinput = udp6_ctlinput,
    303 	.pr_ctloutput = udp6_ctloutput,
    304 	.pr_usrreqs = &udp6_usrreqs,
    305 	.pr_init = udp6_init,
    306 },
    307 {	.pr_type = SOCK_STREAM,
    308 	.pr_domain = &inet6domain,
    309 	.pr_protocol = IPPROTO_TCP,
    310 	.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
    311 	.pr_input = tcp6_input,
    312 	.pr_ctlinput = tcp6_ctlinput,
    313 	.pr_ctloutput = tcp_ctloutput,
    314 	.pr_usrreqs = &tcp_usrreqs,
    315 	.pr_init = tcp6_init,
    316 	.pr_fasttimo = tcp_fasttimo,
    317 	.pr_drain = tcp_drainstub,
    318 },
    319 #ifdef DCCP
    320 {	.pr_type = SOCK_CONN_DGRAM,
    321 	.pr_domain = &inet6domain,
    322 	.pr_protocol = IPPROTO_DCCP,
    323 	.pr_flags = PR_CONNREQUIRED|PR_ATOMIC|PR_LISTEN,
    324 	.pr_input = dccp6_input,
    325 	.pr_ctlinput = dccp6_ctlinput,
    326 	.pr_ctloutput = dccp_ctloutput,
    327 	.pr_usrreqs = &dccp6_usrreqs,
    328 #ifndef INET
    329 	.pr_init = dccp_init,
    330 #endif
    331 },
    332 #endif /* DCCP */
    333 #ifdef SCTP
    334 {	.pr_type = SOCK_DGRAM,
    335 	.pr_domain = &inet6domain,
    336 	.pr_protocol = IPPROTO_SCTP,
    337 	.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
    338 	.pr_input = sctp6_input,
    339 	.pr_ctlinput = sctp6_ctlinput,
    340 	.pr_ctloutput = sctp_ctloutput,
    341 	.pr_usrreqs = &sctp6_usrreqs,
    342 	.pr_drain = sctp_drain,
    343 },
    344 {	.pr_type = SOCK_SEQPACKET,
    345 	.pr_domain = &inet6domain,
    346 	.pr_protocol = IPPROTO_SCTP,
    347 	.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
    348 	.pr_input = sctp6_input,
    349 	.pr_ctlinput = sctp6_ctlinput,
    350 	.pr_ctloutput = sctp_ctloutput,
    351 	.pr_drain = sctp_drain,
    352 },
    353 {	.pr_type = SOCK_STREAM,
    354 	.pr_domain = &inet6domain,
    355 	.pr_protocol = IPPROTO_SCTP,
    356 	.pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD|PR_LISTEN,
    357 	.pr_input = sctp6_input,
    358 	.pr_ctlinput = sctp6_ctlinput,
    359 	.pr_ctloutput = sctp_ctloutput,
    360 	.pr_drain = sctp_drain,
    361 },
    362 #endif /* SCTP */
    363 {	.pr_type = SOCK_RAW,
    364 	.pr_domain = &inet6domain,
    365 	.pr_protocol = IPPROTO_RAW,
    366 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    367 	.pr_input = rip6_input,
    368 	.pr_ctlinput = rip6_ctlinput,
    369 	.pr_ctloutput = rip6_ctloutput,
    370 	.pr_usrreqs = &rip6_usrreqs,
    371 },
    372 #ifdef GATEWAY
    373 {	.pr_domain = &inet6domain,
    374 	.pr_protocol = IPPROTO_IPV6,
    375 	.pr_slowtimo = ip6flow_slowtimo,
    376 	.pr_init = ip6flow_poolinit,
    377 },
    378 #endif /* GATEWAY */
    379 {	.pr_type = SOCK_RAW,
    380 	.pr_domain = &inet6domain,
    381 	.pr_protocol = IPPROTO_DSTOPTS,
    382 	.pr_flags = PR_ATOMIC|PR_ADDR,
    383 	.pr_input = dest6_input,
    384 },
    385 {	.pr_type = SOCK_RAW,
    386 	.pr_domain = &inet6domain,
    387 	.pr_protocol = IPPROTO_ROUTING,
    388 	.pr_flags = PR_ATOMIC|PR_ADDR,
    389 	.pr_input = route6_input,
    390 },
    391 {	.pr_type = SOCK_RAW,
    392 	.pr_domain = &inet6domain,
    393 	.pr_protocol = IPPROTO_FRAGMENT,
    394 	.pr_flags = PR_ATOMIC|PR_ADDR,
    395 	.pr_input = frag6_input,
    396 },
    397 #ifdef IPSEC
    398 {	.pr_type = SOCK_RAW,
    399 	.pr_domain = &inet6domain,
    400 	.pr_protocol = IPPROTO_AH,
    401 	.pr_flags = PR_ATOMIC|PR_ADDR,
    402 	.pr_input = ipsec6_common_input,
    403 	.pr_ctlinput = ah6_ctlinput,
    404 },
    405 {	.pr_type = SOCK_RAW,
    406 	.pr_domain = &inet6domain,
    407 	.pr_protocol = IPPROTO_ESP,
    408 	.pr_flags = PR_ATOMIC|PR_ADDR,
    409 	.pr_input = ipsec6_common_input,
    410 	.pr_ctlinput = esp6_ctlinput,
    411 },
    412 {	.pr_type = SOCK_RAW,
    413 	.pr_domain = &inet6domain,
    414 	.pr_protocol = IPPROTO_IPCOMP,
    415 	.pr_flags = PR_ATOMIC|PR_ADDR,
    416 	.pr_input = ipsec6_common_input,
    417 },
    418 #endif /* IPSEC */
    419 #ifdef INET
    420 {	.pr_type = SOCK_RAW,
    421 	.pr_domain = &inet6domain,
    422 	.pr_protocol = IPPROTO_IPV4,
    423 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    424 	.pr_input = encap6_input,
    425 	.pr_ctlinput = encap6_ctlinput,
    426 	.pr_ctloutput = rip6_ctloutput,
    427 	.pr_usrreqs = &rip6_usrreqs,
    428 	.pr_init = encap_init,
    429 },
    430 #endif
    431 {	.pr_type = SOCK_RAW,
    432 	.pr_domain = &inet6domain,
    433 	.pr_protocol = IPPROTO_IPV6,
    434 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    435 	.pr_input = encap6_input,
    436 	.pr_ctlinput = encap6_ctlinput,
    437 	.pr_ctloutput = rip6_ctloutput,
    438 	.pr_usrreqs = &rip6_usrreqs,
    439 	.pr_init = encap_init,
    440 },
    441 #if NETHERIP > 0
    442 {	.pr_type = SOCK_RAW,
    443 	.pr_domain = &inet6domain,
    444 	.pr_protocol = IPPROTO_ETHERIP,
    445 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    446 	.pr_input = ip6_etherip_input,
    447 	.pr_ctlinput = rip6_ctlinput,
    448 	.pr_ctloutput = rip6_ctloutput,
    449 	.pr_usrreqs = &rip6_usrreqs,
    450 },
    451 #endif
    452 #if NCARP > 0
    453 {	.pr_type = SOCK_RAW,
    454 	.pr_domain = &inet6domain,
    455 	.pr_protocol = IPPROTO_CARP,
    456 	.pr_flags = PR_ATOMIC|PR_ADDR,
    457 	.pr_input = carp6_proto_input,
    458 	.pr_ctloutput = rip6_ctloutput,
    459 	.pr_usrreqs = &rip6_usrreqs,
    460 },
    461 #endif /* NCARP */
    462 {	.pr_type = SOCK_RAW,
    463 	.pr_domain = &inet6domain,
    464 	.pr_protocol = IPPROTO_L2TP,
    465 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    466 	.pr_input = encap6_input,
    467 	.pr_ctlinput = rip6_ctlinput,
    468 	.pr_ctloutput = rip6_ctloutput,
    469 	.pr_usrreqs = &rip6_usrreqs,
    470 	.pr_init = encap_init,
    471 },
    472 {	.pr_type = SOCK_RAW,
    473 	.pr_domain = &inet6domain,
    474 	.pr_protocol = IPPROTO_PIM,
    475 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    476 	.pr_input = pim6_input,
    477 	.pr_ctloutput = rip6_ctloutput,
    478 	.pr_usrreqs = &rip6_usrreqs,
    479 	.pr_init = pim6_init,
    480 },
    481 /* raw wildcard */
    482 {	.pr_type = SOCK_RAW,
    483 	.pr_domain = &inet6domain,
    484 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    485 	.pr_input = rip6_input,
    486 	.pr_ctloutput = rip6_ctloutput,
    487 	.pr_usrreqs = &rip6_usrreqs,
    488 	.pr_init = rip6_init,
    489 },
    490 };
    491 
    492 static const struct sockaddr_in6 in6_any = {
    493 	  .sin6_len = sizeof(in6_any)
    494 	, .sin6_family = AF_INET6
    495 	, .sin6_port = 0
    496 	, .sin6_flowinfo = 0
    497 	, .sin6_addr = IN6ADDR_ANY_INIT
    498 	, .sin6_scope_id = 0
    499 };
    500 
    501 bool in6_present = false;
    502 static void
    503 in6_dom_init(void)
    504 {
    505 
    506 	in6_present = true;
    507 }
    508 
    509 struct domain inet6domain = {
    510 	.dom_family = AF_INET6, .dom_name = "internet6",
    511 	.dom_init = in6_dom_init, .dom_externalize = NULL, .dom_dispose = NULL,
    512 	.dom_protosw = (const struct protosw *)inet6sw,
    513 	.dom_protoswNPROTOSW = (const struct protosw *)&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])],
    514 	.dom_rtattach = rt_inithead,
    515 	.dom_rtoffset = offsetof(struct sockaddr_in6, sin6_addr) << 3,
    516 	.dom_maxrtkey = sizeof(struct ip_pack6),
    517 	.dom_if_up = in6_if_up, .dom_if_down = in6_if_down,
    518 	.dom_ifattach = in6_domifattach, .dom_ifdetach = in6_domifdetach,
    519 	.dom_if_link_state_change = in6_if_link_state_change,
    520 	.dom_ifqueues = { NULL, NULL },
    521 	.dom_link = { NULL },
    522 	.dom_mowner = MOWNER_INIT("",""),
    523 	.dom_sa_cmpofs = offsetof(struct sockaddr_in6, sin6_addr),
    524 	.dom_sa_cmplen = sizeof(struct in6_addr),
    525 	.dom_sa_any = (const struct sockaddr *)&in6_any,
    526 	.dom_sockaddr_externalize = sockaddr_in6_externalize,
    527 };
    528 
    529 #if 0
    530 int
    531 sockaddr_in6_cmp(const struct sockaddr *lsa, const struct sockaddr *rsa)
    532 {
    533 	uint_fast8_t len;
    534 	const uint_fast8_t addrofs = offsetof(struct sockaddr_in6, sin6_addr),
    535 			   addrend = addrofs + sizeof(struct in6_addr);
    536 	int rc;
    537 	const struct sockaddr_in6 *lsin6, *rsin6;
    538 
    539 	lsin6 = satocsin6(lsa);
    540 	rsin6 = satocsin6(rsa);
    541 
    542 	len = MIN(addrend, MIN(lsin6->sin6_len, rsin6->sin6_len));
    543 
    544 	if (len > addrofs &&
    545 	    (rc = memcmp(&lsin6->sin6_addr, &rsin6->sin6_addr,
    546 	                  len - addrofs)) != 0)
    547 		return rc;
    548 
    549 	return lsin6->sin6_len - rsin6->sin6_len;
    550 }
    551 #endif
    552 
    553 /*
    554  * Internet configuration info
    555  */
    556 #ifndef	IPV6FORWARDING
    557 #ifdef GATEWAY6
    558 #define	IPV6FORWARDING	1	/* forward IP6 packets not for us */
    559 #else
    560 #define	IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
    561 #endif /* GATEWAY6 */
    562 #endif /* !IPV6FORWARDING */
    563 
    564 int	ip6_forwarding = IPV6FORWARDING;	/* act as router? */
    565 int	ip6_sendredirects = 1;
    566 int	ip6_defhlim = IPV6_DEFHLIM;
    567 int	ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
    568 int	ip6_accept_rtadv = 0;	/* "IPV6FORWARDING ? 0 : 1" is dangerous */
    569 int	ip6_maxfragpackets = 200;
    570 int	ip6_maxfrags = 200;
    571 int	ip6_log_interval = 5;
    572 int	ip6_hdrnestlimit = 50;	/* appropriate? */
    573 int	ip6_dad_count = 1;	/* DupAddrDetectionTransmits */
    574 int	ip6_auto_flowlabel = 1;
    575 int	ip6_use_deprecated = 1;	/* allow deprecated addr (RFC2462 5.5.4) */
    576 int	ip6_rr_prune = 5;	/* router renumbering prefix
    577 				 * walk list every 5 sec. */
    578 int	ip6_mcast_pmtu = 0;	/* enable pMTU discovery for multicast? */
    579 int	ip6_v6only = 1;
    580 int     ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */
    581 int     ip6_maxifprefixes = 16; /* Max acceptable prefixes via RA per IF */
    582 int     ip6_maxifdefrouters = 16; /* Max acceptable def routers via RA */
    583 int     ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */
    584 
    585 int	ip6_keepfaith = 0;
    586 time_t	ip6_log_time = 0;
    587 int	ip6_rtadv_maxroutes = 100; /* (arbitrary) initial maximum number of
    588                                     * routes via rtadv expected to be
    589                                     * significantly larger than common use.
    590                                     * if you need to count: 3 extra initial
    591                                     * routes, plus 1 per interface after the
    592                                     * first one, then one per non-linklocal
    593                                     * prefix */
    594 
    595 /* icmp6 */
    596 /*
    597  * BSDI4 defines these variables in in_proto.c...
    598  * XXX: what if we don't define INET? Should we define pmtu6_expire
    599  * or so? (jinmei (at) kame.net 19990310)
    600  */
    601 int pmtu_expire = 60*10;
    602 
    603 /* raw IP6 parameters */
    604 /*
    605  * Nominal space allocated to a raw ip socket.
    606  */
    607 #define	RIPV6SNDQ	8192
    608 #define	RIPV6RCVQ	8192
    609 
    610 u_long	rip6_sendspace = RIPV6SNDQ;
    611 u_long	rip6_recvspace = RIPV6RCVQ;
    612 
    613 /* ICMPV6 parameters */
    614 int	icmp6_rediraccept = 1;		/* accept and process redirects */
    615 int	icmp6_redirtimeout = 10 * 60;	/* 10 minutes */
    616 int	icmp6errppslim = 100;		/* 100pps */
    617 int	icmp6_nodeinfo = 1;		/* enable/disable NI response */
    618