From patchwork Wed Jun 12 14:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13695129 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9300317E46F; Wed, 12 Jun 2024 14:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718203281; cv=none; b=XXDeZbrWBKstdJdCVClrZQkf+dIjeUKB0iFVde+/K5AT3ukzOWSIPNk7HSVI6l6mctoeCzfZvzakqnZ+siX9DaFl3WB/YjYty3skSNJ4tb1KTNedeU57ccoHbWz0fVfnJN14WRQdaZztS8F4hPZ3NrWAlb5gTa2dVeYe9iqJtxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718203281; c=relaxed/simple; bh=t857AQ32+0WrHvy2BQlLRYPSgRi9WGUcKdJujyBKiaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cchkuo/hbVLVtcnQbmg+GjSn1JOKrWQtMRSp6mPBQeP5xB3Vs2RgMrjvp2qQnfPcix1M8PC3vyjQexygrEkda6IKJrTRrIB0QVmRP+2VG0pWFgaTf9ctg+n2AE2ArLkuz5btWnCICGnFgVVrxn2G5NlyXNs9fBQwTFpNnlK2ne8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M9Cg2lpy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M9Cg2lpy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A4F8C3277B; Wed, 12 Jun 2024 14:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718203281; bh=t857AQ32+0WrHvy2BQlLRYPSgRi9WGUcKdJujyBKiaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M9Cg2lpyHELOnokC3FcHKoCrMhoLmjdf8g1aEVe62DkWwr1O2dEOG8QKNVXrSrZWT ANvJsu6DA5HWTYzEZLOKrWG/HG5MV1GsJACTvlV6qBD4806Pybi/f5XPdmUX4HJRhh GgKJwXEUlBPgYOZ+Xok7iRfsGmdrwog3243IfSDI3xOUMvHByknfBuefQiGzbnyWhW 2m2/8IkXzPZmuP4SRLCrzPULI89k6EQbBicIbYIjneal2bmA6BapR+BD1nLpITpslK FSM4PFyZUX1ej9hiwu3c7OkKrHYfeSrzZgc1XcfS732fmpgMyUoLyGzVfsN/gmHqmQ NCwD0SoCc5MOw== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 1/4] selftests/bpf: Drop type from network_helper_opts Date: Wed, 12 Jun 2024 22:41:03 +0800 Message-ID: <673f09dc8b8d25661ca21111e42b5790d2136dce.1718202986.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang The opts.{type, noconnect, must_fail} is at least a bit non intuitive or unnecessary. The only use case now is in test_bpf_ip_check_defrag_ok which ends up bypassing most (or at least some) of the connect_to_fd_opts() logic. It's much better that test should have its own connect_to_fd_opts() instead. This patch adds a new "type" parameter for connect_to_fd_opts(), then opts->type can be replaced by "type" parameter in it. In test_bpf_ip_check_defrag_ok, different types are passed to it. And the strcut member "type" of network_helper_opts can be dropped now. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 11 +++++------ tools/testing/selftests/bpf/network_helpers.h | 4 ++-- tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 2 +- tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c | 4 ++-- .../selftests/bpf/prog_tests/ip_check_defrag.c | 5 ++--- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index e20caef06aae..0e52105ae563 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -303,21 +303,20 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add return -1; } -int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) +int connect_to_fd_opts(int server_fd, int type, + const struct network_helper_opts *opts) { struct sockaddr_storage addr; struct sockaddr_in *addr_in; socklen_t addrlen, optlen; - int fd, type, protocol; + int fd, protocol; if (!opts) opts = &default_opts; optlen = sizeof(type); - if (opts->type) { - type = opts->type; - } else { + if (!type) { if (getsockopt(server_fd, SOL_SOCKET, SO_TYPE, &type, &optlen)) { log_err("getsockopt(SOL_TYPE)"); return -1; @@ -370,7 +369,7 @@ int connect_to_fd(int server_fd, int timeout_ms) .timeout_ms = timeout_ms, }; - return connect_to_fd_opts(server_fd, &opts); + return connect_to_fd_opts(server_fd, 0, &opts); } int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 11eea8e2e4f1..6b7e333d266b 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -25,7 +25,6 @@ struct network_helper_opts { int timeout_ms; bool must_fail; bool noconnect; - int type; int proto; int (*post_socket_cb)(int fd, void *opts); void *cb_opts; @@ -61,7 +60,8 @@ void free_fds(int *fds, unsigned int nr_close_fds); int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len, const struct network_helper_opts *opts); int connect_to_fd(int server_fd, int timeout_ms); -int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); +int connect_to_fd_opts(int server_fd, int type, + const struct network_helper_opts *opts); int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); int fastopen_connect(int server_fd, const char *data, unsigned int data_len, int timeout_ms); diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index 67358adf5db3..175ced753a52 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -49,7 +49,7 @@ static bool start_test(char *addr_str, goto err; /* connect to server */ - *cli_fd = connect_to_fd_opts(*srv_fd, cli_opts); + *cli_fd = connect_to_fd_opts(*srv_fd, 0, cli_opts); if (!ASSERT_NEQ(*cli_fd, -1, "connect_to_fd_opts")) goto err; diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c index addf720428f7..1292ced67616 100644 --- a/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c @@ -32,7 +32,7 @@ static int run_test(int cgroup_fd, int server_fd, bool classid) goto out; } - fd = connect_to_fd_opts(server_fd, &opts); + fd = connect_to_fd_opts(server_fd, 0, &opts); if (fd < 0) err = -1; else @@ -52,7 +52,7 @@ void test_cgroup_v1v2(void) server_fd = start_server(AF_INET, SOCK_STREAM, NULL, port, 0); if (!ASSERT_GE(server_fd, 0, "server_fd")) return; - client_fd = connect_to_fd_opts(server_fd, &opts); + client_fd = connect_to_fd_opts(server_fd, 0, &opts); if (!ASSERT_GE(client_fd, 0, "client_fd")) { close(server_fd); return; diff --git a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c index 284764e7179f..e46fc3ec0a40 100644 --- a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c +++ b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c @@ -164,7 +164,6 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) }; struct network_helper_opts tx_ops = { .timeout_ms = 1000, - .type = SOCK_RAW, .proto = IPPROTO_RAW, .noconnect = true, }; @@ -201,7 +200,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS0); if (!ASSERT_OK_PTR(nstoken, "setns ns0")) goto out; - client_tx_fd = connect_to_fd_opts(srv_fd, &tx_ops); + client_tx_fd = connect_to_fd_opts(srv_fd, SOCK_RAW, &tx_ops); close_netns(nstoken); if (!ASSERT_GE(client_tx_fd, 0, "connect_to_fd_opts")) goto out; @@ -210,7 +209,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS0); if (!ASSERT_OK_PTR(nstoken, "setns ns0")) goto out; - client_rx_fd = connect_to_fd_opts(srv_fd, &rx_opts); + client_rx_fd = connect_to_fd_opts(srv_fd, 0, &rx_opts); close_netns(nstoken); if (!ASSERT_GE(client_rx_fd, 0, "connect_to_fd_opts")) goto out; From patchwork Wed Jun 12 14:41:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13695130 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7BD3417DE39; Wed, 12 Jun 2024 14:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718203287; cv=none; b=hVopSYRctZRCudon0Fp3EKw1UHystcdu/FG8vACdylyWMdinTzzX4rBNZzR+/8u91GpyHflc9mhlAZwyc45lzcZfNynAKiXRRrQCXVzVX2cRPyIz3u2oI5UXWTBY8M//UGdYdmsn1CiaTx0qRBX6bksb/VqDXDlFQtZhPgblfdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718203287; c=relaxed/simple; bh=mLbZtJt5FvZqk6vpvI8dwKyF0qLGlC/FKOoK0PJI6AA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=czisg0a0/m32bS9R9IhI6sO4L4CrzLEKkA4TLSstxAHa0w2dhbcT9VZktvrOBfXjXdaDrBgIyDE7ZYuYQtBjEpkkZ13/QHFvuS7xejFa4cVBYOL0r6mmxwlYT+kiqsa0M23aYxJ5S+aYI9WERhVeoQnUV5Yf7CfbnzcZAW7d8H0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hRp158UH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hRp158UH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A07D6C116B1; Wed, 12 Jun 2024 14:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718203286; bh=mLbZtJt5FvZqk6vpvI8dwKyF0qLGlC/FKOoK0PJI6AA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hRp158UHNl759dXivCzTOI56zlJaPM9rX4JY4V2XrzzbL3gWigDbwAtHGopTraKfM vYeodHitVYbj56cDtYawyPTxgKHxALtBUKKVBgw1kOwzqfqlNP7igfDj7kSZ50yzPn fuxiR6dTxFdqpqgwXXPqsPqVVv2xTxcaopBpsHRgQRh23SaJk4PdrW4y3CUiIV41mQ 0JySJjTbDW+1IylqzLfBqFWfkAw1Cl4Alzr30LHvYx/q2FuKPgIw+/SQsYmMV3WGrY vC5R61rvUEB7IVKUY8+1Q9yCIiKFpC6xeH0lSN9+u0XtAGWkrgAMU62mJH6z13snIY Z6hxM2vr2jifQ== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 2/4] selftests/bpf: Drop noconnect from network_helper_opts Date: Wed, 12 Jun 2024 22:41:04 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch extracts a new helper start_client() from connect_to_fd_opts() to create the client socket, but don't connect to the server. Then connect_to_fd_opts() can be implemented using start_client() and connect_fd_to_addr(). In test_bpf_ip_check_defrag_ok(), the new helper can be used to replace connect_to_fd_opts() with "noconnect" opts, and the strcut member "noconnect" of network_helper_opts can be dropped now. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 38 ++++++++++++++++--- tools/testing/selftests/bpf/network_helpers.h | 3 +- .../bpf/prog_tests/ip_check_defrag.c | 6 +-- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 0e52105ae563..8736b564939a 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -303,8 +303,8 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add return -1; } -int connect_to_fd_opts(int server_fd, int type, - const struct network_helper_opts *opts) +int start_client(int server_fd, int type, + const struct network_helper_opts *opts) { struct sockaddr_storage addr; struct sockaddr_in *addr_in; @@ -352,9 +352,37 @@ int connect_to_fd_opts(int server_fd, int type, opts->post_socket_cb(fd, opts->cb_opts)) goto error_close; - if (!opts->noconnect) - if (connect_fd_to_addr(fd, &addr, addrlen, opts->must_fail)) - goto error_close; + return fd; + +error_close: + save_errno_close(fd); + return -1; +} + +int connect_to_fd_opts(int server_fd, int type, + const struct network_helper_opts *opts) +{ + struct sockaddr_storage addr; + socklen_t addrlen; + int fd; + + if (!opts) + opts = &default_opts; + + addrlen = sizeof(addr); + if (getsockname(server_fd, (struct sockaddr *)&addr, &addrlen)) { + log_err("Failed to get server addr"); + return -1; + } + + fd = start_client(server_fd, type, opts); + if (fd < 0) { + log_err("Failed to create client socket"); + return -1; + } + + if (connect_fd_to_addr(fd, &addr, addrlen, opts->must_fail)) + goto error_close; return fd; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 6b7e333d266b..bb5465ad79a9 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -24,7 +24,6 @@ typedef __u16 __sum16; struct network_helper_opts { int timeout_ms; bool must_fail; - bool noconnect; int proto; int (*post_socket_cb)(int fd, void *opts); void *cb_opts; @@ -60,6 +59,8 @@ void free_fds(int *fds, unsigned int nr_close_fds); int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len, const struct network_helper_opts *opts); int connect_to_fd(int server_fd, int timeout_ms); +int start_client(int server_fd, int type, + const struct network_helper_opts *opts); int connect_to_fd_opts(int server_fd, int type, const struct network_helper_opts *opts); int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); diff --git a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c index e46fc3ec0a40..3ec8fdf5c4f8 100644 --- a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c +++ b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c @@ -160,12 +160,10 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) { struct network_helper_opts rx_opts = { .timeout_ms = 1000, - .noconnect = true, }; struct network_helper_opts tx_ops = { .timeout_ms = 1000, .proto = IPPROTO_RAW, - .noconnect = true, }; struct sockaddr_storage caddr; struct ip_check_defrag *skel; @@ -200,7 +198,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS0); if (!ASSERT_OK_PTR(nstoken, "setns ns0")) goto out; - client_tx_fd = connect_to_fd_opts(srv_fd, SOCK_RAW, &tx_ops); + client_tx_fd = start_client(srv_fd, SOCK_RAW, &tx_ops); close_netns(nstoken); if (!ASSERT_GE(client_tx_fd, 0, "connect_to_fd_opts")) goto out; @@ -209,7 +207,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS0); if (!ASSERT_OK_PTR(nstoken, "setns ns0")) goto out; - client_rx_fd = connect_to_fd_opts(srv_fd, 0, &rx_opts); + client_rx_fd = start_client(srv_fd, 0, &rx_opts); close_netns(nstoken); if (!ASSERT_GE(client_rx_fd, 0, "connect_to_fd_opts")) goto out; From patchwork Wed Jun 12 14:41:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13695131 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0B3B017DE37; Wed, 12 Jun 2024 14:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718203292; cv=none; b=Jt9GRWcCnlDJqK3JeAzr9egfthi7KoLMJn9tLfGggx8hCgZxI092V2muxHEyMYeKZpxV03iIc77RFEvuXuvUbx9g8oQRVxdxzbpUQ1OhnWw+6bEnsp6JNRhgkJ6oRBN71aLf4j0lfSD86TXS+C3vrADnf9qaHS1N/3UF92LeVN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718203292; c=relaxed/simple; bh=QDeYipd1o0V9wiiSdEf3dBRvIuDzcvSCSFdjltKsxtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pV73BkO1lhyvet8+ou3W3GMN1ZjfoRDst9ZPjsLl+yjc4rSaTi3lLMQfMzlejUu+8Q5zRsLfq0CyX1cAIgMTGhTMBKqf4gasxbSxEdWxfi9GepTNV5jSEuaIvhbDuSnN5AJSyiAgFMrI5C1MkINbN+TUht9fOLs4+jTVsQebKj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lu7UmvED; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lu7UmvED" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5095C3277B; Wed, 12 Jun 2024 14:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718203290; bh=QDeYipd1o0V9wiiSdEf3dBRvIuDzcvSCSFdjltKsxtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lu7UmvED/y1SwgogW42zHKJGREBVJYgvhOipuuogJpeB1RzS5OojTK0A8DoO7OoMw x9oEJkb9nSasx2jau93ZECb2QgPZBWCtCPEQFATP8Kyf/P1wP7MPFmNboanAHNOWBu BCgsQHmXLCciWf78IewcLjMq/cyi5fm1HQ7ODILjFeRLhVaiPXFkr2WOb8E/sjGAVv UhRSmrBvq9ooInlW51Dj/CbIH9JTnJ4JxyNUNTWThEFmwQfCZYf7Lx/PMqdw/gfOlr 2quSqIwFJvHjcA6JSpCj0fFM8+ehFpzlkTrR9Qv0XfThfnslWjliUknZMen8jY2xr8 q6Nvj1pbqHIow== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 3/4] selftests/bpf: Use start_server_str in mptcp Date: Wed, 12 Jun 2024 22:41:05 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Since start_server_str() is added now, it can be used in mptcp.c in start_mptcp_server() instead of using helpers make_sockaddr() and start_server_addr() to simplify the code. Signed-off-by: Geliang Tang Acked-by: Eduard Zingerman --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 274d2e033e39..d2ca32fa3b21 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -89,13 +89,8 @@ static int start_mptcp_server(int family, const char *addr_str, __u16 port, .timeout_ms = timeout_ms, .proto = IPPROTO_MPTCP, }; - struct sockaddr_storage addr; - socklen_t addrlen; - if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) - return -1; - - return start_server_addr(SOCK_STREAM, &addr, addrlen, &opts); + return start_server_str(family, SOCK_STREAM, addr_str, port, &opts); } static int verify_tsk(int map_fd, int client_fd) From patchwork Wed Jun 12 14:41:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13695132 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A0E2217DE37; Wed, 12 Jun 2024 14:41:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718203295; cv=none; b=SnGPdGPrC2OwAVTa8nRAjXq1bplFIJKAp6A+o5ascdgRmTDQ6x9e0DmBNaE5HgqaiSNRR2pSIJCzc7MPlqLuAyeoo/H7JjftgCj4IfL2PnnO2pG9/lYBV9/BMVyeMjBkonrCnelu0o1o8hOmiAoMcicAkRGQ5qkbsIacQAlgnB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718203295; c=relaxed/simple; bh=ek0iCBSuhwxmBUkXZ25YiD2CARKWMEhFftoQUiEh56g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eUk6jqLtet1MGS9l8Z/ngo2HJd3onW4fPHWPiQguFedQhDtzXk5/jjHdf2oqjlJUo88wRMdqUp4VqWf3E0GoMJ6iZ7/tNOXyB+EgEuwcdCdZ0O6zVrZeGQ14B76TA3l+P+lSval5BJ9/z7McMfkR7XGn2Htb728tifaPj9N3jFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Kie7bveD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Kie7bveD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C3AEC116B1; Wed, 12 Jun 2024 14:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718203295; bh=ek0iCBSuhwxmBUkXZ25YiD2CARKWMEhFftoQUiEh56g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kie7bveDRnv40Lcijd8GCh1wrIAuYrzTZRV63nWF6bvKL1WY9nVCFRW8mO3zxqDSY Yz5zQXug6giG617m2DdH3e+AIL6dOs6/nJM5GfqdCI+u+E5b/+3Nd3h6YiGhv38RsK J9H8KPnoyjvTOfryXu+W2A7RwpLNNVyox1HL3zfi16/t3v17sMPXIKCbOqV9h2eGtn lScj+z18D9HmTkl5ex4ichiaqCpixZ3aI3RawT7qe2JVTjVCaFDH1L1SYFt9Sd3pX5 0EH7VpCB+jr4tY0kIMdiNhlBOwdGtEl5LhAQeBWXXWQrHdgvE8sh0lkQiBq+tvK16W 8QUgR0ycKpH6A== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 4/4] selftests/bpf: Use start_server_str in test_tcp_check_syncookie_user Date: Wed, 12 Jun 2024 22:41:06 +0800 Message-ID: <57bdb7b97e91adb0ea2cdd391e5257298140f236.1718202986.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Since start_server_str() is added now, it can be used in script test_tcp_check_syncookie_user.c instead of start_server_addr() to simplify the code. Signed-off-by: Geliang Tang Acked-by: Eduard Zingerman --- .../bpf/test_tcp_check_syncookie_user.c | 29 ++----------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c index aebc58c24dc5..3844f9b8232a 100644 --- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c @@ -156,10 +156,6 @@ static int v6only_false(int fd, void *opts) int main(int argc, char **argv) { struct network_helper_opts opts = { 0 }; - struct sockaddr_in addr4; - struct sockaddr_in6 addr6; - struct sockaddr_in addr4dual; - struct sockaddr_in6 addr6dual; int server = -1; int server_v6 = -1; int server_dual = -1; @@ -181,36 +177,17 @@ int main(int argc, char **argv) goto err; } - memset(&addr4, 0, sizeof(addr4)); - addr4.sin_family = AF_INET; - addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - addr4.sin_port = 0; - memcpy(&addr4dual, &addr4, sizeof(addr4dual)); - - memset(&addr6, 0, sizeof(addr6)); - addr6.sin6_family = AF_INET6; - addr6.sin6_addr = in6addr_loopback; - addr6.sin6_port = 0; - - memset(&addr6dual, 0, sizeof(addr6dual)); - addr6dual.sin6_family = AF_INET6; - addr6dual.sin6_addr = in6addr_any; - addr6dual.sin6_port = 0; - - server = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr4, - sizeof(addr4), NULL); + server = start_server_str(AF_INET, SOCK_STREAM, "127.0.0.1", 0, NULL); if (server == -1) goto err; opts.post_socket_cb = v6only_true; - server_v6 = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr6, - sizeof(addr6), &opts); + server_v6 = start_server_str(AF_INET6, SOCK_STREAM, "::1", 0, &opts); if (server_v6 == -1) goto err; opts.post_socket_cb = v6only_false; - server_dual = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr6dual, - sizeof(addr6dual), &opts); + server_dual = start_server_str(AF_INET6, SOCK_STREAM, "::0", 0, &opts); if (server_dual == -1) goto err;