On 1/3/25 2:10 AM, Bastien Curutchet (eBPF Foundation) wrote:
+static int ping_setup(struct test_data *data)
+{
+ struct nstoken *nstoken = NULL;
+ int i;
+
+ data->ns[0] = netns_new(NS0, false);
+ if (!ASSERT_OK_PTR(data->ns[0], "create ns"))
+ return -1;
+
+ for (i = 1; i < NS_NB; i++) {
+ char ns_name[4] = {};
+
+ snprintf(ns_name, 4, "NS%d", i);
+ data->ns[i] = netns_new(ns_name, false);
+ if (!ASSERT_OK_PTR(data->ns[i], "create ns"))
+ goto fail;
+
+ nstoken = open_netns(NS0);
+ if (!ASSERT_OK_PTR(nstoken, "open NS0"))
+ goto fail;
+
+ SYS(fail, "ip link add veth%d index %d%d%d type veth peer name veth0 netns %s",
+ i, i, i, i, ns_name);
+ SYS(fail, "ip link set veth%d up", i);
+ close_netns(nstoken);
+
+ nstoken = open_netns(ns_name);
+ if (!ASSERT_OK_PTR(nstoken, "open ns"))
+ goto fail;
+
+ SYS(fail, "ip addr add %s.%d/24 dev veth0", IPV4_NETWORK, i);
+ SYS(fail, "ip link set veth0 up");
+ close_netns(nstoken);
nstoken = NULL;
Otherwise, the other "goto fail;" of this loop will close and free the already
closed nstoken again.
Some of the other close_netns(nstoken) in this patch may have similar issue.
+ }
+
+ return 0;
+
+fail:
+ close_netns(nstoken);
+ cleanup(data);
+ return -1;
+}