From f7e5c7be759cf9cc49538fb4e1d59c893d7d8004 Mon Sep 17 00:00:00 2001
From: Filip Matusiak <filip.matusiak@iopsys.eu>
Date: Tue, 3 Jun 2025 12:43:04 +0200
Subject: [PATCH] Fix topology notification to properly update stalists
---
src/cntlr.c | 10 +++----
src/cntlr.h | 2 +-
src/cntlr_map.c | 75 +++++++++++++++++++++++--------------------------
3 files changed, 41 insertions(+), 46 deletions(-)
diff --git a/src/cntlr.c b/src/cntlr.c
index 7eb8f9cb..132500bc 100644
--- a/src/cntlr.c
+++ b/src/cntlr.c
@@ -231,16 +231,16 @@ struct node *cntlr_find_node_with_bssid(struct controller *c, uint8_t *bssid)
return NULL;
}
-/* find node to which given STA is connected */
-struct node *cntlr_find_node_with_sta(struct controller *c, uint8_t *sta_mac)
+/* returns first found node with given STA MAC on its stalist */
+struct node *cntlr_find_node_with_sta(struct controller *c, uint8_t *stamacaddr)
{
struct node *n = NULL;
list_for_each_entry(n, &c->nodelist, list) {
- struct sta *s = NULL;
+ struct sta *e = NULL;
- list_for_each_entry(s, &n->stalist, list) {
- if (!memcmp(s->macaddr, sta_mac, 6))
+ list_for_each_entry(e, &n->stalist, list) {
+ if (!memcmp(e->macaddr, stamacaddr, 6))
return n;
}
}
diff --git a/src/cntlr.h b/src/cntlr.h
index f5408489..9b153ce1 100644
--- a/src/cntlr.h
+++ b/src/cntlr.h
@@ -367,7 +367,7 @@ struct node *cntlr_add_node(struct controller *c, uint8_t *almacaddr);
struct node *cntlr_alloc_node(struct controller *c, uint8_t *almacaddr);
struct node *cntlr_find_node(struct controller *c, uint8_t *almacaddr);
struct node *cntlr_find_node_with_bssid(struct controller *c, uint8_t *bssid);
-struct node *cntlr_find_node_with_sta(struct controller *c, uint8_t *sta_mac);
+struct node *cntlr_find_node_with_sta(struct controller *c, uint8_t *stamacaddr);
struct netif_link *cntlr_alloc_link(struct controller *c,
uint8_t *upstream, uint8_t *downstream);
diff --git a/src/cntlr_map.c b/src/cntlr_map.c
index 8d32ae7d..a96ea2cc 100644
--- a/src/cntlr_map.c
+++ b/src/cntlr_map.c
@@ -228,75 +228,70 @@ int handle_topology_notification(void *cntlr, struct cmdu_buff *cmdu,
return 0;
}
- bsta_iface = cntlr_find_iface_type(c, ev->macaddr, MAC_ENTRY_BSTA);
-
s = cntlr_find_sta(c->sta_table, ev->macaddr);
- if (associated) {
- struct node *old_n = NULL;
-
- if (s)
- timer_del(&s->stale_sta_timer);
- else {
- s = cntlr_add_sta(c, c->sta_table, ev->macaddr);
- if (!s) {
- cntlr_dbg(LOG_STA, "%s: failed to add STA " MACFMT "\n",
- __func__, MAC2STR(ev->macaddr));
- return -1;
- }
-
+ if (s) {
+ if (associated) {
time(&s->assoc_time);
- s->state = STA_ASSOCIATED;
+ timer_del(&s->stale_sta_timer);
memcpy(s->bssid, ev->bssid, 6);
- node_add_sta(n, s);
+ s->state = STA_ASSOCIATED;
- goto inform_steer_plugins;
- }
+ if (memcmp(s->agent_almacaddr, n->almacaddr, 6)) {
+ /* associated to a new node - remove from the old one */
+ struct node *old_n = NULL;
- /* remove sta from old-node and add to new-node */
- old_n = cntlr_find_node(c, s->agent_almacaddr);
- if (old_n) {
- if (node_find_sta(old_n, s->macaddr)) {
+ old_n = cntlr_find_node(c, s->agent_almacaddr);
+ if (old_n)
+ node_del_sta(old_n, s);
+ }
+
+ node_add_sta(n, s);
+ } else {
+ if (!memcmp(s->agent_almacaddr, n->almacaddr, 6)) {
+ /* disassociated from current node */
time(&s->disassoc_time);
+ timer_set(&s->stale_sta_timer, c->cfg.stale_sta_timeout);
+ //memset(s->bssid, 0, sizeof(s->bssid));
s->state = STA_DISCONNECTED;
- node_del_sta(old_n, s);
}
+
+ node_del_sta(n, s);
}
+ } else { /* unknown sta */
+ if (associated) {
+ s = cntlr_add_sta(c, c->sta_table, ev->macaddr);
+ if (!s) {
+ cntlr_dbg(LOG_STA, "%s: failed to add STA " MACFMT "\n",
+ __func__, MAC2STR(ev->macaddr));
+ return -1;
+ }
- if (!node_find_sta(n, ev->macaddr)) {
time(&s->assoc_time);
- s->state = STA_ASSOCIATED;
memcpy(s->bssid, ev->bssid, 6);
+ s->state = STA_ASSOCIATED;
+
node_add_sta(n, s);
- }
- } else {
- if (!s) {
+ } else {
cntlr_dbg(LOG_STA,
"Ignore unknown STA " MACFMT " disassoc event\n",
MAC2STR(ev->macaddr));
return 0;
}
-
- timer_set(&s->stale_sta_timer, c->cfg.stale_sta_timeout);
-
- if (node_find_sta(n, ev->macaddr)) {
- time(&s->disassoc_time);
- s->state = STA_DISCONNECTED;
- node_del_sta(n, s);
- }
}
+ bsta_iface = cntlr_find_iface_type(c, ev->macaddr, MAC_ENTRY_BSTA);
s->is_bsta = bsta_iface || bh ? true : false;
cntlr_info(LOG_STA, "%s: STA " MACFMT " %s Node " MACFMT"\n",
__func__, MAC2STR(s->macaddr),
s->state == STA_ASSOCIATED ? "associated to" : "disconnected from",
MAC2STR(s->agent_almacaddr));
- }
-inform_steer_plugins:
- if (s) {
cntlr_update_sta_steer_data(c, s);
+ }
+ if (s) {
+ /* Inform steering plugins */
c->inform_cmdu_type = CMDU_TYPE_TOPOLOGY_NOTIFICATION;
c->inform_sta_num = 1;
memset(c->inform_stalist, 0, sizeof(c->inform_stalist));
--
GitLab