From nobody Mon Nov 11 14:09:08 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 4XnBHT4nb1z5bd4t; Mon, 11 Nov 2024 14:09:09 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XnBHT1X8pz3ymY; Mon, 11 Nov 2024 14:09:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731334149; 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=3tIGvOQebIBEWb+3ljC/MEbnQU/sSKT6w37suDLSLBg=; b=W4JhwjgwqIrjQs5FR4CjHwlbl232WT0GMdC5P8rKmMvVH4MIT3/KjTIqEsAeQk+MZfoffu jR4koWwUlXHF1+Gs+0Pczg3nDvJMq2uWQG/z5uZR4brpjSwyVEQUCk4IsLDMuLUxQkJHSj iNgwN7V6uS1dhkUY8jtPGVUJ11ICJ+c78FiUJ/p4YlCDOtGCgbvOGMY1pGxmmpfVkQ4GZA Ld0Uv7Bdy1DJ/i4lYpXjzTObGTraXY0k6j7ghTaOTHbJOkIL40Gxg+FxHD8/vbGzhOo/AH tiI6EGQE5qBfLDpwcYG7rVIq2h49hmKwTJhFA58lcd81Zq6kpFs0AnC/WcCilw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731334149; 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=3tIGvOQebIBEWb+3ljC/MEbnQU/sSKT6w37suDLSLBg=; b=bOQpqFi1kJG/+J7svDuW/u/KykoEV54LGXaezPR19ZKj2n+WYXoOBnPPmVs6ysFtIvWT+o 8N82EVhYJ6yWtNFOPtb4Rx+g5VTDTrp79dcx+IMGIl0y9CBke+fqO1BEzDsN1fZe8UPt/z wkvy9KfSda5/DFAY1iMOJCw4k61BcyJyyZ2uUwZxdR1c6zpqLAUZX2Iy10scFvEXzZRmfV RsbhAhhDb3t2cETuDud4UBsRBWmZm/0t7OLlEISRCXaV7+YleAQyaE04gKsJnwC+bEJ8n9 r8HS5BLPE1MeoZ1Cqr93tSCQO3aDxsgQ63wZ65LBkE/KXaaqqZhkbQemN/U8XQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731334149; a=rsa-sha256; cv=none; b=MV8r4v0wJ1XcdLOwhetwiC2ihvbWEjQH6hxPwvw79k5fOk/sD2rEmMXoq0MUFFZf8AHuPF GMvo7FSZHo6/ejPHrvbisjZWwIF72IhM3fnKQM7seUXFWQdurrjDRYLH0Xi3d/3AiZ1IcQ aenRYwhfJKgyO4gKLzM3jiHrPUEwYykDbCoSctVG4RXExgWHv+jzHUTwwpEXQeca5pbBz9 LrkZ4D3wlmabbB5sg6j8O41zKpAmI6eHVMetHW+uh87Z4ck6B/oErGIJqHcMX7SZqPjfWr pCAkkynUKmusIZjee6jZ3wn0GKSfQFMWdrzU/GN2HkY0MlmZVxqc7nm6zzRrEw== 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 4XnBHT0mjxzSmC; Mon, 11 Nov 2024 14:09:09 +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 4ABE98FF092080; Mon, 11 Nov 2024 14:09:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4ABE98QS092077; Mon, 11 Nov 2024 14:09:08 GMT (envelope-from git) Date: Mon, 11 Nov 2024 14:09:08 GMT Message-Id: <202411111409.4ABE98QS092077@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: 7f0981f8efeb - stable/14 - sockstat: Add a -f option to show FIB numbers of sockets 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: 7f0981f8efeb0fb8c97787e7075cb1f62dd239fe Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7f0981f8efeb0fb8c97787e7075cb1f62dd239fe commit 7f0981f8efeb0fb8c97787e7075cb1f62dd239fe Author: Mark Johnston AuthorDate: 2024-11-04 14:40:30 +0000 Commit: Mark Johnston CommitDate: 2024-11-11 14:01:55 +0000 sockstat: Add a -f option to show FIB numbers of sockets Reviewed by: zlei MFC after: 1 week Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D47316 (cherry picked from commit a471d2b401c9b2d3a95d9139c9a6b123f686a8e9) --- usr.bin/sockstat/sockstat.1 | 7 +++++-- usr.bin/sockstat/sockstat.c | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1 index d7174b48f8d5..ca486a088b13 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 July 9, 2024 +.Dd October 15, 2024 .Dt SOCKSTAT 1 .Os .Sh NAME @@ -33,7 +33,7 @@ .Nd list open sockets .Sh SYNOPSIS .Nm -.Op Fl 46CcIiLlnqSsUuvw +.Op Fl 46CcfIiLlnqSsUuvw .Op Fl j Ar jail .Op Fl p Ar ports .Op Fl P Ar protocols @@ -59,6 +59,8 @@ Display the congestion control module, if applicable. This is currently only implemented for TCP. .It Fl c Show connected sockets. +.It Fl f +Show the FIB number of each socket. .It Fl I Show the local address of the socket to which the current socket is spliced, if any. @@ -228,6 +230,7 @@ $ sockstat -6 -P tcp .Xr fstat 1 , .Xr netstat 1 , .Xr procstat 1 , +.Xr setfib 1 , .Xr inet 4 , .Xr inet6 4 , .Xr protocols 5 diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c index 0481e82efee0..c1886deb89e7 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_f; /* Show FIB numbers */ static int opt_I; /* Show spliced socket addresses */ static int opt_i; /* Show inp_gencnt */ static int opt_j; /* Show specified jail */ @@ -141,6 +142,7 @@ struct sock { int family; int proto; int state; + int fibnum; const char *protoname; char stack[TCP_FUNCTION_NAME_LEN_MAX]; char cc[TCP_CA_NAME_MAX]; @@ -772,6 +774,7 @@ gather_inet(int proto) sock->splice_socket = so->so_splice_so; sock->proto = proto; sock->inp_gencnt = xip->inp_gencnt; + sock->fibnum = so->so_fibnum; if (xip->inp_vflag & INP_IPV4) { sock->family = AF_INET; sockaddr(&laddr->address, sock->family, @@ -1205,6 +1208,12 @@ displaysock(struct sock *s, int pos) default: abort(); } + if (opt_f) { + while (pos < offset) + pos += xprintf(" "); + pos += xprintf("%d", s->fibnum); + offset += 7; + } if (opt_I) { if (s->splice_socket != 0) { struct sock *sp; @@ -1330,6 +1339,9 @@ display(void) "USER", "COMMAND", "PID", "FD", "PROTO", opt_w ? 45 : 21, "LOCAL ADDRESS", opt_w ? 45 : 21, "FOREIGN ADDRESS"); + if (opt_f) + /* RT_MAXFIBS is 65535. */ + printf(" %-6s", "FIB"); if (opt_I) printf(" %-*s", opt_w ? 45 : 21, "SPLICE ADDRESS"); if (opt_i) @@ -1454,9 +1466,8 @@ jail_getvnet(int jid) static void usage(void) { - fprintf(stderr, - "usage: sockstat [-46CcIiLlnqSsUuvw] [-j jid] [-p ports] [-P protocols]\n"); - exit(1); + errx(1, + "usage: sockstat [-46CcfIiLlnqSsUuvw] [-j jid] [-p ports] [-P protocols]"); } int @@ -1470,7 +1481,7 @@ main(int argc, char *argv[]) int o, i; opt_j = -1; - while ((o = getopt(argc, argv, "46CcIij:Llnp:P:qSsUuvw")) != -1) + while ((o = getopt(argc, argv, "46CcfIij:Llnp:P:qSsUuvw")) != -1) switch (o) { case '4': opt_4 = 1; @@ -1484,6 +1495,9 @@ main(int argc, char *argv[]) case 'c': opt_c = 1; break; + case 'f': + opt_f = 1; + break; case 'I': opt_I = 1; break;