Skip to content
Snippets Groups Projects

Utilize mac-addresses hashtable for object lookup

Merged Filip Matusiak requested to merge fm-mac-hashtbl_push into devel
Compare and
2 files
+ 99
51
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 99
49
@@ -49,21 +49,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;
@@ -73,14 +67,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 */
@@ -121,8 +116,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;
@@ -135,8 +130,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;
@@ -150,6 +160,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)
{
@@ -183,8 +207,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;
@@ -196,8 +220,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;
@@ -209,6 +247,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;
@@ -223,23 +275,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;
@@ -257,6 +294,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)
{
@@ -1116,8 +1167,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;
@@ -1253,11 +1303,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;
@@ -2008,7 +2058,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);
ubus_unregister_event_handler(ctx, &c->evh);
cntlr_remove_object(c);
Loading