netlink_smc_diag: decode SMC_DIAG_SHUTDOWN attribute value

* xlat/sock_shutdown_flags.in: New file.
* netlink_smc_diag.c: Include "xlat/sock_shutdown_flags.h".
(decode_smc_diag_shutdown): New function.
(smc_diag_msg_nla_decoders) <[SMC_DIAG_SHUTDOWN]>: Use
decode_smc_diag_shutdown.
* tests/nlattr_smc_diag_msg.c: Add checks for SMC_DIAG_SHUTDOWN.
This commit is contained in:
Eugene Syromyatnikov 2018-08-19 21:33:26 +02:00 committed by Dmitry V. Levin
parent 00bfa52a81
commit 587d1d5663
3 changed files with 30 additions and 1 deletions

View File

@ -49,6 +49,7 @@
#include "xlat/smc_diag_mode.h"
#include "xlat/smc_link_group_roles.h"
#include "xlat/smc_states.h"
#include "xlat/sock_shutdown_flags.h"
DECL_NETLINK_DIAG_DECODER(decode_smc_diag_req)
{
@ -148,6 +149,20 @@ decode_smc_diag_lgrinfo(struct tcb *const tcp,
return true;
}
static bool
decode_smc_diag_shutdown(struct tcb *const tcp,
const kernel_ulong_t addr,
const unsigned int len,
const void *const opaque_data)
{
const struct decode_nla_xlat_opts opts = {
ARRSZ_PAIR(sock_shutdown_flags), "???_SHUTDOWN",
.size = 1,
};
return decode_nla_flags(tcp, addr, len, &opts);
}
static bool
decode_smc_diag_dmbinfo(struct tcb *const tcp,
const kernel_ulong_t addr,
@ -201,7 +216,7 @@ decode_smc_diag_fallback(struct tcb *const tcp,
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_smc_diag_shutdown,
[SMC_DIAG_DMBINFO] = decode_smc_diag_dmbinfo,
[SMC_DIAG_FALLBACK] = decode_smc_diag_fallback,
};

View File

@ -169,6 +169,8 @@ int main(void)
.reason = 0x03060000,
.peer_diagnosis = 0x99999999,
};
static uint8_t sd1 = 0x23;
static uint8_t sd2 = 0x40;
int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct smc_diag_msg);
@ -179,6 +181,16 @@ int main(void)
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_smc_diag_msg, print_smc_diag_msg,
SMC_DIAG_SHUTDOWN, pattern, sd1,
printf("RCV_SHUTDOWN|SEND_SHUTDOWN|0x20"));
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_smc_diag_msg, print_smc_diag_msg,
SMC_DIAG_SHUTDOWN, pattern, sd2,
printf("0x40 /* ???_SHUTDOWN */"));
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_smc_diag_msg, print_smc_diag_msg,
SMC_DIAG_CONNINFO, pattern, cinfo,

View File

@ -0,0 +1,2 @@
RCV_SHUTDOWN 1
SEND_SHUTDOWN 2