From patchwork Sun Jun 23 01:19:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 807434 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 096AF322E; Sun, 23 Jun 2024 01:20:42 +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=1719105643; cv=none; b=mnNoHE2rtXM6Vd7r0FFZiJXHp1bLFnhJZqlXtMMTbH/Se3KuFdO0LAe7U3twZ3z29W0gWIWzzDorRN2hwY+q/yXReYyinhVkgAIQr2pm/58sGkRCI8tFnv21ficsmpfaMAti4eUcD+yjw8IvHgr/vB+Otn9vZ9s1iDN+dcMeYRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719105643; c=relaxed/simple; bh=79yDcImEqqHbx/0HXLa9+5R2nATdrKeFx/puip3C+yk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lJKwGSA/oM4P79PKFGELy/nXQo/WlyhttjJCUeNmx+6PYI3QCuexsCjF/7/5AkyYN1LljmJR7sEG7TgUTLOTH/HnbHNYAf9aY2K2hujc8zPygMB+lP0QlBsBfKltNYAxNwYhNeit9pMLEwJC9vYdFmVFa1pEdIgSKGdMZhVC0Cc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jJaKHy3v; 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="jJaKHy3v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B11ABC32789; Sun, 23 Jun 2024 01:20:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719105642; bh=79yDcImEqqHbx/0HXLa9+5R2nATdrKeFx/puip3C+yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jJaKHy3vVtuNFbr6YJ0XP6EWe2oVULrUcJGtuY3gJ0H5eMQoSoQJBCdGz0hhusE1Z Ynp7FlnG5v/UtUjRr78y5XQZuabosglWETFIVPlLfoQ0t9U1mkMuORnkkoREQNwdGB 9/n47jpdPQ87YEjYspgq3ONhUjE8SvFtMuakC2Ak6WC1cy7nYkBZbadS7zlRbYB4V+ pvX2KVz73DDtEZ+vnuB6hegA5b05WyflkCn4Q7i8vJucqtiHE8LES6Nx/ge1p5E3Vs EDjxu1QGNPSLrptdmobbvrqRxb9vzMEniBkehc9ij3oQ5fR0wUsZcOklaYlcMtrSV9 5/rkv01SPh2Lw== 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 v3 1/8] selftests/bpf: Add backlog for network_helper_opts Date: Sun, 23 Jun 2024 09:19:55 +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" network_helper_opts to allow callers to set backlog 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 Sun Jun 23 01:19:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 806944 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 64730523D; Sun, 23 Jun 2024 01:20:47 +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=1719105647; cv=none; b=OpNHTq/QUmyUwb8ZcM3PzJhIMV13ifC7xdVcItafb96N3FqC2OryjQogSmbl1kr4nYlm/FlDwdPAQhdxpgoU61oZdekXK4Uhcys0hx7tQ+4co25gue2XMdD5DHMzf3WYU+dHasnQK9szGJLA7d1cNvpJ+o++zofs+CixfSn0d7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719105647; c=relaxed/simple; bh=nQzlRXrQgRmmZWsIkuSFqZni7XOIlYWu3bajrkWsxyE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WjVAaGygwDRLDfGzKg300xPY249YdoPnhsD27rZ00QrL5wZDQjUE9YpgpbVruqTDmGajKk78ywlq0mZZBV4yFYoFtW5DhyCamUdVP+8U1kAwkZNNunALM6947rGlEiWCok+cgr/KfFHIWTCRwAwVJxFTVVCtUbuaE85dCKGZJPw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s65u/x4s; 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="s65u/x4s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F75FC4AF0A; Sun, 23 Jun 2024 01:20:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719105646; bh=nQzlRXrQgRmmZWsIkuSFqZni7XOIlYWu3bajrkWsxyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s65u/x4se1ksALdpRizG4Nw4T+GxvuBrmeYjIEf3FEBqN9nvNilh6gwLDhtpUfW6W UJU94BMR5XzNb53v6j1Sct3VhpwBks+0oQUJEOl5rBH3b6ZflFPLNXwvAyUd6XJHQF 4xntxKfztQNYxu7/xRobaPr+FQImLn8uDZcCjL6IUzAcFoiYP0K7ndqskHT/MCLSaz NV0PIKSN4YpD9Z2kaBgiDzPdWhxpgddGg48/6b+C/c42E45mQOsw6m1GcBwFVplbNN bYU2Hthez6+F7tUYcIa69chlU65qMehqlyTpESzyruYjjVYzEMjlsKbQzgfhOpUl6U +wA+OsGFjjOcA== 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 v3 2/8] selftests/bpf: Use start_server_str in sockmap_ktls Date: Sun, 23 Jun 2024 09:19:56 +0800 Message-ID: <659255db4b69badd43ab56e833b1c65607bf4f43.1719105178.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 Include network_helpers.h in prog_tests/sockmap_ktls.c, use public network helper start_server_str() instead of local defined function tcp_server(). This can avoid duplicate code. Technically, this is not a one-for-one replacement, as start_server() also does bind(). But the difference does not seem to matter. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index 2d0796314862..4dc7933bb556 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -6,25 +6,11 @@ #include #include "test_progs.h" +#include "network_helpers.h" #define MAX_TEST_NAME 80 #define TCP_ULP 31 -static int tcp_server(int family) -{ - int err, s; - - s = socket(family, SOCK_STREAM, 0); - if (!ASSERT_GE(s, 0, "socket")) - return -1; - - err = listen(s, SOMAXCONN); - if (!ASSERT_OK(err, "listen")) - return -1; - - return s; -} - static int disconnect(int fd) { struct sockaddr unspec = { AF_UNSPEC }; @@ -35,11 +21,14 @@ 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 network_helper_opts opts = { + .backlog = SOMAXCONN, + }; struct sockaddr_storage addr = {0}; socklen_t len = sizeof(addr); int err, cli, srv, zero = 0; - srv = tcp_server(family); + srv = start_server_str(family, SOCK_STREAM, NULL, 0, &opts); if (srv == -1) return; From patchwork Sun Jun 23 01:19:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 807433 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 63FA14C6C; Sun, 23 Jun 2024 01:20:51 +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=1719105651; cv=none; b=fFRpd4IGrKvOXv4yOVztwme1BcHGhbggwx0qph0PTiPz6Bb1wuOgXnP2kBykQFXrEXU/ukN8HjwkvFMciOf+1KhSkfVzyHQ8RYDYNNji049yNXea2yEyOY5EqkG5ENDuAgkRoST2e7y7ZWHER37rrOmfIgBmbKLsng6XrIQZUK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719105651; c=relaxed/simple; bh=SX7vg9jAuZBrRh97twO0P4gGLK++5xW/iSIpKE0CJtE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bkQmGsFbctT8AIyd7FdWx9j+Qy4MgMxw9RFb1cex8tVe3WKtyTyTRMspE3T3rfrSyO40VRzh7ia1Uf8DLMbe4Oq5kMNL64ayHENTUWIAJVzsAfzi3YmtpxQfEdCjX2iNQZHVwDV5C6aK+6AX6oMepK+odYNvCKzdiaHV9BZrFms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b4c3G0dk; 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="b4c3G0dk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68C25C32789; Sun, 23 Jun 2024 01:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719105651; bh=SX7vg9jAuZBrRh97twO0P4gGLK++5xW/iSIpKE0CJtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b4c3G0dkpT/WzCP7dSuxhwqHOJF2ijXDIuzVYkCtWXzw5pUaVrKVIMjRyjz1IFBCd yotPuVCleG7ULyb9sRo4Po/q5ecn9gbE9Agx5l6gipB1OyWtw7YHxm1cSVI/20NtJ6 g/pxynqu6KC6spNkoKm5yB7K6/LBRVXkQImbp9sP7AnSId22M8iWdm2Drxiy+oCoVC x7mwYVT3K4bQHxhf/ft5GHCAfccj0VBB8f6Pkau4BZkdwGG15c4SlaaDlJmZOVU4xI ysgyU9jYPCVvwflea3WZEwdfJyr7l+5adzLxr1efs08hzzD4vKoWqVgsX6+Ail0VZz WsqhMIN48VPCg== 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 v3 3/8] selftests/bpf: Use connect_to_fd in sockmap_ktls Date: Sun, 23 Jun 2024 09:19:57 +0800 Message-ID: <4357a79ef34a138816b8964b2b15165eadf5a3e1.1719105178.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 Sun Jun 23 01:19:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 806943 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 1B24663B; Sun, 23 Jun 2024 01:20:55 +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=1719105656; cv=none; b=d/G9cZFj9ZpwrjiDcZaIh/nVQ5GlE2khXordeYIZbKL6cxuie4q/81UN94QN+t0eV8xog4LPybJr49sGL0LbB07xfz7vKRBEjJspU6J1VHqaCFdDc3M2FF22uwwJoNUiPMGAkWSWR9wrDMyobWpk/MqQvkWGqs3IRVID5aNFoyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719105656; c=relaxed/simple; bh=/lxFmWi7jg1WBjAVIvKF5h+VNV6it5HMrFyR1RnRPCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nYPMlRR1hsemT1wu77Z9sK/Hb0OIZehqs14CJx9gIZZm2348hhaRCMu66cxrOT+RyiSiO9ZhPVhb4ueOQJOYPi6XcDYSqCIGhsQ2rUKzpxlk8yeOuEBsKMzZCs/CONyilqisEhc203VVQqy7PNvwXUqRoqKGb4Qqgcwn7n4W9kM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l3jpdzrG; 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="l3jpdzrG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4CDAC4AF0F; Sun, 23 Jun 2024 01:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719105655; bh=/lxFmWi7jg1WBjAVIvKF5h+VNV6it5HMrFyR1RnRPCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l3jpdzrGR5K6PnWQAoI5UKX+1yE176kfWhaj0umj37wed2ugn2IIlleSZ7Mb7VupM j/8dGJvW0/qsbN66ewvx+nSpTD3/nO6Wi77TcMiIAzq04B2fgnfQnboRZvh92Jf/Yd XedMZmIMNaOaXsVQZlJUsaHxKSffAVXacv/8yg+/q4fiSrT3qEcm0jPWmGwy00xvV9 qYdsd46vGsddPMoS5iEXB0V7A1C6K95/8qD9+m6yUpy6tRuoeJLYjFU0naIgolo3St h754/73NkPv5nsxaAFwI5vmyLDBKvsMKlRR/ZNJ2J5KFE5i8Yc6OCMOkkM1eGRs4G3 aw4hsU//Bay/Q== 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 v3 4/8] selftests/bpf: Use start_server_str in sk_lookup Date: Sun, 23 Jun 2024 09:19:58 +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 This patch uses public helper start_server_addr() in make_server() in prog_tests/sk_lookup.c to avoid duplicate code. Add a helper setsockopts() to set SOL_CUSTOM sockopt looply, set it to setsockopt pointer of struct network_helper_opts, and pass it to start_server_addr(). Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 57 +++++++++++-------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 597d0467a926..ba73b56f4484 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -77,6 +77,12 @@ struct test { bool reuseport_has_conns; /* Add a connected socket to reuseport group */ }; +struct cb_opts { + int family; + int sotype; + bool reuseport; +}; + static __u32 duration; /* for CHECK macro */ static bool is_ipv6(const char *ip) @@ -142,19 +148,14 @@ static int make_socket(int sotype, const char *ip, int port, return fd; } -static int make_server(int sotype, const char *ip, int port, - struct bpf_program *reuseport_prog) +static int setsockopts(int fd, void *opts) { - struct sockaddr_storage addr = {0}; + struct cb_opts *co = (struct cb_opts *)opts; const int one = 1; - int err, fd = -1; - - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) - return -1; + int err = 0; /* Enabled for UDPv6 sockets for IPv4-mapped IPv6 to work. */ - if (sotype == SOCK_DGRAM) { + if (co->sotype == SOCK_DGRAM) { err = setsockopt(fd, SOL_IP, IP_RECVORIGDSTADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(IP_RECVORIGDSTADDR)", "failed\n")) { @@ -163,7 +164,7 @@ static int make_server(int sotype, const char *ip, int port, } } - if (sotype == SOCK_DGRAM && addr.ss_family == AF_INET6) { + if (co->sotype == SOCK_DGRAM && co->family == AF_INET6) { err = setsockopt(fd, SOL_IPV6, IPV6_RECVORIGDSTADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(IPV6_RECVORIGDSTADDR)", "failed\n")) { @@ -172,7 +173,7 @@ static int make_server(int sotype, const char *ip, int port, } } - if (sotype == SOCK_STREAM) { + if (co->sotype == SOCK_STREAM) { err = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if (CHECK(err, "setsockopt(SO_REUSEADDR)", "failed\n")) { @@ -181,7 +182,7 @@ static int make_server(int sotype, const char *ip, int port, } } - if (reuseport_prog) { + if (co->reuseport) { err = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)); if (CHECK(err, "setsockopt(SO_REUSEPORT)", "failed\n")) { @@ -190,19 +191,27 @@ static int make_server(int sotype, const char *ip, int port, } } - err = bind(fd, (void *)&addr, inetaddr_len(&addr)); - if (CHECK(err, "bind", "failed\n")) { - log_err("failed to bind listen socket"); - goto fail; - } +fail: + return err; +} - if (sotype == SOCK_STREAM) { - err = listen(fd, SOMAXCONN); - if (CHECK(err, "make_server", "listen")) { - log_err("failed to listen on port %d", port); - goto fail; - } - } +static int make_server(int sotype, const char *ip, int port, + struct bpf_program *reuseport_prog) +{ + struct cb_opts cb_opts = { + .family = is_ipv6(ip) ? AF_INET6 : AF_INET, + .sotype = sotype, + .reuseport = reuseport_prog, + }; + struct network_helper_opts opts = { + .post_socket_cb = setsockopts, + .cb_opts = &cb_opts, + }; + int err, fd = -1; + + fd = start_server_str(cb_opts.family, sotype, ip, port, &opts); + if (CHECK(fd < 0, "start_server_addr", "failed\n")) + return -1; /* Late attach reuseport prog so we can have one init path */ if (reuseport_prog) { From patchwork Sun Jun 23 01:19:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 807432 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 8E78B653; Sun, 23 Jun 2024 01:21:00 +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=1719105660; cv=none; b=emgzhZByeDFYWWgxD3FDjA0EZeRJqIa6osSSz206BL3kbvf1QcVS1qShudrkUi7qZtIG7CabILPLYP2rs0iihKPFytIEtQQznyt9P0gMrQi+4EhqhvyIhnr7H71X1BchXy8+tCtmCZptBhUl9nngX7Kx2OJAzQTQ8x/xhct2NDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719105660; c=relaxed/simple; bh=yApkYtcs5+O+7ijpRkT0EqN+HHboLg9uvE4CSPpswQo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QlDI7AePCQlf6FpQZfW8pd9NXw4G8Urfa8CvYSeMYvtsUwHyygX+0BXUleNp8HI8x0TsyFiPRKw+G0Ds2JJcbhuaxBxqiWywW3QFlGV25gDxR8qtPd1SlRJMmEShMHDB1XBJnTn4AADDbWGGSYUqw+HQiVOTNPaf/Db4zzNHQVI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mDthJMOv; 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="mDthJMOv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52F8CC3277B; Sun, 23 Jun 2024 01:20:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719105660; bh=yApkYtcs5+O+7ijpRkT0EqN+HHboLg9uvE4CSPpswQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mDthJMOvah4qp9xNKXQj/NQqZMZBNtDIK6Z8XzHuRdK0/wq1Zihjtay+dCXUUDXkw HT455Kh3Lui4T2DbbH22Nmm5Q29tybzVpjnUP2M5auaZHzyba+igsXpG5mwpsSG73z VRDKFS1I3D/VmXdnjmPW5jfo3vTIpGBhhtOqNByEe3yx8XZO4+rZkfQMW+bct0ka3F uywPJbgZJJRTlqnT7l5he5D7wtWlnpxXeUkOkz/kglq3kFR/lcxcrX78X/JVv+tyrV ENx8OXwGeYCXBLwC+cfS0ApY6weEQjaKXpQ+bYnBbanu84Eh3ajFnTYe6B0aSKdUwo bbHui5qb/7YkA== 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 v3 5/8] selftests/bpf: Use connect_to_fd in sk_lookup Date: Sun, 23 Jun 2024 09:19:59 +0800 Message-ID: <258f597d25fe5b2f279b249deaf7c5b070569387.1719105178.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 ba73b56f4484..4a4fc22ed0d2 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -873,7 +873,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; @@ -887,12 +886,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) @@ -987,7 +985,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; @@ -1011,12 +1008,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) @@ -1163,7 +1159,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; @@ -1177,7 +1173,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 Sun Jun 23 01:20:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 806942 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 B133D10E4; Sun, 23 Jun 2024 01:21: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=1719105664; cv=none; b=txDBWhnGY8wCv6QgPa9sNsy4rsBBGHU3ivj0x3Af4LDOprpU9hjjcRMt3Mp/uRj6vDKvmtrY370Go7vc6sQIFRul8Cwkvqt/OKM6S0+zB5wgykb6qy64jcHocrUEbUJJIUA917BBRj8mUxF3ZPwWKfbBSQ9tMvdf7Z2QTWuiDFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719105664; c=relaxed/simple; bh=BjQ5/tmBwgON0M53VKil/t5eyQrCC3L1Lla7CBl+1EE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dQ6QGnLgyRCW+pJJxCz7StxIqczI7TsSmSicKSRg4XwuopbTaG7+fyrY86F/sxFVKj11qtZ2ikA9jrNONBQ2zTD7wCLmnDH8d31/O1xniYC/ZqONeAapPfxoPNjZvMkt7dpjNZ5BdBwdL3raWkzr+6889jET2BdwVKSmU8XHvw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QSD3uVsc; 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="QSD3uVsc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5104C32789; Sun, 23 Jun 2024 01:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719105664; bh=BjQ5/tmBwgON0M53VKil/t5eyQrCC3L1Lla7CBl+1EE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QSD3uVscmHLc7a1nAx6B4+0w79ro36LocEMV3LmN8pcqixPnxyn5UjiRlNFIuB4VY EpHiD18uSBLz363l2v6G1y5fu6bephSjL3sNwyFYxPUcd0XtCMcDXJ64TdokgwER7n N+FMzv7pXYfZCx2+bxZ08ue882tDBhfeDu0XOreql9o1ll2Om0gNwVSUb2xRYtPjlQ YkQlhKlZS/tqs9MDhTA9R3RhSx2oOfM6so2KiKqBp+fYVa5DstZ1GLl57X6fI4EK2O ZbyU3xm2x7N/gJrwsuaCkKd3CwLp8WsEUzch2NaMu2J3lvJE+Zpkrccj5QMa6ep03i AScf96/pfO6Ag== 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 v3 6/8] selftests/bpf: Use connect_to_addr in sk_lookup Date: Sun, 23 Jun 2024 09:20:00 +0800 Message-ID: <91551dc5eb799941438e3a4efc174e1cd7bf3033.1719105178.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 helpers make_sockaddr() and connect_to_addr() instead of using the local defined function make_socket() and connect(). This make_socket() can be dropped latter. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 4a4fc22ed0d2..ba386484f785 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -230,23 +230,17 @@ static int make_server(int sotype, const char *ip, int port, static int make_client(int sotype, const char *ip, int port) { + int family = is_ipv6(ip) ? AF_INET6 : AF_INET; + struct network_helper_opts opts = { + .timeout_ms = IO_TIMEOUT_SEC, + }; struct sockaddr_storage addr = {0}; - int err, fd; + socklen_t len; - fd = make_socket(sotype, ip, port, &addr); - if (fd < 0) + if (make_sockaddr(family, ip, port, &addr, &len)) return -1; - err = connect(fd, (void *)&addr, inetaddr_len(&addr)); - if (CHECK(err, "make_client", "connect")) { - log_err("failed to connect client socket"); - goto fail; - } - - return fd; -fail: - close(fd); - return -1; + return connect_to_addr(sotype, &addr, len, &opts); } static __u64 socket_cookie(int fd) From patchwork Sun Jun 23 01:20:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 807431 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 52B6363B; Sun, 23 Jun 2024 01:21:09 +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=1719105669; cv=none; b=cVXHppWqq6Eib5AvEZOKCeSkasA9zrepIkDIMLVRY9troO1rZ+rIV6Sul7olzqTdXPU8jnHULD7Nc+HZmDjPFIPJ1yXOxZyXGq/SKKKPmdJPbyrCqQ+paVFcGL0WE7GVGYixD2Y4TEXcXti/RTPQAdAd/u7MeX/tb7uR13cmKjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719105669; c=relaxed/simple; bh=Uv3Veawq41cRk7HDSAwkwv8rOMzc6SdcshDahoslgfI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PxPRkvMKMVVwOe7wK57vTPfQmFedpfpMz6EuerTgZfa2aPQH5Mo8UG8J14lM8hT9/CiuC9xAlRDVuwcF3G1tDAfUkKB8E4CQ48aIUdpLbB3EvbFxTnkrt3flG1rvlbVfSuJ9QQtcv08NvPyjYnxQINepNoEYzyp8tzIJTbZvtUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Daeo5J0u; 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="Daeo5J0u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2284CC32789; Sun, 23 Jun 2024 01:21:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719105669; bh=Uv3Veawq41cRk7HDSAwkwv8rOMzc6SdcshDahoslgfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Daeo5J0urXMVUmgNsk7UGJzeeq6RGu5YWOHz779XTK6KH1MdYuUyv0f0XsfVmMvif XV1BPugPctD8uqKcX8ibormb5bwlkTANOD0Fkw0qDseB4YL3Ejw+iTtWYZgxQNZ2Pd zD4rU6jfyBjcZ8nWzs88TAjbbeScU2hAF5xwApRKg+eC8lmLT89pA3ctdUzAozYrTV 5ufFjNGz5AbjV0Oc9BlvquA6Zj7iWfA7PGVCbL55PJMWe+/cnRJxyL9Dh90y2bUSSV otABEfJT9rOinodPeNOZFY+r7dybaz74OfBB0KLeQ7YMOJWY7UlpafwxgOsQt+7K6s 87HGMAOrXe8lw== 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 v3 7/8] selftests/bpf: Drop inetaddr_len in sk_lookup Date: Sun, 23 Jun 2024 09:20:01 +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 This patch adds a new parameter "len" for make_socket() to get the length of the address by make_sockaddr(), then local helper inetaddr_len() can be dropped. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/sk_lookup.c | 15 +++++---------- 1 file changed, 5 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 ba386484f785..d3821bf350a1 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -108,20 +108,14 @@ 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 sockaddr_storage *addr, socklen_t *len) { 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); + err = make_sockaddr(family, ip, port, addr, len); if (CHECK(err, "make_address", "failed\n")) return -1; @@ -1220,6 +1214,7 @@ static void run_multi_prog_lookup(const struct test_multi_prog *t) int map_fd, server_fd, client_fd; struct bpf_link *link1, *link2; int prog_idx, done, err; + socklen_t len; map_fd = bpf_map__fd(t->run_map); @@ -1249,11 +1244,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_socket(SOCK_STREAM, EXT_IP4, EXT_PORT, &dst, &len); if (client_fd < 0) goto out_close_server; - err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = connect(client_fd, (void *)&dst, len); if (CHECK(err && !t->expect_errno, "connect", "unexpected error %d\n", errno)) goto out_close_client; From patchwork Sun Jun 23 01:20:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 806941 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 806314C6C; Sun, 23 Jun 2024 01:21: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=1719105673; cv=none; b=XtD8aM5uvk4gz0SuBG5NqV8iyyTXCmdhNLW93gaH/SVIxhwyxT3VkQJApJggFCxMFyoOVCVicqrlof8+HTkiB5t/xeS2gLpx2FbU7Usm1gSOmfYdKvMqT/T7wRmNWwDyBYR5/pK/ENZG38cDej2F/iQIxrw5E2RdsLHOCreVSMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719105673; c=relaxed/simple; bh=XqLrapib1ix299gEFLaiIbgWz0vz+XnguQVLwlJx2ec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p67k8OQGHwkmx/raIdg6R4rzXLwVsREKTivoGd91oZFW3Ht1csYOx1dwFSPSquHW5T6SFU/FMUzbTTabne+l1VyMAK8Fpr9GA3gMUt5SIrpluaYS9H41ViJ8Ix/0wFFRgLfi3ECnnlXqcbuFIWEPq4Bnu/5LJ+TT7w8muMvoVbU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c7QCLyvL; 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="c7QCLyvL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 857FAC4AF0A; Sun, 23 Jun 2024 01:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719105673; bh=XqLrapib1ix299gEFLaiIbgWz0vz+XnguQVLwlJx2ec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c7QCLyvLCx/e7DCkVFYAV6HM4r/5jd5BQXQxu6dBCcizPYCr8UaCvFl3SUqAf/od8 cEmD+T3dUiw+l/Ek4jHq0bsja16+UfGJTxtS6wzivRFHFMHUpEhgKR+SGzDgC3W6y5 ZgDnGxhD55fd0UnrO2pRL1PLF4W5oC7BQhrbXv5LpuHqJmUXUHYy1AiNVfEHtWOUEn eFxcCJfV/PtAn2PlBcMnXNQO/6M+unCL7oAeqROFwwr2jkOGZGYg3i3ywd1fI7xIAU F3ducxwGpcfN1kllbAyL2Ja4Bliuid5bNvyGiit1t7GNVty35mCcaFb7SKOsn82PeZ KL82k1sGez++A== 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 v3 8/8] selftests/bpf: Drop make_socket in sk_lookup Date: Sun, 23 Jun 2024 09:20:02 +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() can be dropped now. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 40 +------------------ 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index d3821bf350a1..85e927381192 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -108,40 +108,6 @@ static int attach_reuseport(int sock_fd, struct bpf_program *reuseport_prog) return 0; } -static int make_socket(int sotype, const char *ip, int port, - struct sockaddr_storage *addr, socklen_t *len) -{ - 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, len); - 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; @@ -1210,11 +1176,9 @@ 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; - socklen_t len; map_fd = bpf_map__fd(t->run_map); @@ -1244,11 +1208,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, &len); + client_fd = make_client(SOCK_STREAM, EXT_IP4, EXT_PORT); if (client_fd < 0) goto out_close_server; - err = connect(client_fd, (void *)&dst, len); + err = 0; if (CHECK(err && !t->expect_errno, "connect", "unexpected error %d\n", errno)) goto out_close_client;