usteer_register_node(ctx, obj->path, obj->id);
}
-void usteer_local_node_update_node_info(struct usteer_local_node *ln)
-{
- struct blob_attr *val;
- const char *name;
-
- blob_buf_init(&b, 0);
- kvlist_for_each(&ln->node_info, name, val)
- blobmsg_add_field(&b, blobmsg_type(val), name,
- blobmsg_data(val), blobmsg_len(val));
-
- val = b.head;
- if (!blobmsg_len(val))
- val = NULL;
-
- usteer_node_set_blob(&ln->node.node_info, val);
-}
-
void config_set_node_up_script(struct blob_attr *data)
{
const char *val;
struct ubus_context *ubus_ctx;
struct usteer_config config = {};
+struct blob_attr *host_info_blob;
uint64_t current_time;
LIST_HEAD(node_handlers);
}
fprintf(stderr, "id=%08x, seq=%d\n", msg.id, msg.seq);
+ if (msg.host_info) {
+ char *data = blobmsg_format_json(msg.host_info, true);
+ fprintf(stderr, "\tHost info: %s\n", data);
+ free(data);
+ }
blob_for_each_attr(cur, msg.nodes, rem)
decode_node(cur);
struct avl_node avl;
struct list_head nodes;
+ struct blob_attr *host_info;
char *addr;
};
[APMSG_ID] = { .type = BLOB_ATTR_INT32 },
[APMSG_SEQ] = { .type = BLOB_ATTR_INT32 },
[APMSG_NODES] = { .type = BLOB_ATTR_NESTED },
+ [APMSG_HOST_INFO] = { .type = BLOB_ATTR_NESTED },
};
struct blob_attr *tb[__APMSG_MAX];
msg->id = blob_get_int32(tb[APMSG_ID]);
msg->seq = blob_get_int32(tb[APMSG_SEQ]);
msg->nodes = tb[APMSG_NODES];
+ msg->host_info = tb[APMSG_HOST_INFO];
return true;
}
inet_ntop(AF_INET, addr, addr_str, sizeof(addr_str));
host = interface_get_host(addr_str, msg.id);
+ usteer_node_set_blob(&host->host_info, msg.host_info);
blob_for_each_attr(cur, msg.nodes, rem)
interface_add_node(host, cur);
blob_buf_init(&buf, 0);
blob_put_int32(&buf, APMSG_ID, local_id);
blob_put_int32(&buf, APMSG_SEQ, ++msg_seq);
+ if (host_info_blob)
+ blob_put(&buf, APMSG_HOST_INFO,
+ blob_data(host_info_blob),
+ blob_len(host_info_blob));
return blob_nest_start(&buf, APMSG_NODES);
}
APMSG_ID,
APMSG_SEQ,
APMSG_NODES,
+ APMSG_HOST_INFO,
__APMSG_MAX
};
uint32_t id;
uint32_t seq;
struct blob_attr *nodes;
+ struct blob_attr *host_info;
};
enum {
#include "event.h"
static struct blob_buf b;
+static KVLIST(host_info, kvlist_blob_len);
static int
usteer_ubus_get_clients(struct ubus_context *ctx, struct ubus_object *obj,
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);
+ if (host->host_info)
+ blobmsg_add_field(&b, BLOBMSG_TYPE_TABLE, "host_info",
+ blobmsg_data(host->host_info),
+ blobmsg_len(host->host_info));
blobmsg_close_table(&b, c);
}
};
static void
-__usteer_ubus_update_node_data(struct usteer_local_node *ln, struct blob_attr *data,
- bool delete)
+usteer_update_kvlist_data(struct kvlist *kv, struct blob_attr *data,
+ bool delete)
{
struct blob_attr *cur;
int rem;
blobmsg_for_each_attr(cur, data, rem) {
if (delete)
- kvlist_delete(&ln->node_info, blobmsg_get_string(cur));
+ kvlist_delete(kv, blobmsg_get_string(cur));
else
- kvlist_set(&ln->node_info, blobmsg_name(cur), cur);
+ kvlist_set(kv, blobmsg_name(cur), cur);
}
+}
+
+static void
+usteer_update_kvlist_blob(struct blob_attr **dest, struct kvlist *kv)
+{
+ struct blob_attr *val;
+ const char *name;
+
+ blob_buf_init(&b, 0);
+ kvlist_for_each(kv, name, val)
+ blobmsg_add_field(&b, blobmsg_type(val), name,
+ blobmsg_data(val), blobmsg_len(val));
+
+ val = b.head;
+ if (!blobmsg_len(val))
+ val = NULL;
- usteer_local_node_update_node_info(ln);
+ usteer_node_set_blob(dest, val);
}
static int
if (!ln)
return UBUS_STATUS_NOT_FOUND;
- __usteer_ubus_update_node_data(ln, val, delete);
+ usteer_update_kvlist_data(&ln->node_info, val, delete);
+ usteer_update_kvlist_blob(&ln->node.node_info, &ln->node_info);
return 0;
}
- avl_for_each_element(&local_nodes, ln, node.avl)
- __usteer_ubus_update_node_data(ln, val, delete);
+ usteer_update_kvlist_data(&host_info, val, delete);
+ usteer_update_kvlist_blob(&host_info_blob, &host_info);
return 0;
}
extern struct ubus_object usteer_obj;
extern uint64_t current_time;
extern const char * const event_types[__EVENT_TYPE_MAX];
+extern struct blob_attr *host_info_blob;
void usteer_update_time(void);
void usteer_init_defaults(void);
void usteer_local_nodes_init(struct ubus_context *ctx);
void usteer_local_node_kick(struct usteer_local_node *ln);
-void usteer_local_node_update_node_info(struct usteer_local_node *ln);
void usteer_ubus_init(struct ubus_context *ctx);
void usteer_ubus_kick_client(struct sta_info *si);