summaryrefslogtreecommitdiff
path: root/device.c
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2014-11-13 15:57:56 +0000
committerSteven Barth <steven@midlink.org>2014-11-19 09:30:12 +0100
commitfe08cfd2bfb389f7c174e2dd1561ba4a381db213 (patch)
treec545a179666bb2358647b60ef6f177e487fe7c53 /device.c
parent248ec27b62439662f28deab08adb9ee4e906f3b6 (diff)
downloadnetifd-fe08cfd2bfb389f7c174e2dd1561ba4a381db213.tar.gz
netifd: Fix device ifindex overwrite when processing netlink event messages
When a device with the same name is deleted and created again in the kernel the ifindex changes. A race condition will occur when netlink event messages linked to the old device are processed and will thus overwrite the correct ifindex of the new device. Further make sure a valid ifindex is in place for both external and internal devices when setting the state to enabled. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'device.c')
-rw-r--r--device.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/device.c b/device.c
index b29d73b..5d1dcac 100644
--- a/device.c
+++ b/device.c
@@ -62,6 +62,14 @@ void device_unlock(void)
static int set_device_state(struct device *dev, bool state)
{
+ if (state) {
+ /* Set ifindex for all devices being enabled so a valid */
+ /* ifindex is in place avoiding possible race conditions */
+ device_set_ifindex(dev, system_if_resolve(dev));
+ if (!dev->ifindex)
+ return -1;
+ }
+
if (dev->external)
return 0;