naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0032-ss-allow-dumping-kTLS-info.patch

07a51b
From 06bd12bd8e48182f7f3293bbec187b4e90da796f Mon Sep 17 00:00:00 2001
07a51b
From: Andrea Claudi <aclaudi@redhat.com>
07a51b
Date: Mon, 29 Jun 2020 14:36:51 +0200
07a51b
Subject: [PATCH] ss: allow dumping kTLS info
07a51b
07a51b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1812207
07a51b
Upstream Status: iproute2.git commit 14cadc707b919
07a51b
Conflicts: due to out-of-order cherry-pick of commit
07a51b
           712fdd98c0839 ("ss: allow dumping MPTCP subflow information")
07a51b
07a51b
commit 14cadc707b919914e9a2d5dffad9232c3ae97c5f
07a51b
Author: Davide Caratti <dcaratti@redhat.com>
07a51b
Date:   Mon Oct 7 12:16:44 2019 +0200
07a51b
07a51b
    ss: allow dumping kTLS info
07a51b
07a51b
    now that INET_DIAG_INFO requests can dump TCP ULP information, extend 'ss'
07a51b
    to allow diagnosing kTLS when it is attached to a TCP socket. While at it,
07a51b
    import kTLS uAPI definitions from the latest net-next tree.
07a51b
07a51b
    CC: Andrea Claudi <aclaudi@redhat.com>
07a51b
    Co-developed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
07a51b
    Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
07a51b
    Signed-off-by: Davide Caratti <dcaratti@redhat.com>
07a51b
    Signed-off-by: David Ahern <dsahern@gmail.com>
07a51b
---
07a51b
 misc/ss.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
07a51b
 1 file changed, 82 insertions(+)
07a51b
07a51b
diff --git a/misc/ss.c b/misc/ss.c
07a51b
index 3d565af86087c..8285382bd6c4a 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/tls.h>
07a51b
 #include <linux/mptcp.h>
07a51b
 
07a51b
 /* AF_VSOCK/PF_VSOCK is only provided since glibc 2.18 */
07a51b
@@ -2752,6 +2753,72 @@ static void print_md5sig(struct tcp_diag_md5sig *sig)
07a51b
 	print_escape_buf(sig->tcpm_key, sig->tcpm_keylen, " ,");
07a51b
 }
07a51b
 
07a51b
+static void tcp_tls_version(struct rtattr *attr)
07a51b
+{
07a51b
+	u_int16_t val;
07a51b
+
07a51b
+	if (!attr)
07a51b
+		return;
07a51b
+	val = rta_getattr_u16(attr);
07a51b
+
07a51b
+	switch (val) {
07a51b
+	case TLS_1_2_VERSION:
07a51b
+		out(" version: 1.2");
07a51b
+		break;
07a51b
+	case TLS_1_3_VERSION:
07a51b
+		out(" version: 1.3");
07a51b
+		break;
07a51b
+	default:
07a51b
+		out(" version: unknown(%hu)", val);
07a51b
+		break;
07a51b
+	}
07a51b
+}
07a51b
+
07a51b
+static void tcp_tls_cipher(struct rtattr *attr)
07a51b
+{
07a51b
+	u_int16_t val;
07a51b
+
07a51b
+	if (!attr)
07a51b
+		return;
07a51b
+	val = rta_getattr_u16(attr);
07a51b
+
07a51b
+	switch (val) {
07a51b
+	case TLS_CIPHER_AES_GCM_128:
07a51b
+		out(" cipher: aes-gcm-128");
07a51b
+		break;
07a51b
+	case TLS_CIPHER_AES_GCM_256:
07a51b
+		out(" cipher: aes-gcm-256");
07a51b
+		break;
07a51b
+	}
07a51b
+}
07a51b
+
07a51b
+static void tcp_tls_conf(const char *name, struct rtattr *attr)
07a51b
+{
07a51b
+	u_int16_t val;
07a51b
+
07a51b
+	if (!attr)
07a51b
+		return;
07a51b
+	val = rta_getattr_u16(attr);
07a51b
+
07a51b
+	switch (val) {
07a51b
+	case TLS_CONF_BASE:
07a51b
+		out(" %s: none", name);
07a51b
+		break;
07a51b
+	case TLS_CONF_SW:
07a51b
+		out(" %s: sw", name);
07a51b
+		break;
07a51b
+	case TLS_CONF_HW:
07a51b
+		out(" %s: hw", name);
07a51b
+		break;
07a51b
+	case TLS_CONF_HW_RECORD:
07a51b
+		out(" %s: hw-record", name);
07a51b
+		break;
07a51b
+	default:
07a51b
+		out(" %s: unknown(%hu)", name, val);
07a51b
+		break;
07a51b
+	}
07a51b
+}
07a51b
+
07a51b
 static void mptcp_subflow_info(struct rtattr *tb[])
07a51b
 {
07a51b
 	u_int32_t flags = 0;
07a51b
@@ -2966,6 +3033,21 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
07a51b
 		parse_rtattr_nested(ulpinfo, INET_ULP_INFO_MAX,
07a51b
 				    tb[INET_DIAG_ULP_INFO]);
07a51b
 
07a51b
+		if (ulpinfo[INET_ULP_INFO_NAME])
07a51b
+			out(" tcp-ulp-%s",
07a51b
+			    rta_getattr_str(ulpinfo[INET_ULP_INFO_NAME]));
07a51b
+
07a51b
+		if (ulpinfo[INET_ULP_INFO_TLS]) {
07a51b
+			struct rtattr *tlsinfo[TLS_INFO_MAX + 1] = { 0 };
07a51b
+
07a51b
+			parse_rtattr_nested(tlsinfo, TLS_INFO_MAX,
07a51b
+					    ulpinfo[INET_ULP_INFO_TLS]);
07a51b
+
07a51b
+			tcp_tls_version(tlsinfo[TLS_INFO_VERSION]);
07a51b
+			tcp_tls_cipher(tlsinfo[TLS_INFO_CIPHER]);
07a51b
+			tcp_tls_conf("rxconf", tlsinfo[TLS_INFO_RXCONF]);
07a51b
+			tcp_tls_conf("txconf", tlsinfo[TLS_INFO_TXCONF]);
07a51b
+		}
07a51b
 		if (ulpinfo[INET_ULP_INFO_MPTCP]) {
07a51b
 			struct rtattr *sfinfo[MPTCP_SUBFLOW_ATTR_MAX + 1] =
07a51b
 				{ 0 };
07a51b
-- 
07a51b
2.26.2
07a51b