use network helpers, part 5
Subsystems (3)
cover use network helpers, part 5
From: Geliang Tang <[email protected]>
This patchset uses post_socket_cb and post_connect_cb callbacks of struct network_helper_opts to refactor do_test() in bpf_tcp_ca.c to move dctcp test dedicated code out of do_test() into test_dctcp().
Patch 3 adds a new member in post_socket_opts and patch 4 adds a new callback in network_helper_opts. I'm not sure if this is going too far.
Geliang Tang (4):
selftests/bpf: Use post_socket_cb in connect_to_fd_opts selftests/bpf: Use start_server_addr in bpf_tcp_ca selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca selftests/bpf: Add post_connect_cb callback
tools/testing/selftests/bpf/network_helpers.c | 13 ++- tools/testing/selftests/bpf/network_helpers.h | 8 +- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 105 +++++++++++------- 3 files changed, 81 insertions(+), 45 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 selftests/bpf: Use post_socket_cb in connect_to_fd_opts
From: Geliang Tang <[email protected]>
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.
--- 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(-)
tools/testing/selftests/bpf/network_helpers.c +2 -3
@@ -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)
tools/testing/selftests/bpf/network_helpers.h +4 -2
@@ -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 */
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +8 -1
@@ -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 ;
Signature · 1 line
2.43.0
PATCH 2/4 selftests/bpf: Use start_server_addr in bpf_tcp_ca
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
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().
--- tools/testing/selftests/bpf/network_helpers.c | 2 +- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 46 +++++++++++++++---- 2 files changed, 37 insertions(+), 11 deletions(-)
tools/testing/selftests/bpf/network_helpers.c +1 -1
@@ -94,7 +94,7 @@ static int __start_server(int type, const struct sockaddr *addr, socklen_t addrlif (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; }
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +36 -10
134 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 3/4 selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
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.
--- tools/testing/selftests/bpf/network_helpers.h | 1 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 33 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-)
tools/testing/selftests/bpf/network_helpers.h +1 -0
@@ -23,6 +23,7 @@ typedef __u16 __sum16;struct post_socket_opts {const char *cc; +int map_fd; };struct network_helper_opts {
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +14 -19
@@ -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" );
Signature · 1 line
2.43.0
PATCH 4/4 selftests/bpf: Add post_connect_cb callback
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
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().
--- 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(-)
tools/testing/selftests/bpf/network_helpers.c +5 -1
@@ -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:
tools/testing/selftests/bpf/network_helpers.h +1 -0
@@ -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; };
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +21 -20
110 lines not on this page · raw message
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH bpf-next 4/4] selftests/bpf: Add post_connect_cb callback
:::::: :::::: Manual check reason: "low confidence bisect report" ::::::
::::::
:::::: Manual check reason: "low confidence bisect report" ::::::
BCC: [email protected]
CC: [email protected]
In-Reply-To: <2da67a207bfd53057db219e13bd68a7ee82d5d30.1715396405.git.tanggeliang@kylinos.cn>
References: <2da67a207bfd53057db219e13bd68a7ee82d5d30.1715396405.git.tanggeliang@kylinos.cn>
TO: Geliang Tang <[email protected]>
TO: Andrii Nakryiko <[email protected]>
TO: Eduard Zingerman <[email protected]>
TO: Mykola Lysenko <[email protected]>
TO: Alexei Starovoitov <[email protected]>
TO: Daniel Borkmann <[email protected]>
TO: Martin KaFai Lau <[email protected]>
TO: Song Liu <[email protected]>
TO: Yonghong Song <[email protected]>
TO: John Fastabend <[email protected]>
TO: KP Singh <[email protected]>
TO: Stanislav Fomichev <[email protected]>
TO: Hao Luo <[email protected]>
TO: Jiri Olsa <[email protected]>
TO: Shuah Khan <[email protected]>
CC: Geliang Tang <[email protected]>
CC: [email protected]
CC: [email protected]
Hi Geliang,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Geliang-Tang/selftests-bpf-Use-post_socket_cb-in-connect_to_fd_opts/20240511-111755 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/2da67a207bfd53057db219e13bd68a7ee82d5d30.1715396405.git.tanggeliang%40kylinos.cn patch subject: [PATCH bpf-next 4/4] selftests/bpf: Add post_connect_cb callback
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240514/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
All errors (new ones prefixed by >>):
>> tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c:500:26: error: too many arguments to function call, expected single argument 'opts', have 2 arguments
500 | do_test("bpf_cc_cubic", NULL);
| ~~~~~~~ ^~~~
/opt/cross/clang-617a15a9ea/lib/clang/18/include/__stddef_null.h:26:14: note: expanded from macro 'NULL'
26 | #define NULL ((void*)0)
| ^~~~~~~~~~ tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c:37:13: note: 'do_test' declared here
37 | static void do_test(const struct network_helper_opts *opts)
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
vim +/opts +500 tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
5da7fb04902b0f Martin KaFai Lau 2024-03-22 484
96c3490d6423b7 Miao Xu 2024-05-01 485 static void test_cc_cubic(void)
96c3490d6423b7 Miao Xu 2024-05-01 486 {
96c3490d6423b7 Miao Xu 2024-05-01 487 struct bpf_cc_cubic *cc_cubic_skel;
96c3490d6423b7 Miao Xu 2024-05-01 488 struct bpf_link *link;
96c3490d6423b7 Miao Xu 2024-05-01 489
96c3490d6423b7 Miao Xu 2024-05-01 490 cc_cubic_skel = bpf_cc_cubic__open_and_load();
96c3490d6423b7 Miao Xu 2024-05-01 491 if (!ASSERT_OK_PTR(cc_cubic_skel, "bpf_cc_cubic__open_and_load"))
96c3490d6423b7 Miao Xu 2024-05-01 492 return;
96c3490d6423b7 Miao Xu 2024-05-01 493
96c3490d6423b7 Miao Xu 2024-05-01 494 link = bpf_map__attach_struct_ops(cc_cubic_skel->maps.cc_cubic);
96c3490d6423b7 Miao Xu 2024-05-01 495 if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
96c3490d6423b7 Miao Xu 2024-05-01 496 bpf_cc_cubic__destroy(cc_cubic_skel);
96c3490d6423b7 Miao Xu 2024-05-01 497 return;
96c3490d6423b7 Miao Xu 2024-05-01 498 }
96c3490d6423b7 Miao Xu 2024-05-01 499
96c3490d6423b7 Miao Xu 2024-05-01 @500 do_test("bpf_cc_cubic", NULL);
96c3490d6423b7 Miao Xu 2024-05-01 501
96c3490d6423b7 Miao Xu 2024-05-01 502 bpf_link__destroy(link);
96c3490d6423b7 Miao Xu 2024-05-01 503 bpf_cc_cubic__destroy(cc_cubic_skel);
96c3490d6423b7 Miao Xu 2024-05-01 504 }
96c3490d6423b7 Miao Xu 2024-05-01 505 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki