Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Oct 2024 07:24:31 GMT
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 379b9c6e7c68 - stable/14 - genl: add parser for nlsysevent
Message-ID:  <202410230724.49N7OVId036446@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=379b9c6e7c680d14fac511ad7d5f54ea95c35681

commit 379b9c6e7c680d14fac511ad7d5f54ea95c35681
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2024-10-07 09:43:50 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
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 <netlink/netlink_generic.h>
 #include <netlink/netlink_snl.h>
 #include <netlink/netlink_snl_generic.h>
+#include <netlink/netlink_sysevent.h>
 
 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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202410230724.49N7OVId036446>