From nobody Tue Sep 10 16:55:24 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 4X38vx1QK6z5WCBZ; Tue, 10 Sep 2024 16:55:25 +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 4X38vw3bSfz44S0; Tue, 10 Sep 2024 16:55:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725987324; 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=yygYstyVRTwg23VeD6ImSMuvCOlprUrup4uvKTQEYo4=; b=gfDExBWkhSiC9/NN0QRrTgSKioRyZVMIPaSF/47d2Ftiq+nYiIpY39DEqi6+6d0zRByW5c 8cG8WM2ZL3a+fG+3ERtfaBPSNb12A14HS4ncK9/rPmaSurA0hJJ2F+wdiQyFSQLFLukcIW GUdh2Xfoe3huiIMVjaodfmI3rS/FlQpufzMRlH6pnyYfvJg/Tp0wJ6uTAZcODm7Tv1zQXX qw6NFuK8rTR7x7IMdWHnf7FqF1rYtmRRg9PjoqdhoByFvUNMmqBIVOKLiz4nJWWuYoIKGD LbXb6eKBTDbpzy78j9/ffjYun7vyOwOGr0qJgcFkEXtHAbJ14BVWB017RewuVA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725987324; a=rsa-sha256; cv=none; b=JYEH/ONrWoieX4u3Pw/QSX0XUvJabE5vDHSmn8cU/ne1+K2YS9/o5QBVDxEumnu1F5uBIc O7sYDXkECVjxgr/MrB9BgfZAgZ6eYZrMBqkhJUgKq5WyflbH+pPnHhVs5smEtNxyyv5ct+ v82U/KC9ixOMw35BGNc6X8KHrFWEmbWSqQPyoB1hPB3Hd3NYKBfrp/wzgmJVvFB4WB+WHE QMQoPuPhL5FjEhvAVhFoxe6qdpSdb1wSu777IuHja4qIsv0V/yQ5I3Jn104zwsIdm7g07o NuzhijsnoNjSvhj+MmjIfJ3Ji7TI4Jd0/223WkYfBIviaJfemea+UzNMVCiBSQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725987324; 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=yygYstyVRTwg23VeD6ImSMuvCOlprUrup4uvKTQEYo4=; b=xvq2MTVA0NAW12iXBGx8eEUlJguzGhW8IEw111dvDC8uBUWxBTtyWhrmhYvItXLaVH+m55 DN5Sr2BKWqwqb1J0yUVcS4ETXOPxbnBWQ3FTBdr5HsINk053LaA0z0F20Hr1lJdUyVpPRj V65UpU5rb3KUFMntpWXG1cPi3B2oDOyomfPo9fCBi8J5yIzyAUPPN2a8c4adSTyCJxYlM5 2Vp4F0BZ2qVH6SI7KZtOZIwOBY/HyfFNMAf2I1UC/01w6u/nGaE2usUQgTbKw9uZ5EQy23 gskgQNbqGJMSRKrPNLyEKD8zwaKTBaw5Sh9ILkM50Pmat58RB7Gjqe+5R4m0Yg== 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 4X38vw3C3VzvxD; Tue, 10 Sep 2024 16:55:24 +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 48AGtO38084079; Tue, 10 Sep 2024 16:55:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48AGtObN084076; Tue, 10 Sep 2024 16:55:24 GMT (envelope-from git) Date: Tue, 10 Sep 2024 16:55:24 GMT Message-Id: <202409101655.48AGtObN084076@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 051a2132f41d - main - 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/main X-Git-Reftype: branch X-Git-Commit: 051a2132f41d8394a34b29ac3cfebf8601ede5b6 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=051a2132f41d8394a34b29ac3cfebf8601ede5b6 commit 051a2132f41d8394a34b29ac3cfebf8601ede5b6 Author: Mark Johnston AuthorDate: 2024-09-10 16:51:18 +0000 Commit: Mark Johnston CommitDate: 2024-09-10 16:52:01 +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 --- 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 5eac327ca184..d2581d9f042e 100644 --- a/usr.bin/sockstat/sockstat.c +++ b/usr.bin/sockstat/sockstat.c @@ -82,6 +82,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 */ @@ -132,6 +133,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; @@ -766,6 +768,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) { @@ -1201,6 +1204,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) { @@ -1307,6 +1329,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) @@ -1430,7 +1454,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); } @@ -1445,7 +1469,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; @@ -1459,6 +1483,9 @@ main(int argc, char *argv[]) case 'c': opt_c = 1; break; + case 'I': + opt_I = 1; + break; case 'i': opt_i = 1; break;