diff options
| author | Ishan Agrawal <iagrawal9990@gmail.com> | 2026-07-23 02:29:48 +0000 |
|---|---|---|
| committer | Kristof Provost <kp@FreeBSD.org> | 2026-07-27 09:27:54 +0000 |
| commit | 407b7bcc93862fe0c026e254bac8ec0e8318e7e6 (patch) | |
| tree | fd3bd2cd86dc1d3de8c28ee0e0dfc5aa7d0b8ce6 | |
| parent | 5c1461a2b0fdf845292681aa46b56c620da57e25 (diff) | |
libsysdecode: decode combined Netlink message flags
Change sysdecode_nlm_flag() to decode Netlink message flags as a
bitmask instead of looking up a single flag value. This correctly
prints combinations of NLM_F_* flags while preserving any unknown
bits in hexadecimal.
Reported by: androvonx95 <androvonx95@tutamail.com>
Reviewed by: kp
Signed-off-by: Ishan Agrawal <iagrawal9990@gmail.com>
Sponsored-by: Google LLC (GSoC 2026)
| -rw-r--r-- | lib/libsysdecode/flags.c | 11 | ||||
| -rw-r--r-- | lib/libsysdecode/netlink.c | 7 | ||||
| -rw-r--r-- | lib/libsysdecode/sysdecode.h | 2 |
3 files changed, 10 insertions, 10 deletions
diff --git a/lib/libsysdecode/flags.c b/lib/libsysdecode/flags.c index f94fb88ebf83..880fe5e1ed49 100644 --- a/lib/libsysdecode/flags.c +++ b/lib/libsysdecode/flags.c @@ -1217,9 +1217,14 @@ sysdecode_pfnl_cmd(int cmd) return (lookup_value(pfnl_cmd, cmd)); } -const char * -sysdecode_nlm_flag(int flag) +void +sysdecode_nlm_flag(FILE *fp, int flags) { - return (lookup_value(nlm_flag, flag)); + int rem; + + if (!print_mask_int(fp, nlm_flag, flags, &rem)) + fprintf(fp, "0x%x", rem); + else if (rem != 0) + fprintf(fp, "|0x%x", rem); } diff --git a/lib/libsysdecode/netlink.c b/lib/libsysdecode/netlink.c index bb07ad2e4bf7..6e2af72374b0 100644 --- a/lib/libsysdecode/netlink.c +++ b/lib/libsysdecode/netlink.c @@ -287,11 +287,7 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol) } 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); + sysdecode_nlm_flag(fp, nl->nlmsg_flags); fprintf(fp, ",seq=%u,pid=%u", nl->nlmsg_seq, nl->nlmsg_pid); @@ -371,7 +367,6 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol) family_table[num_family] = (struct name_table){0, NULL}; } - fprintf(fp, "}"); break; default: diff --git a/lib/libsysdecode/sysdecode.h b/lib/libsysdecode/sysdecode.h index bd38bb5bdc42..513ecddf07bd 100644 --- a/lib/libsysdecode/sysdecode.h +++ b/lib/libsysdecode/sysdecode.h @@ -67,7 +67,7 @@ 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_nlm_flag(int _flag); +void sysdecode_nlm_flag(FILE *_fp, 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); |
