ubus: add support for getting a list of remote hosts
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
1
node.h
1
node.h
@@ -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) \
|
||||||
|
2
remote.c
2
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);
|
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
22
ubus.c
@@ -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),
|
||||||
|
Reference in New Issue
Block a user