2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
2017-11-27 15:23:17 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2003-11-20 20:07:39 +00:00
|
|
|
* Copyright (c) 2002 Andre Oppermann, Internet Business Solutions AG
|
2021-03-22 22:32:57 +00:00
|
|
|
* Copyright (c) 2021 Gleb Smirnoff <glebius@FreeBSD.org>
|
2003-11-20 20:07:39 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* The tcp_hostcache moves the tcp-specific cached metrics from the routing
|
|
|
|
* table to a dedicated structure indexed by the remote IP address. It keeps
|
|
|
|
* information on the measured TCP parameters of past TCP sessions to allow
|
|
|
|
* better initial start values to be used with later connections to/from the
|
2015-12-11 06:22:58 +00:00
|
|
|
* same source. Depending on the network parameters (delay, max MTU,
|
|
|
|
* congestion window) between local and remote sites, this can lead to
|
2007-05-27 19:39:26 +00:00
|
|
|
* significant speed-ups for new TCP connections after the first one.
|
2003-11-20 20:07:39 +00:00
|
|
|
*
|
2007-05-27 19:39:26 +00:00
|
|
|
* Due to the tcp_hostcache, all TCP-specific metrics information in the
|
2008-08-28 21:55:40 +00:00
|
|
|
* routing table have been removed. The inpcb no longer keeps a pointer to
|
2007-05-27 19:39:26 +00:00
|
|
|
* the routing entry, and protocol-initiated route cloning has been removed
|
|
|
|
* as well. With these changes, the routing table has gone back to being
|
|
|
|
* more lightwight and only carries information related to packet forwarding.
|
2003-11-20 20:07:39 +00:00
|
|
|
*
|
2007-05-27 19:39:26 +00:00
|
|
|
* tcp_hostcache is designed for multiple concurrent access in SMP
|
2021-03-22 22:32:57 +00:00
|
|
|
* environments and high contention. It is a straight hash. Each bucket row
|
|
|
|
* is protected by its own lock for modification. Readers are protected by
|
|
|
|
* SMR. This puts certain restrictions on writers, e.g. a writer shall only
|
|
|
|
* insert a fully populated entry into a row. Writer can't reuse least used
|
|
|
|
* entry if a hash is full. Value updates for an entry shall be atomic.
|
|
|
|
*
|
|
|
|
* TCP stack(s) communication with tcp_hostcache() is done via KBI functions
|
|
|
|
* tcp_hc_*() and the hc_metrics_lite structure.
|
|
|
|
*
|
|
|
|
* Since tcp_hostcache is only caching information, there are no fatal
|
|
|
|
* consequences if we either can't allocate a new entry or have to drop
|
|
|
|
* an existing entry, or return somewhat stale information.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Many thanks to jlemon for basic structure of tcp_syncache which is being
|
|
|
|
* followed here.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 20:44:24 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-11-20 20:07:39 +00:00
|
|
|
#include "opt_inet6.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2021-04-08 18:28:43 +00:00
|
|
|
#include <sys/hash.h>
|
2017-01-05 17:22:09 +00:00
|
|
|
#include <sys/jail.h>
|
2003-11-20 20:07:39 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/malloc.h>
|
2017-01-05 17:22:09 +00:00
|
|
|
#include <sys/proc.h>
|
2015-01-25 19:45:44 +00:00
|
|
|
#include <sys/sbuf.h>
|
2021-03-22 22:32:57 +00:00
|
|
|
#include <sys/smr.h>
|
2003-11-20 20:07:39 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
2009-08-01 19:26:27 +00:00
|
|
|
#include <net/vnet.h>
|
2003-11-20 20:07:39 +00:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/tcp_var.h>
|
|
|
|
|
|
|
|
#include <vm/uma.h>
|
|
|
|
|
2021-03-22 18:45:29 +00:00
|
|
|
struct hc_head {
|
2021-03-22 22:32:57 +00:00
|
|
|
CK_SLIST_HEAD(hc_qhead, hc_metrics) hch_bucket;
|
2021-03-22 18:45:29 +00:00
|
|
|
u_int hch_length;
|
|
|
|
struct mtx hch_mtx;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hc_metrics {
|
|
|
|
/* housekeeping */
|
2021-03-22 22:32:57 +00:00
|
|
|
CK_SLIST_ENTRY(hc_metrics) rmx_q;
|
2021-03-22 18:45:29 +00:00
|
|
|
struct in_addr ip4; /* IP address */
|
|
|
|
struct in6_addr ip6; /* IP6 address */
|
|
|
|
uint32_t ip6_zoneid; /* IPv6 scope zone id */
|
|
|
|
/* endpoint specific values for tcp */
|
|
|
|
uint32_t rmx_mtu; /* MTU for this path */
|
|
|
|
uint32_t rmx_ssthresh; /* outbound gateway buffer limit */
|
|
|
|
uint32_t rmx_rtt; /* estimated round trip time */
|
|
|
|
uint32_t rmx_rttvar; /* estimated rtt variance */
|
|
|
|
uint32_t rmx_cwnd; /* congestion window */
|
|
|
|
uint32_t rmx_sendpipe; /* outbound delay-bandwidth product */
|
|
|
|
uint32_t rmx_recvpipe; /* inbound delay-bandwidth product */
|
|
|
|
/* TCP hostcache internal data */
|
|
|
|
int rmx_expire; /* lifetime for object */
|
2021-03-22 20:35:25 +00:00
|
|
|
#ifdef TCP_HC_COUNTERS
|
2021-03-22 18:45:29 +00:00
|
|
|
u_long rmx_hits; /* number of hits */
|
|
|
|
u_long rmx_updates; /* number of updates */
|
2021-03-22 20:35:25 +00:00
|
|
|
#endif
|
2021-03-22 18:45:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct tcp_hostcache {
|
|
|
|
struct hc_head *hashbase;
|
|
|
|
uma_zone_t zone;
|
2021-03-22 22:32:57 +00:00
|
|
|
smr_t smr;
|
2021-03-22 18:45:29 +00:00
|
|
|
u_int hashsize;
|
|
|
|
u_int hashmask;
|
2021-04-08 18:28:43 +00:00
|
|
|
u_int hashsalt;
|
2021-03-22 18:45:29 +00:00
|
|
|
u_int bucket_limit;
|
|
|
|
u_int cache_count;
|
|
|
|
u_int cache_limit;
|
|
|
|
int expire;
|
|
|
|
int prune;
|
|
|
|
int purgeall;
|
|
|
|
};
|
|
|
|
|
2003-11-20 20:07:39 +00:00
|
|
|
/* Arbitrary values */
|
|
|
|
#define TCP_HOSTCACHE_HASHSIZE 512
|
|
|
|
#define TCP_HOSTCACHE_BUCKETLIMIT 30
|
|
|
|
#define TCP_HOSTCACHE_EXPIRE 60*60 /* one hour */
|
|
|
|
#define TCP_HOSTCACHE_PRUNE 5*60 /* every 5 minutes */
|
|
|
|
|
2018-07-24 16:35:52 +00:00
|
|
|
VNET_DEFINE_STATIC(struct tcp_hostcache, tcp_hostcache);
|
2009-07-16 21:13:04 +00:00
|
|
|
#define V_tcp_hostcache VNET(tcp_hostcache)
|
2010-04-29 11:52:42 +00:00
|
|
|
|
2018-07-24 16:35:52 +00:00
|
|
|
VNET_DEFINE_STATIC(struct callout, tcp_hc_callout);
|
2009-07-16 21:13:04 +00:00
|
|
|
#define V_tcp_hc_callout VNET(tcp_hc_callout)
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
static struct hc_metrics *tcp_hc_lookup(struct in_conninfo *);
|
2003-11-20 20:07:39 +00:00
|
|
|
static int sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS);
|
2021-04-01 12:44:05 +00:00
|
|
|
static int sysctl_tcp_hc_histo(SYSCTL_HANDLER_ARGS);
|
2015-05-20 01:08:01 +00:00
|
|
|
static int sysctl_tcp_hc_purgenow(SYSCTL_HANDLER_ARGS);
|
2010-02-09 21:31:53 +00:00
|
|
|
static void tcp_hc_purge_internal(int);
|
2003-11-20 20:07:39 +00:00
|
|
|
static void tcp_hc_purge(void *);
|
|
|
|
|
2020-02-26 14:26:36 +00:00
|
|
|
static SYSCTL_NODE(_net_inet_tcp, OID_AUTO, hostcache,
|
|
|
|
CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
|
2008-09-01 19:25:27 +00:00
|
|
|
"TCP Host cache");
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2016-09-30 00:10:57 +00:00
|
|
|
VNET_DEFINE(int, tcp_use_hostcache) = 1;
|
|
|
|
#define V_tcp_use_hostcache VNET(tcp_use_hostcache)
|
|
|
|
SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, enable, CTLFLAG_VNET | CTLFLAG_RW,
|
|
|
|
&VNET_NAME(tcp_use_hostcache), 0,
|
|
|
|
"Enable the TCP hostcache");
|
|
|
|
|
2014-11-07 09:39:05 +00:00
|
|
|
SYSCTL_UINT(_net_inet_tcp_hostcache, OID_AUTO, cachelimit, CTLFLAG_VNET | CTLFLAG_RDTUN,
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
&VNET_NAME(tcp_hostcache.cache_limit), 0,
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
"Overall entry limit for hostcache");
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2014-11-07 09:39:05 +00:00
|
|
|
SYSCTL_UINT(_net_inet_tcp_hostcache, OID_AUTO, hashsize, CTLFLAG_VNET | CTLFLAG_RDTUN,
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
&VNET_NAME(tcp_hostcache.hashsize), 0,
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
"Size of TCP hostcache hashtable");
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2014-11-07 09:39:05 +00:00
|
|
|
SYSCTL_UINT(_net_inet_tcp_hostcache, OID_AUTO, bucketlimit,
|
|
|
|
CTLFLAG_VNET | CTLFLAG_RDTUN, &VNET_NAME(tcp_hostcache.bucket_limit), 0,
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
"Per-bucket hash limit for hostcache");
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2021-04-01 08:00:32 +00:00
|
|
|
SYSCTL_UINT(_net_inet_tcp_hostcache, OID_AUTO, count, CTLFLAG_VNET | CTLFLAG_RD,
|
2021-04-08 21:23:23 +00:00
|
|
|
&VNET_NAME(tcp_hostcache.cache_count), 0,
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
"Current number of entries in hostcache");
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2014-11-07 09:39:05 +00:00
|
|
|
SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, expire, CTLFLAG_VNET | CTLFLAG_RW,
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
&VNET_NAME(tcp_hostcache.expire), 0,
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
"Expire time of TCP hostcache entries");
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2014-11-07 09:39:05 +00:00
|
|
|
SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, prune, CTLFLAG_VNET | CTLFLAG_RW,
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
&VNET_NAME(tcp_hostcache.prune), 0,
|
|
|
|
"Time between purge runs");
|
2007-06-08 13:35:51 +00:00
|
|
|
|
2014-11-07 09:39:05 +00:00
|
|
|
SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, purge, CTLFLAG_VNET | CTLFLAG_RW,
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
&VNET_NAME(tcp_hostcache.purgeall), 0,
|
2021-11-30 06:17:30 +00:00
|
|
|
"Expire all entries on next purge run");
|
2003-11-20 20:07:39 +00:00
|
|
|
|
|
|
|
SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, list,
|
2020-02-26 14:26:36 +00:00
|
|
|
CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_SKIP | CTLFLAG_MPSAFE,
|
|
|
|
0, 0, sysctl_tcp_hc_list, "A",
|
|
|
|
"List of all hostcache entries");
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2021-04-01 12:44:05 +00:00
|
|
|
SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, histo,
|
|
|
|
CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_SKIP | CTLFLAG_MPSAFE,
|
|
|
|
0, 0, sysctl_tcp_hc_histo, "A",
|
|
|
|
"Print a histogram of hostcache hashbucket utilization");
|
|
|
|
|
2015-05-20 01:08:01 +00:00
|
|
|
SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, purgenow,
|
2020-02-26 14:26:36 +00:00
|
|
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
|
|
|
|
NULL, 0, sysctl_tcp_hc_purgenow, "I",
|
|
|
|
"Immediately purge all entries");
|
2003-11-20 20:07:39 +00:00
|
|
|
|
|
|
|
static MALLOC_DEFINE(M_HOSTCACHE, "hostcache", "TCP hostcache");
|
|
|
|
|
2021-04-08 18:28:43 +00:00
|
|
|
/* Use jenkins_hash32(), as in other parts of the tcp stack */
|
2021-03-22 22:32:57 +00:00
|
|
|
#define HOSTCACHE_HASH(inc) \
|
|
|
|
((inc)->inc_flags & INC_ISIPV6) ? \
|
|
|
|
(jenkins_hash32((inc)->inc6_faddr.s6_addr32, 4, \
|
|
|
|
V_tcp_hostcache.hashsalt) & V_tcp_hostcache.hashmask) \
|
|
|
|
: \
|
|
|
|
(jenkins_hash32(&(inc)->inc_faddr.s_addr, 1, \
|
|
|
|
V_tcp_hostcache.hashsalt) & V_tcp_hostcache.hashmask)
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2021-04-09 15:39:40 +00:00
|
|
|
#define THC_LOCK(h) mtx_lock(&(h)->hch_mtx)
|
|
|
|
#define THC_UNLOCK(h) mtx_unlock(&(h)->hch_mtx)
|
2003-11-20 20:07:39 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
tcp_hc_init(void)
|
|
|
|
{
|
2012-10-19 14:00:03 +00:00
|
|
|
u_int cache_limit;
|
2003-11-20 20:07:39 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* Initialize hostcache structures.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
2021-04-01 08:00:32 +00:00
|
|
|
atomic_store_int(&V_tcp_hostcache.cache_count, 0);
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE;
|
|
|
|
V_tcp_hostcache.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT;
|
|
|
|
V_tcp_hostcache.expire = TCP_HOSTCACHE_EXPIRE;
|
|
|
|
V_tcp_hostcache.prune = TCP_HOSTCACHE_PRUNE;
|
2021-04-08 18:28:43 +00:00
|
|
|
V_tcp_hostcache.hashsalt = arc4random();
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2004-08-16 18:32:07 +00:00
|
|
|
TUNABLE_INT_FETCH("net.inet.tcp.hostcache.hashsize",
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
&V_tcp_hostcache.hashsize);
|
|
|
|
if (!powerof2(V_tcp_hostcache.hashsize)) {
|
2004-08-16 18:32:07 +00:00
|
|
|
printf("WARNING: hostcache hash size is not a power of 2.\n");
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; /* default */
|
2004-08-16 18:32:07 +00:00
|
|
|
}
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_tcp_hostcache.hashmask = V_tcp_hostcache.hashsize - 1;
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2012-10-19 14:00:03 +00:00
|
|
|
TUNABLE_INT_FETCH("net.inet.tcp.hostcache.bucketlimit",
|
|
|
|
&V_tcp_hostcache.bucket_limit);
|
|
|
|
|
|
|
|
cache_limit = V_tcp_hostcache.hashsize * V_tcp_hostcache.bucket_limit;
|
|
|
|
V_tcp_hostcache.cache_limit = cache_limit;
|
|
|
|
TUNABLE_INT_FETCH("net.inet.tcp.hostcache.cachelimit",
|
|
|
|
&V_tcp_hostcache.cache_limit);
|
|
|
|
if (V_tcp_hostcache.cache_limit > cache_limit)
|
|
|
|
V_tcp_hostcache.cache_limit = cache_limit;
|
|
|
|
|
2003-11-20 20:07:39 +00:00
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* Allocate the hash table.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_tcp_hostcache.hashbase = (struct hc_head *)
|
|
|
|
malloc(V_tcp_hostcache.hashsize * sizeof(struct hc_head),
|
2003-11-20 20:07:39 +00:00
|
|
|
M_HOSTCACHE, M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* Initialize the hash buckets.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
|
2021-03-22 22:32:57 +00:00
|
|
|
CK_SLIST_INIT(&V_tcp_hostcache.hashbase[i].hch_bucket);
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_tcp_hostcache.hashbase[i].hch_length = 0;
|
|
|
|
mtx_init(&V_tcp_hostcache.hashbase[i].hch_mtx, "tcp_hc_entry",
|
2003-11-20 20:07:39 +00:00
|
|
|
NULL, MTX_DEF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the hostcache entries.
|
|
|
|
*/
|
2008-08-20 01:05:56 +00:00
|
|
|
V_tcp_hostcache.zone =
|
2008-08-20 01:24:55 +00:00
|
|
|
uma_zcreate("hostcache", sizeof(struct hc_metrics),
|
2021-03-22 22:32:57 +00:00
|
|
|
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_SMR);
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
uma_zone_set_max(V_tcp_hostcache.zone, V_tcp_hostcache.cache_limit);
|
2021-03-22 22:32:57 +00:00
|
|
|
V_tcp_hostcache.smr = uma_zone_get_smr(V_tcp_hostcache.zone);
|
2003-11-20 20:07:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up periodic cache cleanup.
|
|
|
|
*/
|
2015-05-22 17:05:21 +00:00
|
|
|
callout_init(&V_tcp_hc_callout, 1);
|
2008-08-20 01:05:56 +00:00
|
|
|
callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
|
Change the curvnet variable from a global const struct vnet *,
previously always pointing to the default vnet context, to a
dynamically changing thread-local one. The currvnet context
should be set on entry to networking code via CURVNET_SET() macros,
and reverted to previous state via CURVNET_RESTORE(). Recursions
on curvnet are permitted, though strongly discuouraged.
This change should have no functional impact on nooptions VIMAGE
kernel builds, where CURVNET_* macros expand to whitespace.
The curthread->td_vnet (aka curvnet) variable's purpose is to be an
indicator of the vnet context in which the current network-related
operation takes place, in case we cannot deduce the current vnet
context from any other source, such as by looking at mbuf's
m->m_pkthdr.rcvif->if_vnet, sockets's so->so_vnet etc. Moreover, so
far curvnet has turned out to be an invaluable consistency checking
aid: it helps to catch cases when sockets, ifnets or any other
vnet-aware structures may have leaked from one vnet to another.
The exact placement of the CURVNET_SET() / CURVNET_RESTORE() macros
was a result of an empirical iterative process, whith an aim to
reduce recursions on CURVNET_SET() to a minimum, while still reducing
the scope of CURVNET_SET() to networking only operations - the
alternative would be calling CURVNET_SET() on each system call entry.
In general, curvnet has to be set in three typicall cases: when
processing socket-related requests from userspace or from within the
kernel; when processing inbound traffic flowing from device drivers
to upper layers of the networking stack, and when executing
timer-driven networking functions.
This change also introduces a DDB subcommand to show the list of all
vnet instances.
Approved by: julian (mentor)
2009-05-05 10:56:12 +00:00
|
|
|
tcp_hc_purge, curvnet);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
Introduce an infrastructure for dismantling vnet instances.
Vnet modules and protocol domains may now register destructor
functions to clean up and release per-module state. The destructor
mechanisms can be triggered by invoking "vimage -d", or a future
equivalent command which will be provided via the new jail framework.
While this patch introduces numerous placeholder destructor functions,
many of those are currently incomplete, thus leaking memory or (even
worse) failing to stop all running timers. Many of such issues are
already known and will be incrementaly fixed over the next weeks in
smaller incremental commits.
Apart from introducing new fields in structs ifnet, domain, protosw
and vnet_net, which requires the kernel and modules to be rebuilt, this
change should have no impact on nooptions VIMAGE builds, since vnet
destructors can only be called in VIMAGE kernels. Moreover,
destructor functions should be in general compiled in only in
options VIMAGE builds, except for kernel modules which can be safely
kldunloaded at run time.
Bump __FreeBSD_version to 800097.
Reviewed by: bz, julian
Approved by: rwatson, kib (re), julian (mentor)
2009-06-08 17:15:40 +00:00
|
|
|
#ifdef VIMAGE
|
|
|
|
void
|
|
|
|
tcp_hc_destroy(void)
|
|
|
|
{
|
2010-02-09 21:31:53 +00:00
|
|
|
int i;
|
Introduce an infrastructure for dismantling vnet instances.
Vnet modules and protocol domains may now register destructor
functions to clean up and release per-module state. The destructor
mechanisms can be triggered by invoking "vimage -d", or a future
equivalent command which will be provided via the new jail framework.
While this patch introduces numerous placeholder destructor functions,
many of those are currently incomplete, thus leaking memory or (even
worse) failing to stop all running timers. Many of such issues are
already known and will be incrementaly fixed over the next weeks in
smaller incremental commits.
Apart from introducing new fields in structs ifnet, domain, protosw
and vnet_net, which requires the kernel and modules to be rebuilt, this
change should have no impact on nooptions VIMAGE builds, since vnet
destructors can only be called in VIMAGE kernels. Moreover,
destructor functions should be in general compiled in only in
options VIMAGE builds, except for kernel modules which can be safely
kldunloaded at run time.
Bump __FreeBSD_version to 800097.
Reviewed by: bz, julian
Approved by: rwatson, kib (re), julian (mentor)
2009-06-08 17:15:40 +00:00
|
|
|
|
|
|
|
callout_drain(&V_tcp_hc_callout);
|
2010-02-09 21:31:53 +00:00
|
|
|
|
|
|
|
/* Purge all hc entries. */
|
|
|
|
tcp_hc_purge_internal(1);
|
|
|
|
|
|
|
|
/* Free the uma zone and the allocated hash table. */
|
|
|
|
uma_zdestroy(V_tcp_hostcache.zone);
|
|
|
|
|
|
|
|
for (i = 0; i < V_tcp_hostcache.hashsize; i++)
|
|
|
|
mtx_destroy(&V_tcp_hostcache.hashbase[i].hch_mtx);
|
|
|
|
free(V_tcp_hostcache.hashbase, M_HOSTCACHE);
|
Introduce an infrastructure for dismantling vnet instances.
Vnet modules and protocol domains may now register destructor
functions to clean up and release per-module state. The destructor
mechanisms can be triggered by invoking "vimage -d", or a future
equivalent command which will be provided via the new jail framework.
While this patch introduces numerous placeholder destructor functions,
many of those are currently incomplete, thus leaking memory or (even
worse) failing to stop all running timers. Many of such issues are
already known and will be incrementaly fixed over the next weeks in
smaller incremental commits.
Apart from introducing new fields in structs ifnet, domain, protosw
and vnet_net, which requires the kernel and modules to be rebuilt, this
change should have no impact on nooptions VIMAGE builds, since vnet
destructors can only be called in VIMAGE kernels. Moreover,
destructor functions should be in general compiled in only in
options VIMAGE builds, except for kernel modules which can be safely
kldunloaded at run time.
Bump __FreeBSD_version to 800097.
Reviewed by: bz, julian
Approved by: rwatson, kib (re), julian (mentor)
2009-06-08 17:15:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-11-20 20:07:39 +00:00
|
|
|
/*
|
2021-03-22 22:32:57 +00:00
|
|
|
* Internal function: compare cache entry to a connection.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
2021-03-22 22:32:57 +00:00
|
|
|
static bool
|
|
|
|
tcp_hc_cmp(struct hc_metrics *hc_entry, struct in_conninfo *inc)
|
2003-11-20 20:07:39 +00:00
|
|
|
{
|
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
if (inc->inc_flags & INC_ISIPV6) {
|
|
|
|
/* XXX: check ip6_zoneid */
|
|
|
|
if (memcmp(&inc->inc6_faddr, &hc_entry->ip6,
|
|
|
|
sizeof(inc->inc6_faddr)) == 0)
|
|
|
|
return (true);
|
|
|
|
} else {
|
|
|
|
if (memcmp(&inc->inc_faddr, &hc_entry->ip4,
|
|
|
|
sizeof(inc->inc_faddr)) == 0)
|
|
|
|
return (true);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
return (false);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-03-22 22:32:57 +00:00
|
|
|
* Internal function: look up an entry in the hostcache for read.
|
|
|
|
* On success returns in SMR section.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
|
|
|
static struct hc_metrics *
|
2021-03-22 22:32:57 +00:00
|
|
|
tcp_hc_lookup(struct in_conninfo *inc)
|
2003-11-20 20:07:39 +00:00
|
|
|
{
|
|
|
|
struct hc_head *hc_head;
|
|
|
|
struct hc_metrics *hc_entry;
|
|
|
|
|
2021-04-08 21:23:23 +00:00
|
|
|
KASSERT(inc != NULL, ("%s: NULL in_conninfo", __func__));
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
hc_head = &V_tcp_hostcache.hashbase[HOSTCACHE_HASH(inc)];
|
2003-11-20 20:07:39 +00:00
|
|
|
|
|
|
|
/*
|
2021-03-22 22:32:57 +00:00
|
|
|
* Iterate through entries in bucket row looking for a match.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
2021-03-22 22:32:57 +00:00
|
|
|
smr_enter(V_tcp_hostcache.smr);
|
|
|
|
CK_SLIST_FOREACH(hc_entry, &hc_head->hch_bucket, rmx_q)
|
|
|
|
if (tcp_hc_cmp(hc_entry, inc))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (hc_entry != NULL) {
|
|
|
|
if (atomic_load_int(&hc_entry->rmx_expire) !=
|
|
|
|
V_tcp_hostcache.expire)
|
|
|
|
atomic_store_int(&hc_entry->rmx_expire,
|
|
|
|
V_tcp_hostcache.expire);
|
|
|
|
#ifdef TCP_HC_COUNTERS
|
|
|
|
hc_entry->rmx_hits++;
|
2003-11-28 16:33:03 +00:00
|
|
|
#endif
|
2014-09-10 16:26:18 +00:00
|
|
|
} else
|
2021-03-22 22:32:57 +00:00
|
|
|
smr_exit(V_tcp_hostcache.smr);
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2021-04-08 21:23:23 +00:00
|
|
|
return (hc_entry);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* External function: look up an entry in the hostcache and fill out the
|
|
|
|
* supplied TCP metrics structure. Fills in NULL when no entry was found or
|
|
|
|
* a value is not set.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
tcp_hc_get(struct in_conninfo *inc, struct hc_metrics_lite *hc_metrics_lite)
|
|
|
|
{
|
|
|
|
struct hc_metrics *hc_entry;
|
|
|
|
|
2020-02-17 14:54:21 +00:00
|
|
|
if (!V_tcp_use_hostcache) {
|
|
|
|
bzero(hc_metrics_lite, sizeof(*hc_metrics_lite));
|
2016-09-30 00:10:57 +00:00
|
|
|
return;
|
2020-02-17 14:54:21 +00:00
|
|
|
}
|
2016-09-30 00:10:57 +00:00
|
|
|
|
2003-11-20 20:07:39 +00:00
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* Find the right bucket.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
2021-03-22 22:32:57 +00:00
|
|
|
hc_entry = tcp_hc_lookup(inc);
|
2003-11-20 20:07:39 +00:00
|
|
|
|
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* If we don't have an existing object.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
|
|
|
if (hc_entry == NULL) {
|
|
|
|
bzero(hc_metrics_lite, sizeof(*hc_metrics_lite));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
hc_metrics_lite->rmx_mtu = atomic_load_32(&hc_entry->rmx_mtu);
|
|
|
|
hc_metrics_lite->rmx_ssthresh = atomic_load_32(&hc_entry->rmx_ssthresh);
|
|
|
|
hc_metrics_lite->rmx_rtt = atomic_load_32(&hc_entry->rmx_rtt);
|
|
|
|
hc_metrics_lite->rmx_rttvar = atomic_load_32(&hc_entry->rmx_rttvar);
|
|
|
|
hc_metrics_lite->rmx_cwnd = atomic_load_32(&hc_entry->rmx_cwnd);
|
|
|
|
hc_metrics_lite->rmx_sendpipe = atomic_load_32(&hc_entry->rmx_sendpipe);
|
|
|
|
hc_metrics_lite->rmx_recvpipe = atomic_load_32(&hc_entry->rmx_recvpipe);
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
smr_exit(V_tcp_hostcache.smr);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* External function: look up an entry in the hostcache and return the
|
2016-09-30 00:10:57 +00:00
|
|
|
* discovered path MTU. Returns 0 if no entry is found or value is not
|
2004-12-05 22:20:59 +00:00
|
|
|
* set.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
2016-10-06 16:28:34 +00:00
|
|
|
uint32_t
|
2003-11-20 20:07:39 +00:00
|
|
|
tcp_hc_getmtu(struct in_conninfo *inc)
|
|
|
|
{
|
|
|
|
struct hc_metrics *hc_entry;
|
2016-10-06 16:28:34 +00:00
|
|
|
uint32_t mtu;
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2016-09-30 00:10:57 +00:00
|
|
|
if (!V_tcp_use_hostcache)
|
2021-04-08 21:23:23 +00:00
|
|
|
return (0);
|
2016-09-30 00:10:57 +00:00
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
hc_entry = tcp_hc_lookup(inc);
|
2003-11-20 20:07:39 +00:00
|
|
|
if (hc_entry == NULL) {
|
2021-04-08 21:23:23 +00:00
|
|
|
return (0);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
mtu = atomic_load_32(&hc_entry->rmx_mtu);
|
|
|
|
smr_exit(V_tcp_hostcache.smr);
|
|
|
|
|
2021-04-08 21:23:23 +00:00
|
|
|
return (mtu);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* External function: update the MTU value of an entry in the hostcache.
|
2003-11-20 20:07:39 +00:00
|
|
|
* Creates a new entry if none was found.
|
|
|
|
*/
|
|
|
|
void
|
2016-10-06 16:28:34 +00:00
|
|
|
tcp_hc_updatemtu(struct in_conninfo *inc, uint32_t mtu)
|
2003-11-20 20:07:39 +00:00
|
|
|
{
|
2021-04-08 21:15:42 +00:00
|
|
|
struct hc_metrics_lite hcml = { .rmx_mtu = mtu };
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2021-04-08 21:15:42 +00:00
|
|
|
return (tcp_hc_update(inc, &hcml));
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-05-27 19:39:26 +00:00
|
|
|
* External function: update the TCP metrics of an entry in the hostcache.
|
2003-11-20 20:07:39 +00:00
|
|
|
* Creates a new entry if none was found.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
tcp_hc_update(struct in_conninfo *inc, struct hc_metrics_lite *hcml)
|
|
|
|
{
|
2021-03-22 22:32:57 +00:00
|
|
|
struct hc_head *hc_head;
|
|
|
|
struct hc_metrics *hc_entry, *hc_prev;
|
|
|
|
uint32_t v;
|
|
|
|
bool new;
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2016-09-30 00:10:57 +00:00
|
|
|
if (!V_tcp_use_hostcache)
|
|
|
|
return;
|
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
hc_head = &V_tcp_hostcache.hashbase[HOSTCACHE_HASH(inc)];
|
|
|
|
hc_prev = NULL;
|
|
|
|
|
|
|
|
THC_LOCK(hc_head);
|
|
|
|
CK_SLIST_FOREACH(hc_entry, &hc_head->hch_bucket, rmx_q) {
|
|
|
|
if (tcp_hc_cmp(hc_entry, inc))
|
|
|
|
break;
|
|
|
|
if (CK_SLIST_NEXT(hc_entry, rmx_q) != NULL)
|
|
|
|
hc_prev = hc_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hc_entry != NULL) {
|
|
|
|
if (atomic_load_int(&hc_entry->rmx_expire) !=
|
|
|
|
V_tcp_hostcache.expire)
|
|
|
|
atomic_store_int(&hc_entry->rmx_expire,
|
|
|
|
V_tcp_hostcache.expire);
|
|
|
|
#ifdef TCP_HC_COUNTERS
|
|
|
|
hc_entry->rmx_updates++;
|
|
|
|
#endif
|
|
|
|
new = false;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Try to allocate a new entry. If the bucket limit is
|
|
|
|
* reached, delete the least-used element, located at the end
|
|
|
|
* of the CK_SLIST. During lookup we saved the pointer to
|
|
|
|
* the second to last element, in case if list has at least 2
|
|
|
|
* elements. This will allow to delete last element without
|
|
|
|
* extra traversal.
|
|
|
|
*
|
|
|
|
* Give up if the row is empty.
|
|
|
|
*/
|
|
|
|
if (hc_head->hch_length >= V_tcp_hostcache.bucket_limit ||
|
|
|
|
atomic_load_int(&V_tcp_hostcache.cache_count) >=
|
|
|
|
V_tcp_hostcache.cache_limit) {
|
|
|
|
if (hc_prev != NULL) {
|
|
|
|
hc_entry = CK_SLIST_NEXT(hc_prev, rmx_q);
|
|
|
|
KASSERT(CK_SLIST_NEXT(hc_entry, rmx_q) == NULL,
|
|
|
|
("%s: %p is not one to last",
|
|
|
|
__func__, hc_prev));
|
|
|
|
CK_SLIST_REMOVE_AFTER(hc_prev, rmx_q);
|
|
|
|
} else if ((hc_entry =
|
|
|
|
CK_SLIST_FIRST(&hc_head->hch_bucket)) != NULL) {
|
|
|
|
KASSERT(CK_SLIST_NEXT(hc_entry, rmx_q) == NULL,
|
|
|
|
("%s: %p is not the only element",
|
|
|
|
__func__, hc_entry));
|
|
|
|
CK_SLIST_REMOVE_HEAD(&hc_head->hch_bucket,
|
|
|
|
rmx_q);
|
|
|
|
} else {
|
|
|
|
THC_UNLOCK(hc_head);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
KASSERT(hc_head->hch_length > 0 &&
|
|
|
|
hc_head->hch_length <= V_tcp_hostcache.bucket_limit,
|
|
|
|
("tcp_hostcache: bucket length violated at %p",
|
|
|
|
hc_head));
|
|
|
|
hc_head->hch_length--;
|
|
|
|
atomic_subtract_int(&V_tcp_hostcache.cache_count, 1);
|
|
|
|
TCPSTAT_INC(tcps_hc_bucketoverflow);
|
|
|
|
uma_zfree_smr(V_tcp_hostcache.zone, hc_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new entry, or balk if not possible.
|
|
|
|
*/
|
|
|
|
hc_entry = uma_zalloc_smr(V_tcp_hostcache.zone, M_NOWAIT);
|
|
|
|
if (hc_entry == NULL) {
|
|
|
|
THC_UNLOCK(hc_head);
|
2003-11-20 20:07:39 +00:00
|
|
|
return;
|
2021-03-22 22:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize basic information of hostcache entry.
|
|
|
|
*/
|
|
|
|
bzero(hc_entry, sizeof(*hc_entry));
|
|
|
|
if (inc->inc_flags & INC_ISIPV6) {
|
|
|
|
hc_entry->ip6 = inc->inc6_faddr;
|
|
|
|
hc_entry->ip6_zoneid = inc->inc6_zoneid;
|
|
|
|
} else
|
|
|
|
hc_entry->ip4 = inc->inc_faddr;
|
|
|
|
hc_entry->rmx_expire = V_tcp_hostcache.expire;
|
|
|
|
new = true;
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
/*
|
|
|
|
* Fill in data. Use atomics, since an existing entry is
|
|
|
|
* accessible by readers in SMR section.
|
|
|
|
*/
|
2021-04-08 21:15:42 +00:00
|
|
|
if (hcml->rmx_mtu != 0) {
|
2021-03-22 22:32:57 +00:00
|
|
|
atomic_store_32(&hc_entry->rmx_mtu, hcml->rmx_mtu);
|
2021-04-08 21:15:42 +00:00
|
|
|
}
|
2003-11-20 20:07:39 +00:00
|
|
|
if (hcml->rmx_rtt != 0) {
|
|
|
|
if (hc_entry->rmx_rtt == 0)
|
2021-03-22 22:32:57 +00:00
|
|
|
v = hcml->rmx_rtt;
|
2003-11-20 20:07:39 +00:00
|
|
|
else
|
2021-03-22 22:32:57 +00:00
|
|
|
v = ((uint64_t)hc_entry->rmx_rtt +
|
2016-10-06 16:28:34 +00:00
|
|
|
(uint64_t)hcml->rmx_rtt) / 2;
|
2021-03-22 22:32:57 +00:00
|
|
|
atomic_store_32(&hc_entry->rmx_rtt, v);
|
2009-04-11 22:07:19 +00:00
|
|
|
TCPSTAT_INC(tcps_cachedrtt);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
if (hcml->rmx_rttvar != 0) {
|
2021-03-22 22:32:57 +00:00
|
|
|
if (hc_entry->rmx_rttvar == 0)
|
|
|
|
v = hcml->rmx_rttvar;
|
2003-11-20 20:07:39 +00:00
|
|
|
else
|
2021-03-22 22:32:57 +00:00
|
|
|
v = ((uint64_t)hc_entry->rmx_rttvar +
|
2016-10-06 16:28:34 +00:00
|
|
|
(uint64_t)hcml->rmx_rttvar) / 2;
|
2021-03-22 22:32:57 +00:00
|
|
|
atomic_store_32(&hc_entry->rmx_rttvar, v);
|
2009-04-11 22:07:19 +00:00
|
|
|
TCPSTAT_INC(tcps_cachedrttvar);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
if (hcml->rmx_ssthresh != 0) {
|
|
|
|
if (hc_entry->rmx_ssthresh == 0)
|
2021-03-22 22:32:57 +00:00
|
|
|
v = hcml->rmx_ssthresh;
|
2003-11-20 20:07:39 +00:00
|
|
|
else
|
2021-03-22 22:32:57 +00:00
|
|
|
v = (hc_entry->rmx_ssthresh + hcml->rmx_ssthresh) / 2;
|
|
|
|
atomic_store_32(&hc_entry->rmx_ssthresh, v);
|
2009-04-11 22:07:19 +00:00
|
|
|
TCPSTAT_INC(tcps_cachedssthresh);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
if (hcml->rmx_cwnd != 0) {
|
|
|
|
if (hc_entry->rmx_cwnd == 0)
|
2021-03-22 22:32:57 +00:00
|
|
|
v = hcml->rmx_cwnd;
|
2003-11-20 20:07:39 +00:00
|
|
|
else
|
2021-03-22 22:32:57 +00:00
|
|
|
v = ((uint64_t)hc_entry->rmx_cwnd +
|
2016-10-06 16:28:34 +00:00
|
|
|
(uint64_t)hcml->rmx_cwnd) / 2;
|
2021-03-22 22:32:57 +00:00
|
|
|
atomic_store_32(&hc_entry->rmx_cwnd, v);
|
2009-04-11 22:07:19 +00:00
|
|
|
/* TCPSTAT_INC(tcps_cachedcwnd); */
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
if (hcml->rmx_sendpipe != 0) {
|
|
|
|
if (hc_entry->rmx_sendpipe == 0)
|
2021-03-22 22:32:57 +00:00
|
|
|
v = hcml->rmx_sendpipe;
|
2003-11-20 20:07:39 +00:00
|
|
|
else
|
2021-03-22 22:32:57 +00:00
|
|
|
v = ((uint64_t)hc_entry->rmx_sendpipe +
|
2016-10-06 16:28:34 +00:00
|
|
|
(uint64_t)hcml->rmx_sendpipe) /2;
|
2021-03-22 22:32:57 +00:00
|
|
|
atomic_store_32(&hc_entry->rmx_sendpipe, v);
|
2009-04-11 22:07:19 +00:00
|
|
|
/* TCPSTAT_INC(tcps_cachedsendpipe); */
|
2004-08-16 18:32:07 +00:00
|
|
|
}
|
2003-11-20 20:07:39 +00:00
|
|
|
if (hcml->rmx_recvpipe != 0) {
|
|
|
|
if (hc_entry->rmx_recvpipe == 0)
|
2021-03-22 22:32:57 +00:00
|
|
|
v = hcml->rmx_recvpipe;
|
2003-11-20 20:07:39 +00:00
|
|
|
else
|
2021-03-22 22:32:57 +00:00
|
|
|
v = ((uint64_t)hc_entry->rmx_recvpipe +
|
2016-10-06 16:28:34 +00:00
|
|
|
(uint64_t)hcml->rmx_recvpipe) /2;
|
2021-03-22 22:32:57 +00:00
|
|
|
atomic_store_32(&hc_entry->rmx_recvpipe, v);
|
2009-04-11 22:07:19 +00:00
|
|
|
/* TCPSTAT_INC(tcps_cachedrecvpipe); */
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 22:32:57 +00:00
|
|
|
/*
|
|
|
|
* Put it upfront.
|
|
|
|
*/
|
|
|
|
if (new) {
|
|
|
|
CK_SLIST_INSERT_HEAD(&hc_head->hch_bucket, hc_entry, rmx_q);
|
|
|
|
hc_head->hch_length++;
|
|
|
|
KASSERT(hc_head->hch_length <= V_tcp_hostcache.bucket_limit,
|
|
|
|
("tcp_hostcache: bucket length too high at %p", hc_head));
|
|
|
|
atomic_add_int(&V_tcp_hostcache.cache_count, 1);
|
|
|
|
TCPSTAT_INC(tcps_hc_added);
|
|
|
|
} else if (hc_entry != CK_SLIST_FIRST(&hc_head->hch_bucket)) {
|
|
|
|
KASSERT(CK_SLIST_NEXT(hc_prev, rmx_q) == hc_entry,
|
|
|
|
("%s: %p next is not %p", __func__, hc_prev, hc_entry));
|
|
|
|
CK_SLIST_REMOVE_AFTER(hc_prev, rmx_q);
|
|
|
|
CK_SLIST_INSERT_HEAD(&hc_head->hch_bucket, hc_entry, rmx_q);
|
|
|
|
}
|
|
|
|
THC_UNLOCK(hc_head);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sysctl function: prints the list and values of all hostcache entries in
|
|
|
|
* unsorted order.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
2015-03-14 18:11:24 +00:00
|
|
|
const int linesize = 128;
|
2015-01-25 19:45:44 +00:00
|
|
|
struct sbuf sb;
|
2021-03-28 21:12:03 +00:00
|
|
|
int i, error, len;
|
2003-11-20 20:07:39 +00:00
|
|
|
struct hc_metrics *hc_entry;
|
2017-02-16 20:47:41 +00:00
|
|
|
char ip4buf[INET_ADDRSTRLEN];
|
2006-12-12 12:17:58 +00:00
|
|
|
#ifdef INET6
|
|
|
|
char ip6buf[INET6_ADDRSTRLEN];
|
|
|
|
#endif
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2017-01-05 17:22:09 +00:00
|
|
|
if (jailed_without_vnet(curthread->td_ucred) != 0)
|
|
|
|
return (EPERM);
|
|
|
|
|
2021-03-28 21:12:03 +00:00
|
|
|
/* Optimize Buffer length query by sbin/sysctl */
|
|
|
|
if (req->oldptr == NULL) {
|
2021-04-01 08:00:32 +00:00
|
|
|
len = (atomic_load_int(&V_tcp_hostcache.cache_count) + 1) *
|
|
|
|
linesize;
|
2021-03-28 21:12:03 +00:00
|
|
|
return (SYSCTL_OUT(req, NULL, len));
|
|
|
|
}
|
|
|
|
|
|
|
|
error = sysctl_wire_old_buffer(req, 0);
|
|
|
|
if (error != 0) {
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2021-03-31 17:24:01 +00:00
|
|
|
/* Use a buffer sized for one full bucket */
|
2021-04-01 08:00:32 +00:00
|
|
|
sbuf_new_for_sysctl(&sb, NULL, V_tcp_hostcache.bucket_limit *
|
|
|
|
linesize, req);
|
2003-11-20 20:07:39 +00:00
|
|
|
|
2015-01-25 19:45:44 +00:00
|
|
|
sbuf_printf(&sb,
|
2021-03-28 21:12:03 +00:00
|
|
|
"\nIP address MTU SSTRESH RTT RTTVAR "
|
2021-03-22 20:35:25 +00:00
|
|
|
" CWND SENDPIPE RECVPIPE "
|
|
|
|
#ifdef TCP_HC_COUNTERS
|
|
|
|
"HITS UPD "
|
|
|
|
#endif
|
|
|
|
"EXP\n");
|
2021-03-31 17:24:01 +00:00
|
|
|
sbuf_drain(&sb);
|
2003-11-20 20:07:39 +00:00
|
|
|
|
|
|
|
#define msec(u) (((u) + 500) / 1000)
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
|
2021-04-09 15:39:40 +00:00
|
|
|
THC_LOCK(&V_tcp_hostcache.hashbase[i]);
|
2021-03-22 22:32:57 +00:00
|
|
|
CK_SLIST_FOREACH(hc_entry,
|
|
|
|
&V_tcp_hostcache.hashbase[i].hch_bucket, rmx_q) {
|
2015-01-25 19:45:44 +00:00
|
|
|
sbuf_printf(&sb,
|
2021-03-22 20:35:25 +00:00
|
|
|
"%-15s %5u %8u %6lums %6lums %8u %8u %8u "
|
|
|
|
#ifdef TCP_HC_COUNTERS
|
|
|
|
"%4lu %4lu "
|
|
|
|
#endif
|
|
|
|
"%4i\n",
|
2017-02-16 20:47:41 +00:00
|
|
|
hc_entry->ip4.s_addr ?
|
|
|
|
inet_ntoa_r(hc_entry->ip4, ip4buf) :
|
2003-11-20 20:07:39 +00:00
|
|
|
#ifdef INET6
|
2006-12-12 12:17:58 +00:00
|
|
|
ip6_sprintf(ip6buf, &hc_entry->ip6),
|
2003-11-20 20:07:39 +00:00
|
|
|
#else
|
|
|
|
"IPv6?",
|
|
|
|
#endif
|
|
|
|
hc_entry->rmx_mtu,
|
|
|
|
hc_entry->rmx_ssthresh,
|
2016-10-06 16:28:34 +00:00
|
|
|
msec((u_long)hc_entry->rmx_rtt *
|
2003-11-20 20:07:39 +00:00
|
|
|
(RTM_RTTUNIT / (hz * TCP_RTT_SCALE))),
|
2016-10-06 16:28:34 +00:00
|
|
|
msec((u_long)hc_entry->rmx_rttvar *
|
2012-07-03 18:59:13 +00:00
|
|
|
(RTM_RTTUNIT / (hz * TCP_RTTVAR_SCALE))),
|
2003-11-20 20:07:39 +00:00
|
|
|
hc_entry->rmx_cwnd,
|
|
|
|
hc_entry->rmx_sendpipe,
|
|
|
|
hc_entry->rmx_recvpipe,
|
2021-03-22 20:35:25 +00:00
|
|
|
#ifdef TCP_HC_COUNTERS
|
2003-11-20 20:07:39 +00:00
|
|
|
hc_entry->rmx_hits,
|
|
|
|
hc_entry->rmx_updates,
|
2021-03-22 20:35:25 +00:00
|
|
|
#endif
|
2003-11-20 20:07:39 +00:00
|
|
|
hc_entry->rmx_expire);
|
|
|
|
}
|
2021-04-09 15:39:40 +00:00
|
|
|
THC_UNLOCK(&V_tcp_hostcache.hashbase[i]);
|
2021-04-02 18:26:48 +00:00
|
|
|
sbuf_drain(&sb);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
|
|
|
#undef msec
|
2015-03-14 18:11:24 +00:00
|
|
|
error = sbuf_finish(&sb);
|
2015-01-25 19:45:44 +00:00
|
|
|
sbuf_delete(&sb);
|
2003-11-20 20:07:39 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2021-04-01 12:44:05 +00:00
|
|
|
/*
|
|
|
|
* Sysctl function: prints a histogram of the hostcache hashbucket
|
|
|
|
* utilization.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sysctl_tcp_hc_histo(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
const int linesize = 50;
|
|
|
|
struct sbuf sb;
|
|
|
|
int i, error;
|
|
|
|
int *histo;
|
|
|
|
u_int hch_length;
|
|
|
|
|
|
|
|
if (jailed_without_vnet(curthread->td_ucred) != 0)
|
|
|
|
return (EPERM);
|
|
|
|
|
|
|
|
histo = (int *)malloc(sizeof(int) * (V_tcp_hostcache.bucket_limit + 1),
|
|
|
|
M_TEMP, M_NOWAIT|M_ZERO);
|
|
|
|
if (histo == NULL)
|
|
|
|
return(ENOMEM);
|
|
|
|
|
|
|
|
for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
|
|
|
|
hch_length = V_tcp_hostcache.hashbase[i].hch_length;
|
|
|
|
KASSERT(hch_length <= V_tcp_hostcache.bucket_limit,
|
2021-04-08 21:23:23 +00:00
|
|
|
("tcp_hostcache: bucket limit exceeded at %u: %u",
|
|
|
|
i, hch_length));
|
2021-04-01 12:44:05 +00:00
|
|
|
histo[hch_length]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use a buffer for 16 lines */
|
|
|
|
sbuf_new_for_sysctl(&sb, NULL, 16 * linesize, req);
|
|
|
|
|
|
|
|
sbuf_printf(&sb, "\nLength\tCount\n");
|
|
|
|
for (i = 0; i <= V_tcp_hostcache.bucket_limit; i++) {
|
|
|
|
sbuf_printf(&sb, "%u\t%u\n", i, histo[i]);
|
|
|
|
}
|
|
|
|
error = sbuf_finish(&sb);
|
|
|
|
sbuf_delete(&sb);
|
|
|
|
free(histo, M_TEMP);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2003-11-20 20:07:39 +00:00
|
|
|
/*
|
2010-02-09 21:31:53 +00:00
|
|
|
* Caller has to make sure the curvnet is set properly.
|
2003-11-20 20:07:39 +00:00
|
|
|
*/
|
|
|
|
static void
|
2010-02-09 21:31:53 +00:00
|
|
|
tcp_hc_purge_internal(int all)
|
2003-11-20 20:07:39 +00:00
|
|
|
{
|
2021-03-22 22:32:57 +00:00
|
|
|
struct hc_head *head;
|
|
|
|
struct hc_metrics *hc_entry, *hc_next, *hc_prev;
|
2003-11-20 20:07:39 +00:00
|
|
|
int i;
|
|
|
|
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
|
2021-03-22 22:32:57 +00:00
|
|
|
head = &V_tcp_hostcache.hashbase[i];
|
|
|
|
hc_prev = NULL;
|
|
|
|
THC_LOCK(head);
|
|
|
|
CK_SLIST_FOREACH_SAFE(hc_entry, &head->hch_bucket, rmx_q,
|
|
|
|
hc_next) {
|
|
|
|
KASSERT(head->hch_length > 0 && head->hch_length <=
|
2021-04-08 21:23:23 +00:00
|
|
|
V_tcp_hostcache.bucket_limit, ("tcp_hostcache: "
|
2021-03-22 22:32:57 +00:00
|
|
|
"bucket length out of range at %u: %u", i,
|
|
|
|
head->hch_length));
|
|
|
|
if (all ||
|
|
|
|
atomic_load_int(&hc_entry->rmx_expire) <= 0) {
|
|
|
|
if (hc_prev != NULL) {
|
|
|
|
KASSERT(hc_entry ==
|
|
|
|
CK_SLIST_NEXT(hc_prev, rmx_q),
|
|
|
|
("%s: %p is not next to %p",
|
|
|
|
__func__, hc_entry, hc_prev));
|
|
|
|
CK_SLIST_REMOVE_AFTER(hc_prev, rmx_q);
|
|
|
|
} else {
|
|
|
|
KASSERT(hc_entry ==
|
|
|
|
CK_SLIST_FIRST(&head->hch_bucket),
|
|
|
|
("%s: %p is not first",
|
|
|
|
__func__, hc_entry));
|
|
|
|
CK_SLIST_REMOVE_HEAD(&head->hch_bucket,
|
|
|
|
rmx_q);
|
|
|
|
}
|
|
|
|
uma_zfree_smr(V_tcp_hostcache.zone, hc_entry);
|
|
|
|
head->hch_length--;
|
2021-04-01 08:00:32 +00:00
|
|
|
atomic_subtract_int(&V_tcp_hostcache.cache_count, 1);
|
2021-03-22 22:32:57 +00:00
|
|
|
} else {
|
|
|
|
atomic_subtract_int(&hc_entry->rmx_expire,
|
|
|
|
V_tcp_hostcache.prune);
|
|
|
|
hc_prev = hc_entry;
|
|
|
|
}
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
2021-03-22 22:32:57 +00:00
|
|
|
THC_UNLOCK(head);
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
2010-02-09 21:31:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expire and purge (old|all) entries in the tcp_hostcache. Runs
|
|
|
|
* periodically from the callout.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
tcp_hc_purge(void *arg)
|
|
|
|
{
|
|
|
|
CURVNET_SET((struct vnet *) arg);
|
|
|
|
int all = 0;
|
|
|
|
|
|
|
|
if (V_tcp_hostcache.purgeall) {
|
2021-04-08 18:28:43 +00:00
|
|
|
if (V_tcp_hostcache.purgeall == 2)
|
|
|
|
V_tcp_hostcache.hashsalt = arc4random();
|
2010-02-09 21:31:53 +00:00
|
|
|
all = 1;
|
|
|
|
V_tcp_hostcache.purgeall = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tcp_hc_purge_internal(all);
|
2008-08-20 01:05:56 +00:00
|
|
|
|
|
|
|
callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
|
|
|
|
tcp_hc_purge, arg);
|
Change the curvnet variable from a global const struct vnet *,
previously always pointing to the default vnet context, to a
dynamically changing thread-local one. The currvnet context
should be set on entry to networking code via CURVNET_SET() macros,
and reverted to previous state via CURVNET_RESTORE(). Recursions
on curvnet are permitted, though strongly discuouraged.
This change should have no functional impact on nooptions VIMAGE
kernel builds, where CURVNET_* macros expand to whitespace.
The curthread->td_vnet (aka curvnet) variable's purpose is to be an
indicator of the vnet context in which the current network-related
operation takes place, in case we cannot deduce the current vnet
context from any other source, such as by looking at mbuf's
m->m_pkthdr.rcvif->if_vnet, sockets's so->so_vnet etc. Moreover, so
far curvnet has turned out to be an invaluable consistency checking
aid: it helps to catch cases when sockets, ifnets or any other
vnet-aware structures may have leaked from one vnet to another.
The exact placement of the CURVNET_SET() / CURVNET_RESTORE() macros
was a result of an empirical iterative process, whith an aim to
reduce recursions on CURVNET_SET() to a minimum, while still reducing
the scope of CURVNET_SET() to networking only operations - the
alternative would be calling CURVNET_SET() on each system call entry.
In general, curvnet has to be set in three typicall cases: when
processing socket-related requests from userspace or from within the
kernel; when processing inbound traffic flowing from device drivers
to upper layers of the networking stack, and when executing
timer-driven networking functions.
This change also introduces a DDB subcommand to show the list of all
vnet instances.
Approved by: julian (mentor)
2009-05-05 10:56:12 +00:00
|
|
|
CURVNET_RESTORE();
|
2003-11-20 20:07:39 +00:00
|
|
|
}
|
2015-05-20 01:08:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Expire and purge all entries in hostcache immediately.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sysctl_tcp_hc_purgenow(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error, val;
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
error = sysctl_handle_int(oidp, &val, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
|
2021-04-08 18:28:43 +00:00
|
|
|
if (val == 2)
|
|
|
|
V_tcp_hostcache.hashsalt = arc4random();
|
2015-05-20 01:08:01 +00:00
|
|
|
tcp_hc_purge_internal(1);
|
|
|
|
|
|
|
|
callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
|
|
|
|
tcp_hc_purge, curvnet);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|