[PATCH v3] netlink: implement generic nlmsg_flags decoding

JingPiao Chen chenjingpiao at gmail.com
Thu Jun 8 01:02:22 UTC 2017


* netlink.c: Include "xlat/netlink_get_flags.h",
"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 at epita.fr>
Co-authored-by: Dmitry V. Levin <ldv at altlinux.org>
---
Update commit message and test RTM_DELACTION first.

 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 f9ff465..dc8a349 100644
--- 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
index 0000000..0b68ba9
--- /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 0000000..fa0c859
--- /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.7.4





More information about the Strace-devel mailing list