[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2c66f688-988f-4f55-a822-de5686178b1a@linux.dev>
Date: Fri, 11 Jul 2025 17:23:06 -0700
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Jordan Rife <jordan@...fe.io>
Cc: Daniel Borkmann <daniel@...earbox.net>,
Willem de Bruijn <willemdebruijn.kernel@...il.com>,
Kuniyuki Iwashima <kuniyu@...gle.com>,
Alexei Starovoitov <alexei.starovoitov@...il.com>,
Stanislav Fomichev <stfomichev@...il.com>, netdev@...r.kernel.org,
bpf@...r.kernel.org
Subject: Re: [PATCH v5 bpf-next 10/12] selftests/bpf: Create established
sockets in socket iterator tests
On 7/9/25 4:03 PM, Jordan Rife wrote:
>
> +static int accept_from_one(int *server_fds, int server_fds_len)
> +{
> + int fd;
> + int i;
> +
> + for (i = 0; i < server_fds_len; i++) {
> + fd = accept(server_fds[i], NULL, NULL);
> + if (fd >= 0)
> + return fd;
> + if (!ASSERT_EQ(errno, EWOULDBLOCK, "EWOULDBLOCK"))
> + return -1;
> + }
> +
> + return -1;
After looking at the set again before landing, I suspect there is a chance that
this function may return -1 here if the final ack of the 3WHS has not been
received yet.
> +}
> +
> +static int *connect_to_server(int family, int sock_type, const char *addr,
> + __u16 port, int nr_connects, int *server_fds,
> + int server_fds_len)
> +{
> + struct network_helper_opts opts = {
> + .timeout_ms = 0,
> + };
> + int *established_socks;
> + int i;
> +
> + /* Make sure accept() doesn't block. */
> + for (i = 0; i < server_fds_len; i++)
> + if (!ASSERT_OK(fcntl(server_fds[i], F_SETFL, O_NONBLOCK),
> + "fcntl(O_NONBLOCK)"))
server_fds is non-blocking.
> + return NULL;
> +
> + established_socks = malloc(sizeof(int) * nr_connects*2);
> + if (!ASSERT_OK_PTR(established_socks, "established_socks"))
> + return NULL;
> +
> + i = 0;
> +
> + while (nr_connects--) {
> + established_socks[i] = connect_to_addr_str(family, sock_type,
> + addr, port, &opts);
connect returns as soon as the syn-ack is received.
> + if (!ASSERT_OK_FD(established_socks[i], "connect_to_addr_str"))
> + goto error;
> + i++;
> + established_socks[i] = accept_from_one(server_fds,
> + server_fds_len);
I am not sure the final ack is always received by the server at this point. If
not, the test could be flaky. Is this case possible? and is it better to
poll/select for a fixed number of seconds?
> + if (!ASSERT_OK_FD(established_socks[i], "accept_from_one"))
> + goto error;
> + i++;
> + }
> +
> + return established_socks;
> +error:
> + free_fds(established_socks, i);
> + return NULL;
> +}
Powered by blists - more mailing lists