@@ -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 *co = (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, co->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) {
@@ -125,13 +109,24 @@ 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 = cc_cb(fd, opts);
+ if (err)
+ return err;
+ return bpf_map_update_elem(cb_opts->map_fd, &fd, &expected_stg, BPF_NOEXIST);
+}
+
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;
@@ -147,6 +142,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");