naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

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

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