From 877e2dc22fa48185124d9ef66a7f59596745da3a Mon Sep 17 00:00:00 2001 From: Ian Clowes Date: Thu, 6 Jan 2022 09:16:18 +0100 Subject: [PATCH] iwinfo: fix get_bandwidth_iwinfo Bug that was preventing kicking working due to mishandling of bandwidth discovery. Fixed bug in use of get_bandwidth_iwinfo() in AP kicking. Fix rounding of transmission rate calculations in get_bandwidth_iwinfo(). Restructure of get_bandwidth...() while finding bug. Signed-off-by: Ian Clowes --- src/storage/datastorage.c | 2 +- src/utils/dawn_iwinfo.c | 53 ++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 28c8ef8..f8c4342 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -721,7 +721,7 @@ int kick_clients(ap* kicking_ap, uint32_t id) { dawnlog_debug("Check if client is active receiving!\n"); float rx_rate, tx_rate; - bool have_bandwidth_iwinfo = !(get_bandwidth_iwinfo(j->client_addr, &rx_rate, &tx_rate)); + bool have_bandwidth_iwinfo = get_bandwidth_iwinfo(j->client_addr, &rx_rate, &tx_rate); if (!have_bandwidth_iwinfo && dawn_metric.bandwidth_threshold > 0) { dawnlog_debug("No active transmission data for client. Don't kick!\n"); } diff --git a/src/utils/dawn_iwinfo.c b/src/utils/dawn_iwinfo.c index 339297e..c3b6a5d 100644 --- a/src/utils/dawn_iwinfo.c +++ b/src/utils/dawn_iwinfo.c @@ -103,12 +103,10 @@ int get_bandwidth_iwinfo(struct dawn_mac client_addr, float *rx_rate, float *tx_ int sucess = 0; - while ((entry = readdir(dirp)) != NULL) { + while (!sucess && ((entry = readdir(dirp)) != NULL)) { if (entry->d_type == DT_SOCK) { - if (get_bandwidth(entry->d_name, client_addr, rx_rate, tx_rate)) { - sucess = 1; - break; - } + dawnlog_debug("[BANDWIDTH INFO] Trying %s\n", entry->d_name); + sucess = get_bandwidth(entry->d_name, client_addr, rx_rate, tx_rate); } } closedir(dirp); @@ -116,35 +114,34 @@ int get_bandwidth_iwinfo(struct dawn_mac client_addr, float *rx_rate, float *tx_ } int get_bandwidth(const char *ifname, struct dawn_mac client_addr, float *rx_rate, float *tx_rate) { + int ret = 0; - int i, len; - char buf[IWINFO_BUFSIZE]; - struct iwinfo_assoclist_entry *e; - const struct iwinfo_ops *iw; - if (strcmp(ifname, "global") == 0) - return 0; - iw = iwinfo_backend(ifname); + if (strcmp(ifname, "global") != 0) + { + const struct iwinfo_ops* iw = iwinfo_backend(ifname); - if (iw->assoclist(ifname, buf, &len)) { - iwinfo_finish(); - return 0; - } else if (len <= 0) { - iwinfo_finish(); - return 0; - } + char buf[IWINFO_BUFSIZE]; + int len; + if (iw->assoclist(ifname, buf, &len) == 0 && len > 0) + { + struct iwinfo_assoclist_entry* e = (struct iwinfo_assoclist_entry*)buf; + for (int i = 0; ret == 0 && i < len; i += sizeof(struct iwinfo_assoclist_entry)) { - for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) { - e = (struct iwinfo_assoclist_entry *) &buf[i]; + if (mac_is_equal(client_addr.u8, e->mac)) { + *rx_rate = e->rx_rate.rate / 1000.0; + *tx_rate = e->tx_rate.rate / 1000.0; - if (mac_is_equal(client_addr.u8, e->mac)) { - *rx_rate = e->rx_rate.rate / 1000; - *tx_rate = e->tx_rate.rate / 1000; - iwinfo_finish(); - return 1; + ret = 1; + } + + e++; + } } + + iwinfo_finish(); } - iwinfo_finish(); - return 0; + + return ret; } int get_rssi_iwinfo(struct dawn_mac client_addr) {