From patchwork Fri Jun 21 10:35:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13707254 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 1B40E171676; Fri, 21 Jun 2024 10:35:53 +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=1718966154; cv=none; b=q1LjnG7vVDP7ec3xYC/7xmmE0JrOYudw4SQQA0X8CpOv87hvPynNBMCG35kIiGF3j15T0HDjbBaIaUebMFIxELTTNqdaXMcwc85eHSTuOqMYrAMEJwetdAzDqAnMOeUN6ghcpC9StpfcKr9qLBlHPl0CGT6U6tAic7weWGxwCEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718966154; c=relaxed/simple; bh=7CMKoJFRAWlWFOBTWpSXqbxq7VKgG6yr7QvPcXK6Enk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PLi4aFrtQ1ceIjEStj8jlzc1j+M90pEBXEBMfrzvNMsCLviHL6vYL2xUT/CD5xIvwVt9cQyPTMIfKLqIluCdE0uk4+c7CppDsYk0I+DbBQVIX9UjnxeKbLT6XHt3cHNY8/+FKGL2aPLTItN8gsqX+0PT4vNFrE53LewWEoFmz0o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T4aLu2ZV; 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="T4aLu2ZV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B95CC4AF0A; Fri, 21 Jun 2024 10:35:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718966153; bh=7CMKoJFRAWlWFOBTWpSXqbxq7VKgG6yr7QvPcXK6Enk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T4aLu2ZVqsdbqYYhFcgNUrrF3a6I+w/d6vtFjYTvBs7SSd5s1kE0XV4AMHBiCAmqW MR+f1uHGpro5cViBopAy+nf81Ivjja7SX5s05CDi1lkj4cnR9j9YRqTt7CzoKx0NWX 8y3lo1QO7LNz3rGZfIm0+C1GY3IwGujglQCdv6bAOx5q0rUp8d8x+LJnUzXt9st+y/ Rg/4X/sEND55D59BS1LPL8EgCuuiWDy2lOylpAjdFUMaxmi2iv8RJFYId51EYfCKgM n1AwNHMRmvAl5uedBN4zKUogux2Jf8WfhJLepqeKhW/r9CQ91ADp8oQJXpaaE9bJYQ uC1OjsBmkUmIw== 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/6] selftests/bpf: Use connect_to_fd in sockmap_ktls Date: Fri, 21 Jun 2024 18:35:25 +0800 Message-ID: <86e6562a9bad3c44ce80c1c38ff27940f177651f.1718965270.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. Signed-off-by: Geliang Tang Acked-by: Eduard Zingerman --- .../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 9cc881b38669..68867028c432 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -21,26 +21,16 @@ 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 sockaddr_storage addr = {0}; - socklen_t len = sizeof(addr); int err, cli, srv, zero = 0; srv = start_server(family, SOCK_STREAM, NULL, 0, 0); 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;