[PATCH v6 02/18] netlink: add a basic netlink attribute parser of AF_PACKET diag

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


* linux/packet_diag.h (PACKET_DIAG_*): New enum.
* netlink_sock_diag.c: Include "xlat/packet_diag_attrs.h".
(decode_packet_diag_msg): Use decode_nlattr.
* xlat/packet_diag_attrs.in: New file.

Co-authored-by: Fabien Siron <fabien.siron at epita.fr>
---
 linux/packet_diag.h       | 11 +++++++++++
 netlink_sock_diag.c       | 12 +++++++++++-
 xlat/packet_diag_attrs.in |  9 +++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 xlat/packet_diag_attrs.in

diff --git a/linux/packet_diag.h b/linux/packet_diag.h
index 10f48d9..3e8120b 100644
--- a/linux/packet_diag.h
+++ b/linux/packet_diag.h
@@ -26,4 +26,15 @@ struct packet_diag_msg {
 	uint32_t pdiag_cookie[2];
 };
 
+enum {
+	PACKET_DIAG_INFO,
+	PACKET_DIAG_MCLIST,
+	PACKET_DIAG_RX_RING,
+	PACKET_DIAG_TX_RING,
+	PACKET_DIAG_FANOUT,
+	PACKET_DIAG_UID,
+	PACKET_DIAG_MEMINFO,
+	PACKET_DIAG_FILTER,
+};
+
 #endif /* !STRACE_LINUX_PACKET_DIAG_H */
diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c
index ec440e3..82d89b2 100644
--- a/netlink_sock_diag.c
+++ b/netlink_sock_diag.c
@@ -49,6 +49,7 @@
 #include "xlat/netlink_diag_show.h"
 #include "xlat/netlink_states.h"
 
+#include "xlat/packet_diag_attrs.h"
 #include "xlat/packet_diag_show.h"
 
 #ifdef AF_SMC
@@ -277,7 +278,8 @@ decode_packet_diag_msg(struct tcb *const tcp,
 		       const kernel_ulong_t len)
 {
 	struct packet_diag_msg msg = { .pdiag_family = family };
-	const size_t offset = sizeof(msg.pdiag_family);
+	size_t offset = sizeof(msg.pdiag_family);
+	bool decode_nla = false;
 
 	tprints("{pdiag_family=");
 	printxval(addrfams, msg.pdiag_family, "AF_???");
@@ -293,10 +295,18 @@ decode_packet_diag_msg(struct tcb *const tcp,
 				", pdiag_cookie=[%" PRIu32 ", %" PRIu32 "]",
 				msg.pdiag_num, msg.pdiag_ino, msg.pdiag_cookie[0],
 				msg.pdiag_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,
+			      packet_diag_attrs, "PACKET_DIAG_???");
+	}
 }
 
 static void
diff --git a/xlat/packet_diag_attrs.in b/xlat/packet_diag_attrs.in
new file mode 100644
index 0000000..5e33871
--- /dev/null
+++ b/xlat/packet_diag_attrs.in
@@ -0,0 +1,9 @@
+#unconditional
+PACKET_DIAG_INFO
+PACKET_DIAG_MCLIST
+PACKET_DIAG_RX_RING
+PACKET_DIAG_TX_RING
+PACKET_DIAG_FANOUT
+PACKET_DIAG_UID
+PACKET_DIAG_MEMINFO
+PACKET_DIAG_FILTER
-- 
2.7.4





More information about the Strace-devel mailing list