]> granicus.if.org Git - strace/commitdiff
netlink: implement generic nlmsg_flags decoding
authorJingPiao Chen <chenjingpiao@gmail.com>
Thu, 8 Jun 2017 01:02:22 +0000 (09:02 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 8 Jun 2017 22:26:46 +0000 (22:26 +0000)
* 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 <fabien.siron@epita.fr>
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
netlink.c
xlat/netlink_get_flags.in [new file with mode: 0644]
xlat/netlink_new_flags.in [new file with mode: 0644]

index f9ff4651a9e70d54718beedca69e6d20856c741f..dc8a3493f528e6bc6be9d8d35bd999fc80cf81e3 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -34,6 +34,8 @@
 #include <linux/rtnetlink.h>
 #include <linux/xfrm.h>
 #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 (file)
index 0000000..0b68ba9
--- /dev/null
@@ -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 (file)
index 0000000..fa0c859
--- /dev/null
@@ -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