From b850fff7e4f4b938c512d81de31bfae872fa42e4 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sat, 16 Mar 2019 13:37:49 +0100 Subject: [PATCH] gluon-mesh-batman-adv: Only use local TT to count non-wifi clients (#1676) The amount of local wifi clients is currently counted by two different ways: * asking the kernel wifi layer for the number of of clients on 2.4GHz and 5GHz band * asking batman-adv for the number of non-timed out entries in the local translation table with WiFi flag The number of wifi24+wifi5 and the number of TT wifi client counts are reported via respondd to various consumers. The ffrgb meshviewer is displaying these values as: * 2,4 GHz: wifi24 * 5 GHz: wifi5 * other: (TT local wifi+non-wifi clients) - (wifi24 + wifi5) But the local translation table is holding entries much longer than the wifi layer. It can therefore easily happen that a wifi client disappears in the kernel wifi layer and batman-adv still has the entry stored in the local TT. The ffrgb meshviewer would then show this count in the category "other". This often results in confusions because "other" is usually for ethernet clients. And nodes with a frequently disappearing larger group of clients (near bus stations or larger intersections) often show most clients under the group "other" even when this devices doesn't have a LAN ethernet port. It is better for presentation to calculate the number of total wifi clients by summing up wifi24 + wifi5. And getting the number of total clients (non wifi + wifi) by adding the result of the previous calculation to the sum of non-wifi client in the local batman-adv translation table. Fixes: 89a9d8138c4b ("gluon-mesh-batman-adv-core: Announce client count by frequency") Reported-by: Pascal Wettin --- package/gluon-mesh-batman-adv/src/respondd.c | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/package/gluon-mesh-batman-adv/src/respondd.c b/package/gluon-mesh-batman-adv/src/respondd.c index 0613e45b..43d51223 100644 --- a/package/gluon-mesh-batman-adv/src/respondd.c +++ b/package/gluon-mesh-batman-adv/src/respondd.c @@ -76,8 +76,7 @@ struct gw_netlink_opts { }; struct clients_netlink_opts { - size_t total; - size_t wifi; + size_t non_wifi; struct batadv_nlquery_opts query_opts; }; @@ -553,26 +552,24 @@ static int parse_clients_list_netlink_cb(struct nl_msg *msg, void *arg) flags = nla_get_u32(attrs[BATADV_ATTR_TT_FLAGS]); - if (flags & BATADV_TT_CLIENT_NOPURGE) + if (flags & (BATADV_TT_CLIENT_NOPURGE | BATADV_TT_CLIENT_WIFI)) return NL_OK; lastseen = nla_get_u32(attrs[BATADV_ATTR_LAST_SEEN_MSECS]); if (lastseen > MAX_INACTIVITY) return NL_OK; - if (flags & BATADV_TT_CLIENT_WIFI) - opts->wifi++; - - opts->total++; + opts->non_wifi++; return NL_OK; } static struct json_object * get_clients(void) { size_t wifi24 = 0, wifi5 = 0; + size_t total; + size_t wifi; struct clients_netlink_opts opts = { - .total = 0, - .wifi = 0, + .non_wifi = 0, .query_opts = { .err = 0, }, @@ -583,10 +580,12 @@ static struct json_object * get_clients(void) { &opts.query_opts); count_stations(&wifi24, &wifi5); + wifi = wifi24 + wifi5; + total = wifi + opts.non_wifi; struct json_object *ret = json_object_new_object(); - json_object_object_add(ret, "total", json_object_new_int(opts.total)); - json_object_object_add(ret, "wifi", json_object_new_int(opts.wifi)); + json_object_object_add(ret, "total", json_object_new_int(total)); + json_object_object_add(ret, "wifi", json_object_new_int(wifi)); json_object_object_add(ret, "wifi24", json_object_new_int(wifi24)); json_object_object_add(ret, "wifi5", json_object_new_int(wifi5)); return ret;