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: 807400 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: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: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: 807399 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: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: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: 807398 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: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: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: 807397 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: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: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: 807396 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: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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;