* Copyright (C) 2020 John Crispin <john@phrozen.org>
*/
+#define _GNU_SOURCE
+
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
interface_add_station(struct usteer_remote_node *node, struct blob_attr *data)
{
struct sta *sta;
- struct sta_info *si;
+ struct sta_info *si, *local_si;
struct apmsg_sta msg;
+ struct usteer_node *local_node;
bool create;
+ bool connect_change;
if (!parse_apmsg_sta(&msg, data)) {
MSG(DEBUG, "Cannot parse station in message\n");
if (!si)
return;
+ connect_change = si->connected != msg.connected;
si->connected = msg.connected;
si->signal = msg.signal;
si->seen = current_time - msg.seen;
+ si->last_connected = current_time - msg.last_connected;
+
+ /* Check if client roamed to this foreign node */
+ if ((connect_change || create) && si->connected == STA_CONNECTED) {
+ for_each_local_node(local_node) {
+ local_si = usteer_sta_info_get(sta, local_node, NULL);
+ if (!local_si)
+ continue;
+
+ if (current_time - local_si->last_connected < config.roam_process_timeout) {
+ node->node.roam_events.target++;
+ break;
+ }
+ }
+ }
+
usteer_sta_info_update_timeout(si, msg.timeout);
}
node = calloc_a(sizeof(*node), &buf, addr_len + 1 + strlen(name) + 1);
node->node.type = NODE_TYPE_REMOTE;
+ node->node.created = current_time;
sprintf(buf, "%s#%s", host->addr, name);
node->node.avl.key = buf;
static void usteer_send_sta_info(struct sta_info *sta)
{
int seen = current_time - sta->seen;
+ int last_connected = !!sta->connected ? 0 : current_time - sta->last_connected;
void *c;
c = blob_nest_start(&buf, 0);
blob_put_int8(&buf, APMSG_STA_CONNECTED, !!sta->connected);
blob_put_int32(&buf, APMSG_STA_SIGNAL, sta->signal);
blob_put_int32(&buf, APMSG_STA_SEEN, seen);
+ blob_put_int32(&buf, APMSG_STA_LAST_CONNECTED, last_connected);
blob_put_int32(&buf, APMSG_STA_TIMEOUT, config.local_sta_timeout - seen);
blob_nest_end(&buf, c);
}
struct usteer_node *node;
void *c;
- if (avl_is_empty(&local_nodes) && !host_info_blob)
- return;
-
usteer_update_time();
uloop_timeout_set(t, config.remote_update_interval);
- c = usteer_update_init();
- for_each_local_node(node)
- usteer_send_node(node, NULL);
+ if (!avl_is_empty(&local_nodes) || host_info_blob) {
+ c = usteer_update_init();
+ for_each_local_node(node)
+ usteer_send_node(node, NULL);
- usteer_update_send(c);
+ usteer_update_send(c);
+ }
usteer_check_timeout();
}