From nobody Wed Oct 23 07:24:31 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 4XYLCN2Z10z5ZxS4; Wed, 23 Oct 2024 07:24:32 +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 4XYLCN0Qpxz47JD; Wed, 23 Oct 2024 07:24:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729668272; 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=QwFx7m0g99/92ejXAqSzRcLZrP6g6RzkEq3lRd7ThDY=; b=aOyQ4Rjy7jafMda30PWjSEoJb6slrLLP0UO/m3+VpOV7TemIJNgcr+7BjPOMQuBY12SFWJ ggfAYjvaOguvg+ZfPXIknp+exUJIGZv/m7Ht5K5lrYZy+/e/sZMUEFLCCdivVtqTxIoqkd qnXmmCfjakvCwame755IhJSX9s6elDDBjReahxtFepw5zwMUIviIhDN0Bkgtmpvg0YjbSd BHI0UWN6G/Dko6XHBtXXYBpX4WbIltufMsux5SSQHheC/66OrAayblN0xwTD6jw8vhYiya 5xLfxXVX62KT99mW7/Y/LEw267UYc5yyG6Hp4bafMJycx5Gklyyt4svbR5VxPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729668272; 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=QwFx7m0g99/92ejXAqSzRcLZrP6g6RzkEq3lRd7ThDY=; b=C4lxXtEKg4bivlzMp5RtDAVzvKSu+6zMUGRDbGPSrOPmUO1kS7yoNiLfAid5Kl5iT21unU /z+yt+EascC2DWq6nEp4INi+V1HXWeDYT238cO3/aywvOOxKCRYJnOUlsDTdbbniXL48L7 7bkVBXQmGvUtLnG0gwSyIaNq67ddk+JyRGjXsJb7SOnT13HneIEL2xWJpke6Ni+vSZzcVd ISjQ8mgJNXJ+YrRhWTJG7aslAkB4NfWGUm0YSBxJFlMxoqAyDJMN8PtjWu0n+HefkxsrSR C+4cU4xjzS1uBzARaQX/0KSqKpxEcPhkEvQj3jCOF+IopX3PQ+UiLS8ASZjR1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729668272; a=rsa-sha256; cv=none; b=Bt4luQsCnhOjfb1F4H3Gmw9jtD/y3I9HvYh9hvO2npnompHi6uphvmsWk8dUJhDKH/yHYu G4ADEX93UeMvYAUJPTH1xDGAMf4na+TgRi9T4V+xpAIVX60gZaW44nm5cEQ2HMYLlpyFL5 bSsvUQHaf2FqOllOaQQZXIShWLLSvKIWww8oPpSjaZjFREOa81PNFHooOQx1dBkTLNhu5S O96CKJih3aXAv1kn8PupFPgxiGDKaQL/2jpeZ/gv/nL+Btq821CigdR6DfE5lnDM+VbMaY kxvImZlkTeeub6HY38YoB+Sx4B4vhuDk5FiHiavBw+j8cRMnLcGGIDP5t/aINQ== 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 4XYLCM6ld6zpXn; Wed, 23 Oct 2024 07:24:31 +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 49N7OVx6036449; Wed, 23 Oct 2024 07:24:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49N7OVId036446; Wed, 23 Oct 2024 07:24:31 GMT (envelope-from git) Date: Wed, 23 Oct 2024 07:24:31 GMT Message-Id: <202410230724.49N7OVId036446@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 379b9c6e7c68 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 379b9c6e7c680d14fac511ad7d5f54ea95c35681 Auto-Submitted: auto-generated The branch stable/14 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=379b9c6e7c680d14fac511ad7d5f54ea95c35681 commit 379b9c6e7c680d14fac511ad7d5f54ea95c35681 Author: Baptiste Daroussin AuthorDate: 2024-10-07 09:43:50 +0000 Commit: Baptiste Daroussin CommitDate: 2024-10-23 07:24:09 +0000 genl: add parser for nlsysevent genl monitor nlsysevent is now able to print the messages received (cherry picked from commit 883722891aa92fc6033020c67ec7f2f0d9fedf95) --- 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)