From patchwork Sat May 25 12:08: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: 13673976 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 4844E18044; Sat, 25 May 2024 12:08:35 +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=1716638916; cv=none; b=kt2YnXCJe897qjwOVUz2wDjnhcIGOGf1QnqLL7lYbgcs2+gctYtBNiEUBoZ1kzX2uGTsXRU26fpW8cah87v5ikhNY3tuRm2YkXFa74utIolN1cedZmpapZ1A0FWtVb+rgaDOT0y7rrUxADKKFRYjgmaCjxcZ5dJtbxHm/UqXM88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716638916; c=relaxed/simple; bh=z/rJWlSUZ4/YuGyhiu6hcQQN4WWNf6a84wS8YU3ikvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Etwerl+/0AFF2vs5yHFSxAXXJATu66UpXTJFQqf/fiONBmNn+8w3tZYT7YsWt2u0DW3gV7mehFlVu3nnCfCa8xxDFtmxWYuLT34cbJmuVic7MaKLLvKfD2t77/RAfY0jwC5fxfEqIiJigxAG3qIw7+9Xb5JvPNDYjsEEUBxrcgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mVd/GRgV; 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="mVd/GRgV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD52CC3277B; Sat, 25 May 2024 12:08:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716638915; bh=z/rJWlSUZ4/YuGyhiu6hcQQN4WWNf6a84wS8YU3ikvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mVd/GRgVelizq+TR98Fn0i6XE08W/TDrwQZiIJHkqYAPpopYPwNIOfY2FL+LogQvL 2bEsb036fx8CAPygZeYlYBFI57bxNCnJTZK7KrO9HcNR+2TeIT2CUztlRWttQF8OzH xixf/jwHcoJsLykUgUovOglOfrDu8bdywWVRXsnnVQiLkQA53Ug1onXhRS00QWykh6 j56oaZ8NnxtY/qe05dAm8hOY5KkQTT2DNzT/+8ejxwATyOM++WXFJe7vd3ByQI3s7c fMyBedcUm17T8Gd8oXTaiOFA8jhTi5yOlVbiLvPTaw+jn7lX1iEszzFwRq9XXqq+Yp J7DyoRou2O/ZA== 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 v5 1/7] selftests/bpf: Drop struct post_socket_opts Date: Sat, 25 May 2024 20:08:15 +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 It's not possible to have one generic/common "struct post_socket_opts" for all tests. It's better to have the individual test define its own callback opts struct. So this patch drops struct post_socket_opts, and changes the second parameter of post_socket_cb as "void *" type. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 2 +- tools/testing/selftests/bpf/network_helpers.h | 4 +--- tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c | 2 +- tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 35250e6cde7f..4d776b78929c 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -133,7 +133,7 @@ int start_server(int family, int type, const char *addr_str, __u16 port, return __start_server(type, (struct sockaddr *)&addr, addrlen, &opts); } -static int reuseport_cb(int fd, const struct post_socket_opts *opts) +static int reuseport_cb(int fd, void *opts) { int on = 1; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 883c7ea9d8d5..40011e0f584b 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -21,8 +21,6 @@ typedef __u16 __sum16; #define VIP_NUM 5 #define MAGIC_BYTES 123 -struct post_socket_opts {}; - struct network_helper_opts { const char *cc; int timeout_ms; @@ -30,7 +28,7 @@ struct network_helper_opts { bool noconnect; int type; int proto; - int (*post_socket_cb)(int fd, const struct post_socket_opts *opts); + int (*post_socket_cb)(int fd, void *opts); }; /* ipv4 test vector */ diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c index 1d3a20f01b60..7cd8be2780ca 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c @@ -70,7 +70,7 @@ static void *server_thread(void *arg) return (void *)(long)err; } -static int custom_cb(int fd, const struct post_socket_opts *opts) +static int custom_cb(int fd, void *opts) { char buf; int err; diff --git a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c index 7b5fc98838cd..aebc58c24dc5 100644 --- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c @@ -139,14 +139,14 @@ static int run_test(int server_fd, int results_fd, bool xdp) return ret; } -static int v6only_true(int fd, const struct post_socket_opts *opts) +static int v6only_true(int fd, void *opts) { int mode = true; return setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &mode, sizeof(mode)); } -static int v6only_false(int fd, const struct post_socket_opts *opts) +static int v6only_false(int fd, void *opts) { int mode = false; From patchwork Sat May 25 12:08: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: 13673977 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 88FD018044; Sat, 25 May 2024 12:08:40 +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=1716638920; cv=none; b=TNIcEcsvdZSOOy2yAFEFDAN+B5qwlUsor5VE8pXvedc5Exga5/n//f8f2su1YhjvZ3ZLMUGspUSGwpgLDl4IQZQCXu4zyW3gqKPKoWXrr4FtlQragGEtunK8h4fsRTmhhRYKBHdn9acwHQrVkBU4f0XKzp8/pLQxz4+5wBT/X4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716638920; c=relaxed/simple; bh=394h3Q9cvyh41rfbfaAmL8bMBRnTOy6D4vSWMspn9Og=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uxg8w+eoOM7F0lEt8uOwA4B38PZC1Vq6Eafkt5EroZNEGrXhkJQb5fVa0axBy3j6L0Q7GLNYeiWd/CiWgZY4C80b3GZiqt9nv2MfDzeAgmlPH1xAZ4HZzQCzQup5v3UxyhxASYNM1fqL6gojgmGEB2iZECMDH5vTk19oJ2NtysQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K7a71Kfy; 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="K7a71Kfy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 545A0C2BD11; Sat, 25 May 2024 12:08:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716638920; bh=394h3Q9cvyh41rfbfaAmL8bMBRnTOy6D4vSWMspn9Og=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K7a71KfyXHUfGl4iufL+H+I/CM4W6R0KfusBc1vf6GvDbfT/z3f8+Y4zxNlU7Z3on YawKeS6ZpK4iF67+Al9SpIbD6WXNHBJ+V+79jDPktXihDUYrKXIKE+HXSaKBFEVWPw mAYUMu8zaXbQVFz55jSGzxWJdHjOGB7vup4aoQl7I28Hlf65UqQ1Gm0HLgncLRp5eE L/Y9nAbofmBxeOdlROBktgM4WWFQTehwBJWumo0WVGYivaiSE/1G2AagLIZSubyUJq AowUb/myi2ygiYfixnhCWvKuzWh9AW9qkxNikh3/EtcTFF97g9Vw7qq/GQ4K9nl+uk g0XVQKiNIyq2Q== 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 v5 2/7] selftests/bpf: Add start_server_str helper Date: Sat, 25 May 2024 20:08:16 +0800 Message-ID: <606e6cfd7e1aff8bc51ede49862eed0802e52170.1716638248.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 It's a tech debt that start_server() does not take the "opts" argument. It's pretty handy to have start_server() as a helper that takes string address. So this patch creates a new helper start_server_str(). Then start_server() can be a wrapper of it. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 22 ++++++++++++++----- tools/testing/selftests/bpf/network_helpers.h | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 4d776b78929c..0e8266f439e4 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -118,19 +118,29 @@ static int __start_server(int type, const struct sockaddr *addr, socklen_t addrl return -1; } -int start_server(int family, int type, const char *addr_str, __u16 port, - int timeout_ms) +int start_server_str(int family, int type, const char *addr_str, __u16 port, + const struct network_helper_opts *opts) { - struct network_helper_opts opts = { - .timeout_ms = timeout_ms, - }; struct sockaddr_storage addr; socklen_t addrlen; + if (!opts) + opts = &default_opts; + if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) return -1; - return __start_server(type, (struct sockaddr *)&addr, addrlen, &opts); + return __start_server(type, (struct sockaddr *)&addr, addrlen, opts); +} + +int start_server(int family, int type, const char *addr_str, __u16 port, + int timeout_ms) +{ + struct network_helper_opts opts = { + .timeout_ms = timeout_ms, + }; + + return start_server_str(family, type, addr_str, port, &opts); } static int reuseport_cb(int fd, void *opts) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 40011e0f584b..4e3e6afe7d3a 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -48,6 +48,8 @@ struct ipv6_packet { extern struct ipv6_packet pkt_v6; int settimeo(int fd, int timeout_ms); +int start_server_str(int family, int type, const char *addr_str, __u16 port, + const struct network_helper_opts *opts); int start_server(int family, int type, const char *addr, __u16 port, int timeout_ms); int *start_reuseport_server(int family, int type, const char *addr_str, From patchwork Sat May 25 12:08: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: 13673978 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 A248518044; Sat, 25 May 2024 12:08:44 +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=1716638924; cv=none; b=V2q9J4gf4hA8v2IzMY4nXE0XgNO3dLw7zJt0iEd/yLexkjF9R8E6FvZpK91UJwA2SHs1sPrNbpjRLN7EGqYzCWGUwVCAjTJ48LBVubYqUATdQmsAduFoDsVbdxCt6LDwmONIfUOcGAZIbAebqETufSJIUeKlKQdqJsgKYBLsY84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716638924; c=relaxed/simple; bh=wGw935yiDzPlQn65eeTyCpfK4FoIfl/VfslSpJ+j3YY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E5rc+zqC1xFXKnCGf030JHjrHIZRCpXkZ5D7LsDfQB0FEoeoaYkZZGDEEaRYzLq58SW+z9GH7MldGsLHRSs3lw/D/+C72oIQ2akFoXdXssFxH3ni+j7coJ1MLsB6qQHQbHPSMwsHnntvX93KrcUiNMho0d9o5Akpvfx0PXK+Pto= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fHGd4PN6; 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="fHGd4PN6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E15BC3277B; Sat, 25 May 2024 12:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716638924; bh=wGw935yiDzPlQn65eeTyCpfK4FoIfl/VfslSpJ+j3YY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHGd4PN63nzzNroPzJC0td3WuN19VgklvmnxvCylqApYmzy8gmh+V0/79lYNL2z0s 8aFze/jLco4+iKg1csc6Bzv6kg7/qs4KVKaGcFZY75yNI8lNGE8o7AMn7Bhb+Ex8hi A8rX8mRVFKes86iWNkEs0jt1VxTsPytJHXvjgXN1DhLua96K9hTjZoQaR1//i8VW3U 3H9kvJcUinrVjK+vZDzIIzP4j9WSnD8rnfJyvOIW9xNwb0E6k6preXCJp6xyvMcFVG Solk/f08bXfW82BYHsOoO2HhGz8s5si/96EzrpwTBVclmWBHzwv1J9JmSPTjAc2oTM gWC/JCAY069CA== 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 v5 3/7] selftests/bpf: Use post_socket_cb in connect_to_fd_opts Date: Sat, 25 May 2024 20:08: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 Since the post_socket_cb() callback is added in struct network_helper_opts, it's make sense to use it not only in __start_server(), but also in connect_to_fd_opts(). Then it can be used to set TCP_CONGESTION sockopt. Add a "void *" type member cb_opts into struct network_helper_opts, and add a new struct named cb_opts in prog_tests/bpf_tcp_ca.c, then cc can be moved into struct cb_opts from network_helper_opts. Define a new callback cc_cb() to set TCP_CONGESTION sockopt, and set it to post_socket_cb pointer of opts. Define a new cb_opts cubic, set it to cb_opts of opts. Pass this opts to connect_to_fd_opts() in test_dctcp_fallback(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 5 ++--- tools/testing/selftests/bpf/network_helpers.h | 2 +- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 0e8266f439e4..8502917b6c7b 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -348,9 +348,8 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) if (settimeo(fd, opts->timeout_ms)) goto error_close; - if (opts->cc && opts->cc[0] && - setsockopt(fd, SOL_TCP, TCP_CONGESTION, opts->cc, - strlen(opts->cc) + 1)) + if (opts->post_socket_cb && + opts->post_socket_cb(fd, opts->cb_opts)) goto error_close; if (!opts->noconnect) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 4e3e6afe7d3a..11eea8e2e4f1 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -22,13 +22,13 @@ typedef __u16 __sum16; #define MAGIC_BYTES 123 struct network_helper_opts { - const char *cc; int timeout_ms; bool must_fail; bool noconnect; int type; int proto; int (*post_socket_cb)(int fd, void *opts); + void *cb_opts; }; /* ipv4 test vector */ diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index 0aca02532794..6f034059888a 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -23,6 +23,10 @@ static const unsigned int total_bytes = 10 * 1024 * 1024; static int expected_stg = 0xeB9F; +struct cb_opts { + const char *cc; +}; + static int settcpca(int fd, const char *tcp_ca) { int err; @@ -81,6 +85,13 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) close(fd); } +static int cc_cb(int fd, void *opts) +{ + struct cb_opts *cb_opts = (struct cb_opts *)opts; + + return settcpca(fd, cb_opts->cc); +} + static void test_cubic(void) { struct bpf_cubic *cubic_skel; @@ -172,10 +183,13 @@ static void test_dctcp_fallback(void) { int err, lfd = -1, cli_fd = -1, srv_fd = -1; struct network_helper_opts opts = { - .cc = "cubic", + .post_socket_cb = cc_cb, }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link = NULL; + struct cb_opts cubic = { + .cc = "cubic", + }; char srv_cc[16]; socklen_t cc_len = sizeof(srv_cc); @@ -195,6 +209,7 @@ static void test_dctcp_fallback(void) !ASSERT_OK(settcpca(lfd, "bpf_dctcp"), "lfd=>bpf_dctcp")) goto done; + opts.cb_opts = &cubic; cli_fd = connect_to_fd_opts(lfd, &opts); if (!ASSERT_GE(cli_fd, 0, "cli_fd")) goto done; From patchwork Sat May 25 12:08: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: 13673979 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 11A5C18044; Sat, 25 May 2024 12:08:49 +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=1716638929; cv=none; b=A/Y2aLpSlJtXZ8IKUuJ/vG34sNshUtvhSCL+hh5hQBHkDmE09vkAmtoXqPw5bjr7Omp2R1BdUDdaeViBD1jkIkq8jHM1s/+v9qI/Ih1E9Aolh3KxzGmbTLnb23B/SjDZGI+NQ7sxfLYNcEynAMAzO/yBXc1EGPIJK2CV85KBRKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716638929; c=relaxed/simple; bh=NjhjhJNshQw1hqZI+zM9sQqjX08SVQvguj3u4AqOLQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sFiv47irtWYeAfyL+p7jx/4Xxs20pb1LHDIDPfMoRdWwdUnoQjOPIQYCCRgydOft/nWKhk0rzkRqZNmsST4APtZ7qCcnDAnlfAV+VmlExrCJygNblKBYtOZAjhbo/niOlRNjqt8B1Y7bZUHYr9X6Iyr5wq2gFXnZMG5SOJa5J6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Mr7qE+ZI; 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="Mr7qE+ZI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDB3EC3277B; Sat, 25 May 2024 12:08:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716638928; bh=NjhjhJNshQw1hqZI+zM9sQqjX08SVQvguj3u4AqOLQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mr7qE+ZIIjqXUW8KessRhLp5nLmIBUCAWl0hVzNeyQHzvYYmzM/96jndrKQ4TWxIf cYbLY0NtgXr8uS5PZ1BY0ycPW3BRAngMrgFPW525G5YTwQWpdIN2Z6G3h6cYBaAT1j jan2ALpA3mQ4MYZ/H1bEzzc++0Xkd7EnxmywshpcVEt0yCSJizzFOvu93VoNl7DnA/ xuskAebYxinr7/h13hMAukjHZb6D/0X0FAjrou0miTt1SrqHWcsWY1Y9eS88YEgLAy +9qofMBaRfjKt59MZhI7NPM9G8RvGXkQ+nK6+n/DLieHDgoPIw6T6BhhTlruvZBNRs ieP/u8eNyo4HQ== 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 v5 4/7] selftests/bpf: Use post_socket_cb in start_server_str Date: Sat, 25 May 2024 20:08:18 +0800 Message-ID: <414c749321fa150435f7fe8e12c80fec8b447c78.1716638248.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 start_server_str() helper in test_dctcp_fallback() in bpf_tcp_ca.c, instead of using start_server() and settcpca(). For support opts in start_server_str() helper, opts->cb_opts needs to be passed to post_socket_cb() in __start_server(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 3 ++- tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 8502917b6c7b..e20caef06aae 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -94,7 +94,8 @@ static int __start_server(int type, const struct sockaddr *addr, socklen_t addrl if (settimeo(fd, opts->timeout_ms)) goto error_close; - if (opts->post_socket_cb && opts->post_socket_cb(fd, NULL)) { + if (opts->post_socket_cb && + opts->post_socket_cb(fd, opts->cb_opts)) { log_err("Failed to call post_socket_cb"); goto error_close; } diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index 6f034059888a..7a523c7a0c6a 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -187,6 +187,9 @@ static void test_dctcp_fallback(void) }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link = NULL; + struct cb_opts dctcp = { + .cc = "bpf_dctcp", + }; struct cb_opts cubic = { .cc = "cubic", }; @@ -204,9 +207,9 @@ static void test_dctcp_fallback(void) if (!ASSERT_OK_PTR(link, "dctcp link")) goto done; - lfd = start_server(AF_INET6, SOCK_STREAM, "::1", 0, 0); - if (!ASSERT_GE(lfd, 0, "lfd") || - !ASSERT_OK(settcpca(lfd, "bpf_dctcp"), "lfd=>bpf_dctcp")) + opts.cb_opts = &dctcp; + lfd = start_server_str(AF_INET6, SOCK_STREAM, "::1", 0, &opts); + if (!ASSERT_GE(lfd, 0, "lfd")) goto done; opts.cb_opts = &cubic; From patchwork Sat May 25 12:08: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: 13673980 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 9B9E540847; Sat, 25 May 2024 12:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716638933; cv=none; b=eDqFO2QYWxriBjTvdDNUMRd3iGIWGbhKOj4woQK8uhE2waZ0WJujtqfWLv7GPbk++t3kkibDZ1SPKSHN01x23kPjswtzVqlrHI0ofjyXodJ8b8H2MZE1mab5ZqClarPfNKvcLoMNFhIn41OpvY8lkFXG1Pe5S/YLKYqJ5mWC/FQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716638933; c=relaxed/simple; bh=EtxyYSK83NhyzeEAez981bC5nUgC2AJ4WLsWfneVf/o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZhP6zkD70JMyKZ5HLSTxxQP2uBevrcQRmWY2CS3FmdkEqzvgYeoi5nD6yLz6qvX3PdqfiuDeA8d/tf3supi9L8xMSsmTPkCf4FqPbDxtoh0BdIjYkJ2Q16qh9TMEOm+j2BFFIjJ7L1P4nvgM1K7tqjXS2wwW/9z2BLDKSj2VJec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dfC3oGaU; 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="dfC3oGaU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E6CBC32789; Sat, 25 May 2024 12:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716638933; bh=EtxyYSK83NhyzeEAez981bC5nUgC2AJ4WLsWfneVf/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dfC3oGaUXnbcQivOu6fH6vtY1wEtGTBHgA2hlaaCoryPbB2QILYuJQeLfgNfdiPJM wFxhH3WEn9xGi0OO/KeNiP1y/t+mDiNqpRvmP5TFwvW0tcBudq9u3ZRB7yPRdzCgEt nqmwFYUkwyRFYqTqUvboNsZDIQRzsUcJElN6NolSCvcmGRugG15bE5yGeeYnw1bCn7 7Wrew+KRoToT/aTtm3VTdA5N8USjMi3tBrkxcbHZIv8f98KRKZR+cDoU1ld8g1ddQ1 cvMXGOfp2duAJ3BpZlb1anwoUNTGokQfWJAeTiD3BCPwt9wa3u+n3i2ukwlmZ+Vq5H u4+Hx9N2Qqagg== 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 v5 5/7] selftests/bpf: Use start_server_str in do_test in bpf_tcp_ca Date: Sat, 25 May 2024 20:08:19 +0800 Message-ID: <6e1b6555e3284e77c8aa60668c61a66c5f99aa37.1716638248.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 new helper start_server_str() in do_test() in bpf_tcp_ca.c to accept a struct network_helper_opts argument instead of using start_server() and settcpca(). Then change the type of the first paramenter of do_test() into a struct network_helper_opts one. Define its own cb_opts and opts for each test, set its own cc name into cb_opts.cc, and cc_cb() into post_socket_cb callback, then pass it to do_test(). Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 66 +++++++++++++++---- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index 7a523c7a0c6a..ebc7d4616880 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -38,12 +38,14 @@ static int settcpca(int fd, const char *tcp_ca) return 0; } -static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) +static void do_test(const struct network_helper_opts *opts, + const struct bpf_map *sk_stg_map) { + struct cb_opts *cb_opts = (struct cb_opts *)opts->cb_opts; int lfd = -1, fd = -1; int err; - lfd = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0); + lfd = start_server_str(AF_INET6, SOCK_STREAM, NULL, 0, opts); if (!ASSERT_NEQ(lfd, -1, "socket")) return; @@ -53,7 +55,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) return; } - if (settcpca(lfd, tcp_ca) || settcpca(fd, tcp_ca)) + if (settcpca(fd, cb_opts->cc)) goto done; if (sk_stg_map) { @@ -94,6 +96,13 @@ static int cc_cb(int fd, void *opts) static void test_cubic(void) { + struct cb_opts cb_opts = { + .cc = "bpf_cubic", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct bpf_cubic *cubic_skel; struct bpf_link *link; @@ -107,7 +116,7 @@ static void test_cubic(void) return; } - do_test("bpf_cubic", NULL); + do_test(&opts, NULL); ASSERT_EQ(cubic_skel->bss->bpf_cubic_acked_called, 1, "pkts_acked called"); @@ -117,6 +126,13 @@ static void test_cubic(void) static void test_dctcp(void) { + struct cb_opts cb_opts = { + .cc = "bpf_dctcp", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link; @@ -130,7 +146,7 @@ static void test_dctcp(void) return; } - do_test("bpf_dctcp", dctcp_skel->maps.sk_stg_map); + do_test(&opts, dctcp_skel->maps.sk_stg_map); ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result"); bpf_link__destroy(link); @@ -315,6 +331,13 @@ static void test_unsupp_cong_op(void) static void test_update_ca(void) { + struct cb_opts cb_opts = { + .cc = "tcp_ca_update", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct tcp_ca_update *skel; struct bpf_link *link; int saved_ca1_cnt; @@ -327,14 +350,14 @@ static void test_update_ca(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); saved_ca1_cnt = skel->bss->ca1_cnt; ASSERT_GT(saved_ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_update_2); ASSERT_OK(err, "update_map"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); ASSERT_EQ(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt"); ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt"); @@ -344,6 +367,13 @@ static void test_update_ca(void) static void test_update_wrong(void) { + struct cb_opts cb_opts = { + .cc = "tcp_ca_update", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct tcp_ca_update *skel; struct bpf_link *link; int saved_ca1_cnt; @@ -356,14 +386,14 @@ static void test_update_wrong(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); saved_ca1_cnt = skel->bss->ca1_cnt; ASSERT_GT(saved_ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_wrong); ASSERT_ERR(err, "update_map"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt"); bpf_link__destroy(link); @@ -372,6 +402,13 @@ static void test_update_wrong(void) static void test_mixed_links(void) { + struct cb_opts cb_opts = { + .cc = "tcp_ca_update", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct tcp_ca_update *skel; struct bpf_link *link, *link_nl; int err; @@ -386,7 +423,7 @@ static void test_mixed_links(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test("tcp_ca_update", NULL); + do_test(&opts, NULL); ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_no_link); @@ -473,6 +510,13 @@ static void test_tcp_ca_kfunc(void) static void test_cc_cubic(void) { + struct cb_opts cb_opts = { + .cc = "bpf_cc_cubic", + }; + struct network_helper_opts opts = { + .post_socket_cb = cc_cb, + .cb_opts = &cb_opts, + }; struct bpf_cc_cubic *cc_cubic_skel; struct bpf_link *link; @@ -486,7 +530,7 @@ static void test_cc_cubic(void) return; } - do_test("bpf_cc_cubic", NULL); + do_test(&opts, NULL); bpf_link__destroy(link); bpf_cc_cubic__destroy(cc_cubic_skel); From patchwork Sat May 25 12:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13673981 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 E03B840847; Sat, 25 May 2024 12:08: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=1716638938; cv=none; b=udGGZwlMaEnryb9bxzy1Q9KqBYIpDF+TmyaBNOYAviTyWPcxuk7iDllvnM6ORnSlNTkzrdKYjFj2oUB5mkR2P6rpHngQyJjwWgzmG26YbMCuCEqEF1SVvclfvq258jlNoqdnL46BF6QPl4wFvzU2rPUMkU12BC0hyizSVqFkQYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716638938; c=relaxed/simple; bh=Qf86i3oXSIEJ67dO1n7U88T7pZ+CuJwy0+8D6xSAk7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u9nrsPym884oXqgOmeXvTepBxEMlZQpk3UAXbyIW31P2yL4JJB1FU1Xm2n5cwYsqkS6v1FVv0YMQXpO10Jkm9M1NjKatSACsSuiqYRlLVT56L0cYgttw/zCPcJpbAQf9kUUjimRialsoV5GyOLcVlNLwxii+FxatWY2B6JG+y0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hYu3Fpl+; 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="hYu3Fpl+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0F1EC2BD11; Sat, 25 May 2024 12:08:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716638937; bh=Qf86i3oXSIEJ67dO1n7U88T7pZ+CuJwy0+8D6xSAk7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hYu3Fpl+5Hc2WXlADvCLb1xy1XmX3sdseZEnFtNC0K+AQnJ+m4MAhvOXRzVjgPXOf QtqUXM+JvXRsbfnuOPtCoHw8Rw8DCs5UIyD1aknrNQCVUrH+SBzqHAFwfpDI6u0AMg 9OwpHf5oEwbG8rfpHgPyEDGbZFMQtNs03vUiuitEf8x6nUJLmKyj7YyULLGVgLwW+5 FUiBdgLSO39W8Hdb5klYy81iW7EsxCPcsDPYZEwJXaGKMpLhqkGxiUEWyy2d+pviL7 uk/BTQ4T6dNPN6m7wMHpy6sG4t9aR+WuXKVcx4KIqlWBqsUNxfEqkZM8WmcrfNpekZ uEF1YOCMvYsDQ== 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 v5 6/7] selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca Date: Sat, 25 May 2024 20:08:20 +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 connect_to_fd_opts() instead of using connect_fd_to_fd() and settcpca() in do_test() in prog_tests/bpf_tcp_ca.c to accept a struct network_helper_opts argument. Then define a dctcp dedicated post_socket_cb callback stg_post_socket_cb(), invoking both cc_cb() and bpf_map_update_elem() in it, and set it in test_dctcp(). For passing map_fd into stg_post_socket_cb() callback, a new member map_fd is added in struct cb_opts. Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index ebc7d4616880..9a7c3dc39008 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -25,6 +25,7 @@ static int expected_stg = 0xeB9F; struct cb_opts { const char *cc; + int map_fd; }; static int settcpca(int fd, const char *tcp_ca) @@ -41,7 +42,6 @@ static int settcpca(int fd, const char *tcp_ca) static void do_test(const struct network_helper_opts *opts, const struct bpf_map *sk_stg_map) { - struct cb_opts *cb_opts = (struct cb_opts *)opts->cb_opts; int lfd = -1, fd = -1; int err; @@ -49,25 +49,9 @@ static void do_test(const struct network_helper_opts *opts, if (!ASSERT_NEQ(lfd, -1, "socket")) return; - fd = socket(AF_INET6, SOCK_STREAM, 0); - if (!ASSERT_NEQ(fd, -1, "socket")) { - close(lfd); - return; - } - - if (settcpca(fd, cb_opts->cc)) - goto done; - - if (sk_stg_map) { - err = bpf_map_update_elem(bpf_map__fd(sk_stg_map), &fd, - &expected_stg, BPF_NOEXIST); - if (!ASSERT_OK(err, "bpf_map_update_elem(sk_stg_map)")) - goto done; - } - /* connect to server */ - err = connect_fd_to_fd(fd, lfd, 0); - if (!ASSERT_NEQ(err, -1, "connect")) + fd = connect_to_fd_opts(lfd, opts); + if (!ASSERT_NEQ(fd, -1, "connect_to_fd_opts")) goto done; if (sk_stg_map) { @@ -124,13 +108,30 @@ static void test_cubic(void) bpf_cubic__destroy(cubic_skel); } +static int stg_post_socket_cb(int fd, void *opts) +{ + struct cb_opts *cb_opts = (struct cb_opts *)opts; + int err; + + err = settcpca(fd, cb_opts->cc); + if (err) + return err; + + err = bpf_map_update_elem(cb_opts->map_fd, &fd, + &expected_stg, BPF_NOEXIST); + if (!ASSERT_OK(err, "bpf_map_update_elem(sk_stg_map)")) + return err; + + return 0; +} + static void test_dctcp(void) { struct cb_opts cb_opts = { .cc = "bpf_dctcp", }; struct network_helper_opts opts = { - .post_socket_cb = cc_cb, + .post_socket_cb = stg_post_socket_cb, .cb_opts = &cb_opts, }; struct bpf_dctcp *dctcp_skel; @@ -146,6 +147,7 @@ static void test_dctcp(void) return; } + cb_opts.map_fd = bpf_map__fd(dctcp_skel->maps.sk_stg_map); do_test(&opts, dctcp_skel->maps.sk_stg_map); ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result"); From patchwork Sat May 25 12:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13673982 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 429254204B; Sat, 25 May 2024 12:09:02 +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=1716638942; cv=none; b=HE+VPfaJgbamozjKEaWEZAN2RR3FotpUmjp1PMqe7i/f8dM46cUoPzEjkj3oVN4/ip527Tz/3jMNEVuCr3hzCM1wWo4XuW+dTiGKBfa+hwQ7LPZm9yXDBBqZg88KfOCcmRE8TMHdBMU6NIfceZw2WZ56O9FZZujLwVHZomZD1LU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716638942; c=relaxed/simple; bh=Z9oReom4OcpwOIk6DSXKNHCUKdLqN5YiEZpEcZFsHrk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s55SuEsfOLL9YDRG1dIcYJbCeetbie7oWDU1fnknqQGy62FPrP7lCQUEvdqrIhw8UI99+NpsMkwEWKw3UUDpmCW86HvFW73Y7rf/poQ2dE6HcoU1YF8+Ppbpd1lT8MANNhh9okflmeMrn4Fl/dVXTD0MPyTYVrI50n/K8xeAoDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tMxcX0JV; 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="tMxcX0JV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F375C3277B; Sat, 25 May 2024 12:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716638942; bh=Z9oReom4OcpwOIk6DSXKNHCUKdLqN5YiEZpEcZFsHrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tMxcX0JVREIg0peQmaMg44VKTutYxxwT/8ym1tE2cpH/LTvKjfadIv0tLYIllBezz k561DIEQBjmxCKn6XD1pO4DCG/uM/Wtf4OCpjbuXSprHp7YfNdQfY7Nc1c04nkrZKG iTv1tL5W/DipOuqgfoqaWrZV3KSkChIbFt3bqkhsce9jYCXQemw8UE6YzF6etkNIvK YnSXUjn/BzLB1FNqf1yfpBbDhPYNgKSBSA/7GPYsoWs1Gy72TCVa1kL6OJYWKWnclR EUSyjGPgY4yJUbFPMrjHAAGJfx6wcksfQfL0WAw/1AFzV+WKCkmH6SbzhwMaRb6BnI HugxxJbuDmp/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 v5 7/7] selftests/bpf: Add post_connect_cb callback Date: Sat, 25 May 2024 20:08:21 +0800 Message-ID: <3c5e8bd6c38cbe233daee6e0359a99d8d22ed821.1716638248.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 For getting rid of the second parameter of do_test(), this patch adds a new callback post_connect_cb in struct network_helper_opts, it will be invoked after connect_fd_to_addr() in connect_to_fd_opts(). Then define a dctcp dedicated post_connect_cb callback, invoking bpf_map_lookup_elem() in it, named stg_post_connect_cb() and set it in test_dctcp(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 7 ++- tools/testing/selftests/bpf/network_helpers.h | 1 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 45 ++++++++++--------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index e20caef06aae..75589597c17e 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -353,10 +353,15 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) opts->post_socket_cb(fd, opts->cb_opts)) goto error_close; - if (!opts->noconnect) + if (!opts->noconnect) { if (connect_fd_to_addr(fd, &addr, addrlen, opts->must_fail)) goto error_close; + if (opts->post_connect_cb && + opts->post_connect_cb(fd, opts->cb_opts)) + goto error_close; + } + return fd; error_close: diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 11eea8e2e4f1..b387e8142f3c 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -28,6 +28,7 @@ struct network_helper_opts { int type; int proto; int (*post_socket_cb)(int fd, void *opts); + int (*post_connect_cb)(int fd, void *opts); void *cb_opts; }; diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index 9a7c3dc39008..e6fc6dfbcb7b 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -39,11 +39,9 @@ static int settcpca(int fd, const char *tcp_ca) return 0; } -static void do_test(const struct network_helper_opts *opts, - const struct bpf_map *sk_stg_map) +static void do_test(const struct network_helper_opts *opts) { int lfd = -1, fd = -1; - int err; lfd = start_server_str(AF_INET6, SOCK_STREAM, NULL, 0, opts); if (!ASSERT_NEQ(lfd, -1, "socket")) @@ -54,16 +52,6 @@ static void do_test(const struct network_helper_opts *opts, if (!ASSERT_NEQ(fd, -1, "connect_to_fd_opts")) goto done; - if (sk_stg_map) { - int tmp_stg; - - err = bpf_map_lookup_elem(bpf_map__fd(sk_stg_map), &fd, - &tmp_stg); - if (!ASSERT_ERR(err, "bpf_map_lookup_elem(sk_stg_map)") || - !ASSERT_EQ(errno, ENOENT, "bpf_map_lookup_elem(sk_stg_map)")) - goto done; - } - ASSERT_OK(send_recv_data(lfd, fd, total_bytes), "send_recv_data"); done: @@ -100,7 +88,7 @@ static void test_cubic(void) return; } - do_test(&opts, NULL); + do_test(&opts); ASSERT_EQ(cubic_skel->bss->bpf_cubic_acked_called, 1, "pkts_acked called"); @@ -125,6 +113,20 @@ static int stg_post_socket_cb(int fd, void *opts) return 0; } +static int stg_post_connect_cb(int fd, void *opts) +{ + struct cb_opts *cb_opts = (struct cb_opts *)opts; + int tmp_stg; + int err; + + err = bpf_map_lookup_elem(cb_opts->map_fd, &fd, &tmp_stg); + if (!ASSERT_ERR(err, "bpf_map_lookup_elem(sk_stg_map)") || + !ASSERT_EQ(errno, ENOENT, "bpf_map_lookup_elem(sk_stg_map)")) + return err; + + return 0; +} + static void test_dctcp(void) { struct cb_opts cb_opts = { @@ -132,6 +134,7 @@ static void test_dctcp(void) }; struct network_helper_opts opts = { .post_socket_cb = stg_post_socket_cb, + .post_connect_cb = stg_post_connect_cb, .cb_opts = &cb_opts, }; struct bpf_dctcp *dctcp_skel; @@ -148,7 +151,7 @@ static void test_dctcp(void) } cb_opts.map_fd = bpf_map__fd(dctcp_skel->maps.sk_stg_map); - do_test(&opts, dctcp_skel->maps.sk_stg_map); + do_test(&opts); ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result"); bpf_link__destroy(link); @@ -352,14 +355,14 @@ static void test_update_ca(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test(&opts, NULL); + do_test(&opts); saved_ca1_cnt = skel->bss->ca1_cnt; ASSERT_GT(saved_ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_update_2); ASSERT_OK(err, "update_map"); - do_test(&opts, NULL); + do_test(&opts); ASSERT_EQ(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt"); ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt"); @@ -388,14 +391,14 @@ static void test_update_wrong(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test(&opts, NULL); + do_test(&opts); saved_ca1_cnt = skel->bss->ca1_cnt; ASSERT_GT(saved_ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_wrong); ASSERT_ERR(err, "update_map"); - do_test(&opts, NULL); + do_test(&opts); ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt"); bpf_link__destroy(link); @@ -425,7 +428,7 @@ static void test_mixed_links(void) link = bpf_map__attach_struct_ops(skel->maps.ca_update_1); ASSERT_OK_PTR(link, "attach_struct_ops"); - do_test(&opts, NULL); + do_test(&opts); ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt"); err = bpf_link__update_map(link, skel->maps.ca_no_link); @@ -532,7 +535,7 @@ static void test_cc_cubic(void) return; } - do_test(&opts, NULL); + do_test(&opts); bpf_link__destroy(link); bpf_cc_cubic__destroy(cc_cubic_skel);