X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=interface.c;h=ed6095936700e0cd35c4c91779822bd73769f5e2;hb=c09e944416d76ed162efc55483f987cd537c2c8b;hp=a4d7b8de2dee7cafe4157d8cabbaf2472337030a;hpb=4b7662c5841214c105a174fdc9ab9fac870abab9;p=project%2Fnetifd.git diff --git a/interface.c b/interface.c index a4d7b8d..ed60959 100644 --- a/interface.c +++ b/interface.c @@ -308,6 +308,13 @@ interface_set_link_state(struct interface *iface, bool new_state) } static void +interface_ext_cb(struct device_user *dep, enum device_event ev) +{ + if (ev == DEV_EVENT_REMOVE) + device_remove_user(dep); +} + +static void interface_cb(struct device_user *dep, enum device_event ev) { struct interface *iface; @@ -319,7 +326,7 @@ interface_cb(struct device_user *dep, enum device_event ev) new_state = true; case DEV_EVENT_REMOVE: interface_set_available(iface, new_state); - if (!new_state && dep->dev->external) + if (!new_state && dep->dev && dep->dev->external) interface_set_main_dev(iface, NULL); break; case DEV_EVENT_UP: @@ -329,7 +336,7 @@ interface_cb(struct device_user *dep, enum device_event ev) break; case DEV_EVENT_LINK_UP: new_state = true; - case DEV_EVENT_LINK_DOWN: + case DEV_EVENT_LINK_DOWN: interface_set_link_state(iface, new_state); break; case DEV_EVENT_TOPO_CHANGE: @@ -491,6 +498,8 @@ interface_claim_device(struct interface *iface) } else if (iface->ifname && !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) { dev = device_get(iface->ifname, true); + } else { + dev = iface->ext_dev.dev; } if (dev) @@ -509,8 +518,8 @@ interface_cleanup_state(struct interface *iface) interface_clear_errors(iface); interface_set_proto_state(iface, NULL); - if (iface->main_dev.dev) - interface_set_main_dev(iface, NULL); + interface_set_main_dev(iface, NULL); + interface_set_l3_dev(iface, NULL); } static void @@ -518,6 +527,8 @@ interface_cleanup(struct interface *iface) { struct interface_user *dep, *tmp; + device_remove_user(&iface->ext_dev); + if (iface->parent_iface.iface) interface_remove_user(&iface->parent_iface); @@ -641,6 +652,7 @@ interface_alloc(const char *name, struct blob_attr *config) struct blob_attr *cur; const char *proto_name = NULL; char *iface_name; + bool force_link = false; iface = calloc_a(sizeof(*iface), &iface_name, strlen(name) + 1); iface->name = strcpy(iface_name, name); @@ -653,6 +665,7 @@ interface_alloc(const char *name, struct blob_attr *config) iface->config_ip.enabled = false; iface->main_dev.cb = interface_cb; + iface->ext_dev.cb = interface_ext_cb; blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb, blob_data(config), blob_len(config)); @@ -661,9 +674,11 @@ interface_alloc(const char *name, struct blob_attr *config) proto_name = blobmsg_data(cur); proto_attach_interface(iface, proto_name); + if (iface->proto_handler->flags & PROTO_FLAG_FORCE_LINK_DEFAULT) + force_link = true; iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true); - iface->force_link = blobmsg_get_bool_default(tb[IFACE_ATTR_FORCE_LINK], false); + iface->force_link = blobmsg_get_bool_default(tb[IFACE_ATTR_FORCE_LINK], force_link); iface->proto_ip.no_defaultroute = !blobmsg_get_bool_default(tb[IFACE_ATTR_DEFAULTROUTE], true); iface->proto_ip.no_dns = @@ -709,6 +724,7 @@ interface_alloc(const char *name, struct blob_attr *config) void interface_set_dynamic(struct interface *iface) { iface->dynamic = true; + iface->autostart = true; iface->node.version = -1; // Don't delete on reload } @@ -766,8 +782,10 @@ interface_set_l3_dev(struct interface *iface, struct device *dev) device_add_user(&iface->l3_dev, dev); if (dev) { - if (claimed) - device_claim(&iface->l3_dev); + if (claimed) { + if (device_claim(&iface->l3_dev) < 0) + return; + } interface_ip_set_enabled(&iface->config_ip, enabled); } } @@ -787,8 +805,10 @@ interface_set_main_dev(struct interface *iface, struct device *dev) return; } - if (claimed) - device_claim(&iface->l3_dev); + if (claimed) { + if (device_claim(&iface->l3_dev) < 0) + return; + } if (!iface->l3_dev.dev) interface_set_l3_dev(iface, dev); @@ -802,6 +822,9 @@ interface_remove_link(struct interface *iface, struct device *dev) if (mdev && mdev->hotplug_ops) return mdev->hotplug_ops->del(mdev, dev); + if (dev == iface->ext_dev.dev) + device_remove_user(&iface->ext_dev); + if (!iface->main_dev.hotplug) return UBUS_STATUS_INVALID_ARGUMENT; @@ -830,6 +853,7 @@ interface_add_link(struct interface *iface, struct device *dev) return UBUS_STATUS_NOT_SUPPORTED; } + device_add_user(&iface->ext_dev, dev); interface_set_main_dev(iface, dev); iface->main_dev.hotplug = true; return 0;