Date: Sun, 05 Jul 2026 14:15:55 +0000 From: Kristof Provost <kp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Ishan Agrawal <iagrawal9990@gmail.com> Subject: git: c268c80fc3d5 - main - libsysdecode: cache Generic Netlink family IDs Message-ID: <6a4a671b.3c4f2.ab40292@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=c268c80fc3d5eaeec2d01205b338dbaa7661502a commit c268c80fc3d5eaeec2d01205b338dbaa7661502a Author: Ishan Agrawal <iagrawal9990@gmail.com> AuthorDate: 2026-06-29 06:00:40 +0000 Commit: Kristof Provost <kp@FreeBSD.org> CommitDate: 2026-07-05 14:03:52 +0000 libsysdecode: cache Generic Netlink family IDs Record Generic Netlink family IDs learned from CTRL_CMD_GETFAMILY responses and use them to decode subsequent Generic Netlink messages using symbolic family names instead of numeric IDs. Signed-off-by: Ishan Agrawal <iagrawal9990@gmail.com> Reviewed by: kp Sponsored-by: Google LLC (GSoC 2026) --- lib/libsysdecode/netlink.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/libsysdecode/netlink.c b/lib/libsysdecode/netlink.c index 4dbe6c087dcf..a9c226e6065d 100644 --- a/lib/libsysdecode/netlink.c +++ b/lib/libsysdecode/netlink.c @@ -12,8 +12,11 @@ #include <stdio.h> #include <stdbool.h> #include <stddef.h> +#include <stdlib.h> +#include <string.h> #include "sysdecode.h" +#include "support.h" /* * Decodes a buffer as a Netlink message stream. @@ -23,6 +26,9 @@ * to fallback to a standard hex/string dump. */ +static struct name_table *family_table = NULL; +static size_t num_family = 0; + bool sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol) { @@ -41,6 +47,12 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol) if (nl->nlmsg_len < sizeof(struct nlmsghdr) || nl->nlmsg_len > remaining) return (false); + if (family_table == NULL) { + family_table = malloc((num_family + 1) * + sizeof(struct name_table)); + family_table[num_family] = (struct name_table){0, NULL}; + } + fprintf(fp, "netlink{"); while (remaining >= sizeof(struct nlmsghdr)) { @@ -124,6 +136,22 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol) } } + if (family_name && family_id && + !lookup_value(family_table, family_id)) { + num_family++; + + family_table = realloc(family_table, + (num_family + 1) * + sizeof(struct name_table)); + family_table[num_family - 1].val = + family_id; + family_table[num_family - 1].str = + strdup(family_name); + + family_table[num_family] = + (struct name_table){0, NULL}; + } + fprintf(fp, "}"); break; default: @@ -131,6 +159,10 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol) break; } + const char *family = lookup_value(family_table, nl->nlmsg_type); + if (family != NULL && strcmp(family, "pfctl") == 0) + fprintf(fp, ",pf={}"); + /* Handle Alignment (Netlink messages are 4-byte aligned). */ size_t aligned_len = NLMSG_ALIGN(nl->nlmsg_len); if (aligned_len > remaining)home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a4a671b.3c4f2.ab40292>
