Home | History | Annotate | Line # | Download | only in netinet6
ip6_input.c revision 1.206
      1  1.206      maxv /*	$NetBSD: ip6_input.c,v 1.206 2019/01/14 18:51:15 maxv Exp $	*/
      2   1.40    itojun /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
      3    1.3   thorpej 
      4    1.2    itojun /*
      5    1.2    itojun  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      6    1.2    itojun  * All rights reserved.
      7   1.21    itojun  *
      8    1.2    itojun  * Redistribution and use in source and binary forms, with or without
      9    1.2    itojun  * modification, are permitted provided that the following conditions
     10    1.2    itojun  * are met:
     11    1.2    itojun  * 1. Redistributions of source code must retain the above copyright
     12    1.2    itojun  *    notice, this list of conditions and the following disclaimer.
     13    1.2    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     14    1.2    itojun  *    notice, this list of conditions and the following disclaimer in the
     15    1.2    itojun  *    documentation and/or other materials provided with the distribution.
     16    1.2    itojun  * 3. Neither the name of the project nor the names of its contributors
     17    1.2    itojun  *    may be used to endorse or promote products derived from this software
     18    1.2    itojun  *    without specific prior written permission.
     19   1.21    itojun  *
     20    1.2    itojun  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     21    1.2    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22    1.2    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23    1.2    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     24    1.2    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25    1.2    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26    1.2    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27    1.2    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28    1.2    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29    1.2    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30    1.2    itojun  * SUCH DAMAGE.
     31    1.2    itojun  */
     32    1.2    itojun 
     33    1.2    itojun /*
     34    1.2    itojun  * Copyright (c) 1982, 1986, 1988, 1993
     35    1.2    itojun  *	The Regents of the University of California.  All rights reserved.
     36    1.2    itojun  *
     37    1.2    itojun  * Redistribution and use in source and binary forms, with or without
     38    1.2    itojun  * modification, are permitted provided that the following conditions
     39    1.2    itojun  * are met:
     40    1.2    itojun  * 1. Redistributions of source code must retain the above copyright
     41    1.2    itojun  *    notice, this list of conditions and the following disclaimer.
     42    1.2    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     43    1.2    itojun  *    notice, this list of conditions and the following disclaimer in the
     44    1.2    itojun  *    documentation and/or other materials provided with the distribution.
     45   1.65       agc  * 3. Neither the name of the University nor the names of its contributors
     46    1.2    itojun  *    may be used to endorse or promote products derived from this software
     47    1.2    itojun  *    without specific prior written permission.
     48    1.2    itojun  *
     49    1.2    itojun  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     50    1.2    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51    1.2    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52    1.2    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     53    1.2    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54    1.2    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55    1.2    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56    1.2    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57    1.2    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58    1.2    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59    1.2    itojun  * SUCH DAMAGE.
     60    1.2    itojun  *
     61    1.2    itojun  *	@(#)ip_input.c	8.2 (Berkeley) 1/4/94
     62    1.2    itojun  */
     63   1.48     lukem 
     64   1.48     lukem #include <sys/cdefs.h>
     65  1.206      maxv __KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.206 2019/01/14 18:51:15 maxv Exp $");
     66    1.2    itojun 
     67  1.152     pooka #ifdef _KERNEL_OPT
     68  1.129     joerg #include "opt_gateway.h"
     69    1.2    itojun #include "opt_inet.h"
     70   1.85    rpaulo #include "opt_inet6.h"
     71    1.4   thorpej #include "opt_ipsec.h"
     72  1.169     ozaki #include "opt_net_mpsafe.h"
     73  1.152     pooka #endif
     74    1.2    itojun 
     75    1.2    itojun #include <sys/param.h>
     76    1.2    itojun #include <sys/systm.h>
     77    1.2    itojun #include <sys/mbuf.h>
     78    1.2    itojun #include <sys/domain.h>
     79    1.2    itojun #include <sys/protosw.h>
     80    1.2    itojun #include <sys/socket.h>
     81    1.2    itojun #include <sys/socketvar.h>
     82    1.2    itojun #include <sys/errno.h>
     83    1.2    itojun #include <sys/time.h>
     84    1.2    itojun #include <sys/kernel.h>
     85    1.2    itojun #include <sys/syslog.h>
     86    1.2    itojun #include <sys/proc.h>
     87   1.46    simonb #include <sys/sysctl.h>
     88  1.133       tls #include <sys/cprng.h>
     89  1.167     ozaki #include <sys/percpu.h>
     90    1.2    itojun 
     91    1.2    itojun #include <net/if.h>
     92    1.2    itojun #include <net/if_types.h>
     93    1.2    itojun #include <net/if_dl.h>
     94    1.2    itojun #include <net/route.h>
     95  1.148     rmind #include <net/pktqueue.h>
     96   1.15   darrenr #include <net/pfil.h>
     97    1.2    itojun 
     98    1.2    itojun #include <netinet/in.h>
     99    1.9    itojun #include <netinet/in_systm.h>
    100    1.9    itojun #ifdef INET
    101    1.9    itojun #include <netinet/ip.h>
    102  1.148     rmind #include <netinet/ip_var.h>
    103    1.9    itojun #include <netinet/ip_icmp.h>
    104   1.45    itojun #endif /* INET */
    105   1.14    itojun #include <netinet/ip6.h>
    106  1.140  christos #include <netinet/portalgo.h>
    107    1.2    itojun #include <netinet6/in6_var.h>
    108   1.11    itojun #include <netinet6/ip6_var.h>
    109  1.116   thorpej #include <netinet6/ip6_private.h>
    110    1.2    itojun #include <netinet6/in6_pcb.h>
    111   1.14    itojun #include <netinet/icmp6.h>
    112   1.81    rpaulo #include <netinet6/scope6_var.h>
    113    1.2    itojun #include <netinet6/in6_ifattach.h>
    114    1.2    itojun #include <netinet6/nd6.h>
    115    1.2    itojun 
    116  1.142  christos #ifdef IPSEC
    117   1.94  degroote #include <netipsec/ipsec.h>
    118   1.94  degroote #include <netipsec/ipsec6.h>
    119   1.94  degroote #include <netipsec/key.h>
    120  1.142  christos #endif /* IPSEC */
    121   1.94  degroote 
    122    1.2    itojun #include <netinet6/ip6protosw.h>
    123    1.2    itojun 
    124    1.2    itojun #include "faith.h"
    125    1.2    itojun 
    126    1.2    itojun extern struct domain inet6domain;
    127    1.2    itojun 
    128    1.2    itojun u_char ip6_protox[IPPROTO_MAX];
    129  1.148     rmind pktqueue_t *ip6_pktq __read_mostly;
    130    1.2    itojun 
    131  1.143     rmind pfil_head_t *inet6_pfil_hook;
    132   1.29   thorpej 
    133  1.116   thorpej percpu_t *ip6stat_percpu;
    134    1.2    itojun 
    135  1.167     ozaki percpu_t *ip6_forward_rt_percpu __cacheline_aligned;
    136  1.167     ozaki 
    137  1.156     ozaki static void ip6_init2(void);
    138  1.148     rmind static void ip6intr(void *);
    139  1.199      maxv static bool ip6_badaddr(struct ip6_hdr *);
    140  1.112    dyoung static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *);
    141    1.2    itojun 
    142  1.136  drochner static int ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *,
    143  1.189      maxv     u_int32_t *);
    144  1.111    dyoung static struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int);
    145  1.128     pooka static void sysctl_net_inet6_ip6_setup(struct sysctllog **);
    146    1.2    itojun 
    147  1.169     ozaki #ifdef NET_MPSAFE
    148  1.169     ozaki #define	SOFTNET_LOCK()		mutex_enter(softnet_lock)
    149  1.169     ozaki #define	SOFTNET_UNLOCK()	mutex_exit(softnet_lock)
    150  1.169     ozaki #else
    151  1.169     ozaki #define	SOFTNET_LOCK()		KASSERT(mutex_owned(softnet_lock))
    152  1.169     ozaki #define	SOFTNET_UNLOCK()	KASSERT(mutex_owned(softnet_lock))
    153  1.169     ozaki #endif
    154  1.169     ozaki 
    155    1.2    itojun /*
    156    1.2    itojun  * IP6 initialization: fill in IP6 protocol switch table.
    157    1.2    itojun  * All protocols not implemented in kernel go to raw IP6 protocol handler.
    158    1.2    itojun  */
    159    1.2    itojun void
    160  1.114      matt ip6_init(void)
    161    1.2    itojun {
    162   1.78  christos 	const struct ip6protosw *pr;
    163   1.35    itojun 	int i;
    164    1.2    itojun 
    165  1.163     ozaki 	in6_init();
    166  1.162     ozaki 
    167  1.128     pooka 	sysctl_net_inet6_ip6_setup(NULL);
    168   1.78  christos 	pr = (const struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
    169    1.2    itojun 	if (pr == 0)
    170    1.2    itojun 		panic("ip6_init");
    171    1.2    itojun 	for (i = 0; i < IPPROTO_MAX; i++)
    172    1.2    itojun 		ip6_protox[i] = pr - inet6sw;
    173   1.78  christos 	for (pr = (const struct ip6protosw *)inet6domain.dom_protosw;
    174   1.78  christos 	    pr < (const struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++)
    175    1.2    itojun 		if (pr->pr_domain->dom_family == PF_INET6 &&
    176    1.2    itojun 		    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
    177    1.2    itojun 			ip6_protox[pr->pr_protocol] = pr - inet6sw;
    178  1.148     rmind 
    179  1.149     ozaki 	ip6_pktq = pktq_create(IFQ_MAXLEN, ip6intr, NULL);
    180  1.148     rmind 	KASSERT(ip6_pktq != NULL);
    181  1.148     rmind 
    182   1.81    rpaulo 	scope6_init();
    183   1.81    rpaulo 	addrsel_policy_init();
    184    1.2    itojun 	nd6_init();
    185    1.2    itojun 	frag6_init();
    186  1.133       tls 	ip6_desync_factor = cprng_fast32() % MAX_TEMP_DESYNC_FACTOR;
    187    1.2    itojun 
    188  1.156     ozaki 	ip6_init2();
    189   1.98  liamjfoy #ifdef GATEWAY
    190   1.99  liamjfoy 	ip6flow_init(ip6_hashsize);
    191   1.98  liamjfoy #endif
    192   1.29   thorpej 	/* Register our Packet Filter hook. */
    193  1.143     rmind 	inet6_pfil_hook = pfil_head_create(PFIL_TYPE_AF, (void *)AF_INET6);
    194  1.143     rmind 	KASSERT(inet6_pfil_hook != NULL);
    195  1.116   thorpej 
    196  1.116   thorpej 	ip6stat_percpu = percpu_alloc(sizeof(uint64_t) * IP6_NSTATS);
    197  1.167     ozaki 	ip6_forward_rt_percpu = percpu_alloc(sizeof(struct route));
    198    1.2    itojun }
    199    1.2    itojun 
    200    1.2    itojun static void
    201  1.156     ozaki ip6_init2(void)
    202    1.2    itojun {
    203    1.2    itojun 
    204  1.186      maxv 	/* timer for regeneration of temporary addresses randomize ID */
    205  1.118        ad 	callout_init(&in6_tmpaddrtimer_ch, CALLOUT_MPSAFE);
    206   1.83    rpaulo 	callout_reset(&in6_tmpaddrtimer_ch,
    207   1.83    rpaulo 		      (ip6_temp_preferred_lifetime - ip6_desync_factor -
    208   1.83    rpaulo 		       ip6_temp_regen_advance) * hz,
    209   1.83    rpaulo 		      in6_tmpaddrtimer, NULL);
    210    1.2    itojun }
    211    1.2    itojun 
    212    1.2    itojun /*
    213    1.2    itojun  * IP6 input interrupt handling. Just pass the packet to ip6_input.
    214    1.2    itojun  */
    215  1.148     rmind static void
    216  1.148     rmind ip6intr(void *arg __unused)
    217    1.2    itojun {
    218    1.2    itojun 	struct mbuf *m;
    219    1.2    itojun 
    220  1.193     ozaki 	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
    221  1.148     rmind 	while ((m = pktq_dequeue(ip6_pktq)) != NULL) {
    222  1.160     ozaki 		struct psref psref;
    223  1.160     ozaki 		struct ifnet *rcvif = m_get_rcvif_psref(m, &psref);
    224  1.148     rmind 
    225  1.160     ozaki 		if (rcvif == NULL) {
    226  1.160     ozaki 			m_freem(m);
    227  1.160     ozaki 			continue;
    228  1.160     ozaki 		}
    229  1.148     rmind 		/*
    230  1.148     rmind 		 * Drop the packet if IPv6 is disabled on the interface.
    231  1.148     rmind 		 */
    232  1.160     ozaki 		if ((ND_IFINFO(rcvif)->flags & ND6_IFF_IFDISABLED)) {
    233  1.160     ozaki 			m_put_rcvif_psref(rcvif, &psref);
    234   1.83    rpaulo 			m_freem(m);
    235  1.148     rmind 			continue;
    236   1.83    rpaulo 		}
    237  1.160     ozaki 		ip6_input(m, rcvif);
    238  1.160     ozaki 		m_put_rcvif_psref(rcvif, &psref);
    239    1.2    itojun 	}
    240  1.193     ozaki 	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
    241    1.2    itojun }
    242    1.2    itojun 
    243    1.2    itojun void
    244  1.160     ozaki ip6_input(struct mbuf *m, struct ifnet *rcvif)
    245    1.2    itojun {
    246    1.9    itojun 	struct ip6_hdr *ip6;
    247  1.105    dyoung 	int hit, off = sizeof(struct ip6_hdr), nest;
    248    1.2    itojun 	u_int32_t plen;
    249    1.5    itojun 	u_int32_t rtalert = ~0;
    250  1.188      maxv 	int nxt, ours = 0, rh_present = 0, frg_present;
    251    1.9    itojun 	struct ifnet *deliverifp = NULL;
    252   1.64    itojun 	int srcrt = 0;
    253  1.171     ozaki 	struct rtentry *rt = NULL;
    254  1.105    dyoung 	union {
    255  1.105    dyoung 		struct sockaddr		dst;
    256  1.105    dyoung 		struct sockaddr_in6	dst6;
    257  1.105    dyoung 	} u;
    258  1.167     ozaki 	struct route *ro;
    259    1.2    itojun 
    260  1.186      maxv 	KASSERT(rcvif != NULL);
    261  1.186      maxv 
    262    1.2    itojun 	/*
    263   1.81    rpaulo 	 * make sure we don't have onion peering information into m_tag.
    264   1.81    rpaulo 	 */
    265   1.81    rpaulo 	ip6_delaux(m);
    266   1.81    rpaulo 
    267   1.81    rpaulo 	/*
    268   1.44    itojun 	 * mbuf statistics
    269    1.2    itojun 	 */
    270    1.2    itojun 	if (m->m_flags & M_EXT) {
    271    1.2    itojun 		if (m->m_next)
    272  1.116   thorpej 			IP6_STATINC(IP6_STAT_MEXT2M);
    273    1.2    itojun 		else
    274  1.116   thorpej 			IP6_STATINC(IP6_STAT_MEXT1);
    275    1.2    itojun 	} else {
    276  1.115   thorpej #define M2MMAX	32
    277    1.2    itojun 		if (m->m_next) {
    278  1.159     ozaki 			if (m->m_flags & M_LOOP)
    279  1.116   thorpej 			/*XXX*/	IP6_STATINC(IP6_STAT_M2M + lo0ifp->if_index);
    280  1.159     ozaki 			else if (rcvif->if_index < M2MMAX)
    281  1.159     ozaki 				IP6_STATINC(IP6_STAT_M2M + rcvif->if_index);
    282  1.159     ozaki 			else
    283  1.116   thorpej 				IP6_STATINC(IP6_STAT_M2M);
    284    1.2    itojun 		} else
    285  1.116   thorpej 			IP6_STATINC(IP6_STAT_M1);
    286   1.40    itojun #undef M2MMAX
    287    1.2    itojun 	}
    288    1.2    itojun 
    289  1.159     ozaki 	in6_ifstat_inc(rcvif, ifs6_in_receive);
    290  1.116   thorpej 	IP6_STATINC(IP6_STAT_TOTAL);
    291    1.9    itojun 
    292   1.57   thorpej 	/*
    293   1.57   thorpej 	 * If the IPv6 header is not aligned, slurp it up into a new
    294   1.57   thorpej 	 * mbuf with space for link headers, in the event we forward
    295   1.81    rpaulo 	 * it.  Otherwise, if it is aligned, make sure the entire base
    296   1.57   thorpej 	 * IPv6 header is in the first mbuf of the chain.
    297   1.57   thorpej 	 */
    298   1.97  christos 	if (IP6_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
    299   1.57   thorpej 		if ((m = m_copyup(m, sizeof(struct ip6_hdr),
    300  1.186      maxv 		    (max_linkhdr + 3) & ~3)) == NULL) {
    301   1.57   thorpej 			/* XXXJRT new stat, please */
    302  1.116   thorpej 			IP6_STATINC(IP6_STAT_TOOSMALL);
    303  1.159     ozaki 			in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
    304   1.57   thorpej 			return;
    305   1.57   thorpej 		}
    306   1.57   thorpej 	} else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
    307   1.55    itojun 		if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
    308  1.116   thorpej 			IP6_STATINC(IP6_STAT_TOOSMALL);
    309  1.159     ozaki 			in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
    310    1.9    itojun 			return;
    311    1.9    itojun 		}
    312    1.2    itojun 	}
    313    1.2    itojun 
    314    1.2    itojun 	ip6 = mtod(m, struct ip6_hdr *);
    315    1.2    itojun 
    316    1.2    itojun 	if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
    317  1.116   thorpej 		IP6_STATINC(IP6_STAT_BADVERS);
    318  1.159     ozaki 		in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
    319    1.2    itojun 		goto bad;
    320    1.2    itojun 	}
    321   1.15   darrenr 
    322  1.199      maxv 	if (ip6_badaddr(ip6)) {
    323  1.194      maxv 		IP6_STATINC(IP6_STAT_BADSCOPE);
    324  1.194      maxv 		in6_ifstat_inc(rcvif, ifs6_in_addrerr);
    325  1.194      maxv 		goto bad;
    326  1.194      maxv 	}
    327  1.194      maxv 
    328  1.194      maxv 	/*
    329   1.98  liamjfoy 	 * Assume that we can create a fast-forward IP flow entry
    330   1.98  liamjfoy 	 * based on this packet.
    331   1.98  liamjfoy 	 */
    332   1.98  liamjfoy 	m->m_flags |= M_CANFASTFWD;
    333   1.98  liamjfoy 
    334   1.15   darrenr 	/*
    335   1.15   darrenr 	 * Run through list of hooks for input packets.  If there are any
    336   1.15   darrenr 	 * filters which require that additional packets in the flow are
    337   1.15   darrenr 	 * not fast-forwarded, they must clear the M_CANFASTFWD flag.
    338   1.15   darrenr 	 * Note that filters must _never_ set this flag, as another filter
    339   1.15   darrenr 	 * in the list may have previously cleared it.
    340  1.196      maxv 	 *
    341  1.196      maxv 	 * Don't call hooks if the packet has already been processed by
    342  1.196      maxv 	 * IPsec (encapsulated, tunnel mode).
    343   1.39    itojun 	 */
    344  1.142  christos #if defined(IPSEC)
    345  1.146  christos 	if (!ipsec_used || !ipsec_indone(m))
    346   1.39    itojun #else
    347   1.39    itojun 	if (1)
    348   1.39    itojun #endif
    349   1.39    itojun 	{
    350   1.64    itojun 		struct in6_addr odst;
    351   1.64    itojun 
    352   1.64    itojun 		odst = ip6->ip6_dst;
    353  1.159     ozaki 		if (pfil_run_hooks(inet6_pfil_hook, &m, rcvif, PFIL_IN) != 0)
    354   1.39    itojun 			return;
    355   1.39    itojun 		if (m == NULL)
    356   1.39    itojun 			return;
    357  1.203      maxv 		KASSERT(m->m_len >= sizeof(struct ip6_hdr));
    358   1.39    itojun 		ip6 = mtod(m, struct ip6_hdr *);
    359   1.64    itojun 		srcrt = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst);
    360   1.39    itojun 	}
    361   1.15   darrenr 
    362  1.116   thorpej 	IP6_STATINC(IP6_STAT_NXTHIST + ip6->ip6_nxt);
    363    1.2    itojun 
    364   1.30   thorpej #ifdef ALTQ
    365  1.169     ozaki 	if (altq_input != NULL) {
    366  1.169     ozaki 		SOFTNET_LOCK();
    367  1.169     ozaki 		if ((*altq_input)(m, AF_INET6) == 0) {
    368  1.169     ozaki 			SOFTNET_UNLOCK();
    369  1.169     ozaki 			/* packet is dropped by traffic conditioner */
    370  1.169     ozaki 			return;
    371  1.169     ozaki 		}
    372  1.169     ozaki 		SOFTNET_UNLOCK();
    373    1.9    itojun 	}
    374    1.9    itojun #endif
    375    1.9    itojun 
    376    1.2    itojun 	/*
    377   1.82      yamt 	 * Disambiguate address scope zones (if there is ambiguity).
    378   1.82      yamt 	 * We first make sure that the original source or destination address
    379   1.82      yamt 	 * is not in our internal form for scoped addresses.  Such addresses
    380   1.82      yamt 	 * are not necessarily invalid spec-wise, but we cannot accept them due
    381   1.82      yamt 	 * to the usage conflict.
    382   1.82      yamt 	 * in6_setscope() then also checks and rejects the cases where src or
    383   1.82      yamt 	 * dst are the loopback address and the receiving interface
    384  1.186      maxv 	 * is not loopback.
    385   1.82      yamt 	 */
    386   1.88    bouyer 	if (__predict_false(
    387   1.88    bouyer 	    m_makewritable(&m, 0, sizeof(struct ip6_hdr), M_DONTWAIT)))
    388   1.88    bouyer 		goto bad;
    389   1.88    bouyer 	ip6 = mtod(m, struct ip6_hdr *);
    390   1.82      yamt 	if (in6_clearscope(&ip6->ip6_src) || in6_clearscope(&ip6->ip6_dst)) {
    391  1.116   thorpej 		IP6_STATINC(IP6_STAT_BADSCOPE);	/* XXX */
    392   1.82      yamt 		goto bad;
    393   1.82      yamt 	}
    394  1.159     ozaki 	if (in6_setscope(&ip6->ip6_src, rcvif, NULL) ||
    395  1.159     ozaki 	    in6_setscope(&ip6->ip6_dst, rcvif, NULL)) {
    396  1.116   thorpej 		IP6_STATINC(IP6_STAT_BADSCOPE);
    397   1.82      yamt 		goto bad;
    398   1.82      yamt 	}
    399   1.82      yamt 
    400  1.171     ozaki 	ro = percpu_getref(ip6_forward_rt_percpu);
    401  1.186      maxv 
    402   1.82      yamt 	/*
    403    1.2    itojun 	 * Multicast check
    404    1.2    itojun 	 */
    405    1.2    itojun 	if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
    406  1.176     ozaki 		bool ingroup;
    407    1.9    itojun 
    408  1.159     ozaki 		in6_ifstat_inc(rcvif, ifs6_in_mcast);
    409    1.2    itojun 		/*
    410    1.2    itojun 		 * See if we belong to the destination multicast group on the
    411    1.2    itojun 		 * arrival interface.
    412    1.2    itojun 		 */
    413  1.176     ozaki 		ingroup = in6_multi_group(&ip6->ip6_dst, rcvif);
    414  1.186      maxv 		if (ingroup) {
    415    1.2    itojun 			ours = 1;
    416  1.186      maxv 		} else if (!ip6_mrouter) {
    417  1.116   thorpej 			uint64_t *ip6s = IP6_STAT_GETREF();
    418  1.116   thorpej 			ip6s[IP6_STAT_NOTMEMBER]++;
    419  1.116   thorpej 			ip6s[IP6_STAT_CANTFORWARD]++;
    420  1.116   thorpej 			IP6_STAT_PUTREF();
    421  1.159     ozaki 			in6_ifstat_inc(rcvif, ifs6_in_discard);
    422  1.171     ozaki 			goto bad_unref;
    423    1.2    itojun 		}
    424  1.159     ozaki 		deliverifp = rcvif;
    425    1.2    itojun 		goto hbhcheck;
    426    1.2    itojun 	}
    427    1.2    itojun 
    428  1.105    dyoung 	sockaddr_in6_init(&u.dst6, &ip6->ip6_dst, 0, 0, 0);
    429  1.105    dyoung 
    430    1.2    itojun 	/*
    431  1.186      maxv 	 * Unicast check
    432    1.2    itojun 	 */
    433  1.167     ozaki 	rt = rtcache_lookup2(ro, &u.dst, 1, &hit);
    434  1.105    dyoung 	if (hit)
    435  1.116   thorpej 		IP6_STATINC(IP6_STAT_FORWARD_CACHEHIT);
    436   1.93     joerg 	else
    437  1.116   thorpej 		IP6_STATINC(IP6_STAT_FORWARD_CACHEMISS);
    438   1.22    itojun 
    439    1.2    itojun 	/*
    440    1.2    itojun 	 * Accept the packet if the forwarding interface to the destination
    441  1.186      maxv 	 * (according to the routing table) is the loopback interface,
    442    1.2    itojun 	 * unless the associated route has a gateway.
    443  1.186      maxv 	 *
    444  1.186      maxv 	 * We don't explicitly match ip6_dst against an interface here. It
    445  1.186      maxv 	 * is already done in rtcache_lookup2: rt->rt_ifp->if_type will be
    446  1.186      maxv 	 * IFT_LOOP if the packet is for us.
    447  1.186      maxv 	 *
    448    1.2    itojun 	 * Note that this approach causes to accept a packet if there is a
    449    1.2    itojun 	 * route to the loopback interface for the destination of the packet.
    450    1.2    itojun 	 * But we think it's even useful in some situations, e.g. when using
    451    1.2    itojun 	 * a special daemon which wants to intercept the packet.
    452    1.2    itojun 	 */
    453  1.105    dyoung 	if (rt != NULL &&
    454  1.105    dyoung 	    (rt->rt_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST &&
    455  1.105    dyoung 	    rt->rt_ifp->if_type == IFT_LOOP) {
    456  1.105    dyoung 		struct in6_ifaddr *ia6 = (struct in6_ifaddr *)rt->rt_ifa;
    457  1.184       roy 		int addrok;
    458  1.184       roy 
    459    1.2    itojun 		if (ia6->ia6_flags & IN6_IFF_ANYCAST)
    460    1.2    itojun 			m->m_flags |= M_ANYCAST6;
    461   1.24    itojun 		/*
    462   1.24    itojun 		 * packets to a tentative, duplicated, or somehow invalid
    463   1.24    itojun 		 * address must not be accepted.
    464   1.24    itojun 		 */
    465  1.184       roy 		if (ia6->ia6_flags & IN6_IFF_NOTREADY)
    466  1.184       roy 			addrok = 0;
    467  1.184       roy 		else if (ia6->ia6_flags & IN6_IFF_DETACHED &&
    468  1.184       roy 		    !IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src))
    469  1.184       roy 		{
    470  1.184       roy 			/* Allow internal traffic to DETACHED addresses */
    471  1.184       roy 			struct sockaddr_in6 sin6;
    472  1.184       roy 			int s;
    473  1.184       roy 
    474  1.184       roy 			memset(&sin6, 0, sizeof(sin6));
    475  1.184       roy 			sin6.sin6_family = AF_INET6;
    476  1.184       roy 			sin6.sin6_len = sizeof(sin6);
    477  1.184       roy 			sin6.sin6_addr = ip6->ip6_src;
    478  1.184       roy 			s = pserialize_read_enter();
    479  1.184       roy 			addrok = (ifa_ifwithaddr(sin6tosa(&sin6)) != NULL);
    480  1.184       roy 			pserialize_read_exit(s);
    481  1.184       roy 		} else
    482  1.185       kre 			addrok = 1;
    483  1.184       roy 		if (addrok) {
    484   1.24    itojun 			/* this address is ready */
    485    1.2    itojun 			ours = 1;
    486    1.9    itojun 			deliverifp = ia6->ia_ifp;	/* correct? */
    487    1.2    itojun 			goto hbhcheck;
    488    1.2    itojun 		} else {
    489   1.24    itojun 			/* address is not ready, so discard the packet. */
    490  1.172       ryo 			char ip6bufs[INET6_ADDRSTRLEN];
    491  1.172       ryo 			char ip6bufd[INET6_ADDRSTRLEN];
    492  1.157     ozaki 			nd6log(LOG_INFO, "packet to an unready address %s->%s\n",
    493  1.173  christos 			    IN6_PRINT(ip6bufs, &ip6->ip6_src),
    494  1.173  christos 			    IN6_PRINT(ip6bufd, &ip6->ip6_dst));
    495   1.24    itojun 
    496  1.171     ozaki 			goto bad_unref;
    497    1.2    itojun 		}
    498    1.2    itojun 	}
    499    1.2    itojun 
    500    1.2    itojun 	/*
    501   1.55    itojun 	 * FAITH (Firewall Aided Internet Translator)
    502    1.2    itojun 	 */
    503    1.2    itojun #if defined(NFAITH) && 0 < NFAITH
    504    1.2    itojun 	if (ip6_keepfaith) {
    505  1.105    dyoung 		if (rt != NULL && rt->rt_ifp != NULL &&
    506  1.105    dyoung 		    rt->rt_ifp->if_type == IFT_FAITH) {
    507    1.2    itojun 			/* XXX do we need more sanity checks? */
    508    1.2    itojun 			ours = 1;
    509  1.105    dyoung 			deliverifp = rt->rt_ifp; /* faith */
    510    1.9    itojun 			goto hbhcheck;
    511    1.9    itojun 		}
    512    1.9    itojun 	}
    513    1.9    itojun #endif
    514    1.9    itojun 
    515    1.2    itojun 	/*
    516    1.2    itojun 	 * Now there is no reason to process the packet if it's not our own
    517    1.2    itojun 	 * and we're not a router.
    518    1.2    itojun 	 */
    519    1.2    itojun 	if (!ip6_forwarding) {
    520  1.116   thorpej 		IP6_STATINC(IP6_STAT_CANTFORWARD);
    521  1.159     ozaki 		in6_ifstat_inc(rcvif, ifs6_in_discard);
    522  1.171     ozaki 		goto bad_unref;
    523    1.2    itojun 	}
    524    1.2    itojun 
    525  1.186      maxv hbhcheck:
    526    1.2    itojun 	/*
    527  1.186      maxv 	 * Record address information into m_tag, if we don't have one yet.
    528  1.186      maxv 	 * Note that we are unable to record it, if the address is not listed
    529   1.81    rpaulo 	 * as our interface address (e.g. multicast addresses, addresses
    530   1.81    rpaulo 	 * within FAITH prefixes and such).
    531   1.81    rpaulo 	 */
    532  1.111    dyoung 	if (deliverifp && ip6_getdstifaddr(m) == NULL) {
    533   1.81    rpaulo 		struct in6_ifaddr *ia6;
    534  1.165     ozaki 		int s = pserialize_read_enter();
    535   1.81    rpaulo 
    536   1.81    rpaulo 		ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);
    537  1.165     ozaki 		/* Depends on ip6_setdstifaddr never sleep */
    538  1.111    dyoung 		if (ia6 != NULL && ip6_setdstifaddr(m, ia6) == NULL) {
    539  1.111    dyoung 			/*
    540  1.111    dyoung 			 * XXX maybe we should drop the packet here,
    541  1.111    dyoung 			 * as we could not provide enough information
    542  1.111    dyoung 			 * to the upper layers.
    543  1.111    dyoung 			 */
    544   1.81    rpaulo 		}
    545  1.165     ozaki 		pserialize_read_exit(s);
    546   1.81    rpaulo 	}
    547   1.81    rpaulo 
    548   1.81    rpaulo 	/*
    549    1.2    itojun 	 * Process Hop-by-Hop options header if it's contained.
    550    1.2    itojun 	 * m may be modified in ip6_hopopts_input().
    551    1.2    itojun 	 * If a JumboPayload option is included, plen will also be modified.
    552    1.2    itojun 	 */
    553    1.2    itojun 	plen = (u_int32_t)ntohs(ip6->ip6_plen);
    554    1.2    itojun 	if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {
    555    1.9    itojun 		struct ip6_hbh *hbh;
    556    1.9    itojun 
    557    1.9    itojun 		if (ip6_hopopts_input(&plen, &rtalert, &m, &off)) {
    558  1.186      maxv 			/* m already freed */
    559  1.159     ozaki 			in6_ifstat_inc(rcvif, ifs6_in_discard);
    560  1.171     ozaki 			rtcache_unref(rt, ro);
    561  1.171     ozaki 			percpu_putref(ip6_forward_rt_percpu);
    562  1.186      maxv 			return;
    563    1.9    itojun 		}
    564   1.22    itojun 
    565    1.2    itojun 		/* adjust pointer */
    566    1.2    itojun 		ip6 = mtod(m, struct ip6_hdr *);
    567   1.22    itojun 
    568   1.22    itojun 		/*
    569   1.49    itojun 		 * if the payload length field is 0 and the next header field
    570   1.22    itojun 		 * indicates Hop-by-Hop Options header, then a Jumbo Payload
    571   1.22    itojun 		 * option MUST be included.
    572   1.22    itojun 		 */
    573   1.22    itojun 		if (ip6->ip6_plen == 0 && plen == 0) {
    574   1.22    itojun 			/*
    575   1.22    itojun 			 * Note that if a valid jumbo payload option is
    576   1.83    rpaulo 			 * contained, ip6_hopopts_input() must set a valid
    577   1.55    itojun 			 * (non-zero) payload length to the variable plen.
    578   1.22    itojun 			 */
    579  1.116   thorpej 			IP6_STATINC(IP6_STAT_BADOPTIONS);
    580  1.159     ozaki 			in6_ifstat_inc(rcvif, ifs6_in_discard);
    581  1.159     ozaki 			in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
    582   1.22    itojun 			icmp6_error(m, ICMP6_PARAM_PROB,
    583   1.22    itojun 				    ICMP6_PARAMPROB_HEADER,
    584   1.97  christos 				    (char *)&ip6->ip6_plen - (char *)ip6);
    585  1.171     ozaki 			rtcache_unref(rt, ro);
    586  1.171     ozaki 			percpu_putref(ip6_forward_rt_percpu);
    587   1.22    itojun 			return;
    588   1.22    itojun 		}
    589    1.9    itojun 		IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
    590    1.9    itojun 			sizeof(struct ip6_hbh));
    591    1.9    itojun 		if (hbh == NULL) {
    592  1.116   thorpej 			IP6_STATINC(IP6_STAT_TOOSHORT);
    593  1.171     ozaki 			rtcache_unref(rt, ro);
    594  1.171     ozaki 			percpu_putref(ip6_forward_rt_percpu);
    595    1.9    itojun 			return;
    596    1.9    itojun 		}
    597   1.57   thorpej 		KASSERT(IP6_HDR_ALIGNED_P(hbh));
    598    1.9    itojun 		nxt = hbh->ip6h_nxt;
    599    1.2    itojun 
    600    1.2    itojun 		/*
    601    1.2    itojun 		 * accept the packet if a router alert option is included
    602    1.2    itojun 		 * and we act as an IPv6 router.
    603    1.2    itojun 		 */
    604    1.5    itojun 		if (rtalert != ~0 && ip6_forwarding)
    605    1.2    itojun 			ours = 1;
    606    1.2    itojun 	} else
    607    1.2    itojun 		nxt = ip6->ip6_nxt;
    608    1.2    itojun 
    609    1.2    itojun 	/*
    610  1.186      maxv 	 * Check that the amount of data in the buffers is at least much as
    611  1.186      maxv 	 * the IPv6 header would have us expect. Trim mbufs if longer than we
    612  1.186      maxv 	 * expect. Drop packet if shorter than we expect.
    613    1.2    itojun 	 */
    614    1.2    itojun 	if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) {
    615  1.116   thorpej 		IP6_STATINC(IP6_STAT_TOOSHORT);
    616  1.159     ozaki 		in6_ifstat_inc(rcvif, ifs6_in_truncated);
    617  1.171     ozaki 		goto bad_unref;
    618    1.2    itojun 	}
    619    1.2    itojun 	if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) {
    620    1.2    itojun 		if (m->m_len == m->m_pkthdr.len) {
    621    1.2    itojun 			m->m_len = sizeof(struct ip6_hdr) + plen;
    622    1.2    itojun 			m->m_pkthdr.len = sizeof(struct ip6_hdr) + plen;
    623    1.2    itojun 		} else
    624    1.2    itojun 			m_adj(m, sizeof(struct ip6_hdr) + plen - m->m_pkthdr.len);
    625    1.2    itojun 	}
    626    1.2    itojun 
    627    1.2    itojun 	/*
    628    1.2    itojun 	 * Forward if desirable.
    629    1.2    itojun 	 */
    630    1.2    itojun 	if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
    631    1.2    itojun 		/*
    632    1.2    itojun 		 * If we are acting as a multicast router, all
    633    1.2    itojun 		 * incoming multicast packets are passed to the
    634    1.2    itojun 		 * kernel-level multicast forwarding function.
    635    1.2    itojun 		 * The packet is returned (relatively) intact; if
    636    1.2    itojun 		 * ip6_mforward() returns a non-zero value, the packet
    637    1.2    itojun 		 * must be discarded, else it may be accepted below.
    638    1.2    itojun 		 */
    639  1.169     ozaki 		if (ip6_mrouter != NULL) {
    640  1.169     ozaki 			int error;
    641  1.169     ozaki 
    642  1.169     ozaki 			SOFTNET_LOCK();
    643  1.169     ozaki 			error = ip6_mforward(ip6, rcvif, m);
    644  1.169     ozaki 			SOFTNET_UNLOCK();
    645  1.169     ozaki 
    646  1.169     ozaki 			if (error != 0) {
    647  1.171     ozaki 				rtcache_unref(rt, ro);
    648  1.171     ozaki 				percpu_putref(ip6_forward_rt_percpu);
    649  1.169     ozaki 				IP6_STATINC(IP6_STAT_CANTFORWARD);
    650  1.170     ozaki 				goto bad;
    651  1.169     ozaki 			}
    652    1.2    itojun 		}
    653  1.170     ozaki 		if (!ours)
    654  1.171     ozaki 			goto bad_unref;
    655   1.22    itojun 	} else if (!ours) {
    656  1.171     ozaki 		rtcache_unref(rt, ro);
    657  1.171     ozaki 		percpu_putref(ip6_forward_rt_percpu);
    658   1.64    itojun 		ip6_forward(m, srcrt);
    659    1.2    itojun 		return;
    660   1.56    itojun 	}
    661   1.25    itojun 
    662   1.25    itojun 	ip6 = mtod(m, struct ip6_hdr *);
    663   1.25    itojun 
    664   1.25    itojun 	/*
    665   1.25    itojun 	 * Malicious party may be able to use IPv4 mapped addr to confuse
    666   1.25    itojun 	 * tcp/udp stack and bypass security checks (act as if it was from
    667   1.25    itojun 	 * 127.0.0.1 by using IPv6 src ::ffff:127.0.0.1).  Be cautious.
    668   1.25    itojun 	 *
    669   1.25    itojun 	 * For SIIT end node behavior, you may want to disable the check.
    670   1.25    itojun 	 * However, you will  become vulnerable to attacks using IPv4 mapped
    671   1.25    itojun 	 * source.
    672   1.25    itojun 	 */
    673   1.25    itojun 	if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
    674   1.25    itojun 	    IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
    675  1.116   thorpej 		IP6_STATINC(IP6_STAT_BADSCOPE);
    676  1.159     ozaki 		in6_ifstat_inc(rcvif, ifs6_in_addrerr);
    677  1.171     ozaki 		goto bad_unref;
    678   1.25    itojun 	}
    679    1.2    itojun 
    680   1.12    itojun #ifdef IFA_STATS
    681   1.28    itojun 	if (deliverifp != NULL) {
    682    1.9    itojun 		struct in6_ifaddr *ia6;
    683  1.165     ozaki 		int s = pserialize_read_enter();
    684    1.9    itojun 		ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);
    685    1.9    itojun 		if (ia6)
    686    1.9    itojun 			ia6->ia_ifa.ifa_data.ifad_inbytes += m->m_pkthdr.len;
    687  1.165     ozaki 		pserialize_read_exit(s);
    688    1.9    itojun 	}
    689    1.9    itojun #endif
    690  1.116   thorpej 	IP6_STATINC(IP6_STAT_DELIVERED);
    691    1.9    itojun 	in6_ifstat_inc(deliverifp, ifs6_in_deliver);
    692    1.2    itojun 	nest = 0;
    693   1.40    itojun 
    694  1.171     ozaki 	if (rt != NULL) {
    695  1.171     ozaki 		rtcache_unref(rt, ro);
    696  1.171     ozaki 		rt = NULL;
    697  1.171     ozaki 	}
    698  1.171     ozaki 	percpu_putref(ip6_forward_rt_percpu);
    699  1.171     ozaki 
    700  1.104      yamt 	rh_present = 0;
    701  1.188      maxv 	frg_present = 0;
    702    1.2    itojun 	while (nxt != IPPROTO_DONE) {
    703    1.2    itojun 		if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
    704  1.116   thorpej 			IP6_STATINC(IP6_STAT_TOOMANYHDR);
    705  1.159     ozaki 			in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
    706    1.2    itojun 			goto bad;
    707    1.2    itojun 		}
    708    1.8    itojun 
    709  1.197      maxv 		M_VERIFY_PACKET(m);
    710  1.197      maxv 
    711    1.8    itojun 		/*
    712    1.8    itojun 		 * protection against faulty packet - there should be
    713    1.8    itojun 		 * more sanity checks in header chain processing.
    714    1.8    itojun 		 */
    715    1.8    itojun 		if (m->m_pkthdr.len < off) {
    716  1.116   thorpej 			IP6_STATINC(IP6_STAT_TOOSHORT);
    717  1.159     ozaki 			in6_ifstat_inc(rcvif, ifs6_in_truncated);
    718    1.8    itojun 			goto bad;
    719    1.8    itojun 		}
    720    1.8    itojun 
    721  1.104      yamt 		if (nxt == IPPROTO_ROUTING) {
    722  1.104      yamt 			if (rh_present++) {
    723  1.159     ozaki 				in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
    724  1.116   thorpej 				IP6_STATINC(IP6_STAT_BADOPTIONS);
    725  1.104      yamt 				goto bad;
    726  1.104      yamt 			}
    727  1.188      maxv 		} else if (nxt == IPPROTO_FRAGMENT) {
    728  1.188      maxv 			if (frg_present++) {
    729  1.188      maxv 				in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
    730  1.188      maxv 				IP6_STATINC(IP6_STAT_BADOPTIONS);
    731  1.188      maxv 				goto bad;
    732  1.188      maxv 			}
    733  1.104      yamt 		}
    734  1.104      yamt 
    735  1.142  christos #ifdef IPSEC
    736  1.146  christos 		if (ipsec_used) {
    737   1.94  degroote 			/*
    738  1.186      maxv 			 * Enforce IPsec policy checking if we are seeing last
    739  1.186      maxv 			 * header. Note that we do not visit this with
    740  1.146  christos 			 * protocols with pcb layer code - like udp/tcp/raw ip.
    741   1.94  degroote 			 */
    742  1.206      maxv 			if ((inet6sw[ip6_protox[nxt]].pr_flags
    743  1.146  christos 			    & PR_LASTHDR) != 0) {
    744  1.169     ozaki 				int error;
    745  1.169     ozaki 
    746  1.202      maxv 				error = ipsec_ip_input(m, false);
    747  1.146  christos 				if (error)
    748  1.146  christos 					goto bad;
    749  1.146  christos 			}
    750   1.94  degroote 		}
    751  1.186      maxv #endif
    752   1.94  degroote 
    753    1.2    itojun 		nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
    754    1.2    itojun 	}
    755    1.2    itojun 	return;
    756  1.171     ozaki 
    757  1.186      maxv bad_unref:
    758  1.171     ozaki 	rtcache_unref(rt, ro);
    759  1.171     ozaki 	percpu_putref(ip6_forward_rt_percpu);
    760  1.186      maxv bad:
    761    1.2    itojun 	m_freem(m);
    762  1.171     ozaki 	return;
    763    1.2    itojun }
    764    1.2    itojun 
    765  1.199      maxv static bool
    766  1.199      maxv ip6_badaddr(struct ip6_hdr *ip6)
    767  1.199      maxv {
    768  1.199      maxv 	/* Check against address spoofing/corruption. */
    769  1.199      maxv 	if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_src) ||
    770  1.199      maxv 	    IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_dst)) {
    771  1.199      maxv 		return true;
    772  1.199      maxv 	}
    773  1.199      maxv 
    774  1.199      maxv 	/*
    775  1.199      maxv 	 * The following check is not documented in specs.  A malicious
    776  1.199      maxv 	 * party may be able to use IPv4 mapped addr to confuse tcp/udp stack
    777  1.199      maxv 	 * and bypass security checks (act as if it was from 127.0.0.1 by using
    778  1.199      maxv 	 * IPv6 src ::ffff:127.0.0.1).  Be cautious.
    779  1.199      maxv 	 *
    780  1.199      maxv 	 * This check chokes if we are in an SIIT cloud.  As none of BSDs
    781  1.199      maxv 	 * support IPv4-less kernel compilation, we cannot support SIIT
    782  1.199      maxv 	 * environment at all.  So, it makes more sense for us to reject any
    783  1.199      maxv 	 * malicious packets for non-SIIT environment, than try to do a
    784  1.199      maxv 	 * partial support for SIIT environment.
    785  1.199      maxv 	 */
    786  1.199      maxv 	if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
    787  1.199      maxv 	    IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
    788  1.199      maxv 		return true;
    789  1.199      maxv 	}
    790  1.199      maxv 
    791  1.199      maxv 	/*
    792  1.199      maxv 	 * Reject packets with IPv4-compatible IPv6 addresses (RFC4291).
    793  1.199      maxv 	 */
    794  1.199      maxv 	if (IN6_IS_ADDR_V4COMPAT(&ip6->ip6_src) ||
    795  1.199      maxv 	    IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) {
    796  1.199      maxv 		return true;
    797  1.199      maxv 	}
    798  1.199      maxv 
    799  1.199      maxv 	return false;
    800  1.199      maxv }
    801  1.199      maxv 
    802    1.2    itojun /*
    803   1.81    rpaulo  * set/grab in6_ifaddr correspond to IPv6 destination address.
    804   1.81    rpaulo  */
    805   1.81    rpaulo static struct m_tag *
    806  1.112    dyoung ip6_setdstifaddr(struct mbuf *m, const struct in6_ifaddr *ia)
    807   1.81    rpaulo {
    808   1.81    rpaulo 	struct m_tag *mtag;
    809  1.144  christos 	struct ip6aux *ip6a;
    810   1.81    rpaulo 
    811   1.81    rpaulo 	mtag = ip6_addaux(m);
    812  1.144  christos 	if (mtag == NULL)
    813  1.144  christos 		return NULL;
    814  1.112    dyoung 
    815  1.144  christos 	ip6a = (struct ip6aux *)(mtag + 1);
    816  1.144  christos 	if (in6_setscope(&ip6a->ip6a_src, ia->ia_ifp, &ip6a->ip6a_scope_id)) {
    817  1.144  christos 		IP6_STATINC(IP6_STAT_BADSCOPE);
    818  1.144  christos 		return NULL;
    819  1.112    dyoung 	}
    820  1.144  christos 
    821  1.144  christos 	ip6a->ip6a_src = ia->ia_addr.sin6_addr;
    822  1.144  christos 	ip6a->ip6a_flags = ia->ia6_flags;
    823  1.144  christos 	return mtag;
    824   1.81    rpaulo }
    825   1.81    rpaulo 
    826  1.112    dyoung const struct ip6aux *
    827  1.107  christos ip6_getdstifaddr(struct mbuf *m)
    828   1.81    rpaulo {
    829   1.81    rpaulo 	struct m_tag *mtag;
    830   1.81    rpaulo 
    831   1.81    rpaulo 	mtag = ip6_findaux(m);
    832  1.112    dyoung 	if (mtag != NULL)
    833  1.112    dyoung 		return (struct ip6aux *)(mtag + 1);
    834   1.81    rpaulo 	else
    835   1.81    rpaulo 		return NULL;
    836   1.81    rpaulo }
    837   1.81    rpaulo 
    838   1.81    rpaulo /*
    839    1.2    itojun  * Hop-by-Hop options header processing. If a valid jumbo payload option is
    840    1.2    itojun  * included, the real payload length will be stored in plenp.
    841  1.107  christos  *
    842  1.107  christos  * rtalertp - XXX: should be stored more smart way
    843    1.2    itojun  */
    844  1.136  drochner int
    845  1.107  christos ip6_hopopts_input(u_int32_t *plenp, u_int32_t *rtalertp,
    846  1.107  christos 	struct mbuf **mp, int *offp)
    847    1.2    itojun {
    848   1.35    itojun 	struct mbuf *m = *mp;
    849    1.2    itojun 	int off = *offp, hbhlen;
    850    1.2    itojun 	struct ip6_hbh *hbh;
    851    1.2    itojun 
    852    1.2    itojun 	/* validation of the length of the header */
    853    1.9    itojun 	IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m,
    854  1.189      maxv 	    sizeof(struct ip6_hdr), sizeof(struct ip6_hbh));
    855    1.9    itojun 	if (hbh == NULL) {
    856  1.116   thorpej 		IP6_STATINC(IP6_STAT_TOOSHORT);
    857    1.9    itojun 		return -1;
    858    1.9    itojun 	}
    859    1.9    itojun 	hbhlen = (hbh->ip6h_len + 1) << 3;
    860    1.9    itojun 	IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
    861  1.189      maxv 	    hbhlen);
    862    1.9    itojun 	if (hbh == NULL) {
    863  1.116   thorpej 		IP6_STATINC(IP6_STAT_TOOSHORT);
    864    1.9    itojun 		return -1;
    865    1.9    itojun 	}
    866   1.57   thorpej 	KASSERT(IP6_HDR_ALIGNED_P(hbh));
    867    1.2    itojun 	off += hbhlen;
    868    1.2    itojun 	hbhlen -= sizeof(struct ip6_hbh);
    869    1.2    itojun 
    870    1.2    itojun 	if (ip6_process_hopopts(m, (u_int8_t *)hbh + sizeof(struct ip6_hbh),
    871  1.189      maxv 	    hbhlen, rtalertp, plenp) < 0)
    872  1.189      maxv 		return -1;
    873    1.2    itojun 
    874    1.2    itojun 	*offp = off;
    875    1.2    itojun 	*mp = m;
    876  1.189      maxv 	return 0;
    877    1.2    itojun }
    878    1.2    itojun 
    879    1.2    itojun /*
    880    1.2    itojun  * Search header for all Hop-by-hop options and process each option.
    881    1.2    itojun  * This function is separate from ip6_hopopts_input() in order to
    882    1.2    itojun  * handle a case where the sending node itself process its hop-by-hop
    883    1.2    itojun  * options header. In such a case, the function is called from ip6_output().
    884   1.55    itojun  *
    885   1.55    itojun  * The function assumes that hbh header is located right after the IPv6 header
    886   1.55    itojun  * (RFC2460 p7), opthead is pointer into data content in m, and opthead to
    887   1.55    itojun  * opthead + hbhlen is located in continuous memory region.
    888    1.2    itojun  */
    889  1.136  drochner static int
    890  1.107  christos ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen,
    891  1.107  christos 	u_int32_t *rtalertp, u_int32_t *plenp)
    892    1.2    itojun {
    893    1.2    itojun 	struct ip6_hdr *ip6;
    894    1.2    itojun 	int optlen = 0;
    895    1.2    itojun 	u_int8_t *opt = opthead;
    896    1.2    itojun 	u_int16_t rtalert_val;
    897   1.22    itojun 	u_int32_t jumboplen;
    898   1.55    itojun 	const int erroff = sizeof(struct ip6_hdr) + sizeof(struct ip6_hbh);
    899    1.2    itojun 
    900    1.2    itojun 	for (; hbhlen > 0; hbhlen -= optlen, opt += optlen) {
    901   1.35    itojun 		switch (*opt) {
    902   1.35    itojun 		case IP6OPT_PAD1:
    903   1.35    itojun 			optlen = 1;
    904   1.35    itojun 			break;
    905   1.35    itojun 		case IP6OPT_PADN:
    906   1.35    itojun 			if (hbhlen < IP6OPT_MINLEN) {
    907  1.116   thorpej 				IP6_STATINC(IP6_STAT_TOOSMALL);
    908   1.35    itojun 				goto bad;
    909   1.35    itojun 			}
    910   1.35    itojun 			optlen = *(opt + 1) + 2;
    911   1.35    itojun 			break;
    912   1.35    itojun 		case IP6OPT_RTALERT:
    913   1.35    itojun 			/* XXX may need check for alignment */
    914   1.35    itojun 			if (hbhlen < IP6OPT_RTALERT_LEN) {
    915  1.116   thorpej 				IP6_STATINC(IP6_STAT_TOOSMALL);
    916   1.35    itojun 				goto bad;
    917   1.35    itojun 			}
    918   1.35    itojun 			if (*(opt + 1) != IP6OPT_RTALERT_LEN - 2) {
    919   1.55    itojun 				/* XXX stat */
    920   1.55    itojun 				icmp6_error(m, ICMP6_PARAM_PROB,
    921   1.55    itojun 				    ICMP6_PARAMPROB_HEADER,
    922   1.55    itojun 				    erroff + opt + 1 - opthead);
    923   1.55    itojun 				return (-1);
    924   1.35    itojun 			}
    925   1.35    itojun 			optlen = IP6OPT_RTALERT_LEN;
    926  1.126   tsutsui 			memcpy((void *)&rtalert_val, (void *)(opt + 2), 2);
    927   1.35    itojun 			*rtalertp = ntohs(rtalert_val);
    928   1.35    itojun 			break;
    929   1.35    itojun 		case IP6OPT_JUMBO:
    930   1.22    itojun 			/* XXX may need check for alignment */
    931   1.22    itojun 			if (hbhlen < IP6OPT_JUMBO_LEN) {
    932  1.116   thorpej 				IP6_STATINC(IP6_STAT_TOOSMALL);
    933   1.22    itojun 				goto bad;
    934   1.22    itojun 			}
    935   1.35    itojun 			if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) {
    936   1.55    itojun 				/* XXX stat */
    937   1.55    itojun 				icmp6_error(m, ICMP6_PARAM_PROB,
    938   1.55    itojun 				    ICMP6_PARAMPROB_HEADER,
    939   1.55    itojun 				    erroff + opt + 1 - opthead);
    940   1.55    itojun 				return (-1);
    941   1.35    itojun 			}
    942   1.22    itojun 			optlen = IP6OPT_JUMBO_LEN;
    943   1.22    itojun 
    944   1.22    itojun 			/*
    945   1.22    itojun 			 * IPv6 packets that have non 0 payload length
    946   1.35    itojun 			 * must not contain a jumbo payload option.
    947   1.22    itojun 			 */
    948   1.22    itojun 			ip6 = mtod(m, struct ip6_hdr *);
    949   1.22    itojun 			if (ip6->ip6_plen) {
    950  1.116   thorpej 				IP6_STATINC(IP6_STAT_BADOPTIONS);
    951   1.22    itojun 				icmp6_error(m, ICMP6_PARAM_PROB,
    952   1.55    itojun 				    ICMP6_PARAMPROB_HEADER,
    953   1.55    itojun 				    erroff + opt - opthead);
    954   1.55    itojun 				return (-1);
    955   1.22    itojun 			}
    956    1.2    itojun 
    957   1.22    itojun 			/*
    958   1.22    itojun 			 * We may see jumbolen in unaligned location, so
    959  1.191      maxv 			 * we'd need to perform memcpy().
    960   1.22    itojun 			 */
    961  1.126   tsutsui 			memcpy(&jumboplen, opt + 2, sizeof(jumboplen));
    962   1.22    itojun 			jumboplen = (u_int32_t)htonl(jumboplen);
    963   1.22    itojun 
    964   1.22    itojun #if 1
    965   1.22    itojun 			/*
    966   1.22    itojun 			 * if there are multiple jumbo payload options,
    967   1.22    itojun 			 * *plenp will be non-zero and the packet will be
    968   1.22    itojun 			 * rejected.
    969   1.22    itojun 			 * the behavior may need some debate in ipngwg -
    970   1.22    itojun 			 * multiple options does not make sense, however,
    971   1.22    itojun 			 * there's no explicit mention in specification.
    972   1.22    itojun 			 */
    973   1.22    itojun 			if (*plenp != 0) {
    974  1.116   thorpej 				IP6_STATINC(IP6_STAT_BADOPTIONS);
    975   1.22    itojun 				icmp6_error(m, ICMP6_PARAM_PROB,
    976   1.55    itojun 				    ICMP6_PARAMPROB_HEADER,
    977   1.55    itojun 				    erroff + opt + 2 - opthead);
    978   1.55    itojun 				return (-1);
    979   1.22    itojun 			}
    980    1.8    itojun #endif
    981    1.2    itojun 
    982   1.22    itojun 			/*
    983   1.22    itojun 			 * jumbo payload length must be larger than 65535.
    984   1.22    itojun 			 */
    985   1.22    itojun 			if (jumboplen <= IPV6_MAXPACKET) {
    986  1.116   thorpej 				IP6_STATINC(IP6_STAT_BADOPTIONS);
    987   1.22    itojun 				icmp6_error(m, ICMP6_PARAM_PROB,
    988   1.55    itojun 				    ICMP6_PARAMPROB_HEADER,
    989   1.55    itojun 				    erroff + opt + 2 - opthead);
    990   1.55    itojun 				return (-1);
    991   1.22    itojun 			}
    992   1.22    itojun 			*plenp = jumboplen;
    993   1.22    itojun 
    994   1.22    itojun 			break;
    995   1.35    itojun 		default:		/* unknown option */
    996   1.35    itojun 			if (hbhlen < IP6OPT_MINLEN) {
    997  1.116   thorpej 				IP6_STATINC(IP6_STAT_TOOSMALL);
    998   1.35    itojun 				goto bad;
    999   1.35    itojun 			}
   1000   1.55    itojun 			optlen = ip6_unknown_opt(opt, m,
   1001   1.55    itojun 			    erroff + opt - opthead);
   1002   1.55    itojun 			if (optlen == -1)
   1003   1.55    itojun 				return (-1);
   1004   1.35    itojun 			optlen += 2;
   1005   1.35    itojun 			break;
   1006    1.2    itojun 		}
   1007    1.2    itojun 	}
   1008    1.2    itojun 
   1009   1.55    itojun 	return (0);
   1010    1.2    itojun 
   1011    1.2    itojun   bad:
   1012    1.2    itojun 	m_freem(m);
   1013   1.55    itojun 	return (-1);
   1014    1.2    itojun }
   1015    1.2    itojun 
   1016    1.2    itojun /*
   1017    1.2    itojun  * Unknown option processing.
   1018    1.2    itojun  * The third argument `off' is the offset from the IPv6 header to the option,
   1019    1.2    itojun  * which is necessary if the IPv6 header the and option header and IPv6 header
   1020    1.2    itojun  * is not continuous in order to return an ICMPv6 error.
   1021    1.2    itojun  */
   1022    1.2    itojun int
   1023  1.107  christos ip6_unknown_opt(u_int8_t *optp, struct mbuf *m, int off)
   1024    1.2    itojun {
   1025    1.2    itojun 	struct ip6_hdr *ip6;
   1026    1.2    itojun 
   1027   1.35    itojun 	switch (IP6OPT_TYPE(*optp)) {
   1028   1.35    itojun 	case IP6OPT_TYPE_SKIP: /* ignore the option */
   1029   1.58    itojun 		return ((int)*(optp + 1));
   1030   1.35    itojun 	case IP6OPT_TYPE_DISCARD:	/* silently discard */
   1031   1.35    itojun 		m_freem(m);
   1032   1.58    itojun 		return (-1);
   1033   1.35    itojun 	case IP6OPT_TYPE_FORCEICMP: /* send ICMP even if multicasted */
   1034  1.116   thorpej 		IP6_STATINC(IP6_STAT_BADOPTIONS);
   1035   1.35    itojun 		icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, off);
   1036   1.58    itojun 		return (-1);
   1037   1.35    itojun 	case IP6OPT_TYPE_ICMP: /* send ICMP if not multicasted */
   1038  1.116   thorpej 		IP6_STATINC(IP6_STAT_BADOPTIONS);
   1039   1.35    itojun 		ip6 = mtod(m, struct ip6_hdr *);
   1040   1.35    itojun 		if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
   1041   1.35    itojun 		    (m->m_flags & (M_BCAST|M_MCAST)))
   1042   1.35    itojun 			m_freem(m);
   1043   1.35    itojun 		else
   1044   1.35    itojun 			icmp6_error(m, ICMP6_PARAM_PROB,
   1045   1.35    itojun 				    ICMP6_PARAMPROB_OPTION, off);
   1046   1.58    itojun 		return (-1);
   1047    1.2    itojun 	}
   1048    1.2    itojun 
   1049    1.2    itojun 	m_freem(m);		/* XXX: NOTREACHED */
   1050   1.58    itojun 	return (-1);
   1051    1.2    itojun }
   1052    1.2    itojun 
   1053    1.2    itojun void
   1054  1.107  christos ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp,
   1055  1.107  christos 	struct ip6_hdr *ip6, struct mbuf *m)
   1056    1.2    itojun {
   1057  1.179  christos 	struct socket *so = in6p->in6p_socket;
   1058   1.85    rpaulo #ifdef RFC2292
   1059   1.85    rpaulo #define IS2292(x, y)	((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y))
   1060   1.85    rpaulo #else
   1061   1.85    rpaulo #define IS2292(x, y)	(y)
   1062   1.85    rpaulo #endif
   1063   1.85    rpaulo 
   1064  1.179  christos 	if (SOOPT_TIMESTAMP(so->so_options))
   1065  1.200      maxv 		mp = sbsavetimestamp(so->so_options, mp);
   1066   1.87    rpaulo 
   1067   1.87    rpaulo 	/* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */
   1068   1.87    rpaulo 	if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION)
   1069   1.87    rpaulo 		return;
   1070   1.87    rpaulo 
   1071    1.2    itojun 	/* RFC 2292 sec. 5 */
   1072   1.35    itojun 	if ((in6p->in6p_flags & IN6P_PKTINFO) != 0) {
   1073    1.2    itojun 		struct in6_pktinfo pi6;
   1074   1.85    rpaulo 
   1075  1.126   tsutsui 		memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr));
   1076   1.81    rpaulo 		in6_clearscope(&pi6.ipi6_addr);	/* XXX */
   1077  1.160     ozaki 		pi6.ipi6_ifindex = m->m_pkthdr.rcvif_index;
   1078  1.180  christos 		*mp = sbcreatecontrol(&pi6, sizeof(pi6),
   1079   1.85    rpaulo 		    IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6);
   1080    1.2    itojun 		if (*mp)
   1081    1.2    itojun 			mp = &(*mp)->m_next;
   1082    1.2    itojun 	}
   1083   1.85    rpaulo 
   1084    1.2    itojun 	if (in6p->in6p_flags & IN6P_HOPLIMIT) {
   1085    1.2    itojun 		int hlim = ip6->ip6_hlim & 0xff;
   1086   1.85    rpaulo 
   1087  1.180  christos 		*mp = sbcreatecontrol(&hlim, sizeof(hlim),
   1088   1.85    rpaulo 		    IS2292(IPV6_2292HOPLIMIT, IPV6_HOPLIMIT), IPPROTO_IPV6);
   1089   1.85    rpaulo 		if (*mp)
   1090   1.85    rpaulo 			mp = &(*mp)->m_next;
   1091   1.85    rpaulo 	}
   1092   1.85    rpaulo 
   1093   1.85    rpaulo 	if ((in6p->in6p_flags & IN6P_TCLASS) != 0) {
   1094   1.85    rpaulo 		u_int32_t flowinfo;
   1095   1.85    rpaulo 		int tclass;
   1096   1.85    rpaulo 
   1097   1.85    rpaulo 		flowinfo = (u_int32_t)ntohl(ip6->ip6_flow & IPV6_FLOWINFO_MASK);
   1098   1.85    rpaulo 		flowinfo >>= 20;
   1099   1.85    rpaulo 
   1100   1.85    rpaulo 		tclass = flowinfo & 0xff;
   1101  1.180  christos 		*mp = sbcreatecontrol(&tclass, sizeof(tclass),
   1102   1.85    rpaulo 		    IPV6_TCLASS, IPPROTO_IPV6);
   1103   1.85    rpaulo 
   1104    1.2    itojun 		if (*mp)
   1105    1.2    itojun 			mp = &(*mp)->m_next;
   1106    1.2    itojun 	}
   1107    1.2    itojun 
   1108    1.2    itojun 	/*
   1109   1.75    itojun 	 * IPV6_HOPOPTS socket option.  Recall that we required super-user
   1110   1.75    itojun 	 * privilege for the option (see ip6_ctloutput), but it might be too
   1111   1.75    itojun 	 * strict, since there might be some hop-by-hop options which can be
   1112   1.75    itojun 	 * returned to normal user.
   1113   1.85    rpaulo 	 * See also RFC3542 section 8 (or RFC2292 section 6).
   1114    1.2    itojun 	 */
   1115   1.75    itojun 	if ((in6p->in6p_flags & IN6P_HOPOPTS) != 0) {
   1116    1.2    itojun 		/*
   1117    1.2    itojun 		 * Check if a hop-by-hop options header is contatined in the
   1118    1.2    itojun 		 * received packet, and if so, store the options as ancillary
   1119    1.2    itojun 		 * data. Note that a hop-by-hop options header must be
   1120    1.2    itojun 		 * just after the IPv6 header, which fact is assured through
   1121    1.2    itojun 		 * the IPv6 input processing.
   1122    1.2    itojun 		 */
   1123   1.78  christos 		struct ip6_hdr *xip6 = mtod(m, struct ip6_hdr *);
   1124   1.78  christos 		if (xip6->ip6_nxt == IPPROTO_HOPOPTS) {
   1125    1.9    itojun 			struct ip6_hbh *hbh;
   1126    1.9    itojun 			int hbhlen;
   1127   1.62    itojun 			struct mbuf *ext;
   1128    1.9    itojun 
   1129   1.62    itojun 			ext = ip6_pullexthdr(m, sizeof(struct ip6_hdr),
   1130   1.78  christos 			    xip6->ip6_nxt);
   1131   1.62    itojun 			if (ext == NULL) {
   1132  1.116   thorpej 				IP6_STATINC(IP6_STAT_TOOSHORT);
   1133    1.9    itojun 				return;
   1134    1.9    itojun 			}
   1135   1.62    itojun 			hbh = mtod(ext, struct ip6_hbh *);
   1136    1.9    itojun 			hbhlen = (hbh->ip6h_len + 1) << 3;
   1137   1.62    itojun 			if (hbhlen != ext->m_len) {
   1138   1.62    itojun 				m_freem(ext);
   1139  1.116   thorpej 				IP6_STATINC(IP6_STAT_TOOSHORT);
   1140    1.9    itojun 				return;
   1141    1.9    itojun 			}
   1142    1.2    itojun 
   1143    1.2    itojun 			/*
   1144    1.2    itojun 			 * XXX: We copy whole the header even if a jumbo
   1145    1.2    itojun 			 * payload option is included, which option is to
   1146    1.2    itojun 			 * be removed before returning in the RFC 2292.
   1147   1.85    rpaulo 			 * Note: this constraint is removed in RFC3542.
   1148    1.2    itojun 			 */
   1149  1.180  christos 			*mp = sbcreatecontrol(hbh, hbhlen,
   1150   1.85    rpaulo 			    IS2292(IPV6_2292HOPOPTS, IPV6_HOPOPTS),
   1151   1.85    rpaulo 			    IPPROTO_IPV6);
   1152    1.2    itojun 			if (*mp)
   1153    1.2    itojun 				mp = &(*mp)->m_next;
   1154   1.62    itojun 			m_freem(ext);
   1155    1.2    itojun 		}
   1156    1.2    itojun 	}
   1157    1.2    itojun 
   1158    1.2    itojun 	/* IPV6_DSTOPTS and IPV6_RTHDR socket options */
   1159    1.2    itojun 	if (in6p->in6p_flags & (IN6P_DSTOPTS | IN6P_RTHDR)) {
   1160   1.78  christos 		struct ip6_hdr *xip6 = mtod(m, struct ip6_hdr *);
   1161   1.78  christos 		int nxt = xip6->ip6_nxt, off = sizeof(struct ip6_hdr);
   1162    1.2    itojun 
   1163    1.2    itojun 		/*
   1164    1.2    itojun 		 * Search for destination options headers or routing
   1165    1.2    itojun 		 * header(s) through the header chain, and stores each
   1166    1.2    itojun 		 * header as ancillary data.
   1167    1.2    itojun 		 * Note that the order of the headers remains in
   1168    1.2    itojun 		 * the chain of ancillary data.
   1169    1.2    itojun 		 */
   1170   1.86    rpaulo 		for (;;) {	/* is explicit loop prevention necessary? */
   1171   1.62    itojun 			struct ip6_ext *ip6e = NULL;
   1172    1.9    itojun 			int elen;
   1173   1.62    itojun 			struct mbuf *ext = NULL;
   1174    1.9    itojun 
   1175   1.62    itojun 			/*
   1176   1.62    itojun 			 * if it is not an extension header, don't try to
   1177   1.62    itojun 			 * pull it from the chain.
   1178   1.62    itojun 			 */
   1179   1.62    itojun 			switch (nxt) {
   1180   1.62    itojun 			case IPPROTO_DSTOPTS:
   1181   1.62    itojun 			case IPPROTO_ROUTING:
   1182   1.62    itojun 			case IPPROTO_HOPOPTS:
   1183   1.62    itojun 			case IPPROTO_AH: /* is it possible? */
   1184   1.62    itojun 				break;
   1185   1.62    itojun 			default:
   1186   1.62    itojun 				goto loopend;
   1187   1.62    itojun 			}
   1188   1.62    itojun 
   1189   1.62    itojun 			ext = ip6_pullexthdr(m, off, nxt);
   1190   1.62    itojun 			if (ext == NULL) {
   1191  1.116   thorpej 				IP6_STATINC(IP6_STAT_TOOSHORT);
   1192    1.9    itojun 				return;
   1193    1.9    itojun 			}
   1194   1.62    itojun 			ip6e = mtod(ext, struct ip6_ext *);
   1195    1.9    itojun 			if (nxt == IPPROTO_AH)
   1196    1.9    itojun 				elen = (ip6e->ip6e_len + 2) << 2;
   1197    1.9    itojun 			else
   1198    1.9    itojun 				elen = (ip6e->ip6e_len + 1) << 3;
   1199   1.62    itojun 			if (elen != ext->m_len) {
   1200   1.62    itojun 				m_freem(ext);
   1201  1.116   thorpej 				IP6_STATINC(IP6_STAT_TOOSHORT);
   1202    1.9    itojun 				return;
   1203    1.9    itojun 			}
   1204   1.57   thorpej 			KASSERT(IP6_HDR_ALIGNED_P(ip6e));
   1205    1.2    itojun 
   1206   1.35    itojun 			switch (nxt) {
   1207   1.62    itojun 			case IPPROTO_DSTOPTS:
   1208  1.127    martin 				if (!(in6p->in6p_flags & IN6P_DSTOPTS))
   1209   1.35    itojun 					break;
   1210   1.35    itojun 
   1211  1.180  christos 				*mp = sbcreatecontrol(ip6e, elen,
   1212   1.85    rpaulo 				    IS2292(IPV6_2292DSTOPTS, IPV6_DSTOPTS),
   1213   1.85    rpaulo 				    IPPROTO_IPV6);
   1214   1.35    itojun 				if (*mp)
   1215   1.35    itojun 					mp = &(*mp)->m_next;
   1216   1.35    itojun 				break;
   1217   1.35    itojun 
   1218   1.35    itojun 			case IPPROTO_ROUTING:
   1219  1.127    martin 				if (!(in6p->in6p_flags & IN6P_RTHDR))
   1220   1.35    itojun 					break;
   1221   1.35    itojun 
   1222  1.180  christos 				*mp = sbcreatecontrol(ip6e, elen,
   1223   1.85    rpaulo 				    IS2292(IPV6_2292RTHDR, IPV6_RTHDR),
   1224   1.85    rpaulo 				    IPPROTO_IPV6);
   1225   1.35    itojun 				if (*mp)
   1226   1.35    itojun 					mp = &(*mp)->m_next;
   1227   1.35    itojun 				break;
   1228   1.35    itojun 
   1229   1.62    itojun 			case IPPROTO_HOPOPTS:
   1230   1.62    itojun 			case IPPROTO_AH: /* is it possible? */
   1231   1.62    itojun 				break;
   1232   1.62    itojun 
   1233   1.35    itojun 			default:
   1234   1.35    itojun 				/*
   1235   1.62    itojun 			 	 * other cases have been filtered in the above.
   1236   1.62    itojun 				 * none will visit this case.  here we supply
   1237   1.62    itojun 				 * the code just in case (nxt overwritten or
   1238   1.62    itojun 				 * other cases).
   1239   1.35    itojun 				 */
   1240   1.62    itojun 				m_freem(ext);
   1241   1.35    itojun 				goto loopend;
   1242   1.35    itojun 
   1243    1.2    itojun 			}
   1244    1.2    itojun 
   1245    1.2    itojun 			/* proceed with the next header. */
   1246    1.9    itojun 			off += elen;
   1247    1.2    itojun 			nxt = ip6e->ip6e_nxt;
   1248   1.62    itojun 			ip6e = NULL;
   1249   1.62    itojun 			m_freem(ext);
   1250   1.62    itojun 			ext = NULL;
   1251    1.2    itojun 		}
   1252    1.2    itojun 	  loopend:
   1253   1.62    itojun 	  	;
   1254    1.2    itojun 	}
   1255   1.62    itojun }
   1256   1.85    rpaulo #undef IS2292
   1257   1.85    rpaulo 
   1258   1.85    rpaulo 
   1259   1.85    rpaulo void
   1260   1.95    dyoung ip6_notify_pmtu(struct in6pcb *in6p, const struct sockaddr_in6 *dst,
   1261   1.95    dyoung     uint32_t *mtu)
   1262   1.85    rpaulo {
   1263   1.85    rpaulo 	struct socket *so;
   1264   1.85    rpaulo 	struct mbuf *m_mtu;
   1265   1.85    rpaulo 	struct ip6_mtuinfo mtuctl;
   1266   1.85    rpaulo 
   1267   1.85    rpaulo 	so = in6p->in6p_socket;
   1268   1.85    rpaulo 
   1269   1.85    rpaulo 	if (mtu == NULL)
   1270   1.85    rpaulo 		return;
   1271   1.85    rpaulo 
   1272  1.177     ozaki 	KASSERT(so != NULL);
   1273   1.85    rpaulo 
   1274   1.85    rpaulo 	memset(&mtuctl, 0, sizeof(mtuctl));	/* zero-clear for safety */
   1275   1.85    rpaulo 	mtuctl.ip6m_mtu = *mtu;
   1276   1.85    rpaulo 	mtuctl.ip6m_addr = *dst;
   1277   1.85    rpaulo 	if (sa6_recoverscope(&mtuctl.ip6m_addr))
   1278   1.85    rpaulo 		return;
   1279   1.85    rpaulo 
   1280  1.180  christos 	if ((m_mtu = sbcreatecontrol(&mtuctl, sizeof(mtuctl),
   1281   1.85    rpaulo 	    IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)
   1282   1.85    rpaulo 		return;
   1283   1.85    rpaulo 
   1284   1.95    dyoung 	if (sbappendaddr(&so->so_rcv, (const struct sockaddr *)dst, NULL, m_mtu)
   1285   1.85    rpaulo 	    == 0) {
   1286  1.195       roy 		soroverflow(so);
   1287   1.85    rpaulo 		m_freem(m_mtu);
   1288   1.85    rpaulo 	} else
   1289   1.85    rpaulo 		sorwakeup(so);
   1290   1.85    rpaulo 
   1291   1.85    rpaulo 	return;
   1292   1.85    rpaulo }
   1293   1.62    itojun 
   1294   1.62    itojun /*
   1295   1.62    itojun  * pull single extension header from mbuf chain.  returns single mbuf that
   1296   1.62    itojun  * contains the result, or NULL on error.
   1297   1.62    itojun  */
   1298   1.62    itojun static struct mbuf *
   1299  1.107  christos ip6_pullexthdr(struct mbuf *m, size_t off, int nxt)
   1300   1.62    itojun {
   1301   1.62    itojun 	struct ip6_ext ip6e;
   1302   1.62    itojun 	size_t elen;
   1303   1.62    itojun 	struct mbuf *n;
   1304   1.62    itojun 
   1305   1.97  christos 	m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
   1306   1.62    itojun 	if (nxt == IPPROTO_AH)
   1307   1.62    itojun 		elen = (ip6e.ip6e_len + 2) << 2;
   1308   1.62    itojun 	else
   1309   1.62    itojun 		elen = (ip6e.ip6e_len + 1) << 3;
   1310   1.62    itojun 
   1311   1.62    itojun 	MGET(n, M_DONTWAIT, MT_DATA);
   1312   1.62    itojun 	if (n && elen >= MLEN) {
   1313   1.62    itojun 		MCLGET(n, M_DONTWAIT);
   1314   1.62    itojun 		if ((n->m_flags & M_EXT) == 0) {
   1315   1.62    itojun 			m_free(n);
   1316   1.62    itojun 			n = NULL;
   1317   1.62    itojun 		}
   1318   1.62    itojun 	}
   1319   1.62    itojun 	if (!n)
   1320   1.62    itojun 		return NULL;
   1321   1.62    itojun 
   1322   1.62    itojun 	n->m_len = 0;
   1323   1.62    itojun 	if (elen >= M_TRAILINGSPACE(n)) {
   1324   1.62    itojun 		m_free(n);
   1325   1.62    itojun 		return NULL;
   1326   1.62    itojun 	}
   1327   1.62    itojun 
   1328   1.97  christos 	m_copydata(m, off, elen, mtod(n, void *));
   1329   1.62    itojun 	n->m_len = elen;
   1330   1.62    itojun 	return n;
   1331    1.2    itojun }
   1332    1.2    itojun 
   1333    1.2    itojun /*
   1334  1.187      maxv  * Get offset to the previous header followed by the header
   1335    1.2    itojun  * currently processed.
   1336    1.2    itojun  */
   1337  1.187      maxv int
   1338  1.107  christos ip6_get_prevhdr(struct mbuf *m, int off)
   1339    1.2    itojun {
   1340    1.2    itojun 	struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
   1341    1.2    itojun 
   1342  1.187      maxv 	if (off == sizeof(struct ip6_hdr)) {
   1343  1.187      maxv 		return offsetof(struct ip6_hdr, ip6_nxt);
   1344  1.187      maxv 	} else if (off < sizeof(struct ip6_hdr)) {
   1345  1.187      maxv 		panic("%s: off < sizeof(struct ip6_hdr)", __func__);
   1346  1.187      maxv 	} else {
   1347  1.187      maxv 		int len, nlen, nxt;
   1348  1.187      maxv 		struct ip6_ext ip6e;
   1349    1.2    itojun 
   1350    1.2    itojun 		nxt = ip6->ip6_nxt;
   1351    1.2    itojun 		len = sizeof(struct ip6_hdr);
   1352  1.187      maxv 		nlen = 0;
   1353    1.2    itojun 		while (len < off) {
   1354  1.187      maxv 			m_copydata(m, len, sizeof(ip6e), &ip6e);
   1355    1.2    itojun 
   1356   1.35    itojun 			switch (nxt) {
   1357    1.2    itojun 			case IPPROTO_FRAGMENT:
   1358  1.187      maxv 				nlen = sizeof(struct ip6_frag);
   1359    1.2    itojun 				break;
   1360    1.2    itojun 			case IPPROTO_AH:
   1361  1.187      maxv 				nlen = (ip6e.ip6e_len + 2) << 2;
   1362    1.2    itojun 				break;
   1363    1.2    itojun 			default:
   1364  1.187      maxv 				nlen = (ip6e.ip6e_len + 1) << 3;
   1365    1.2    itojun 				break;
   1366    1.2    itojun 			}
   1367  1.187      maxv 			len += nlen;
   1368  1.187      maxv 			nxt = ip6e.ip6e_nxt;
   1369    1.2    itojun 		}
   1370  1.187      maxv 
   1371  1.187      maxv 		return (len - nlen);
   1372   1.18    itojun 	}
   1373   1.18    itojun }
   1374   1.18    itojun 
   1375   1.18    itojun /*
   1376   1.18    itojun  * get next header offset.  m will be retained.
   1377   1.18    itojun  */
   1378  1.192      maxv int
   1379  1.107  christos ip6_nexthdr(struct mbuf *m, int off, int proto, int *nxtp)
   1380   1.18    itojun {
   1381   1.18    itojun 	struct ip6_hdr ip6;
   1382   1.18    itojun 	struct ip6_ext ip6e;
   1383   1.18    itojun 	struct ip6_frag fh;
   1384   1.18    itojun 
   1385   1.18    itojun 	/* just in case */
   1386   1.18    itojun 	if (m == NULL)
   1387  1.189      maxv 		panic("%s: m == NULL", __func__);
   1388   1.18    itojun 	if ((m->m_flags & M_PKTHDR) == 0 || m->m_pkthdr.len < off)
   1389   1.18    itojun 		return -1;
   1390   1.18    itojun 
   1391   1.18    itojun 	switch (proto) {
   1392   1.18    itojun 	case IPPROTO_IPV6:
   1393   1.83    rpaulo 		/* do not chase beyond intermediate IPv6 headers */
   1394   1.83    rpaulo 		if (off != 0)
   1395   1.83    rpaulo 			return -1;
   1396   1.18    itojun 		if (m->m_pkthdr.len < off + sizeof(ip6))
   1397   1.18    itojun 			return -1;
   1398   1.97  christos 		m_copydata(m, off, sizeof(ip6), (void *)&ip6);
   1399   1.18    itojun 		if (nxtp)
   1400   1.18    itojun 			*nxtp = ip6.ip6_nxt;
   1401   1.18    itojun 		off += sizeof(ip6);
   1402   1.18    itojun 		return off;
   1403   1.18    itojun 
   1404   1.18    itojun 	case IPPROTO_FRAGMENT:
   1405   1.18    itojun 		/*
   1406   1.18    itojun 		 * terminate parsing if it is not the first fragment,
   1407   1.18    itojun 		 * it does not make sense to parse through it.
   1408   1.18    itojun 		 */
   1409   1.18    itojun 		if (m->m_pkthdr.len < off + sizeof(fh))
   1410   1.18    itojun 			return -1;
   1411   1.97  christos 		m_copydata(m, off, sizeof(fh), (void *)&fh);
   1412   1.67    itojun 		if ((fh.ip6f_offlg & IP6F_OFF_MASK) != 0)
   1413   1.18    itojun 			return -1;
   1414   1.18    itojun 		if (nxtp)
   1415   1.18    itojun 			*nxtp = fh.ip6f_nxt;
   1416   1.18    itojun 		off += sizeof(struct ip6_frag);
   1417   1.18    itojun 		return off;
   1418   1.18    itojun 
   1419   1.18    itojun 	case IPPROTO_AH:
   1420   1.18    itojun 		if (m->m_pkthdr.len < off + sizeof(ip6e))
   1421   1.18    itojun 			return -1;
   1422   1.97  christos 		m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
   1423   1.18    itojun 		if (nxtp)
   1424   1.18    itojun 			*nxtp = ip6e.ip6e_nxt;
   1425   1.18    itojun 		off += (ip6e.ip6e_len + 2) << 2;
   1426   1.47    itojun 		if (m->m_pkthdr.len < off)
   1427   1.47    itojun 			return -1;
   1428   1.18    itojun 		return off;
   1429   1.18    itojun 
   1430   1.18    itojun 	case IPPROTO_HOPOPTS:
   1431   1.18    itojun 	case IPPROTO_ROUTING:
   1432   1.18    itojun 	case IPPROTO_DSTOPTS:
   1433   1.18    itojun 		if (m->m_pkthdr.len < off + sizeof(ip6e))
   1434   1.18    itojun 			return -1;
   1435   1.97  christos 		m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
   1436   1.18    itojun 		if (nxtp)
   1437   1.18    itojun 			*nxtp = ip6e.ip6e_nxt;
   1438   1.18    itojun 		off += (ip6e.ip6e_len + 1) << 3;
   1439   1.47    itojun 		if (m->m_pkthdr.len < off)
   1440   1.47    itojun 			return -1;
   1441   1.18    itojun 		return off;
   1442   1.18    itojun 
   1443   1.18    itojun 	case IPPROTO_NONE:
   1444   1.18    itojun 	case IPPROTO_ESP:
   1445   1.18    itojun 	case IPPROTO_IPCOMP:
   1446   1.18    itojun 		/* give up */
   1447   1.18    itojun 		return -1;
   1448   1.18    itojun 
   1449   1.18    itojun 	default:
   1450   1.18    itojun 		return -1;
   1451   1.18    itojun 	}
   1452   1.18    itojun }
   1453   1.18    itojun 
   1454   1.18    itojun /*
   1455   1.18    itojun  * get offset for the last header in the chain.  m will be kept untainted.
   1456   1.18    itojun  */
   1457   1.18    itojun int
   1458  1.107  christos ip6_lasthdr(struct mbuf *m, int off, int proto, int *nxtp)
   1459   1.18    itojun {
   1460   1.18    itojun 	int newoff;
   1461   1.18    itojun 	int nxt;
   1462   1.18    itojun 
   1463   1.18    itojun 	if (!nxtp) {
   1464   1.18    itojun 		nxt = -1;
   1465   1.18    itojun 		nxtp = &nxt;
   1466   1.18    itojun 	}
   1467   1.86    rpaulo 	for (;;) {
   1468   1.18    itojun 		newoff = ip6_nexthdr(m, off, proto, nxtp);
   1469   1.18    itojun 		if (newoff < 0)
   1470   1.18    itojun 			return off;
   1471   1.18    itojun 		else if (newoff < off)
   1472   1.18    itojun 			return -1;	/* invalid */
   1473   1.18    itojun 		else if (newoff == off)
   1474   1.18    itojun 			return newoff;
   1475   1.18    itojun 
   1476   1.18    itojun 		off = newoff;
   1477   1.18    itojun 		proto = *nxtp;
   1478    1.2    itojun 	}
   1479    1.2    itojun }
   1480    1.2    itojun 
   1481   1.81    rpaulo struct m_tag *
   1482  1.107  christos ip6_addaux(struct mbuf *m)
   1483   1.81    rpaulo {
   1484   1.81    rpaulo 	struct m_tag *mtag;
   1485   1.81    rpaulo 
   1486  1.205      maxv 	mtag = m_tag_find(m, PACKET_TAG_INET6);
   1487   1.81    rpaulo 	if (!mtag) {
   1488   1.81    rpaulo 		mtag = m_tag_get(PACKET_TAG_INET6, sizeof(struct ip6aux),
   1489   1.81    rpaulo 		    M_NOWAIT);
   1490   1.81    rpaulo 		if (mtag) {
   1491   1.81    rpaulo 			m_tag_prepend(m, mtag);
   1492  1.124    cegger 			memset(mtag + 1, 0, sizeof(struct ip6aux));
   1493   1.81    rpaulo 		}
   1494   1.81    rpaulo 	}
   1495   1.81    rpaulo 	return mtag;
   1496   1.81    rpaulo }
   1497   1.81    rpaulo 
   1498   1.81    rpaulo struct m_tag *
   1499  1.107  christos ip6_findaux(struct mbuf *m)
   1500   1.81    rpaulo {
   1501   1.81    rpaulo 	struct m_tag *mtag;
   1502   1.81    rpaulo 
   1503  1.205      maxv 	mtag = m_tag_find(m, PACKET_TAG_INET6);
   1504   1.81    rpaulo 	return mtag;
   1505   1.81    rpaulo }
   1506   1.81    rpaulo 
   1507   1.81    rpaulo void
   1508  1.107  christos ip6_delaux(struct mbuf *m)
   1509   1.81    rpaulo {
   1510   1.81    rpaulo 	struct m_tag *mtag;
   1511   1.81    rpaulo 
   1512  1.205      maxv 	mtag = m_tag_find(m, PACKET_TAG_INET6);
   1513   1.81    rpaulo 	if (mtag)
   1514   1.81    rpaulo 		m_tag_delete(m, mtag);
   1515   1.81    rpaulo }
   1516   1.81    rpaulo 
   1517    1.2    itojun /*
   1518    1.2    itojun  * System control for IP6
   1519    1.2    itojun  */
   1520    1.2    itojun 
   1521  1.120      matt const u_char inet6ctlerrmap[PRC_NCMDS] = {
   1522    1.2    itojun 	0,		0,		0,		0,
   1523    1.2    itojun 	0,		EMSGSIZE,	EHOSTDOWN,	EHOSTUNREACH,
   1524    1.2    itojun 	EHOSTUNREACH,	EHOSTUNREACH,	ECONNREFUSED,	ECONNREFUSED,
   1525    1.2    itojun 	EMSGSIZE,	EHOSTUNREACH,	0,		0,
   1526    1.2    itojun 	0,		0,		0,		0,
   1527    1.2    itojun 	ENOPROTOOPT
   1528    1.2    itojun };
   1529    1.2    itojun 
   1530  1.153  christos extern int sysctl_net_inet6_addrctlpolicy(SYSCTLFN_ARGS);
   1531  1.153  christos 
   1532  1.116   thorpej static int
   1533  1.116   thorpej sysctl_net_inet6_ip6_stats(SYSCTLFN_ARGS)
   1534  1.116   thorpej {
   1535  1.116   thorpej 
   1536  1.119   thorpej 	return (NETSTAT_SYSCTL(ip6stat_percpu, IP6_NSTATS));
   1537  1.116   thorpej }
   1538  1.116   thorpej 
   1539  1.128     pooka static void
   1540  1.128     pooka sysctl_net_inet6_ip6_setup(struct sysctllog **clog)
   1541    1.2    itojun {
   1542   1.26    itojun 
   1543   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1544   1.73    atatat 		       CTLFLAG_PERMANENT,
   1545   1.74    atatat 		       CTLTYPE_NODE, "inet6",
   1546   1.74    atatat 		       SYSCTL_DESCR("PF_INET6 related settings"),
   1547   1.70    atatat 		       NULL, 0, NULL, 0,
   1548   1.70    atatat 		       CTL_NET, PF_INET6, CTL_EOL);
   1549   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1550   1.73    atatat 		       CTLFLAG_PERMANENT,
   1551   1.74    atatat 		       CTLTYPE_NODE, "ip6",
   1552   1.74    atatat 		       SYSCTL_DESCR("IPv6 related settings"),
   1553   1.70    atatat 		       NULL, 0, NULL, 0,
   1554   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_EOL);
   1555   1.70    atatat 
   1556   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1557   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1558   1.74    atatat 		       CTLTYPE_INT, "forwarding",
   1559   1.74    atatat 		       SYSCTL_DESCR("Enable forwarding of INET6 datagrams"),
   1560   1.70    atatat 		       NULL, 0, &ip6_forwarding, 0,
   1561   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1562   1.70    atatat 		       IPV6CTL_FORWARDING, CTL_EOL);
   1563   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1564   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1565   1.74    atatat 		       CTLTYPE_INT, "redirect",
   1566   1.74    atatat 		       SYSCTL_DESCR("Enable sending of ICMPv6 redirect messages"),
   1567   1.70    atatat 		       NULL, 0, &ip6_sendredirects, 0,
   1568   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1569   1.70    atatat 		       IPV6CTL_SENDREDIRECTS, CTL_EOL);
   1570   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1571   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1572   1.74    atatat 		       CTLTYPE_INT, "hlim",
   1573   1.74    atatat 		       SYSCTL_DESCR("Hop limit for an INET6 datagram"),
   1574   1.70    atatat 		       NULL, 0, &ip6_defhlim, 0,
   1575   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1576   1.70    atatat 		       IPV6CTL_DEFHLIM, CTL_EOL);
   1577   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1578   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1579   1.74    atatat 		       CTLTYPE_INT, "maxfragpackets",
   1580   1.74    atatat 		       SYSCTL_DESCR("Maximum number of fragments to buffer "
   1581   1.74    atatat 				    "for reassembly"),
   1582   1.70    atatat 		       NULL, 0, &ip6_maxfragpackets, 0,
   1583   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1584   1.70    atatat 		       IPV6CTL_MAXFRAGPACKETS, CTL_EOL);
   1585   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1586   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1587   1.74    atatat 		       CTLTYPE_INT, "accept_rtadv",
   1588   1.74    atatat 		       SYSCTL_DESCR("Accept router advertisements"),
   1589   1.70    atatat 		       NULL, 0, &ip6_accept_rtadv, 0,
   1590   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1591   1.70    atatat 		       IPV6CTL_ACCEPT_RTADV, CTL_EOL);
   1592   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1593   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1594  1.131       spz 		       CTLTYPE_INT, "rtadv_maxroutes",
   1595  1.131       spz 		       SYSCTL_DESCR("Maximum number of routes accepted via router advertisements"),
   1596  1.131       spz 		       NULL, 0, &ip6_rtadv_maxroutes, 0,
   1597  1.131       spz 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1598  1.131       spz 		       IPV6CTL_RTADV_MAXROUTES, CTL_EOL);
   1599  1.131       spz 	sysctl_createv(clog, 0, NULL, NULL,
   1600  1.131       spz 		       CTLFLAG_PERMANENT,
   1601  1.131       spz 		       CTLTYPE_INT, "rtadv_numroutes",
   1602  1.131       spz 		       SYSCTL_DESCR("Current number of routes accepted via router advertisements"),
   1603  1.131       spz 		       NULL, 0, &nd6_numroutes, 0,
   1604  1.131       spz 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1605  1.131       spz 		       IPV6CTL_RTADV_NUMROUTES, CTL_EOL);
   1606  1.131       spz 	sysctl_createv(clog, 0, NULL, NULL,
   1607  1.131       spz 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1608   1.74    atatat 		       CTLTYPE_INT, "keepfaith",
   1609   1.74    atatat 		       SYSCTL_DESCR("Activate faith interface"),
   1610   1.70    atatat 		       NULL, 0, &ip6_keepfaith, 0,
   1611   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1612   1.70    atatat 		       IPV6CTL_KEEPFAITH, CTL_EOL);
   1613   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1614   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1615   1.74    atatat 		       CTLTYPE_INT, "log_interval",
   1616  1.189      maxv 		       SYSCTL_DESCR("Minimum interval between logging "
   1617   1.74    atatat 				    "unroutable packets"),
   1618   1.70    atatat 		       NULL, 0, &ip6_log_interval, 0,
   1619   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1620   1.70    atatat 		       IPV6CTL_LOG_INTERVAL, CTL_EOL);
   1621   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1622   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1623   1.74    atatat 		       CTLTYPE_INT, "hdrnestlimit",
   1624   1.74    atatat 		       SYSCTL_DESCR("Maximum number of nested IPv6 headers"),
   1625   1.70    atatat 		       NULL, 0, &ip6_hdrnestlimit, 0,
   1626   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1627   1.70    atatat 		       IPV6CTL_HDRNESTLIMIT, CTL_EOL);
   1628   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1629   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1630   1.74    atatat 		       CTLTYPE_INT, "dad_count",
   1631   1.74    atatat 		       SYSCTL_DESCR("Number of Duplicate Address Detection "
   1632   1.74    atatat 				    "probes to send"),
   1633   1.70    atatat 		       NULL, 0, &ip6_dad_count, 0,
   1634   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1635   1.70    atatat 		       IPV6CTL_DAD_COUNT, CTL_EOL);
   1636   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1637   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1638   1.74    atatat 		       CTLTYPE_INT, "auto_flowlabel",
   1639   1.74    atatat 		       SYSCTL_DESCR("Assign random IPv6 flow labels"),
   1640   1.70    atatat 		       NULL, 0, &ip6_auto_flowlabel, 0,
   1641   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1642   1.70    atatat 		       IPV6CTL_AUTO_FLOWLABEL, CTL_EOL);
   1643   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1644   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1645   1.74    atatat 		       CTLTYPE_INT, "defmcasthlim",
   1646   1.74    atatat 		       SYSCTL_DESCR("Default multicast hop limit"),
   1647   1.70    atatat 		       NULL, 0, &ip6_defmcasthlim, 0,
   1648   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1649   1.70    atatat 		       IPV6CTL_DEFMCASTHLIM, CTL_EOL);
   1650   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1651   1.73    atatat 		       CTLFLAG_PERMANENT,
   1652   1.74    atatat 		       CTLTYPE_STRING, "kame_version",
   1653   1.74    atatat 		       SYSCTL_DESCR("KAME Version"),
   1654   1.78  christos 		       NULL, 0, __UNCONST(__KAME_VERSION), 0,
   1655   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1656   1.70    atatat 		       IPV6CTL_KAME_VERSION, CTL_EOL);
   1657   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1658   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1659   1.74    atatat 		       CTLTYPE_INT, "use_deprecated",
   1660   1.74    atatat 		       SYSCTL_DESCR("Allow use of deprecated addresses as "
   1661   1.74    atatat 				    "source addresses"),
   1662   1.70    atatat 		       NULL, 0, &ip6_use_deprecated, 0,
   1663   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1664   1.70    atatat 		       IPV6CTL_USE_DEPRECATED, CTL_EOL);
   1665   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1666   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1667   1.70    atatat 		       CTLTYPE_INT, "rr_prune", NULL,
   1668   1.70    atatat 		       NULL, 0, &ip6_rr_prune, 0,
   1669   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1670   1.70    atatat 		       IPV6CTL_RR_PRUNE, CTL_EOL);
   1671   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1672   1.73    atatat 		       CTLFLAG_PERMANENT
   1673   1.70    atatat #ifndef INET6_BINDV6ONLY
   1674   1.73    atatat 		       |CTLFLAG_READWRITE,
   1675   1.70    atatat #endif
   1676   1.74    atatat 		       CTLTYPE_INT, "v6only",
   1677   1.74    atatat 		       SYSCTL_DESCR("Disallow PF_INET6 sockets from connecting "
   1678   1.74    atatat 				    "to PF_INET sockets"),
   1679   1.70    atatat 		       NULL, 0, &ip6_v6only, 0,
   1680   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1681   1.70    atatat 		       IPV6CTL_V6ONLY, CTL_EOL);
   1682   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1683   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1684   1.74    atatat 		       CTLTYPE_INT, "anonportmin",
   1685   1.74    atatat 		       SYSCTL_DESCR("Lowest ephemeral port number to assign"),
   1686   1.70    atatat 		       sysctl_net_inet_ip_ports, 0, &ip6_anonportmin, 0,
   1687   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1688   1.70    atatat 		       IPV6CTL_ANONPORTMIN, CTL_EOL);
   1689   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1690   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1691   1.74    atatat 		       CTLTYPE_INT, "anonportmax",
   1692   1.74    atatat 		       SYSCTL_DESCR("Highest ephemeral port number to assign"),
   1693   1.70    atatat 		       sysctl_net_inet_ip_ports, 0, &ip6_anonportmax, 0,
   1694   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1695   1.70    atatat 		       IPV6CTL_ANONPORTMAX, CTL_EOL);
   1696   1.26    itojun #ifndef IPNOPRIVPORTS
   1697   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1698   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1699   1.74    atatat 		       CTLTYPE_INT, "lowportmin",
   1700   1.74    atatat 		       SYSCTL_DESCR("Lowest privileged ephemeral port number "
   1701   1.74    atatat 				    "to assign"),
   1702   1.70    atatat 		       sysctl_net_inet_ip_ports, 0, &ip6_lowportmin, 0,
   1703   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1704   1.70    atatat 		       IPV6CTL_LOWPORTMIN, CTL_EOL);
   1705   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1706   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1707   1.74    atatat 		       CTLTYPE_INT, "lowportmax",
   1708   1.74    atatat 		       SYSCTL_DESCR("Highest privileged ephemeral port number "
   1709   1.74    atatat 				    "to assign"),
   1710   1.70    atatat 		       sysctl_net_inet_ip_ports, 0, &ip6_lowportmax, 0,
   1711   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1712   1.70    atatat 		       IPV6CTL_LOWPORTMAX, CTL_EOL);
   1713   1.70    atatat #endif /* IPNOPRIVPORTS */
   1714   1.73    atatat 	sysctl_createv(clog, 0, NULL, NULL,
   1715   1.73    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1716  1.153  christos 		       CTLTYPE_INT, "auto_linklocal",
   1717  1.153  christos 		       SYSCTL_DESCR("Default value of per-interface flag for "
   1718  1.153  christos 		                    "adding an IPv6 link-local address to "
   1719  1.153  christos 				    "interfaces when attached"),
   1720  1.153  christos 		       NULL, 0, &ip6_auto_linklocal, 0,
   1721  1.153  christos 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1722  1.153  christos 		       IPV6CTL_AUTO_LINKLOCAL, CTL_EOL);
   1723  1.153  christos 	sysctl_createv(clog, 0, NULL, NULL,
   1724  1.153  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
   1725  1.153  christos 		       CTLTYPE_STRUCT, "addctlpolicy",
   1726  1.153  christos 		       SYSCTL_DESCR("Return the current address control"
   1727  1.153  christos 			   " policy"),
   1728  1.153  christos 		       sysctl_net_inet6_addrctlpolicy, 0, NULL, 0,
   1729  1.153  christos 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1730  1.153  christos 		       IPV6CTL_ADDRCTLPOLICY, CTL_EOL);
   1731  1.153  christos 	sysctl_createv(clog, 0, NULL, NULL,
   1732  1.153  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1733   1.83    rpaulo 		       CTLTYPE_INT, "use_tempaddr",
   1734   1.83    rpaulo 		       SYSCTL_DESCR("Use temporary address"),
   1735   1.83    rpaulo 		       NULL, 0, &ip6_use_tempaddr, 0,
   1736   1.83    rpaulo 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1737   1.83    rpaulo 		       CTL_CREATE, CTL_EOL);
   1738   1.83    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
   1739   1.83    rpaulo 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1740  1.150       roy 		       CTLTYPE_INT, "prefer_tempaddr",
   1741  1.150       roy 		       SYSCTL_DESCR("Prefer temporary address as source "
   1742  1.150       roy 		                    "address"),
   1743  1.150       roy 		       NULL, 0, &ip6_prefer_tempaddr, 0,
   1744  1.150       roy 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1745  1.150       roy 		       CTL_CREATE, CTL_EOL);
   1746  1.150       roy 	sysctl_createv(clog, 0, NULL, NULL,
   1747  1.150       roy 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1748   1.83    rpaulo 		       CTLTYPE_INT, "temppltime",
   1749   1.83    rpaulo 		       SYSCTL_DESCR("preferred lifetime of a temporary address"),
   1750   1.83    rpaulo 		       NULL, 0, &ip6_temp_preferred_lifetime, 0,
   1751   1.83    rpaulo 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1752   1.83    rpaulo 		       CTL_CREATE, CTL_EOL);
   1753   1.83    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
   1754   1.83    rpaulo 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1755   1.83    rpaulo 		       CTLTYPE_INT, "tempvltime",
   1756   1.83    rpaulo 		       SYSCTL_DESCR("valid lifetime of a temporary address"),
   1757   1.83    rpaulo 		       NULL, 0, &ip6_temp_valid_lifetime, 0,
   1758   1.83    rpaulo 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1759   1.83    rpaulo 		       CTL_CREATE, CTL_EOL);
   1760   1.83    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
   1761   1.83    rpaulo 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1762   1.74    atatat 		       CTLTYPE_INT, "maxfrags",
   1763   1.74    atatat 		       SYSCTL_DESCR("Maximum fragments in reassembly queue"),
   1764   1.70    atatat 		       NULL, 0, &ip6_maxfrags, 0,
   1765   1.70    atatat 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1766   1.70    atatat 		       IPV6CTL_MAXFRAGS, CTL_EOL);
   1767   1.79    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
   1768   1.79    rpaulo 		       CTLFLAG_PERMANENT,
   1769   1.79    rpaulo 		       CTLTYPE_STRUCT, "stats",
   1770   1.79    rpaulo 		       SYSCTL_DESCR("IPv6 statistics"),
   1771  1.116   thorpej 		       sysctl_net_inet6_ip6_stats, 0, NULL, 0,
   1772   1.79    rpaulo 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1773   1.79    rpaulo 		       IPV6CTL_STATS, CTL_EOL);
   1774   1.81    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
   1775   1.81    rpaulo 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1776   1.81    rpaulo 		       CTLTYPE_INT, "use_defaultzone",
   1777   1.81    rpaulo 		       SYSCTL_DESCR("Whether to use the default scope zones"),
   1778   1.81    rpaulo 		       NULL, 0, &ip6_use_defzone, 0,
   1779   1.81    rpaulo 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1780   1.81    rpaulo 		       IPV6CTL_USE_DEFAULTZONE, CTL_EOL);
   1781   1.83    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
   1782   1.83    rpaulo 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1783   1.83    rpaulo 		       CTLTYPE_INT, "mcast_pmtu",
   1784   1.83    rpaulo 		       SYSCTL_DESCR("Enable pMTU discovery for multicast packet"),
   1785   1.83    rpaulo 		       NULL, 0, &ip6_mcast_pmtu, 0,
   1786   1.83    rpaulo 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1787   1.83    rpaulo 		       CTL_CREATE, CTL_EOL);
   1788  1.138  christos 	/* anonportalgo RFC6056 subtree */
   1789  1.140  christos 	const struct sysctlnode *portalgo_node;
   1790  1.140  christos 	sysctl_createv(clog, 0, NULL, &portalgo_node,
   1791  1.138  christos 		       CTLFLAG_PERMANENT,
   1792  1.138  christos 		       CTLTYPE_NODE, "anonportalgo",
   1793  1.138  christos 		       SYSCTL_DESCR("Anonymous port algorithm selection (RFC 6056)"),
   1794  1.138  christos 	    	       NULL, 0, NULL, 0,
   1795  1.138  christos 		       CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_CREATE, CTL_EOL);
   1796  1.140  christos 	sysctl_createv(clog, 0, &portalgo_node, NULL,
   1797  1.138  christos 		       CTLFLAG_PERMANENT,
   1798  1.138  christos 		       CTLTYPE_STRING, "available",
   1799  1.138  christos 		       SYSCTL_DESCR("available algorithms"),
   1800  1.140  christos 		       sysctl_portalgo_available, 0, NULL, PORTALGO_MAXLEN,
   1801  1.138  christos 		       CTL_CREATE, CTL_EOL);
   1802  1.140  christos 	sysctl_createv(clog, 0, &portalgo_node, NULL,
   1803  1.138  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1804  1.138  christos 		       CTLTYPE_STRING, "selected",
   1805  1.138  christos 		       SYSCTL_DESCR("selected algorithm"),
   1806  1.140  christos 	               sysctl_portalgo_selected6, 0, NULL, PORTALGO_MAXLEN,
   1807  1.138  christos 		       CTL_CREATE, CTL_EOL);
   1808  1.141  christos 	sysctl_createv(clog, 0, &portalgo_node, NULL,
   1809  1.141  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1810  1.141  christos 		       CTLTYPE_STRUCT, "reserve",
   1811  1.141  christos 		       SYSCTL_DESCR("bitmap of reserved ports"),
   1812  1.141  christos 		       sysctl_portalgo_reserve6, 0, NULL, 0,
   1813  1.141  christos 		       CTL_CREATE, CTL_EOL);
   1814  1.139  christos 	sysctl_createv(clog, 0, NULL, NULL,
   1815  1.139  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1816  1.139  christos 		       CTLTYPE_INT, "neighborgcthresh",
   1817  1.139  christos 		       SYSCTL_DESCR("Maximum number of entries in neighbor"
   1818  1.139  christos 			" cache"),
   1819  1.139  christos 		       NULL, 1, &ip6_neighborgcthresh, 0,
   1820  1.139  christos 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1821  1.139  christos 		       CTL_CREATE, CTL_EOL);
   1822  1.139  christos 	sysctl_createv(clog, 0, NULL, NULL,
   1823  1.139  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1824  1.139  christos 		       CTLTYPE_INT, "maxifprefixes",
   1825  1.139  christos 		       SYSCTL_DESCR("Maximum number of prefixes created by"
   1826  1.139  christos 			   " route advertisement per interface"),
   1827  1.139  christos 		       NULL, 1, &ip6_maxifprefixes, 0,
   1828  1.139  christos 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1829  1.139  christos 		       CTL_CREATE, CTL_EOL);
   1830  1.139  christos 	sysctl_createv(clog, 0, NULL, NULL,
   1831  1.139  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1832  1.139  christos 		       CTLTYPE_INT, "maxifdefrouters",
   1833  1.139  christos 		       SYSCTL_DESCR("Maximum number of default routers created"
   1834  1.139  christos 			   " by route advertisement per interface"),
   1835  1.139  christos 		       NULL, 1, &ip6_maxifdefrouters, 0,
   1836  1.139  christos 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1837  1.139  christos 		       CTL_CREATE, CTL_EOL);
   1838  1.139  christos 	sysctl_createv(clog, 0, NULL, NULL,
   1839  1.139  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1840  1.139  christos 		       CTLTYPE_INT, "maxdynroutes",
   1841  1.139  christos 		       SYSCTL_DESCR("Maximum number of routes created via"
   1842  1.139  christos 			   " redirect"),
   1843  1.139  christos 		       NULL, 1, &ip6_maxdynroutes, 0,
   1844  1.139  christos 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
   1845  1.139  christos 		       CTL_CREATE, CTL_EOL);
   1846    1.2    itojun }
   1847  1.116   thorpej 
   1848  1.116   thorpej void
   1849  1.116   thorpej ip6_statinc(u_int stat)
   1850  1.116   thorpej {
   1851  1.116   thorpej 
   1852  1.116   thorpej 	KASSERT(stat < IP6_NSTATS);
   1853  1.116   thorpej 	IP6_STATINC(stat);
   1854  1.116   thorpej }
   1855