From nobody Thu Jan 25 17:08:24 2024 X-Original-To: dev-commits-src-main@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 4TLS2d1X1Mz57dXH; Thu, 25 Jan 2024 17:08: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TLS2d0wHCz59P2; Thu, 25 Jan 2024 17:08:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706202505; 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=SwmkBUZjrJzUQZmCVPjXq4rnIIjvCVzo7eorz82m8ls=; b=m9qpexH+5yCQSVf5JplVblBjCPoGHZRx8qcVe6ghNM6CXaAigMDpScvSGog492whpAjYBH /WtQtmVuXPr3KMiTn48+v7cHcAMa4za88cI/vnv+iwW5qnHFQcdcDoJSvaVQl0RrSsZYdK YKt1aEWFAF6vfAeWp+9LGcEFT3xdl1QJBdTRq9wEZCorYUf4wbu8mESM7/Nr+2UDvyx+RC vnB4nTZVLfk796CcJf5MMPo73Cg1BEA0MMu5MZPSqnBvy+FFDjhh1cEHbN8nl4VFnkmhLl OA773VKegwEQyDWX26FM7ZY06qeODDEkQMfSZuSsa916lLogf/pHBgPkpsT/Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706202505; 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=SwmkBUZjrJzUQZmCVPjXq4rnIIjvCVzo7eorz82m8ls=; b=kEgpeRkoAVfkPa9mAsAorCFNxtGR954eWz9Cm+cRGb7ZlpZOFv6SbPi3A0FngxeJ/dB+tW Gbyrf4z/gUqgJ/blEJh+tWuD0N9eHp9fUrNpbCgMrlD5JdGPXO598ONs/RVQDtp7PBlbUq Ukzr7x+jz5u1fagcNNSVIlmSdXckFMfDdWtrb5Jo22jzEVJJ5VvMlak9iy7v3XcG1tShxC py2ghQpMEPPfPY5QJNBApo+JN5HZGVD5HV1NqZ8oQMes/fL/1oyHYl7INDEpEE9USRih95 TmdTfiOtwms6XjOZqq4LqSyl2c6w2hEN7xUYURx6qjTwtxNPSPnuvzRZJ32dYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706202505; a=rsa-sha256; cv=none; b=cSyUDI4SQV/jSEHqrOBMSF0tURrP2jWgn1Ly4xS1nm6TzuqYkrrT6eYhZcTuL3ZlYGbiw0 fxKwsW2nIa8i0x25dia+qmBZEhe6B702uGu2ML68UhqFwPR4D1nTmVIFFqn9XxiUrdnnn+ 4DtfdixcOcBQoikG2Fbmd+g5LD28Y0icpfjvO2IKT4spkVNRwwIviOP5jqHVlsj7jsjMmf wregpyBPGKYgsvW3daGK5X7jxGQwubq1ED33b0BkB13uVvA8iFqig41jsptUDlhHI6NDpV me24w2BnRsuDUmEONYr7L0+y5aUPLY3YWmhzJ2wvrSO3vpNM56b6f+tYH1kXSg== 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 4TLS2d01f2z15kl; Thu, 25 Jan 2024 17:08:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40PH8OHv060523; Thu, 25 Jan 2024 17:08:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40PH8OTb060520; Thu, 25 Jan 2024 17:08:24 GMT (envelope-from git) Date: Thu, 25 Jan 2024 17:08:24 GMT Message-Id: <202401251708.40PH8OTb060520@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: e95025ed9388 - main - pflow: show socket status in verbose mode List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e95025ed93886dc854c2c92a2d2812cb51abf4ed Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=e95025ed93886dc854c2c92a2d2812cb51abf4ed commit e95025ed93886dc854c2c92a2d2812cb51abf4ed Author: Kristof Provost AuthorDate: 2024-01-25 16:37:51 +0000 Commit: Kristof Provost CommitDate: 2024-01-25 16:37:51 +0000 pflow: show socket status in verbose mode Introduce a verbose output mode to pflowctl, and expose the status of the socket to userspace. This can be helpful in debugging configuration errors. Sponsored by: Rubicon Communications, LLC ("Netgate") --- sbin/pflowctl/pflowctl.8 | 5 ++++- sbin/pflowctl/pflowctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++------ sys/net/pflow.h | 3 ++- sys/netpfil/pf/pflow.c | 1 + 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/sbin/pflowctl/pflowctl.8 b/sbin/pflowctl/pflowctl.8 index 446679486db6..8c4142f31396 100644 --- a/sbin/pflowctl/pflowctl.8 +++ b/sbin/pflowctl/pflowctl.8 @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 08 2024 $ +.Dd $Mdocdate: January 25 2024 $ .Dt PFLOWCTL 8 .Os .Sh NAME @@ -24,6 +24,7 @@ .Sh SYNOPSIS .Nm pflowctl .Bk -words +.Op Fl v .Op Fl lc .Op Fl d Ar id .Op Fl s Ar id ... @@ -40,6 +41,8 @@ The utility provides several commands. The options are as follows: .Bl -tag -width Ds +.It Fl v +Produce verbose output. .It Fl c Create a new .Xr pflow 4 diff --git a/sbin/pflowctl/pflowctl.c b/sbin/pflowctl/pflowctl.c index e5dd3df7e6a7..f6ca8980db1b 100644 --- a/sbin/pflowctl/pflowctl.c +++ b/sbin/pflowctl/pflowctl.c @@ -47,13 +47,15 @@ static int get(int id); +static bool verbose = false; + extern char *__progname; static void usage(void) { fprintf(stderr, -"usage: %s [-lc] [-d id] [-s id ...]\n", +"usage: %s [-lc] [-d id] [-s id ...] [-v]\n", __progname); exit(1); @@ -253,6 +255,7 @@ struct pflowctl_get { struct pflowctl_sockaddr src; struct pflowctl_sockaddr dst; uint32_t obs_dom; + uint8_t so_status; }; #define _IN(_field) offsetof(struct genlmsghdr, _field) #define _OUT(_field) offsetof(struct pflowctl_get, _field) @@ -262,6 +265,7 @@ static struct snl_attr_parser ap_get[] = { { .type = PFLOWNL_GET_SRC, .off = _OUT(src), .arg = &sockaddr_parser, .cb = snl_attr_get_nested }, { .type = PFLOWNL_GET_DST, .off = _OUT(dst), .arg = &sockaddr_parser, .cb = snl_attr_get_nested }, { .type = PFLOWNL_GET_OBSERVATION_DOMAIN, .off = _OUT(obs_dom), .cb = snl_attr_get_uint32 }, + { .type = PFLOWNL_GET_SOCKET_STATUS, .off = _OUT(so_status), .cb = snl_attr_get_uint8 }, }; static struct snl_field_parser fp_get[] = {}; #undef _IN @@ -344,6 +348,10 @@ get(int id) print_sockaddr(" src ", &g.src.storage); print_sockaddr(" dst ", &g.dst.storage); printf("\n"); + if (verbose) { + printf("\tsocket: %s\n", + g.so_status ? "connected" : "disconnected"); + } } if (e.error) @@ -533,10 +541,20 @@ static const struct snl_hdr_parser *all_parsers[] = { &get_parser, }; +enum pflowctl_op_t { + OP_HELP, + OP_LIST, + OP_CREATE, + OP_DELETE, + OP_SET, +}; int main(int argc, char *argv[]) { int ch; + enum pflowctl_op_t op = OP_HELP; + char **set_args = NULL; + size_t set_arg_count = 0; SNL_VERIFY_PARSERS(all_parsers); @@ -544,18 +562,40 @@ main(int argc, char *argv[]) usage(); while ((ch = getopt(argc, argv, - "lcd:s:")) != -1) { + "lcd:s:v")) != -1) { switch (ch) { case 'l': - return (list()); + op = OP_LIST; + break; case 'c': - return (create()); + op = OP_CREATE; + break; case 'd': - return (del(optarg)); + op = OP_DELETE; + break; case 's': - return (set(optarg, argc - optind, argv + optind)); + op = OP_SET; + set_arg_count = argc - optind; + set_args = argv + optind; + case 'v': + verbose = true; + break; } } + switch (op) { + case OP_LIST: + return (list()); + case OP_CREATE: + return (create()); + case OP_DELETE: + return (del(optarg)); + case OP_SET: + return (set(optarg, set_arg_count, set_args)); + case OP_HELP: + usage(); + break; + } + return (0); } diff --git a/sys/net/pflow.h b/sys/net/pflow.h index 4c194e14e001..ee747d1a6a46 100644 --- a/sys/net/pflow.h +++ b/sys/net/pflow.h @@ -362,7 +362,8 @@ enum pflow_get_type_t { PFLOWNL_GET_VERSION = 2, /* u16 */ PFLOWNL_GET_SRC = 3, /* struct sockaddr_storage */ PFLOWNL_GET_DST = 4, /* struct sockaddr_storage */ - PFLOWNL_GET_OBSERVATION_DOMAIN = 5, /* u32 */ + PFLOWNL_GET_OBSERVATION_DOMAIN = 5, /* u32 */ + PFLOWNL_GET_SOCKET_STATUS = 6, /* u8 */ }; enum pflow_set_type_t { diff --git a/sys/netpfil/pf/pflow.c b/sys/netpfil/pf/pflow.c index 17a68e0d9e57..f3dba7687d05 100644 --- a/sys/netpfil/pf/pflow.c +++ b/sys/netpfil/pf/pflow.c @@ -1485,6 +1485,7 @@ pflow_nl_get(struct nlmsghdr *hdr, struct nl_pstate *npt) nlattr_add_sockaddr(nw, PFLOWNL_GET_DST, sc->sc_flowdst); nlattr_add_u32(nw, PFLOWNL_GET_OBSERVATION_DOMAIN, sc->sc_observation_dom); + nlattr_add_u8(nw, PFLOWNL_GET_SOCKET_STATUS, sc->so != NULL); if (! nlmsg_end(nw)) { nlmsg_abort(nw);