X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=interface.c;h=057616669cafaa040b85237ffc638dc03f2a51fa;hp=8be8727906ea5636d567b9c9f56e79d9801aa788;hb=fd4efb1bbfe5a502a802f43871cfae9944c8d75f;hpb=aa76c9ee78146f97512f96524d3abb94210040a5 diff --git a/interface.c b/interface.c index 8be8727..0576166 100644 --- a/interface.c +++ b/interface.c @@ -26,7 +26,7 @@ void interface_add_error(struct interface *iface, const char *subsystem, { struct interface_error *error; int i, len = 0; - int *datalen; + int *datalen = NULL; char *dest; if (n_data) { @@ -81,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; @@ -103,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 @@ -131,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); @@ -162,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; } @@ -176,7 +175,7 @@ void interface_set_proto_state(struct interface *iface, struct interface_proto_s } struct interface * -alloc_interface(const char *name) +alloc_interface(const char *name, struct uci_section *s) { struct interface *iface; @@ -185,19 +184,14 @@ alloc_interface(const char *name) return iface; iface = calloc(1, sizeof(*iface)); - - interface_set_proto_state(iface, get_default_proto()); - if (!iface->proto) { - free(iface); - return NULL; - } - iface->main_dev.cb = interface_cb; iface->l3_iface = &iface->main_dev; strncpy(iface->name, name, sizeof(iface->name) - 1); list_add(&iface->list, &interfaces); INIT_LIST_HEAD(&iface->errors); + proto_attach_interface(iface, s); + netifd_ubus_add_interface(iface); return iface; @@ -226,12 +220,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; } @@ -239,17 +233,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; } @@ -278,3 +272,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); + } +}