From patchwork Tue Jun 11 01:59:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13692735 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 E0645A945; Tue, 11 Jun 2024 02:00:02 +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=1718071203; cv=none; b=ZBOnsCq8eSi5VRx1xj1zrahzd0D/dDjIPz431wDQAWbBfc8zIDwblrR7ZooVjy/KCjQXqKRvq4BFxCFIEdC6ZlujyEGztYKlDds+g01lVtNyAxgb+JUSXlyQ5w/AkksiXS56C6Soqt8nJ2TUzO2xLPMoLTntckxFwGzvsdUXENM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718071203; c=relaxed/simple; bh=GLcqHPSIDcYyOOhUOQFgzOMdTgSerYPzPDHb2rayz3A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YD5bM3GyKY1eLw19qqoPGy0kFd1hSPSh+lSwAbc96QHLtrBeFKBaF9ofIB6/xzgXcV2Ss1ci/pj+vcr3bSZ/ys8NMxRu8YWn/LoJmM9im8rOMBSBcEhBaR6W24mM1lhpKrY4jBeZPjRPp2PO3RvVo08gP4U7cpw3qxvimNY2sEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Oc+l36f7; 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="Oc+l36f7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15900C4AF53; Tue, 11 Jun 2024 01:59:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718071202; bh=GLcqHPSIDcYyOOhUOQFgzOMdTgSerYPzPDHb2rayz3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oc+l36f7QW9YBtPUZwGJQs013KOcVUc+E9pYzKTS0+0NfeVYrVrtFUlFhuH0Nmc1w 4QKoBLzidiV3tpQiV/G0qT88reCBqi28WgbHoE55u/Jo5FuMVKyLqLEHydhtYLByt+ tLAwEcGwSYtrcGxHqQJOZ8fal8C8LwHOJ66cjow3fh++qPRzFaxXd1siqAXkteJrGq nVdzyucjPy+MusuJAu1v7Gy1c/eLFnj2Sjqt5xNNBn/EGiwe5E0KW5i5smI1p5y0Uh MmmHC4Cze4FBo7hz0lyVFfZ6K9xQsfcKUsaanWP8PIbbUZUcFVvT6eixaShbo/a86t 4tFpiXdifgLZg== 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 1/5] selftests/bpf: Drop type from network_helper_opts Date: Tue, 11 Jun 2024 09:59:34 +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 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 helper named __connect_to_fd_opts() to do this. It accepts a new "type" parameter, then opts->type can be replaced by "type" parameter in this helper. 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. Then connect_to_fd_opts can implement as a wrapper of this new helper. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 14 +++++++++----- tools/testing/selftests/bpf/network_helpers.h | 3 ++- .../selftests/bpf/prog_tests/ip_check_defrag.c | 5 ++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index e20caef06aae..902060a70e3b 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; @@ -364,6 +363,11 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) return -1; } +int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) +{ + return __connect_to_fd_opts(server_fd, 0, opts); +} + int connect_to_fd(int server_fd, int timeout_ms) { struct network_helper_opts opts = { diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 11eea8e2e4f1..9a7cbea87967 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,6 +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, int type, + const struct network_helper_opts *opts); int connect_to_fd_opts(int server_fd, 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, 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..30349c866c77 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 Tue Jun 11 01:59:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13692736 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 5C7384C81; Tue, 11 Jun 2024 02:00:12 +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=1718071212; cv=none; b=Q2QKWT7EhXaAYRLOX5ZudPShrsqtkKMeezGbmpi7CDJmZ3h5vGdomeLjuOW3C0IsnsfEZJ7hdf1/rimfE6PqsijLs5nMD0gRO27Xc05ZrC0prSZLK2n9m5+8k4FFwoJWmcFfZ5W7O/eVuhqH3gmW/O9+505lWwa2Iy+4GBOFgl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718071212; c=relaxed/simple; bh=8EV55NK1hekoJ8C1IwqaoBlUiqoKSewbiQkaMFy1IqA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m0PP1LVcQ3+zAARS3r0M5Yqz+gnBLr7wV2BO+5mgRQ1oOVQ57DFR5m62wGesuewt0pb+9XFaYr3xKB1cXtEOjFnQ6xxWoaE/Avhq7IRP88uy53ZWOu35bj2n3Hgrqq5S1g1nVnD5j0qT0s81rFarRRpbaNaLP/XoKiLGO3vg5mg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aQnPwHmT; 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="aQnPwHmT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2632AC2BBFC; Tue, 11 Jun 2024 02:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718071212; bh=8EV55NK1hekoJ8C1IwqaoBlUiqoKSewbiQkaMFy1IqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQnPwHmTbqBZ1bXmGaJM9HJemoZB1XPFaxpJbjY/JIOBwF9Z2C10MBFF1oX0l0AyP g0QhEUYnQRbtGWBOp64SeKRb9Prc8n/4l7WIa7IdNzPpmCdbyi/kigslhHyyi1zV9o AhKiJb+x0oOqCbItIGKbuSSN3QfLWvCmNdmYJfMIyfZGF5rQwDtSaNhjLy+5mA1pxg olwpSZKZIxxQlxcsYbp8cRBAfo0ObBgFJcz7jWyjRMiCJU41fmaYSkiv2/+TgEcFxt qC5XAELIhJ77Nm1UbfW3v7Z8PIUkkwem/WLobSAJVaTfTKOPtX7MqJGbafuNIfdvC6 afApph1SlLFKQ== 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 2/5] selftests/bpf: Drop noconnect from network_helper_opts Date: Tue, 11 Jun 2024 09:59:35 +0800 Message-ID: <9d2b9adc6e0892e4836c76d115658d6a41619789.1718070939.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 This patch adds another new parameter "noconnect" for __connect_to_fd_opts, then opts->noconnect can be replaced by "noconnect" parameter in it. In test_bpf_ip_check_defrag_ok(), true is passed to it. 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 | 6 +++--- tools/testing/selftests/bpf/network_helpers.h | 3 +-- tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c | 6 ++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 902060a70e3b..0f53638ae5a0 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -303,7 +303,7 @@ 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, +int __connect_to_fd_opts(int server_fd, int type, bool noconnect, const struct network_helper_opts *opts) { struct sockaddr_storage addr; @@ -352,7 +352,7 @@ 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 (!noconnect) if (connect_fd_to_addr(fd, &addr, addrlen, opts->must_fail)) goto error_close; @@ -365,7 +365,7 @@ int __connect_to_fd_opts(int server_fd, int type, int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) { - return __connect_to_fd_opts(server_fd, 0, opts); + return __connect_to_fd_opts(server_fd, 0, false, opts); } int connect_to_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 9a7cbea87967..e029d4ff983e 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,7 +59,7 @@ 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, int type, +int __connect_to_fd_opts(int server_fd, int type, bool noconnect, const struct network_helper_opts *opts); int connect_to_fd_opts(int server_fd, 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 30349c866c77..330dfba95c56 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 = __connect_to_fd_opts(srv_fd, SOCK_RAW, true, &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 = __connect_to_fd_opts(srv_fd, 0, true, &rx_opts); close_netns(nstoken); if (!ASSERT_GE(client_rx_fd, 0, "connect_to_fd_opts")) goto out; From patchwork Tue Jun 11 01:59:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13692737 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 C1AF7AD21; Tue, 11 Jun 2024 02:00:22 +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=1718071222; cv=none; b=nCTJD/IHp8JCmMfJbaRf0/iNA9R4XbZG2Tc7P0w1Fmoe7vTNCpAK1BGDt7t7y5Xzs1/BIOK0a2JaIVQnc+D5o2YlgZeWCiViOwxAWcDFiIrRJF3pn5RInsRWH7hQQxKUnJ4jPXRXV/XwceXasDntFOdXh7rMfwKSK5Z4de5mFZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718071222; c=relaxed/simple; bh=sdjlLBAsvE2W4eBhVZks7M8fUv20YbIs8/ERLLS59xg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=owA9MI8I0GAuRkxxia5ik44ZkglUTKp4IwZNlP/xBlYmoczlEKPoEE8WDxe1q0O/r7EjlsjqYt/ti9d4XflCe3Q3RyHBl0G96ompqs8pAPBY7GlZUZIEK0Od5afKI8ShsJzXHgOzxR9ZLVtyfkKI9y9moUxtO3O+wN6gywZ7lLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CdfrdtSO; 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="CdfrdtSO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB2EEC4AF5F; Tue, 11 Jun 2024 02:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718071222; bh=sdjlLBAsvE2W4eBhVZks7M8fUv20YbIs8/ERLLS59xg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CdfrdtSOagmZRRENoqnsqI8hEC1l//F0Cy0n/Mh1pzgjoR1eqLAqX/V0PHg1mfepG 94Xbibw+s/mrXhkRXc8HryAMFC/ktH92wQAOg7ybTsozmoNc5ZuP03I2QHsLEPv6Vm d5RblyuZ2dFlq/p3qkEj2p0pJDIYP6Coep8bwNYWDjeuN91vgeDvU6PXH9UagMp3Oi Tcq8ZQDJikyfHnz71ThDDJ0vUN2C7jsglaHyqMk2OJOsLk6tTP82ZD2HIvdkwXmkpV ZaYFwd8ORhP+td9CT3KbVaRzVyJnF1PI5EuaHb+fB1eZe1LBFoI2p1w01euwN9giXK TED9pBh0A8vgg== 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 3/5] selftests/bpf: Drop must_fail from network_helper_opts Date: Tue, 11 Jun 2024 09:59:36 +0800 Message-ID: <281d02d849e0f6bbf7b89f301301d0be5889107a.1718070940.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 This patch adds another new parameter "must_fail" for __connect_to_fd_opts, then opts->must_fail can be replaced by "must_fail" parameter in it. In run_test() of cgroup_v1v2, true is passed to it, while false is passed in other places. And the strcut member "must_fail" of network_helper_opts can be dropped now. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 8 ++++---- tools/testing/selftests/bpf/network_helpers.h | 3 +-- tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c | 5 +---- tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 0f53638ae5a0..1c4c783719b7 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -293,7 +293,7 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add if (settimeo(fd, opts->timeout_ms)) goto error_close; - if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail)) + if (connect_fd_to_addr(fd, addr, addrlen, false)) goto error_close; return fd; @@ -303,7 +303,7 @@ 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, bool noconnect, +int __connect_to_fd_opts(int server_fd, int type, bool noconnect, bool must_fail, const struct network_helper_opts *opts) { struct sockaddr_storage addr; @@ -353,7 +353,7 @@ int __connect_to_fd_opts(int server_fd, int type, bool noconnect, goto error_close; if (!noconnect) - if (connect_fd_to_addr(fd, &addr, addrlen, opts->must_fail)) + if (connect_fd_to_addr(fd, &addr, addrlen, must_fail)) goto error_close; return fd; @@ -365,7 +365,7 @@ int __connect_to_fd_opts(int server_fd, int type, bool noconnect, int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) { - return __connect_to_fd_opts(server_fd, 0, false, opts); + return __connect_to_fd_opts(server_fd, 0, false, false, opts); } int connect_to_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 e029d4ff983e..fefe2ed0c798 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -23,7 +23,6 @@ typedef __u16 __sum16; struct network_helper_opts { int timeout_ms; - bool must_fail; int proto; int (*post_socket_cb)(int fd, void *opts); void *cb_opts; @@ -59,7 +58,7 @@ 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, int type, bool noconnect, +int __connect_to_fd_opts(int server_fd, int type, bool noconnect, bool must_fail, const struct network_helper_opts *opts); int connect_to_fd_opts(int server_fd, 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/cgroup_v1v2.c b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c index addf720428f7..124132b435ba 100644 --- a/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c @@ -9,9 +9,6 @@ static int run_test(int cgroup_fd, int server_fd, bool classid) { - struct network_helper_opts opts = { - .must_fail = true, - }; struct connect4_dropper *skel; int fd, err = 0; @@ -32,7 +29,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, false, true, NULL); if (fd < 0) err = -1; else 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 330dfba95c56..948e1ca287a2 100644 --- a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c +++ b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c @@ -198,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, true, &tx_ops); + client_tx_fd = __connect_to_fd_opts(srv_fd, SOCK_RAW, true, false, &tx_ops); close_netns(nstoken); if (!ASSERT_GE(client_tx_fd, 0, "connect_to_fd_opts")) goto out; @@ -207,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, true, &rx_opts); + client_rx_fd = __connect_to_fd_opts(srv_fd, 0, true, false, &rx_opts); close_netns(nstoken); if (!ASSERT_GE(client_rx_fd, 0, "connect_to_fd_opts")) goto out; From patchwork Tue Jun 11 01:59:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13692738 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 37211AD21; Tue, 11 Jun 2024 02:00:29 +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=1718071230; cv=none; b=sdUrqZ9Osfmor/cHgnaGapCQz+TOM9ELASqUXLTqU9rvuYqWtVmV8HanNYRL6gxBfMSK6x3iFtul2Zwrdy/wt4SOvujoJcGfy0eQE7kQphqRPrXCwKdeNZufcRLzhFblnwb2UbaLvL+z6gkMBtJnnk7xgauABczdpkW43q3sqAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718071230; c=relaxed/simple; bh=EOuXoUhyZErUAKP/jyrB94SzTJRRLAYfeiAWVUX3QGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ee3DiIthH1LVccMYlaY6icoj/367l4Fnp2vmd8dVFR3hlYOL59Dgh1ANA0aO7CYS16bUiN62zzOTaXXMpxPxn01sY4Pn0OFCVjc9261b2/LW+eD0DKKKKzg4p4iv395/jIFbPLZuDGRI511JZ9qQEnztazfqhLhpwxCjh/q5gH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BC10WO+K; 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="BC10WO+K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09F89C2BBFC; Tue, 11 Jun 2024 02:00:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718071229; bh=EOuXoUhyZErUAKP/jyrB94SzTJRRLAYfeiAWVUX3QGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BC10WO+KtQ0Q1WUUr768cLfJ/GzaRE5db7X5iBHx0yiTgbEa8fqAsb43N+0GFwJnp Fcig0JMy6Aw1bfBjZZVeaMYGzQynGkee6fE6TXP2HVVoYuk/FHrhT5pZJNygGafEE2 olL2gO8sDWdxn8df6hfBIVHaGyVbaTTzet3XrsfOqO3nG0mwGTF7U+Pfb8eskRwcCj uqVQeNux37dikGj87vNJQbjLUe06sDYXyaUn4jTaqagbbL/IA7XolsNYckJ1HQvTnT UQd/NT0u5Dnzy0qbb8AW4s4CPqi3H69QPxktMZZ7VXnM1cpFc3LFMZQYCls27Q/IH8 ObiPNbsG2M7+A== 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 4/5] selftests/bpf: Use start_server_str in mptcp Date: Tue, 11 Jun 2024 09:59:37 +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 4472aa404da0..00f63f3f19f4 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -104,13 +104,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 Tue Jun 11 01:59:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13692739 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 D86213C00; Tue, 11 Jun 2024 02:00:36 +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=1718071236; cv=none; b=iF1wQB1o7ZxGpF2UkihcuYFyBCkr8LD61lUn0S/4MTiexyqbI4NhVhpXTkztn3Y0+Rh/T3dx6TnpVIiJYGP6eQFx/3mLdlZFkgwvuFMuaH1t+yJ8Pk3Ker4KIzD+fhVL7cHzYSo72Bh6GTWSVlaF9CwWm2wADegbPkLKNEUX9lY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718071236; c=relaxed/simple; bh=HEbzerycj4AKQiB0vafBFrk8TauCU0t7sQlhkaeae6g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pz+oz5ND6jjR+BLSsFB/lvBysifb5U9yGpgd9TGewgqdWPTO6vAayVvY9poLtQa5OugYnKaOqErIQpFd02l48YLe8CJd/eNXb0MTR3vgX1+QGsGr3+/f7th7BNGnXpRmz/opExitq4Zgk9Vgz1uvPxL61PDpOJLojTHh5/4LJ/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nqmQMO3d; 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="nqmQMO3d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E630C2BBFC; Tue, 11 Jun 2024 02:00:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718071236; bh=HEbzerycj4AKQiB0vafBFrk8TauCU0t7sQlhkaeae6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nqmQMO3dwkT/Pv7TxNB3wJBD/1aVV311glXFk8i+Y9+fY5pacVmXBwXTh5+LkscIj RVJ1pY5Gm/Hh6wq2bcufsj/Df4X0dzM5b/xMPPseUxSD0yaylW0eAiQ4ruEMTKRojh mp03XLFPFRe4wDiW8xRyVspKzMle75ZqrZkej7z9+FBD85K3sioTt8zX4Y7lMTE7QP hmX7IKjHjpvS7TjIz6OjGfrbyr5Jw4oqbUjKH44BtnLa81F598aA3K33+r193tgzQK tM3ei4NV5BF0wG05ioxD/DNBGePBv07+E0cxpRchK2hQgudml+eXP12pRBOVvXfitr 2GVNBj6h62EYA== 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 5/5] selftests/bpf: Use start_server_str in test_tcp_check_syncookie_user Date: Tue, 11 Jun 2024 09:59:38 +0800 Message-ID: <39358e8cb8b91db5587d6e5ce735d12279981732.1718070940.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;