naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

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

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