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;
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;
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);
}
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_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);
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)
{
- 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);
+ bool link_ext = true;
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 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);
}
{ .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 },