From patchwork Sun May 5 11:35:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13654246 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 EF67317BD9; Sun, 5 May 2024 11:36:46 +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=1714909007; cv=none; b=P6j1E0B/lkOan56TUeMVcCIyZ202ZoNvBcC80WeoU8pgVsNMKzAsP7kBbvuitBMFFiuA2WfiOb6gC5tx5eH6qst5Q0lJLBQmGAxgxRmZ5r/POQLDdwe47mZEdXH2eIL6rk/iAODqD2xYwcvlz+VAVlEqVlT6h3/iKwb68FARBu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714909007; c=relaxed/simple; bh=zTT8utGtNMXPeE9ci+04rvk7F9kPQj3xfSI34Wl/coQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bmzqj0Ikcd7vYBbwu3b38g4sJF1gcfLMmJRPdATWm/Q0YnSQaajD00wh3lErRndXYoyGp1lOF6jEaXV9ERVLIGZhGwf9BfQ/ulI2DVxoYI+ris6NbXiAzwO/+kJ5TJI112X+b2Peg6SwGeL9U4kv+cgBtP3fb2aiqn7pFSRZ6UQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V1ku4iN8; 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="V1ku4iN8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30749C113CC; Sun, 5 May 2024 11:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714909006; bh=zTT8utGtNMXPeE9ci+04rvk7F9kPQj3xfSI34Wl/coQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V1ku4iN8bYVaRW3aWAPaN7JGF3n7eBiAB3fOq5pglOwaFmE9cjrNQaeXxvjUtfO1D f3nCsYsLRa67TCL6yiA/bGo1LV4gwdNNnazMQ8FS0ZArPzRtr4fStgqbLkBAZYS2VZ ywIsR3+kZXUfqMGx/UvoyAwJW63gpaycSFtlfk5mbSG6mtTjmCY1oRwGkiy0ghpz2G qS5DY0QIexoKbF7Dfw7yRi9Qt1DqJ04bLgfaJ5fZpDLouUPVsE9SWzsWrz/GjZf4yE PYw157DBdHgkmckyCp2hjbbZL5m6w+DfnOLWf/VRCBTBa7Ws9HMf6I7NmI1UrY8t+5 dRO/QcvocNQSQ== 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 , Jakub Sitnicki Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Geliang Tang Subject: [PATCH bpf-next 5/6] selftests/bpf: Use connect_to_fd in test_tcp_check_syncookie Date: Sun, 5 May 2024 19:35:12 +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 connect_to_fd() exported in network_helpers.h instead of the local defined function connect_to_server() in test_tcp_check_syncookie_user.c. This can avoid duplicate code. Then the arguments "addr" and "len" of run_test() become useless, drop them too. Signed-off-by: Geliang Tang --- .../bpf/test_tcp_check_syncookie_user.c | 38 +++---------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c index bf60bc267cbc..b928474f3bf9 100644 --- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c @@ -18,30 +18,6 @@ #include "cgroup_helpers.h" #include "network_helpers.h" -static int connect_to_server(const struct sockaddr *addr, socklen_t len) -{ - int fd = -1; - - fd = socket(addr->sa_family, SOCK_STREAM, 0); - if (fd == -1) { - log_err("Failed to create client socket"); - goto out; - } - - if (connect(fd, (const struct sockaddr *)addr, len) == -1) { - log_err("Fail to connect to server"); - goto close_out; - } - - goto out; - -close_out: - close(fd); - fd = -1; -out: - return fd; -} - static int get_map_fd_by_prog_id(int prog_id, bool *xdp) { struct bpf_prog_info info = {}; @@ -80,8 +56,7 @@ static int get_map_fd_by_prog_id(int prog_id, bool *xdp) return map_fd; } -static int run_test(int server_fd, int results_fd, bool xdp, - const struct sockaddr *addr, socklen_t len) +static int run_test(int server_fd, int results_fd, bool xdp) { int client = -1, srv_client = -1; int ret = 0; @@ -107,7 +82,7 @@ static int run_test(int server_fd, int results_fd, bool xdp, goto err; } - client = connect_to_server(addr, len); + client = connect_to_fd(server_fd, 0); if (client == -1) goto err; @@ -254,16 +229,13 @@ int main(int argc, char **argv) if (server_dual == -1 || !get_port(server_dual, &addr4dual.sin_port)) goto err; - if (run_test(server, results, xdp, - (const struct sockaddr *)&addr4, sizeof(addr4))) + if (run_test(server, results, xdp)) goto err; - if (run_test(server_v6, results, xdp, - (const struct sockaddr *)&addr6, sizeof(addr6))) + if (run_test(server_v6, results, xdp)) goto err; - if (run_test(server_dual, results, xdp, - (const struct sockaddr *)&addr4dual, sizeof(addr4dual))) + if (run_test(server_dual, results, xdp)) goto err; printf("ok\n");