File smc-tools-sles12sp4-parse-address-family-of-ip-address.patch of Package smc-tools.14708
From 7369dbf9f454802ff1eb1a7903df0315dcbde560 Mon Sep 17 00:00:00 2001
From: Karsten Graul <kgraul@linux.ibm.com>
Date: Wed, 17 Oct 2018 10:50:22 +0200
Subject: [PATCH] smc-tools: parse address family of ip address
The content of the diag_family field does not reliably indicate the
ip address family. Parse the address family from the address.
Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
---
smcss.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/smcss.c b/smcss.c
index 8948779..5b1df14 100644
--- a/smcss.c
+++ b/smcss.c
@@ -251,11 +251,26 @@ static void parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta,
/* format one sockaddr / port */
static void addr_format(char *buf, size_t buf_len, size_t short_len,
- int af, void *addr, int port)
+ __be32 addr[4], int port)
{
char *errmsg = "(inet_ntop error)"; /* very unlikely */
char addr_buf[64], port_buf[16];
int addr_len, port_len;
+ int af;
+
+ /* There was an upstream discussion about the content of the
+ * diag_family field. Originally it was AF_SMC, but was changed with
+ * IPv6 support to indicate AF_INET or AF_INET6. Upstream complained
+ * later that there is no way to separate AF_INET from AF_SMC diag msgs.
+ * We now change back the value of the diag_family field to be always
+ * AF_SMC. We now 'parse' the IP address type.
+ * Note that smc_diag.c in kernel always clears the whole addr field
+ * before the ip address is copied into and we can rely on that here.
+ */
+ if (addr[1] == 0 && addr[2] == 0 && addr[3] == 0)
+ af = AF_INET;
+ else
+ af = AF_INET6;
if (!inet_ntop(af, addr, addr_buf, sizeof(addr_buf))) {
strcpy(buf, errmsg);
@@ -307,13 +322,13 @@ static void show_one_smc_sock(struct nlmsghdr *nlh)
goto newline;
addr_format(txtbuf, sizeof(txtbuf), ADDR_LEN_SHORT,
- r->diag_family, r->id.idiag_src, ntohs(r->id.idiag_sport));
+ r->id.idiag_src, ntohs(r->id.idiag_sport));
printf("%-*s ", (int)MAX(ADDR_LEN_SHORT, strlen(txtbuf)), txtbuf);
if (r->diag_state == 10) /* LISTEN state */
goto newline;
addr_format(txtbuf, sizeof(txtbuf), ADDR_LEN_SHORT,
- r->diag_family, r->id.idiag_dst, ntohs(r->id.idiag_dport));
+ r->id.idiag_dst, ntohs(r->id.idiag_dport));
printf("%-*s ", (int)MAX(ADDR_LEN_SHORT, strlen(txtbuf)), txtbuf);
printf("%04x ", r->id.idiag_if);
if (r->diag_mode == SMC_DIAG_MODE_FALLBACK_TCP) {
--
2.23.0.windows.1