The branch main has been updated by kp:

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

commit c268c80fc3d5eaeec2d01205b338dbaa7661502a
Author:     Ishan Agrawal <[email protected]>
AuthorDate: 2026-06-29 06:00:40 +0000
Commit:     Kristof Provost <[email protected]>
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 <[email protected]>
    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)

Reply via email to