From patchwork Tue Jul 9 09:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13727518 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 BD96E15383C; Tue, 9 Jul 2024 09:17:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720516641; cv=none; b=UY+VdPV9zs6Oz0QckSIBDkuzy1VuLU4V9i8IpcopAJtZswzmmLDXryfZsKK2bRrPjmdgHippAljSB3rtudcKhgyZPfct5Y+ZXVanla2VzC1NI+w6hu4KxYxVnsfLZ43wM1UsNCTh1SamLx4rIGDe6UFwSlnbnmjcHddcnSKxVqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720516641; c=relaxed/simple; bh=obV9apooCgZ6Dwx3T8r2jSXX7I/NFkL8m08yFMyG2Fg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jaz3jxcul+4HgUmPozLfAIwwh6ZWM4hBIxqlwy9vT/0q0Yd1/86sy+PT1NJsY/A3iqdvNtzUjIK+lP5qefEGAVcZxlZNl8WU6p9ws9g580Z54et2p2hYre1vBY5awS6/rdIyaApOx0pckzGRazLY9AvCDjF5URFpJFg9Bca7pa0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sGN5wxwc; 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="sGN5wxwc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E756CC4AF0D; Tue, 9 Jul 2024 09:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720516641; bh=obV9apooCgZ6Dwx3T8r2jSXX7I/NFkL8m08yFMyG2Fg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sGN5wxwc+IZz5jDWLTLxRFREEqlRScoL1bGIiRBHXkkZ+aK/GmlYe/k8fQjgnPbHq 5IS7aMxy3oSmZ9/UA102oVo6JCeGprJ3LD/zJJwbOAYz5n/qStfWASeRm5ccqdtZBU MBVcK3vP8eUGcNb7ACgZ+60QgX+m1wf/q353wJeXrE1TIVgRByE5ujLnU9cQkcjG7F kXcyoFI7j3ST2/kcu7CD2pIpyYw1js3u1di6IfxcM4S4iogTK7PC9akun/1rVW08QR 9/NA0rb/fzKfpNJiOEog3ZaiaW769IAiKvMsRMKJ7L2w8SUT3fKmIOfGhWOEVzrhjl naIytYAxQ9wvA== 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 v11 6/9] selftests/bpf: Use connect_fd_to_fd in sk_lookup Date: Tue, 9 Jul 2024 17:16:22 +0800 Message-ID: <7077c277cde5a1864cdc244727162fb75c8bb9c5.1720515893.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_fd_to_fd() exported in network_helpers.h instead of using getsockname() + connect() in run_lookup_prog() in prog_tests/sk_lookup.c. This can simplify the code. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 386e482be617..ad3f943cc2bd 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -633,9 +633,6 @@ static void run_lookup_prog(const struct test *t) * BPF socket lookup. */ if (t->reuseport_has_conns) { - struct sockaddr_storage addr = {}; - socklen_t len = sizeof(addr); - /* Add an extra socket to reuseport group */ reuse_conn_fd = make_server(t->sotype, t->listen_at.ip, t->listen_at.port, @@ -643,12 +640,8 @@ static void run_lookup_prog(const struct test *t) if (reuse_conn_fd < 0) goto close; - /* Connect the extra socket to itself */ - err = getsockname(reuse_conn_fd, (void *)&addr, &len); - if (CHECK(err, "getsockname", "errno %d\n", errno)) - goto close; - err = connect(reuse_conn_fd, (void *)&addr, len); - if (CHECK(err, "connect", "errno %d\n", errno)) + err = connect_fd_to_fd(reuse_conn_fd, reuse_conn_fd, 0); + if (!ASSERT_OK(err, "connect_fd_to_fd")) goto close; }