From a2d32f0dcf16880226680d07b07b249f77a3af58 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 19 Dec 2023 22:32:56 +0100 Subject: [PATCH] Revert "system-linux: set pending to 0 on ifindex found or error for if_get_master" 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 --- system-linux.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/system-linux.c b/system-linux.c index 0092fec..e7945e3 100644 --- a/system-linux.c +++ b/system-linux.c @@ -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) -- 2.30.2