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: 89a9d8138c ("gluon-mesh-batman-adv-core: Announce client count by frequency")
Reported-by: Pascal Wettin <p.wettin@gmx.de>
This commit is contained in:
Sven Eckelmann 2019-03-16 13:37:49 +01:00 committed by Matthias Schiffer
parent 917d6af299
commit b850fff7e4

View File

@ -76,8 +76,7 @@ struct gw_netlink_opts {
}; };
struct clients_netlink_opts { struct clients_netlink_opts {
size_t total; size_t non_wifi;
size_t wifi;
struct batadv_nlquery_opts query_opts; 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]); 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; return NL_OK;
lastseen = nla_get_u32(attrs[BATADV_ATTR_LAST_SEEN_MSECS]); lastseen = nla_get_u32(attrs[BATADV_ATTR_LAST_SEEN_MSECS]);
if (lastseen > MAX_INACTIVITY) if (lastseen > MAX_INACTIVITY)
return NL_OK; return NL_OK;
if (flags & BATADV_TT_CLIENT_WIFI) opts->non_wifi++;
opts->wifi++;
opts->total++;
return NL_OK; return NL_OK;
} }
static struct json_object * get_clients(void) { static struct json_object * get_clients(void) {
size_t wifi24 = 0, wifi5 = 0; size_t wifi24 = 0, wifi5 = 0;
size_t total;
size_t wifi;
struct clients_netlink_opts opts = { struct clients_netlink_opts opts = {
.total = 0, .non_wifi = 0,
.wifi = 0,
.query_opts = { .query_opts = {
.err = 0, .err = 0,
}, },
@ -583,10 +580,12 @@ static struct json_object * get_clients(void) {
&opts.query_opts); &opts.query_opts);
count_stations(&wifi24, &wifi5); count_stations(&wifi24, &wifi5);
wifi = wifi24 + wifi5;
total = wifi + opts.non_wifi;
struct json_object *ret = json_object_new_object(); 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, "total", json_object_new_int(total));
json_object_object_add(ret, "wifi", json_object_new_int(opts.wifi)); 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, "wifi24", json_object_new_int(wifi24));
json_object_object_add(ret, "wifi5", json_object_new_int(wifi5)); json_object_object_add(ret, "wifi5", json_object_new_int(wifi5));
return ret; return ret;