git: df4b9fa460ab - main - snmp_mibII: use sysctl(3) to read min/max TCP retransmission timeouts

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Tue, 17 Jun 2025 15:54:36 UTC
The branch main has been updated by glebius:

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

commit df4b9fa460ab7f31d11b046d6f3335be101bc576
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2025-06-17 15:53:50 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2025-06-17 15:54:18 +0000

    snmp_mibII: use sysctl(3) to read min/max TCP retransmission timeouts
    
    Reviewed by:            tuexen
    Differential Revision:  https://reviews.freebsd.org/D50892
---
 contrib/bsnmp/snmp_mibII/mibII_tcp.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/contrib/bsnmp/snmp_mibII/mibII_tcp.c b/contrib/bsnmp/snmp_mibII/mibII_tcp.c
index e6d5920d9f88..551db06e9f0f 100644
--- a/contrib/bsnmp/snmp_mibII/mibII_tcp.c
+++ b/contrib/bsnmp/snmp_mibII/mibII_tcp.c
@@ -36,7 +36,6 @@
 #include <netinet/in_pcb.h>
 #include <netinet/tcp.h>
 #include <netinet/tcp_var.h>
-#include <netinet/tcp_timer.h>
 #include <netinet/tcp_fsm.h>
 
 struct tcp_index {
@@ -51,7 +50,8 @@ static uint64_t tcps_states[TCP_NSTATES];
 static struct xinpgen *xinpgen;
 static size_t xinpgen_len;
 static u_int tcp_total;
-
+static int tcp_rexmit_min;
+static int tcp_rexmit_max;
 static u_int oidnum;
 static struct tcp_index *tcpoids;
 
@@ -90,6 +90,28 @@ fetch_tcp_stats(void)
 		return (-1);
 	}
 
+	len = sizeof(tcp_rexmit_min);
+	if (sysctlbyname("net.inet.tcp.rexmit_min", &tcp_rexmit_min, &len,
+	    NULL, 0) == -1) {
+		syslog(LOG_ERR, "net.inet.tcp.rexmit_min: %m");
+		return (-1);
+	}
+	if (len != sizeof(tcp_rexmit_min)) {
+		syslog(LOG_ERR, "net.inet.tcp.rexmit_min: wrong size");
+		return (-1);
+	}
+
+	len = sizeof(tcp_rexmit_max);
+	if (sysctlbyname("net.inet.tcp.rexmit_max", &tcp_rexmit_max, &len,
+	    NULL, 0) == -1) {
+		syslog(LOG_ERR, "net.inet.tcp.rexmit_max: %m");
+		return (-1);
+	}
+	if (len != sizeof(tcp_rexmit_max)) {
+		syslog(LOG_ERR, "net.inet.tcp.rexmit_max: wrong size");
+		return (-1);
+	}
+
 	tcp_stats_tick = get_ticks();
 
 	return (0);
@@ -211,16 +233,13 @@ op_tcp(struct snmp_context *ctx __unused, struct snmp_value *value,
 		value->v.integer = 4;	/* Van Jacobson */
 		break;
 
-#define hz clockinfo.hz
-
 	  case LEAF_tcpRtoMin:
-		value->v.integer = 1000 * TCPTV_MIN / hz;
+		value->v.integer = tcp_rexmit_min;
 		break;
 
 	  case LEAF_tcpRtoMax:
-		value->v.integer = 1000 * TCPTV_REXMTMAX / hz;
+		value->v.integer = tcp_rexmit_max;
 		break;
-#undef hz
 
 	  case LEAF_tcpMaxConn:
 		value->v.integer = -1;