Home | History | Annotate | Line # | Download | only in netinet6
ip6_flow.c revision 1.28.2.4
      1  1.28.2.4  pgoyette /*	$NetBSD: ip6_flow.c,v 1.28.2.4 2017/03/20 06:57:51 pgoyette Exp $	*/
      2       1.1  liamjfoy 
      3       1.1  liamjfoy /*-
      4       1.1  liamjfoy  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5       1.1  liamjfoy  * All rights reserved.
      6       1.1  liamjfoy  *
      7       1.1  liamjfoy  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1  liamjfoy  * by the 3am Software Foundry ("3am").  It was developed by Liam J. Foy
      9       1.1  liamjfoy  * <liamjfoy (at) netbsd.org> and Matt Thomas <matt (at) netbsd.org>.
     10       1.1  liamjfoy  *
     11       1.1  liamjfoy  * Redistribution and use in source and binary forms, with or without
     12       1.1  liamjfoy  * modification, are permitted provided that the following conditions
     13       1.1  liamjfoy  * are met:
     14       1.1  liamjfoy  * 1. Redistributions of source code must retain the above copyright
     15       1.1  liamjfoy  *    notice, this list of conditions and the following disclaimer.
     16       1.1  liamjfoy  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1  liamjfoy  *    notice, this list of conditions and the following disclaimer in the
     18       1.1  liamjfoy  *    documentation and/or other materials provided with the distribution.
     19       1.1  liamjfoy  *
     20       1.1  liamjfoy  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21       1.1  liamjfoy  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22       1.1  liamjfoy  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23       1.1  liamjfoy  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24       1.1  liamjfoy  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25       1.1  liamjfoy  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26       1.1  liamjfoy  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27       1.1  liamjfoy  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28       1.1  liamjfoy  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29       1.1  liamjfoy  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30       1.1  liamjfoy  * POSSIBILITY OF SUCH DAMAGE.
     31       1.1  liamjfoy  *
     32       1.1  liamjfoy  * IPv6 version was developed by Liam J. Foy. Original source existed in IPv4
     33       1.1  liamjfoy  * format developed by Matt Thomas. Thanks to Joerg Sonnenberger, Matt
     34       1.1  liamjfoy  * Thomas and Christos Zoulas.
     35       1.1  liamjfoy  *
     36       1.1  liamjfoy  * Thanks to Liverpool John Moores University, especially Dr. David Llewellyn-Jones
     37       1.1  liamjfoy  * for providing resources (to test) and Professor Madjid Merabti.
     38       1.1  liamjfoy  */
     39       1.1  liamjfoy 
     40       1.1  liamjfoy #include <sys/cdefs.h>
     41  1.28.2.4  pgoyette __KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.28.2.4 2017/03/20 06:57:51 pgoyette Exp $");
     42  1.28.2.2  pgoyette 
     43  1.28.2.2  pgoyette #ifdef _KERNEL_OPT
     44  1.28.2.2  pgoyette #include "opt_net_mpsafe.h"
     45  1.28.2.2  pgoyette #endif
     46       1.1  liamjfoy 
     47       1.1  liamjfoy #include <sys/param.h>
     48       1.1  liamjfoy #include <sys/systm.h>
     49       1.1  liamjfoy #include <sys/malloc.h>
     50       1.1  liamjfoy #include <sys/mbuf.h>
     51       1.1  liamjfoy #include <sys/socketvar.h>
     52       1.1  liamjfoy #include <sys/time.h>
     53       1.1  liamjfoy #include <sys/kernel.h>
     54       1.1  liamjfoy #include <sys/pool.h>
     55       1.1  liamjfoy #include <sys/sysctl.h>
     56      1.28     ozaki #include <sys/workqueue.h>
     57  1.28.2.1  pgoyette #include <sys/atomic.h>
     58       1.1  liamjfoy 
     59       1.1  liamjfoy #include <net/if.h>
     60       1.1  liamjfoy #include <net/if_dl.h>
     61       1.1  liamjfoy #include <net/route.h>
     62       1.1  liamjfoy #include <net/pfil.h>
     63       1.1  liamjfoy 
     64       1.1  liamjfoy #include <netinet/in.h>
     65       1.1  liamjfoy #include <netinet6/in6_var.h>
     66       1.1  liamjfoy #include <netinet/in_systm.h>
     67       1.1  liamjfoy #include <netinet/ip6.h>
     68       1.1  liamjfoy #include <netinet6/ip6_var.h>
     69      1.15   thorpej #include <netinet6/ip6_private.h>
     70       1.1  liamjfoy 
     71       1.1  liamjfoy /*
     72       1.1  liamjfoy  * IPv6 Fast Forward caches/hashes flows from one source to destination.
     73       1.1  liamjfoy  *
     74       1.1  liamjfoy  * Upon a successful forward IPv6FF caches and hashes details such as the
     75       1.1  liamjfoy  * route, source and destination. Once another packet is received matching
     76       1.1  liamjfoy  * the source and destination the packet is forwarded straight onto if_output
     77       1.1  liamjfoy  * using the cached details.
     78       1.1  liamjfoy  *
     79       1.1  liamjfoy  * Example:
     80      1.20  christos  * ether/fddi_input -> ip6flow_fastforward -> if_output
     81       1.1  liamjfoy  */
     82       1.1  liamjfoy 
     83      1.18  liamjfoy static struct pool ip6flow_pool;
     84       1.1  liamjfoy 
     85       1.1  liamjfoy LIST_HEAD(ip6flowhead, ip6flow);
     86       1.1  liamjfoy 
     87       1.1  liamjfoy /*
     88       1.1  liamjfoy  * We could use IPv4 defines (IPFLOW_HASHBITS) but we'll
     89       1.1  liamjfoy  * use our own (possibly for future expansion).
     90       1.1  liamjfoy  */
     91       1.1  liamjfoy #define	IP6FLOW_TIMER		(5 * PR_SLOWHZ)
     92       1.4  liamjfoy #define	IP6FLOW_DEFAULT_HASHSIZE	(1 << IP6FLOW_HASHBITS)
     93       1.1  liamjfoy 
     94      1.25  knakahar /*
     95      1.25  knakahar  * ip6_flow.c internal lock.
     96      1.25  knakahar  * If we use softnet_lock, it would cause recursive lock.
     97      1.25  knakahar  *
     98      1.25  knakahar  * This is a tentative workaround.
     99      1.25  knakahar  * We should make it scalable somehow in the future.
    100      1.25  knakahar  */
    101      1.25  knakahar static kmutex_t ip6flow_lock;
    102       1.4  liamjfoy static struct ip6flowhead *ip6flowtable = NULL;
    103       1.1  liamjfoy static struct ip6flowhead ip6flowlist;
    104       1.1  liamjfoy static int ip6flow_inuse;
    105       1.1  liamjfoy 
    106      1.28     ozaki static void ip6flow_slowtimo_work(struct work *, void *);
    107      1.28     ozaki static struct workqueue	*ip6flow_slowtimo_wq;
    108      1.28     ozaki static struct work	ip6flow_slowtimo_wk;
    109      1.28     ozaki 
    110  1.28.2.1  pgoyette static int sysctl_net_inet6_ip6_hashsize(SYSCTLFN_PROTO);
    111  1.28.2.1  pgoyette static int sysctl_net_inet6_ip6_maxflows(SYSCTLFN_PROTO);
    112  1.28.2.1  pgoyette static void ip6flow_sysctl_init(struct sysctllog **);
    113  1.28.2.1  pgoyette 
    114       1.1  liamjfoy /*
    115       1.1  liamjfoy  * Insert an ip6flow into the list.
    116       1.1  liamjfoy  */
    117       1.1  liamjfoy #define	IP6FLOW_INSERT(bucket, ip6f) \
    118       1.1  liamjfoy do { \
    119       1.1  liamjfoy 	LIST_INSERT_HEAD((bucket), (ip6f), ip6f_hash); \
    120       1.1  liamjfoy 	LIST_INSERT_HEAD(&ip6flowlist, (ip6f), ip6f_list); \
    121       1.1  liamjfoy } while (/*CONSTCOND*/ 0)
    122       1.1  liamjfoy 
    123       1.1  liamjfoy /*
    124       1.1  liamjfoy  * Remove an ip6flow from the list.
    125       1.1  liamjfoy  */
    126       1.1  liamjfoy #define	IP6FLOW_REMOVE(ip6f) \
    127       1.1  liamjfoy do { \
    128       1.1  liamjfoy 	LIST_REMOVE((ip6f), ip6f_hash); \
    129       1.1  liamjfoy 	LIST_REMOVE((ip6f), ip6f_list); \
    130       1.1  liamjfoy } while (/*CONSTCOND*/ 0)
    131       1.1  liamjfoy 
    132       1.1  liamjfoy #ifndef IP6FLOW_DEFAULT
    133       1.1  liamjfoy #define	IP6FLOW_DEFAULT		256
    134       1.1  liamjfoy #endif
    135       1.1  liamjfoy 
    136       1.1  liamjfoy int ip6_maxflows = IP6FLOW_DEFAULT;
    137       1.4  liamjfoy int ip6_hashsize = IP6FLOW_DEFAULT_HASHSIZE;
    138       1.1  liamjfoy 
    139       1.1  liamjfoy /*
    140       1.1  liamjfoy  * Calculate hash table position.
    141       1.1  liamjfoy  */
    142       1.1  liamjfoy static size_t
    143      1.13    dyoung ip6flow_hash(const struct ip6_hdr *ip6)
    144       1.1  liamjfoy {
    145       1.1  liamjfoy 	size_t hash;
    146       1.1  liamjfoy 	uint32_t dst_sum, src_sum;
    147       1.6  liamjfoy 	size_t idx;
    148       1.1  liamjfoy 
    149       1.1  liamjfoy 	src_sum = ip6->ip6_src.s6_addr32[0] + ip6->ip6_src.s6_addr32[1]
    150       1.1  liamjfoy 	    + ip6->ip6_src.s6_addr32[2] + ip6->ip6_src.s6_addr32[3];
    151       1.1  liamjfoy 	dst_sum = ip6->ip6_dst.s6_addr32[0] + ip6->ip6_dst.s6_addr32[1]
    152       1.1  liamjfoy 	    + ip6->ip6_dst.s6_addr32[2] + ip6->ip6_dst.s6_addr32[3];
    153       1.1  liamjfoy 
    154       1.1  liamjfoy 	hash = ip6->ip6_flow;
    155       1.1  liamjfoy 
    156       1.1  liamjfoy 	for (idx = 0; idx < 32; idx += IP6FLOW_HASHBITS)
    157       1.1  liamjfoy 		hash += (dst_sum >> (32 - idx)) + (src_sum >> idx);
    158       1.1  liamjfoy 
    159       1.4  liamjfoy 	return hash & (ip6_hashsize-1);
    160       1.1  liamjfoy }
    161       1.1  liamjfoy 
    162       1.1  liamjfoy /*
    163       1.1  liamjfoy  * Check to see if a flow already exists - if so return it.
    164       1.1  liamjfoy  */
    165       1.1  liamjfoy static struct ip6flow *
    166      1.13    dyoung ip6flow_lookup(const struct ip6_hdr *ip6)
    167       1.1  liamjfoy {
    168       1.1  liamjfoy 	size_t hash;
    169       1.1  liamjfoy 	struct ip6flow *ip6f;
    170       1.1  liamjfoy 
    171      1.25  knakahar 	KASSERT(mutex_owned(&ip6flow_lock));
    172      1.25  knakahar 
    173       1.1  liamjfoy 	hash = ip6flow_hash(ip6);
    174       1.1  liamjfoy 
    175       1.2  liamjfoy 	LIST_FOREACH(ip6f, &ip6flowtable[hash], ip6f_hash) {
    176       1.1  liamjfoy 		if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &ip6f->ip6f_dst)
    177       1.1  liamjfoy 		    && IN6_ARE_ADDR_EQUAL(&ip6->ip6_src, &ip6f->ip6f_src)
    178       1.1  liamjfoy 		    && ip6f->ip6f_flow == ip6->ip6_flow) {
    179       1.1  liamjfoy 		    	/* A cached flow has been found. */
    180       1.1  liamjfoy 			return ip6f;
    181       1.1  liamjfoy 		}
    182       1.1  liamjfoy 	}
    183       1.1  liamjfoy 
    184       1.1  liamjfoy 	return NULL;
    185       1.1  liamjfoy }
    186       1.1  liamjfoy 
    187      1.18  liamjfoy void
    188      1.18  liamjfoy ip6flow_poolinit(void)
    189      1.18  liamjfoy {
    190      1.18  liamjfoy 
    191      1.18  liamjfoy 	pool_init(&ip6flow_pool, sizeof(struct ip6flow), 0, 0, 0, "ip6flowpl",
    192      1.18  liamjfoy 			NULL, IPL_NET);
    193      1.18  liamjfoy }
    194      1.18  liamjfoy 
    195       1.1  liamjfoy /*
    196       1.4  liamjfoy  * Allocate memory and initialise lists. This function is called
    197       1.4  liamjfoy  * from ip6_init and called there after to resize the hash table.
    198       1.4  liamjfoy  * If a newly sized table cannot be malloc'ed we just continue
    199       1.4  liamjfoy  * to use the old one.
    200       1.1  liamjfoy  */
    201      1.25  knakahar static int
    202      1.25  knakahar ip6flow_init_locked(int table_size)
    203       1.1  liamjfoy {
    204       1.4  liamjfoy 	struct ip6flowhead *new_table;
    205       1.1  liamjfoy 	size_t i;
    206       1.1  liamjfoy 
    207      1.25  knakahar 	KASSERT(mutex_owned(&ip6flow_lock));
    208      1.25  knakahar 
    209       1.4  liamjfoy 	new_table = (struct ip6flowhead *)malloc(sizeof(struct ip6flowhead) *
    210       1.4  liamjfoy 	    table_size, M_RTABLE, M_NOWAIT);
    211       1.4  liamjfoy 
    212       1.4  liamjfoy 	if (new_table == NULL)
    213       1.4  liamjfoy 		return 1;
    214       1.4  liamjfoy 
    215       1.4  liamjfoy 	if (ip6flowtable != NULL)
    216       1.4  liamjfoy 		free(ip6flowtable, M_RTABLE);
    217       1.4  liamjfoy 
    218       1.4  liamjfoy 	ip6flowtable = new_table;
    219       1.4  liamjfoy 	ip6_hashsize = table_size;
    220       1.4  liamjfoy 
    221       1.1  liamjfoy 	LIST_INIT(&ip6flowlist);
    222       1.4  liamjfoy 	for (i = 0; i < ip6_hashsize; i++)
    223       1.1  liamjfoy 		LIST_INIT(&ip6flowtable[i]);
    224       1.4  liamjfoy 
    225       1.4  liamjfoy 	return 0;
    226       1.1  liamjfoy }
    227       1.1  liamjfoy 
    228      1.25  knakahar int
    229      1.25  knakahar ip6flow_init(int table_size)
    230      1.25  knakahar {
    231      1.28     ozaki 	int ret, error;
    232      1.28     ozaki 
    233      1.28     ozaki 	error = workqueue_create(&ip6flow_slowtimo_wq, "ip6flow_slowtimo",
    234      1.28     ozaki 	    ip6flow_slowtimo_work, NULL, PRI_SOFTNET, IPL_SOFTNET, WQ_MPSAFE);
    235      1.28     ozaki 	if (error != 0)
    236      1.28     ozaki 		panic("%s: workqueue_create failed (%d)\n", __func__, error);
    237      1.25  knakahar 
    238      1.25  knakahar 	mutex_init(&ip6flow_lock, MUTEX_DEFAULT, IPL_NONE);
    239      1.25  knakahar 
    240      1.25  knakahar 	mutex_enter(&ip6flow_lock);
    241      1.25  knakahar 	ret = ip6flow_init_locked(table_size);
    242      1.25  knakahar 	mutex_exit(&ip6flow_lock);
    243  1.28.2.1  pgoyette 	ip6flow_sysctl_init(NULL);
    244      1.25  knakahar 
    245      1.25  knakahar 	return ret;
    246      1.25  knakahar }
    247      1.25  knakahar 
    248       1.1  liamjfoy /*
    249       1.1  liamjfoy  * IPv6 Fast Forward routine. Attempt to forward the packet -
    250       1.1  liamjfoy  * if any problems are found return to the main IPv6 input
    251       1.1  liamjfoy  * routine to deal with.
    252       1.1  liamjfoy  */
    253       1.1  liamjfoy int
    254      1.20  christos ip6flow_fastforward(struct mbuf **mp)
    255       1.1  liamjfoy {
    256       1.1  liamjfoy 	struct ip6flow *ip6f;
    257       1.1  liamjfoy 	struct ip6_hdr *ip6;
    258  1.28.2.3  pgoyette 	struct rtentry *rt = NULL;
    259      1.20  christos 	struct mbuf *m;
    260       1.7    dyoung 	const struct sockaddr *dst;
    261       1.1  liamjfoy 	int error;
    262      1.25  knakahar 	int ret = 0;
    263      1.25  knakahar 
    264      1.25  knakahar 	mutex_enter(&ip6flow_lock);
    265       1.1  liamjfoy 
    266       1.1  liamjfoy 	/*
    267       1.1  liamjfoy 	 * Are we forwarding packets and have flows?
    268       1.1  liamjfoy 	 */
    269       1.1  liamjfoy 	if (!ip6_forwarding || ip6flow_inuse == 0)
    270      1.25  knakahar 		goto out;
    271       1.1  liamjfoy 
    272      1.20  christos 	m = *mp;
    273       1.1  liamjfoy 	/*
    274       1.1  liamjfoy 	 * At least size of IPv6 Header?
    275       1.1  liamjfoy 	 */
    276       1.1  liamjfoy 	if (m->m_len < sizeof(struct ip6_hdr))
    277      1.25  knakahar 		goto out;
    278       1.1  liamjfoy 	/*
    279       1.1  liamjfoy 	 * Was packet received as a link-level multicast or broadcast?
    280       1.1  liamjfoy 	 * If so, don't try to fast forward.
    281       1.1  liamjfoy 	 */
    282       1.1  liamjfoy 	if ((m->m_flags & (M_BCAST|M_MCAST)) != 0)
    283      1.25  knakahar 		goto out;
    284       1.1  liamjfoy 
    285      1.13    dyoung 	if (IP6_HDR_ALIGNED_P(mtod(m, const void *)) == 0) {
    286       1.1  liamjfoy 		if ((m = m_copyup(m, sizeof(struct ip6_hdr),
    287       1.1  liamjfoy 				(max_linkhdr + 3) & ~3)) == NULL) {
    288      1.25  knakahar 			goto out;
    289       1.1  liamjfoy 		}
    290      1.20  christos 		*mp = m;
    291       1.1  liamjfoy 	} else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
    292       1.1  liamjfoy 		if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
    293      1.25  knakahar 			goto out;
    294       1.1  liamjfoy 		}
    295      1.20  christos 		*mp = m;
    296       1.1  liamjfoy 	}
    297       1.1  liamjfoy 
    298       1.1  liamjfoy 	ip6 = mtod(m, struct ip6_hdr *);
    299       1.1  liamjfoy 
    300       1.1  liamjfoy 	if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
    301       1.1  liamjfoy 		/* Bad version. */
    302      1.25  knakahar 		goto out;
    303       1.1  liamjfoy 	}
    304       1.1  liamjfoy 
    305       1.1  liamjfoy 	/*
    306       1.1  liamjfoy 	 * If we have a hop-by-hop extension we must process it.
    307       1.1  liamjfoy 	 * We just leave this up to ip6_input to deal with.
    308       1.1  liamjfoy 	 */
    309       1.1  liamjfoy 	if (ip6->ip6_nxt == IPPROTO_HOPOPTS)
    310      1.25  knakahar 		goto out;
    311       1.1  liamjfoy 
    312       1.1  liamjfoy 	/*
    313       1.1  liamjfoy 	 * Attempt to find a flow.
    314       1.1  liamjfoy 	 */
    315       1.1  liamjfoy 	if ((ip6f = ip6flow_lookup(ip6)) == NULL) {
    316       1.1  liamjfoy 		/* No flow found. */
    317      1.25  knakahar 		goto out;
    318       1.1  liamjfoy 	}
    319       1.1  liamjfoy 
    320       1.1  liamjfoy 	/*
    321       1.1  liamjfoy 	 * Route and interface still up?
    322       1.1  liamjfoy 	 */
    323      1.12    dyoung 	if ((rt = rtcache_validate(&ip6f->ip6f_ro)) == NULL ||
    324      1.24       roy 	    (rt->rt_ifp->if_flags & IFF_UP) == 0 ||
    325      1.24       roy 	    (rt->rt_flags & RTF_BLACKHOLE) != 0)
    326  1.28.2.3  pgoyette 		goto out_unref;
    327       1.1  liamjfoy 
    328       1.1  liamjfoy 	/*
    329       1.1  liamjfoy 	 * Packet size greater than MTU?
    330       1.1  liamjfoy 	 */
    331       1.1  liamjfoy 	if (m->m_pkthdr.len > rt->rt_ifp->if_mtu) {
    332       1.1  liamjfoy 		/* Return to main IPv6 input function. */
    333  1.28.2.3  pgoyette 		goto out_unref;
    334       1.1  liamjfoy 	}
    335       1.1  liamjfoy 
    336      1.21   msaitoh 	/*
    337      1.21   msaitoh 	 * Clear any in-bound checksum flags for this packet.
    338      1.21   msaitoh 	 */
    339      1.21   msaitoh 	m->m_pkthdr.csum_flags = 0;
    340      1.21   msaitoh 
    341       1.1  liamjfoy 	if (ip6->ip6_hlim <= IPV6_HLIMDEC)
    342  1.28.2.3  pgoyette 		goto out_unref;
    343       1.1  liamjfoy 
    344       1.1  liamjfoy 	/* Decrement hop limit (same as TTL) */
    345       1.1  liamjfoy 	ip6->ip6_hlim -= IPV6_HLIMDEC;
    346       1.1  liamjfoy 
    347       1.1  liamjfoy 	if (rt->rt_flags & RTF_GATEWAY)
    348       1.7    dyoung 		dst = rt->rt_gateway;
    349       1.1  liamjfoy 	else
    350       1.7    dyoung 		dst = rtcache_getdst(&ip6f->ip6f_ro);
    351       1.1  liamjfoy 
    352       1.1  liamjfoy 	PRT_SLOW_ARM(ip6f->ip6f_timer, IP6FLOW_TIMER);
    353       1.1  liamjfoy 
    354       1.1  liamjfoy 	ip6f->ip6f_uses++;
    355       1.1  liamjfoy 
    356       1.1  liamjfoy 	/* Send on its way - straight to the interface output routine. */
    357      1.27  knakahar 	if ((error = if_output_lock(rt->rt_ifp, rt->rt_ifp, m, dst, rt)) != 0) {
    358       1.1  liamjfoy 		ip6f->ip6f_dropped++;
    359       1.1  liamjfoy 	} else {
    360       1.1  liamjfoy 		ip6f->ip6f_forwarded++;
    361       1.1  liamjfoy 	}
    362      1.25  knakahar 	ret = 1;
    363  1.28.2.3  pgoyette out_unref:
    364  1.28.2.3  pgoyette 	rtcache_unref(rt, &ip6f->ip6f_ro);
    365  1.28.2.3  pgoyette out:
    366      1.25  knakahar 	mutex_exit(&ip6flow_lock);
    367      1.25  knakahar 	return ret;
    368       1.1  liamjfoy }
    369       1.1  liamjfoy 
    370       1.1  liamjfoy /*
    371       1.1  liamjfoy  * Add the IPv6 flow statistics to the main IPv6 statistics.
    372       1.1  liamjfoy  */
    373       1.1  liamjfoy static void
    374  1.28.2.3  pgoyette ip6flow_addstats_rt(struct rtentry *rt, struct ip6flow *ip6f)
    375       1.1  liamjfoy {
    376      1.15   thorpej 	uint64_t *ip6s;
    377      1.11    dyoung 
    378  1.28.2.3  pgoyette 	if (rt != NULL)
    379      1.11    dyoung 		rt->rt_use += ip6f->ip6f_uses;
    380      1.15   thorpej 	ip6s = IP6_STAT_GETREF();
    381      1.15   thorpej 	ip6s[IP6_STAT_FASTFORWARDFLOWS] = ip6flow_inuse;
    382      1.15   thorpej 	ip6s[IP6_STAT_CANTFORWARD] += ip6f->ip6f_dropped;
    383      1.15   thorpej 	ip6s[IP6_STAT_ODROPPED] += ip6f->ip6f_dropped;
    384      1.15   thorpej 	ip6s[IP6_STAT_TOTAL] += ip6f->ip6f_uses;
    385      1.15   thorpej 	ip6s[IP6_STAT_FORWARD] += ip6f->ip6f_forwarded;
    386      1.15   thorpej 	ip6s[IP6_STAT_FASTFORWARD] += ip6f->ip6f_forwarded;
    387      1.15   thorpej 	IP6_STAT_PUTREF();
    388       1.1  liamjfoy }
    389       1.1  liamjfoy 
    390  1.28.2.3  pgoyette static void
    391  1.28.2.3  pgoyette ip6flow_addstats(struct ip6flow *ip6f)
    392  1.28.2.3  pgoyette {
    393  1.28.2.3  pgoyette 	struct rtentry *rt;
    394  1.28.2.3  pgoyette 
    395  1.28.2.3  pgoyette 	rt = rtcache_validate(&ip6f->ip6f_ro);
    396  1.28.2.3  pgoyette 	ip6flow_addstats_rt(rt, ip6f);
    397  1.28.2.3  pgoyette 	rtcache_unref(rt, &ip6f->ip6f_ro);
    398  1.28.2.3  pgoyette }
    399  1.28.2.3  pgoyette 
    400       1.1  liamjfoy /*
    401       1.1  liamjfoy  * Add statistics and free the flow.
    402       1.1  liamjfoy  */
    403       1.1  liamjfoy static void
    404       1.1  liamjfoy ip6flow_free(struct ip6flow *ip6f)
    405       1.1  liamjfoy {
    406       1.1  liamjfoy 
    407      1.25  knakahar 	KASSERT(mutex_owned(&ip6flow_lock));
    408      1.25  knakahar 
    409       1.1  liamjfoy 	/*
    410       1.1  liamjfoy 	 * Remove the flow from the hash table (at elevated IPL).
    411       1.1  liamjfoy 	 * Once it's off the list, we can deal with it at normal
    412       1.1  liamjfoy 	 * network IPL.
    413       1.1  liamjfoy 	 */
    414       1.1  liamjfoy 	IP6FLOW_REMOVE(ip6f);
    415      1.26  knakahar 
    416       1.1  liamjfoy 	ip6flow_inuse--;
    417       1.1  liamjfoy 	ip6flow_addstats(ip6f);
    418       1.7    dyoung 	rtcache_free(&ip6f->ip6f_ro);
    419       1.1  liamjfoy 	pool_put(&ip6flow_pool, ip6f);
    420       1.1  liamjfoy }
    421       1.1  liamjfoy 
    422      1.25  knakahar static struct ip6flow *
    423      1.25  knakahar ip6flow_reap_locked(int just_one)
    424       1.1  liamjfoy {
    425      1.25  knakahar 
    426      1.25  knakahar 	KASSERT(mutex_owned(&ip6flow_lock));
    427      1.25  knakahar 
    428       1.1  liamjfoy 	while (just_one || ip6flow_inuse > ip6_maxflows) {
    429       1.1  liamjfoy 		struct ip6flow *ip6f, *maybe_ip6f = NULL;
    430       1.1  liamjfoy 
    431  1.28.2.3  pgoyette 	/*
    432  1.28.2.3  pgoyette 	 * This case is used in slow path(sysctl).
    433  1.28.2.3  pgoyette 	 * At first, remove invalid rtcache ip6flow, and then remove TAILQ_LAST
    434  1.28.2.3  pgoyette 	 * ip6flow if it is ensured least recently used by comparing last_uses.
    435  1.28.2.3  pgoyette 	 */
    436  1.28.2.3  pgoyette 	while (ip6flow_inuse > ip6_maxflows) {
    437  1.28.2.3  pgoyette 		struct ip6flow *maybe_ip6f = TAILQ_LAST(&ip6flowlist, ip6flowhead);
    438  1.28.2.3  pgoyette 
    439  1.28.2.3  pgoyette 		TAILQ_FOREACH(ip6f, &ip6flowlist, ip6f_list) {
    440  1.28.2.3  pgoyette 			struct rtentry *rt;
    441       1.1  liamjfoy 			/*
    442       1.1  liamjfoy 			 * If this no longer points to a valid route -
    443       1.1  liamjfoy 			 * reclaim it.
    444       1.1  liamjfoy 			 */
    445  1.28.2.3  pgoyette 			if ((rt = rtcache_validate(&ip6f->ip6f_ro)) == NULL)
    446       1.1  liamjfoy 				goto done;
    447  1.28.2.3  pgoyette 			rtcache_unref(rt, &ip6f->ip6f_ro);
    448       1.1  liamjfoy 			/*
    449       1.1  liamjfoy 			 * choose the one that's been least recently
    450       1.1  liamjfoy 			 * used or has had the least uses in the
    451       1.1  liamjfoy 			 * last 1.5 intervals.
    452       1.1  liamjfoy 			 */
    453       1.1  liamjfoy 			if (maybe_ip6f == NULL ||
    454       1.1  liamjfoy 			    ip6f->ip6f_timer < maybe_ip6f->ip6f_timer ||
    455       1.1  liamjfoy 			    (ip6f->ip6f_timer == maybe_ip6f->ip6f_timer &&
    456       1.1  liamjfoy 			     ip6f->ip6f_last_uses + ip6f->ip6f_uses <
    457       1.1  liamjfoy 			         maybe_ip6f->ip6f_last_uses +
    458       1.1  liamjfoy 			         maybe_ip6f->ip6f_uses))
    459       1.1  liamjfoy 				maybe_ip6f = ip6f;
    460       1.1  liamjfoy 			ip6f = LIST_NEXT(ip6f, ip6f_list);
    461       1.1  liamjfoy 		}
    462       1.1  liamjfoy 		ip6f = maybe_ip6f;
    463       1.1  liamjfoy 	    done:
    464       1.1  liamjfoy 		/*
    465       1.1  liamjfoy 		 * Remove the entry from the flow table
    466       1.1  liamjfoy 		 */
    467       1.1  liamjfoy 		IP6FLOW_REMOVE(ip6f);
    468      1.26  knakahar 
    469       1.7    dyoung 		rtcache_free(&ip6f->ip6f_ro);
    470       1.1  liamjfoy 		if (just_one) {
    471       1.1  liamjfoy 			ip6flow_addstats(ip6f);
    472       1.1  liamjfoy 			return ip6f;
    473       1.1  liamjfoy 		}
    474       1.1  liamjfoy 		ip6flow_inuse--;
    475       1.1  liamjfoy 		ip6flow_addstats(ip6f);
    476       1.1  liamjfoy 		pool_put(&ip6flow_pool, ip6f);
    477       1.1  liamjfoy 	}
    478       1.1  liamjfoy 	return NULL;
    479       1.1  liamjfoy }
    480       1.1  liamjfoy 
    481      1.25  knakahar /*
    482      1.25  knakahar  * Reap one or more flows - ip6flow_reap may remove
    483      1.25  knakahar  * multiple flows if net.inet6.ip6.maxflows is reduced.
    484      1.25  knakahar  */
    485      1.25  knakahar struct ip6flow *
    486      1.25  knakahar ip6flow_reap(int just_one)
    487      1.25  knakahar {
    488      1.25  knakahar 	struct ip6flow *ip6f;
    489      1.25  knakahar 
    490      1.25  knakahar 	mutex_enter(&ip6flow_lock);
    491      1.25  knakahar 	ip6f = ip6flow_reap_locked(just_one);
    492      1.25  knakahar 	mutex_exit(&ip6flow_lock);
    493      1.25  knakahar 	return ip6f;
    494      1.25  knakahar }
    495      1.25  knakahar 
    496  1.28.2.1  pgoyette static unsigned int ip6flow_work_enqueued = 0;
    497      1.28     ozaki 
    498       1.1  liamjfoy void
    499      1.28     ozaki ip6flow_slowtimo_work(struct work *wk, void *arg)
    500       1.1  liamjfoy {
    501       1.1  liamjfoy 	struct ip6flow *ip6f, *next_ip6f;
    502       1.1  liamjfoy 
    503  1.28.2.1  pgoyette 	/* We can allow enqueuing another work at this point */
    504  1.28.2.1  pgoyette 	atomic_swap_uint(&ip6flow_work_enqueued, 0);
    505  1.28.2.1  pgoyette 
    506  1.28.2.2  pgoyette #ifndef NET_MPSAFE
    507      1.16        ad 	mutex_enter(softnet_lock);
    508      1.16        ad 	KERNEL_LOCK(1, NULL);
    509  1.28.2.2  pgoyette #endif
    510  1.28.2.2  pgoyette 	mutex_enter(&ip6flow_lock);
    511      1.16        ad 
    512  1.28.2.3  pgoyette 	for (ip6f = TAILQ_FIRST(&ip6flowlist); ip6f != NULL; ip6f = next_ip6f) {
    513  1.28.2.3  pgoyette 		struct rtentry *rt = NULL;
    514  1.28.2.3  pgoyette 		next_ip6f = TAILQ_NEXT(ip6f, ip6f_list);
    515       1.1  liamjfoy 		if (PRT_SLOW_ISEXPIRED(ip6f->ip6f_timer) ||
    516  1.28.2.3  pgoyette 		    (rt = rtcache_validate(&ip6f->ip6f_ro)) == NULL) {
    517       1.1  liamjfoy 			ip6flow_free(ip6f);
    518       1.1  liamjfoy 		} else {
    519       1.1  liamjfoy 			ip6f->ip6f_last_uses = ip6f->ip6f_uses;
    520  1.28.2.3  pgoyette 			ip6flow_addstats_rt(rt, ip6f);
    521       1.1  liamjfoy 			ip6f->ip6f_uses = 0;
    522       1.1  liamjfoy 			ip6f->ip6f_dropped = 0;
    523       1.1  liamjfoy 			ip6f->ip6f_forwarded = 0;
    524       1.1  liamjfoy 		}
    525  1.28.2.3  pgoyette 		rtcache_unref(rt, &ip6f->ip6f_ro);
    526       1.1  liamjfoy 	}
    527      1.16        ad 
    528      1.25  knakahar 	mutex_exit(&ip6flow_lock);
    529  1.28.2.2  pgoyette #ifndef NET_MPSAFE
    530  1.28.2.2  pgoyette 	KERNEL_UNLOCK_ONE(NULL);
    531      1.16        ad 	mutex_exit(softnet_lock);
    532  1.28.2.2  pgoyette #endif
    533       1.1  liamjfoy }
    534       1.1  liamjfoy 
    535      1.28     ozaki void
    536      1.28     ozaki ip6flow_slowtimo(void)
    537      1.28     ozaki {
    538      1.28     ozaki 
    539      1.28     ozaki 	/* Avoid enqueuing another work when one is already enqueued */
    540  1.28.2.1  pgoyette 	if (atomic_swap_uint(&ip6flow_work_enqueued, 1) == 1)
    541      1.28     ozaki 		return;
    542      1.28     ozaki 
    543      1.28     ozaki 	workqueue_enqueue(ip6flow_slowtimo_wq, &ip6flow_slowtimo_wk, NULL);
    544      1.28     ozaki }
    545      1.28     ozaki 
    546       1.1  liamjfoy /*
    547       1.1  liamjfoy  * We have successfully forwarded a packet using the normal
    548       1.1  liamjfoy  * IPv6 stack. Now create/update a flow.
    549       1.1  liamjfoy  */
    550       1.1  liamjfoy void
    551  1.28.2.3  pgoyette ip6flow_create(struct route *ro, struct mbuf *m)
    552       1.1  liamjfoy {
    553      1.13    dyoung 	const struct ip6_hdr *ip6;
    554       1.1  liamjfoy 	struct ip6flow *ip6f;
    555       1.1  liamjfoy 	size_t hash;
    556       1.1  liamjfoy 
    557      1.13    dyoung 	ip6 = mtod(m, const struct ip6_hdr *);
    558       1.1  liamjfoy 
    559  1.28.2.2  pgoyette #ifndef NET_MPSAFE
    560  1.28.2.2  pgoyette 	KERNEL_LOCK(1, NULL);
    561  1.28.2.2  pgoyette #endif
    562  1.28.2.2  pgoyette 	mutex_enter(&ip6flow_lock);
    563  1.28.2.2  pgoyette 
    564       1.1  liamjfoy 	/*
    565       1.1  liamjfoy 	 * If IPv6 Fast Forward is disabled, don't create a flow.
    566       1.1  liamjfoy 	 * It can be disabled by setting net.inet6.ip6.maxflows to 0.
    567       1.1  liamjfoy 	 *
    568       1.1  liamjfoy 	 * Don't create a flow for ICMPv6 messages.
    569       1.1  liamjfoy 	 */
    570  1.28.2.2  pgoyette 	if (ip6_maxflows == 0 || ip6->ip6_nxt == IPPROTO_IPV6_ICMP)
    571  1.28.2.2  pgoyette 		goto out;
    572      1.22     pooka 
    573       1.1  liamjfoy 	/*
    574       1.1  liamjfoy 	 * See if an existing flow exists.  If so:
    575       1.1  liamjfoy 	 *	- Remove the flow
    576       1.1  liamjfoy 	 *	- Add flow statistics
    577       1.1  liamjfoy 	 *	- Free the route
    578       1.1  liamjfoy 	 *	- Reset statistics
    579       1.1  liamjfoy 	 *
    580       1.1  liamjfoy 	 * If a flow doesn't exist allocate a new one if
    581       1.1  liamjfoy 	 * ip6_maxflows hasn't reached its limit. If it has
    582       1.1  liamjfoy 	 * been reached, reap some flows.
    583       1.1  liamjfoy 	 */
    584       1.1  liamjfoy 	ip6f = ip6flow_lookup(ip6);
    585       1.1  liamjfoy 	if (ip6f == NULL) {
    586       1.1  liamjfoy 		if (ip6flow_inuse >= ip6_maxflows) {
    587      1.25  knakahar 			ip6f = ip6flow_reap_locked(1);
    588       1.1  liamjfoy 		} else {
    589       1.1  liamjfoy 			ip6f = pool_get(&ip6flow_pool, PR_NOWAIT);
    590       1.1  liamjfoy 			if (ip6f == NULL)
    591      1.22     pooka 				goto out;
    592       1.1  liamjfoy 			ip6flow_inuse++;
    593       1.1  liamjfoy 		}
    594       1.1  liamjfoy 		memset(ip6f, 0, sizeof(*ip6f));
    595       1.1  liamjfoy 	} else {
    596       1.1  liamjfoy 		IP6FLOW_REMOVE(ip6f);
    597      1.26  knakahar 
    598       1.1  liamjfoy 		ip6flow_addstats(ip6f);
    599       1.7    dyoung 		rtcache_free(&ip6f->ip6f_ro);
    600       1.1  liamjfoy 		ip6f->ip6f_uses = 0;
    601       1.1  liamjfoy 		ip6f->ip6f_last_uses = 0;
    602       1.1  liamjfoy 		ip6f->ip6f_dropped = 0;
    603       1.1  liamjfoy 		ip6f->ip6f_forwarded = 0;
    604       1.1  liamjfoy 	}
    605       1.1  liamjfoy 
    606       1.1  liamjfoy 	/*
    607       1.1  liamjfoy 	 * Fill in the updated/new details.
    608       1.1  liamjfoy 	 */
    609       1.7    dyoung 	rtcache_copy(&ip6f->ip6f_ro, ro);
    610       1.1  liamjfoy 	ip6f->ip6f_dst = ip6->ip6_dst;
    611       1.1  liamjfoy 	ip6f->ip6f_src = ip6->ip6_src;
    612       1.1  liamjfoy 	ip6f->ip6f_flow = ip6->ip6_flow;
    613       1.1  liamjfoy 	PRT_SLOW_ARM(ip6f->ip6f_timer, IP6FLOW_TIMER);
    614       1.1  liamjfoy 
    615       1.1  liamjfoy 	/*
    616       1.1  liamjfoy 	 * Insert into the approriate bucket of the flow table.
    617       1.1  liamjfoy 	 */
    618       1.1  liamjfoy 	hash = ip6flow_hash(ip6);
    619       1.1  liamjfoy 	IP6FLOW_INSERT(&ip6flowtable[hash], ip6f);
    620      1.22     pooka 
    621      1.22     pooka  out:
    622      1.25  knakahar 	mutex_exit(&ip6flow_lock);
    623  1.28.2.2  pgoyette #ifndef NET_MPSAFE
    624  1.28.2.2  pgoyette 	KERNEL_UNLOCK_ONE(NULL);
    625  1.28.2.2  pgoyette #endif
    626       1.1  liamjfoy }
    627       1.1  liamjfoy 
    628       1.1  liamjfoy /*
    629       1.4  liamjfoy  * Invalidate/remove all flows - if new_size is positive we
    630       1.4  liamjfoy  * resize the hash table.
    631       1.1  liamjfoy  */
    632       1.4  liamjfoy int
    633       1.4  liamjfoy ip6flow_invalidate_all(int new_size)
    634       1.1  liamjfoy {
    635       1.1  liamjfoy 	struct ip6flow *ip6f, *next_ip6f;
    636      1.26  knakahar 	int error;
    637       1.1  liamjfoy 
    638       1.4  liamjfoy 	error = 0;
    639      1.25  knakahar 
    640      1.25  knakahar 	mutex_enter(&ip6flow_lock);
    641      1.25  knakahar 
    642       1.1  liamjfoy 	for (ip6f = LIST_FIRST(&ip6flowlist); ip6f != NULL; ip6f = next_ip6f) {
    643       1.1  liamjfoy 		next_ip6f = LIST_NEXT(ip6f, ip6f_list);
    644       1.1  liamjfoy 		ip6flow_free(ip6f);
    645       1.1  liamjfoy 	}
    646       1.4  liamjfoy 
    647       1.4  liamjfoy 	if (new_size)
    648      1.25  knakahar 		error = ip6flow_init_locked(new_size);
    649       1.4  liamjfoy 
    650      1.25  knakahar 	mutex_exit(&ip6flow_lock);
    651      1.25  knakahar 
    652       1.4  liamjfoy 	return error;
    653       1.1  liamjfoy }
    654  1.28.2.1  pgoyette 
    655  1.28.2.1  pgoyette /*
    656  1.28.2.1  pgoyette  * sysctl helper routine for net.inet.ip6.maxflows. Since
    657  1.28.2.1  pgoyette  * we could reduce this value, call ip6flow_reap();
    658  1.28.2.1  pgoyette  */
    659  1.28.2.1  pgoyette static int
    660  1.28.2.1  pgoyette sysctl_net_inet6_ip6_maxflows(SYSCTLFN_ARGS)
    661  1.28.2.1  pgoyette {
    662  1.28.2.1  pgoyette 	int error;
    663  1.28.2.1  pgoyette 
    664  1.28.2.1  pgoyette 	error = sysctl_lookup(SYSCTLFN_CALL(rnode));
    665  1.28.2.1  pgoyette 	if (error || newp == NULL)
    666  1.28.2.1  pgoyette 		return (error);
    667  1.28.2.1  pgoyette 
    668  1.28.2.2  pgoyette #ifndef NET_MPSAFE
    669  1.28.2.1  pgoyette 	mutex_enter(softnet_lock);
    670  1.28.2.1  pgoyette 	KERNEL_LOCK(1, NULL);
    671  1.28.2.2  pgoyette #endif
    672  1.28.2.1  pgoyette 
    673  1.28.2.1  pgoyette 	ip6flow_reap(0);
    674  1.28.2.1  pgoyette 
    675  1.28.2.2  pgoyette #ifndef NET_MPSAFE
    676  1.28.2.1  pgoyette 	KERNEL_UNLOCK_ONE(NULL);
    677  1.28.2.1  pgoyette 	mutex_exit(softnet_lock);
    678  1.28.2.2  pgoyette #endif
    679  1.28.2.1  pgoyette 
    680  1.28.2.1  pgoyette 	return (0);
    681  1.28.2.1  pgoyette }
    682  1.28.2.1  pgoyette 
    683  1.28.2.1  pgoyette static int
    684  1.28.2.1  pgoyette sysctl_net_inet6_ip6_hashsize(SYSCTLFN_ARGS)
    685  1.28.2.1  pgoyette {
    686  1.28.2.1  pgoyette 	int error, tmp;
    687  1.28.2.1  pgoyette 	struct sysctlnode node;
    688  1.28.2.1  pgoyette 
    689  1.28.2.1  pgoyette 	node = *rnode;
    690  1.28.2.1  pgoyette 	tmp = ip6_hashsize;
    691  1.28.2.1  pgoyette 	node.sysctl_data = &tmp;
    692  1.28.2.1  pgoyette 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    693  1.28.2.1  pgoyette 	if (error || newp == NULL)
    694  1.28.2.1  pgoyette 		return (error);
    695  1.28.2.1  pgoyette 
    696  1.28.2.1  pgoyette 	if ((tmp & (tmp - 1)) == 0 && tmp != 0) {
    697  1.28.2.1  pgoyette 		/*
    698  1.28.2.1  pgoyette 		 * Can only fail due to malloc()
    699  1.28.2.1  pgoyette 		 */
    700  1.28.2.2  pgoyette #ifndef NET_MPSAFE
    701  1.28.2.1  pgoyette 		mutex_enter(softnet_lock);
    702  1.28.2.1  pgoyette 		KERNEL_LOCK(1, NULL);
    703  1.28.2.2  pgoyette #endif
    704  1.28.2.1  pgoyette 		error = ip6flow_invalidate_all(tmp);
    705  1.28.2.2  pgoyette #ifndef NET_MPSAFE
    706  1.28.2.1  pgoyette 		KERNEL_UNLOCK_ONE(NULL);
    707  1.28.2.1  pgoyette 		mutex_exit(softnet_lock);
    708  1.28.2.2  pgoyette #endif
    709  1.28.2.1  pgoyette 	} else {
    710  1.28.2.1  pgoyette 		/*
    711  1.28.2.1  pgoyette 		 * EINVAL if not a power of 2
    712  1.28.2.1  pgoyette 		 */
    713  1.28.2.1  pgoyette 		error = EINVAL;
    714  1.28.2.1  pgoyette 	}
    715  1.28.2.1  pgoyette 
    716  1.28.2.1  pgoyette 	return error;
    717  1.28.2.1  pgoyette }
    718  1.28.2.1  pgoyette 
    719  1.28.2.1  pgoyette static void
    720  1.28.2.1  pgoyette ip6flow_sysctl_init(struct sysctllog **clog)
    721  1.28.2.1  pgoyette {
    722  1.28.2.1  pgoyette 
    723  1.28.2.1  pgoyette 	sysctl_createv(clog, 0, NULL, NULL,
    724  1.28.2.1  pgoyette 		       CTLFLAG_PERMANENT,
    725  1.28.2.1  pgoyette 		       CTLTYPE_NODE, "inet6",
    726  1.28.2.1  pgoyette 		       SYSCTL_DESCR("PF_INET6 related settings"),
    727  1.28.2.1  pgoyette 		       NULL, 0, NULL, 0,
    728  1.28.2.1  pgoyette 		       CTL_NET, PF_INET6, CTL_EOL);
    729  1.28.2.1  pgoyette 	sysctl_createv(clog, 0, NULL, NULL,
    730  1.28.2.1  pgoyette 		       CTLFLAG_PERMANENT,
    731  1.28.2.1  pgoyette 		       CTLTYPE_NODE, "ip6",
    732  1.28.2.1  pgoyette 		       SYSCTL_DESCR("IPv6 related settings"),
    733  1.28.2.1  pgoyette 		       NULL, 0, NULL, 0,
    734  1.28.2.1  pgoyette 		       CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_EOL);
    735  1.28.2.1  pgoyette 
    736  1.28.2.1  pgoyette 	sysctl_createv(clog, 0, NULL, NULL,
    737  1.28.2.1  pgoyette 			CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    738  1.28.2.1  pgoyette 			CTLTYPE_INT, "maxflows",
    739  1.28.2.1  pgoyette 			SYSCTL_DESCR("Number of flows for fast forwarding (IPv6)"),
    740  1.28.2.1  pgoyette 			sysctl_net_inet6_ip6_maxflows, 0, &ip6_maxflows, 0,
    741  1.28.2.1  pgoyette 			CTL_NET, PF_INET6, IPPROTO_IPV6,
    742  1.28.2.1  pgoyette 			CTL_CREATE, CTL_EOL);
    743  1.28.2.1  pgoyette 	sysctl_createv(clog, 0, NULL, NULL,
    744  1.28.2.1  pgoyette 			CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    745  1.28.2.1  pgoyette 			CTLTYPE_INT, "hashsize",
    746  1.28.2.1  pgoyette 			SYSCTL_DESCR("Size of hash table for fast forwarding (IPv6)"),
    747  1.28.2.1  pgoyette 			sysctl_net_inet6_ip6_hashsize, 0, &ip6_hashsize, 0,
    748  1.28.2.1  pgoyette 			CTL_NET, PF_INET6, IPPROTO_IPV6,
    749  1.28.2.1  pgoyette 			CTL_CREATE, CTL_EOL);
    750  1.28.2.1  pgoyette }
    751