From nobody Tue Jul 28 21:20:53 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4h8pKf1Q1Rz6nJxq for ; Tue, 28 Jul 2026 21:20:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4h8pKd6dtlz3Pqx for ; Tue, 28 Jul 2026 21:20:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785273654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Nk6qIktRKC3l8Encs0X46Ghy/SK2qX+tww2W3fehuIc=; b=X0SJuhsunZD/1QKR9S5R7hGbsAegRhje5ZtCPsB20d0oF2e89pMZDPfEloHM+yDJN+iUdI qqs8RP/V7E1vWCeQnYidlNQLOhtJE8fAc7S/MvK4xQ+8XQFk2Od7FKbxQPpRFEaJJOnlbe tNjj80JbhDrDeFiju3ACx5bTxXkTkS9Efwgp+t7b76pUMSjetA9tqkwoaMfGdK1Q62ZWY5 KumHBMojo8h4RGd7Ar2DVnBKC/HMiFjxg5QKGbO5RGgj2TyO33ltqriNCG+btLNV9LiTv+ gAw08aM7MxB5uJLr+t6CbDYoR/WysH0T/WUET0jule7CsPNSubsiJi7YrA6ahQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785273653; a=rsa-sha256; cv=none; b=RdffyLu20mkdTr5znQ2evwEEBUTZ0wSoAaoEw0Uh5iVvQkSNba2sGUXuXYSDP0482sgpyW wd+5C0nXpfyXk0kuBZbAuZKkypQeCv5XOc+roxzm0zcjUXVlXBOOhtUov8Gz0JB+T8gvio eX0/jD9zb7x8/U3oAgmjG8S9KoK6G4+fr8e40jezel+kMFmcNFwxS04Ozg8ip1G33NMnsn M0l1TJeuDPef7j10ABxhp6TxcxLXi+n1yr5R4ZtIKXR+iuYKoa+0Dt9vOKh51v0ViTgZoc j2ext9twbIRQ/KiVMqz6BmN+JP+dDw4uPmYzNgnMetqW+mbWWk3JNv+Ee7jFnA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785273653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Nk6qIktRKC3l8Encs0X46Ghy/SK2qX+tww2W3fehuIc=; b=us47fZBEB+LIASl+NYc6Xbfs0Hrd2yvksoCGvEzB3bTmJsLMUz5loICrKju+ZoqaBvxMS5 UE+XA/ZL1EKCbAMzsBuhQDFfCBoJ5wgpeK0XDHId7kLuOo93gbqI9RnhsyX7RIyKqdqOyK mALJHvgRNhvQ96aLSXXNIE4SqfYuHrnE+w6w/VHj2mtkT9srLmIbDKcxApCyINh17rb081 GHEHUGuWQninNWOAwbWwcFSKRijwfbZFN+1hwIu54EIn4I5onUc7h/79usqPOSZjCdnk50 iJFV99Z5iEYLJjXa5RAYNqYbCIPewEFRTt2sr4fOgTgwSlov7Nwb71KCCDmjnA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h8pKd5hj3zxJ1 for ; Tue, 28 Jul 2026 21:20:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1f3ce by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 28 Jul 2026 21:20:53 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Richard Scheffenegger Subject: git: 2d01998e9e8a - main - tcp_hostcache: ensure expire and prune values stay consistent with each other List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rscheff X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2d01998e9e8ab3081d7f586d59dc41a487bb5f0c Auto-Submitted: auto-generated Date: Tue, 28 Jul 2026 21:20:53 +0000 Message-Id: <6a691d35.1f3ce.1a72d9e5@gitrepo.freebsd.org> The branch main has been updated by rscheff: URL: https://cgit.FreeBSD.org/src/commit/?id=2d01998e9e8ab3081d7f586d59dc41a487bb5f0c commit 2d01998e9e8ab3081d7f586d59dc41a487bb5f0c Author: Richard Scheffenegger AuthorDate: 2026-07-28 20:42:25 +0000 Commit: Richard Scheffenegger CommitDate: 2026-07-28 21:13:20 +0000 tcp_hostcache: ensure expire and prune values stay consistent with each other When configuring the expire timeout to something short, make sure that the prune time runs at least at that interval. Similarly, when adjusting the prune interval up, ensure the expire timeout reflect that expected minimum time also. Finally, restart the callout timer so that the next pruning happens after the new, expected interval. Reviewed By: glebius MFC after: 2 weeks Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D58424 --- sys/netinet/tcp_hostcache.c | 64 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/sys/netinet/tcp_hostcache.c b/sys/netinet/tcp_hostcache.c index 2ed035b6fd06..7a5e2ef095ec 100644 --- a/sys/netinet/tcp_hostcache.c +++ b/sys/netinet/tcp_hostcache.c @@ -128,9 +128,9 @@ struct tcp_hostcache { 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 @@ VNET_DEFINE_STATIC(struct callout, tcp_hc_callout); #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 @@ SYSCTL_UINT(_net_inet_tcp_hostcache, OID_AUTO, count, CTLFLAG_VNET | CTLFLAG_RD, &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 @@ SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, histo, "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"); @@ -620,6 +624,44 @@ tcp_hc_update(const struct in_conninfo *inc, struct tcp_hc_metrics *hcm) 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. @@ -831,7 +873,7 @@ sysctl_tcp_hc_purgenow(SYSCTL_HANDLER_ARGS) val = 0; error = sysctl_handle_int(oidp, &val, 0, req); - if (error || !req->newptr) + if (error != 0 || !req->newptr) return (error); if (val == 2)