From owner-svn-src-all@freebsd.org Sun Apr 26 20:55:12 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 830512BC701; Sun, 26 Apr 2020 20:55:12 +0000 (UTC) (envelope-from freqlabs@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 499Kt82t9tz3yY7; Sun, 26 Apr 2020 20:55:12 +0000 (UTC) (envelope-from freqlabs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5DD5B27034; Sun, 26 Apr 2020 20:55:12 +0000 (UTC) (envelope-from freqlabs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03QKtC7K068993; Sun, 26 Apr 2020 20:55:12 GMT (envelope-from freqlabs@FreeBSD.org) Received: (from freqlabs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03QKtC0i068992; Sun, 26 Apr 2020 20:55:12 GMT (envelope-from freqlabs@FreeBSD.org) Message-Id: <202004262055.03QKtC0i068992@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: freqlabs set sender to freqlabs@FreeBSD.org using -f From: Ryan Moeller Date: Sun, 26 Apr 2020 20:55:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360356 - head/usr.bin/sockstat X-SVN-Group: head X-SVN-Commit-Author: freqlabs X-SVN-Commit-Paths: head/usr.bin/sockstat X-SVN-Commit-Revision: 360356 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Apr 2020 20:55:12 -0000 Author: freqlabs Date: Sun Apr 26 20:55:11 2020 New Revision: 360356 URL: https://svnweb.freebsd.org/changeset/base/360356 Log: sockstat: Attach to jail if in new vnet Attach sockstat -j to the specified jail if the jail is in a new vnet. Otherwise we do not see all sockets belonging to the jail. Reviewed by: jamie Approved by: mmacy (mentor) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D24413 Modified: head/usr.bin/sockstat/sockstat.c Modified: head/usr.bin/sockstat/sockstat.c ============================================================================== --- head/usr.bin/sockstat/sockstat.c Sun Apr 26 20:16:18 2020 (r360355) +++ head/usr.bin/sockstat/sockstat.c Sun Apr 26 20:55:11 2020 (r360356) @@ -32,10 +32,11 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include -#include +#include #include #include @@ -1218,7 +1219,8 @@ display(void) } } -static int set_default_protos(void) +static int +set_default_protos(void) { struct protoent *prot; const char *pname; @@ -1237,6 +1239,38 @@ static int set_default_protos(void) return (pindex); } +/* + * Return the vnet property of the jail, or -1 on error. + */ +static int +jail_getvnet(int jid) +{ + struct iovec jiov[6]; + int vnet; + + vnet = -1; + jiov[0].iov_base = __DECONST(char *, "jid"); + jiov[0].iov_len = sizeof("jid"); + jiov[1].iov_base = &jid; + jiov[1].iov_len = sizeof(jid); + jiov[2].iov_base = __DECONST(char *, "vnet"); + jiov[2].iov_len = sizeof("vnet"); + jiov[3].iov_base = &vnet; + jiov[3].iov_len = sizeof(vnet); + jiov[4].iov_base = __DECONST(char *, "errmsg"); + jiov[4].iov_len = sizeof("errmsg"); + jiov[5].iov_base = jail_errmsg; + jiov[5].iov_len = JAIL_ERRMSGLEN; + jail_errmsg[0] = '\0'; + if (jail_get(jiov, nitems(jiov), 0) < 0) { + if (!jail_errmsg[0]) + snprintf(jail_errmsg, JAIL_ERRMSGLEN, + "jail_get: %s", strerror(errno)); + return (-1); + } + return (vnet); +} + static void usage(void) { @@ -1310,6 +1344,21 @@ main(int argc, char *argv[]) if (argc > 0) usage(); + + if (opt_j > 0) { + switch (jail_getvnet(opt_j)) { + case -1: + errx(2, "%s", jail_errmsg); + case JAIL_SYS_NEW: + if (jail_attach(opt_j) < 0) + errx(3, "%s", jail_errmsg); + /* Set back to -1 for normal output in vnet jail. */ + opt_j = -1; + break; + default: + break; + } + } if ((!opt_4 && !opt_6) && protos_defined != -1) opt_4 = opt_6 = 1;