[PATCH 7/8] netlink: add a basic socket diag parser of AF_SMC messages

JingPiao Chen chenjingpiao at gmail.com
Tue Jun 13 14:13:24 UTC 2017


* linux/smc_diag.h: New file.
* Makefile.am (EXTRA_DIST): Add linux/smc_diag.h.
* netlink_sock_diag.c: Include <linux/smc_diag.h>,
"xlat/smc_diag_extended_flags.h" and "xlat/smc_states.h".
(decode_smc_diag_req, decode_smc_diag_msg): New functions.
(diag_decoders): Add AF_SMC.
* xlat/smc_diag_extended_flags.in: New file.
* xlat/smc_states.in: Likewise.
---
 Makefile.am                     |  1 +
 linux/smc_diag.h                | 40 +++++++++++++++++++++++
 netlink_sock_diag.c             | 70 +++++++++++++++++++++++++++++++++++++++++
 xlat/smc_diag_extended_flags.in |  2 ++
 xlat/smc_states.in              | 12 +++++++
 5 files changed, 125 insertions(+)
 create mode 100644 linux/smc_diag.h
 create mode 100644 xlat/smc_diag_extended_flags.in
 create mode 100644 xlat/smc_states.in

diff --git a/Makefile.am b/Makefile.am
index 75a9828..e22d480 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -681,6 +681,7 @@ EXTRA_DIST =				\
 	linux/sh64/syscallent.h		\
 	linux/sh64/userent.h		\
 	linux/signalent.h		\
+	linux/smc_diag.h		\
 	linux/sock_diag.h		\
 	linux/sparc/arch_getrval2.c	\
 	linux/sparc/arch_regs.c		\
diff --git a/linux/smc_diag.h b/linux/smc_diag.h
new file mode 100644
index 0000000..b7401b8
--- /dev/null
+++ b/linux/smc_diag.h
@@ -0,0 +1,40 @@
+#ifndef STRACE_LINUX_SMC_DIAG_H
+#define STRACE_LINUX_SMC_DIAG_H
+
+#include <linux/inet_diag.h>
+
+/* Request structure */
+struct smc_diag_req {
+	uint8_t diag_family;
+	uint8_t pad[2];
+	uint8_t diag_ext;		/* Query extended information */
+	struct inet_diag_sockid	id;
+};
+
+/* Base info structure. It contains socket identity (addrs/ports/cookie) based
+ * on the internal clcsock, and more SMC-related socket data
+ */
+struct smc_diag_msg {
+	uint8_t diag_family;
+	uint8_t diag_state;
+	uint8_t diag_fallback;
+	uint8_t diag_shutdown;
+	struct inet_diag_sockid id;
+
+	uint32_t diag_uid;
+	uint64_t diag_inode;
+};
+
+/* Extensions */
+
+enum {
+	SMC_DIAG_NONE,
+	SMC_DIAG_CONNINFO,
+	SMC_DIAG_LGRINFO,
+	SMC_DIAG_SHUTDOWN,
+	__SMC_DIAG_MAX,
+};
+
+#define SMC_DIAG_MAX (__SMC_DIAG_MAX - 1)
+
+#endif /* !STRACE_LINUX_SMC_DIAG_H */
diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c
index 7467d1a..e42b75a 100644
--- a/netlink_sock_diag.c
+++ b/netlink_sock_diag.c
@@ -35,6 +35,9 @@
 #include <linux/netlink.h>
 #include <linux/netlink_diag.h>
 #include <linux/packet_diag.h>
+#ifdef AF_SMC
+# include <linux/smc_diag.h>
+#endif
 #include <linux/unix_diag.h>
 
 #include "xlat/inet_diag_extended_flags.h"
@@ -47,6 +50,11 @@
 
 #include "xlat/packet_diag_show.h"
 
+#ifdef AF_SMC
+# include "xlat/smc_diag_extended_flags.h"
+# include "xlat/smc_states.h"
+#endif
+
 #include "xlat/unix_diag_show.h"
 
 static void
@@ -331,12 +339,74 @@ decode_inet_diag_msg(struct tcb *const tcp,
 	return true;
 }
 
+#ifdef AF_SMC
+static bool
+decode_smc_diag_req(struct tcb *const tcp,
+		    const struct nlmsghdr *const nlmsghdr,
+		    const kernel_ulong_t addr,
+		    const kernel_ulong_t len)
+{
+	struct smc_diag_req req;
+
+	if (len < sizeof(req) || umove(tcp, addr, &req))
+		return false;
+
+	tprints("{diag_family=");
+	printxval(addrfams, req.diag_family, "AF_???");
+	tprints(", diag_ext=");
+	printflags(smc_diag_extended_flags, req.diag_ext,
+		   "1<<(SMC_DIAG_\?\?\?-1)");
+	tprints(", id=");
+	/*
+	 * AF_SMC protocol family socket handler
+	 * keeping the AF_INET sock address.
+	 */
+	print_inet_diag_sockid(&req.id, AF_INET);
+	tprints("}");
+
+	return true;
+}
+
+static bool
+decode_smc_diag_msg(struct tcb *const tcp,
+		    const struct nlmsghdr *const nlmsghdr,
+		    const kernel_ulong_t addr,
+		    const kernel_ulong_t len)
+{
+	struct smc_diag_msg msg;
+
+	if (len < sizeof(msg) || umove(tcp, addr, &msg))
+		return false;
+
+	tprints("{diag_family=");
+	printxval(addrfams, msg.diag_family, "AF_???");
+	tprints(", diag_state=");
+	printxval(smc_states, msg.diag_state, "SMC_???");
+	tprintf(", diag_fallback=%" PRIu8 ", diag_shutdown=%" PRIu8,
+		msg.diag_fallback, msg.diag_shutdown);
+	tprints(", id=");
+	/*
+	 * AF_SMC protocol family socket handler
+	 * keeping the AF_INET sock address.
+	 */
+	print_inet_diag_sockid(&msg.id, AF_INET);
+	tprintf(", diag_uid=%" PRIu32 ", diag_inode=%" PRIu64 "}",
+		msg.diag_uid, msg.diag_inode);
+
+	return true;
+
+}
+#endif
+
 static const struct {
 	const netlink_decoder_t request, response;
 } diag_decoders[] = {
 	[AF_INET] = { decode_inet_diag_req, decode_inet_diag_msg },
 	[AF_NETLINK] = { decode_netlink_diag_req, decode_netlink_diag_msg },
 	[AF_PACKET] = { decode_packet_diag_req, decode_packet_diag_msg },
+#ifdef AF_SMC
+	[AF_SMC] = { decode_smc_diag_req, decode_smc_diag_msg },
+#endif
 	[AF_UNIX] = { decode_unix_diag_req, decode_unix_diag_msg }
 };
 
diff --git a/xlat/smc_diag_extended_flags.in b/xlat/smc_diag_extended_flags.in
new file mode 100644
index 0000000..8084f1c
--- /dev/null
+++ b/xlat/smc_diag_extended_flags.in
@@ -0,0 +1,2 @@
+{ 1<<(SMC_DIAG_CONNINFO-1)	, "(1<<(SMC_DIAG_CONNINFO-1))"		},
+{ 1<<(SMC_DIAG_LGRINFO-1)	, "(1<<(SMC_DIAG_LGRINFO-1))"		},
diff --git a/xlat/smc_states.in b/xlat/smc_states.in
new file mode 100644
index 0000000..d197b1f
--- /dev/null
+++ b/xlat/smc_states.in
@@ -0,0 +1,12 @@
+SMC_ACTIVE		1
+SMC_INIT		2
+SMC_CLOSED		7
+SMC_LISTEN		10
+SMC_PEERCLOSEWAIT1	20
+SMC_PEERCLOSEWAIT2	21
+SMC_APPFINCLOSEWAIT	24
+SMC_APPCLOSEWAIT1	22
+SMC_APPCLOSEWAIT2	23
+SMC_PEERFINCLOSEWAIT	25
+SMC_PEERABORTWAIT	26
+SMC_PROCESSABORT	27
-- 
2.7.4





More information about the Strace-devel mailing list