From nobody Thu Oct 17 16:16:37 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XTtJ55sLsz5Z9LD; Thu, 17 Oct 2024 16:16:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XTtJ53qfZz42cD; Thu, 17 Oct 2024 16:16:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729181797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KvFJAdir/p8N+MJp5buLpXGqMrDneJifBYLCh4MuWp0=; b=wETZLBKNkbZy05KJotvFdYwa8dUGVcb7Ss6RIZGkfQKOSu3OQpgQz2rJsbOMAKuy2L2y4x n4NadDh9P0qEPraJpSIvYDH4UA4uONI+yB7IIYHkNUCMmejzoleL6fLGMypdyVrd1rIosd esh3nnWG/HGoNYrE5FGmnk00WQFjKdgqFMV3fJsP71VmVKR+JZd3hWCEiYi0PlAVgLoEd0 7c05YdymHSdkpWT24wana6+hKsoekuM5C2c6QeBxW2BGLtJ23w/JIQuYAMwUvGM2pW5kQq /LBgsbga6RRK4xC1Mq4O5OhmfjURkXcNk2qfDVnhjTWKE2jUljWEJt+xyZAieQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729181797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KvFJAdir/p8N+MJp5buLpXGqMrDneJifBYLCh4MuWp0=; b=mLd/rpFveRDwjRM0nEK1ppckcrbkUQuujSQZEv5F0c6skjon7WujjgbgueQd44bAct2hMs epXTYLwCzrnfiNtpRuV4g9kWgH5SD8UiREONqZ3cl4eLEcEVxgM4DIKSu/hq44uNqNN3+r 4I0jZ19oTQlV/28bgHvvLN11KAsEXd7nbUOOtCue2ptdaVy6WFHjCYb5S46DcbWy5xGdUw Wc4th+p5qFwDsZ5wa9s9zVhbmYgQmS4lIlfeop5/BfZyZTqLTwDgok+b43yMBiW5//LQz0 Lif8T18+OAunNhoPY/pq7QnxEdOuQDBdR9zVNzYSD16XhgIBeAb4Lp4pP6tVPw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729181797; a=rsa-sha256; cv=none; b=kb77gRo8y8Yf/WNh1HQgUj+ZsPHe8fTObcsHhfX6CMv/L03h3v4k3FOyNP4EAs9Ad4+m7X pvDlwupGe4XPloih+CNW/COcqbhU4g/jujacIy65pRl5baqfQRmkAfNPWWt1o1nxS2xp1n lafDG4RhPUzOmvt4An/2LD08v2arlNVDF+pfgclYel1J3YaMlxTQQZF4GGhlputTJYtf68 UmmHhcEANtzQtlSIlvGX1ZgMc3hiQlEfUvHdTt2E8KBl6u/Us8ki99eF/1bK9ch77cTSSg Pf7bCyW2VsQP94QFTTA226kJVC7LuJ66NNXTMVdtBAEIuStQ4HNwqWQUo85ONw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XTtJ52gC5zwvW; Thu, 17 Oct 2024 16:16:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49HGGbTA099182; Thu, 17 Oct 2024 16:16:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49HGGbYH099179; Thu, 17 Oct 2024 16:16:37 GMT (envelope-from git) Date: Thu, 17 Oct 2024 16:16:37 GMT Message-Id: <202410171616.49HGGbYH099179@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 51edbf66a816 - stable/14 - sockstat: Show the address of the spliced socket when -I is specified List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 51edbf66a8166a3698c875db8fbf00c965fa9f60 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=51edbf66a8166a3698c875db8fbf00c965fa9f60 commit 51edbf66a8166a3698c875db8fbf00c965fa9f60 Author: Mark Johnston AuthorDate: 2024-09-10 16:51:18 +0000 Commit: Mark Johnston CommitDate: 2024-10-17 15:48:37 +0000 sockstat: Show the address of the spliced socket when -I is specified MFC after: 3 months Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D46413 (cherry picked from commit 051a2132f41d8394a34b29ac3cfebf8601ede5b6) --- usr.bin/sockstat/sockstat.1 | 11 +++++++++-- usr.bin/sockstat/sockstat.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1 index 2e1b06688afa..d7174b48f8d5 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 June 6, 2022 +.Dd July 9, 2024 .Dt SOCKSTAT 1 .Os .Sh NAME @@ -33,7 +33,7 @@ .Nd list open sockets .Sh SYNOPSIS .Nm -.Op Fl 46CciLlnqSsUuvw +.Op Fl 46CcIiLlnqSsUuvw .Op Fl j Ar jail .Op Fl p Ar ports .Op Fl P Ar protocols @@ -59,6 +59,13 @@ Display the congestion control module, if applicable. This is currently only implemented for TCP. .It Fl c Show connected sockets. +.It Fl I +Show the local address of the socket to which the current socket is spliced, if +any. +See the +.Xr setsockopt 2 +.Dv SO_SPLICE +option for more information. .It Fl i Display the .Dv inp_gencnt . diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c index 56f107b5cdaf..0481e82efee0 100644 --- a/usr.bin/sockstat/sockstat.c +++ b/usr.bin/sockstat/sockstat.c @@ -83,6 +83,7 @@ static int opt_4; /* Show IPv4 sockets */ static int opt_6; /* Show IPv6 sockets */ static int opt_C; /* Show congestion control */ static int opt_c; /* Show connected sockets */ +static int opt_I; /* Show spliced socket addresses */ static int opt_i; /* Show inp_gencnt */ static int opt_j; /* Show specified jail */ static int opt_L; /* Don't show IPv4 or IPv6 loopback sockets */ @@ -133,6 +134,7 @@ struct sock { RB_ENTRY(sock) pcb_tree; kvaddr_t socket; kvaddr_t pcb; + kvaddr_t splice_socket; uint64_t inp_gencnt; int shown; int vflag; @@ -767,6 +769,7 @@ gather_inet(int proto) if ((faddr = calloc(1, sizeof *faddr)) == NULL) err(1, "malloc()"); sock->socket = so->xso_so; + sock->splice_socket = so->so_splice_so; sock->proto = proto; sock->inp_gencnt = xip->inp_gencnt; if (xip->inp_vflag & INP_IPV4) { @@ -1202,6 +1205,25 @@ displaysock(struct sock *s, int pos) default: abort(); } + if (opt_I) { + if (s->splice_socket != 0) { + struct sock *sp; + + sp = RB_FIND(socks_t, &socks, &(struct sock) + { .socket = s->splice_socket }); + if (sp != NULL) { + while (pos < offset) + pos += xprintf(" "); + pos += printaddr(&sp->laddr->address); + } else { + while (pos < offset) + pos += xprintf(" "); + pos += xprintf("??"); + offset += opt_w ? 46 : 22; + } + } + offset += opt_w ? 46 : 22; + } if (opt_i) { if (s->proto == IPPROTO_TCP || s->proto == IPPROTO_UDP) { @@ -1308,6 +1330,8 @@ display(void) "USER", "COMMAND", "PID", "FD", "PROTO", opt_w ? 45 : 21, "LOCAL ADDRESS", opt_w ? 45 : 21, "FOREIGN ADDRESS"); + if (opt_I) + printf(" %-*s", opt_w ? 45 : 21, "SPLICE ADDRESS"); if (opt_i) printf(" %-8s", "ID"); if (opt_U) @@ -1431,7 +1455,7 @@ static void usage(void) { fprintf(stderr, - "usage: sockstat [-46CciLlnqSsUuvw] [-j jid] [-p ports] [-P protocols]\n"); + "usage: sockstat [-46CcIiLlnqSsUuvw] [-j jid] [-p ports] [-P protocols]\n"); exit(1); } @@ -1446,7 +1470,7 @@ main(int argc, char *argv[]) int o, i; opt_j = -1; - while ((o = getopt(argc, argv, "46Ccij:Llnp:P:qSsUuvw")) != -1) + while ((o = getopt(argc, argv, "46CcIij:Llnp:P:qSsUuvw")) != -1) switch (o) { case '4': opt_4 = 1; @@ -1460,6 +1484,9 @@ main(int argc, char *argv[]) case 'c': opt_c = 1; break; + case 'I': + opt_I = 1; + break; case 'i': opt_i = 1; break;