add some configuration code for interfaces, bind interfaces to regular devices
[project/netifd.git] / interface.c
index e12d356..06a36ed 100644 (file)
@@ -3,6 +3,8 @@
 #include <stdio.h>
 
 #include "netifd.h"
+#include "device.h"
+#include "interface.h"
 #include "proto.h"
 #include "ubus.h"
 
@@ -79,7 +81,7 @@ __set_interface_up(struct interface *iface)
                return ret;
 
        iface->state = IFS_SETUP;
-       ret = iface->proto->handler(iface->proto, PROTO_CMD_SETUP, false);
+       ret = interface_proto_event(iface->proto, PROTO_CMD_SETUP, false);
        if (ret) {
                mark_interface_down(iface);
                return ret;
@@ -101,8 +103,7 @@ __set_interface_down(struct interface *iface, bool force)
        iface->state = IFS_TEARDOWN;
        interface_event(iface, IFEV_DOWN);
 
-       iface->proto->handler(iface->proto, PROTO_CMD_TEARDOWN, force);
-       release_device(iface->main_dev.dev);
+       interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, force);
 }
 
 static void
@@ -129,7 +130,7 @@ interface_cb(struct device_user *dep, enum device_event ev)
        iface->active = new_state;
 
        if (new_state) {
-               if (iface->autostart)
+               if (iface->autostart && !config_init)
                        set_interface_up(iface);
        } else
                __set_interface_down(iface, true);
@@ -160,7 +161,7 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state)
 {
        if (iface->proto) {
-               iface->proto->handler(iface->proto, PROTO_CMD_TEARDOWN, true);
+               interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, true);
                iface->proto->free(iface->proto);
                iface->proto = NULL;
        }
@@ -224,12 +225,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;
        }
 
@@ -237,17 +238,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;
 }
@@ -276,3 +277,14 @@ set_interface_down(struct interface *iface)
 
        return 0;
 }
+
+void
+start_pending_interfaces(void)
+{
+       struct interface *iface;
+
+       list_for_each_entry(iface, &interfaces, list) {
+               if (iface->active && iface->autostart)
+                       set_interface_up(iface);
+       }
+}