[PATCH v2 11/18] netlink: decode AF_UNIX unix_diag_msg attributes

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


* netlink_sock_diag.c (unix_diag_msg_nla_decoders): New array.
(decode_unix_diag_msg): Use it.
* linux/unix_diag.h (unix_diag_vfs, unix_diag_rqlen): New structures.
---
 linux/unix_diag.h   | 10 ++++++++
 netlink_sock_diag.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/linux/unix_diag.h b/linux/unix_diag.h
index 3c9d99f..f1a7fc0 100644
--- a/linux/unix_diag.h
+++ b/linux/unix_diag.h
@@ -37,4 +37,14 @@ enum {
 	UNIX_DIAG_SHUTDOWN,
 };
 
+struct unix_diag_vfs {
+	uint32_t udiag_vfs_ino;
+	uint32_t udiag_vfs_dev;
+};
+
+struct unix_diag_rqlen {
+	uint32_t udiag_rqueue;
+	uint32_t udiag_wqueue;
+};
+
 #endif /* !STRACE_LINUX_UNIX_DIAG_H */
diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c
index dfa7fea..5c2f3ac 100644
--- a/netlink_sock_diag.c
+++ b/netlink_sock_diag.c
@@ -141,6 +141,76 @@ decode_meminfo(struct tcb *tcp, kernel_ulong_t addr,
 	return true;
 }
 
+static bool
+decode_unix_diag_vfs(struct tcb *tcp, kernel_ulong_t addr,
+		     kernel_ulong_t len, void *const opaque_data)
+{
+	struct unix_diag_vfs uv;
+
+	if (len < sizeof(uv))
+		return false;
+	if (umove_or_printaddr(tcp, addr, &uv))
+		return true;
+
+	tprints("{udiag_vfs_dev=");
+	print_dev_t(uv.udiag_vfs_dev);
+	tprintf(", udiag_vfs_ino=%" PRIu32 "}", uv.udiag_vfs_ino);
+
+	return true;
+}
+
+static bool
+print_inode(struct tcb *tcp, void *elem_buf,
+	    size_t elem_size, void *opaque_data)
+{
+	tprintf("%" PRIu32, *(uint32_t *) elem_buf);
+
+	return true;
+}
+
+static bool
+decode_unix_diag_inode(struct tcb *tcp, kernel_ulong_t addr,
+		       kernel_ulong_t len, void *const opaque_data)
+{
+	uint32_t inode;
+	int nmemb = len / sizeof(inode);
+
+	if (!nmemb)
+		return false;
+
+	print_array(tcp, addr, nmemb, &inode, sizeof(inode),
+		    umoven_or_printaddr, print_inode, 0);
+
+	return true;
+}
+
+static bool
+decode_unix_diag_rqlen(struct tcb *tcp, kernel_ulong_t addr,
+		       kernel_ulong_t len, void *const opaque_data)
+{
+	struct unix_diag_rqlen rql;
+
+	if (len < sizeof(rql))
+		return false;
+	if (umove_or_printaddr(tcp, addr, &rql))
+		return true;
+
+	tprintf("{udiag_rqueue=%" PRIu32 ", udiag_wqueue=%" PRIu32 "}",
+		rql.udiag_rqueue, rql.udiag_wqueue);
+
+	return true;
+}
+
+static const nla_decoder_t unix_diag_msg_nla_decoders[] = {
+	[UNIX_DIAG_NAME]	= decode_nla_str,
+	[UNIX_DIAG_VFS]		= decode_unix_diag_vfs,
+	[UNIX_DIAG_PEER]	= decode_nla_u32,
+	[UNIX_DIAG_ICONS]	= decode_unix_diag_inode,
+	[UNIX_DIAG_RQLEN]	= decode_unix_diag_rqlen,
+	[UNIX_DIAG_MEMINFO]	= decode_meminfo,
+	[UNIX_DIAG_SHUTDOWN]	= decode_nla_u8
+};
+
 static void
 decode_unix_diag_msg(struct tcb *const tcp,
 		     const struct nlmsghdr *const nlmsghdr,
@@ -179,7 +249,8 @@ decode_unix_diag_msg(struct tcb *const tcp,
 		tprints(", ");
 		decode_nlattr(tcp, addr + offset, len - offset,
 			      unix_diag_attrs, "UNIX_DIAG_???",
-			      NULL, 0, NULL);
+			      unix_diag_msg_nla_decoders,
+			      ARRAY_SIZE(unix_diag_msg_nla_decoders), NULL);
 	}
 }
 
-- 
2.7.4





More information about the Strace-devel mailing list