From patchwork Tue Jun 25 05:42:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13710644 X-Patchwork-Delegate: bpf@iogearbox.net 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 72F042D600; Tue, 25 Jun 2024 05:42:54 +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=1719294174; cv=none; b=pcdK+/FA3YqsZTwlUyA2v9d4CChnw6qYqn+Bn+S26VIaZNeIBOnAFD2mBWzPOGk9r2fNrTHxAiQJnmRrNQdw5seMhBEHuT+aPAPB8WZVDLFZzzFydmIAJ8pIoIi7HCAlwa4WQGz/wddURu6YULiFoF4wcMYhXY7ufjJ1eYzAutE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719294174; c=relaxed/simple; bh=6J3QFqYCAkOLhnKytwHZMLodd5u01jabVIARSdmS/Qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Epm2BVRDmimjdkfEtUWIEUgiECd5JWrxIhpzLAvhGjLTQoUKGrVFhb/XFwlXkaEuvFofR1nG4uYmEGqMM1mZ2GZLcypJAujoS8WFkzwIeV+dfbzG0NsyYXX04QntwpdhXRnDOlYdjS12MXyuH1ogIMxEDzYqGki4KxKzpXaYQHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tl1k2khC; 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="Tl1k2khC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EB0CC4AF07; Tue, 25 Jun 2024 05:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719294174; bh=6J3QFqYCAkOLhnKytwHZMLodd5u01jabVIARSdmS/Qk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tl1k2khCCCGnSBBDNQo2Q8YJ4QuaeXqNSQbxhYSt/NufvAFbnErrNHwKc0/TYSc2Q Zy3qNTZr0VVPpNTfbxWSX6qfvSTXlFDisKp3Vyd5GApFZJwB9fJuNBePsgkLkDSLIC 9K+Tf6tESkSNYFm8ChYv2nJmh/nFQpL784NNoUGkwR1VDcvQC6Fit89P6urbOue2UK FCRGYGFK7ieHDItIrOF1RMhKdjH0Dyk27pyRCX69Ajj6ULoZxJj2iefIDC+fWuAE7R ULHuRe7YIU2j3EUmYsIBInu/WjlHu7Duysq+bnGI2QobRXp/ZSvx1+otmx5wepthmg p3raFEXER6HwQ== 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 v5 1/9] selftests/bpf: Add backlog for network_helper_opts Date: Tue, 25 Jun 2024 13:42:28 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Some callers expect __start_server() helper to pass their own "backlog" value to listen() instead of the default of 1. So this patch adds struct member "backlog" for network_helper_opts to allow callers to set "backlog" value via start_server_str() helper. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 2 +- tools/testing/selftests/bpf/network_helpers.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 44c2c8fa542a..16cbb3fdcabf 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -106,7 +106,7 @@ static int __start_server(int type, const struct sockaddr *addr, socklen_t addrl } if (type == SOCK_STREAM) { - if (listen(fd, 1) < 0) { + if (listen(fd, opts->backlog ? : 1) < 0) { log_err("Failed to listed on socket"); goto error_close; } diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 9ea36524b9db..8339c4e4b075 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -25,6 +25,7 @@ struct network_helper_opts { int timeout_ms; bool must_fail; int proto; + int backlog; int (*post_socket_cb)(int fd, void *opts); void *cb_opts; }; From patchwork Tue Jun 25 05:42:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13710645 X-Patchwork-Delegate: bpf@iogearbox.net 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 9DB3D145A1E; Tue, 25 Jun 2024 05:42:59 +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=1719294179; cv=none; b=O00Nak7O6iMlYPjDL1KfZhgtwW+dveup1d7zZKJ04SQLOiKZrJCrh3iZbWjnDWOnVdOtuHYNbU2cw6BRh2I7naUSr9r+6WhUYQw6evE5eid3KMGGcHLv5poBm0bLUoxLt5Xl2M1w/5/1LNwfmpsbqJn2vLa5hx2LFqBHppGjiqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719294179; c=relaxed/simple; bh=RPUpwnHqWv9OF1LgymXpVyycZoyJsq5oTKQuRymN69I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=poPW86ZxWiHXQ17DxAN+YasvJkTF/n/abh6FfeiViH8ufZ7UM6LYGwkWp+sZOi0qBt+dFJB/nH6j66KyGHwkuK1nvFcU/dcjCHVb515Wlr7fozagBYujjCyMA5howrQhehPKhHJqQnfmp7OOy2d/qKeFF+wEbVbAi6GUgrxDRfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FppMrEEl; 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="FppMrEEl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA30FC4AF0A; Tue, 25 Jun 2024 05:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719294179; bh=RPUpwnHqWv9OF1LgymXpVyycZoyJsq5oTKQuRymN69I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FppMrEElFJXBqWoo3/g9otLOKFdXIhSrrs3U+24R//5mO3iTR26+zOYUZsDF6GcPt iA/71p4oV4hesImPZwAExOREf27VPX8CN9J4HA3ejZpj+tQEPbQf/Qtmt5l7NWBj5l KLSWs69ErWW9iVQ9U80N0BNMY4rK1BnjI+bFOv5mFEcpAST4ajfI1UosjiEFnrV72T dwxN+UeojrDpq0a73XiYFhAgdcJkU9DGZ9NWM5G1S6m9948MO0XUAkbK1hmbjT7bzF 1hcDyNOeKyWDZfJm2FDdgdJ94c7r1gUKnDq47zIpxQ6aHRDU5xlCTCLGegKqVEOrqr 9v/63BuM+mQ+Q== 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 v5 2/9] selftests/bpf: Use start_server_str in sockmap_ktls Date: Tue, 25 Jun 2024 13:42:29 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Include network_helpers.h in prog_tests/sockmap_ktls.c, use public network helper start_server_str() instead of local defined function tcp_server(). This can avoid duplicate code. Technically, this is not a one-for-one replacement, as start_server_str() also does bind(). But the difference does not seem to matter. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index 2d0796314862..4dc7933bb556 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -6,25 +6,11 @@ #include #include "test_progs.h" +#include "network_helpers.h" #define MAX_TEST_NAME 80 #define TCP_ULP 31 -static int tcp_server(int family) -{ - int err, s; - - s = socket(family, SOCK_STREAM, 0); - if (!ASSERT_GE(s, 0, "socket")) - return -1; - - err = listen(s, SOMAXCONN); - if (!ASSERT_OK(err, "listen")) - return -1; - - return s; -} - static int disconnect(int fd) { struct sockaddr unspec = { AF_UNSPEC }; @@ -35,11 +21,14 @@ static int disconnect(int fd) /* Disconnect (unhash) a kTLS socket after removing it from sockmap. */ static void test_sockmap_ktls_disconnect_after_delete(int family, int map) { + struct network_helper_opts opts = { + .backlog = SOMAXCONN, + }; struct sockaddr_storage addr = {0}; socklen_t len = sizeof(addr); int err, cli, srv, zero = 0; - srv = tcp_server(family); + srv = start_server_str(family, SOCK_STREAM, NULL, 0, &opts); if (srv == -1) return; From patchwork Tue Jun 25 05:42:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13710646 X-Patchwork-Delegate: bpf@iogearbox.net 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 5377B145A0A; Tue, 25 Jun 2024 05:43:04 +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=1719294184; cv=none; b=YpCv8ofp+TEpXV3dkJslO9jU+7cohLURnWrIl9XKRgykT2XhGOu0RuYAQ/BL6SbutPlLZ3gbZiWioOrgiGEPZNQRHlQPJDsRwTpAYKdqLz7x8m5G/MLnKRVCWSp0cmdVg2++1kuxevWy/kQba0Xk6+dKPlNDNLOVEdlTgM7rXCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719294184; c=relaxed/simple; bh=SX7vg9jAuZBrRh97twO0P4gGLK++5xW/iSIpKE0CJtE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L75L1H09uRVK03SZqb/nYDoRMWFWO1pD4OwMN5OIW4ulb7Kj5sMYniKClsUlhNgQXm0hp7GIv/9szjkMkF5WSxGqo+BNqbEAe6xeI1DnHBfETI3Uy6RkZv8I54O85BHanVX4hLLO3t2YWdl/JkMT4LlNn3uJ2EqIWIphtvO5bfc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TNvV1b8y; 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="TNvV1b8y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3C9DC32782; Tue, 25 Jun 2024 05:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719294183; bh=SX7vg9jAuZBrRh97twO0P4gGLK++5xW/iSIpKE0CJtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TNvV1b8ylcJRSZ1vZzCinE9vil/83g1b4S/chqFxr5+T3qMdplNewWAscxCJ2Ls7k zfcLcecrHNsxtKbOwrNTk18sb+sNC2O2ab2g1kcsgeDYObztmpKQpBlUYPMrNZfmV2 g+zbYH/xE6Gt78QZDpweaSRWazv2ZHge+jJV/YefCLrJ4/n0a00o4OiG054PPcqiNy W39RvWtDEDttCayvXoALB2po7xklZpvclWgD63Jr8HTjxoKKfpw5ugjivE3x5tJWCF RhXnbtsjmY2nsWIlGje8aP8cngSVyRb+AuP6MAh82wVmi1zS0ecKkRjydREL5koyCq TGAQqwD7ghCuA== 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 v5 3/9] selftests/bpf: Use connect_to_fd in sockmap_ktls Date: Tue, 25 Jun 2024 13:42:30 +0800 Message-ID: <8e07fd6509d105c4529d3fb57dc030337d57e47a.1719293738.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Use public network helper connect_to_fd() instead of open-coding it in prog_tests/sockmap_ktls.c. This can avoid duplicate code. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index 4dc7933bb556..a6b0ed633505 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -24,26 +24,16 @@ static void test_sockmap_ktls_disconnect_after_delete(int family, int map) struct network_helper_opts opts = { .backlog = SOMAXCONN, }; - struct sockaddr_storage addr = {0}; - socklen_t len = sizeof(addr); int err, cli, srv, zero = 0; srv = start_server_str(family, SOCK_STREAM, NULL, 0, &opts); if (srv == -1) return; - err = getsockname(srv, (struct sockaddr *)&addr, &len); - if (!ASSERT_OK(err, "getsockopt")) - goto close_srv; - - cli = socket(family, SOCK_STREAM, 0); - if (!ASSERT_GE(cli, 0, "socket")) + cli = connect_to_fd(srv, 0); + if (!ASSERT_GE(cli, 0, "connect_to_fd")) goto close_srv; - err = connect(cli, (struct sockaddr *)&addr, len); - if (!ASSERT_OK(err, "connect")) - goto close_cli; - err = bpf_map_update_elem(map, &zero, &cli, 0); if (!ASSERT_OK(err, "bpf_map_update_elem")) goto close_cli; From patchwork Tue Jun 25 05:42:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13710647 X-Patchwork-Delegate: bpf@iogearbox.net 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 343A9145B07; Tue, 25 Jun 2024 05:43:08 +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=1719294189; cv=none; b=XLPaey6zxbv5wRx4QUaM9uLt9hvox7obGpQuBFhxD0Sli6BKFwOGJYiEPXHTfMNe+iJV5Kn2hBLFiUmWgYhOh042H0rBKYySxkIyXtVG8Bmm0RiNU7QCSxVlRgcjcW56bMo2DW64vyk2V9iVyoTzrW3Me7JXkzrtDEVSrFikbfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719294189; c=relaxed/simple; bh=gUn5BqWp3IVfT5rD93Pb9hRJDCSQq98aPl6Spd2KWGI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QRQAqbb1uWLPnRe4htOyKwKR/5CSWjfda41fIgQNjcBpHlxdi22mCvvg3mC82wQcGfNba7v6Vu0tsxb4xRnndXvRKOcNvC3QCmousLZzGKkT0UgDOVBYUgdt1ziSg/brDc6ifu0Gz9Y2JLe8l5h4miTRmvywQNtV+Fq9mE+HuRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j8vRIstA; 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="j8vRIstA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6ADEDC4AF0B; Tue, 25 Jun 2024 05:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719294188; bh=gUn5BqWp3IVfT5rD93Pb9hRJDCSQq98aPl6Spd2KWGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j8vRIstAzifUqhM3ziONznU3MTKv+Xva1YKK8brDPGCaQaWp8gDYuttTNNnO1OvKV +T6/hxebD+OLAB4zoPE+hkIctpB+xEzmMrIUav3MHu+XnxnxRkKEOy5f01ToY949t+ MIZem/Gez110PR54TMs2H9eEoBMaVXALLhuNHyUyP1T1K3Rt3xk/IerlwKCtNaOreM fqrXuWwQj0eyLtx8FeV6/nnjZe0TzKU/Izt6BmopizC5QLPSkENrldVApf21aHEHfW IfCWbGGAoNOpyGDnv2EU3tDSBH9RVpE5SXFV5w0InNDUuJi+970davJFyOUnTh1MIc doIFRv/1VPTxQ== 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 v5 4/9] selftests/bpf: Use make_sockaddr in sockmap_ktls Date: Tue, 25 Jun 2024 13:42:31 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch uses public helper make_sockaddr() exported in network_helpers.h instead of open-coding in sockmap_ktls.c. This can avoid duplicate code. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index a6b0ed633505..34fdb1cf10f1 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -59,23 +59,11 @@ static void test_sockmap_ktls_update_fails_when_sock_has_ulp(int family, int map { struct sockaddr_storage addr = {}; socklen_t len = sizeof(addr); - struct sockaddr_in6 *v6; - struct sockaddr_in *v4; int err, s, zero = 0; - switch (family) { - case AF_INET: - v4 = (struct sockaddr_in *)&addr; - v4->sin_family = AF_INET; - break; - case AF_INET6: - v6 = (struct sockaddr_in6 *)&addr; - v6->sin6_family = AF_INET6; - break; - default: - PRINT_FAIL("unsupported socket family %d", family); + err = make_sockaddr(family, NULL, 0, &addr, &len); + if (!ASSERT_OK(err, "make_sockaddr")) return; - } s = socket(family, SOCK_STREAM, 0); if (!ASSERT_GE(s, 0, "socket")) From patchwork Tue Jun 25 05:42:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13710648 X-Patchwork-Delegate: bpf@iogearbox.net 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 A7259145A0A; Tue, 25 Jun 2024 05:43:13 +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=1719294193; cv=none; b=MzUhmFVBrFIVRl7hf+lRfe/98FZeiVOz0xAT08vyLNJqQih3fmxHzEe3a+lEuoWysSQPy6kZzjfet/UIr24xQgEl7ZpYUQLbo8jxqs41cSzl/XVHSzoaFvsyDqhKVGcAQab+iEjH31P6s6tE5voW/GgZna6I7Emzl46NkfvXQr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719294193; c=relaxed/simple; bh=JAWAcKR7zBXRC50szWd1XFpZsq7hHNsF3ZdFSJ3411U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZYdhiMewgtRf/5WoHZQzpBm89J22dJ7fZvUqp34WvkYInDcQ7wtvpEBWIT41mE2Xqc22uK60cZ7uo1ysJnXjwKlZEGj+g6/7ExD+nYtZdH20U1M7h1VKBe/vrkSFzb1yjlvRneHh4CXWhMdw6KfPKFyE/jvqXfaycqW/xE/XVu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eWbEUXJT; 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="eWbEUXJT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 547FEC4AF0A; Tue, 25 Jun 2024 05:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719294193; bh=JAWAcKR7zBXRC50szWd1XFpZsq7hHNsF3ZdFSJ3411U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eWbEUXJTFYAD2tN/88OP9qj8KsPWIoYtu2hbFPZfcGkUNiUi1yOhcDPhNIlW2hKfc ZQhPzPCsFGrjgMppKYmlCkAXU/LhM/EAfGl5uOWhwmtx4EKgNpES4367xpZj2Uu7cT wLIfHd1LpRwEWzHCSj0vECtAIQzWGNHIDkehHkhqzGtR8WdCKqVw0LXkeYnNJ5MxWi DhXRM+AYLRXAo6+yVcyQs4g3lXBrOlu783DjBE+TDCqtkAi6oZeNtBgEGlliXrnRME +Y5DhM1FjxaQ+wSUI4umovAnpbI28VFCBmJXTfb0tWAGHqvryW1S12cqbP1MCX9a3A fhq0iCiqvgacA== 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 v5 5/9] selftests/bpf: Close fd in error path in drop_on_reuseport Date: Tue, 25 Jun 2024 13:42:32 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Server 1 fd should be closed in the error path when update_lookup_map() fails. This patch fixes it by goto "close_srv1" instead of "detach" lable in that case. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 597d0467a926..de2466547efe 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -994,7 +994,7 @@ static void drop_on_reuseport(const struct test *t) err = update_lookup_map(t->sock_map, SERVER_A, server1); if (err) - goto detach; + goto close_srv1; /* second server on destination address we should never reach */ server2 = make_server(t->sotype, t->connect_to.ip, t->connect_to.port, From patchwork Tue Jun 25 05:42:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13710649 X-Patchwork-Delegate: bpf@iogearbox.net 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 9D9ED143C67; Tue, 25 Jun 2024 05:43:18 +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=1719294198; cv=none; b=gHtDlIdGdifIa8xhkC6tApwmlPW5p/rbC577i2EWTTpG0O3y/PDqJ0zbcC6+yiF0kmF4heqgBbfsD4wdmNuCWRb+gPDUZAEHSXxgwTVd3ZU0rWU4UAd9Duh2c1wJH6ugWMs0Bp+7LtNAAKP6Jq3vxIeGRQ8ykWL6m0e7GLSXVqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719294198; c=relaxed/simple; bh=BmXh2PAjRTCFTJ8N15OQguMjGuxD0TicPhk0j6l7l/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d9fNpvXfVYf0wTFYojOthXIGYEHG6IBkw7jE5uwxG5zGgFK3CcjtSdnc9QibUqijvp/8yl01yc2YE23kiUAMh6lTPMC3fyGVWfOZTi106vE9PKxGr9hgNygTNeuiTxFathepXtEgWV9WXil/87rM87ZPyJg+nLh3Eik4wUplSHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ctP2oMjL; 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="ctP2oMjL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DF97C4AF0B; Tue, 25 Jun 2024 05:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719294198; bh=BmXh2PAjRTCFTJ8N15OQguMjGuxD0TicPhk0j6l7l/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ctP2oMjLhGnba4BTpRXvJTrAr7wlDdFyXxcHRxHo1ButE3AEWUyfYduoQ9f9kwl3W 8vGXdnAL3DoNE8Mgrnuj8AZ1WQJ1c1tuwhiyQBCpg3EWCkG7yZIEtb7uysC9EqjGdE H+PyK0KjxJtzENRUp6K9l1S4If+oLcNW/Nh4wV206iAGMiOCI/Gv+vxI7v/Cth4I8z MxS/j0u75/9AmXhQeb4A/6fRrDY2A7epWbzebVkDJ1NsctUOpU6Z7CF3OpeoMiZXOQ sjni8js8fE+nYCZU96tbV53jVwKs19V7MTN0U3zjzBELxu08C9aB+F5EOzt5BoUVdW nMntJO5ms/nRA== 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 v5 6/9] selftests/bpf: Use start_server_str in sk_lookup Date: Tue, 25 Jun 2024 13:42:33 +0800 Message-ID: <244b5ac86c177f9f9c38304e07a1e3cc0d9bb92d.1719293738.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch uses public helper start_server_addr() instead of local defined function make_server() in prog_tests/sk_lookup.c to avoid duplicate code. Add a helper setsockopts() to set SOL_CUSTOM sockopt looply, set it to setsockopt pointer of struct network_helper_opts, and pass it to start_server_addr(). Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index de2466547efe..91cba3bc784d 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -77,6 +77,12 @@ struct test { bool reuseport_has_conns; /* Add a connected socket to reuseport group */ }; +struct cb_opts { + int family; + int sotype; + bool reuseport; +}; + static __u32 duration; /* for CHECK macro */ static bool is_ipv6(const char *ip) @@ -142,19 +148,14 @@ static int make_socket(int sotype, const char *ip, int port, return fd; } -static int make_server(int sotype, const char *ip, int port, - struct bpf_program *reuseport_prog) +static int setsockopts(int fd, void *opts) { - struct sockaddr_storage addr = {0}; + struct cb_opts *co = (struct cb_opts *)opts; const int one = 1; - int err, fd = -1; - - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) - return -1; + int err = 0; /* Enabled for UDPv6 sockets for IPv4-mapped IPv6 to work. */ - if (sotype == SOCK_DGRAM) { + if (co->sotype == SOCK_DGRAM) { err = setsockopt(fd, SOL_IP, IP_RECVORIGDSTADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(IP_RECVORIGDSTADDR)", "failed\n")) { @@ -163,7 +164,7 @@ static int make_server(int sotype, const char *ip, int port, } } - if (sotype == SOCK_DGRAM && addr.ss_family == AF_INET6) { + if (co->sotype == SOCK_DGRAM && co->family == AF_INET6) { err = setsockopt(fd, SOL_IPV6, IPV6_RECVORIGDSTADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(IPV6_RECVORIGDSTADDR)", "failed\n")) { @@ -172,7 +173,7 @@ static int make_server(int sotype, const char *ip, int port, } } - if (sotype == SOCK_STREAM) { + if (co->sotype == SOCK_STREAM) { err = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(SO_REUSEADDR)", "failed\n")) { @@ -181,7 +182,7 @@ static int make_server(int sotype, const char *ip, int port, } } - if (reuseport_prog) { + if (co->reuseport) { err = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)); if (CHECK(err, "setsockopt(SO_REUSEPORT)", "failed\n")) { @@ -190,19 +191,28 @@ static int make_server(int sotype, const char *ip, int port, } } - err = bind(fd, (void *)&addr, inetaddr_len(&addr)); - if (CHECK(err, "bind", "failed\n")) { - log_err("failed to bind listen socket"); - goto fail; - } +fail: + return err; +} - if (sotype == SOCK_STREAM) { - err = listen(fd, SOMAXCONN); - if (CHECK(err, "make_server", "listen")) { - log_err("failed to listen on port %d", port); - goto fail; - } - } +static int make_server(int sotype, const char *ip, int port, + struct bpf_program *reuseport_prog) +{ + struct cb_opts cb_opts = { + .family = is_ipv6(ip) ? AF_INET6 : AF_INET, + .sotype = sotype, + .reuseport = reuseport_prog, + }; + struct network_helper_opts opts = { + .backlog = SOMAXCONN, + .post_socket_cb = setsockopts, + .cb_opts = &cb_opts, + }; + int err, fd = -1; + + fd = start_server_str(cb_opts.family, sotype, ip, port, &opts); + if (CHECK(fd < 0, "start_server_addr", "failed\n")) + return -1; /* Late attach reuseport prog so we can have one init path */ if (reuseport_prog) { From patchwork Tue Jun 25 05:42: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: 13710650 X-Patchwork-Delegate: bpf@iogearbox.net 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 7B842143C67; Tue, 25 Jun 2024 05:43:23 +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=1719294203; cv=none; b=ess1mOhdn4RFaBmRtwqfrgzhjL+6zFfdvnlZyPfPnrx6zyYd6xlAZe1Zvfc9PWb5dOu3HgiMAjtBei+EjMe5Q7s40aLCE3DoqPwJV5OZoqMjBAHlkztPJunBTLH6p1Hp+MpBvXNi15mJtLZsmebzZ0DosN5C4bNEY1gKdmQkFHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719294203; c=relaxed/simple; bh=b8plJjolo+WIbJNr4M4YV5ebpljqZyRuqrQVHyzM2eA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pe3Ecofefl8vi2HeZyGBuw//9k8FAfxXrhAafPdxwpkTyhUNshGpQlzPLW16jw0ItYKcPUA3ncYYqOTHqTiDV/UAUqHotxm03ucnH5DIceRN8lDfM/djL4VpjHLz0OQoUkENs8Vi4b8q0Mnethmf1I21DGd9EHtLFBh/eXp7WGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QjqgKQcM; 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="QjqgKQcM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7269C32782; Tue, 25 Jun 2024 05:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719294203; bh=b8plJjolo+WIbJNr4M4YV5ebpljqZyRuqrQVHyzM2eA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QjqgKQcMN1Uiq0/XufJ2EBTa9SjlfakrM+YqtTQ6NbnmG2NhvDlT+QTj6P9bMU203 6MdcsRqjpmAsELjzgwuFH2n7wNVJvQvke89R9YEmjNU2AlyJMZaPAeTenBClY28wci R+v3oDLY04PdrFpw3KqD5l8aa9/8EETpRG8OIVXxY+w9dvMicV4uHAIDt/TFdqgnBp Xr3/FWBrthRGypW+/nuckZWPE5xcVmRUubSQxSAzkTI9AE7SsUZrWzo7E5/Gzq2Zfo xE1E6SrMq7EEg/gOapWCuAFZBi/0BZqNFDCqhoXy5x2FuM+aj7cDEx7vwgEphp+5C7 issMxEeQ54Jyg== 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 v5 7/9] selftests/bpf: Use connect_to_fd in sk_lookup Date: Tue, 25 Jun 2024 13:42:34 +0800 Message-ID: <546d7a0ee9fc633eb8b266e3866d14a8e172d196.1719293738.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch uses public helper connect_to_fd() exported in network_helpers.h instead of using make_socket() and connect() in prog_tests/sk_lookup.c. This can simplify the code. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/sk_lookup.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 91cba3bc784d..5a8b4ef876ef 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -874,7 +874,6 @@ static void test_redirect_lookup(struct test_sk_lookup *skel) static void drop_on_lookup(const struct test *t) { - struct sockaddr_storage dst = {}; int client_fd, server_fd, err; struct bpf_link *lookup_link; ssize_t n; @@ -888,12 +887,11 @@ static void drop_on_lookup(const struct test *t) if (server_fd < 0) goto detach; - client_fd = make_socket(t->sotype, t->connect_to.ip, - t->connect_to.port, &dst); + client_fd = connect_to_fd(server_fd, IO_TIMEOUT_SEC); if (client_fd < 0) goto close_srv; - err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = 0; if (t->sotype == SOCK_DGRAM) { err = send_byte(client_fd); if (err) @@ -988,7 +986,6 @@ static void test_drop_on_lookup(struct test_sk_lookup *skel) static void drop_on_reuseport(const struct test *t) { - struct sockaddr_storage dst = { 0 }; int client, server1, server2, err; struct bpf_link *lookup_link; ssize_t n; @@ -1012,12 +1009,11 @@ static void drop_on_reuseport(const struct test *t) if (server2 < 0) goto close_srv1; - client = make_socket(t->sotype, t->connect_to.ip, - t->connect_to.port, &dst); + client = connect_to_fd(server2, IO_TIMEOUT_SEC); if (client < 0) goto close_srv2; - err = connect(client, (void *)&dst, inetaddr_len(&dst)); + err = 0; if (t->sotype == SOCK_DGRAM) { err = send_byte(client); if (err) @@ -1164,7 +1160,7 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel, if (server_fd < 0) return; - connected_fd = make_client(sotype, EXT_IP4, EXT_PORT); + connected_fd = connect_to_fd(server_fd, IO_TIMEOUT_SEC); if (connected_fd < 0) goto out_close_server; @@ -1178,7 +1174,7 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel, goto out_close_connected; /* Try to redirect TCP SYN / UDP packet to a connected socket */ - client_fd = make_client(sotype, EXT_IP4, EXT_PORT); + client_fd = connect_to_fd(server_fd, IO_TIMEOUT_SEC); if (client_fd < 0) goto out_unlink_prog; if (sotype == SOCK_DGRAM) { From patchwork Tue Jun 25 05:42: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: 13710651 X-Patchwork-Delegate: bpf@iogearbox.net 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 B4CDE145B17; Tue, 25 Jun 2024 05:43:28 +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=1719294208; cv=none; b=EMLRA0USSyeK68G9/yW43vBdjUnylQPPXjDJqp/f+fAESQbNmmPhpe1JiUoUESQr6AC7M/SU2EQk94XmHWJpHNBxTUVbImnQLB24P0MwzZr5TGFhFK6j1DqhOO/xeII2IZdTrwXM6HfuWPAjoEyTJ5Ua/bjqvnB5QyYZLwzzwOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719294208; c=relaxed/simple; bh=PI14D7VZXKcZqKqwI2/KA1DL1Lba3ri2NiyiGdCKagk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PpwYW3qydkslVbQ+UKxPMFHSW6BL//w4IQQ6jKKCu/V+3vlB0pr5trisi3+7xvdYWh6QhIJejKDFJ8FKzReni/Z3FgbX3sA+JsV+O191GrqnrJK3DKWo5sr5sL15gqnsqzZ9FiwP3kcsSWvB4KO9lfDts029L4tJe2I17+2aYws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=meJQzTuZ; 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="meJQzTuZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2105C32782; Tue, 25 Jun 2024 05:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719294208; bh=PI14D7VZXKcZqKqwI2/KA1DL1Lba3ri2NiyiGdCKagk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=meJQzTuZ7ZEuvF10bQENIFtOjWHpm9fEmu8IPIw3UnrLRQ3VwIsTHkMJjTROuKfTQ mcFhJjDuJpSnRMqRc6vNXZvxafzqxGD0h1WfrfYl/czL8dmvywkb0LY7cjXhySFryI /XA+vauD5n3rIRpTzrK2KEvqfDjORZPBlzUjpRjC5eeGsAZ2XOse461u6k3B7eYJ9S 9lcRMHD8ZaIhPPQz2lMmYQvUMllUWjQmGP3hn0/S0YY3yksTENkyUCQ8XAf5jLtdVw ryhoSQV3j4z2cY8Ppu84cIZ9ik/uDpLN5GHav97tn4LYmscNzdr3LfQi+wM0CPFo+k NG4fFxxH3uWXg== 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 v5 8/9] selftests/bpf: Use connect_to_addr in sk_lookup Date: Tue, 25 Jun 2024 13:42:35 +0800 Message-ID: <8dd254c64f199027320cd752e5391d46ae8ea01f.1719293738.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Use public network helpers make_sockaddr() and connect_to_addr() instead of using the local defined function make_socket() and connect(). This make_socket() can be dropped latter. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 5a8b4ef876ef..5839ed25e94c 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -231,23 +231,17 @@ static int make_server(int sotype, const char *ip, int port, static int make_client(int sotype, const char *ip, int port) { + int family = is_ipv6(ip) ? AF_INET6 : AF_INET; + struct network_helper_opts opts = { + .timeout_ms = IO_TIMEOUT_SEC, + }; struct sockaddr_storage addr = {0}; - int err, fd; + socklen_t len; - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) + if (make_sockaddr(family, ip, port, &addr, &len)) return -1; - err = connect(fd, (void *)&addr, inetaddr_len(&addr)); - if (CHECK(err, "make_client", "connect")) { - log_err("failed to connect client socket"); - goto fail; - } - - return fd; -fail: - close(fd); - return -1; + return connect_to_addr(sotype, &addr, len, &opts); } static __u64 socket_cookie(int fd) From patchwork Tue Jun 25 05:42: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: 13710652 X-Patchwork-Delegate: bpf@iogearbox.net 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 773542D600; Tue, 25 Jun 2024 05:43:33 +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=1719294213; cv=none; b=OBo46Cjpxoj/uzCkKtOiHktmw0986wdc8PnB1pB+L8CfgupoXEAxOiGt/q9klwzgCvdxLipJiagHI+q7+wlhossI8XcWL1fLGle9lReAT3jZBK8PiF2VpCaXNRIUhb1IklMg1CyQcpFce9hIC401cqazfh2YWGSHkWiEK03zgGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719294213; c=relaxed/simple; bh=y0KlEu8qqg6i7bF+oF7d2hRGpi9c7oK4UZ52Kvccdo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=An2P3KNROsLwQ7Z2EAZYClE26Qx/uGB4tyVZ2bVxdvyDblFgH1AwqUyaGfAfEwQ38jURdB+QM9Jdo+VdJrHlwjqmNvnFNXfYlU1BgmT6lvv+0qe/SbYOUL3vrzYk4vAC3sapAy3gDSyEZtS45uef8CfPDXnKxLwv9AwDtZ80748= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cAWeqDXe; 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="cAWeqDXe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD21DC32789; Tue, 25 Jun 2024 05:43:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719294213; bh=y0KlEu8qqg6i7bF+oF7d2hRGpi9c7oK4UZ52Kvccdo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cAWeqDXe1opLF8aRYZnE3v9bB7oOZXn65wzDAFBSHNuyB9+20ArIexTqYJt4Iqq6Y ymCDT0BjRaq3eII6PPbMdVNDkjg9cRyRHSx35+hsWhf4cQ5jYUViFfudpFW97uYQIN 8Qy8DDIIVD4TA1YwntZ8qJVST8QfCupVfeqSg7muhgHDLkKhDbVandtsMB+MH6xtwC w2b0YGkPuGRu4enZx9mny1Vr7D7P/rvniDf7xvCvFjAcJxN2JfnbEZCSrgXtlKM2WL 0fhZ+iq5PybmzVhXxCP0D7JIdwK53XwrBrgFidD2298s9cu3N4r9NrfMeWMRoSfa59 fwy+Me1T87Q6A== 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 v5 9/9] selftests/bpf: Drop make_socket in sk_lookup Date: Tue, 25 Jun 2024 13:42:36 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Use local helper make_client() instead of using make_socket() and connect(). Then make_socket() and inetaddr_len() can be dropped now. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 45 +------------------ 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 5839ed25e94c..59feb0d5c212 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -108,46 +108,6 @@ static int attach_reuseport(int sock_fd, struct bpf_program *reuseport_prog) return 0; } -static socklen_t inetaddr_len(const struct sockaddr_storage *addr) -{ - return (addr->ss_family == AF_INET ? sizeof(struct sockaddr_in) : - addr->ss_family == AF_INET6 ? sizeof(struct sockaddr_in6) : 0); -} - -static int make_socket(int sotype, const char *ip, int port, - struct sockaddr_storage *addr) -{ - struct timeval timeo = { .tv_sec = IO_TIMEOUT_SEC }; - int err, family, fd; - - family = is_ipv6(ip) ? AF_INET6 : AF_INET; - err = make_sockaddr(family, ip, port, addr, NULL); - if (CHECK(err, "make_address", "failed\n")) - return -1; - - fd = socket(addr->ss_family, sotype, 0); - if (CHECK(fd < 0, "socket", "failed\n")) { - log_err("failed to make socket"); - return -1; - } - - err = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo)); - if (CHECK(err, "setsockopt(SO_SNDTIMEO)", "failed\n")) { - log_err("failed to set SNDTIMEO"); - close(fd); - return -1; - } - - err = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)); - if (CHECK(err, "setsockopt(SO_RCVTIMEO)", "failed\n")) { - log_err("failed to set RCVTIMEO"); - close(fd); - return -1; - } - - return fd; -} - static int setsockopts(int fd, void *opts) { struct cb_opts *co = (struct cb_opts *)opts; @@ -1217,7 +1177,6 @@ struct test_multi_prog { static void run_multi_prog_lookup(const struct test_multi_prog *t) { - struct sockaddr_storage dst = {}; int map_fd, server_fd, client_fd; struct bpf_link *link1, *link2; int prog_idx, done, err; @@ -1250,11 +1209,11 @@ static void run_multi_prog_lookup(const struct test_multi_prog *t) if (err) goto out_close_server; - client_fd = make_socket(SOCK_STREAM, EXT_IP4, EXT_PORT, &dst); + client_fd = make_client(SOCK_STREAM, EXT_IP4, EXT_PORT); if (client_fd < 0) goto out_close_server; - err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = 0; if (CHECK(err && !t->expect_errno, "connect", "unexpected error %d\n", errno)) goto out_close_client;