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