git: 9f55128fecb5 - main - sockstat: with -A print pcb addresses, just like netstat(1)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 11 Feb 2025 18:23:53 UTC
The branch main has been updated by glebius:
URL: https://cgit.FreeBSD.org/src/commit/?id=9f55128fecb5b5eb8e8fffa5b65d38255762d176
commit 9f55128fecb5b5eb8e8fffa5b65d38255762d176
Author: Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2025-02-11 18:23:15 +0000
Commit: Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2025-02-11 18:23:15 +0000
sockstat: with -A print pcb addresses, just like netstat(1)
---
usr.bin/sockstat/sockstat.1 | 7 +++++--
usr.bin/sockstat/sockstat.c | 20 +++++++++++++++-----
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1
index ca486a088b13..b13c6afdd9c0 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 October 15, 2024
+.Dd February 6, 2025
.Dt SOCKSTAT 1
.Os
.Sh NAME
@@ -33,7 +33,7 @@
.Nd list open sockets
.Sh SYNOPSIS
.Nm
-.Op Fl 46CcfIiLlnqSsUuvw
+.Op Fl 46ACcfIiLlnqSsUuvw
.Op Fl j Ar jail
.Op Fl p Ar ports
.Op Fl P Ar protocols
@@ -54,6 +54,9 @@ Show
Show
.Dv AF_INET6
(IPv6) sockets.
+.It Fl A
+Show the address of a protocol control block (PCB) associated with a socket;
+used for debugging.
.It Fl C
Display the congestion control module, if applicable.
This is currently only implemented for TCP.
diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c
index 6283f600b322..e1a52c57b3d1 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -81,6 +81,7 @@
static bool opt_4; /* Show IPv4 sockets */
static bool opt_6; /* Show IPv6 sockets */
+static bool opt_A; /* Show kernel address of pcb */
static bool opt_C; /* Show congestion control */
static bool opt_c; /* Show connected sockets */
static bool opt_f; /* Show FIB numbers */
@@ -771,6 +772,7 @@ gather_inet(int proto)
if ((faddr = calloc(1, sizeof *faddr)) == NULL)
err(1, "malloc()");
sock->socket = so->xso_so;
+ sock->pcb = so->so_pcb;
sock->splice_socket = so->so_splice_so;
sock->proto = proto;
sock->inp_gencnt = xip->inp_gencnt;
@@ -1206,10 +1208,13 @@ displaysock(struct sock *s, int pos)
default:
abort();
}
+ while (pos < offset)
+ pos += xprintf(" ");
+ if (opt_A) {
+ pos += xprintf("0x%16lx", s->pcb);
+ offset += 18;
+ }
if (opt_f) {
- do
- pos += xprintf(" ");
- while (pos < offset);
pos += xprintf("%d", s->fibnum);
offset += 7;
}
@@ -1346,6 +1351,8 @@ display(void)
"USER", "COMMAND", "PID", "FD", "PROTO",
opt_w ? 45 : 21, "LOCAL ADDRESS",
opt_w ? 45 : 21, "FOREIGN ADDRESS");
+ if (opt_A)
+ printf(" %-18s", "PCB KVA");
if (opt_f)
/* RT_MAXFIBS is 65535. */
printf(" %-6s", "FIB");
@@ -1477,7 +1484,7 @@ static void
usage(void)
{
errx(1,
- "usage: sockstat [-46CcfIiLlnqSsUuvw] [-j jid] [-p ports] [-P protocols]");
+ "usage: sockstat [-46ACcfIiLlnqSsUuvw] [-j jid] [-p ports] [-P protocols]");
}
int
@@ -1491,7 +1498,7 @@ main(int argc, char *argv[])
int o, i;
opt_j = -1;
- while ((o = getopt(argc, argv, "46CcfIij:Llnp:P:qSsUuvw")) != -1)
+ while ((o = getopt(argc, argv, "46ACcfIij:Llnp:P:qSsUuvw")) != -1)
switch (o) {
case '4':
opt_4 = true;
@@ -1499,6 +1506,9 @@ main(int argc, char *argv[])
case '6':
opt_6 = true;
break;
+ case 'A':
+ opt_A = true;
+ break;
case 'C':
opt_C = true;
break;