diff options
| author | Ishan Agrawal <iagrawal9990@gmail.com> | 2026-06-24 04:08:07 +0000 |
|---|---|---|
| committer | Kristof Provost <kp@FreeBSD.org> | 2026-06-24 12:15:20 +0000 |
| commit | 4c932a4d45fb3130ffa80176f5ff9dcacabd49f1 (patch) | |
| tree | 9465234988b821d7f5b109987c8a878bdbda9efd | |
| parent | 34397aec163cacf179991fc3606273093be6df2e (diff) | |
netlink: decode netlink message flags symbolically
Generate an nlm_flag table definition for mktable from
netlink/netlink.h, add a sysdecode_nlm_flag() helper to
libsysdecode, and use it when decoding netlink message headers.
This enables mktable to generate netlink message flag lookup tables and
replaces raw hexadecimal output for recognized NLM_F_* flag values
with their symbolic names.
Reviewed by: kp
Signed-off-by: Ishan Agrawal <iagrawal9990@gmail.com>
Sponsored by: Google LLC (GSoC 2026)
Pull Request: https://github.com/freebsd/freebsd-src/pull/2294
| -rw-r--r-- | lib/libsysdecode/flags.c | 8 | ||||
| -rw-r--r-- | lib/libsysdecode/mktables | 1 | ||||
| -rw-r--r-- | lib/libsysdecode/netlink.c | 7 | ||||
| -rw-r--r-- | lib/libsysdecode/sysdecode.h | 3 |
4 files changed, 16 insertions, 3 deletions
diff --git a/lib/libsysdecode/flags.c b/lib/libsysdecode/flags.c index 8009a7a2f97e..983314e56369 100644 --- a/lib/libsysdecode/flags.c +++ b/lib/libsysdecode/flags.c @@ -70,6 +70,7 @@ #include <netgraph/bluetooth/include/ng_l2cap.h> #include <netgraph/bluetooth/include/ng_btsocket.h> #include <netpfil/pf/pf_nl.h> +#include <netlink/netlink.h> #include "support.h" @@ -1215,3 +1216,10 @@ sysdecode_pfnl_cmd(int cmd) return (lookup_value(pfnl_cmd, cmd)); } + +const char * +sysdecode_nlm_flag(int flag) +{ + + return (lookup_value(nlm_flag, flag)); +} diff --git a/lib/libsysdecode/mktables b/lib/libsysdecode/mktables index 2bfbaf529f44..df794b74c168 100644 --- a/lib/libsysdecode/mktables +++ b/lib/libsysdecode/mktables @@ -171,6 +171,7 @@ fi gen_table "shmflags" "SHM_[A-Z_]+[[:space:]]+0x[0-9]+" "sys/mman.h" "SHM_ANON" gen_table "itimerwhich" "ITIMER_[A-Z]+[[:space:]]+[0-9]+" "sys/time.h" gen_table "pfnl_cmd" "PFNL_CMD_[A-Z_]+[[:space:]]+[0-9]+" "netpfil/pf/pf_nl.h" +gen_table "nlm_flag" "NLM_F_[A-Z]+[[:space:]]+0x[0-9]+" "netlink/netlink.h" # Generate a .depend file for our output file if [ -n "$output_file" ]; then diff --git a/lib/libsysdecode/netlink.c b/lib/libsysdecode/netlink.c index a28a0a061134..2143a0d391a5 100644 --- a/lib/libsysdecode/netlink.c +++ b/lib/libsysdecode/netlink.c @@ -73,8 +73,11 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len) } fprintf(fp, ",flags="); - /* TODO: decode flags symbolically using sysdecode_mask. */ - fprintf(fp, "0x%x", nl->nlmsg_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); diff --git a/lib/libsysdecode/sysdecode.h b/lib/libsysdecode/sysdecode.h index 4675b1e3c463..3675a582a9b8 100644 --- a/lib/libsysdecode/sysdecode.h +++ b/lib/libsysdecode/sysdecode.h @@ -66,7 +66,8 @@ const char *sysdecode_ipproto(int _protocol); void sysdecode_kevent_fflags(FILE *_fp, short _filter, int _fflags, int _base); const char *sysdecode_itimer(int _which); -const char *sysdecode_pfnl_cmd(int cmd); +const char *sysdecode_pfnl_cmd(int _cmd); +const char *sysdecode_nlm_flag(int _flag); const char *sysdecode_kevent_filter(int _filter); bool sysdecode_kevent_flags(FILE *_fp, int _flags, int *_rem); const char *sysdecode_kldsym_cmd(int _cmd); |
