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.
This commit is contained in:
Eugene Syromyatnikov 2018-08-19 10:48:06 +02:00 committed by Dmitry V. Levin
parent f9578731fc
commit cf174ac87a
4 changed files with 56 additions and 1 deletions

View File

@ -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 */

View File

@ -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)

View File

@ -154,6 +154,13 @@ int main(void)
},
.role = SMC_CLNT
};
static const struct smcd_diag_dmbinfo dinfo = {
.linkid = 0xdeadc0de,
.peer_gid = 0xbefeededbadc0dedULL,
.my_gid = 0xdeec0dedfacebeefULL,
.token = 0xcafedecaffeedeedULL,
.peer_token = 0xfeedfacebeeff00dULL,
};
int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct smc_diag_msg);
@ -194,6 +201,16 @@ int main(void)
printf(", peer_gid=\"%s\"}", linfo.lnk[0].peer_gid);
printf(", role=SMC_CLNT}"));
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_smc_diag_msg, print_smc_diag_msg,
SMC_DIAG_DMBINFO, pattern, dinfo,
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);
printf("}"));
printf("+++ exited with 0 +++\n");
return 0;
}

View File

@ -3,3 +3,4 @@ SMC_DIAG_NONE
SMC_DIAG_CONNINFO
SMC_DIAG_LGRINFO
SMC_DIAG_SHUTDOWN
SMC_DIAG_DMBINFO