Blame SOURCES/0020-ss-allow-dumping-MPTCP-subflow-information.patch

07a51b
From afc9c910cc9c818180364860b04535def3c19b6e Mon Sep 17 00:00:00 2001
07a51b
From: Andrea Claudi <aclaudi@redhat.com>
07a51b
Date: Thu, 4 Jun 2020 19:27:41 +0200
07a51b
Subject: [PATCH] ss: allow dumping MPTCP subflow information
07a51b
07a51b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1812207
07a51b
Upstream Status: unknown commit 712fdd98c0839
07a51b
Conflicts: context changes and code slightly adapted in tcp_show_info()
07a51b
           due to missing commit 14cadc707b919 ("ss: allow dumping kTLS info")
07a51b
07a51b
commit 712fdd98c0839540a50baca0fb858c7a72d18031
07a51b
Author: Davide Caratti <dcaratti@redhat.com>
07a51b
Date:   Thu Apr 23 15:37:09 2020 +0200
07a51b
07a51b
    ss: allow dumping MPTCP subflow information
07a51b
07a51b
     [root@f31 packetdrill]# ss -tni
07a51b
07a51b
     ESTAB    0        0           192.168.82.247:8080           192.0.2.1:35273
07a51b
              cubic wscale:7,8 [...] tcp-ulp-mptcp flags:Mec token:0000(id:0)/5f856c60(id:0) seq:b810457db34209a5 sfseq:1 ssnoff:0 maplen:190
07a51b
07a51b
    Additionally extends ss manpage to describe the new entry layout.
07a51b
07a51b
    Signed-off-by: Davide Caratti <dcaratti@redhat.com>
07a51b
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>
07a51b
    Signed-off-by: David Ahern <dsahern@gmail.com>
07a51b
---
07a51b
 man/man8/ss.8 |  5 ++++
07a51b
 misc/ss.c     | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++
07a51b
 2 files changed, 74 insertions(+)
07a51b
07a51b
diff --git a/man/man8/ss.8 b/man/man8/ss.8
07a51b
index 023d771b17878..c80853f98c49a 100644
07a51b
--- a/man/man8/ss.8
07a51b
+++ b/man/man8/ss.8
07a51b
@@ -261,6 +261,11 @@ the pacing rate and max pacing rate
07a51b
 .TP
07a51b
 .B rcv_space:<rcv_space>
07a51b
 a helper variable for TCP internal auto tuning socket receive buffer
07a51b
+.P
07a51b
+.TP
07a51b
+.B tcp-ulp-mptcp flags:[MmBbJjecv] token:<rem_token(rem_id)/loc_token(loc_id)> seq:<sn> sfseq:<ssn> ssnoff:<off> maplen:<maplen>
07a51b
+MPTCP subflow information
07a51b
+.P
07a51b
 .RE
07a51b
 .TP
07a51b
 .B \-\-tos
07a51b
diff --git a/misc/ss.c b/misc/ss.c
07a51b
index 363b4c8d87cd3..3d565af86087c 100644
07a51b
--- a/misc/ss.c
07a51b
+++ b/misc/ss.c
07a51b
@@ -51,6 +51,7 @@
07a51b
 #include <linux/tipc.h>
07a51b
 #include <linux/tipc_netlink.h>
07a51b
 #include <linux/tipc_sockets_diag.h>
07a51b
+#include <linux/mptcp.h>
07a51b
 
07a51b
 /* AF_VSOCK/PF_VSOCK is only provided since glibc 2.18 */
07a51b
 #ifndef PF_VSOCK
07a51b
@@ -2751,6 +2752,59 @@ static void print_md5sig(struct tcp_diag_md5sig *sig)
07a51b
 	print_escape_buf(sig->tcpm_key, sig->tcpm_keylen, " ,");
07a51b
 }
07a51b
 
07a51b
+static void mptcp_subflow_info(struct rtattr *tb[])
07a51b
+{
07a51b
+	u_int32_t flags = 0;
07a51b
+
07a51b
+	if (tb[MPTCP_SUBFLOW_ATTR_FLAGS]) {
07a51b
+		char caps[32 + 1] = { 0 }, *cap = &caps[0];
07a51b
+
07a51b
+		flags = rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_FLAGS]);
07a51b
+
07a51b
+		if (flags & MPTCP_SUBFLOW_FLAG_MCAP_REM)
07a51b
+			*cap++ = 'M';
07a51b
+		if (flags & MPTCP_SUBFLOW_FLAG_MCAP_LOC)
07a51b
+			*cap++ = 'm';
07a51b
+		if (flags & MPTCP_SUBFLOW_FLAG_JOIN_REM)
07a51b
+			*cap++ = 'J';
07a51b
+		if (flags & MPTCP_SUBFLOW_FLAG_JOIN_LOC)
07a51b
+			*cap++ = 'j';
07a51b
+		if (flags & MPTCP_SUBFLOW_FLAG_BKUP_REM)
07a51b
+			*cap++ = 'B';
07a51b
+		if (flags & MPTCP_SUBFLOW_FLAG_BKUP_LOC)
07a51b
+			*cap++ = 'b';
07a51b
+		if (flags & MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED)
07a51b
+			*cap++ = 'e';
07a51b
+		if (flags & MPTCP_SUBFLOW_FLAG_CONNECTED)
07a51b
+			*cap++ = 'c';
07a51b
+		if (flags & MPTCP_SUBFLOW_FLAG_MAPVALID)
07a51b
+			*cap++ = 'v';
07a51b
+		if (flags)
07a51b
+			out(" flags:%s", caps);
07a51b
+	}
07a51b
+	if (tb[MPTCP_SUBFLOW_ATTR_TOKEN_REM] &&
07a51b
+	    tb[MPTCP_SUBFLOW_ATTR_TOKEN_LOC] &&
07a51b
+	    tb[MPTCP_SUBFLOW_ATTR_ID_REM] &&
07a51b
+	    tb[MPTCP_SUBFLOW_ATTR_ID_LOC])
07a51b
+		out(" token:%04x(id:%hhu)/%04x(id:%hhu)",
07a51b
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_TOKEN_REM]),
07a51b
+		    rta_getattr_u8(tb[MPTCP_SUBFLOW_ATTR_ID_REM]),
07a51b
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_TOKEN_LOC]),
07a51b
+		    rta_getattr_u8(tb[MPTCP_SUBFLOW_ATTR_ID_LOC]));
07a51b
+	if (tb[MPTCP_SUBFLOW_ATTR_MAP_SEQ])
07a51b
+		out(" seq:%llx",
07a51b
+		    rta_getattr_u64(tb[MPTCP_SUBFLOW_ATTR_MAP_SEQ]));
07a51b
+	if (tb[MPTCP_SUBFLOW_ATTR_MAP_SFSEQ])
07a51b
+		out(" sfseq:%x",
07a51b
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_MAP_SFSEQ]));
07a51b
+	if (tb[MPTCP_SUBFLOW_ATTR_SSN_OFFSET])
07a51b
+		out(" ssnoff:%x",
07a51b
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_SSN_OFFSET]));
07a51b
+	if (tb[MPTCP_SUBFLOW_ATTR_MAP_DATALEN])
07a51b
+		out(" maplen:%x",
07a51b
+		    rta_getattr_u32(tb[MPTCP_SUBFLOW_ATTR_MAP_DATALEN]));
07a51b
+}
07a51b
+
07a51b
 #define TCPI_HAS_OPT(info, opt) !!(info->tcpi_options & (opt))
07a51b
 
07a51b
 static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
07a51b
@@ -2906,6 +2960,21 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
07a51b
 			print_md5sig(sig++);
07a51b
 		}
07a51b
 	}
07a51b
+	if (tb[INET_DIAG_ULP_INFO]) {
07a51b
+		struct rtattr *ulpinfo[INET_ULP_INFO_MAX + 1] = { 0 };
07a51b
+
07a51b
+		parse_rtattr_nested(ulpinfo, INET_ULP_INFO_MAX,
07a51b
+				    tb[INET_DIAG_ULP_INFO]);
07a51b
+
07a51b
+		if (ulpinfo[INET_ULP_INFO_MPTCP]) {
07a51b
+			struct rtattr *sfinfo[MPTCP_SUBFLOW_ATTR_MAX + 1] =
07a51b
+				{ 0 };
07a51b
+
07a51b
+			parse_rtattr_nested(sfinfo, MPTCP_SUBFLOW_ATTR_MAX,
07a51b
+					    ulpinfo[INET_ULP_INFO_MPTCP]);
07a51b
+			mptcp_subflow_info(sfinfo);
07a51b
+		}
07a51b
+	}
07a51b
 }
07a51b
 
07a51b
 static const char *format_host_sa(struct sockaddr_storage *sa)
07a51b
-- 
07a51b
2.26.2
07a51b