[OpenWrt-Devel] [PATCH 3/3] [V2] netifd: Read current link state when processing netlink event

Hans Dedecker dedeckeh at gmail.com
Thu Oct 23 05:13:44 EDT 2014

Netifd commit b2dcb02570939d98b92c7c55db1c328693a5d52a introduces
a race condition resulting into infinite toggling interfaces
(eg static interfaces with linksensing enabled, vlan interfaces
with proto none (#18106)) when linksensing is enabled resulting into
a crash.
As netlink event messages will be queued on the netlink event socket
the included lower up interface flag will not always represent the
current link state when netifd processes the netlink messages;
by reading the current link state when a netlink event message is
parsed the correct info is passed to the device layer.
This will avoid continuous interface toggling (down/up) triggered
by link state changes based on outdated netlink interface info.

Signed-off-by: Hans Dedecker <dedeckeh at gmail.com>
 system-linux.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/system-linux.c b/system-linux.c
index 7ae9e27..295256f 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -299,16 +299,14 @@ static int system_get_disable_ipv6(struct device *dev, char *buf, const size_t b
 			dev->ifname, buf, buf_sz);
-#ifndef IFF_LOWER_UP
-#define IFF_LOWER_UP	0x10000
 // Evaluate netlink messages
 static int cb_rtnl_event(struct nl_msg *msg, void *arg)
 	struct nlmsghdr *nh = nlmsg_hdr(msg);
 	struct ifinfomsg *ifi = NLMSG_DATA(nh);
 	struct nlattr *nla[__IFLA_MAX];
+	int link_state = 0;
+	char buf[10];
 	if (nh->nlmsg_type != RTM_NEWLINK)
 		goto out;
@@ -322,8 +320,13 @@ static int cb_rtnl_event(struct nl_msg *msg, void *arg)
 		goto out;
 	device_set_ifindex(dev, ifi->ifi_index);
-	if (!dev->type->keep_link_status)
-		device_set_link(dev, ifi->ifi_flags & IFF_LOWER_UP ? true : false);
+	if (dev->type->keep_link_status)
+		goto out;
+	if (!system_get_dev_sysctl("/sys/class/net/%s/carrier", dev->ifname, buf, sizeof(buf)))
+		link_state = strtoul(buf, NULL, 0);
+	device_set_link(dev, link_state ? true : false);
 	return 0;
@@ -1020,6 +1023,10 @@ struct if_check_data {
 	int ret;
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP	0x10000
 static int cb_if_check_valid(struct nl_msg *msg, void *arg)
 	struct nlmsghdr *nh = nlmsg_hdr(msg);
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list