From 94687c0059c89704004caaa98f84621952ae09b6 Mon Sep 17 00:00:00 2001 From: bluhm Date: Mon, 4 Sep 2023 23:00:36 +0000 Subject: [PATCH] Fix netstat output of uses of current SYN cache left. TCP syn cache variable scs_use is basically counting packet insertions into syn cache. Prefer type long to exclude overflow on fast machines. Due to counting downwards from a limit, it can become negative. Copy it out as tcps_sc_uses_left via sysctl, and print it as signed long long integer. OK mvs@ --- sys/netinet/tcp_var.h | 6 +++--- usr.bin/netstat/inet.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index be7e986f7b7..912381b5e9a 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.170 2023/08/28 14:50:02 bluhm Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.171 2023/09/04 23:00:36 bluhm Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -288,9 +288,9 @@ struct syn_cache_head { struct syn_cache_set { struct syn_cache_head *scs_buckethead; + long scs_use; int scs_size; int scs_count; - int scs_use; u_int32_t scs_random[5]; }; @@ -430,7 +430,7 @@ struct tcpstat { u_int64_t tcps_sc_entry_limit; /* limit of syn cache entries */ u_int64_t tcps_sc_bucket_maxlen;/* maximum # of entries in any bucket */ u_int64_t tcps_sc_bucket_limit; /* limit of syn cache bucket list */ - u_int64_t tcps_sc_uses_left; /* use counter of current syn cache */ + int64_t tcps_sc_uses_left; /* use counter of current syn cache */ u_int64_t tcps_conndrained; /* # of connections drained */ diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index a677d22a377..94089d5b8a1 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet.c,v 1.178 2023/07/07 09:15:13 yasuoka Exp $ */ +/* $OpenBSD: inet.c,v 1.179 2023/09/04 23:00:36 bluhm Exp $ */ /* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */ /* @@ -498,7 +498,7 @@ tcp_stats(char *name) "\t%llu entr%s in current SYN cache, limit is %llu\n"); p2b(tcps_sc_bucket_maxlen, tcps_sc_bucket_limit, "\t%llu longest bucket length in current SYN cache, limit is %llu\n"); - p(tcps_sc_uses_left, "\t%llu use%s of current SYN cache left\n"); + p(tcps_sc_uses_left, "\t%lld use%s of current SYN cache left\n"); p(tcps_sack_recovery_episode, "\t%llu SACK recovery episode%s\n"); p(tcps_sack_rexmits, -- 2.20.1