git: 80586e853674 - main - libsysdecode: decode Generic Netlink controller messages
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 05 Jul 2026 14:15:54 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=80586e853674c6d63888379274accea5c82407f2
commit 80586e853674c6d63888379274accea5c82407f2
Author: Ishan Agrawal <iagrawal9990@gmail.com>
AuthorDate: 2026-06-29 05:17:14 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2026-07-05 14:03:34 +0000
libsysdecode: decode Generic Netlink controller messages
Decode Generic Netlink controller (GENL_ID_CTRL) messages in
Netlink payloads. Display the Generic Netlink header along with
the CTRL_CMD_GETFAMILY attributes, including the family ID and
family name.
Signed-off-by: Ishan Agrawal <iagrawal9990@gmail.com>
Reviewed by: kp
Sponsored-by: Google LLC (GSoC 2026)
---
lib/libsysdecode/netlink.c | 70 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 60 insertions(+), 10 deletions(-)
diff --git a/lib/libsysdecode/netlink.c b/lib/libsysdecode/netlink.c
index 723272d3b8da..4dbe6c087dcf 100644
--- a/lib/libsysdecode/netlink.c
+++ b/lib/libsysdecode/netlink.c
@@ -6,6 +6,8 @@
#include <sys/param.h>
#include <netlink/netlink.h>
+#include <netlink/netlink_generic.h>
+#include <netlink/netlink_snl.h>
#include <stdio.h>
#include <stdbool.h>
@@ -20,6 +22,7 @@
* Returns false if the data is malformed, allowing the caller
* to fallback to a standard hex/string dump.
*/
+
bool
sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol)
{
@@ -51,7 +54,16 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol)
break;
}
- fprintf(fp, "len=%u,type=", nl->nlmsg_len);
+ fprintf(fp, "flags=");
+ const char *nlm_f = sysdecode_nlm_flag(nl->nlmsg_flags);
+ if (nlm_f != NULL)
+ fprintf(fp, "%s", nlm_f);
+ else
+ fprintf(fp, "0x%x", nl->nlmsg_flags);
+
+ fprintf(fp, ",seq=%u,pid=%u", nl->nlmsg_seq, nl->nlmsg_pid);
+
+ fprintf(fp, ",len=%u,type=", nl->nlmsg_len);
/* Decode Standard Message Types. */
switch (nl->nlmsg_type) {
@@ -67,20 +79,58 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol)
case NLMSG_OVERRUN:
fprintf(fp, "NLMSG_OVERRUN");
break;
+ case GENL_ID_CTRL:
+ if (protocol != NETLINK_GENERIC)
+ break;
+
+ fprintf(fp, "GENL_ID_CTRL");
+
+ const struct genlmsghdr *genl =
+ (const struct genlmsghdr *)(const void *)
+ ((const char *)nl + sizeof(struct nlmsghdr));
+
+ uint16_t family_id = 0;
+ const char *family_name = NULL;
+
+ fprintf(fp,
+ ",genl={cmd=%u,"
+ "ver=%u,reserve=%u",
+ genl->cmd,
+ genl->version, genl->reserved);
+
+ size_t cur_len = (sizeof(struct nlmsghdr)
+ + sizeof(struct genlmsghdr));
+ size_t nla_len = nl->nlmsg_len - cur_len;
+
+ const struct nlattr *nla;
+ const struct nlattr *nla_head = (const struct nlattr *)
+ (const void *)((const char *)nl + cur_len);
+
+ NLA_FOREACH_CONST(nla, nla_head, nla_len) {
+ switch (nla->nla_type) {
+ case CTRL_ATTR_FAMILY_ID:
+ memcpy(&family_id, NLA_DATA_CONST(nla),
+ sizeof(family_id));
+ fprintf(fp, ",family_id=%u", family_id);
+ break;
+ case CTRL_ATTR_FAMILY_NAME:
+ family_name =
+ ((const char *)NLA_DATA_CONST(nla));
+ fprintf(fp, ",family_name=%s",
+ family_name);
+ break;
+ default:
+ break;
+ }
+ }
+
+ fprintf(fp, "}");
+ break;
default:
fprintf(fp, "%u", nl->nlmsg_type);
break;
}
- fprintf(fp, ",flags=");
- const char *nlm_f = sysdecode_nlm_flag(nl->nlmsg_flags);
- if (nlm_f != NULL)
- fprintf(fp, "%s", nlm_f);
- else
- fprintf(fp, "0x%x", nl->nlmsg_flags);
-
- fprintf(fp, ",seq=%u,pid=%u", nl->nlmsg_seq, nl->nlmsg_pid);
-
/* Handle Alignment (Netlink messages are 4-byte aligned). */
size_t aligned_len = NLMSG_ALIGN(nl->nlmsg_len);
if (aligned_len > remaining)