From patchwork Sat Oct 1 03:15:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Shytyi X-Patchwork-Id: 12996345 X-Patchwork-Delegate: pabeni@redhat.com Received: from sender11-of-o51.zoho.eu (sender11-of-o51.zoho.eu [31.186.226.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9860F1FD2 for ; Sat, 1 Oct 2022 03:15:21 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1664594119; cv=none; d=zohomail.eu; s=zohoarc; b=JA1UyrLWvRvbmP30SPyzTXAi1hukLn8sJ5R3Ctz22zRFSvNxIO7OBhLIDDsG3KQRlBumDL9LmXJoMUObkQQJQ/94IWza1C9wfUuetMeSLCBZ9GmTtk4FQ6YKKGX0K7VHm29XALaOn1W12yP9SQlrUOpVEDBG2SlW+RBMDZbvwsM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1664594119; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=rDvKS/y4ifrmSjdukq6vsDamnf5X+7MrJcFBzZ0I/v4=; b=UzgvKwOrifkCIRDajVQL3ZzQwbU1PzwXp8ar8ufl7B20CRVBPr3ZWDxTL0OrbURD1OMJiQMqA5CIh/8goNmtWcSRdjiZ7dqEY/+mrAwgCfjzrfRz+1jHQkULfJ5s5z+GdCQ3ORwI6KVykGuP85p3bu7CF6tc4WQk6nX7/owrpiU= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=shytyi.net; spf=pass smtp.mailfrom=dmytro@shytyi.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1664594119; s=hs; d=shytyi.net; i=dmytro@shytyi.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=rDvKS/y4ifrmSjdukq6vsDamnf5X+7MrJcFBzZ0I/v4=; b=d0RQhgs0QhcM8MpbyZ3yh1HUWelDfvTbyCqJEr8RsubScUbXp2hKkQNk76neOqlR 2lu3/7DNuCz3CH/KO5in50zlXKGtve8jLYhH1mcnVbMXVto+BKuF4cCAKOy6jN+/jKI /yPtLbmd/0UlCQYokCqCdPmHDUUq0Vpk4vr4QkSk= Received: from localhost.localdomain (243.34.22.93.rev.sfr.net [93.22.34.243]) by mx.zoho.eu with SMTPS id 1664594117468646.7969425783506; Sat, 1 Oct 2022 05:15:17 +0200 (CEST) From: Dmytro Shytyi To: mptcp@lists.linux.dev Cc: Dmytro Shytyi Message-ID: <20221001031502.29152-8-dmytro@shytyi.net> Subject: [RFC PATCH mptcp-next v13 7/7] selftests: mptfo initiator/listener Date: Sat, 1 Oct 2022 03:15:02 +0000 X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221001031502.29152-1-dmytro@shytyi.net> References: <20221001031502.29152-1-dmytro@shytyi.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ZohoMailClient: External MPTFO tests: these are examples of initiator (sendto) and listener, probably are going to be integrated to the mptcp_connect.* selftests Signed-off-by: Dmytro Shytyi --- tools/testing/selftests/net/mptcp/mptfo.sh | 13 +++ .../selftests/net/mptcp/mptfo_initiator.c | 43 ++++++++ .../selftests/net/mptcp/mptfo_listener.c | 100 ++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 tools/testing/selftests/net/mptcp/mptfo.sh create mode 100644 tools/testing/selftests/net/mptcp/mptfo_initiator.c create mode 100644 tools/testing/selftests/net/mptcp/mptfo_listener.c diff --git a/tools/testing/selftests/net/mptcp/mptfo.sh b/tools/testing/selftests/net/mptcp/mptfo.sh new file mode 100644 index 000000000000..9ed0cb281094 --- /dev/null +++ b/tools/testing/selftests/net/mptcp/mptfo.sh @@ -0,0 +1,13 @@ +#!/bin/bash +#This is an example of environmen that was used to generate wireshark +sudo ip netns add server +sudo ip netns add client +sudo ip link add veth0 type veth peer name veth1 +sudo ip link set veth1 netns server +sudo ip link set veth0 netns client +sudo ip netns exec client ip a a 10.10.0.1/24 dev veth0 +sudo ip netns exec server ip a a 10.10.0.2/24 dev veth1 +sudo ip netns exec client ip link set dev veth0 up +sudo ip netns exec server ip link set dev veth1 up +sudo ip netns exec server bash -c "echo 2 > /proc/sys/net/ipv4/tcp_fastopen" +sudo ip netns exec client bash -c "echo 1 > /proc/sys/net/ipv4/tcp_fastopen" diff --git a/tools/testing/selftests/net/mptcp/mptfo_initiator.c b/tools/testing/selftests/net/mptcp/mptfo_initiator.c new file mode 100644 index 000000000000..05e6a3d62bb8 --- /dev/null +++ b/tools/testing/selftests/net/mptcp/mptfo_initiator.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SERVER_PORT 7003 + +int main(int argc, char *argv[]) +{ + unsigned char valsyn[3] = "abc"; + struct sockaddr_in daddr; + char *valend = "fff"; + char *val1 = "zz1"; + char *val2 = "zz2"; + char *val3 = "zz3"; + int sock_fd = -1; + int ret; + + memset(&daddr, 0, sizeof(daddr)); + inet_pton(AF_INET, "10.10.0.2", &daddr.sin_addr); + daddr.sin_family = AF_INET; + daddr.sin_port = htons(SERVER_PORT); + + sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP); + + ret = sendto(sock_fd, valsyn, 3, MSG_FASTOPEN, (struct sockaddr *) &daddr, sizeof(daddr)); + ret = write(sock_fd, val1, 3); + ret = write(sock_fd, val2, 3); + ret = write(sock_fd, val2, 3); + ret = write(sock_fd, val2, 3); + ret = write(sock_fd, val3, 3); + ret = write(sock_fd, valend, 3); + + close(sock_fd); + return EXIT_SUCCESS; +} diff --git a/tools/testing/selftests/net/mptcp/mptfo_listener.c b/tools/testing/selftests/net/mptcp/mptfo_listener.c new file mode 100644 index 000000000000..6890349b14bb --- /dev/null +++ b/tools/testing/selftests/net/mptcp/mptfo_listener.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CLIENT_QUEUE_LEN 10 +#define SERVER_PORT 7003 + +int main(void) +{ + int listen_sock_fd = -1, client_sock_fd = -1; + char str_addr[INET6_ADDRSTRLEN]; + struct sockaddr_in server_addr; + int ret, flag; + int qlen = 5; + char ch; + + server_addr.sin_family = AF_INET; + inet_pton(AF_INET, "10.10.0.2", &server_addr.sin_addr); + server_addr.sin_port = htons(SERVER_PORT); + + /* Create socket for listening (client requests) */ + listen_sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP); + if (listen_sock_fd == -1) { + perror("socket()server"); + return EXIT_FAILURE; + } + + /* Set socket to reuse address */ + flag = 1; + ret = setsockopt(listen_sock_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); + if (ret == -1) { + perror("setsockopt()"); + return EXIT_FAILURE; + } + + ret = setsockopt(listen_sock_fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)); + if (ret == -1) { + perror("setsockopt()TCP_FASTOPEN"); + return EXIT_FAILURE; + } + + /* Bind address and socket together */ + ret = bind(listen_sock_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)); + if (ret == -1) { + perror("bind()"); + close(listen_sock_fd); + return EXIT_FAILURE; + } + + /* Create listening queue (client requests) */ + ret = listen(listen_sock_fd, CLIENT_QUEUE_LEN); + if (ret == -1) { + perror("listen()"); + close(listen_sock_fd); + return EXIT_FAILURE; + } + perror("Server listening"); + while (1) { + /* Do TCP handshake with client */ + client_sock_fd = accept(listen_sock_fd, + NULL, + 0); + if (client_sock_fd == -1) { + perror("accept()"); + close(listen_sock_fd); + return EXIT_FAILURE; + } else { + perror("ACCEPT_SUCCESS"); + } + + char rb[1024]; + + while (1) { + ret = read(client_sock_fd, rb, 3); + + if (ret == -1) { + perror("SERVVERread()"); + close(client_sock_fd); + break; + } else { + fprintf(stderr, "received %c%c%c from client", rb[0], rb[1], rb[2]); + } + if (rb[0] == 'f' && rb[1] == 'f' && rb[2] == 'f') { + close(client_sock_fd); + break; + } + + } + } + + return EXIT_SUCCESS; +}