]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
selftests/bpf: Use connect_fd_to_fd in bpf_tcp_ca
authorGeliang Tang <tanggeliang@kylinos.cn>
Tue, 26 Mar 2024 10:03:38 +0000 (18:03 +0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Fri, 29 Mar 2024 02:12:14 +0000 (19:12 -0700)
To simplify the code, use BPF selftests helper connect_fd_to_fd() in
bpf_tcp_ca.c instead of open-coding it. This helper is defined in
network_helpers.c, and exported in network_helpers.h, which is already
included in bpf_tcp_ca.c.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/e105d1f225c643bee838409378dd90fd9aabb6dc.1711447102.git.tanggeliang@kylinos.cn
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c

index 332ed54cc6af2385e51dc6806407e6a5f997f639..2f6b8b2780e6440b227757c23d9c92a3348f769d 100644 (file)
@@ -79,11 +79,9 @@ done:
 
 static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
 {
-       struct sockaddr_in6 sa6 = {};
        ssize_t nr_recv = 0, bytes = 0;
        int lfd = -1, fd = -1;
        pthread_t srv_thread;
-       socklen_t addrlen = sizeof(sa6);
        void *thread_ret;
        char batch[1500];
        int err;
@@ -104,10 +102,6 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
            settimeo(lfd, 0) || settimeo(fd, 0))
                goto done;
 
-       err = getsockname(lfd, (struct sockaddr *)&sa6, &addrlen);
-       if (!ASSERT_NEQ(err, -1, "getsockname"))
-               goto done;
-
        if (sk_stg_map) {
                err = bpf_map_update_elem(bpf_map__fd(sk_stg_map), &fd,
                                          &expected_stg, BPF_NOEXIST);
@@ -116,7 +110,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
        }
 
        /* connect to server */
-       err = connect(fd, (struct sockaddr *)&sa6, addrlen);
+       err = connect_fd_to_fd(fd, lfd, 0);
        if (!ASSERT_NEQ(err, -1, "connect"))
                goto done;