From cf174ac87a04d386513b5af9bf5cc08dc333febf Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Sun, 19 Aug 2018 10:48:06 +0200
Subject: [PATCH 021/293] netlink_smc_diag: implement SMC_DIAG_DMBINFO
 decoding

The message has been added by Linux commit v4.19-rc1~140^2~507^2~1.

* linux/smc_diag.h: Include "gcc_compat.h".
(enum): Add SMC_DIAG_DMBINFO.
(struct smcd_diag_dmbinfo): New type definition.
* xlat/smc_diag_attrs.in (SMC_DIAG_DMBINFO): New constant.
* netlink_smc_diag.c (decode_smc_diag_dmbinfo): New function.
(smc_diag_msg_nla_decoders) [SMC_DIAG_DMBINFO]: New decoder, calls
decode_smc_diag_dmbinfo.
* tests/nlattr_smc_diag_msg.c: Add SMC_DIAG_DMBINFO check.
---
 linux/smc_diag.h            | 13 +++++++++++++
 netlink_smc_diag.c          | 26 +++++++++++++++++++++++++-
 xlat/smc_diag_attrs.in      |  1 +
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/linux/smc_diag.h b/linux/smc_diag.h
index a9d4a51..287cb55 100644
--- a/linux/smc_diag.h
+++ b/linux/smc_diag.h
@@ -3,6 +3,8 @@
 
 #include <linux/inet_diag.h>
 
+#include "gcc_compat.h"
+
 /* Request structure */
 struct smc_diag_req {
 	uint8_t diag_family;
@@ -28,6 +30,7 @@ enum {
 	SMC_DIAG_CONNINFO,
 	SMC_DIAG_LGRINFO,
 	SMC_DIAG_SHUTDOWN,
+	SMC_DIAG_DMBINFO,
 };
 
 /* SMC_DIAG_CONNINFO */
@@ -64,9 +67,19 @@ struct smc_diag_linkinfo {
 	uint8_t peer_gid[40];
 };
 
+/* SMC_DIAG_LGRINFO */
 struct smc_diag_lgrinfo {
 	struct smc_diag_linkinfo lnk[1];
 	uint8_t role;
 };
 
+/* SMC_DIAG_DMBINFO */
+struct smcd_diag_dmbinfo {
+	uint32_t linkid;
+	uint64_t ATTRIBUTE_ALIGNED(8) peer_gid;
+	uint64_t ATTRIBUTE_ALIGNED(8) my_gid;
+	uint64_t ATTRIBUTE_ALIGNED(8) token;
+	uint64_t ATTRIBUTE_ALIGNED(8) peer_token;
+};
+
 #endif /* !STRACE_LINUX_SMC_DIAG_H */
diff --git a/netlink_smc_diag.c b/netlink_smc_diag.c
index 4ce31e7..42369ad 100644
--- a/netlink_smc_diag.c
+++ b/netlink_smc_diag.c
@@ -146,10 +146,34 @@ decode_smc_diag_lgrinfo(struct tcb *const tcp,
 	return true;
 }
 
+static bool
+decode_smc_diag_dmbinfo(struct tcb *const tcp,
+			const kernel_ulong_t addr,
+			const unsigned int len,
+			const void *const opaque_data)
+{
+	struct smcd_diag_dmbinfo dinfo;
+
+	if (len < sizeof(dinfo))
+		return false;
+	if (umove_or_printaddr(tcp, addr, &dinfo))
+		return true;
+
+	PRINT_FIELD_U("{", dinfo, linkid);
+	PRINT_FIELD_X(", ", dinfo, peer_gid);
+	PRINT_FIELD_X(", ", dinfo, my_gid);
+	PRINT_FIELD_X(", ", dinfo, token);
+	PRINT_FIELD_X(", ", dinfo, peer_token);
+	tprints("}");
+
+	return true;
+}
+
 static const nla_decoder_t smc_diag_msg_nla_decoders[] = {
 	[SMC_DIAG_CONNINFO]	= decode_smc_diag_conninfo,
 	[SMC_DIAG_LGRINFO]	= decode_smc_diag_lgrinfo,
-	[SMC_DIAG_SHUTDOWN]	= decode_nla_u8
+	[SMC_DIAG_SHUTDOWN]	= decode_nla_u8,
+	[SMC_DIAG_DMBINFO]      = decode_smc_diag_dmbinfo,
 };
 
 DECL_NETLINK_DIAG_DECODER(decode_smc_diag_msg)
diff --git a/xlat/smc_diag_attrs.in b/xlat/smc_diag_attrs.in
index cd6179b..023f398 100644
--- a/xlat/smc_diag_attrs.in
+++ b/xlat/smc_diag_attrs.in
@@ -3,3 +3,4 @@ SMC_DIAG_NONE
 SMC_DIAG_CONNINFO
 SMC_DIAG_LGRINFO
 SMC_DIAG_SHUTDOWN
+SMC_DIAG_DMBINFO
-- 
1.7.12.4

