From nobody Mon Oct 07 10:14:58 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 4XMZlR12KTz5XgK0; Mon, 07 Oct 2024 10:14:59 +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 4XMZlR0CKbz47sJ; Mon, 7 Oct 2024 10:14:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728296099; 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=flt3GI0AShHKEdwBQ5SOOC14oOKwS5Gc3goub80ytLw=; b=vfWuCKwRx92qwCq4KG8dPgIXQSWuHYcLxIWqANYyt6wCMYY46IUHdj6ArJTOIOpD/y0Gar VM/a8OviEeJxBYHfc6ltdmBUfyaFwAuU+zaYamj/p02LCaF4BBbyIP/otnHa4ZtNbXVrhG pCle1Uc4JDENGs1Z8U8hWXIwAySn3EkAze4rnBbVFiEwQPwntNb+yLgsIJJdhOAvqfpYnD 3ryT87SZSmWQfhXpt3ZhPGA1M/RxY9vCA77GfDWlvH9yhStjymtTSoQwwU/kqYk78bzAHL NFG/48u/lriNyQM8bNwGp58pJvC5FpSjWbJTFtqlS/1JdJWixcuviW4tHVPkqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728296099; 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=flt3GI0AShHKEdwBQ5SOOC14oOKwS5Gc3goub80ytLw=; b=q0ISK7OR7ghwDalTxHFB9VspEAYYM1NonWQUdrmLOWH0Cy4AGOcznY1JUCscJJd/Ln1BFn kG30C5zfVAHlDPEUbPVD2wZPrsVC0+ofkqwon7NGTVTf8gSn2AR3chE5Cz8Br2vuxkcw4V Og6EAYmQPOUHNSME4YiQDi9e+9LmJW2JdLujQQDTfb/dyznec6w3ar0dnfgjwUYnefg0tz TE0/FWh0Yp3I7u/NNajyPUZk8qHlB/jJFOBuYUlfOHdOq+kw2RSrXEz4vWJkF6cQN21TFa gI1CCPByBwYbsI2737SU21n/T+YrLkWeVLfi7A6T2KR7RJr7Y8zsDk0RZL0gfg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728296099; a=rsa-sha256; cv=none; b=Pw/k7OTBU8EMnK3xhGPijQE/gsqQ+w6xcD/LYx+XHLXxJzcZWyxp4t44aBgnt1ystXUsKG yo4gvVXuM7JS58hgZx9VSMG5xOZq+ZwDYX6VW4Liya7dlmxWtoaqc/vM1pCevJ+JVFn/DI eubXnEJD0F+n+CI36pKoArjfN20lo9LpUHRUy5b77fYU+WqmtCHtrmUIdyPB9jPuxuLblQ wKhzpIbB9EuK+NPGbMUmRPat3v2qziXUewJJYOAXNdP/qeuuzGbnmNdiNi/pVYJqkk+cXH k9EcrJEv7AJBvqVan1lDs4ApBkEJTtVTcKK0+jgNkapWd1v3cyv9GGhuk4H0PA== 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 4XMZlQ6qmMzhQs; Mon, 7 Oct 2024 10:14:58 +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 497AEwOp000392; Mon, 7 Oct 2024 10:14:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 497AEwQ9000389; Mon, 7 Oct 2024 10:14:58 GMT (envelope-from git) Date: Mon, 7 Oct 2024 10:14:58 GMT Message-Id: <202410071014.497AEwQ9000389@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 883722891aa9 - main - genl: add parser for nlsysevent 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: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 883722891aa92fc6033020c67ec7f2f0d9fedf95 Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=883722891aa92fc6033020c67ec7f2f0d9fedf95 commit 883722891aa92fc6033020c67ec7f2f0d9fedf95 Author: Baptiste Daroussin AuthorDate: 2024-10-07 09:43:50 +0000 Commit: Baptiste Daroussin CommitDate: 2024-10-07 10:11:20 +0000 genl: add parser for nlsysevent genl monitor nlsysevent is now able to print the messages received --- usr.bin/genl/genl.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/usr.bin/genl/genl.c b/usr.bin/genl/genl.c index 88880c4bacbd..48c74fa20c81 100644 --- a/usr.bin/genl/genl.c +++ b/usr.bin/genl/genl.c @@ -40,10 +40,12 @@ #include #include #include +#include static int monitor_mcast(int argc, char **argv); static int list_families(int argc, char **argv); static void parser_nlctrl_notify(struct snl_state *ss, struct nlmsghdr *hdr); +static void parser_nlsysevent(struct snl_state *ss, struct nlmsghdr *hdr); static void parser_fallback(struct snl_state *ss, struct nlmsghdr *hdr); static struct commands { @@ -60,8 +62,25 @@ static struct mcast_parsers { void (*parser)(struct snl_state *ss, struct nlmsghdr *hdr); } mcast_parsers [] = { { "nlctrl", parser_nlctrl_notify }, + { "nlsysevent", parser_nlsysevent }, }; +struct nlevent { + const char *name; + const char *subsystem; + const char *type; + const char *data; +}; +#define _OUT(_field) offsetof(struct nlevent, _field) +static struct snl_attr_parser ap_nlevent_get[] = { + { .type = NLSE_ATTR_SYSTEM, .off = _OUT(name), .cb = snl_attr_get_string }, + { .type = NLSE_ATTR_SUBSYSTEM, .off = _OUT(subsystem), .cb = snl_attr_get_string }, + { .type = NLSE_ATTR_TYPE, .off = _OUT(type), .cb = snl_attr_get_string }, + { .type = NLSE_ATTR_DATA, .off = _OUT(data), .cb = snl_attr_get_string }, +}; +#undef _OUT +SNL_DECLARE_GENL_PARSER(nlevent_get_parser, ap_nlevent_get); + struct genl_ctrl_op { uint32_t id; uint32_t flags; @@ -183,6 +202,20 @@ parser_nlctrl_notify(struct snl_state *ss, struct nlmsghdr *hdr) dump_family(&family); } +void +parser_nlsysevent(struct snl_state *ss, struct nlmsghdr *hdr) +{ + struct nlevent ne = {}; + if (snl_parse_nlmsg(ss, hdr, &nlevent_get_parser, &ne)) { + printf("system=%s subsystem=%s type=%s", ne.name, ne.subsystem, ne.type); + if (ne.data) { + printf(" %s", ne.data); + if (ne.data[strlen(ne.data) -1] != '\n') + printf("\n"); + } + } +} + void parser_fallback(struct snl_state *ss __unused, struct nlmsghdr *hdr __unused) { @@ -209,6 +242,7 @@ monitor_mcast(int argc __unused, char **argv) usage(); return (EXIT_FAILURE); } + if (!snl_get_genl_family_info(&ss, argv[0], &attrs)) errx(EXIT_FAILURE, "Unknown family '%s'", argv[0]); if (argc == 1)