From 922c169147fc6e4c4ecf94029528192636e917e7 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Wed, 30 Jul 2014 10:56:30 +0000 Subject: [PATCH] netifd: Allow to add link devices which can be marked as non external Signed-off-by: Hans Dedecker --- interface.c | 14 ++++++++------ interface.h | 3 +-- ubus.c | 29 +++++++++++++++++++++++------ wireless.c | 2 +- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/interface.c b/interface.c index ed60959..8627d97 100644 --- a/interface.c +++ b/interface.c @@ -835,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; @@ -853,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; @@ -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); - ret = interface_add_link(iface, dev); + ret = interface_add_link(iface, dev, link_ext); } else { ret = interface_remove_link(iface, dev); } diff --git a/interface.h b/interface.h index 1cd7e96..90087fc 100644 --- a/interface.h +++ b/interface.h @@ -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); -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); diff --git a/ubus.c b/ubus.c index 2522cfa..161fbe7 100644 --- a/ubus.c +++ b/ubus.c @@ -812,23 +812,40 @@ netifd_handle_dump(struct ubus_context *ctx, struct ubus_object *obj, 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); } @@ -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 }, - 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 }, diff --git a/wireless.c b/wireless.c index c0f3b71..6675d6a 100644 --- a/wireless.c +++ b/wireless.c @@ -215,7 +215,7 @@ static void wireless_interface_handle_link(struct wireless_interface *vif, bool if (!iface) continue; - interface_handle_link(iface, vif->ifname, up); + interface_handle_link(iface, vif->ifname, up, true); } } -- 2.30.2