From: Geliang Tang <tanggeliang@kylinos.cn>
A new TLS type has been added to cfg_sockopt_types, enabled via the
parameter "-o TLS". do_setsockopt_tls() has been implemented to set
TLS parameters for both the server and client.
Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
.../selftests/net/mptcp/mptcp_connect.c | 47 ++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index 9da32701d2d0..3dd22d7e0460 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -33,6 +33,7 @@
#include <linux/tcp.h>
#include <linux/time_types.h>
#include <linux/sockios.h>
+#include <linux/tls.h>
extern int optind;
@@ -88,6 +89,7 @@ struct cfg_cmsg_types {
struct cfg_sockopt_types {
unsigned int transparent:1;
unsigned int mptfo:1;
+ unsigned int tls:1;
};
struct tcp_inq_state {
@@ -283,6 +285,39 @@ static int is_mptcp(int fd)
return mptcp;
}
+static void do_setsockopt_tls(int fd)
+{
+ struct tls12_crypto_info_aes_gcm_128 tls_tx = {
+ .info = {
+ .version = TLS_1_2_VERSION,
+ .cipher_type = TLS_CIPHER_AES_GCM_128,
+ },
+ };
+ struct tls12_crypto_info_aes_gcm_128 tls_rx = {
+ .info = {
+ .version = TLS_1_2_VERSION,
+ .cipher_type = TLS_CIPHER_AES_GCM_128,
+ },
+ };
+ int so_buf = 6553500;
+ int err;
+
+ err = do_ulp_so(fd, "tls");
+ if (err)
+ xerror("setsockopt TCP_ULP");
+
+ err = setsockopt(fd, SOL_TLS, TLS_TX, (void *)&tls_tx, sizeof(tls_tx));
+ if (err)
+ xerror("setsockopt TLS_TX");
+
+ err = setsockopt(fd, SOL_TLS, TLS_RX, (void *)&tls_rx, sizeof(tls_rx));
+ if (err)
+ xerror("setsockopt TLS_RX");
+
+ set_sndbuf(fd, so_buf);
+ set_rcvbuf(fd, so_buf);
+}
+
#define X(m) xerror("%s:%u: %s: failed for proto %d at line %u", __FILE__, __LINE__, (m), proto, line)
static void sock_test_tcpulp(int sock, int proto, unsigned int line)
{
@@ -436,8 +471,11 @@ static int sock_connect_mptcp(const char * const remoteaddr,
}
freeaddrinfo(addr);
- if (sock != -1)
+ if (sock != -1) {
SOCK_TEST_TCPULP(sock, proto);
+ if (cfg_sockopt_types.tls)
+ do_setsockopt_tls(sock);
+ }
return sock;
}
@@ -1210,6 +1248,8 @@ int main_loop_s(int listensock)
}
SOCK_TEST_TCPULP(remotesock, 0);
+ if (cfg_sockopt_types.tls)
+ do_setsockopt_tls(remotesock);
memset(&winfo, 0, sizeof(winfo));
err = copyfd_io(fd, remotesock, 1, true, &winfo);
@@ -1310,6 +1350,11 @@ static void parse_setsock_options(const char *name)
return;
}
+ if (strncmp(name, "TLS", len) == 0) {
+ cfg_sockopt_types.tls = 1;
+ return;
+ }
+
fprintf(stderr, "Unrecognized setsockopt option %s\n", name);
exit(1);
}
--
2.51.0