Revert "system-linux: set pending to 0 on ifindex found or error for if_get_master"
authorFelix Fietkau <nbd@nbd.name>
Tue, 19 Dec 2023 21:32:56 +0000 (22:32 +0100)
committerFelix Fietkau <nbd@nbd.name>
Tue, 19 Dec 2023 21:34:14 +0000 (22:34 +0100)
This reverts commit 66a7652176a7580b55076a0975b77c2bfb5bf7ce.
Users reported that netifd hangs after this commit. I suspect that the added
optimization which sets data->pending to false early might be the cause.
It might leave unprocessed netlink messages in the socket, which could mess up
the next netlink call.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
system-linux.c

index 0092fec02133d5fbde352393b8583ffd3a73f689..e7945e3330a80fd14824bfd83bd7f50501c5f6ed 100644 (file)
@@ -1730,7 +1730,7 @@ int system_vlandev_del(struct device *vlandev)
 struct if_get_master_data {
        int ifindex;
        int master_ifindex;
-       bool pending;
+       int pending;
 };
 
 static void if_get_master_dsa_linkinfo_attr(struct if_get_master_data *data,
@@ -1744,7 +1744,6 @@ static void if_get_master_dsa_linkinfo_attr(struct if_get_master_data *data,
                        continue;
 
                data->master_ifindex = *(__u32 *)RTA_DATA(cur);
-               return;
        }
 }
 
@@ -1759,7 +1758,7 @@ static void if_get_master_linkinfo_attr(struct if_get_master_data *data,
                        continue;
 
                if (cur->rta_type == IFLA_INFO_KIND && strcmp("dsa", (char *)RTA_DATA(cur)))
-                       return;
+                       break;
 
                if (cur->rta_type == IFLA_INFO_DATA)
                        if_get_master_dsa_linkinfo_attr(data, cur);
@@ -1787,11 +1786,8 @@ static int cb_if_get_master_valid(struct nl_msg *msg, void *arg)
        rem = nh->nlmsg_len - NLMSG_LENGTH(sizeof(*ifi));
 
        while (RTA_OK(attr, rem)) {
-               if (attr->rta_type == IFLA_LINKINFO) {
+               if (attr->rta_type == IFLA_LINKINFO)
                        if_get_master_linkinfo_attr(data, attr);
-                       data->pending = false;
-                       break;
-               }
 
                attr = RTA_NEXT(attr, rem);
        }
@@ -1802,16 +1798,14 @@ static int cb_if_get_master_valid(struct nl_msg *msg, void *arg)
 static int cb_if_get_master_ack(struct nl_msg *msg, void *arg)
 {
        struct if_get_master_data *data = (struct if_get_master_data *)arg;
-       data->pending = false;
-
+       data->pending = 0;
        return NL_STOP;
 }
 
 static int cb_if_get_master_error(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg)
 {
        struct if_get_master_data *data = (struct if_get_master_data *)arg;
-       data->pending = false;
-
+       data->pending = 0;
        return NL_STOP;
 }
 
@@ -1826,7 +1820,7 @@ static int system_if_get_master_ifindex(struct device *dev)
        struct if_get_master_data data = {
                .ifindex = if_nametoindex(dev->ifname),
                .master_ifindex = -1,
-               .pending = true,
+               .pending = 1,
        };
        int ret = -1;
 
@@ -1849,7 +1843,7 @@ static int system_if_get_master_ifindex(struct device *dev)
        if (ret < 0)
                goto free;
 
-       while (data.pending)
+       while (data.pending > 0)
                nl_recvmsgs(sock_rtnl, cb);
 
        if (data.master_ifindex >= 0)