netifd: Allow to add link devices which can be marked as non external
authorHans Dedecker <dedeckeh@gmail.com>
Wed, 30 Jul 2014 10:56:30 +0000 (10:56 +0000)
committerSteven Barth <steven@midlink.org>
Wed, 30 Jul 2014 13:22:04 +0000 (15:22 +0200)
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
interface.c
interface.h
ubus.c
wireless.c

index ed60959..8627d97 100644 (file)
@@ -835,8 +835,8 @@ interface_remove_link(struct interface *iface, struct device *dev)
        return 0;
 }
 
        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;
 
 {
        struct device *mdev = iface->main_dev.dev;
 
@@ -853,21 +853,23 @@ interface_add_link(struct interface *iface, struct device *dev)
                        return UBUS_STATUS_NOT_SUPPORTED;
        }
 
                        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_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();
 
 {
        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;
        if (!dev) {
                ret = UBUS_STATUS_NOT_FOUND;
                goto out;
@@ -879,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);
                        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);
        }
        } else {
                ret = interface_remove_link(iface, dev);
        }
index 1cd7e96..90087fc 100644 (file)
@@ -177,9 +177,8 @@ void interface_set_l3_dev(struct interface *iface, struct device *dev);
 void interface_add_user(struct interface_user *dep, struct interface *iface);
 void interface_remove_user(struct interface_user *dep);
 
 void interface_add_user(struct interface_user *dep, struct interface *iface);
 void interface_remove_user(struct interface_user *dep);
 
-int interface_add_link(struct interface *iface, struct device *dev);
 int interface_remove_link(struct interface *iface, struct device *dev);
 int interface_remove_link(struct interface *iface, struct device *dev);
-int interface_handle_link(struct interface *iface, const char *name, bool add);
+int interface_handle_link(struct interface *iface, const char *name, bool add, bool link_ext);
 
 void interface_add_error(struct interface *iface, const char *subsystem,
                         const char *code, const char **data, int n_data);
 
 void interface_add_error(struct interface *iface, const char *subsystem,
                         const char *code, const char **data, int n_data);
diff --git a/ubus.c b/ubus.c
index 2522cfa..161fbe7 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -812,23 +812,40 @@ netifd_handle_dump(struct ubus_context *ctx, struct ubus_object *obj,
        return 0;
 }
 
        return 0;
 }
 
+enum {
+       DEV_LINK_NAME,
+       DEV_LINK_EXT,
+       __DEV_LINK_MAX,
+};
+
+static const struct blobmsg_policy dev_link_policy[__DEV_LINK_MAX] = {
+       [DEV_LINK_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
+       [DEV_LINK_EXT] = { .name = "link-ext", .type = BLOBMSG_TYPE_BOOL },
+};
+
 static int
 netifd_iface_handle_device(struct ubus_context *ctx, struct ubus_object *obj,
                           struct ubus_request_data *req, const char *method,
                           struct blob_attr *msg)
 {
 static int
 netifd_iface_handle_device(struct ubus_context *ctx, struct ubus_object *obj,
                           struct ubus_request_data *req, const char *method,
                           struct blob_attr *msg)
 {
-       struct blob_attr *tb[__DEV_MAX];
+       struct blob_attr *tb[__DEV_LINK_MAX];
+       struct blob_attr *cur;
        struct interface *iface;
        bool add = !strncmp(method, "add", 3);
        struct interface *iface;
        bool add = !strncmp(method, "add", 3);
+       bool link_ext = true;
 
        iface = container_of(obj, struct interface, ubus);
 
 
        iface = container_of(obj, struct interface, ubus);
 
-       blobmsg_parse(dev_policy, __DEV_MAX, tb, blob_data(msg), blob_len(msg));
+       blobmsg_parse(dev_link_policy, __DEV_LINK_MAX, tb, blob_data(msg), blob_len(msg));
 
 
-       if (!tb[DEV_NAME])
+       if (!tb[DEV_LINK_NAME])
                return UBUS_STATUS_INVALID_ARGUMENT;
 
                return UBUS_STATUS_INVALID_ARGUMENT;
 
-       return interface_handle_link(iface, blobmsg_data(tb[DEV_NAME]), add);
+       cur = tb[DEV_LINK_EXT];
+       if (cur)
+               link_ext = !!blobmsg_get_u8(cur);
+
+       return interface_handle_link(iface, blobmsg_data(tb[DEV_LINK_NAME]), add, link_ext);
 }
 
 
 }
 
 
@@ -919,8 +936,8 @@ static struct ubus_method iface_object_methods[] = {
        { .name = "status", .handler = netifd_handle_status },
        { .name = "prepare", .handler = netifd_handle_iface_prepare },
        { .name = "dump", .handler = netifd_handle_dump },
        { .name = "status", .handler = netifd_handle_status },
        { .name = "prepare", .handler = netifd_handle_iface_prepare },
        { .name = "dump", .handler = netifd_handle_dump },
-       UBUS_METHOD("add_device", netifd_iface_handle_device, dev_policy ),
-       UBUS_METHOD("remove_device", netifd_iface_handle_device, dev_policy ),
+       UBUS_METHOD("add_device", netifd_iface_handle_device, dev_link_policy ),
+       UBUS_METHOD("remove_device", netifd_iface_handle_device, dev_link_policy ),
        { .name = "notify_proto", .handler = netifd_iface_notify_proto },
        { .name = "remove", .handler = netifd_iface_remove },
        { .name = "set_data", .handler = netifd_handle_set_data },
        { .name = "notify_proto", .handler = netifd_iface_notify_proto },
        { .name = "remove", .handler = netifd_iface_remove },
        { .name = "set_data", .handler = netifd_handle_set_data },
index c0f3b71..6675d6a 100644 (file)
@@ -215,7 +215,7 @@ static void wireless_interface_handle_link(struct wireless_interface *vif, bool
                if (!iface)
                        continue;
 
                if (!iface)
                        continue;
 
-               interface_handle_link(iface, vif->ifname, up);
+               interface_handle_link(iface, vif->ifname, up, true);
        }
 }
 
        }
 }