From patchwork Sat May 11 03:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 796611 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 C9DFA4204E; Sat, 11 May 2024 03:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715397407; cv=none; b=rKhont5ycENI0cIvnoqqvsqV00GOscec9Dc6qpSnLCtrW0Lwk2kuTRp6Moures6JvV769wyyAlefwb+WzhSrrD1u2twJsQsKy63Y7RYyprS1nObmVhaqlLiBcquRB8Uicv0Uro2YR6OxXgqlF6fwPeoipZPmIxJ9PrWyT+2HWs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715397407; c=relaxed/simple; bh=98zZ/NjyeaFDtoVqxPBN/26Bl1zmbL3inBDa1Mvxads=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oFQ0TNcrURIiC49Q2CgGKFE0X0qgJhlS9oEAgLfS52YQWAGQBUQZ2AESZm1vBLv5j6G9R3MHhPzNBt29rTI3R6G7eeP0fjpAQjSZUzHYPavsKkBCUugVUrFpdFCTVK5Nuh/086F1gvAgd4zclVCQurnjR7i3znbnPUHuW2Vu8Kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QnJ38I6X; 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="QnJ38I6X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7064AC2BD10; Sat, 11 May 2024 03:16:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715397407; bh=98zZ/NjyeaFDtoVqxPBN/26Bl1zmbL3inBDa1Mvxads=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QnJ38I6X1RQKUCX4LJOohvbhpiSsCQULSt61nmOLWcZws71AafnOX4OGbgev2NlaD NvYAS+pxfFxVU7TlybDjvB+Qj19w0sh0+pJla4PWAUFIEcKa3YQ0LQLO6JH6Esu3cn gXadvgTGX0oshk/b0AfCEoi92IvBI0rWRKP1LqC+vguDPRFet7WPJ5G83zZfyEjPgX d8J+4Emu56AJxakQJdd8w6FPJB6uXBeWS6h74ajB/ATN+aPwo4+40MjUDuN/Yw9XOW aUGuaFi9xep3vb2LKzcmXfOgb3uodX2leSZbm5r3paEUe/YtuMDuNDqrWov0mVq2MW h6Dl1qXKgDdPQ== 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 1/4] selftests/bpf: Use post_socket_cb in connect_to_fd_opts Date: Sat, 11 May 2024 11:16:25 +0800 Message-ID: <14f54f651baef131c38262246f75768bff02ab00.1715396405.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 907bac46c774..4eedc161b5b3 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -80,6 +80,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; @@ -171,7 +177,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 Sat May 11 03:16:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 796287 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 AA09D21A04; Sat, 11 May 2024 03:16: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=1715397413; cv=none; b=txpAEjfqJCHT2HyOGwB1CM0FHvI017OltNdtv5SBY+Afno7zDmgChEpGwrhNSsshJoxRZUsrYshJU8vY55ZMGMUAa+SFhsIwPQJoOeps/Snr6HXGlVJpmT83FHdUPXY7/UIL+hETHSxZn5k+1UbLtKOQreEZMMBukAakAxGib5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715397413; c=relaxed/simple; bh=mVxa3ZAgx8qoD/ZUT5ME2rgJsMq3QfeaJ05szvCjf7g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VxKPvxDDKcFgIbw32FCjmbgnFccuILj5h77leTCi+YweYXYsg+Bozfah86bRxV4BXnP09DzmCcM+7ZH0T6siklvAQYdD/d3AoD7EleNccEt13WsEqnkjOGfrOsBtzcCipmCpp5bIIRsXi1ebaM7AHTPKbECiuAOnAUfF9jL1xkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V5XSOjzN; 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="V5XSOjzN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CCBAC113CC; Sat, 11 May 2024 03:16:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715397413; bh=mVxa3ZAgx8qoD/ZUT5ME2rgJsMq3QfeaJ05szvCjf7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V5XSOjzNlP4h0qURWs93K4+yRGUJC+6gu6EPnXMgarMyJ81ov6GxI7XS9A0E1tyDF S6k+sKhP7jniYBbqK7PhhlGOMwHw7iXgrYwB6+xQCUb2RL9ok3konJE5YgIgFDSiDC V+c+IRchslM26cdAAO1cTGPsncHfq1eLS3Y8XP0sQM8Vabc0Z2Zci+b9nOnaKGx62p okiVb9VroWkEagr2StcGPG1T4hlXYPWCwQUxCMoKWLET8FnlOm/cUeT+/nRNmcdtJ6 z2lanyqQgcq3is+mVLDIonLsgp32T+1DWaRbPjWCicdkaxf2XaQr2IzgpUziQzlY9u WdcPjJ4PkHQLQ== 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 2/4] selftests/bpf: Use start_server_addr in bpf_tcp_ca Date: Sat, 11 May 2024 11:16:26 +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 | 46 +++++++++++++++---- 2 files changed, 37 insertions(+), 11 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 4eedc161b5b3..f50832b7838e 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -33,12 +33,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; @@ -48,7 +54,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) { @@ -88,6 +94,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; @@ -101,7 +111,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"); @@ -111,6 +121,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; @@ -124,7 +138,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); @@ -303,6 +317,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; @@ -315,14 +333,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"); @@ -332,6 +350,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; @@ -344,14 +366,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); @@ -360,6 +382,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; @@ -374,7 +400,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); From patchwork Sat May 11 03:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 796610 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 E6B9D24B5B; Sat, 11 May 2024 03:17: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=1715397421; cv=none; b=D+gO1NcoPSExQ2ovRL0fise4nUsji57P+hedhfNA964qBB0bU8wUSQyospasqmrzSQs003ObsvZp7ASJd/LrRFx/A3ijCDlueLrM+tGUfgBHzkSHgDkV0y6FVoewB+U+4drfIgjoqLbWqgFQQdhP1UWtLKFVcP0XM9nxcvuP4tI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715397421; c=relaxed/simple; bh=0vxgv25QFjc3cMV5VMfE90vkRVesX+DuyKQNxuqx5EY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JRRrhJ5JBx1Rz5rRZwpyoKErWakPUsHB+GIy9peAh7WKn7Wh9zwlGM7SBGyHhy9kcVn0VFytlKcCxN3sfeO3Uy0NEzDCkLcmj96FJKz32ZfLnQhlUlLYgb/YQpBNl2P/vfnD+Au0OobRwpyiaDjavC0LtTBdQiOC1ZfqnrmjkGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DFip1oKn; 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="DFip1oKn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF3E4C113CC; Sat, 11 May 2024 03:16:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715397420; bh=0vxgv25QFjc3cMV5VMfE90vkRVesX+DuyKQNxuqx5EY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DFip1oKnOl745yjEiGegO8P/nYgGsUsnqvXluXZp2ozNvZ+Zm7hZ04SlA9rje7y9E Iw7TmDl71jib7U3TVBN5HIEBIUjEqPX2f50iUjzufqY9iSR4ew2OOlDYSV7R6otEsj D3UUGvuLMzDc2ee3E5OqLAuPvJUmLkVhQ9uRiQluUKApeLAq/szkvBbP9QjFIipd2m NIsUHolnhKd+p6ICO01TqQGrnY2ZZtdaZwiqanX/ibyMqCQsgl1xS8AGwx9AFH/yMA yXQbj9ieCAIohs3l0THqbfDNEtHPWlK/UfOkhtWfMVp7rmKo14mDrlCuz3chD5szdv sW2c2fheTPTUg== 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 3/4] selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca Date: Sat, 11 May 2024 11:16:27 +0800 Message-ID: <983d40625775a3f330df5ad556ec2eba931ee51a.1715396405.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 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 f50832b7838e..bca30c32b819 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -48,25 +48,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) { @@ -119,11 +103,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; @@ -138,6 +132,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 Sat May 11 03:16:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 796286 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 6974F2D7A8; Sat, 11 May 2024 03:17:06 +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=1715397426; cv=none; b=Z3sWuFaDwwMM1bB/SPFu18hWZMsHRlHEnx1Ip9TuHOE4TKVYhxFmw4TH5n/jaXOAhJpk7Yja4ghyq+3JTcb/Pbs3s1AS6TF1EwUAlxe2ZJiEnbRxIYMY+vzxY+7j93/tvObXmW0Hs1028FNkexK4ciFqd5YXAL2ZGcpkxVWPvDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715397426; c=relaxed/simple; bh=ujYqDjMkiMlOcOnstTDDhc9seHskWrj4BUtZbN7bV3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BsnV0JDao9zfG9aw9XSdm51L+L+CfsByklQbsKNQbLK461/cc+x/eOMRzX9IWNu0XdcxEnSYsPBacOoVvWnIV2q3CiJqfQXzdu5RSAPSDEiy/VnxMXehK26/H1FVdHWAjGyDS6KW8djZZQ+DPEcHTnkJEZMDPcJEzeCy5XSOWls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n3SPX7uT; 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="n3SPX7uT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04A3FC32782; Sat, 11 May 2024 03:17:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715397426; bh=ujYqDjMkiMlOcOnstTDDhc9seHskWrj4BUtZbN7bV3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3SPX7uTYmcPI+PxIdmgYh3kV50eWrfC2NkcqeJ3g0ypGxid6+VMPgp0a+wzRJcqK IBhQ50A4oPrPGY48/5et5onK0KZoQirbl44JS+BgUtbSD7HBgwM7OJBe27M4vwx8KB NfV31uJuaDmxtpi8YQ3Ctdfjd1NU+PCFn2hlb0BZp+59gJd4vTEGcBlKi5OYNoYWQB yOArFtKnSOL1dtAJeT5KBV4OGVqwWGgtBoj8KvUR6ZQIJZDwFAn8Lsq9Nm0GV1hNmj FVl7uLH8XWcqcL+Ob2LRCAKzx+XQnVuDR3SQmQ9vjPLpgil+9rPL6DoTXaCB8Oo6pw WAvRqGDbuKbZg== 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 4/4] selftests/bpf: Add post_connect_cb callback Date: Sat, 11 May 2024 11:16:28 +0800 Message-ID: <2da67a207bfd53057db219e13bd68a7ee82d5d30.1715396405.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 | 6 ++- tools/testing/selftests/bpf/network_helpers.h | 1 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 41 ++++++++++--------- 3 files changed, 27 insertions(+), 21 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 bca30c32b819..0801b0c39cfe 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -33,13 +33,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; @@ -53,16 +51,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: @@ -95,7 +83,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"); @@ -113,11 +101,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; @@ -133,7 +134,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); @@ -328,14 +329,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"); @@ -361,14 +362,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); @@ -395,7 +396,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);