clean up variable names (llif -> dev)
[project/netifd.git] / interface.c
index 78cfe12..ba7b5e5 100644 (file)
@@ -3,6 +3,8 @@
 #include <stdio.h>
 
 #include "netifd.h"
+#include "device.h"
+#include "interface.h"
 #include "proto.h"
 #include "ubus.h"
 
@@ -59,6 +61,13 @@ interface_event(struct interface *iface, enum interface_event ev)
        /* TODO */
 }
 
+static void
+mark_interface_down(struct interface *iface)
+{
+       release_device(iface->main_dev.dev);
+       iface->state = IFS_DOWN;
+}
+
 static int
 __set_interface_up(struct interface *iface)
 {
@@ -69,20 +78,17 @@ __set_interface_up(struct interface *iface)
 
        ret = claim_device(iface->main_dev.dev);
        if (ret)
-               goto out;
+               return ret;
 
        iface->state = IFS_SETUP;
        ret = iface->proto->handler(iface->proto, PROTO_CMD_SETUP, false);
-       if (ret)
-               goto release;
+       if (ret) {
+               mark_interface_down(iface);
+               return ret;
+       }
 
        return 0;
 
-release:
-       release_device(iface->main_dev.dev);
-out:
-       iface->state = IFS_DOWN;
-       return ret;
 }
 
 static void
@@ -145,7 +151,10 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
                interface_event(iface, IFEV_UP);
                break;
        case IFPEV_DOWN:
-               iface->state = IFS_DOWN;
+               if (iface->state == IFS_DOWN)
+                       return;
+
+               mark_interface_down(iface);
                break;
        }
 }
@@ -217,12 +226,12 @@ get_interface(const char *name)
 }
 
 void
-interface_remove_link(struct interface *iface, struct device *llif)
+interface_remove_link(struct interface *iface, struct device *dev)
 {
-       struct device *dev = iface->main_dev.dev;
+       struct device *mdev = iface->main_dev.dev;
 
-       if (dev && dev->hotplug_ops) {
-               dev->hotplug_ops->del(dev, llif);
+       if (mdev && mdev->hotplug_ops) {
+               mdev->hotplug_ops->del(mdev, dev);
                return;
        }
 
@@ -230,17 +239,17 @@ interface_remove_link(struct interface *iface, struct device *llif)
 }
 
 int
-interface_add_link(struct interface *iface, struct device *llif)
+interface_add_link(struct interface *iface, struct device *dev)
 {
-       struct device *dev = iface->main_dev.dev;
+       struct device *mdev = iface->main_dev.dev;
 
-       if (dev && dev->hotplug_ops)
-               return dev->hotplug_ops->add(dev, llif);
+       if (mdev && mdev->hotplug_ops)
+               return mdev->hotplug_ops->add(mdev, dev);
 
        if (iface->main_dev.dev)
                interface_remove_link(iface, NULL);
 
-       add_device_user(&iface->main_dev, llif);
+       add_device_user(&iface->main_dev, dev);
 
        return 0;
 }