From nobody Thu Mar 12 16:40:51 2026 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 4fWtfK3FJVz6VchN for ; Thu, 12 Mar 2026 16:40:57 +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 "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fWtfK1WgJz3Fh3 for ; Thu, 12 Mar 2026 16:40:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1773333657; 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=YosNvTPzps/GCgSsnP3UIna+PRZbZz0sE/cwHaANOZI=; b=kZLzjOs7aYcoe1qTlRNR7qRB6jb38rFBU22KJ2jydfIRe7J4Pgcs7OL757FR1/uO3LDguR CHoCsfxpvpVGEqpT3e3k5/qFOmIp6d1zJ7YnZrH32k0cducU9NsRsOGqXZMqhlbQmhADdV gZlOr7oD9wYxv3AXckmPTQ6CaTGxNp7xvog3dQu9cTF5LAo5A+v3nnh0Vsw6kvfvzoNoXw gI11pcCJSlMglkjGU54cDh1VTGG5YqWZdh5rgbzCwypXjzjzmJZSzgE9Nshtl6Vsy/UigA owVBhbeiYoPFqXyJMboVCQsqE4D5N4P+yPw/OV/QTfRWZftEX5vCs7RsxC6lCw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1773333657; a=rsa-sha256; cv=none; b=sjuz7y0pQsHgVvb/Y41a5XtHrt3CiXPXaZNcqPg5GJCxRGq7jFZ1nj5ronboSVahtV1p0x dfAe8XUmlagipooOgn5QrAQvkkMV8x+FRQxPUz/j7UrWihVFmsZbPU+hvBp17C9KULMG+m Zt5WAj5R4bQgzEbmn++O6+sqfifj9+aZGO2OxUbHQ4mCwoMlNOjdymxy/CM66We54bXQW8 SSSd6c7j3ID4oJi3yBn3o3J68v+CZUiZr0UAL5IzXltIyhQmsYLDC8Q2hTPfPpH1vE5koO CIto3hu3Peh38NVTcyniqp/4sOVfRJr3rFSlLcJvN1OO5QJiD1AJsYcnPIl6uQ== 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=1773333657; 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=YosNvTPzps/GCgSsnP3UIna+PRZbZz0sE/cwHaANOZI=; b=d/4vl83QuLSywYWaXQNkZ3wgVPaNGnoMCRpWvdW1/kfMpmejjqfEDar4UFfS1daFZp2crZ UkfeiPW97nrk+Vu5DpfbcUdUi9MuRqYDxF2Mk4c/6+SWKKQHkvaSOr6wKepvxHTaSA7hdW DjuZOPkFaXUPMTzTNPYDPK7SNYdQuNsPW31CemFZo2Dx3a7ti43t1WTmP3l+8dZ9hVJze1 8StbGF+oZEe4D1ZjXHe4y8oOYyaO6anoZML8ixCF0KctNb3DtZI4SwjMAzIjzfWvYD7axZ HOfA/it3gLTBFMgDEml6C0tv3trUxw5Mse1vuIWAJLLNQUatQLUdNyeAiWb+wA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fWtfK0GjJztXh for ; Thu, 12 Mar 2026 16:40:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 44d2a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 12 Mar 2026 16:40:51 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 985ac741384e - main - systat: remove kvm(3) support for -netstat mode 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 985ac741384ec65463669edee5e1d90dee4c895a Auto-Submitted: auto-generated Date: Thu, 12 Mar 2026 16:40:51 +0000 Message-Id: <69b2ec93.44d2a.2c71c859@gitrepo.freebsd.org> The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=985ac741384ec65463669edee5e1d90dee4c895a commit 985ac741384ec65463669edee5e1d90dee4c895a Author: Gleb Smirnoff AuthorDate: 2026-03-12 04:16:44 +0000 Commit: Gleb Smirnoff CommitDate: 2026-03-12 16:37:52 +0000 systat: remove kvm(3) support for -netstat mode The kvm(3) mode was actually non-functional since FreeBSD 8 for kernels with VIMAGE, since FreeBSD 12 for the GENERIC kernel and since FreeBSD 14 for all kernels. The reason for that is that systat(1) tried to lookup symbol "tcb" to check if kvm(3) is working. The symbol no longer exist in the kernel. A side effect was that systat(1) lost true kvm(3) support for all other modes, e.g. -swap or -pigs. The tool was still working, but libkvm was just a shim to sysctl(3) API. So, contrary to what the header line says, this change actually restores the kvm(3) support for other modes. Now we read the "allproc" symbol. This was the last tool that abused _WANT_INPCB. --- usr.bin/systat/extern.h | 2 - usr.bin/systat/main.c | 5 +- usr.bin/systat/netstat.c | 132 ++++------------------------------------------- usr.bin/systat/systat.h | 11 ---- 4 files changed, 14 insertions(+), 136 deletions(-) diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h index 8d19aec024b4..4d9f686dcc65 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -69,8 +69,6 @@ extern int num_selected; extern int num_selections; extern long select_generation; -extern struct nlist namelist[]; - int checkhost(struct in_conninfo *); int checkport(struct in_conninfo *); void closeicmp(WINDOW *); diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c index dbb82ebbb1c0..3582447281b6 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -64,7 +64,6 @@ char *namp; char hostname[MAXHOSTNAMELEN]; WINDOW *wnd; int CMDLINE; -int use_kvm = 1; static WINDOW *wload; /* one line window for load average */ @@ -166,6 +165,9 @@ main(int argc, char **argv) } kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); if (kd != NULL) { + struct nlist namelist[] = { { .n_name = "allproc" }, + { .n_name = NULL } }; + /* * Try to actually read something, we may be in a jail, and * have /dev/null opened as /dev/mem. @@ -182,7 +184,6 @@ main(int argc, char **argv) * Maybe we are lacking permissions? Retry, this time with bogus * devices. We can now use sysctl only. */ - use_kvm = 0; kd = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, _PATH_DEVNULL, O_RDONLY, errbuf); if (kd == NULL) { diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c index d9a0266aaea4..31838fc207d8 100644 --- a/usr.bin/systat/netstat.c +++ b/usr.bin/systat/netstat.c @@ -38,7 +38,6 @@ #include #include #include -#define _WANT_SOCKET #include #include @@ -50,7 +49,6 @@ #ifdef INET6 #include #endif -#define _WANT_INPCB #include #include #include @@ -60,7 +58,6 @@ #include #define TCPSTATES #include -#define _WANT_TCPCB #include #include #include @@ -74,11 +71,7 @@ #include "systat.h" #include "extern.h" -static struct netinfo *enter(struct in_conninfo *, uint8_t, int, const char *); -static void enter_kvm(struct inpcb *, struct socket *, int, const char *); -static void enter_sysctl(struct xinpcb *, struct xsocket *, int, const char *); -static void fetchnetstat_kvm(void); -static void fetchnetstat_sysctl(void); +static void enter(struct xinpcb *, struct xsocket *so, int, const char *); static char *inetname(struct sockaddr *); static void inetprint(struct sockaddr *, const char *); @@ -138,16 +131,6 @@ static const char *miblist[] = { "net.inet.udp.pcblist" }; -static char tcb[] = "tcb", udb[] = "udb"; - -struct nlist namelist[] = { -#define X_TCB 0 - { .n_name = tcb }, -#define X_UDB 1 - { .n_name = udb }, - { .n_name = NULL }, -}; - int initnetstat(void) { @@ -157,77 +140,6 @@ initnetstat(void) void fetchnetstat(void) -{ - if (use_kvm) - fetchnetstat_kvm(); - else - fetchnetstat_sysctl(); -} - -static void -fetchnetstat_kvm(void) -{ - struct netinfo *p; - struct inpcbhead head; - struct socket sockb; - struct tcpcb tcpcb; - struct inpcb *inpcb; - void *off; - int istcp; - - if (namelist[X_TCB].n_value == 0) - return; - TAILQ_FOREACH(p, &netcb, chain) - p->ni_seen = 0; - if (protos&TCP) { - off = NPTR(X_TCB); - istcp = 1; - } - else if (protos&UDP) { - off = NPTR(X_UDB); - istcp = 0; - } - else { - error("No protocols to display"); - return; - } -again: - KREAD(off, &head, sizeof (struct inpcbhead)); - LIST_FOREACH(inpcb, &head, inp_list) { - KREAD(inpcb, &tcpcb, istcp ? sizeof(tcpcb) : sizeof(inpcb)); - inpcb = (struct inpcb *)&tcpcb; - if (!aflag) { - if (inpcb->inp_vflag & INP_IPV4) { - if (inpcb->inp_laddr.s_addr == INADDR_ANY) - continue; - } -#ifdef INET6 - else if (inpcb->inp_vflag & INP_IPV6) { - if (memcmp(&inpcb->in6p_laddr, - &in6addr_any, sizeof(in6addr_any)) == 0) - continue; - } -#endif - } - if (nhosts && !checkhost(&inpcb->inp_inc)) - continue; - if (nports && !checkport(&inpcb->inp_inc)) - continue; - if (istcp) { - KREAD(inpcb->inp_socket, &sockb, sizeof (sockb)); - enter_kvm(inpcb, &sockb, tcpcb.t_state, "tcp"); - } else - enter_kvm(inpcb, &sockb, 0, "udp"); - } - if (istcp && (protos&UDP)) { - istcp = 0; - off = NPTR(X_UDB); - goto again; - } -} - -static void -fetchnetstat_sysctl(void) { struct netinfo *p; int idx; @@ -303,41 +215,20 @@ fetchnetstat_sysctl(void) if (nports && !checkport(&xip->inp_inc)) continue; if (idx == 0) - enter_sysctl(xip, &xip->xi_socket, - xtp->t_state, "tcp"); + enter(xip, &xip->xi_socket, xtp->t_state, + "tcp"); else - enter_sysctl(xip, &xip->xi_socket, 0, "udp"); + enter(xip, &xip->xi_socket, 0, "udp"); } free(inpg); } } static void -enter_kvm(struct inpcb *inp, struct socket *so, int state, const char *proto) -{ - struct netinfo *p; - - if ((p = enter(&inp->inp_inc, inp->inp_vflag, state, proto)) != NULL) { - p->ni_rcvcc = so->so_rcv.sb_ccc; - p->ni_sndcc = so->so_snd.sb_ccc; - } -} - -static void -enter_sysctl(struct xinpcb *xip, struct xsocket *so, int state, - const char *proto) -{ - struct netinfo *p; - - if ((p = enter(&xip->inp_inc, xip->inp_vflag, state, proto)) != NULL) { - p->ni_rcvcc = so->so_rcv.sb_cc; - p->ni_sndcc = so->so_snd.sb_cc; - } -} - -static struct netinfo * -enter(struct in_conninfo *inc, uint8_t vflag, int state, const char *proto) +enter(struct xinpcb *xip, struct xsocket *so, int state, const char *proto) { + struct in_conninfo *inc = &xip->inp_inc; + uint8_t vflag = xip->inp_vflag; struct netinfo *p; struct sockaddr_storage lsa, fsa; struct sockaddr_in *sa4; @@ -378,7 +269,7 @@ enter(struct in_conninfo *inc, uint8_t vflag, int state, const char *proto) } #endif else - return NULL; + return; /* * Only take exact matches, any sockets with @@ -400,7 +291,7 @@ enter(struct in_conninfo *inc, uint8_t vflag, int state, const char *proto) if (p == NULL) { if ((p = malloc(sizeof(*p))) == NULL) { error("Out of memory"); - return NULL; + return; } TAILQ_INSERT_HEAD(&netcb, p, chain); p->ni_line = -1; @@ -411,7 +302,8 @@ enter(struct in_conninfo *inc, uint8_t vflag, int state, const char *proto) } p->ni_state = state; p->ni_seen = 1; - return p; + p->ni_rcvcc = so->so_rcv.sb_cc; + p->ni_sndcc = so->so_snd.sb_cc; } /* column locations */ @@ -425,8 +317,6 @@ enter(struct in_conninfo *inc, uint8_t vflag, int state, const char *proto) void labelnetstat(void) { - if (use_kvm && namelist[X_TCB].n_type == 0) - return; wmove(wnd, 0, 0); wclrtobot(wnd); mvwaddstr(wnd, 0, LADDR, "Local Address"); mvwaddstr(wnd, 0, FADDR, "Foreign Address"); diff --git a/usr.bin/systat/systat.h b/usr.bin/systat/systat.h index 55a21a04998a..371fdf57f6fc 100644 --- a/usr.bin/systat/systat.h +++ b/usr.bin/systat/systat.h @@ -45,13 +45,6 @@ struct cmdtab { char c_flags; /* see below */ }; -/* - * If we are started with privileges, use a kmem interface for netstat handling, - * otherwise use sysctl. - * In case of many open sockets, the sysctl handling might become slow. - */ -extern int use_kvm; - #define CF_INIT 0x1 /* been initialized */ #define CF_LOADAV 0x2 /* display w/ load average */ #define CF_ZFSARC 0x4 /* display w/ ZFS cache usage */ @@ -62,10 +55,6 @@ extern int use_kvm; #define MAINWIN_ROW 3 /* top row for the main/lower window */ #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) -#define KREAD(addr, buf, len) kvm_ckread((addr), (buf), (len)) -#define NVAL(indx) namelist[(indx)].n_value -#define NPTR(indx) (void *)NVAL((indx)) -#define NREAD(indx, buf, len) kvm_ckread(NPTR((indx)), (buf), (len)) extern void putint(int, int, int, int); extern void putfloat(double, int, int, int, int, int);