From patchwork Wed May 15 04:20: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: 797392 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 C6B7338DE0; Wed, 15 May 2024 04:20: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=1715746844; cv=none; b=ZXexg2iSOKxgcHEo+9xU0W4pXDIre/JcYHHK+S4+4cxiMOoygYmLAyQYB6lC04YYfBf1tVVqI9/NUzyPSb3w2bQi1e+j+7P9/5seS3RH220BqmSw5OaQsmnvbBblmWYyBvE/mTBCqCIF4oPbirTk3J6v0OgW0p9xc3UY7VUcwJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715746844; c=relaxed/simple; bh=2EQNSMsbvUMMfTdrfFOCFTL322farv5pEPh6cXpZcSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rPu/O4BQ6U8YMyTxxJqDy4mIX0qjo8s9Hrrg5MGg3LynAdL5ubWE/8KhC1b1A8yveRv8i4rNbEK8AEq6vbo7HokcfSoAlxdAdJg42LDG441KVyO4h4NhlLfOF55P8/RhZvzezGV+o4cFRq2Cw12WSRsoZCvqTs8EXdjy2MXmvs4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fy1QISpB; 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="Fy1QISpB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69BA1C4AF07; Wed, 15 May 2024 04:20:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715746844; bh=2EQNSMsbvUMMfTdrfFOCFTL322farv5pEPh6cXpZcSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fy1QISpBORgeow4S2NAMUX5cobe4o2BigTsiGBm+pNLO+zmnBNWOKPWDdj+m6t1jA WieK3NSwyiKuWUFdKF8qv/YAKk48/q2UhpP4eLsBjhxDWiApktOPR83PbsWQfhfyrh pFrh7W/ZqzE+Y/YTB7MytuJBUzy9VGp3IYXyDcYIygX9wXh+oNZB9lOYYtSMYPaiam cnRWkUwt6OvJaryTltJFt/qXf0yH8BmfBkTnOijEwUxJmTJf1Bxfb6j4fPzYtI1o+W cS9UPFEpOc00p4wgABdv466H2/vCdjD6dxhfdKqDpVHLgKyK7AWVxg8mC/0K+N+Rh4 ne1OO7yhyr2Jg== 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, Geliang Tang Subject: [PATCH bpf-next v2 1/4] selftests/bpf: Use post_socket_cb in connect_to_fd_opts Date: Wed, 15 May 2024 12:20:21 +0800 Message-ID: <0de05f2ffdfa4adb832fb87d08e6d1c56bef62b2.1715745588.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 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 post_socket_opts type member cb_opts into struct network_helper_opts, then cc can be moved into struct post_socket_opts from network_helper_opts. Define a new callback cc_cb() to set TCP_CONGESTION sockopt, and set it to post_socket_cb pointer. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 5 ++--- tools/testing/selftests/bpf/network_helpers.h | 6 ++++-- tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 9 ++++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 35250e6cde7f..d97f8a669b38 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -338,9 +338,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 883c7ea9d8d5..e44a6e5d8344 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -21,16 +21,18 @@ typedef __u16 __sum16; #define VIP_NUM 5 #define MAGIC_BYTES 123 -struct post_socket_opts {}; +struct post_socket_opts { + const char *cc; +}; 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, const struct post_socket_opts *opts); + struct post_socket_opts 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..9bc909fa0833 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -81,6 +81,12 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) close(fd); } +static int cc_cb(int fd, const struct post_socket_opts *opts) +{ + return setsockopt(fd, SOL_TCP, TCP_CONGESTION, opts->cc, + strlen(opts->cc) + 1); +} + static void test_cubic(void) { struct bpf_cubic *cubic_skel; @@ -172,7 +178,8 @@ static void test_dctcp_fallback(void) { int err, lfd = -1, cli_fd = -1, srv_fd = -1; struct network_helper_opts opts = { - .cc = "cubic", + .cb_opts.cc = "cubic", + .post_socket_cb = cc_cb, }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link = NULL; From patchwork Wed May 15 04:20:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 797141 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 16CB0383A1; Wed, 15 May 2024 04:20:50 +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=1715746851; cv=none; b=GiG1PQY73ISdA2lDhBHecriT9DWot6SXcAIl7E7CHIgoYVAMf9QLBZ9fRW2RZYId8KkvClZ6lCmPVuIOocS00Sy5rKj+c7WHLy4AqmB9D7NmTUTIpXwPJtCo8kZzcP/IbjrFS9PXfYbDwnPN9VPGSNgXExikN+0/wz4z3+p+h3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715746851; c=relaxed/simple; bh=O4lwtqDDPeBUnGU0HAH5cF9ar9DD2TsAFR5rf9sF2vQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DfXW06m3Yod2wqx0Izr5lFQaKLJfacNnfUX+1HNmVsyh89Ol5H2IRiFHdPTSmD4owtybjv2kIteC0ogD/gPBgGajdY0Kt3r4QWwwt1IN/j4ozYOgdiFGFCE72Lvc2xoqXzWr6V10lwl+gdUipU+UaMzLG2TRp/tvuxXGOjbp+mI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hWw5ODk1; 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="hWw5ODk1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F69AC4AF12; Wed, 15 May 2024 04:20:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715746850; bh=O4lwtqDDPeBUnGU0HAH5cF9ar9DD2TsAFR5rf9sF2vQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hWw5ODk1vOk7I6v64G/FxyIuIRzqiNCaG0dM6yCR5kL95BfeF6wnJMA3mL/UlDEme mJy4pO5ztQFKAXpic1S6cl7OWi1Yt3uEFtxqtGR7F6vqmG+EwrVaVRcGoVssxpwNFL m9lkCwRzjzIvFHPykHu6e4NyeBP28t/Sm1zzJXxjH+Vrxlrsm9Ca+pBF3R4fq4pGMf jq/6wUHo/0mA9SnlxHDcTAwWMj3Pnvp6xzPkfX7CNtUYeOXMjnoeWG5ZBvJfEpOUxz 1QGvACbluXsLVw/+wJYcbCK+sTfiOwsuMe66lB1WzTvH5OVe17di9PWnBd+aO2NG13 thIkBYs2+FZZQ== 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, Geliang Tang Subject: [PATCH bpf-next v2 2/4] selftests/bpf: Use start_server_addr in bpf_tcp_ca Date: Wed, 15 May 2024 12:20:22 +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 start_server_addr() in do_test() in prog_tests/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 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(). 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 | 2 +- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 52 +++++++++++++++---- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index d97f8a669b38..6864af665508 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -94,7 +94,7 @@ 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 9bc909fa0833..25961ce850cb 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -34,12 +34,18 @@ 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 sockaddr_storage addr; int lfd = -1, fd = -1; + socklen_t addrlen; int err; - lfd = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0); + if (make_sockaddr(AF_INET6, NULL, 0, &addr, &addrlen)) + return; + + lfd = start_server_addr(SOCK_STREAM, &addr, addrlen, opts); if (!ASSERT_NEQ(lfd, -1, "socket")) return; @@ -49,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, opts->cb_opts.cc)) goto done; if (sk_stg_map) { @@ -89,6 +95,10 @@ static int cc_cb(int fd, const struct post_socket_opts *opts) static void test_cubic(void) { + struct network_helper_opts opts = { + .cb_opts.cc = "bpf_cubic", + .post_socket_cb = cc_cb, + }; struct bpf_cubic *cubic_skel; struct bpf_link *link; @@ -102,7 +112,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"); @@ -112,6 +122,10 @@ static void test_cubic(void) static void test_dctcp(void) { + struct network_helper_opts opts = { + .cb_opts.cc = "bpf_dctcp", + .post_socket_cb = cc_cb, + }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link; @@ -125,7 +139,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); @@ -304,6 +318,10 @@ static void test_unsupp_cong_op(void) static void test_update_ca(void) { + struct network_helper_opts opts = { + .cb_opts.cc = "tcp_ca_update", + .post_socket_cb = cc_cb, + }; struct tcp_ca_update *skel; struct bpf_link *link; int saved_ca1_cnt; @@ -316,14 +334,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"); @@ -333,6 +351,10 @@ static void test_update_ca(void) static void test_update_wrong(void) { + struct network_helper_opts opts = { + .cb_opts.cc = "tcp_ca_update", + .post_socket_cb = cc_cb, + }; struct tcp_ca_update *skel; struct bpf_link *link; int saved_ca1_cnt; @@ -345,14 +367,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); @@ -361,6 +383,10 @@ static void test_update_wrong(void) static void test_mixed_links(void) { + struct network_helper_opts opts = { + .cb_opts.cc = "tcp_ca_update", + .post_socket_cb = cc_cb, + }; struct tcp_ca_update *skel; struct bpf_link *link, *link_nl; int err; @@ -375,7 +401,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); @@ -462,6 +488,10 @@ static void test_tcp_ca_kfunc(void) static void test_cc_cubic(void) { + struct network_helper_opts opts = { + .cb_opts.cc = "bpf_cc_cubic", + .post_socket_cb = cc_cb, + }; struct bpf_cc_cubic *cc_cubic_skel; struct bpf_link *link; @@ -475,7 +505,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 Wed May 15 04:20:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 797391 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 02B77383A1; Wed, 15 May 2024 04: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=1715746857; cv=none; b=iSqW5wH2d0QMV5q0OPFcOj9fsqMN0OtfMHbJtP1z9h9S3CH3H/L0/Rnr/LDGC8rM9yPNs50RnZjmuspfMvHt6Gk/rDfTuLgVynoBwv8mH0erY12OfgzcT5lH1qK6jS+Ap4HcJ0QY+5yqntle1ffdBIy38rR2GMpOG7PB49utLLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715746857; c=relaxed/simple; bh=HkzV+4jolSuOdg1n7+5S6ok0t8H/Yn2aEB0nuV0GCzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C3AhJKCxu07CwjN2i23rNFdGwZLC529rKKBWgebmJfmOZtR4TA6eBrkhtKKweBu07bcAmfYKkFpbtlN/eLwfFSloTXIbHOW9AyirJwX+wTvFw11kpT6o47vvQZ0ogl7WJ8dOz6jJf1wX2nJYMgAOkg/mTJNyB6AIL+UjJW4a38s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L7cczszD; 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="L7cczszD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5548DC2BD11; Wed, 15 May 2024 04:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715746856; bh=HkzV+4jolSuOdg1n7+5S6ok0t8H/Yn2aEB0nuV0GCzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L7cczszDnNut1F87MM3kpBysmmzZXIjhihUvIfzAw0WgB05VAqApk7EGGRfkVWj2U htHOh36BRVbdANaeKW6/8gZKZbsC9F/BcFUH5col4qsyLH+cgRm43Ota3FbPYMoQLq X666TjfLF90JdpWCDS+dqHYh+YeurUMDHqb1kClw8MZf2doz4DYp0awxziBQsdnvVW Lbcz5tzYaOIKyVkE657E2O0trJkqJ5ICBY79QpuP9E/uIzDmKZdU0jDgdcyPPCyx/f XGG3zqMXHFYhBK1BWtjrACaed8OaDugvHlexHyGRrwzByxceqP20QbKP9Kj0ATy0dd FapbQuP0j9/5g== 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, Geliang Tang Subject: [PATCH bpf-next v2 3/4] selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca Date: Wed, 15 May 2024 12:20:23 +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 post_socket_opts. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.h | 1 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 33 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index e44a6e5d8344..62dd40095cf2 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -23,6 +23,7 @@ typedef __u16 __sum16; struct post_socket_opts { const char *cc; + int map_fd; }; struct network_helper_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 25961ce850cb..7c9c79e35551 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -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, opts->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) { @@ -120,11 +104,21 @@ static void test_cubic(void) bpf_cubic__destroy(cubic_skel); } +static int stg_post_socket_cb(int fd, const struct post_socket_opts *opts) +{ + int err; + + err = cc_cb(fd, opts); + if (err) + return err; + return bpf_map_update_elem(opts->map_fd, &fd, &expected_stg, BPF_NOEXIST); +} + static void test_dctcp(void) { struct network_helper_opts opts = { .cb_opts.cc = "bpf_dctcp", - .post_socket_cb = cc_cb, + .post_socket_cb = stg_post_socket_cb, }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link; @@ -139,6 +133,7 @@ static void test_dctcp(void) return; } + opts.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 Wed May 15 04:20:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 797140 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 7D8443838A; Wed, 15 May 2024 04:21:03 +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=1715746863; cv=none; b=g5MRbjILpim8aX4hfRxHu+SXqkGYI2fjLylGPs/rtzbvMeDSlv9peLFHBkyUVM7Bf12ms1onprBBwJvt7njSwJBj7QheV0s2zUTTxJtKlOlXBcXiWQ5tJM7VUy6vJ3SVVo44aCfphgiosPfVhvNs0cnUCTxsenGXDyw806CxT00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715746863; c=relaxed/simple; bh=uqqq8xHZEu3FsErv+gXQyhiJdQiI3eJ/IXas1Dknud8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eb5IHmK1SKqaEwDZFa8+Ow+aT5s7dx3agSbeI1TkHU4NPGhw5NVUfIkn1OAcqQ6kMlrEsB3AZHob3GKtvxpwXFpHACf0wiDZtb7ECJ2KSTkXoMUQhDBRe1JFKrAQv4YFp22L946KJu/99uEnZ0mXgrvnVpRb0u1kCXbrdUXYm3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BsylV6p6; 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="BsylV6p6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2ACD5C32781; Wed, 15 May 2024 04:20:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715746863; bh=uqqq8xHZEu3FsErv+gXQyhiJdQiI3eJ/IXas1Dknud8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BsylV6p6imbr4f3rK4oSSyf63FaJ7SlwnbG166UfU/lry+Tqjl13kRGHwSh6GrBrH H1gJXBWzcYP6BmOV7cxGFbP8EJfoa7yadsxY/eqLRHswyJJqknBbcf3o9ak6Uogx4T haePx/nhbbr1ZVyGQvuKZiroksMIQ4/dJqCGlJm/AhbIAFTltblWZd2fPlV30CF/NY f8eVqbJ48dbgEdrT3USfaEvxepFrmmBZovocp7Tbtlkg+ZSKQXM0n2XN+EStf3FntS p4dzBOoWtcMIJSEM7KLt+NfFXK94hM0DyAPvM4uGlMix8zAfTXRWK+iPb104yMrN+0 wvr8DzxN09Ijw== 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, Geliang Tang Subject: [PATCH bpf-next v2 4/4] selftests/bpf: Add post_connect_cb callback Date: Wed, 15 May 2024 12:20:24 +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 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 | 6 ++- tools/testing/selftests/bpf/network_helpers.h | 1 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 43 ++++++++++--------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 6864af665508..5636488dfb42 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -342,10 +342,14 @@ 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 62dd40095cf2..0c8859651e7a 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -33,6 +33,7 @@ struct network_helper_opts { int type; int proto; int (*post_socket_cb)(int fd, const struct post_socket_opts *opts); + int (*post_connect_cb)(int fd, const struct post_socket_opts *opts); struct post_socket_opts 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 7c9c79e35551..05bcdb4830fa 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -34,13 +34,11 @@ 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) { struct sockaddr_storage addr; int lfd = -1, fd = -1; socklen_t addrlen; - int err; if (make_sockaddr(AF_INET6, NULL, 0, &addr, &addrlen)) return; @@ -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: @@ -96,7 +84,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"); @@ -114,11 +102,24 @@ static int stg_post_socket_cb(int fd, const struct post_socket_opts *opts) return bpf_map_update_elem(opts->map_fd, &fd, &expected_stg, BPF_NOEXIST); } +static int stg_post_connect_cb(int fd, const struct post_socket_opts *opts) +{ + int tmp_stg; + int err; + + err = bpf_map_lookup_elem(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 network_helper_opts opts = { .cb_opts.cc = "bpf_dctcp", .post_socket_cb = stg_post_socket_cb, + .post_connect_cb = stg_post_connect_cb, }; struct bpf_dctcp *dctcp_skel; struct bpf_link *link; @@ -134,7 +135,7 @@ static void test_dctcp(void) } opts.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); @@ -329,14 +330,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"); @@ -362,14 +363,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); @@ -396,7 +397,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); @@ -500,7 +501,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);