1c398230bSWarner Losh /*- 297d8d152SAndre Oppermann * Copyright (c) 2002 Andre Oppermann, Internet Business Solutions AG 397d8d152SAndre Oppermann * All rights reserved. 497d8d152SAndre Oppermann * 597d8d152SAndre Oppermann * Redistribution and use in source and binary forms, with or without 697d8d152SAndre Oppermann * modification, are permitted provided that the following conditions 797d8d152SAndre Oppermann * are met: 897d8d152SAndre Oppermann * 1. Redistributions of source code must retain the above copyright 997d8d152SAndre Oppermann * notice, this list of conditions and the following disclaimer. 1097d8d152SAndre Oppermann * 2. Redistributions in binary form must reproduce the above copyright 1197d8d152SAndre Oppermann * notice, this list of conditions and the following disclaimer in the 1297d8d152SAndre Oppermann * documentation and/or other materials provided with the distribution. 1397d8d152SAndre Oppermann * 3. The name of the author may not be used to endorse or promote 1497d8d152SAndre Oppermann * products derived from this software without specific prior written 1597d8d152SAndre Oppermann * permission. 1697d8d152SAndre Oppermann * 1797d8d152SAndre Oppermann * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1897d8d152SAndre Oppermann * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1997d8d152SAndre Oppermann * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2097d8d152SAndre Oppermann * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2197d8d152SAndre Oppermann * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2297d8d152SAndre Oppermann * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2397d8d152SAndre Oppermann * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2497d8d152SAndre Oppermann * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2597d8d152SAndre Oppermann * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2697d8d152SAndre Oppermann * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2797d8d152SAndre Oppermann * SUCH DAMAGE. 2897d8d152SAndre Oppermann */ 2997d8d152SAndre Oppermann 3097d8d152SAndre Oppermann /* 31e487a5e2SRobert Watson * The tcp_hostcache moves the tcp-specific cached metrics from the routing 32e487a5e2SRobert Watson * table to a dedicated structure indexed by the remote IP address. It keeps 33e487a5e2SRobert Watson * information on the measured TCP parameters of past TCP sessions to allow 34e487a5e2SRobert Watson * better initial start values to be used with later connections to/from the 3597d8d152SAndre Oppermann * same source. Depending on the network parameters (delay, bandwidth, max 36e487a5e2SRobert Watson * MTU, congestion window) between local and remote sites, this can lead to 37e487a5e2SRobert Watson * significant speed-ups for new TCP connections after the first one. 3897d8d152SAndre Oppermann * 39e487a5e2SRobert Watson * Due to the tcp_hostcache, all TCP-specific metrics information in the 40003c7e36SRui Paulo * routing table have been removed. The inpcb no longer keeps a pointer to 41e487a5e2SRobert Watson * the routing entry, and protocol-initiated route cloning has been removed 42e487a5e2SRobert Watson * as well. With these changes, the routing table has gone back to being 43e487a5e2SRobert Watson * more lightwight and only carries information related to packet forwarding. 4497d8d152SAndre Oppermann * 45e487a5e2SRobert Watson * tcp_hostcache is designed for multiple concurrent access in SMP 46e487a5e2SRobert Watson * environments and high contention. All bucket rows have their own lock and 47e487a5e2SRobert Watson * thus multiple lookups and modifies can be done at the same time as long as 48e487a5e2SRobert Watson * they are in different bucket rows. If a request for insertion of a new 49e487a5e2SRobert Watson * record can't be satisfied, it simply returns an empty structure. Nobody 50e487a5e2SRobert Watson * and nothing outside of tcp_hostcache.c will ever point directly to any 51e487a5e2SRobert Watson * entry in the tcp_hostcache. All communication is done in an 52e487a5e2SRobert Watson * object-oriented way and only functions of tcp_hostcache will manipulate 53e487a5e2SRobert Watson * hostcache entries. Otherwise, we are unable to achieve good behaviour in 54e487a5e2SRobert Watson * concurrent access situations. Since tcp_hostcache is only caching 55e487a5e2SRobert Watson * information, there are no fatal consequences if we either can't satisfy 56e487a5e2SRobert Watson * any particular request or have to drop/overwrite an existing entry because 57e487a5e2SRobert Watson * of bucket limit memory constrains. 5897d8d152SAndre Oppermann */ 5997d8d152SAndre Oppermann 6097d8d152SAndre Oppermann /* 6197d8d152SAndre Oppermann * Many thanks to jlemon for basic structure of tcp_syncache which is being 6297d8d152SAndre Oppermann * followed here. 6397d8d152SAndre Oppermann */ 6497d8d152SAndre Oppermann 654b421e2dSMike Silbersack #include <sys/cdefs.h> 664b421e2dSMike Silbersack __FBSDID("$FreeBSD$"); 674b421e2dSMike Silbersack 6897d8d152SAndre Oppermann #include "opt_inet6.h" 6997d8d152SAndre Oppermann 7097d8d152SAndre Oppermann #include <sys/param.h> 7197d8d152SAndre Oppermann #include <sys/systm.h> 7297d8d152SAndre Oppermann #include <sys/kernel.h> 7397d8d152SAndre Oppermann #include <sys/lock.h> 7497d8d152SAndre Oppermann #include <sys/mutex.h> 7597d8d152SAndre Oppermann #include <sys/malloc.h> 7697d8d152SAndre Oppermann #include <sys/socket.h> 7797d8d152SAndre Oppermann #include <sys/socketvar.h> 7897d8d152SAndre Oppermann #include <sys/sysctl.h> 7997d8d152SAndre Oppermann 8097d8d152SAndre Oppermann #include <net/if.h> 815736e6fbSBjoern A. Zeeb #include <net/route.h> 82530c0060SRobert Watson #include <net/vnet.h> 8397d8d152SAndre Oppermann 8497d8d152SAndre Oppermann #include <netinet/in.h> 8597d8d152SAndre Oppermann #include <netinet/in_systm.h> 8697d8d152SAndre Oppermann #include <netinet/ip.h> 8797d8d152SAndre Oppermann #include <netinet/in_var.h> 8897d8d152SAndre Oppermann #include <netinet/in_pcb.h> 8997d8d152SAndre Oppermann #include <netinet/ip_var.h> 9097d8d152SAndre Oppermann #ifdef INET6 9197d8d152SAndre Oppermann #include <netinet/ip6.h> 9297d8d152SAndre Oppermann #include <netinet6/ip6_var.h> 9397d8d152SAndre Oppermann #endif 9497d8d152SAndre Oppermann #include <netinet/tcp.h> 9597d8d152SAndre Oppermann #include <netinet/tcp_var.h> 964b79449eSBjoern A. Zeeb #include <netinet/tcp_hostcache.h> 9797d8d152SAndre Oppermann #ifdef INET6 9897d8d152SAndre Oppermann #include <netinet6/tcp6_var.h> 9997d8d152SAndre Oppermann #endif 10097d8d152SAndre Oppermann 10197d8d152SAndre Oppermann #include <vm/uma.h> 10297d8d152SAndre Oppermann 10397d8d152SAndre Oppermann /* Arbitrary values */ 10497d8d152SAndre Oppermann #define TCP_HOSTCACHE_HASHSIZE 512 10597d8d152SAndre Oppermann #define TCP_HOSTCACHE_BUCKETLIMIT 30 10697d8d152SAndre Oppermann #define TCP_HOSTCACHE_EXPIRE 60*60 /* one hour */ 10797d8d152SAndre Oppermann #define TCP_HOSTCACHE_PRUNE 5*60 /* every 5 minutes */ 10897d8d152SAndre Oppermann 109eddfbb76SRobert Watson static VNET_DEFINE(struct tcp_hostcache, tcp_hostcache); 110eddfbb76SRobert Watson static VNET_DEFINE(struct callout, tcp_hc_callout); 111eddfbb76SRobert Watson 1121e77c105SRobert Watson #define V_tcp_hostcache VNET(tcp_hostcache) 1131e77c105SRobert Watson #define V_tcp_hc_callout VNET(tcp_hc_callout) 11497d8d152SAndre Oppermann 11597d8d152SAndre Oppermann static struct hc_metrics *tcp_hc_lookup(struct in_conninfo *); 11697d8d152SAndre Oppermann static struct hc_metrics *tcp_hc_insert(struct in_conninfo *); 11797d8d152SAndre Oppermann static int sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS); 11897d8d152SAndre Oppermann static void tcp_hc_purge(void *); 11997d8d152SAndre Oppermann 1200eb7cf4dSBrooks Davis SYSCTL_NODE(_net_inet_tcp, OID_AUTO, hostcache, CTLFLAG_RW, 0, 1210eb7cf4dSBrooks Davis "TCP Host cache"); 12297d8d152SAndre Oppermann 123eddfbb76SRobert Watson SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, cachelimit, CTLFLAG_RDTUN, 124eddfbb76SRobert Watson &VNET_NAME(tcp_hostcache.cache_limit), 0, 1258b615593SMarko Zec "Overall entry limit for hostcache"); 12697d8d152SAndre Oppermann 127eddfbb76SRobert Watson SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, hashsize, CTLFLAG_RDTUN, 128eddfbb76SRobert Watson &VNET_NAME(tcp_hostcache.hashsize), 0, 1298b615593SMarko Zec "Size of TCP hostcache hashtable"); 13097d8d152SAndre Oppermann 131eddfbb76SRobert Watson SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, bucketlimit, 132eddfbb76SRobert Watson CTLFLAG_RDTUN, &VNET_NAME(tcp_hostcache.bucket_limit), 0, 1338b615593SMarko Zec "Per-bucket hash limit for hostcache"); 13497d8d152SAndre Oppermann 135eddfbb76SRobert Watson SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, count, CTLFLAG_RD, 136eddfbb76SRobert Watson &VNET_NAME(tcp_hostcache.cache_count), 0, 1378b615593SMarko Zec "Current number of entries in hostcache"); 13897d8d152SAndre Oppermann 139eddfbb76SRobert Watson SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, expire, CTLFLAG_RW, 140eddfbb76SRobert Watson &VNET_NAME(tcp_hostcache.expire), 0, 1418b615593SMarko Zec "Expire time of TCP hostcache entries"); 14297d8d152SAndre Oppermann 143eddfbb76SRobert Watson SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, prune, CTLFLAG_RW, 144eddfbb76SRobert Watson &VNET_NAME(tcp_hostcache.prune), 0, 145eddfbb76SRobert Watson "Time between purge runs"); 146dba3c508SYaroslav Tykhiy 147eddfbb76SRobert Watson SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, purge, CTLFLAG_RW, 148eddfbb76SRobert Watson &VNET_NAME(tcp_hostcache.purgeall), 0, 1498b615593SMarko Zec "Expire all entires on next purge run"); 15097d8d152SAndre Oppermann 15197d8d152SAndre Oppermann SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, list, 15297d8d152SAndre Oppermann CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_SKIP, 0, 0, 15397d8d152SAndre Oppermann sysctl_tcp_hc_list, "A", "List of all hostcache entries"); 15497d8d152SAndre Oppermann 15597d8d152SAndre Oppermann 15697d8d152SAndre Oppermann static MALLOC_DEFINE(M_HOSTCACHE, "hostcache", "TCP hostcache"); 15797d8d152SAndre Oppermann 15897d8d152SAndre Oppermann #define HOSTCACHE_HASH(ip) \ 15997d8d152SAndre Oppermann (((ip)->s_addr ^ ((ip)->s_addr >> 7) ^ ((ip)->s_addr >> 17)) & \ 160603724d3SBjoern A. Zeeb V_tcp_hostcache.hashmask) 16197d8d152SAndre Oppermann 16297d8d152SAndre Oppermann /* XXX: What is the recommended hash to get good entropy for IPv6 addresses? */ 16397d8d152SAndre Oppermann #define HOSTCACHE_HASH6(ip6) \ 16497d8d152SAndre Oppermann (((ip6)->s6_addr32[0] ^ \ 16597d8d152SAndre Oppermann (ip6)->s6_addr32[1] ^ \ 16697d8d152SAndre Oppermann (ip6)->s6_addr32[2] ^ \ 16797d8d152SAndre Oppermann (ip6)->s6_addr32[3]) & \ 168603724d3SBjoern A. Zeeb V_tcp_hostcache.hashmask) 16997d8d152SAndre Oppermann 17097d8d152SAndre Oppermann #define THC_LOCK(lp) mtx_lock(lp) 17197d8d152SAndre Oppermann #define THC_UNLOCK(lp) mtx_unlock(lp) 17297d8d152SAndre Oppermann 17397d8d152SAndre Oppermann void 17497d8d152SAndre Oppermann tcp_hc_init(void) 17597d8d152SAndre Oppermann { 17697d8d152SAndre Oppermann int i; 17797d8d152SAndre Oppermann 17897d8d152SAndre Oppermann /* 179e487a5e2SRobert Watson * Initialize hostcache structures. 18097d8d152SAndre Oppermann */ 181603724d3SBjoern A. Zeeb V_tcp_hostcache.cache_count = 0; 182603724d3SBjoern A. Zeeb V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; 183603724d3SBjoern A. Zeeb V_tcp_hostcache.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT; 184603724d3SBjoern A. Zeeb V_tcp_hostcache.cache_limit = 185603724d3SBjoern A. Zeeb V_tcp_hostcache.hashsize * V_tcp_hostcache.bucket_limit; 186603724d3SBjoern A. Zeeb V_tcp_hostcache.expire = TCP_HOSTCACHE_EXPIRE; 187603724d3SBjoern A. Zeeb V_tcp_hostcache.prune = TCP_HOSTCACHE_PRUNE; 18897d8d152SAndre Oppermann 18997d8d152SAndre Oppermann TUNABLE_INT_FETCH("net.inet.tcp.hostcache.hashsize", 190603724d3SBjoern A. Zeeb &V_tcp_hostcache.hashsize); 19197d8d152SAndre Oppermann TUNABLE_INT_FETCH("net.inet.tcp.hostcache.cachelimit", 192603724d3SBjoern A. Zeeb &V_tcp_hostcache.cache_limit); 19397d8d152SAndre Oppermann TUNABLE_INT_FETCH("net.inet.tcp.hostcache.bucketlimit", 194603724d3SBjoern A. Zeeb &V_tcp_hostcache.bucket_limit); 195603724d3SBjoern A. Zeeb if (!powerof2(V_tcp_hostcache.hashsize)) { 19697d8d152SAndre Oppermann printf("WARNING: hostcache hash size is not a power of 2.\n"); 197603724d3SBjoern A. Zeeb V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; /* default */ 19897d8d152SAndre Oppermann } 199603724d3SBjoern A. Zeeb V_tcp_hostcache.hashmask = V_tcp_hostcache.hashsize - 1; 20097d8d152SAndre Oppermann 20197d8d152SAndre Oppermann /* 202e487a5e2SRobert Watson * Allocate the hash table. 20397d8d152SAndre Oppermann */ 204603724d3SBjoern A. Zeeb V_tcp_hostcache.hashbase = (struct hc_head *) 205603724d3SBjoern A. Zeeb malloc(V_tcp_hostcache.hashsize * sizeof(struct hc_head), 20697d8d152SAndre Oppermann M_HOSTCACHE, M_WAITOK | M_ZERO); 20797d8d152SAndre Oppermann 20897d8d152SAndre Oppermann /* 209e487a5e2SRobert Watson * Initialize the hash buckets. 21097d8d152SAndre Oppermann */ 211603724d3SBjoern A. Zeeb for (i = 0; i < V_tcp_hostcache.hashsize; i++) { 212603724d3SBjoern A. Zeeb TAILQ_INIT(&V_tcp_hostcache.hashbase[i].hch_bucket); 213603724d3SBjoern A. Zeeb V_tcp_hostcache.hashbase[i].hch_length = 0; 214603724d3SBjoern A. Zeeb mtx_init(&V_tcp_hostcache.hashbase[i].hch_mtx, "tcp_hc_entry", 21597d8d152SAndre Oppermann NULL, MTX_DEF); 21697d8d152SAndre Oppermann } 21797d8d152SAndre Oppermann 21897d8d152SAndre Oppermann /* 21997d8d152SAndre Oppermann * Allocate the hostcache entries. 22097d8d152SAndre Oppermann */ 221ac957cd2SJulian Elischer V_tcp_hostcache.zone = 222ac957cd2SJulian Elischer uma_zcreate("hostcache", sizeof(struct hc_metrics), 2234efb805cSAndre Oppermann NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); 224603724d3SBjoern A. Zeeb uma_zone_set_max(V_tcp_hostcache.zone, V_tcp_hostcache.cache_limit); 22597d8d152SAndre Oppermann 22697d8d152SAndre Oppermann /* 22797d8d152SAndre Oppermann * Set up periodic cache cleanup. 22897d8d152SAndre Oppermann */ 229603724d3SBjoern A. Zeeb callout_init(&V_tcp_hc_callout, CALLOUT_MPSAFE); 230ac957cd2SJulian Elischer callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz, 23121ca7b57SMarko Zec tcp_hc_purge, curvnet); 23297d8d152SAndre Oppermann } 23397d8d152SAndre Oppermann 234bc29160dSMarko Zec #ifdef VIMAGE 235bc29160dSMarko Zec void 236bc29160dSMarko Zec tcp_hc_destroy(void) 237bc29160dSMarko Zec { 238bc29160dSMarko Zec 239bc29160dSMarko Zec /* XXX TODO walk the hashtable and free all entries */ 240bc29160dSMarko Zec 241bc29160dSMarko Zec callout_drain(&V_tcp_hc_callout); 242bc29160dSMarko Zec } 243bc29160dSMarko Zec #endif 244bc29160dSMarko Zec 24597d8d152SAndre Oppermann /* 24697d8d152SAndre Oppermann * Internal function: look up an entry in the hostcache or return NULL. 24797d8d152SAndre Oppermann * 24897d8d152SAndre Oppermann * If an entry has been returned, the caller becomes responsible for 24997d8d152SAndre Oppermann * unlocking the bucket row after he is done reading/modifying the entry. 25097d8d152SAndre Oppermann */ 25197d8d152SAndre Oppermann static struct hc_metrics * 25297d8d152SAndre Oppermann tcp_hc_lookup(struct in_conninfo *inc) 25397d8d152SAndre Oppermann { 25497d8d152SAndre Oppermann int hash; 25597d8d152SAndre Oppermann struct hc_head *hc_head; 25697d8d152SAndre Oppermann struct hc_metrics *hc_entry; 25797d8d152SAndre Oppermann 25897d8d152SAndre Oppermann KASSERT(inc != NULL, ("tcp_hc_lookup with NULL in_conninfo pointer")); 25997d8d152SAndre Oppermann 26097d8d152SAndre Oppermann /* 26197d8d152SAndre Oppermann * Hash the foreign ip address. 26297d8d152SAndre Oppermann */ 263dcdb4371SBjoern A. Zeeb if (inc->inc_flags & INC_ISIPV6) 26497d8d152SAndre Oppermann hash = HOSTCACHE_HASH6(&inc->inc6_faddr); 26597d8d152SAndre Oppermann else 26697d8d152SAndre Oppermann hash = HOSTCACHE_HASH(&inc->inc_faddr); 26797d8d152SAndre Oppermann 268603724d3SBjoern A. Zeeb hc_head = &V_tcp_hostcache.hashbase[hash]; 26997d8d152SAndre Oppermann 27097d8d152SAndre Oppermann /* 271e487a5e2SRobert Watson * Acquire lock for this bucket row; we release the lock if we don't 272e487a5e2SRobert Watson * find an entry, otherwise the caller has to unlock after he is 273e487a5e2SRobert Watson * done. 27497d8d152SAndre Oppermann */ 27597d8d152SAndre Oppermann THC_LOCK(&hc_head->hch_mtx); 27697d8d152SAndre Oppermann 27797d8d152SAndre Oppermann /* 278e487a5e2SRobert Watson * Iterate through entries in bucket row looking for a match. 27997d8d152SAndre Oppermann */ 28097d8d152SAndre Oppermann TAILQ_FOREACH(hc_entry, &hc_head->hch_bucket, rmx_q) { 281dcdb4371SBjoern A. Zeeb if (inc->inc_flags & INC_ISIPV6) { 28297d8d152SAndre Oppermann if (memcmp(&inc->inc6_faddr, &hc_entry->ip6, 28397d8d152SAndre Oppermann sizeof(inc->inc6_faddr)) == 0) 28497d8d152SAndre Oppermann return hc_entry; 28597d8d152SAndre Oppermann } else { 28697d8d152SAndre Oppermann if (memcmp(&inc->inc_faddr, &hc_entry->ip4, 28797d8d152SAndre Oppermann sizeof(inc->inc_faddr)) == 0) 28897d8d152SAndre Oppermann return hc_entry; 28997d8d152SAndre Oppermann } 29097d8d152SAndre Oppermann } 29197d8d152SAndre Oppermann 29297d8d152SAndre Oppermann /* 293e487a5e2SRobert Watson * We were unsuccessful and didn't find anything. 29497d8d152SAndre Oppermann */ 29597d8d152SAndre Oppermann THC_UNLOCK(&hc_head->hch_mtx); 29697d8d152SAndre Oppermann return NULL; 29797d8d152SAndre Oppermann } 29897d8d152SAndre Oppermann 29997d8d152SAndre Oppermann /* 300e487a5e2SRobert Watson * Internal function: insert an entry into the hostcache or return NULL if 301e487a5e2SRobert Watson * unable to allocate a new one. 30297d8d152SAndre Oppermann * 30397d8d152SAndre Oppermann * If an entry has been returned, the caller becomes responsible for 30497d8d152SAndre Oppermann * unlocking the bucket row after he is done reading/modifying the entry. 30597d8d152SAndre Oppermann */ 30697d8d152SAndre Oppermann static struct hc_metrics * 30797d8d152SAndre Oppermann tcp_hc_insert(struct in_conninfo *inc) 30897d8d152SAndre Oppermann { 30997d8d152SAndre Oppermann int hash; 31097d8d152SAndre Oppermann struct hc_head *hc_head; 31197d8d152SAndre Oppermann struct hc_metrics *hc_entry; 31297d8d152SAndre Oppermann 31397d8d152SAndre Oppermann KASSERT(inc != NULL, ("tcp_hc_insert with NULL in_conninfo pointer")); 31497d8d152SAndre Oppermann 31597d8d152SAndre Oppermann /* 316e487a5e2SRobert Watson * Hash the foreign ip address. 31797d8d152SAndre Oppermann */ 318dcdb4371SBjoern A. Zeeb if (inc->inc_flags & INC_ISIPV6) 31997d8d152SAndre Oppermann hash = HOSTCACHE_HASH6(&inc->inc6_faddr); 32097d8d152SAndre Oppermann else 32197d8d152SAndre Oppermann hash = HOSTCACHE_HASH(&inc->inc_faddr); 32297d8d152SAndre Oppermann 323603724d3SBjoern A. Zeeb hc_head = &V_tcp_hostcache.hashbase[hash]; 32497d8d152SAndre Oppermann 32597d8d152SAndre Oppermann /* 326e487a5e2SRobert Watson * Acquire lock for this bucket row; we release the lock if we don't 327e487a5e2SRobert Watson * find an entry, otherwise the caller has to unlock after he is 328e487a5e2SRobert Watson * done. 32997d8d152SAndre Oppermann */ 33097d8d152SAndre Oppermann THC_LOCK(&hc_head->hch_mtx); 33197d8d152SAndre Oppermann 33297d8d152SAndre Oppermann /* 333e487a5e2SRobert Watson * If the bucket limit is reached, reuse the least-used element. 33497d8d152SAndre Oppermann */ 335603724d3SBjoern A. Zeeb if (hc_head->hch_length >= V_tcp_hostcache.bucket_limit || 336603724d3SBjoern A. Zeeb V_tcp_hostcache.cache_count >= V_tcp_hostcache.cache_limit) { 33797d8d152SAndre Oppermann hc_entry = TAILQ_LAST(&hc_head->hch_bucket, hc_qhead); 33897d8d152SAndre Oppermann /* 33997d8d152SAndre Oppermann * At first we were dropping the last element, just to 340e487a5e2SRobert Watson * reacquire it in the next two lines again, which isn't very 341e487a5e2SRobert Watson * efficient. Instead just reuse the least used element. 342e487a5e2SRobert Watson * We may drop something that is still "in-use" but we can be 343e487a5e2SRobert Watson * "lossy". 34445024be0SAndre Oppermann * Just give up if this bucket row is empty and we don't have 34545024be0SAndre Oppermann * anything to replace. 34697d8d152SAndre Oppermann */ 34745024be0SAndre Oppermann if (hc_entry == NULL) { 34845024be0SAndre Oppermann THC_UNLOCK(&hc_head->hch_mtx); 34945024be0SAndre Oppermann return NULL; 35045024be0SAndre Oppermann } 35197d8d152SAndre Oppermann TAILQ_REMOVE(&hc_head->hch_bucket, hc_entry, rmx_q); 352603724d3SBjoern A. Zeeb V_tcp_hostcache.hashbase[hash].hch_length--; 353603724d3SBjoern A. Zeeb V_tcp_hostcache.cache_count--; 35478b50714SRobert Watson TCPSTAT_INC(tcps_hc_bucketoverflow); 355cd6c4060SAndre Oppermann #if 0 356603724d3SBjoern A. Zeeb uma_zfree(V_tcp_hostcache.zone, hc_entry); 357cd6c4060SAndre Oppermann #endif 35897d8d152SAndre Oppermann } else { 35997d8d152SAndre Oppermann /* 360e487a5e2SRobert Watson * Allocate a new entry, or balk if not possible. 36197d8d152SAndre Oppermann */ 362603724d3SBjoern A. Zeeb hc_entry = uma_zalloc(V_tcp_hostcache.zone, M_NOWAIT); 36397d8d152SAndre Oppermann if (hc_entry == NULL) { 36497d8d152SAndre Oppermann THC_UNLOCK(&hc_head->hch_mtx); 36597d8d152SAndre Oppermann return NULL; 36697d8d152SAndre Oppermann } 36797d8d152SAndre Oppermann } 36897d8d152SAndre Oppermann 36997d8d152SAndre Oppermann /* 370e487a5e2SRobert Watson * Initialize basic information of hostcache entry. 37197d8d152SAndre Oppermann */ 37297d8d152SAndre Oppermann bzero(hc_entry, sizeof(*hc_entry)); 373dcdb4371SBjoern A. Zeeb if (inc->inc_flags & INC_ISIPV6) 374f5bd8e9aSAndre Oppermann bcopy(&inc->inc6_faddr, &hc_entry->ip6, sizeof(hc_entry->ip6)); 37597d8d152SAndre Oppermann else 37697d8d152SAndre Oppermann hc_entry->ip4 = inc->inc_faddr; 37797d8d152SAndre Oppermann hc_entry->rmx_head = hc_head; 378603724d3SBjoern A. Zeeb hc_entry->rmx_expire = V_tcp_hostcache.expire; 37997d8d152SAndre Oppermann 38097d8d152SAndre Oppermann /* 381e487a5e2SRobert Watson * Put it upfront. 38297d8d152SAndre Oppermann */ 38397d8d152SAndre Oppermann TAILQ_INSERT_HEAD(&hc_head->hch_bucket, hc_entry, rmx_q); 384603724d3SBjoern A. Zeeb V_tcp_hostcache.hashbase[hash].hch_length++; 385603724d3SBjoern A. Zeeb V_tcp_hostcache.cache_count++; 38678b50714SRobert Watson TCPSTAT_INC(tcps_hc_added); 38797d8d152SAndre Oppermann 38897d8d152SAndre Oppermann return hc_entry; 38997d8d152SAndre Oppermann } 39097d8d152SAndre Oppermann 39197d8d152SAndre Oppermann /* 39297d8d152SAndre Oppermann * External function: look up an entry in the hostcache and fill out the 393e487a5e2SRobert Watson * supplied TCP metrics structure. Fills in NULL when no entry was found or 394e487a5e2SRobert Watson * a value is not set. 39597d8d152SAndre Oppermann */ 39697d8d152SAndre Oppermann void 39797d8d152SAndre Oppermann tcp_hc_get(struct in_conninfo *inc, struct hc_metrics_lite *hc_metrics_lite) 39897d8d152SAndre Oppermann { 39997d8d152SAndre Oppermann struct hc_metrics *hc_entry; 40097d8d152SAndre Oppermann 40197d8d152SAndre Oppermann /* 402e487a5e2SRobert Watson * Find the right bucket. 40397d8d152SAndre Oppermann */ 40497d8d152SAndre Oppermann hc_entry = tcp_hc_lookup(inc); 40597d8d152SAndre Oppermann 40697d8d152SAndre Oppermann /* 407e487a5e2SRobert Watson * If we don't have an existing object. 40897d8d152SAndre Oppermann */ 40997d8d152SAndre Oppermann if (hc_entry == NULL) { 41097d8d152SAndre Oppermann bzero(hc_metrics_lite, sizeof(*hc_metrics_lite)); 41197d8d152SAndre Oppermann return; 41297d8d152SAndre Oppermann } 41397d8d152SAndre Oppermann hc_entry->rmx_hits++; 414603724d3SBjoern A. Zeeb hc_entry->rmx_expire = V_tcp_hostcache.expire; /* start over again */ 41597d8d152SAndre Oppermann 41697d8d152SAndre Oppermann hc_metrics_lite->rmx_mtu = hc_entry->rmx_mtu; 41797d8d152SAndre Oppermann hc_metrics_lite->rmx_ssthresh = hc_entry->rmx_ssthresh; 41897d8d152SAndre Oppermann hc_metrics_lite->rmx_rtt = hc_entry->rmx_rtt; 41997d8d152SAndre Oppermann hc_metrics_lite->rmx_rttvar = hc_entry->rmx_rttvar; 42097d8d152SAndre Oppermann hc_metrics_lite->rmx_bandwidth = hc_entry->rmx_bandwidth; 42197d8d152SAndre Oppermann hc_metrics_lite->rmx_cwnd = hc_entry->rmx_cwnd; 42297d8d152SAndre Oppermann hc_metrics_lite->rmx_sendpipe = hc_entry->rmx_sendpipe; 42397d8d152SAndre Oppermann hc_metrics_lite->rmx_recvpipe = hc_entry->rmx_recvpipe; 42497d8d152SAndre Oppermann 42597d8d152SAndre Oppermann /* 426e487a5e2SRobert Watson * Unlock bucket row. 42797d8d152SAndre Oppermann */ 42897d8d152SAndre Oppermann THC_UNLOCK(&hc_entry->rmx_head->hch_mtx); 42997d8d152SAndre Oppermann } 43097d8d152SAndre Oppermann 43197d8d152SAndre Oppermann /* 43297d8d152SAndre Oppermann * External function: look up an entry in the hostcache and return the 433e487a5e2SRobert Watson * discovered path MTU. Returns NULL if no entry is found or value is not 4346fbed4afSRobert Watson * set. 43597d8d152SAndre Oppermann */ 43697d8d152SAndre Oppermann u_long 43797d8d152SAndre Oppermann tcp_hc_getmtu(struct in_conninfo *inc) 43897d8d152SAndre Oppermann { 43997d8d152SAndre Oppermann struct hc_metrics *hc_entry; 44097d8d152SAndre Oppermann u_long mtu; 44197d8d152SAndre Oppermann 44297d8d152SAndre Oppermann hc_entry = tcp_hc_lookup(inc); 44397d8d152SAndre Oppermann if (hc_entry == NULL) { 44497d8d152SAndre Oppermann return 0; 44597d8d152SAndre Oppermann } 44697d8d152SAndre Oppermann hc_entry->rmx_hits++; 447603724d3SBjoern A. Zeeb hc_entry->rmx_expire = V_tcp_hostcache.expire; /* start over again */ 44897d8d152SAndre Oppermann 44997d8d152SAndre Oppermann mtu = hc_entry->rmx_mtu; 45097d8d152SAndre Oppermann THC_UNLOCK(&hc_entry->rmx_head->hch_mtx); 45197d8d152SAndre Oppermann return mtu; 45297d8d152SAndre Oppermann } 45397d8d152SAndre Oppermann 45497d8d152SAndre Oppermann /* 455e487a5e2SRobert Watson * External function: update the MTU value of an entry in the hostcache. 45697d8d152SAndre Oppermann * Creates a new entry if none was found. 45797d8d152SAndre Oppermann */ 45897d8d152SAndre Oppermann void 45997d8d152SAndre Oppermann tcp_hc_updatemtu(struct in_conninfo *inc, u_long mtu) 46097d8d152SAndre Oppermann { 46197d8d152SAndre Oppermann struct hc_metrics *hc_entry; 46297d8d152SAndre Oppermann 46397d8d152SAndre Oppermann /* 464e487a5e2SRobert Watson * Find the right bucket. 46597d8d152SAndre Oppermann */ 46697d8d152SAndre Oppermann hc_entry = tcp_hc_lookup(inc); 46797d8d152SAndre Oppermann 46897d8d152SAndre Oppermann /* 469e487a5e2SRobert Watson * If we don't have an existing object, try to insert a new one. 47097d8d152SAndre Oppermann */ 47197d8d152SAndre Oppermann if (hc_entry == NULL) { 47297d8d152SAndre Oppermann hc_entry = tcp_hc_insert(inc); 47397d8d152SAndre Oppermann if (hc_entry == NULL) 47497d8d152SAndre Oppermann return; 47597d8d152SAndre Oppermann } 47697d8d152SAndre Oppermann hc_entry->rmx_updates++; 477603724d3SBjoern A. Zeeb hc_entry->rmx_expire = V_tcp_hostcache.expire; /* start over again */ 47897d8d152SAndre Oppermann 47997d8d152SAndre Oppermann hc_entry->rmx_mtu = mtu; 48097d8d152SAndre Oppermann 48197d8d152SAndre Oppermann /* 482e487a5e2SRobert Watson * Put it upfront so we find it faster next time. 48397d8d152SAndre Oppermann */ 48497d8d152SAndre Oppermann TAILQ_REMOVE(&hc_entry->rmx_head->hch_bucket, hc_entry, rmx_q); 48597d8d152SAndre Oppermann TAILQ_INSERT_HEAD(&hc_entry->rmx_head->hch_bucket, hc_entry, rmx_q); 48697d8d152SAndre Oppermann 48797d8d152SAndre Oppermann /* 488e487a5e2SRobert Watson * Unlock bucket row. 48997d8d152SAndre Oppermann */ 49097d8d152SAndre Oppermann THC_UNLOCK(&hc_entry->rmx_head->hch_mtx); 49197d8d152SAndre Oppermann } 49297d8d152SAndre Oppermann 49397d8d152SAndre Oppermann /* 494e487a5e2SRobert Watson * External function: update the TCP metrics of an entry in the hostcache. 49597d8d152SAndre Oppermann * Creates a new entry if none was found. 49697d8d152SAndre Oppermann */ 49797d8d152SAndre Oppermann void 49897d8d152SAndre Oppermann tcp_hc_update(struct in_conninfo *inc, struct hc_metrics_lite *hcml) 49997d8d152SAndre Oppermann { 50097d8d152SAndre Oppermann struct hc_metrics *hc_entry; 50197d8d152SAndre Oppermann 50297d8d152SAndre Oppermann hc_entry = tcp_hc_lookup(inc); 50397d8d152SAndre Oppermann if (hc_entry == NULL) { 50497d8d152SAndre Oppermann hc_entry = tcp_hc_insert(inc); 50597d8d152SAndre Oppermann if (hc_entry == NULL) 50697d8d152SAndre Oppermann return; 50797d8d152SAndre Oppermann } 50897d8d152SAndre Oppermann hc_entry->rmx_updates++; 509603724d3SBjoern A. Zeeb hc_entry->rmx_expire = V_tcp_hostcache.expire; /* start over again */ 51097d8d152SAndre Oppermann 51197d8d152SAndre Oppermann if (hcml->rmx_rtt != 0) { 51297d8d152SAndre Oppermann if (hc_entry->rmx_rtt == 0) 51397d8d152SAndre Oppermann hc_entry->rmx_rtt = hcml->rmx_rtt; 51497d8d152SAndre Oppermann else 51597d8d152SAndre Oppermann hc_entry->rmx_rtt = 51697d8d152SAndre Oppermann (hc_entry->rmx_rtt + hcml->rmx_rtt) / 2; 51778b50714SRobert Watson TCPSTAT_INC(tcps_cachedrtt); 51897d8d152SAndre Oppermann } 51997d8d152SAndre Oppermann if (hcml->rmx_rttvar != 0) { 52097d8d152SAndre Oppermann if (hc_entry->rmx_rttvar == 0) 52197d8d152SAndre Oppermann hc_entry->rmx_rttvar = hcml->rmx_rttvar; 52297d8d152SAndre Oppermann else 52397d8d152SAndre Oppermann hc_entry->rmx_rttvar = 52497d8d152SAndre Oppermann (hc_entry->rmx_rttvar + hcml->rmx_rttvar) / 2; 52578b50714SRobert Watson TCPSTAT_INC(tcps_cachedrttvar); 52697d8d152SAndre Oppermann } 52797d8d152SAndre Oppermann if (hcml->rmx_ssthresh != 0) { 52897d8d152SAndre Oppermann if (hc_entry->rmx_ssthresh == 0) 52997d8d152SAndre Oppermann hc_entry->rmx_ssthresh = hcml->rmx_ssthresh; 53097d8d152SAndre Oppermann else 53197d8d152SAndre Oppermann hc_entry->rmx_ssthresh = 53297d8d152SAndre Oppermann (hc_entry->rmx_ssthresh + hcml->rmx_ssthresh) / 2; 53378b50714SRobert Watson TCPSTAT_INC(tcps_cachedssthresh); 53497d8d152SAndre Oppermann } 53597d8d152SAndre Oppermann if (hcml->rmx_bandwidth != 0) { 53697d8d152SAndre Oppermann if (hc_entry->rmx_bandwidth == 0) 53797d8d152SAndre Oppermann hc_entry->rmx_bandwidth = hcml->rmx_bandwidth; 53897d8d152SAndre Oppermann else 53997d8d152SAndre Oppermann hc_entry->rmx_bandwidth = 54097d8d152SAndre Oppermann (hc_entry->rmx_bandwidth + hcml->rmx_bandwidth) / 2; 54178b50714SRobert Watson /* TCPSTAT_INC(tcps_cachedbandwidth); */ 54297d8d152SAndre Oppermann } 54397d8d152SAndre Oppermann if (hcml->rmx_cwnd != 0) { 54497d8d152SAndre Oppermann if (hc_entry->rmx_cwnd == 0) 54597d8d152SAndre Oppermann hc_entry->rmx_cwnd = hcml->rmx_cwnd; 54697d8d152SAndre Oppermann else 54797d8d152SAndre Oppermann hc_entry->rmx_cwnd = 54897d8d152SAndre Oppermann (hc_entry->rmx_cwnd + hcml->rmx_cwnd) / 2; 54978b50714SRobert Watson /* TCPSTAT_INC(tcps_cachedcwnd); */ 55097d8d152SAndre Oppermann } 55197d8d152SAndre Oppermann if (hcml->rmx_sendpipe != 0) { 55297d8d152SAndre Oppermann if (hc_entry->rmx_sendpipe == 0) 55397d8d152SAndre Oppermann hc_entry->rmx_sendpipe = hcml->rmx_sendpipe; 55497d8d152SAndre Oppermann else 55597d8d152SAndre Oppermann hc_entry->rmx_sendpipe = 55697d8d152SAndre Oppermann (hc_entry->rmx_sendpipe + hcml->rmx_sendpipe) /2; 55778b50714SRobert Watson /* TCPSTAT_INC(tcps_cachedsendpipe); */ 55897d8d152SAndre Oppermann } 55997d8d152SAndre Oppermann if (hcml->rmx_recvpipe != 0) { 56097d8d152SAndre Oppermann if (hc_entry->rmx_recvpipe == 0) 56197d8d152SAndre Oppermann hc_entry->rmx_recvpipe = hcml->rmx_recvpipe; 56297d8d152SAndre Oppermann else 56397d8d152SAndre Oppermann hc_entry->rmx_recvpipe = 56497d8d152SAndre Oppermann (hc_entry->rmx_recvpipe + hcml->rmx_recvpipe) /2; 56578b50714SRobert Watson /* TCPSTAT_INC(tcps_cachedrecvpipe); */ 56697d8d152SAndre Oppermann } 56797d8d152SAndre Oppermann 56897d8d152SAndre Oppermann TAILQ_REMOVE(&hc_entry->rmx_head->hch_bucket, hc_entry, rmx_q); 56997d8d152SAndre Oppermann TAILQ_INSERT_HEAD(&hc_entry->rmx_head->hch_bucket, hc_entry, rmx_q); 57097d8d152SAndre Oppermann THC_UNLOCK(&hc_entry->rmx_head->hch_mtx); 57197d8d152SAndre Oppermann } 57297d8d152SAndre Oppermann 57397d8d152SAndre Oppermann /* 57497d8d152SAndre Oppermann * Sysctl function: prints the list and values of all hostcache entries in 57597d8d152SAndre Oppermann * unsorted order. 57697d8d152SAndre Oppermann */ 57797d8d152SAndre Oppermann static int 57897d8d152SAndre Oppermann sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) 57997d8d152SAndre Oppermann { 58097d8d152SAndre Oppermann int bufsize; 58197d8d152SAndre Oppermann int linesize = 128; 58297d8d152SAndre Oppermann char *p, *buf; 58397d8d152SAndre Oppermann int len, i, error; 58497d8d152SAndre Oppermann struct hc_metrics *hc_entry; 5851d54aa3bSBjoern A. Zeeb #ifdef INET6 5861d54aa3bSBjoern A. Zeeb char ip6buf[INET6_ADDRSTRLEN]; 5871d54aa3bSBjoern A. Zeeb #endif 58897d8d152SAndre Oppermann 589603724d3SBjoern A. Zeeb bufsize = linesize * (V_tcp_hostcache.cache_count + 1); 59097d8d152SAndre Oppermann 59197d8d152SAndre Oppermann p = buf = (char *)malloc(bufsize, M_TEMP, M_WAITOK|M_ZERO); 59297d8d152SAndre Oppermann 59397d8d152SAndre Oppermann len = snprintf(p, linesize, 59497d8d152SAndre Oppermann "\nIP address MTU SSTRESH RTT RTTVAR BANDWIDTH " 59597d8d152SAndre Oppermann " CWND SENDPIPE RECVPIPE HITS UPD EXP\n"); 59697d8d152SAndre Oppermann p += len; 59797d8d152SAndre Oppermann 59897d8d152SAndre Oppermann #define msec(u) (((u) + 500) / 1000) 599603724d3SBjoern A. Zeeb for (i = 0; i < V_tcp_hostcache.hashsize; i++) { 600603724d3SBjoern A. Zeeb THC_LOCK(&V_tcp_hostcache.hashbase[i].hch_mtx); 601603724d3SBjoern A. Zeeb TAILQ_FOREACH(hc_entry, &V_tcp_hostcache.hashbase[i].hch_bucket, 60297d8d152SAndre Oppermann rmx_q) { 60397d8d152SAndre Oppermann len = snprintf(p, linesize, 60497d8d152SAndre Oppermann "%-15s %5lu %8lu %6lums %6lums %9lu %8lu %8lu %8lu " 60597d8d152SAndre Oppermann "%4lu %4lu %4i\n", 60697d8d152SAndre Oppermann hc_entry->ip4.s_addr ? inet_ntoa(hc_entry->ip4) : 60797d8d152SAndre Oppermann #ifdef INET6 6081d54aa3bSBjoern A. Zeeb ip6_sprintf(ip6buf, &hc_entry->ip6), 60997d8d152SAndre Oppermann #else 61097d8d152SAndre Oppermann "IPv6?", 61197d8d152SAndre Oppermann #endif 61297d8d152SAndre Oppermann hc_entry->rmx_mtu, 61397d8d152SAndre Oppermann hc_entry->rmx_ssthresh, 61497d8d152SAndre Oppermann msec(hc_entry->rmx_rtt * 61597d8d152SAndre Oppermann (RTM_RTTUNIT / (hz * TCP_RTT_SCALE))), 61697d8d152SAndre Oppermann msec(hc_entry->rmx_rttvar * 61797d8d152SAndre Oppermann (RTM_RTTUNIT / (hz * TCP_RTT_SCALE))), 6182f6e6e9bSAndre Oppermann hc_entry->rmx_bandwidth * 8, 61997d8d152SAndre Oppermann hc_entry->rmx_cwnd, 62097d8d152SAndre Oppermann hc_entry->rmx_sendpipe, 62197d8d152SAndre Oppermann hc_entry->rmx_recvpipe, 62297d8d152SAndre Oppermann hc_entry->rmx_hits, 62397d8d152SAndre Oppermann hc_entry->rmx_updates, 62497d8d152SAndre Oppermann hc_entry->rmx_expire); 62597d8d152SAndre Oppermann p += len; 62697d8d152SAndre Oppermann } 627603724d3SBjoern A. Zeeb THC_UNLOCK(&V_tcp_hostcache.hashbase[i].hch_mtx); 62897d8d152SAndre Oppermann } 62997d8d152SAndre Oppermann #undef msec 63097d8d152SAndre Oppermann error = SYSCTL_OUT(req, buf, p - buf); 63197d8d152SAndre Oppermann free(buf, M_TEMP); 63297d8d152SAndre Oppermann return(error); 63397d8d152SAndre Oppermann } 63497d8d152SAndre Oppermann 63597d8d152SAndre Oppermann /* 636e487a5e2SRobert Watson * Expire and purge (old|all) entries in the tcp_hostcache. Runs 637e487a5e2SRobert Watson * periodically from the callout. 63897d8d152SAndre Oppermann */ 63997d8d152SAndre Oppermann static void 64097d8d152SAndre Oppermann tcp_hc_purge(void *arg) 64197d8d152SAndre Oppermann { 64221ca7b57SMarko Zec CURVNET_SET((struct vnet *) arg); 643b62dccc7SAndre Oppermann struct hc_metrics *hc_entry, *hc_next; 6442114e063SMarko Zec int all = 0; 64597d8d152SAndre Oppermann int i; 64697d8d152SAndre Oppermann 647603724d3SBjoern A. Zeeb if (V_tcp_hostcache.purgeall) { 64897d8d152SAndre Oppermann all = 1; 649603724d3SBjoern A. Zeeb V_tcp_hostcache.purgeall = 0; 65097d8d152SAndre Oppermann } 65197d8d152SAndre Oppermann 652603724d3SBjoern A. Zeeb for (i = 0; i < V_tcp_hostcache.hashsize; i++) { 653603724d3SBjoern A. Zeeb THC_LOCK(&V_tcp_hostcache.hashbase[i].hch_mtx); 654ac957cd2SJulian Elischer TAILQ_FOREACH_SAFE(hc_entry, 6555ed3800eSJulian Elischer &V_tcp_hostcache.hashbase[i].hch_bucket, rmx_q, hc_next) { 65697d8d152SAndre Oppermann if (all || hc_entry->rmx_expire <= 0) { 657603724d3SBjoern A. Zeeb TAILQ_REMOVE(&V_tcp_hostcache.hashbase[i].hch_bucket, 65897d8d152SAndre Oppermann hc_entry, rmx_q); 659603724d3SBjoern A. Zeeb uma_zfree(V_tcp_hostcache.zone, hc_entry); 660603724d3SBjoern A. Zeeb V_tcp_hostcache.hashbase[i].hch_length--; 661603724d3SBjoern A. Zeeb V_tcp_hostcache.cache_count--; 66297d8d152SAndre Oppermann } else 663603724d3SBjoern A. Zeeb hc_entry->rmx_expire -= V_tcp_hostcache.prune; 66497d8d152SAndre Oppermann } 665603724d3SBjoern A. Zeeb THC_UNLOCK(&V_tcp_hostcache.hashbase[i].hch_mtx); 66697d8d152SAndre Oppermann } 667ac957cd2SJulian Elischer 668ac957cd2SJulian Elischer callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz, 669ac957cd2SJulian Elischer tcp_hc_purge, arg); 67021ca7b57SMarko Zec CURVNET_RESTORE(); 67197d8d152SAndre Oppermann } 672