if (!iface)
return UBUS_STATUS_UNKNOWN_ERROR;
- iface->device_config = true;
-
config = blob_memdup(msg);
if (!config)
goto error;
interface_add(iface, config);
- interface_set_dynamic(iface);
- // need to look up the interface name again, in case of config update,
+ // need to look up the interface name again, in case of config update
+ // the pointer will have changed
iface = vlist_find(&interfaces, name, iface, node);
if (!iface)
return UBUS_STATUS_UNKNOWN_ERROR;
+ // Set interface as dynamic
+ interface_set_dynamic(iface);
+
dev = iface->main_dev.dev;
if (!dev || !dev->default_config)
return UBUS_STATUS_UNKNOWN_ERROR;
- device_set_config(dev, dev->type, msg);
return UBUS_STATUS_OK;
error:
return UBUS_STATUS_UNKNOWN_ERROR;
}
+static int
+netifd_del_dynamic(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ struct blob_attr *tb[__DI_MAX];
+ struct interface *iface;
+
+ blobmsg_parse(dynamic_policy, __DI_MAX, tb, blob_data(msg), blob_len(msg));
+
+ if (!tb[DI_NAME])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ const char *name = blobmsg_get_string(tb[DI_NAME]);
+ iface = vlist_find(&interfaces, name, iface, node);
+
+ if (!iface)
+ return UBUS_STATUS_NOT_FOUND;
+ else if (!iface->dynamic)
+ return UBUS_STATUS_INVALID_COMMAND;
+
+ vlist_delete(&interfaces, &iface->node);
+ return UBUS_STATUS_OK;
+}
+
static struct ubus_method main_object_methods[] = {
{ .name = "restart", .handler = netifd_handle_restart },
{ .name = "reload", .handler = netifd_handle_reload },
UBUS_METHOD("add_host_route", netifd_add_host_route, route_policy),
{ .name = "get_proto_handlers", .handler = netifd_get_proto_handlers },
UBUS_METHOD("add_dynamic", netifd_add_dynamic, dynamic_policy),
+ UBUS_METHOD("del_dynamic", netifd_del_dynamic, dynamic_policy),
};
static struct ubus_object_type main_object_type =
inet_ntop(af, &route->nexthop, buf, buflen);
blobmsg_add_string_buffer(&b);
+ if (route->flags & DEVROUTE_TYPE)
+ blobmsg_add_u32(&b, "type", route->type);
+
if (route->flags & DEVROUTE_MTU)
blobmsg_add_u32(&b, "mtu", route->mtu);
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 },
void
netifd_ubus_interface_notify(struct interface *iface, bool up)
{
- const char *event = (up) ? "update" : "down";
+ const char *event = (up) ? "interface.update" : "interface.down";
blob_buf_init(&b, 0);
blobmsg_add_string(&b, "interface", iface->name);
netifd_dump_status(iface);