ubus: add support for getting a list of remote hosts

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau
2021-07-06 19:23:59 +02:00
parent 8be33b596b
commit 0029f3ce2e
3 changed files with 24 additions and 1 deletions

1
node.h
View File

@@ -86,6 +86,7 @@ struct usteer_remote_node {
extern struct avl_tree local_nodes; extern struct avl_tree local_nodes;
extern struct list_head remote_nodes; extern struct list_head remote_nodes;
extern struct avl_tree remote_hosts;
#define for_each_local_node(node) \ #define for_each_local_node(node) \
avl_for_each_element(&local_nodes, node, avl) \ avl_for_each_element(&local_nodes, node, avl) \

View File

@@ -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); static VLIST_TREE(interfaces, avl_strcmp, interfaces_update_cb, true, true);
LIST_HEAD(remote_nodes); 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 * static const char *
interface_name(struct interface *iface) interface_name(struct interface *iface)

22
ubus.c
View File

@@ -306,6 +306,27 @@ usteer_ubus_local_info(struct ubus_context *ctx, struct ubus_object *obj,
return 0; 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 static int
usteer_ubus_remote_info(struct ubus_context *ctx, struct ubus_object *obj, usteer_ubus_remote_info(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, 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[] = { static const struct ubus_method usteer_methods[] = {
UBUS_METHOD_NOARG("local_info", usteer_ubus_local_info), 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("remote_info", usteer_ubus_remote_info),
UBUS_METHOD_NOARG("get_clients", usteer_ubus_get_clients), UBUS_METHOD_NOARG("get_clients", usteer_ubus_get_clients),
UBUS_METHOD("get_client_info", usteer_ubus_get_client_info, client_arg), UBUS_METHOD("get_client_info", usteer_ubus_get_client_info, client_arg),