From: Felix Fietkau Date: Tue, 6 Jul 2021 17:23:59 +0000 (+0200) Subject: ubus: add support for getting a list of remote hosts X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=0029f3ce2e36fa38e332833c0dcce11c8fd77895;p=project%2Fusteer.git ubus: add support for getting a list of remote hosts Signed-off-by: Felix Fietkau --- diff --git a/node.h b/node.h index 7e708b7..9d5b7aa 100644 --- a/node.h +++ b/node.h @@ -86,6 +86,7 @@ struct usteer_remote_node { extern struct avl_tree local_nodes; extern struct list_head remote_nodes; +extern struct avl_tree remote_hosts; #define for_each_local_node(node) \ avl_for_each_element(&local_nodes, node, avl) \ diff --git a/remote.c b/remote.c index 64375be..e5b2797 100644 --- a/remote.c +++ b/remote.c @@ -60,7 +60,7 @@ static int remote_host_cmp(const void *k1, const void *k2, void *ptr) static VLIST_TREE(interfaces, avl_strcmp, interfaces_update_cb, true, true); LIST_HEAD(remote_nodes); -static AVL_TREE(remote_hosts, remote_host_cmp, false, NULL); +AVL_TREE(remote_hosts, remote_host_cmp, false, NULL); static const char * interface_name(struct interface *iface) diff --git a/ubus.c b/ubus.c index f38ce53..4ae5ef9 100644 --- a/ubus.c +++ b/ubus.c @@ -306,6 +306,27 @@ usteer_ubus_local_info(struct ubus_context *ctx, struct ubus_object *obj, return 0; } +static int +usteer_ubus_remote_hosts(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct usteer_remote_host *host; + void *c; + + blob_buf_init(&b, 0); + + avl_for_each_element(&remote_hosts, host, avl) { + c = blobmsg_open_table(&b, host->addr); + blobmsg_add_u32(&b, "id", (uint32_t)(uintptr_t)host->avl.key); + blobmsg_close_table(&b, c); + } + + ubus_send_reply(ctx, req, b.head); + + return 0; +} + static int usteer_ubus_remote_info(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -398,6 +419,7 @@ usteer_ubus_update_node_data(struct ubus_context *ctx, struct ubus_object *obj, static const struct ubus_method usteer_methods[] = { UBUS_METHOD_NOARG("local_info", usteer_ubus_local_info), + UBUS_METHOD_NOARG("remote_hosts", usteer_ubus_remote_hosts), UBUS_METHOD_NOARG("remote_info", usteer_ubus_remote_info), UBUS_METHOD_NOARG("get_clients", usteer_ubus_get_clients), UBUS_METHOD("get_client_info", usteer_ubus_get_client_info, client_arg),