Commit fee97d0c authored by Geliang Tang's avatar Geliang Tang Committed by Daniel Borkmann

selftests/bpf: Add start_test helper in bpf_tcp_ca

For moving the "if (sk_stg_map)" block out of do_test(), extract the
code before this block as a new function start_test(). It creates
server-side and client-side sockets and returns them to the caller.
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/48f2921ff9be958f5d3d28fe6bb7269a61cafa9f.1717054461.git.tanggeliang@kylinos.cn
parent 9abdfd8a
...@@ -39,6 +39,34 @@ static int settcpca(int fd, const char *tcp_ca) ...@@ -39,6 +39,34 @@ static int settcpca(int fd, const char *tcp_ca)
return 0; return 0;
} }
static bool start_test(char *addr_str,
const struct network_helper_opts *srv_opts,
const struct network_helper_opts *cli_opts,
int *srv_fd, int *cli_fd)
{
*srv_fd = start_server_str(AF_INET6, SOCK_STREAM, addr_str, 0, srv_opts);
if (!ASSERT_NEQ(*srv_fd, -1, "start_server_str"))
goto err;
/* connect to server */
*cli_fd = connect_to_fd_opts(*srv_fd, cli_opts);
if (!ASSERT_NEQ(*cli_fd, -1, "connect_to_fd_opts"))
goto err;
return true;
err:
if (*srv_fd != -1) {
close(*srv_fd);
*srv_fd = -1;
}
if (*cli_fd != -1) {
close(*cli_fd);
*cli_fd = -1;
}
return false;
}
static void do_test(const struct network_helper_opts *opts, static void do_test(const struct network_helper_opts *opts,
const struct network_helper_opts *cli_opts, const struct network_helper_opts *cli_opts,
const struct bpf_map *sk_stg_map) const struct bpf_map *sk_stg_map)
...@@ -46,13 +74,7 @@ static void do_test(const struct network_helper_opts *opts, ...@@ -46,13 +74,7 @@ static void do_test(const struct network_helper_opts *opts,
int lfd = -1, fd = -1; int lfd = -1, fd = -1;
int err; int err;
lfd = start_server_str(AF_INET6, SOCK_STREAM, NULL, 0, opts); if (!start_test(NULL, opts, cli_opts, &lfd, &fd))
if (!ASSERT_NEQ(lfd, -1, "socket"))
return;
/* connect to server */
fd = connect_to_fd_opts(lfd, cli_opts);
if (!ASSERT_NEQ(fd, -1, "connect_to_fd_opts"))
goto done; goto done;
if (sk_stg_map) { if (sk_stg_map) {
...@@ -68,8 +90,10 @@ static void do_test(const struct network_helper_opts *opts, ...@@ -68,8 +90,10 @@ static void do_test(const struct network_helper_opts *opts,
ASSERT_OK(send_recv_data(lfd, fd, total_bytes), "send_recv_data"); ASSERT_OK(send_recv_data(lfd, fd, total_bytes), "send_recv_data");
done: done:
close(lfd); if (lfd != -1)
close(fd); close(lfd);
if (fd != -1)
close(fd);
} }
static int cc_cb(int fd, void *opts) static int cc_cb(int fd, void *opts)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment