[PATCH v6 01/18] netlink: add a basic netlink attribute parser of AF_NETLINK diag

JingPiao Chen chenjingpiao at gmail.com
Tue Jun 27 10:10:03 UTC 2017


* linux/netlink_diag.h (NETLINK_DIAG_*): New enum.
* netlink_sock_diag.c: Include "xlat/netlink_diag_attrs.h".
(decode_netlink_diag_msg): Use decode_nlattr.
* xlat/netlink_diag_attrs.in: New file.

Co-authored-by: Fabien Siron <fabien.siron at epita.fr>
---
 linux/netlink_diag.h       |  8 ++++++++
 netlink_sock_diag.c        | 12 +++++++++++-
 xlat/netlink_diag_attrs.in |  6 ++++++
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 xlat/netlink_diag_attrs.in

diff --git a/linux/netlink_diag.h b/linux/netlink_diag.h
index c56ffe6..eda3ec3 100644
--- a/linux/netlink_diag.h
+++ b/linux/netlink_diag.h
@@ -23,6 +23,14 @@ struct netlink_diag_msg {
 	uint32_t ndiag_cookie[2];
 };
 
+enum {
+	NETLINK_DIAG_MEMINFO,
+	NETLINK_DIAG_GROUPS,
+	NETLINK_DIAG_RX_RING,
+	NETLINK_DIAG_TX_RING,
+	NETLINK_DIAG_FLAGS,
+};
+
 #define NDIAG_SHOW_MEMINFO		0x00000001
 #define NDIAG_SHOW_GROUPS		0x00000002
 #define NDIAG_SHOW_RING_CFG		0x00000004 /* deprecated since 4.6 */
diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c
index d854808..ec440e3 100644
--- a/netlink_sock_diag.c
+++ b/netlink_sock_diag.c
@@ -45,6 +45,7 @@
 #include "xlat/tcp_states.h"
 #include "xlat/tcp_state_flags.h"
 
+#include "xlat/netlink_diag_attrs.h"
 #include "xlat/netlink_diag_show.h"
 #include "xlat/netlink_states.h"
 
@@ -191,7 +192,8 @@ decode_netlink_diag_msg(struct tcb *const tcp,
 			const kernel_ulong_t len)
 {
 	struct netlink_diag_msg msg = { .ndiag_family = family };
-	const size_t offset = sizeof(msg.ndiag_family);
+	size_t offset = sizeof(msg.ndiag_family);
+	bool decode_nla = false;
 
 	tprints("{ndiag_family=");
 	printxval(addrfams, msg.ndiag_family, "AF_???");
@@ -221,10 +223,18 @@ decode_netlink_diag_msg(struct tcb *const tcp,
 				msg.ndiag_ino,
 				msg.ndiag_cookie[0],
 				msg.ndiag_cookie[1]);
+			decode_nla = true;
 		}
 	} else
 		tprints("...");
 	tprints("}");
+
+	offset = NLA_ALIGN(sizeof(msg));
+	if (decode_nla && len > offset) {
+		tprints(", ");
+		decode_nlattr(tcp, addr + offset, len - offset,
+			      netlink_diag_attrs, "NETLINK_DIAG_???");
+	}
 }
 
 static void
diff --git a/xlat/netlink_diag_attrs.in b/xlat/netlink_diag_attrs.in
new file mode 100644
index 0000000..41e9a7a
--- /dev/null
+++ b/xlat/netlink_diag_attrs.in
@@ -0,0 +1,6 @@
+#unconditional
+NETLINK_DIAG_MEMINFO
+NETLINK_DIAG_GROUPS
+NETLINK_DIAG_RX_RING
+NETLINK_DIAG_TX_RING
+NETLINK_DIAG_FLAGS
-- 
2.7.4





More information about the Strace-devel mailing list