From 6d4d4792d5849eb777a0887bc60112716fde4e80 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sat, 17 Nov 2018 20:12:25 +0100
Subject: [PATCH] gluon-mesh-*: do not count wifi clients/neighbours inactive
 for more than 60s

---
 package/gluon-mesh-babel/src/respondd.c      | 11 ++++++++++-
 package/gluon-mesh-batman-adv/src/respondd.c |  9 ++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/package/gluon-mesh-babel/src/respondd.c b/package/gluon-mesh-babel/src/respondd.c
index f7c870c14..733e9abb7 100644
--- a/package/gluon-mesh-babel/src/respondd.c
+++ b/package/gluon-mesh-babel/src/respondd.c
@@ -63,6 +63,8 @@
 #define STRINGIFY(s) _STRINGIFY(s)
 #include <stdlib.h>
 
+#define MAX_INACTIVITY 60000
+
 #define SOCKET_INPUT_BUFFER_SIZE 255
 #define BABEL_PORT 33123
 #define VPN_INTERFACE "mesh-vpn"
@@ -461,8 +463,12 @@ static void count_iface_stations(size_t *wifi24, size_t *wifi5, const char *ifna
 		return;
 
 	struct iwinfo_assoclist_entry *entry;
-	for (entry = (struct iwinfo_assoclist_entry *)buf; (char*)(entry+1) <= buf + len; entry++)
+	for (entry = (struct iwinfo_assoclist_entry *)buf; (char*)(entry+1) <= buf + len; entry++) {
+		if (entry->inactive > MAX_INACTIVITY)
+			continue;
+
 		(*wifi)++;
+	}
 }
 
 static void count_stations(size_t *wifi24, size_t *wifi5) {
@@ -623,6 +629,9 @@ static struct json_object * get_wifi_neighbours(const char *ifname) {
 
 	struct iwinfo_assoclist_entry *entry;
 	for (entry = (struct iwinfo_assoclist_entry *)buf; (char*)(entry+1) <= buf + len; entry++) {
+		if (entry->inactive > MAX_INACTIVITY)
+			continue;
+
 		struct json_object *obj = json_object_new_object();
 
 		json_object_object_add(obj, "signal", json_object_new_int(entry->signal));
diff --git a/package/gluon-mesh-batman-adv/src/respondd.c b/package/gluon-mesh-batman-adv/src/respondd.c
index 9c95b17f0..7417acfbf 100644
--- a/package/gluon-mesh-batman-adv/src/respondd.c
+++ b/package/gluon-mesh-batman-adv/src/respondd.c
@@ -444,8 +444,12 @@ static void count_iface_stations(size_t *wifi24, size_t *wifi5, const char *ifna
 		return;
 
 	struct iwinfo_assoclist_entry *entry;
-	for (entry = (struct iwinfo_assoclist_entry *)buf; (char*)(entry+1) <= buf + len; entry++)
+	for (entry = (struct iwinfo_assoclist_entry *)buf; (char*)(entry+1) <= buf + len; entry++) {
+		if (entry->inactive > MAX_INACTIVITY)
+			continue;
+
 		(*wifi)++;
+	}
 }
 
 static void count_stations(size_t *wifi24, size_t *wifi5) {
@@ -712,6 +716,9 @@ static struct json_object * get_wifi_neighbours(const char *ifname) {
 
 	struct iwinfo_assoclist_entry *entry;
 	for (entry = (struct iwinfo_assoclist_entry *)buf; (char*)(entry+1) <= buf + len; entry++) {
+		if (entry->inactive > MAX_INACTIVITY)
+			continue;
+
 		struct json_object *obj = json_object_new_object();
 
 		json_object_object_add(obj, "signal", json_object_new_int(entry->signal));
-- 
GitLab