[PATCH v4 03/10] netlink: add a dummy netlink attribute parser of AF_NETLINK diag

JingPiao Chen chenjingpiao at gmail.com
Tue Jun 20 09:23:48 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 |  5 +++++
 3 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 xlat/netlink_diag_attrs.in

diff --git a/linux/netlink_diag.h b/linux/netlink_diag.h
index 49b7550..ad13aa9 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 f92253e..899a980 100644
--- a/netlink_sock_diag.c
+++ b/netlink_sock_diag.c
@@ -46,6 +46,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"
 
@@ -192,7 +193,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_???");
@@ -222,10 +224,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..22c70bd
--- /dev/null
+++ b/xlat/netlink_diag_attrs.in
@@ -0,0 +1,5 @@
+#unconditional
+NETLINK_DIAG_MEMINFO
+NETLINK_DIAG_GROUPS
+NETLINK_DIAG_RX_RING
+NETLINK_DIAG_TX_RING
-- 
2.7.4





More information about the Strace-devel mailing list