device: Resolve ifindex for external claimed devices
authorHans Dedecker <dedeckeh@gmail.com>
Wed, 9 Sep 2015 13:45:47 +0000 (15:45 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 10 Sep 2015 20:49:34 +0000 (22:49 +0200)
Fixes regression issues introduced by commit 3224b80 as external (PPP)
device ifindex was not in sync with kernel device ifindex due to re-creation
of the device by the PPP daemon

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
device.c

index 21b436f9dbd2c2e665d5a2fcec9571d71aab4dab..a29c981e334c3206e8fc1bd1d4d4987b3c8ee68e 100644 (file)
--- a/device.c
+++ b/device.c
@@ -74,15 +74,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  */
+               /* Get 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 (state)
                system_if_up(dev);
+       }
        else
                system_if_down(dev);
 
@@ -332,7 +331,13 @@ int device_claim(struct device_user *dep)
                return 0;
 
        device_broadcast_event(dev, DEV_EVENT_SETUP);
-       if (!dev->external)
+       if (dev->external) {
+               /* Get ifindex for external claimed devices so a valid   */
+               /* ifindex is in place avoiding possible race conditions */
+               device_set_ifindex(dev, system_if_resolve(dev));
+               if (!dev->ifindex)
+                       ret = -1;
+       } else
                ret = dev->set_state(dev, true);
 
        if (ret == 0)