git: 6e95753ac517 - stable/14 - ddb: add show all tcpcbs

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Thu, 04 Sep 2025 20:01:02 UTC
The branch stable/14 has been updated by tuexen:

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

commit 6e95753ac51716aec45cef049e1493d3c96874b1
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2025-05-28 10:25:26 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2025-09-04 20:00:15 +0000

    ddb: add show all tcpcbs
    
    Add a command to show all TCP control blocks. Also provide an option
    to limit the output to TCP control blocks, which are locked.
    The plan is to run show all tcpcbs/l when syzkaller triggers a panic.
    If a TCP control block is affected, it is most likely locked and
    therefore the command shows the information of the affected TCP
    control block.
    
    Reviewed by:            markj, thj
    Tested by:              thj
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D50516
    
    (cherry picked from commit f1430567f26bc84db3818914fa91c74507d1602a)
---
 share/man/man4/ddb.4     | 10 +++++++++-
 sys/netinet/tcp_usrreq.c | 23 +++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/share/man/man4/ddb.4 b/share/man/man4/ddb.4
index 0bab4dc3e61b..cb14f42da489 100644
--- a/share/man/man4/ddb.4
+++ b/share/man/man4/ddb.4
@@ -24,7 +24,7 @@
 .\" any improvements or extensions that they make and grant Carnegie Mellon
 .\" the rights to redistribute these changes.
 .\"
-.Dd May 24, 2025
+.Dd May 28, 2025
 .Dt DDB 4
 .Os
 .Sh NAME
@@ -580,6 +580,14 @@ The
 modifier will print command line arguments for each process.
 .\"
 .Pp
+.It Ic show Cm all tcpcbs Ns Op Li / Ns Cm l
+Show the same output as "show tcpcb" does, but for all
+TCP control blocks within the system.
+Using the
+.Cm l
+modifier will limit the output to TCP control blocks, which are locked.
+.\"
+.Pp
 .It Ic show Cm all trace
 .It Ic alltrace
 Show a stack trace for every thread in the system.
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 7bad828c4821..e0e921ebc42e 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -3255,4 +3255,27 @@ DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
 
 	db_print_tcpcb(tp, "tcpcb", 0);
 }
+
+DB_SHOW_ALL_COMMAND(tcpcbs, db_show_all_tcpcbs)
+{
+	VNET_ITERATOR_DECL(vnet_iter);
+	struct inpcb *inp;
+	bool only_locked;
+
+	only_locked = strchr(modif, 'l') != NULL;
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		CK_LIST_FOREACH(inp, &V_tcbinfo.ipi_listhead, inp_list) {
+			if (only_locked &&
+			    inp->inp_lock.rw_lock == RW_UNLOCKED)
+				continue;
+			db_print_tcpcb(intotcpcb(inp), "tcpcb", 0);
+			if (db_pager_quit)
+				break;
+		}
+		CURVNET_RESTORE();
+		if (db_pager_quit)
+			break;
+	}
+}
 #endif