[PATCH 7/8] netlink: add a basic socket diag parser of AF_SMC messages
Dmitry V. Levin
ldv at altlinux.org
Tue Jun 13 20:47:45 UTC 2017
On Tue, Jun 13, 2017 at 10:13:24PM +0800, JingPiao Chen wrote:
> * 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
> + */
I don't think these lengthy comments are relevant for strace.
> +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)
I don't think we need either __SMC_DIAG_MAX or SMC_DIAG_MAX.
> +
> +#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);
Is it correct? Does the kernel treat smc_diag_req.id as AF_INET, AF_INET6,
or something else?
> + 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);
Likewise, how does the kernel treat smc_diag_msg.id?
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170613/c40102dc/attachment.bin>
More information about the Strace-devel
mailing list