Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F164713942
D58424.id182914.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D58424.id182914.diff
View Options
diff --git a/sys/netinet/tcp_hostcache.c b/sys/netinet/tcp_hostcache.c
--- a/sys/netinet/tcp_hostcache.c
+++ b/sys/netinet/tcp_hostcache.c
@@ -128,9 +128,9 @@
u_int bucket_limit;
u_int cache_count;
u_int cache_limit;
- int expire;
- int prune;
- int purgeall;
+ u_int expire;
+ u_int prune;
+ u_int purgeall;
};
/* Arbitrary values */
@@ -146,6 +146,8 @@
#define V_tcp_hc_callout VNET(tcp_hc_callout)
static struct hc_metrics *tcp_hc_lookup(const struct in_conninfo *);
+static int sysctl_tcp_hc_expire(SYSCTL_HANDLER_ARGS);
+static int sysctl_tcp_hc_prune(SYSCTL_HANDLER_ARGS);
static int sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS);
static int sysctl_tcp_hc_histo(SYSCTL_HANDLER_ARGS);
static int sysctl_tcp_hc_purgenow(SYSCTL_HANDLER_ARGS);
@@ -178,15 +180,17 @@
&VNET_NAME(tcp_hostcache.cache_count), 0,
"Current number of entries in hostcache");
-SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, expire, CTLFLAG_VNET | CTLFLAG_RW,
- &VNET_NAME(tcp_hostcache.expire), 0,
+SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, expire,
+ CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+ &VNET_NAME(tcp_hostcache.expire), 0, sysctl_tcp_hc_expire, "IU",
"Expire time of TCP hostcache entries");
-SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, prune, CTLFLAG_VNET | CTLFLAG_RW,
- &VNET_NAME(tcp_hostcache.prune), 0,
+SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, prune,
+ CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+ &VNET_NAME(tcp_hostcache.prune), 0, sysctl_tcp_hc_prune, "IU",
"Time between purge runs");
-SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, purge, CTLFLAG_VNET | CTLFLAG_RW,
+SYSCTL_UINT(_net_inet_tcp_hostcache, OID_AUTO, purge, CTLFLAG_VNET | CTLFLAG_RW,
&VNET_NAME(tcp_hostcache.purgeall), 0,
"Expire all entries on next purge run");
@@ -201,8 +205,8 @@
"Print a histogram of hostcache hashbucket utilization");
SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, purgenow,
- CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
- NULL, 0, sysctl_tcp_hc_purgenow, "I",
+ CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+ NULL, 0, sysctl_tcp_hc_purgenow, "IU",
"Immediately purge all entries");
static MALLOC_DEFINE(M_HOSTCACHE, "hostcache", "TCP hostcache");
@@ -619,6 +623,44 @@
THC_UNLOCK(hc_head);
}
+/*
+ * Sysctl function: adjusts the expire timeout and adjusts the prune value accordingly.
+ */
+static int
+sysctl_tcp_hc_expire(SYSCTL_HANDLER_ARGS)
+{
+ int error, expire;
+
+ expire = V_tcp_hostcache.expire;
+ error = sysctl_handle_int(oidp, &expire, 0, req);
+ if (error != 0 || !req->newptr)
+ return (error);
+ if (expire < V_tcp_hostcache.prune)
+ V_tcp_hostcache.prune = expire;
+ V_tcp_hostcache.expire = expire;
+ return (0);
+}
+
+/*
+ * Sysctl function: adjusts the prune time and adjusts the expire timeout accordingly.
+ */
+static int
+sysctl_tcp_hc_prune(SYSCTL_HANDLER_ARGS)
+{
+ int error, prune;
+
+ prune = V_tcp_hostcache.prune;
+ error = sysctl_handle_int(oidp, &prune, 0, req);
+ if (error != 0 || !req->newptr)
+ return (error);
+ if (prune > V_tcp_hostcache.expire)
+ V_tcp_hostcache.expire = prune;
+ V_tcp_hostcache.prune = prune;
+ callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
+ tcp_hc_purge, curvnet);
+ return (0);
+}
+
/*
* Sysctl function: prints the list and values of all hostcache entries in
* unsorted order.
@@ -830,7 +872,7 @@
val = 0;
error = sysctl_handle_int(oidp, &val, 0, req);
- if (error || !req->newptr)
+ if (error != 0 || !req->newptr)
return (error);
if (val == 2)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 4, 7:48 AM (4 m, 55 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35688664
Default Alt Text
D58424.id182914.diff (3 KB)
Attached To
Mode
D58424: tcp_hostcache: ensure expire and prune values stay consistent with each other
Attached
Detach File
Event Timeline
Log In to Comment