diff --git a/src/cntlr.c b/src/cntlr.c index 370db8850792452745783d52dbb1333de94aa11d..db9b706d4a2ec0dff262c79e1f14113d2c1931d9 100644 --- a/src/cntlr.c +++ b/src/cntlr.c @@ -58,21 +58,15 @@ extern bool waitext; -/* find interface by macaddress - no radio argument */ -struct netif_iface *find_interface_by_mac_nor(struct controller *c, - uint8_t *hwaddr) +/* deprecated */ +struct netif_iface *_find_interface_by_mac(struct controller *c, + struct netif_radio *r, uint8_t *hwaddr) { - struct netif_iface *p = NULL; /* fh anf bk iface */ - struct netif_radio *r = NULL; - struct node *n = NULL; + struct netif_iface *p = NULL; - list_for_each_entry(n, &c->nodelist, list) { - list_for_each_entry(r, &n->radiolist, list) { - list_for_each_entry(p, &r->iflist, list) { - if (!memcmp(p->bss->bssid, hwaddr, 6)) - return p; - } - } + list_for_each_entry(p, &r->iflist, list) { + if (!memcmp(p->bss->bssid, hwaddr, 6)) + return p; } return NULL; @@ -82,14 +76,15 @@ struct netif_iface *find_interface_by_mac_nor(struct controller *c, struct netif_iface *find_interface_by_mac(struct controller *c, struct netif_radio *r, uint8_t *hwaddr) { - struct netif_iface *p = NULL; + struct map_macaddr_entry *entry = NULL; - list_for_each_entry(p, &r->iflist, list) { - if (!memcmp(p->bss->bssid, hwaddr, 6)) - return p; - } + entry = allmac_lookup(&c->mac_table, hwaddr, MAC_ENTRY_FBSS); - return NULL; + if (WARN_ON(!entry)) + /* fall back to old find - TODO: deprecate */ + return _find_interface_by_mac(c, r, hwaddr); + + return (struct netif_iface*)entry->data; } /* find radio by ssid, node known */ @@ -145,8 +140,8 @@ struct netif_iface *find_interface_by_ssid(struct controller *c, return NULL; } -/* find radio by node */ -struct netif_radio *find_radio_by_node(struct controller *c, struct node *n, +/* deprecated */ +struct netif_radio *_find_radio_by_node(struct controller *c, struct node *n, uint8_t *radio_mac) { struct netif_radio *p = NULL; @@ -159,8 +154,23 @@ struct netif_radio *find_radio_by_node(struct controller *c, struct node *n, return NULL; } -/* find radio by macaddress, search all nodes */ -struct netif_radio *find_radio_by_mac(struct controller *c, uint8_t *mac) +/* find radio by node */ +struct netif_radio *find_radio_by_node(struct controller *c, struct node *n, + uint8_t *radio_mac) +{ + struct map_macaddr_entry *entry = NULL; + + entry = allmac_lookup(&c->mac_table, radio_mac, MAC_ENTRY_RADIO); + + if (WARN_ON(!entry)) + /* fall back to old find - TODO: deprecate */ + return _find_radio_by_node(c, n, radio_mac); + + return (struct netif_radio*)entry->data; +} + +/* deprecated */ +struct netif_radio *_find_radio_by_mac(struct controller *c, uint8_t *mac) { struct node *n = NULL; struct netif_radio *r = NULL; @@ -174,6 +184,20 @@ struct netif_radio *find_radio_by_mac(struct controller *c, uint8_t *mac) return NULL; } +/* find radio by macaddress, search all nodes */ +struct netif_radio *find_radio_by_mac(struct controller *c, uint8_t *mac) +{ + struct map_macaddr_entry *entry = NULL; + + entry = allmac_lookup(&c->mac_table, mac, MAC_ENTRY_RADIO); + + if (WARN_ON(!entry)) + /* fall back to old find - TODO: deprecate */ + return _find_radio_by_mac(c, mac); + + return (struct netif_radio*)entry->data; +} + /* finds radio struct from interface macaddr */ struct netif_radio *find_radio_by_bssid(struct controller *c, uint8_t *bssid) { @@ -207,8 +231,8 @@ struct netif_link *find_link_by_mac(struct controller *c, uint8_t *upstream, uin return NULL; } -/* find node by macaddress */ -struct node *cntlr_find_node(struct controller *c, uint8_t *almac) +/* deprecated */ +struct node *_cntlr_find_node(struct controller *c, uint8_t *almac) { struct node *n = NULL; @@ -220,8 +244,22 @@ struct node *cntlr_find_node(struct controller *c, uint8_t *almac) return NULL; } -/* find sta by macaddress */ -struct sta *cntlr_find_sta(struct controller *c, uint8_t *mac) +/* find node by macaddress */ +struct node *cntlr_find_node(struct controller *c, uint8_t *mac) +{ + struct map_macaddr_entry *entry = NULL; + + entry = allmac_lookup(&c->mac_table, mac, MAC_ENTRY_ALID); + + if (WARN_ON(!entry)) + /* fall back to old find - TODO: deprecate */ + return _cntlr_find_node(c, mac); + + return (struct node*)entry->data; +} + +/* deprecated */ +struct sta *_cntlr_find_sta(struct controller *c, uint8_t *mac) { struct sta *s = NULL; @@ -233,6 +271,20 @@ struct sta *cntlr_find_sta(struct controller *c, uint8_t *mac) return NULL; } +/* find sta by macaddress */ +struct sta *cntlr_find_sta(struct controller *c, uint8_t *mac) +{ + struct map_macaddr_entry *entry = NULL; + + entry = allmac_lookup(&c->mac_table, mac, MAC_ENTRY_ALID); + + if (WARN_ON(!entry)) + /* fall back to old find - TODO: deprecate */ + return _cntlr_find_sta(c, mac); + + return (struct sta*)entry->data; +} + struct bcnreq *cntlr_find_bcnreq(struct controller *c, uint8_t *sta, uint8_t *alid) { struct bcnreq *br = NULL; @@ -247,23 +299,8 @@ struct bcnreq *cntlr_find_bcnreq(struct controller *c, uint8_t *sta, uint8_t *al return NULL; } -#if 0 -/* find node by macaddress */ -struct netif_iface *cntlr_get_fbss_by_mac(struct controller *c, struct node *n, - uint8_t *mac) -{ - struct netif_iface *p; - - list_for_each_entry(p, &n->iflist, list) { - if (!memcmp(p->bss->bssid, mac, 6)) - return p; - } - - return NULL; -} -#endif -/* find fbss based on macaddr */ -struct netif_iface *cntlr_iterate_fbss(struct controller *c, uint8_t *mac) +/* deprecated */ +struct netif_iface *_cntlr_iterate_fbss(struct controller *c, uint8_t *mac) { struct node *n = NULL; struct netif_radio *r = NULL; @@ -281,6 +318,20 @@ struct netif_iface *cntlr_iterate_fbss(struct controller *c, uint8_t *mac) return NULL; } +/* find fbss based on macaddr */ +struct netif_iface *cntlr_iterate_fbss(struct controller *c, uint8_t *mac) +{ + struct map_macaddr_entry *entry = NULL; + + entry = allmac_lookup(&c->mac_table, mac, MAC_ENTRY_FBSS); + + if (WARN_ON(!entry)) + /* fall back to old find - TODO: deprecate */ + return _cntlr_iterate_fbss(c, mac); + + return (struct netif_iface*)entry->data; +} + /* find node based on bssid */ struct node *cntlr_find_node_by_iface(struct controller *c, uint8_t *bssid) { @@ -1202,8 +1253,7 @@ void cntlr_clean_bcnreqlist(struct controller *c) free(b); } } - -void cntlr_clean_linklist(struct controller *c) +void node_clean_linklist(struct controller *c) { struct netif_link *l = NULL, *tmp; @@ -1329,11 +1379,11 @@ struct netif_link *alloc_link_init(struct controller *c, if (!l->metrics) goto out; - l->upstream = find_interface_by_mac_nor(c, upstream); + l->upstream = cntlr_iterate_fbss(c, upstream); if (!l->upstream) goto out_metrics; - l->downstream = find_interface_by_mac_nor(c, downstream); + l->downstream = cntlr_iterate_fbss(c, downstream); if (!l->downstream) goto out_metrics; @@ -2096,7 +2146,7 @@ out_exit: cntlr_clean_mac_hashtable(c); cntlr_clean_stalist(c); cntlr_clean_bcnreqlist(c); - cntlr_clean_linklist(c); + node_clean_linklist(c); cntlr_clean_nodelist(c); free_bh_topology(); ubus_unregister_event_handler(ctx, &c->evh); diff --git a/src/cntlr.h b/src/cntlr.h index 2e1a4324e373c6e230baa15e261e4ad72033f08f..1ede4d1e414756362f4d879f0c12c623a8a1fbf1 100644 --- a/src/cntlr.h +++ b/src/cntlr.h @@ -396,8 +396,6 @@ struct steer_control_config *get_steer_control_config(struct controller *c); struct sta *cntlr_add_sta(struct controller *c, uint8_t *macaddr); struct sta *cntlr_find_sta(struct controller *c, uint8_t *mac); struct bcnreq *cntlr_find_bcnreq(struct controller *c, uint8_t *sta, uint8_t *alid); -struct netif_iface *cntlr_get_fbss_by_mac(struct controller *c, struct node *n, - uint8_t *mac); bool cntlr_resync_config(struct controller *c, bool reload); int cntlr_radio_clean_scanlist_el(struct wifi_scanres_element *el);