X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=ubus.c;h=bed1fa498ee0b19f5ed656e8605c17b1e0cf0052;hp=b81136b6d4a1207ea12436e8247b5cf6af88018f;hb=7b81300f7329a7c815dc8543c1a50febddfa6632;hpb=047a1ee7680e9a668896a12e2773d6544669d0e9 diff --git a/ubus.c b/ubus.c index b81136b..bed1fa4 100644 --- a/ubus.c +++ b/ubus.c @@ -147,18 +147,25 @@ netifd_add_dynamic(struct ubus_context *ctx, struct ubus_object *obj, 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); + + if (iface->state != IFS_SETUP && iface->state != IFS_UP) + vlist_delete(&interfaces, &iface->node); + return UBUS_STATUS_OK; error: @@ -166,12 +173,38 @@ 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 = @@ -483,6 +516,9 @@ interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled) 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); @@ -650,7 +686,8 @@ netifd_dump_status(struct interface *iface) if (iface->state == IFS_UP) { time_t cur = system_get_rtime(); blobmsg_add_u32(&b, "uptime", cur - iface->start_time); - blobmsg_add_string(&b, "l3_device", iface->l3_dev.dev->ifname); + if (iface->l3_dev.dev) + blobmsg_add_string(&b, "l3_device", iface->l3_dev.dev->ifname); } if (iface->proto_handler) @@ -737,11 +774,11 @@ netifd_dump_status(struct interface *iface) a = blobmsg_open_table(&b, "data"); avl_for_each_element(&iface->data, data, node) - blob_put(&b, blob_id(data->data), blob_data(data->data), blob_len(data->data)); + blobmsg_add_blob(&b, data->data); blobmsg_close_table(&b, a); - if (!list_is_empty(&iface->errors)) + if (!list_empty(&iface->errors)) netifd_add_interface_errors(&b, iface); } @@ -1160,7 +1197,7 @@ netifd_ubus_interface_event(struct interface *iface, bool up) 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);