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;