Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Jul 2026 21:20:52 +0000
From:      Richard Scheffenegger <rscheff@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 5de91610cc74 - main - tcp_hostcache: limit scope of struct hc_metrics_lite and rename with tcp_ prefix
Message-ID:  <6a691d34.1f7b5.2170b8c3@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by rscheff:

URL: https://cgit.FreeBSD.org/src/commit/?id=5de91610cc744815244c1adfe202408dbfc9dbf2

commit 5de91610cc744815244c1adfe202408dbfc9dbf2
Author:     Richard Scheffenegger <rscheff@FreeBSD.org>
AuthorDate: 2026-07-28 20:38:32 +0000
Commit:     Richard Scheffenegger <rscheff@FreeBSD.org>
CommitDate: 2026-07-28 21:13:08 +0000

    tcp_hostcache: limit scope of struct hc_metrics_lite and rename with tcp_ prefix
    
        Restrict the scope of the struct hc_metrics_lite to the kernel only.
        Update the naming to align with other kernel structures and add a tcp_ prefix.
    
    Reviewed by:            glebius
    MFC after:              2 weeks
    Sponsored by:           NetApp, Inc.
    Differential Revision:  https://reviews.freebsd.org/D58440
---
 sys/netinet/tcp_hostcache.c | 69 +++++++++++++++++++++++----------------------
 sys/netinet/tcp_input.c     | 10 +++----
 sys/netinet/tcp_subr.c      |  2 +-
 sys/netinet/tcp_var.h       | 10 ++++---
 4 files changed, 47 insertions(+), 44 deletions(-)

diff --git a/sys/netinet/tcp_hostcache.c b/sys/netinet/tcp_hostcache.c
index fbf81b1f2303..2ed035b6fd06 100644
--- a/sys/netinet/tcp_hostcache.c
+++ b/sys/netinet/tcp_hostcache.c
@@ -53,7 +53,7 @@
  * 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.
+ * tcp_hc_*() and the tcp_hc_metrics 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
@@ -371,12 +371,12 @@ tcp_hc_lookup(const struct in_conninfo *inc)
  */
 void
 tcp_hc_get(const struct in_conninfo *inc,
-    struct hc_metrics_lite *hc_metrics_lite)
+    struct tcp_hc_metrics *hc_metrics)
 {
 	struct hc_metrics *hc_entry;
 
 	if (!V_tcp_use_hostcache) {
-		bzero(hc_metrics_lite, sizeof(*hc_metrics_lite));
+		bzero(hc_metrics, sizeof(*hc_metrics));
 		return;
 	}
 
@@ -389,17 +389,17 @@ tcp_hc_get(const struct in_conninfo *inc,
 	 * If we don't have an existing object.
 	 */
 	if (hc_entry == NULL) {
-		bzero(hc_metrics_lite, sizeof(*hc_metrics_lite));
+		bzero(hc_metrics, sizeof(*hc_metrics));
 		return;
 	}
 
-	hc_metrics_lite->hc_mtu = atomic_load_32(&hc_entry->hc_mtu);
-	hc_metrics_lite->hc_ssthresh = atomic_load_32(&hc_entry->hc_ssthresh);
-	hc_metrics_lite->hc_rtt = atomic_load_32(&hc_entry->hc_rtt);
-	hc_metrics_lite->hc_rttvar = atomic_load_32(&hc_entry->hc_rttvar);
-	hc_metrics_lite->hc_cwnd = atomic_load_32(&hc_entry->hc_cwnd);
-	hc_metrics_lite->hc_sendpipe = atomic_load_32(&hc_entry->hc_sendpipe);
-	hc_metrics_lite->hc_recvpipe = atomic_load_32(&hc_entry->hc_recvpipe);
+	hc_metrics->hc_mtu = atomic_load_32(&hc_entry->hc_mtu);
+	hc_metrics->hc_ssthresh = atomic_load_32(&hc_entry->hc_ssthresh);
+	hc_metrics->hc_rtt = atomic_load_32(&hc_entry->hc_rtt);
+	hc_metrics->hc_rttvar = atomic_load_32(&hc_entry->hc_rttvar);
+	hc_metrics->hc_cwnd = atomic_load_32(&hc_entry->hc_cwnd);
+	hc_metrics->hc_sendpipe = atomic_load_32(&hc_entry->hc_sendpipe);
+	hc_metrics->hc_recvpipe = atomic_load_32(&hc_entry->hc_recvpipe);
 
 	smr_exit(V_tcp_hostcache.smr);
 }
@@ -436,9 +436,9 @@ tcp_hc_getmtu(const struct in_conninfo *inc)
 void
 tcp_hc_updatemtu(const struct in_conninfo *inc, uint32_t mtu)
 {
-	struct hc_metrics_lite hcml = { .hc_mtu = mtu };
+	struct tcp_hc_metrics hcm = { .hc_mtu = mtu };
 
-	return (tcp_hc_update(inc, &hcml));
+	return (tcp_hc_update(inc, &hcm));
 }
 
 /*
@@ -446,7 +446,7 @@ tcp_hc_updatemtu(const struct in_conninfo *inc, uint32_t mtu)
  * Creates a new entry if none was found.
  */
 void
-tcp_hc_update(const struct in_conninfo *inc, struct hc_metrics_lite *hcml)
+tcp_hc_update(const struct in_conninfo *inc, struct tcp_hc_metrics *hcm)
 {
 	struct hc_head *hc_head;
 	struct hc_metrics *hc_entry, *hc_prev;
@@ -543,59 +543,60 @@ tcp_hc_update(const struct in_conninfo *inc, struct hc_metrics_lite *hcml)
 	 * Fill in data.  Use atomics, since an existing entry is
 	 * accessible by readers in SMR section.
 	 */
-	if (hcml->hc_mtu != 0) {
-		atomic_store_32(&hc_entry->hc_mtu, hcml->hc_mtu);
+	if (hcm->hc_mtu != 0) {
+		atomic_store_32(&hc_entry->hc_mtu, hcm->hc_mtu);
 	}
-	if (hcml->hc_rtt != 0) {
+	if (hcm->hc_rtt != 0) {
 		if (hc_entry->hc_rtt == 0)
-			v = hcml->hc_rtt;
+			v = hcm->hc_rtt;
 		else
 			v = ((uint64_t)hc_entry->hc_rtt +
-			    (uint64_t)hcml->hc_rtt) / 2;
+			    (uint64_t)hcm->hc_rtt) / 2;
 		atomic_store_32(&hc_entry->hc_rtt, v);
 		TCPSTAT_INC(tcps_cachedrtt);
 	}
-	if (hcml->hc_rttvar != 0) {
+	if (hcm->hc_rttvar != 0) {
 	        if (hc_entry->hc_rttvar == 0)
-			v = hcml->hc_rttvar;
+			v = hcm->hc_rttvar;
 		else
 			v = ((uint64_t)hc_entry->hc_rttvar +
-			    (uint64_t)hcml->hc_rttvar) / 2;
+			    (uint64_t)hcm->hc_rttvar) / 2;
 		atomic_store_32(&hc_entry->hc_rttvar, v);
 		TCPSTAT_INC(tcps_cachedrttvar);
 	}
-	if (hcml->hc_ssthresh != 0) {
+	if (hcm->hc_ssthresh != 0) {
 		if (hc_entry->hc_ssthresh == 0)
-			v = hcml->hc_ssthresh;
+			v = hcm->hc_ssthresh;
 		else
-			v = (hc_entry->hc_ssthresh + hcml->hc_ssthresh) / 2;
+			v = (hc_entry->hc_ssthresh +
+			    hcm->hc_ssthresh) / 2;
 		atomic_store_32(&hc_entry->hc_ssthresh, v);
 		TCPSTAT_INC(tcps_cachedssthresh);
 	}
-	if (hcml->hc_cwnd != 0) {
+	if (hcm->hc_cwnd != 0) {
 		if (hc_entry->hc_cwnd == 0)
-			v = hcml->hc_cwnd;
+			v = hcm->hc_cwnd;
 		else
 			v = ((uint64_t)hc_entry->hc_cwnd +
-			    (uint64_t)hcml->hc_cwnd) / 2;
+			    (uint64_t)hcm->hc_cwnd) / 2;
 		atomic_store_32(&hc_entry->hc_cwnd, v);
 		/* TCPSTAT_INC(tcps_cachedcwnd); */
 	}
-	if (hcml->hc_sendpipe != 0) {
+	if (hcm->hc_sendpipe != 0) {
 		if (hc_entry->hc_sendpipe == 0)
-			v = hcml->hc_sendpipe;
+			v = hcm->hc_sendpipe;
 		else
 			v = ((uint64_t)hc_entry->hc_sendpipe +
-			    (uint64_t)hcml->hc_sendpipe) /2;
+			    (uint64_t)hcm->hc_sendpipe) / 2;
 		atomic_store_32(&hc_entry->hc_sendpipe, v);
 		/* TCPSTAT_INC(tcps_cachedsendpipe); */
 	}
-	if (hcml->hc_recvpipe != 0) {
+	if (hcm->hc_recvpipe != 0) {
 		if (hc_entry->hc_recvpipe == 0)
-			v = hcml->hc_recvpipe;
+			v = hcm->hc_recvpipe;
 		else
 			v = ((uint64_t)hc_entry->hc_recvpipe +
-			    (uint64_t)hcml->hc_recvpipe) /2;
+			    (uint64_t)hcm->hc_recvpipe) / 2;
 		atomic_store_32(&hc_entry->hc_recvpipe, v);
 		/* TCPSTAT_INC(tcps_cachedrecvpipe); */
 	}
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c
index 37706343d621..bfef374af2d9 100644
--- a/sys/netinet/tcp_input.c
+++ b/sys/netinet/tcp_input.c
@@ -359,7 +359,7 @@ cc_ack_received(struct tcpcb *tp, struct tcphdr *th, uint16_t nsegs,
 void
 cc_conn_init(struct tcpcb *tp)
 {
-	struct hc_metrics_lite metrics;
+	struct tcp_hc_metrics metrics;
 	struct inpcb *inp = tptoinpcb(tp);
 	u_int maxseg;
 	int rtt;
@@ -3714,12 +3714,12 @@ tcp_xmit_timer(struct tcpcb *tp, int rtt)
  */
 void
 tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer,
-    struct hc_metrics_lite *metricptr, struct tcp_ifcap *cap)
+    struct tcp_hc_metrics *metricptr, struct tcp_ifcap *cap)
 {
 	int mss = 0;
 	uint32_t maxmtu = 0;
 	struct inpcb *inp = tptoinpcb(tp);
-	struct hc_metrics_lite metrics;
+	struct tcp_hc_metrics metrics;
 #ifdef INET6
 	int isipv6 = ((inp->inp_vflag & INP_IPV6) != 0) ? 1 : 0;
 	size_t min_protoh = isipv6 ?
@@ -3765,7 +3765,7 @@ tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer,
 		 * if there was no cache hit.
 		 */
 		if (metricptr != NULL)
-			bzero(metricptr, sizeof(struct hc_metrics_lite));
+			bzero(metricptr, sizeof(struct tcp_hc_metrics));
 		return;
 	}
 
@@ -3876,7 +3876,7 @@ tcp_mss(struct tcpcb *tp, int offer)
 	uint32_t bufsize;
 	struct inpcb *inp = tptoinpcb(tp);
 	struct socket *so;
-	struct hc_metrics_lite metrics;
+	struct tcp_hc_metrics metrics;
 	struct tcp_ifcap cap;
 
 	KASSERT(tp != NULL, ("%s: tp == NULL", __func__));
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 7c56a7a77cb5..af381b0b4102 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -2479,7 +2479,7 @@ tcp_discardcb(struct tcpcb *tp)
 	 * say srtt etc into the general one used by other stacks.
 	 */
 	if (tp->t_rttupdated >= 4) {
-		struct hc_metrics_lite metrics;
+		struct tcp_hc_metrics metrics;
 		uint32_t ssthresh;
 
 		bzero(&metrics, sizeof(metrics));
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index fa8fdb570897..4f1e8fa9fd49 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -906,7 +906,8 @@ struct tcpopt {
  */
 #define	TO_SYN		0x01		/* parse SYN-only options */
 
-struct hc_metrics_lite {	/* must stay in sync with hc_metrics */
+#ifdef _KERNEL
+struct tcp_hc_metrics {
 	uint32_t	hc_mtu;		/* MTU for this path */
 	uint32_t	hc_ssthresh;	/* outbound gateway buffer limit */
 	uint32_t	hc_rtt;		/* estimated round trip time */
@@ -915,6 +916,7 @@ struct hc_metrics_lite {	/* must stay in sync with hc_metrics */
 	uint32_t	hc_sendpipe;	/* outbound delay-bandwidth product */
 	uint32_t	hc_recvpipe;	/* inbound delay-bandwidth product */
 };
+#endif	/* _KERNEL */
 
 #ifndef _NETINET_IN_PCB_H_
 struct in_conninfo;
@@ -1480,7 +1482,7 @@ uint32_t tcp_maxmtu6(struct in_conninfo *, struct tcp_ifcap *);
 void	 tcp6_use_min_mtu(struct tcpcb *);
 u_int	 tcp_maxseg(const struct tcpcb *);
 u_int	 tcp_fixed_maxseg(const struct tcpcb *);
-void	 tcp_mss_update(struct tcpcb *, int, int, struct hc_metrics_lite *,
+void	 tcp_mss_update(struct tcpcb *, int, int, struct tcp_hc_metrics *,
 	    struct tcp_ifcap *);
 void	 tcp_mss(struct tcpcb *, int);
 int	 tcp_mssopt(struct in_conninfo *);
@@ -1510,10 +1512,10 @@ void	 tcp_hc_init(void);
 #ifdef VIMAGE
 void	 tcp_hc_destroy(void);
 #endif
-void	 tcp_hc_get(const struct in_conninfo *, struct hc_metrics_lite *);
+void	 tcp_hc_get(const struct in_conninfo *, struct tcp_hc_metrics *);
 uint32_t tcp_hc_getmtu(const struct in_conninfo *);
 void	 tcp_hc_updatemtu(const struct in_conninfo *, uint32_t);
-void	 tcp_hc_update(const struct in_conninfo *, struct hc_metrics_lite *);
+void	 tcp_hc_update(const struct in_conninfo *, struct tcp_hc_metrics *);
 void 	 cc_after_idle(struct tcpcb *tp);
 
 extern	struct protosw tcp_protosw;		/* shared for TOE */


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a691d34.1f7b5.2170b8c3>