On 10/27/25 7:51 AM, Alexis Lothoré (eBPF Foundation) wrote:
+static int run_server(struct subtest_cfg *cfg)
+{
+ struct nstoken *nstoken = open_netns(SERVER_NS);
It is unlikely but still better to check for open_netns failure. Just in
case that the network changes/traffic is accidentally done in the
original netns. There are a few netns switching in the test. Please
followup.
+ int family = cfg->ipproto == 6 ? AF_INET6 : AF_INET;
+
+ cfg->server_fd = start_reuseport_server(family, SOCK_STREAM,
+ cfg->server_addr, TEST_PORT,
+ TIMEOUT_MS, 1);
Why reuseport is needed? Does it have issue in bind() to the same
ip/port in the later sub-test?
+ close_netns(nstoken);
+ if (!ASSERT_NEQ(cfg->server_fd, NULL, "start server"))
I changed the check to ASSERT_OK_PTR. Also two other similar
ASSERT_[N]EQ(..., NULL, ...) usages.
+ return -1;
+
+ return 0;
+}
+
+static void stop_server(struct subtest_cfg *cfg)
+{
+ close(*cfg->server_fd);
NULL check on cfg->server_fd is needed during the error path of
run_test(). cfg->server_fd is leaked also. I changed it to
free_fds(cfg->server_fd, 1) instead.
+ cfg->server_fd = NULL;
I don't think cfg will be reused, so I skip this NULL assignment.
+}
+
+static int check_server_rx_data(struct subtest_cfg *cfg,
+ struct connection *conn, int len)
+{
+ int err;
+
+ memset(rx_buffer, 0, BUFFER_LEN);
+ err = recv(conn->server_fd, rx_buffer, len, 0);
+ if (!ASSERT_EQ(err, len, "check rx data len"))
+ return 1;
+ if (!ASSERT_MEMEQ(tx_buffer, rx_buffer, len, "check received data"))
+ return 1;
+ return 0;
+}
+
+static struct connection *connect_client_to_server(struct subtest_cfg *cfg)
+{
+ struct network_helper_opts opts = {.timeout_ms = 500};
+ int family = cfg->ipproto == 6 ? AF_INET6 : AF_INET;
+ struct connection *conn = NULL;
+ int client_fd, server_fd;
+
+ conn = malloc(sizeof(struct connection));
+ if (!conn)
+ return conn;
+
+ client_fd = connect_to_addr_str(family, SOCK_STREAM, cfg->server_addr,
+ TEST_PORT, &opts);
+
+ if (client_fd < 0) {
+ free(conn);
+ return NULL;
+ }
+
+ server_fd = accept(*cfg->server_fd, NULL, NULL);
+ if (server_fd < 0) {
Fixed the client_fd leak.
Applied. Thanks.