From 955cc506139b87d9794513747dc05a3e0cf6ca85 Mon Sep 17 00:00:00 2001 From: JingPiao Chen Date: Tue, 13 Jun 2017 13:38:27 +0800 Subject: [PATCH] netlink: add a basic socket diag parser of AF_SMC messages * linux/smc_diag.h: New file. * Makefile.am (EXTRA_DIST): Add it. * netlink_sock_diag.c: Include , "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 | 33 +++++++++++++ netlink_sock_diag.c | 84 +++++++++++++++++++++++++++++++++ xlat/smc_diag_extended_flags.in | 3 ++ xlat/smc_states.in | 12 +++++ 5 files changed, 133 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 75a9828e..e22d4804 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 00000000..aea7d320 --- /dev/null +++ b/linux/smc_diag.h @@ -0,0 +1,33 @@ +#ifndef STRACE_LINUX_SMC_DIAG_H +#define STRACE_LINUX_SMC_DIAG_H + +#include + +/* 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; +}; + +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, +}; + +#endif /* !STRACE_LINUX_SMC_DIAG_H */ diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c index 690a032a..8dbfd077 100644 --- a/netlink_sock_diag.c +++ b/netlink_sock_diag.c @@ -35,6 +35,9 @@ #include #include #include +#ifdef AF_SMC +# include +#endif #include #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 @@ -418,6 +426,79 @@ decode_inet_diag_msg(struct tcb *const tcp, tprints("}"); } +#ifdef AF_SMC +static void +decode_smc_diag_req(struct tcb *const tcp, + const struct nlmsghdr *const nlmsghdr, + const uint8_t family, + const kernel_ulong_t addr, + const kernel_ulong_t len) +{ + struct smc_diag_req req = { .diag_family = family }; + const size_t offset = sizeof(req.diag_family); + + tprints("{diag_family="); + printxval(addrfams, req.diag_family, "AF_???"); + + tprints(", "); + if (len >= sizeof(req)) { + if (!umoven_or_printaddr(tcp, addr + offset, + sizeof(req) - offset, + (void *) &req + offset)) { + tprints("diag_ext="); + printflags(smc_diag_extended_flags, req.diag_ext, + "1<= sizeof(msg)) { + if (!umoven_or_printaddr(tcp, addr + offset, + sizeof(msg) - offset, + (void *) &msg + offset)) { + 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); + } + } else + tprints("..."); + tprints("}"); + +} +#endif + typedef void (*netlink_diag_decoder_t)(struct tcb *, const struct nlmsghdr *, uint8_t family, @@ -431,6 +512,9 @@ static const struct { [AF_INET6] = { 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 00000000..9bd39581 --- /dev/null +++ b/xlat/smc_diag_extended_flags.in @@ -0,0 +1,3 @@ +#unconditional +1<<(SMC_DIAG_CONNINFO-1) +1<<(SMC_DIAG_LGRINFO-1) diff --git a/xlat/smc_states.in b/xlat/smc_states.in new file mode 100644 index 00000000..d197b1f7 --- /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.40.0