From patchwork Sat Jun 29 01:20:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13716731 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 B60624430; Sat, 29 Jun 2024 01:20:41 +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=1719624041; cv=none; b=BN1PSgF4lvOdWiPqLXswJfrZsDCI11GZg+dQyCyfE8hDzW8TF+NdQ1QF7xRuYLliM8CT7G3trb/hlOv9hYRshLLM7D0GZgxvCC9WBgkYxjNPx3w7ClquU5sqILKIXk4pjhtXMID+TbX+VS7mzunM7n+xJ2Dww1exzCaopXNbMUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719624041; c=relaxed/simple; bh=6J3QFqYCAkOLhnKytwHZMLodd5u01jabVIARSdmS/Qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vho661UMMzMGiEx5UiDWbu0u90GeF5R6cBxKCSubGijiKgJ0ar/wBJf1/9tQmOHg0q+Mxj9UdYLZzhJNLTUERgm49joyVS02j4eCcZG6q38FSJfUe9sBxKpA1Kux+GB3aD91PjuLKHw+ylQ9Is+Wkj4N/VReAimVSxyvSFnrSnI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GLtguVNr; 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="GLtguVNr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C73B7C32789; Sat, 29 Jun 2024 01:20:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719624041; bh=6J3QFqYCAkOLhnKytwHZMLodd5u01jabVIARSdmS/Qk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GLtguVNrcSZwPGIWx52zQ9JPwjyL4lu2rXXN9ei5aDSaAGGy2PPY8Fpegc43Ly/bq Qeo6tLJILkZsCc/JVa8fVy1Sw9+o3rSW25sdcIjNIu82Uf0XHv9ZPq1RBDsAKmz4+p 3RPCCqhKZzE6kMGDutGEKibJefIB0WhM+0W7qX7kY7HcgCtBaNDNk3jGc+v2cfvyXQ GFi+Nqos4pZGwOQLNdoJjsuKCXb2cy+ynWJwAFuADnr4OGwfQa4LtPjxOjugBKXkFu My+/7vrdEBUqrQ7nqyJ3vr/IycDrGysvHBlWFswdqSPPDtky1VmP5ccLsFe8yD7vKe Gzmz0I5mruQcg== 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 v6 1/9] selftests/bpf: Add backlog for network_helper_opts Date: Sat, 29 Jun 2024 09:20:11 +0800 Message-ID: <7ee521c76e45a536da7940c19a4d8de235e63e78.1719623708.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 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" for network_helper_opts to allow callers to set "backlog" value 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 Sat Jun 29 01:20: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: 13716732 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 5BEA6A29; Sat, 29 Jun 2024 01:20: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=1719624046; cv=none; b=di4/aaDMl5dgI1C2HJ2VnnpBiLBqgV5Y26x78d537I03Hxkr8WaZmJVgdBgjjqisZMKIiYq8NeIQBY5YLgfcXTEdBCwyH7W3te89PjqjnEl/sQQcx6NFjcMKOxvs1rhBAi1WZwroXYUP1FOFRpKNlaVAtUPfeeznnHvWEisyndA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719624046; c=relaxed/simple; bh=RPUpwnHqWv9OF1LgymXpVyycZoyJsq5oTKQuRymN69I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YpFVG0ZYOJPI5xOcZXEUddiRCop8z+/h0Z/0oIsNMxPV8he9CZ7fNm3Q7OAjknj8HUyTY+givj7eAbbIQ2Idg6kyNyLT0oQ5p++QbY8r4tZvGFA51girCEy7xMmE7U27HaR22fKZsWrY3C9neVFOlBezkHSUfMYAWMciGpTPvb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aKBfP3PP; 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="aKBfP3PP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4C74C116B1; Sat, 29 Jun 2024 01:20:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719624046; bh=RPUpwnHqWv9OF1LgymXpVyycZoyJsq5oTKQuRymN69I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aKBfP3PPEyg/9f88SjeK0/qUg22/9JaMJE6rPbFi1LcXkglyV3N6KlWvgh4cj9hm6 hXEcnz2QIcl+4+OFFCF5h/BzsO+vbXyTjfLRfyq3q8SBLbTYSLQB+QMxJMhMVPN3Zi J1imli6i1VXsL7LJQQ5vVNwmKAuU/DGySoMAb6XRayCA9bWqUE0BEyZ220/F5/Je9S a3gCt3NVWftUbqWcoYEvqjznh8MYfmVYWaFqsqxQ39mngh38BRfBVdZnUomJaPiyxR NubMZsk5hbbsXhN5ExEZA/aKE+MzdiVE5NRfrEfuPvHMan5Gkld6GTgjWfEK067wE+ 5ZBP/QaL1HmtQ== 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 v6 2/9] selftests/bpf: Use start_server_str in sockmap_ktls Date: Sat, 29 Jun 2024 09:20:12 +0800 Message-ID: <549f4b0a22ee953a57ebd3d96a5a6619e881b110.1719623708.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 | 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 Sat Jun 29 01:20:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13716733 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 3B4C0184F; Sat, 29 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=1719624051; cv=none; b=naUKKrk/OxN5uV3ZXR87gnJTyXWmKhspuF+JejfcXCZAdkkIWYa3gfeyVyQL/Mc5pJYTRP9ZUFCvHdiLepMCCCAGBlAFHgPhIMm3VmfJNJoGWiLbd26WhhU94C3+8Q+hRPdGy3aozUDNw0j3TSWuAzJYiaFLxOdjO/qpJMJCNyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719624051; c=relaxed/simple; bh=SX7vg9jAuZBrRh97twO0P4gGLK++5xW/iSIpKE0CJtE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gHxo+QcamrH/s93sij3Ike7ea/pWN6hOCKHyAYiL869fgWTI8MDmMYdACLpxsTyVX8shxevrGwNpjK5H9cIvL0hT5xm7Mt+W/MR3hl5aVZXqpKCJzxcAhJxpWgXqwLk7QMrkDV46JOwjzqZWO4hYaK5o2ZAhc/Oy0+u3CSmLKqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WGSXC588; 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="WGSXC588" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9617C32786; Sat, 29 Jun 2024 01:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719624051; bh=SX7vg9jAuZBrRh97twO0P4gGLK++5xW/iSIpKE0CJtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WGSXC588rnCG9YFkFrPltWMBr63icvRQHXa3VjhC1bc/bviwhjjSGh/AspQKgfNyW 5WCIYmD4O4eazNxiZ1SC6SCJZU3vBwEbTEqxzNMwaovcuHBPMI08IlkwuyGSxtHFx+ 4QzObrDXt0Pdzu8jcwzn3HnX0pyi4XVlq+7npfg+Q7wjRIrpfMPdnf2utImhHejOPA HMk7JbJs/QX2UnDzH+2AMY13x0DgB1IJFJ0xlCgKIAneJ4nMXLrCHpNRr3KnXb92Bg 06mSyjdbTg32XS2QB//93bbLleVdsuPjjyCcPH5cCk/LQjnIA0nwnykhlNNnDTgW8j FxiWP/Dtj/Y5A== 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 v6 3/9] selftests/bpf: Use connect_to_fd in sockmap_ktls Date: Sat, 29 Jun 2024 09:20:13 +0800 Message-ID: <98ed2cd91b180e637c8011b8d035b4d8bf57abc3.1719623708.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 Sat Jun 29 01:20:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13716734 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 46B06386; Sat, 29 Jun 2024 01:20:56 +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=1719624056; cv=none; b=qKq3znG6j8rXHMDHg8U12D4P6TDWeqnRjtCl9ozIm7j5z7FuM8ldGMbdhnuvoAkd27qM9jm5g4cOsUIaMhCKdHUaoAORkccSjb2dmITzcypu63qoyGX6aN853YHYUe+px7qDtmgIMfY2U9gKcmObItKExQvNMDGa4lkid6IcX8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719624056; c=relaxed/simple; bh=gUn5BqWp3IVfT5rD93Pb9hRJDCSQq98aPl6Spd2KWGI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UEuIxVfOEaep4/40IiZYVGDtHo1drEmvcLO0D/IhF60855Fcoy6FPdL191YJDuBDz5I3obmSCZHkQYYLv4ezBGsmazYS6/+/0R8iMEtlVGqvDkKh/okh4avf9V7UsOjPvd/FLG0wkxmISZB1LgIAv6t949ZCRjvIfhQKMhYMwSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PbLjl7CV; 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="PbLjl7CV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAE63C4AF0D; Sat, 29 Jun 2024 01:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719624055; bh=gUn5BqWp3IVfT5rD93Pb9hRJDCSQq98aPl6Spd2KWGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PbLjl7CVrasfelGJKug16W3DWk3yIWSjWdo/7spupncH+PflXQ7e4mWMI8bpvGjlE NBeH8sqoKJsVO+ScGgV7e7C4Ah5mTXxnC2Ekl7PTyNnWiXdWIEGiP6ohWiim0J/oyj Q/QckR8kSYv4/szs6rCROsHkmNwLVGHQrEV39Yr1gKcYNeHRFhHyESXz4nUcdOHaLx 1NkDg8Rg7Tt50Dk24fYO6oU8Kbs3MtIgIu7kg6z3dayDu8sRIzQ9LJXhHcUVA79alg LzUD2AE8oDS/Xu8GCfieQ0z6lqRmjS7MvE43gU5OgJBP/GhglRl0oM3tbfo8XPO+71 P5PNWWH0lPklQ== 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 v6 4/9] selftests/bpf: Use make_sockaddr in sockmap_ktls Date: Sat, 29 Jun 2024 09:20:14 +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 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 a6b0ed633505..34fdb1cf10f1 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 Sat Jun 29 01:20:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13716735 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 EA39E386; Sat, 29 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=1719624061; cv=none; b=JSgpMtutvwAsyDJidg40iYyXAqYZM5tfDWgOBAo6HkWTQ29f76WLpPSTzfEozI2gddCVap437k15AW6IejNRVkqiTCFahE7EigUz4Y/uHbFdoSZeCX2YprRC2IS8K8H3RJTbidlmq5/EUa+V2eJwaq6YgVbDcDBEPWzwLvqahqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719624061; c=relaxed/simple; bh=JAWAcKR7zBXRC50szWd1XFpZsq7hHNsF3ZdFSJ3411U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cWt0E9QQ+GNuACtIPksweyi/yzvzaewBYLeanPwxJGadmaDfJP8Lf/ew5xAyA/FKsVSGAHf3kc9Y4n485+VA5lFVKSzGSjvKYbLeUYBveFRbKAz4/QVODg3BjJ/Z0iYH7pH7RMpcPk6x/3fpCIRkwhXdPZolT1F9cdaqhj/2VLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hcQAzv4n; 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="hcQAzv4n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D3B4C32786; Sat, 29 Jun 2024 01:20:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719624060; bh=JAWAcKR7zBXRC50szWd1XFpZsq7hHNsF3ZdFSJ3411U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hcQAzv4n1Oh7Qn5PN7+HGDuFWQDvkSKauCfeePpnkbWXa+fKsxJuEM9wjW1A0S/jF M96R1XQc7tZ7IVXlHOqX5Uu4Zj545HTNkWKPm1OkvfOrmjeO+HKsFBGFpl7qL0M0NY ybCEsLrPfPRz2cbykXLomp5wjDqSw9T4h/SQj+9QJ3P+RGjOth7zJnlG4k6rQJ3IKX HGPAqmE6M42R1p4zIwfxN1nKW76igg5knKAysnZK7cybem9T+CgFf1/9MNavCB16P0 tls/c2RNhBouLRfLHL/1JYs7wuWoqYQeSquWH08Drx1jKfHVd1+hvUgRbfcue4oZzU hLujwwyIwllXg== 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 v6 5/9] selftests/bpf: Close fd in error path in drop_on_reuseport Date: Sat, 29 Jun 2024 09:20:15 +0800 Message-ID: <0b2faacc0001a4d5e1f2f44816c986ebacbb5f11.1719623708.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 Server 1 fd should be closed in the error path when update_lookup_map() fails. This patch fixes it by goto "close_srv1" instead of "detach" lable in that 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 Sat Jun 29 01:20:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13716736 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 2F7B4386; Sat, 29 Jun 2024 01:21:05 +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=1719624066; cv=none; b=sUP8ln8WONtBQdayVAKDt2dshG6PU2b781BxEAASOVcg27djnu9U3dL2KOx2Hyz71OMOqjD9ullUeivGkgdV8nDLPrfzhLJ5QlMyI2kPkW+cptIfN4jaYwGyl8pDwjLfN4rb2ttVV3sNebVr2pJS+giDhErpUxfo97ZTRayVtQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719624066; c=relaxed/simple; bh=FDHK1zyb77zcqwP5MsM13u+RC93l8CDezrmOejHaRLE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uyH2uTqbY127f7zJMNgypkG2akUzgFtBcaKv//MVXTy6PWCFx3QEeUryiWPD3Tme3atXFWnR0N5Bn87U0xnhOvR6xsv+itfq/NCsvzk+hXLYiLND9Akd9u8lF/B1WdHXRympEQrM3rdZifcHgC+SvEKe6UkJhZwQfD9AYX4nSWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AspHRMpN; 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="AspHRMpN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 786C4C4AF0A; Sat, 29 Jun 2024 01:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719624065; bh=FDHK1zyb77zcqwP5MsM13u+RC93l8CDezrmOejHaRLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AspHRMpNpDmVUAit+YUwozb43tYC8urnYLzRJ6E9C2X5bbVBY6aZaW+b0NFkDhLdG FjKXPCEqLVEunyQ/Yl1j3gqkXHDsLuFfa6t216p0QAPMBQWwRnMu7xUO8aYkDpKZoc ab8dV2ARDWUJ+rBC4EndYPcNYYXWNH2kfMyQT5kXZvUbTy8SH93QYoiMr7FijwH5rd Sm96rVbBRNgupt78Pyj2As2FHmqoIPKKAIbx/pdn0CL5w79Qz5BSvAUPrVF4pYKsKz yZze4YPvluMJEx/ruetB0LPR1FUboWsvkoKr+t0s2P4dN+bDBbCa2ViasdmY8W7xMK nGmBfagLVNk6A== 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 v6 6/9] selftests/bpf: Use start_server_str in sk_lookup Date: Sat, 29 Jun 2024 09:20:16 +0800 Message-ID: <06045a7bd4014d62e762778f149efa837d66b8dc.1719623708.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 start_server_addr() instead of local defined function 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 | 58 +++++++++++-------- 1 file changed, 34 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 de2466547efe..5939be51c928 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,28 @@ 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 = { + .backlog = SOMAXCONN, + .post_socket_cb = setsockopts, + .cb_opts = &cb_opts, + }; + int err, fd; + + fd = start_server_str(cb_opts.family, sotype, ip, port, &opts); + if (!ASSERT_GT(fd, 0, "start_server_str")) + return -1; /* Late attach reuseport prog so we can have one init path */ if (reuseport_prog) { From patchwork Sat Jun 29 01:20:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13716737 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 CAC91184F; Sat, 29 Jun 2024 01:21:10 +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=1719624070; cv=none; b=gfMiztmDSciDtmtaoqLUDI9+HIIuV7oZt41rFmSwc9u3Zxgdr3N02pcJamPYvsBF+L8/O0L8+i1nV1kS87gH7BaoDV+i1mKgwWp9b35E9Hj4+TX9we/OmHlC41RHGlifCbZuEvQoC2dJtu93H2het7x+9JfhzpSm4dY22K4HKhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719624070; c=relaxed/simple; bh=ZCeE8Z/nWEd6sWEM1dJoxrwtrvc9O31RPAo+rMnD5HU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CxCMzYBCbkr6kUUhJeyII/obX7IyX1EMPVUsyYGwE1t9PEdc9fMpZlulSiG9HGOXcty7Vy+7cTTK0wS+FYQ5MSPVDVqXKDPfsinoOVs0CMi3DuTwC0zGrruolSb8unOJRzL19Jx1FXm4Ff/AjqoTUf0A+39IcpdcFr3RCnMSXM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CsMjIwNU; 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="CsMjIwNU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AECDC116B1; Sat, 29 Jun 2024 01:21:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719624070; bh=ZCeE8Z/nWEd6sWEM1dJoxrwtrvc9O31RPAo+rMnD5HU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CsMjIwNUoWtCLATMaLanZ3YcPRd+DSSHY/cNOsWWHDnIzihhXDiaCJ1tATRPtQFB9 d+RONX5HZ8U0gNpayF9GZlZfrBLeCG4sk1LLB9zosIBU0wOZo+xfrPTRvIwonS/7L5 yEw6qAh+1pdMSdFRcBuDRoUJMf397uEcYW2aOxYWzqaIdRRqOP5Jpr+6mr3N4jdKFK If7wMYqBqKRnHBiQZEWGSqdR3jJDuBxM4Rh/V0Q4qb0GiMvFEt1OEF871ja+ulMsgt IOVELM339zKRGf27Lw25LbWJ5YiwuFapt1L+g8uUnDtquftgVsBjjX87ojwnrS0Q61 5ID4CNbAqkbdQ== 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 v6 7/9] selftests/bpf: Use connect_to_fd in sk_lookup Date: Sat, 29 Jun 2024 09:20:17 +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_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 5939be51c928..38382dffe997 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -874,7 +874,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; @@ -888,12 +887,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) @@ -988,7 +986,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; @@ -1012,12 +1009,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) @@ -1164,7 +1160,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; @@ -1178,7 +1174,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 Sat Jun 29 01:20:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13716738 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 CD62A386; Sat, 29 Jun 2024 01:21:15 +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=1719624075; cv=none; b=nropUq1Sryo5dNy0qDc8G3K4t47w+3nrG6plhgMWmbf7JGIMDC9bgLA9HbPrFftHbbuqXtuDWp13N3qESCYiOaqhR+T0/WIRWQ6jo5lX0+pdu0X4a9VfcIK3bTgMZEp8U/GvY7bTf5Rw8o8cVhNu88exHfMXhpSj1MsZqmzY8c0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719624075; c=relaxed/simple; bh=waBpOVBBTtv22Hz1oPTjYfI552tMcY2GrZ7PLsZ6UaI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EQ/WiEpSj3xxDFmwRWUB4kwxf55aL5MrPBu/H67VtXu7YdHPxngkyxaZnV4cvxhIVB2/e4161AnzEBADovBVH3i5BsjJ7tHWdZKrpVoEEK3wit7GJ5v7DuJAOhUKrLxyfiNiyFMP92dBXy4MSGSCSymOxzUjJ+Ejyo4HDZ5dulg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ia8XmHlu; 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="ia8XmHlu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D5D4C32789; Sat, 29 Jun 2024 01:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719624075; bh=waBpOVBBTtv22Hz1oPTjYfI552tMcY2GrZ7PLsZ6UaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ia8XmHluV1NxM4db29o/VioK1hwZKkCKCJIG2NezIId3Uw2UrlCEIEFl+K6sc36Ku +lgz57tqyVFclt6ek48A6zXBNSJOmFjI9twwgdurudBX7T4op7x93T8YrOQ4W808qW ieoq5HjBmN3iSSZ/hEYkA/Ah59TzVop9ruAtRNv/Zr9G2suIOyxcyBuSn3lqSJ2GY0 5hhioB3nCK+eG3eRp90LYcNi3yr7bCSScijCuaay+I0LJZIjtDPTNZd+oMO9t6U4uI sXHmj339oWh3KrTFcRUaPTO3Mx9JVXe70U8F7Y18xfrsOmGrCYuC5t8SG0LbGF+Ui7 MfMNVMPbEdEDg== 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 v6 8/9] selftests/bpf: Use connect_to_addr in sk_lookup Date: Sat, 29 Jun 2024 09:20:18 +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 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 38382dffe997..005776f5964e 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -231,23 +231,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 Sat Jun 29 01:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13716739 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 B5094A29; Sat, 29 Jun 2024 01:21: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=1719624080; cv=none; b=ElcH6O9fuwHpxF9MB+BQK6o7+1jw7VWFmrbO+etywr49ghkDanqB1CfaM1QlqxtceJurr9rRpw1wusPO3zODq/Yux2PszkCJ/i8ck3+Tsxwh52HnRZfwGjeWrR6wN802Q2sbXv9jKsNOOtxJzNLGM8nakHTIhGK7BS6MKzeQdL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719624080; c=relaxed/simple; bh=ks9r+liag6rRVAFpIWvs+ysJLHoLzdm5zcgMD5xI51Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T6Uo1FVKIl+TmszKTkpn81d7KkQ9Q326n0gLG6f17ZaOfkAw/oHl3FzInOZd6+MdH2zEesE+Fhslfk0Fvxo7jkRaACYdCfaun0LwUMP0ihox8LIb/pS3TFt/qc+9ZpmdFFESjL+2VKMAzvy0c5CuyIgnP2yBIUfjeKWoBKYmq7g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VbBF9FAz; 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="VbBF9FAz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53AECC4AF0A; Sat, 29 Jun 2024 01:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719624080; bh=ks9r+liag6rRVAFpIWvs+ysJLHoLzdm5zcgMD5xI51Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VbBF9FAz9+S/9rtwPF4wf9r7OHdLLpC3dVna9kuR4RRgW6TzL9RHAbeJ6W85kDSMI Auhv05KqC++MDWce7MzDzn347BGecduAVKv0/46pGkMzMoshATV6KCTjSCIYtQj0Qh ROqmeTg+8uKw0QEkWKP2SQa+oK7tYrjWE8XLOO2dIuZcIcdoQNVhuX2gP1ucK7j+3I WOfMAVXkEQeqPLwLb/cAQ4q891JQOlsTggx+4cAThrZcSm0+9pzzeaTdUI0Wyk6U4s 6VwUfd3PvzKzF+oqQnlXi413J6YTWkvQ36+56lx4clzkO4j7hAY4O3rrKlEk5uv4FE EZVKXi0NT53/g== 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 v6 9/9] selftests/bpf: Drop make_socket in sk_lookup Date: Sat, 29 Jun 2024 09:20:19 +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() and inetaddr_len() can be dropped now. 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 005776f5964e..c999cfff94e6 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; @@ -1217,7 +1177,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; @@ -1250,11 +1209,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); if (client_fd < 0) goto out_close_server; - err = connect(client_fd, (void *)&dst, inetaddr_len(&dst)); + err = 0; if (CHECK(err && !t->expect_errno, "connect", "unexpected error %d\n", errno)) goto out_close_client;