From fe36545586e3c41cfd12e71be5afc4beb4e72daa Mon Sep 17 00:00:00 2001 From: JingPiao Chen Date: Thu, 8 Jun 2017 09:02:22 +0800 Subject: [PATCH] netlink: implement generic nlmsg_flags decoding * netlink.c: Include "xlat/netlink_get_flags.h" and "xlat/netlink_new_flags.h". (decode_nlmsg_flags): New function. (print_nlmsghdr): Use it. * xlat/netlink_get_flags.in: New file. * xlat/netlink_new_flags.in: Likewise. Co-authored-by: Fabien Siron Co-authored-by: Dmitry V. Levin --- netlink.c | 52 ++++++++++++++++++++++++++++++++++++++- xlat/netlink_get_flags.in | 11 +++++++++ xlat/netlink_new_flags.in | 11 +++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 xlat/netlink_get_flags.in create mode 100644 xlat/netlink_new_flags.in diff --git a/netlink.c b/netlink.c index f9ff4651..dc8a3493 100644 --- a/netlink.c +++ b/netlink.c @@ -34,6 +34,8 @@ #include #include #include "xlat/netlink_flags.h" +#include "xlat/netlink_get_flags.h" +#include "xlat/netlink_new_flags.h" #include "xlat/netlink_protocols.h" #include "xlat/netlink_types.h" #include "xlat/nl_audit_types.h" @@ -152,6 +154,53 @@ decode_nlmsg_type(const uint16_t type, const unsigned int family) } } +static void +decode_nlmsg_flags(const uint16_t flags, const uint16_t type, const int family) +{ + const struct xlat *table = netlink_flags; + + switch (family) { + case NETLINK_SOCK_DIAG: + table = netlink_get_flags; + break; + case NETLINK_ROUTE: + if (type == RTM_DELACTION) { + table = netlink_get_flags; + break; + } + switch (type & 3) { + case 0: + table = netlink_new_flags; + break; + case 2: + table = netlink_get_flags; + break; + } + break; + case NETLINK_XFRM: + switch (type) { + case XFRM_MSG_NEWSA: + case XFRM_MSG_NEWPOLICY: + case XFRM_MSG_NEWAE: + case XFRM_MSG_NEWSADINFO: + case XFRM_MSG_NEWSPDINFO: + table = netlink_new_flags; + break; + + case XFRM_MSG_GETSA: + case XFRM_MSG_GETPOLICY: + case XFRM_MSG_GETAE: + case XFRM_MSG_GETSADINFO: + case XFRM_MSG_GETSPDINFO: + table = netlink_get_flags; + break; + } + break; + } + + printflags(table, flags, "NLM_F_???"); +} + static int print_nlmsghdr(struct tcb *tcp, const int fd, @@ -170,7 +219,8 @@ print_nlmsghdr(struct tcb *tcp, decode_nlmsg_type(nlmsghdr->nlmsg_type, hdr_family); tprints(", flags="); - printflags(netlink_flags, nlmsghdr->nlmsg_flags, "NLM_F_???"); + decode_nlmsg_flags(nlmsghdr->nlmsg_flags, + nlmsghdr->nlmsg_type, hdr_family); tprintf(", seq=%u, pid=%u}", nlmsghdr->nlmsg_seq, nlmsghdr->nlmsg_pid); diff --git a/xlat/netlink_get_flags.in b/xlat/netlink_get_flags.in new file mode 100644 index 00000000..0b68ba91 --- /dev/null +++ b/xlat/netlink_get_flags.in @@ -0,0 +1,11 @@ +NLM_F_REQUEST +NLM_F_MULTI +NLM_F_ACK +NLM_F_ECHO +NLM_F_DUMP_INTR +NLM_F_DUMP_FILTERED + +NLM_F_DUMP +NLM_F_ROOT +NLM_F_MATCH +NLM_F_ATOMIC diff --git a/xlat/netlink_new_flags.in b/xlat/netlink_new_flags.in new file mode 100644 index 00000000..fa0c8594 --- /dev/null +++ b/xlat/netlink_new_flags.in @@ -0,0 +1,11 @@ +NLM_F_REQUEST +NLM_F_MULTI +NLM_F_ACK +NLM_F_ECHO +NLM_F_DUMP_INTR +NLM_F_DUMP_FILTERED + +NLM_F_REPLACE +NLM_F_EXCL +NLM_F_CREATE +NLM_F_APPEND -- 2.40.0