git: 335bee05d914 - stable/15 - sockstat: provide more BBLog information

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Sat, 24 Oct 2026 10:52:46 UTC
The branch stable/15 has been updated by tuexen:

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

commit 335bee05d91467aa38caa68e8e4134c1c883c5e6
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2026-08-26 18:32:20 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2026-10-23 20:19:11 +0000

    sockstat: provide more BBLog information
    
    When using -b, provide in addition to the BBLog state also the number
    of entries stored at the endpoint, the corresponding upper limit and
    the next sequence number to be assigned.
    
    Reviewed by:            rrs
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D59131
    
    (cherry picked from commit 209668726c2fff047b27a13c6add7e9820696651)
---
 sys/netinet/tcp_subr.c      |  3 +++
 sys/netinet/tcp_var.h       |  5 ++++-
 usr.bin/sockstat/main.c     | 47 ++++++++++++++++++++++++++++++++++++++++++---
 usr.bin/sockstat/sockstat.1 | 17 ++++++++++++++--
 4 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 5cccb1e91d0b..533f19699074 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -4273,6 +4273,9 @@ tcp_inptoxtp(const struct inpcb *inp, struct xtcpcb *xt)
 	bcopy(CC_ALGO(tp)->name, xt->xt_cc, TCP_CA_NAME_MAX);
 #ifdef TCP_BLACKBOX
 	(void)tcp_log_get_id(tp, xt->xt_logid);
+	xt->t_lognum = tp->t_lognum;
+	xt->t_loglimit = tp->t_loglimit;
+	xt->t_logsn = tp->t_logsn;
 #endif
 
 	xt->xt_len = sizeof(struct xtcpcb);
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index f04d6ffde5bb..6e787387ef19 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -1231,7 +1231,10 @@ struct xtcpcb {
 	uint32_t	t_dsack_pack;		/* (n) */
 	uint16_t	xt_encaps_port;		/* (s) */
 	int16_t		spare16;
-	int32_t		spare32[22];
+	int32_t		t_lognum;		/* (s) */
+	int32_t		t_loglimit;		/* (s) */
+	uint32_t	t_logsn;		/* (s) */
+	int32_t		spare32[19];
 } __aligned(8);
 
 #ifdef _KERNEL
diff --git a/usr.bin/sockstat/main.c b/usr.bin/sockstat/main.c
index f334ba13d681..3dd794d598bd 100644
--- a/usr.bin/sockstat/main.c
+++ b/usr.bin/sockstat/main.c
@@ -146,6 +146,9 @@ struct sock {
 	int state;
 	int fibnum;
 	int bblog_state;
+	int bblog_num;
+	int bblog_limit;
+	unsigned int bblog_sn;
 	const char *protoname;
 	char stack[TCP_FUNCTION_NAME_LEN_MAX];
 	char cc[TCP_CA_NAME_MAX];
@@ -750,6 +753,9 @@ gather_inet(int proto)
 		if (proto == IPPROTO_TCP) {
 			sock->state = xtp->t_state;
 			sock->bblog_state = xtp->t_logstate;
+			sock->bblog_num = xtp->t_lognum;
+			sock->bblog_limit = xtp->t_loglimit;
+			sock->bblog_sn = xtp->t_logsn;
 			memcpy(sock->stack, xtp->xt_stack,
 			    TCP_FUNCTION_NAME_LEN_MAX);
 			memcpy(sock->cc, xtp->xt_cc, TCP_CA_NAME_MAX);
@@ -1195,6 +1201,9 @@ struct col_widths {
 	int path_state;
 	int conn_state;
 	int bblog_state;
+	int bblog_num;
+	int bblog_limit;
+	int bblog_sn;
 	int stack;
 	int cc;
 };
@@ -1321,6 +1330,12 @@ calculate_sock_column_widths(struct col_widths *cw, struct sock *s)
 			if (opt_b && s->proto == IPPROTO_TCP) {
 				len = strlen(bblog_state(s->bblog_state));
 				cw->bblog_state = MAX(cw->bblog_state, len);
+				len = snprintf(NULL, 0, "%d", s->bblog_num);
+				cw->bblog_num = MAX(cw->bblog_num, len);
+				len = snprintf(NULL, 0, "%d", s->bblog_limit);
+				cw->bblog_limit = MAX(cw->bblog_limit, len);
+				len = snprintf(NULL, 0, "%u", s->bblog_sn);
+				cw->bblog_sn = MAX(cw->bblog_sn, len);
 			}
 			first = false;
 		}
@@ -1545,13 +1560,32 @@ display_sock(struct sock *s, struct col_widths *cw, char *buf, size_t bufsize)
 					    cw->conn_state, "??");
 			}
 			if (opt_b) {
-				if (s->proto == IPPROTO_TCP)
+				if (s->proto == IPPROTO_TCP) {
 					xo_emit(" {:bblog-state/%-*s}",
 					    cw->bblog_state,
 					    bblog_state(s->bblog_state));
-				else if (!is_xo_style_encoding)
+					snprintf(buf, bufsize, "%d",
+					    s->bblog_num);
+					xo_emit(" {:bblog-number/%*s}",
+					    cw->bblog_num, buf);
+					snprintf(buf, bufsize, "%d",
+					    s->bblog_limit);
+					xo_emit(" {:bblog-limit/%*s}",
+					    cw->bblog_limit, buf);
+					snprintf(buf, bufsize, "%u",
+					    s->bblog_sn);
+					xo_emit(" {:bblog-serial-number/%*s}",
+					    cw->bblog_sn, buf);
+				} else if (!is_xo_style_encoding) {
 					xo_emit(" {:bblog-state/%-*s}",
 					    cw->bblog_state, "??");
+					xo_emit(" {:bblog-number/%*s}",
+					    cw->bblog_num, "??");
+					xo_emit(" {:bblog-limit/%*s}",
+					    cw->bblog_limit, "??");
+					xo_emit(" {:bblog-serial-number/%*s}",
+					    cw->bblog_sn, "??");
+				}
 			}
 			if (opt_S) {
 				if (s->proto == IPPROTO_TCP)
@@ -1625,6 +1659,9 @@ display(void)
 			.path_state = strlen("PATH STATE"),
 			.conn_state = strlen("CONN STATE"),
 			.bblog_state = strlen("BBLOG STATE"),
+			.bblog_num = strlen("BBLOG NUM"),
+			.bblog_limit = strlen("BBLOG LIM"),
+			.bblog_sn = strlen("BBLOG SN"),
 			.stack = strlen("STACK"),
 			.cc = strlen("CC"),
 		};
@@ -1659,8 +1696,12 @@ display(void)
 				    "PATH STATE");
 			xo_emit(" {T:/%-*s}", cw.conn_state, "CONN STATE");
 		}
-		if (opt_b)
+		if (opt_b) {
 			xo_emit(" {T:/%-*s}", cw.bblog_state, "BBLOG STATE");
+			xo_emit(" {T:/%*s}", cw.bblog_num, "BBLOG NUM");
+			xo_emit(" {T:/%*s}", cw.bblog_limit, "BBLOG LIM");
+			xo_emit(" {T:/%*s}", cw.bblog_sn, "BBLOG SN");
+		}
 		if (opt_S)
 			xo_emit(" {T:/%-*s}", cw.stack, "STACK");
 		if (opt_C)
diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1
index a8ea3ac0a88f..ea4924d99919 100644
--- a/usr.bin/sockstat/sockstat.1
+++ b/usr.bin/sockstat/sockstat.1
@@ -25,7 +25,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 15, 2026
+.Dd August 26, 2026
 .Dt SOCKSTAT 1
 .Os
 .Sh NAME
@@ -66,7 +66,7 @@ Show
 Show the address of a protocol control block (PCB) associated with a socket;
 used for debugging.
 .It Fl b
-Show the BBLog state of the socket.
+Show BBLog related information for the socket.
 This is currently only implemented for TCP.
 .It Fl C
 Display the congestion control module, if applicable.
@@ -215,6 +215,19 @@ is specified (only for SCTP or TCP).
 The BBLog state if
 .Fl b
 is specified (only for TCP).
+.It Li BBLOG NUM
+The number of BBLog entries currently being stored at the endpoint if
+.Fl b
+is specified (only for TCP).
+.It Li BBLOG LIM
+The maximum number of BBLog entries which can be stored at the endpoint
+if
+.Fl b
+is specified (only for TCP).
+.It Li BBLOG SN
+The next BBLog sequence number to be assigned if
+.Fl b
+is specified (only for TCP).
 .It Li STACK
 The protocol stack if
 .Fl S