X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=interface.c;h=8627d97d652bfd6f6fe3d92df1553059000e950a;hb=e4aebda4d774d0b92f4c95c4490745aaedf4cd35;hp=e66b58a1da658b876f1af4a939592f4924f2396e;hpb=5844d3caa26f5f8810476836a8b711107e4ba8d7;p=project%2Fnetifd.git diff --git a/interface.c b/interface.c index e66b58a..8627d97 100644 --- a/interface.c +++ b/interface.c @@ -652,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); @@ -673,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 = @@ -832,8 +835,8 @@ interface_remove_link(struct interface *iface, struct device *dev) return 0; } -int -interface_add_link(struct interface *iface, struct device *dev) +static int +interface_add_link(struct interface *iface, struct device *dev, bool link_ext) { struct device *mdev = iface->main_dev.dev; @@ -850,21 +853,23 @@ interface_add_link(struct interface *iface, struct device *dev) return UBUS_STATUS_NOT_SUPPORTED; } - device_add_user(&iface->ext_dev, dev); + if (link_ext) + device_add_user(&iface->ext_dev, dev); + interface_set_main_dev(iface, dev); iface->main_dev.hotplug = true; return 0; } int -interface_handle_link(struct interface *iface, const char *name, bool add) +interface_handle_link(struct interface *iface, const char *name, bool add, bool link_ext) { struct device *dev; int ret; device_lock(); - dev = device_get(name, add ? 2 : 0); + dev = device_get(name, add ? (link_ext ? 2 : 1) : 0); if (!dev) { ret = UBUS_STATUS_NOT_FOUND; goto out; @@ -876,7 +881,7 @@ interface_handle_link(struct interface *iface, const char *name, bool add) device_set_config(dev, &simple_device_type, iface->config); system_if_apply_settings(dev, &dev->settings, dev->settings.flags); - ret = interface_add_link(iface, dev); + ret = interface_add_link(iface, dev, link_ext); } else { ret = interface_remove_link(iface, dev); }