From patchwork Mon Jul 8 02:29:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 811322 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 352051FA3; Mon, 8 Jul 2024 02:30:18 +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=1720405819; cv=none; b=lVUqwm4OXGGjY8nBKQPCMpv5WHYMyNMoQXwBuGP/01vmbxV0gUzFJ7z0EXFB1Zo4JzqKvO5o/MXbz4I4HPTWX8HAW/YDIY0Qr6mbc3ltGzep5YDHAJi+/XC++pdudg5/SDptXUPh4zWnfxSX1VrHYFq1LQ/ItpUWo5MbBetO4I0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720405819; c=relaxed/simple; bh=00pdNC+8+bJCChvMSP7B2ks/Ry/OoNnOXIemGC5RruM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IfNnO/zBDkPmZty/I7NG45VKDXJebcKWeWNoGGixCZ5vwZKMVvKBwlKuySpaynMZgQWCNizYo6ZQW8MwMfB/DFxd7Pn7bMEkQsAx+BCe0c/Ew7CXLDksJL2uaBxgszo0CaGaSIxfuVh/M7/ebjfSWMTeGwHSCG85fKDbKxuNSsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U7O9D65f; 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="U7O9D65f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9643DC4AF14; Mon, 8 Jul 2024 02:30:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720405818; bh=00pdNC+8+bJCChvMSP7B2ks/Ry/OoNnOXIemGC5RruM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U7O9D65f6HmnYQhWcurwSJSsWMHQW56LEVQakloS0vjHZDJmnaBYmm0oBLxGB0mYt kBGcq8PM/TAtNWZKGRtDkEPsg/J6AXSm85OAEOQ/G6SWdh0qkFaQcwB1+Ka0nKX6o5 mwOaqh7FUor6RnOa18sFSWzgQv1hf5PL/MvUc6CuqJXXOtNHlNYF1Rtj3bAO2hLFeg HuK2TcH06817YBFoO8E+X2BpmO2Q98u4W+l4uG6CnI8GKbWuPRh8ynQP+rn9sEH57x 4Tp8Wb6FD9WPOiJErqjf35Rs+ToCRA6kWRRQdhtDigDLGCLe8Jmssh/ad9wdI8j+9O wYClT+kMQGRoQ== 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 v10 02/12] selftests/bpf: Use start_server_str in sockmap_ktls Date: Mon, 8 Jul 2024 10:29:40 +0800 Message-ID: <52e84e1325b977c971d1745f8056a1cf9b5add17.1720405046.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_str() 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 | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 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..32be112967a5 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,12 +21,15 @@ 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); - if (srv == -1) + srv = start_server_str(family, SOCK_STREAM, NULL, 0, &opts); + if (!ASSERT_GE(srv, 0, "start_server_str")) return; err = getsockname(srv, (struct sockaddr *)&addr, &len); From patchwork Mon Jul 8 02:29:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 811321 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 40183538A; Mon, 8 Jul 2024 02:30:31 +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=1720405832; cv=none; b=j3uP8wZJXbmh6vGx7Yi/x45RgWh9kqcJSib8hRO6mTA6PQn+LA+S5/KQDRW810stiBQh9wje5rfQmEdmr/SYrsRbKHbPohTA/BuZkXVCWtx/30XDIyFnabuhKT2j5fUq0CwbUPILAsPDsIINXK3t5jcNQzIK75/kYg5c9hWl4Sk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720405832; c=relaxed/simple; bh=rRP0ZiPRY0W17MVOWxZwWV5aU8LBd+K/G2ydWK7Wq+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HEpDpxrBi88j2Wbg88oE0cYeLvXdPDfj3+o2g7VAIQxhxpTjxgh8p5LJRvL0qIBBzA+YXQl+CoX7sBIkUEHEeuOI5kFl+kVph7S05SupwVrTVOdWekvnQk5HTCfXaZP90pdSDn5O4VbOCmc9AFEexQnPHrigdb8i6OYZFWClVUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f6JuFKcK; 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="f6JuFKcK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DB85C3277B; Mon, 8 Jul 2024 02:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720405831; bh=rRP0ZiPRY0W17MVOWxZwWV5aU8LBd+K/G2ydWK7Wq+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f6JuFKcKg1FWqh2nKb4KSB6piD37DM6ouwUy8vi29FPd2TrxbRwW3qYw0KeYqM2YQ N7dbiS2lFbCDaVQcY+NIHmkRXzqRHX57VswimH7UT7YarTraF/Q3t4qBDjQCF1M6IK axrFsCeKBZ11WRsuh0XjHbGmKBAtqfzHVhkWzdxUIo91CnXUhRUMX3DT0d80lfZFxD 8y08DBBgHhvrhXXYccUXzyDFSiwm47q7HSg7arwllA15gd8yxWEtgWJH/cN00UOffU Cb3zlxbAKYZUnZRa5M+Ng1BHMGG4t0ilW80wrRCcdU2XOjaYIJDhAYQauKe9h70wN4 y+yhRK044UEOA== 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 v10 04/12] selftests/bpf: Use make_sockaddr in sockmap_ktls Date: Mon, 8 Jul 2024 10:29:42 +0800 Message-ID: <8de45e7b849e086e4b91ee30c2896087f4e73a27.1720405046.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 make_sockaddr() exported in network_helpers.h instead of open-coding in sockmap_ktls.c. This can avoid duplicate code. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sockmap_ktls.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c index a794aa688ab5..3c223601e8b6 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c @@ -59,23 +59,11 @@ static void test_sockmap_ktls_update_fails_when_sock_has_ulp(int family, int map { struct sockaddr_storage addr = {}; socklen_t len = sizeof(addr); - struct sockaddr_in6 *v6; - struct sockaddr_in *v4; int err, s, zero = 0; - switch (family) { - case AF_INET: - v4 = (struct sockaddr_in *)&addr; - v4->sin_family = AF_INET; - break; - case AF_INET6: - v6 = (struct sockaddr_in6 *)&addr; - v6->sin6_family = AF_INET6; - break; - default: - PRINT_FAIL("unsupported socket family %d", family); + err = make_sockaddr(family, NULL, 0, &addr, &len); + if (!ASSERT_OK(err, "make_sockaddr")) return; - } s = socket(family, SOCK_STREAM, 0); if (!ASSERT_GE(s, 0, "socket")) From patchwork Mon Jul 8 02:29:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 811320 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 2FC77442F; Mon, 8 Jul 2024 02:30:45 +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=1720405845; cv=none; b=LUKGZ3Xt+cCNkbLMAyiO6XSW/lRmnDRCs0z8FADsprKzpcw5e9gdfnRwV6+zPwqP35o2Hx1FXXkH2xpzZX1bT2iy/Pu9RZJTLUGw/MxU8sP7eO4JapAehCfcDNxL8eKJtcSRY9MvrO4O2yWaQrQkUjr3HTQVXzuwHMEMJJYO33Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720405845; c=relaxed/simple; bh=xkEJWzojc89EojQm4GQ2qYFqMqQKzaIHgglr7UG2tq0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kkJQ0VlF7OOESqxAp9oR5tkHUFE5+jI/usIFPlCOc+gHPpavdNV/v1WgI0lORDhS28+L7CbHIOwaWpwrr5vKIyTb6yLceMMetJ/seYFyQjw3hgyrhFsO4MORM4AbHQD28Y1ZEu7vSK2x0LtHEHPxQgfHTjE+4E+jqh0DHnqPwuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a6+5UoTY; 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="a6+5UoTY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2303FC4AF07; Mon, 8 Jul 2024 02:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720405845; bh=xkEJWzojc89EojQm4GQ2qYFqMqQKzaIHgglr7UG2tq0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a6+5UoTY4TFQVSrlOH0zleLuVCmkRI11Mw+oyoxSzT6wkZEWfvG4OX6bYV0okPOMF /Vk/VaanbLfzdgBTGi2bZPaRXTKLwjteyF89UN/RcebRd5suDbYjeEC7DwzoijRcYA V17ar9DTb2tvHOCkPG7BMb8XRKN1i2B9cEl5FAoPQal2+79PBTeiiDUX0GrKWA3hZH guPhwK0yuzljiADvexDzuHWuKw97co3iG020HqTU78dL5z52ZNV8zVP2OQMlMwi5yO hDF00YXvqaigZYlWHiManqgrILE5PGXAKWgIFscN4fJ2NbfzJYcjbcppLaX4Mdr6OD s9du//vaQsAZw== 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 v10 06/12] selftests/bpf: Add expect_errno for network_helper_opts Date: Mon, 8 Jul 2024 10:29:44 +0800 Message-ID: <35ab4f6f094e3c700aa9ec20ee6d6d1a91284b5a.1720405046.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 The errno EPERM is skipped in connect_fd_to_addr() by cgroup_v1v2 tests. More generally, it makes sense to add a struct member "expect_errno" for network_helper_opts to identify the expect errno to be skipped. Correspondingly, connect_fd_to_addr() helper needs to add a new parameter "expect_errno" too to accept "opts->expect_errno" passed from the caller connect_to_addr() or connect_fd_to_fd(). With this change, only need to set "expect_errno" as EPERM in run_test() in prog_tests/cgroup_v1v2.c. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 11 +++++++---- tools/testing/selftests/bpf/network_helpers.h | 1 + tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 475a5a04e61e..062170d6be1c 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -279,7 +279,8 @@ int client_socket(int family, int type, static int connect_fd_to_addr(int fd, const struct sockaddr_storage *addr, - socklen_t addrlen, const bool must_fail) + socklen_t addrlen, const bool must_fail, + const int expect_errno) { int ret; @@ -290,7 +291,7 @@ static int connect_fd_to_addr(int fd, log_err("Unexpected success to connect to server"); return -1; } - if (errno != EPERM) { + if (errno != expect_errno) { log_err("Unexpected error from connect to server"); return -1; } @@ -318,7 +319,8 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add return -1; } - if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail)) + if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail, + opts->expect_errno)) goto error_close; return fd; @@ -386,7 +388,8 @@ int connect_fd_to_fd(int client_fd, int server_fd, return -1; } - if (connect_fd_to_addr(client_fd, &addr, len, opts->must_fail)) + if (connect_fd_to_addr(client_fd, &addr, len, opts->must_fail, + opts->expect_errno)) return -1; return 0; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index fcda6b2333ad..14d161d35248 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -24,6 +24,7 @@ typedef __u16 __sum16; struct network_helper_opts { int timeout_ms; bool must_fail; + int expect_errno; int proto; /* The backlog argument for listen(), defines the maximum length to which * the queue of pending connections for sockfd may grow. diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c index 9709c8db7275..ff477163f0ea 100644 --- a/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c @@ -11,6 +11,7 @@ static int run_test(int cgroup_fd, int server_fd, bool classid) { struct network_helper_opts opts = { .must_fail = true, + .expect_errno = EPERM, }; struct connect4_dropper *skel; int fd, err = 0; From patchwork Mon Jul 8 02:29:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 811319 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 B0B18816; Mon, 8 Jul 2024 02:30:57 +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=1720405857; cv=none; b=Y1McxEB+iV/CnM7bCphX1QlE07eFsy2aKM7SXlHGE2tTRblbA86JI1OXxE3XcrWL8LsrL3e8jYUu5atxKfePf3xIvd707zZVHpv6PdclwlU65iCDm3kTdSQ6n+naj/BqSRbNvc0lkxy5JgsTtPVSjL9L7Bgdtmtk8IzZcMwJxW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720405857; c=relaxed/simple; bh=fM+Fvp9zNJCCiGYWxrP8nEmg3zhc+E1Yb8AOlDJckXc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=prkV2wL/46J2vmBvbPKy6fY8YI/BqYjo8JfvdJE/dfzPt+ekQbJA4Z2tXf/sYR35WJkXT9hdCTeC3nQpdPyUxhAOWPgdJDse/ml5WZMnSB/2+9NKrLGzC8IpE2BeJNyMPb60DDf1EJ10o/7I4PIdcyQ0Umx9Rxlpz9mnj2iJQ3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VJR/pntR; 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="VJR/pntR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B769C4AF0C; Mon, 8 Jul 2024 02:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720405857; bh=fM+Fvp9zNJCCiGYWxrP8nEmg3zhc+E1Yb8AOlDJckXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VJR/pntRAE/jgxtlGUK7LaRkTtaiJrgbdc6l3cpoZmSMcSMaIClbePVBxajYpYMAV GRt+H6ebCIkV4bwQYIEzIFJKRBxOc5VIv5L6lCvJAsevDR0SaKgCrG+thZZPiLCnkD rOdPrHL87Ob1EZ53Ft9GLnJEeoIf7xFla+29VL7jZpdZFbDpWnrcBDX4ECjLVn89j6 KiGx26SmtlKpi6E6ni5GqtOV1XPdua2XFX8G7TA6uCdmvvzUSikJ3Q/7ojqtul2is7 inxUxh5Bkov2IRpX8rMvdLSDIv+FN9XXOq+FvwzEF17lTTSuY3lIUnSYM/P3gkP4WQ N0MGtRCxrxOvw== 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 v10 08/12] selftests/bpf: Close fd in error path in drop_on_reuseport Date: Mon, 8 Jul 2024 10:29:46 +0800 Message-ID: <285c913620e67c2e8160ec056b5332c8c19d438b.1720405046.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 In the error path when update_lookup_map() fails in drop_on_reuseport in prog_tests/sk_lookup.c, "server1", the fd of server 1, should be closed. This patch fixes this by using "goto close_srv1" lable instead of "detach" to close "server1" in this case. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 597d0467a926..de2466547efe 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -994,7 +994,7 @@ static void drop_on_reuseport(const struct test *t) err = update_lookup_map(t->sock_map, SERVER_A, server1); if (err) - goto detach; + goto close_srv1; /* second server on destination address we should never reach */ server2 = make_server(t->sotype, t->connect_to.ip, t->connect_to.port, From patchwork Mon Jul 8 02:29:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 811318 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 EAC9A803; Mon, 8 Jul 2024 02:31: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=1720405871; cv=none; b=TsRgUQKaLcaZofGlpizylTb8h1g1hJlcuvno2ODfLtiIvLCXxfqmUNLLkebes12C/EjxIQbW0oXNB2fpnmV2oFTAHbaM23JLKwHLF6fRJLT/M44B0V1A2WbDF4OXhFvT3DYfJIhCgKaXQzPo9FbdDeXalayn7/pizArF+dd6+DY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720405871; c=relaxed/simple; bh=5NfKVOskZyhSWPjqaC3bovwMwDTjbj5c/qMAAgRj5xs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YrixLij7P/3MRKGYkXosMqNcZTPUea3uTHLM2K05pV89hoALjDSPV0OPHH32F1n1A8KTNtOeRjLN6C8wDNcw+AdOUgcwCcTSCfpMJdTonuXkR0CnVRhdKFV9zqEMwJ5T8oQBCPfAAYbyc6N+ut/HJsIpo7APvCAtj6yZHaB7kms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KPHYMoiV; 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="KPHYMoiV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E06BCC4AF11; Mon, 8 Jul 2024 02:31:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720405869; bh=5NfKVOskZyhSWPjqaC3bovwMwDTjbj5c/qMAAgRj5xs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KPHYMoiVa/A+SIAB/T/YQ+aYNS4XC34VT13wbwjnYilDfrpLmaL6AAinGrYjVTNRe Sn+J9NtzqFw/es8/gIIFiTfiuGkLnmOr0DwOhvgCOakUZAlwB1y7UAz8QcuYPtIo/N yR7avA8+m1T069m3NIGJpAU/rmI1aUnwocML9xn5iwhufeUs0+TFZBlGWaO82dNdG6 6UgrEjWkID1Tv9Gu/cECj9BnMkX2fVnjlnzKn5vk6LK5dEdCtG+9Ev7Yw9VItHfNra 2YBIqGW3mEsd0fY7oy2cwIziiBUo3yoT1N0VPXwuQg2VyfTQcW2dijx7YP5oOJAZJW MGmj7yL6a2l6g== 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 v10 10/12] selftests/bpf: Use connect_fd_to_fd in sk_lookup Date: Mon, 8 Jul 2024 10:29:48 +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 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 d03ea3e64a2e..184b838a9872 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -639,9 +639,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, @@ -649,12 +646,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, NULL); + if (!ASSERT_OK(err, "connect_fd_to_fd")) goto close; } From patchwork Mon Jul 8 02:29:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 811317 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 B192F803; Mon, 8 Jul 2024 02:31:20 +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=1720405880; cv=none; b=GoRzt/D3plxcNa75lWP3/sn1r6CNk1Q1ssCfP0iAPzS4XLBYhjlHTpRRMEhe6KbdpdLvYvgOefjahHwFdNNmofpjd6XJdfA5c8xBQexLInQqA6HMLl3gVXyNzR7oT/eUEvL7yytfL4j7kHgVW9LBWd9kKtwRbC1uvwF6JvtHYrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720405880; c=relaxed/simple; bh=8fDEfzWnbO0l/KBAAoAS40/0DvLfb8+vaBAwKdnfSww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=seT4L/cInjocvbYCwSq1HsND1xdGp4G6c/56zpzl3lW8Mja9+fD75b3qbidH8Y+x1Q89aIRp4v9tV1y1RszJBN2d5h9X4TWq0txgp3sbQ7XT6h2CpRFgm7R6V4Jb+zhmzaKhriFMah5zv8elRslyv+NW5RZhiTF7pu/yvunyjHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W5r1sgS8; 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="W5r1sgS8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A85CAC3277B; Mon, 8 Jul 2024 02:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720405880; bh=8fDEfzWnbO0l/KBAAoAS40/0DvLfb8+vaBAwKdnfSww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W5r1sgS8SjbYYz6UB4jEjvga/ygylmhDmQECDO/+Fk8n3D7A8gOaqCEyMIpP6fDHH fS26F8yKQzrpkuCogjOYOt4MsfyEf17Oq7ZqKxe+78f4K82+MsdE15J1TX7GNJYu6d 0FqQ3RP7E/DFae16UVgfX2jFcThjVHLUYL5eR9Q4E4lNbRUw0KT9nrEZpPJ3zZLejZ QtQc+6Za8OzEGEMkra2M0LaZfFSToLxMvVtwz7GqHdknXxSZzsmD/1k+9KsYmUoewu TRL1KVj4KxBHFA5u8GheGUQEU9c8V4lJkwMX1LgC4g4zdqm/ZMusgF5jARfahRG4JC zMNMUN/SNJAIg== 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 v10 12/12] selftests/bpf: Drop make_socket in sk_lookup Date: Mon, 8 Jul 2024 10:29:50 +0800 Message-ID: <411ddbcb2bf875b096466f0f28472f3d5bd5dd94.1720405046.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 local helper make_client() in run_multi_prog_lookup() instead of using make_socket() + connect(). Then make_socket() and inetaddr_len() can be dropped now. make_client() returns normal "fd" instead of "-1" when connect() fails but "expect_errno" matched in it. So "err = -errno" is needed to get the real error number before checking value of "err". Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sk_lookup.c | 45 +------------------ 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 5e013e0f8136..95307ccbfc42 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -108,46 +108,6 @@ 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 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); - 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; @@ -1220,7 +1180,6 @@ 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; @@ -1253,11 +1212,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_client(SOCK_STREAM, EXT_IP4, EXT_PORT, t->expect_errno); if (client_fd < 0) goto out_close_server; - err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = -errno; if (CHECK(err && !t->expect_errno, "connect", "unexpected error %d\n", errno)) goto out_close_client;