diff mbox series

[3/4] wpa_supplicant-2.8: Add wpa_blacklist_update()

Message ID 20200520183417.214702-3-kglund@google.com
State Superseded
Headers show
Series [1/4] wpa_supplicant-2.8: Track consecutive connection failures | expand

Commit Message

Kevin Lund May 20, 2020, 6:34 p.m. UTC
This change adds the function wpa_blacklist_update(), which goes through
all blacklist entries and deletes them if their blacklist expired over
an hour ago. The purpose of this is to remove stale entries from the
blacklist which likely do not reflect the current condition of device's
network surroundings. This function is called whenever the blacklist is
polled, meaning that the caller always gets an up-to-date reflection of
the blacklist.

Another solution to clearing the blacklist that was considered was
to slowly reduce the counts of blacklist entries over time, and delete
them if the counts dropped below 0. We decided to go with the current
solution instead because an AP's "problematic" status is really a binary
thing: either the AP is no longer problematic, or it's still causing us
problems. So if we see any more problems within a reasonable amount of
time, it makes sense to just keep the blacklist where it was since the
AP is likely still undergoing the same issue. If we go a significant
amount of time (semi-arbitrarily chosen as 1 hour) without any issues
with an AP, it's reasonable to behave as if the AP is no longer
undergoing the same issue. If we see more problems at a later time, we
can start the blacklisting process fresh again, treating this as a brand
new issue.

BUG=chromium:1040974, chromium:1051374
TEST=emerge-drallion wpa_supplicant-2_8
Run test and check logs. Reduce timer from one hour to 5 seconds, and
check that the blacklist entry removal logic works as intended.
TEST=Run suite:wifi_matfunc: "Total PASS: 180/180 (100%)"
TEST=Emerge and deploy hostap-test on board Betty to cros_vm instance
`tast -verbose run -var=network.HostapHwsim.runArgs='-f module_tests'
localhost:9222 network.HostapHwsim.full`
`tast -verbose run -var=network.HostapHwsim.runArgs='-f ap_open ap_roam
wpas_ctrl' localhost:9222 network.HostapHwsim.full`
`tast -verbose run localhost:9222 network.HostapHwsim.full`
tast -verbose run localhost:9222 network.HostapHwsim.sanity`
No new hwsim test failures are introduced by this change.

Signed-off-by: Kevin Lund <kglund@google.com>
Change-Id: I7a274bdce35911d42894fc66ec16b1357662c7e1
 wpa_supplicant/blacklist.c | 39 ++++++++++++++++++++++++++++++++++++++
 wpa_supplicant/blacklist.h |  1 +
 2 files changed, 40 insertions(+)
diff mbox series


diff --git a/wpa_supplicant/blacklist.c b/wpa_supplicant/blacklist.c
index 74d6b0bcd..0b4848af4 100644
--- a/wpa_supplicant/blacklist.c
+++ b/wpa_supplicant/blacklist.c
@@ -26,6 +26,8 @@  struct wpa_blacklist * wpa_blacklist_get(struct wpa_supplicant *wpa_s,
 	if (wpa_s == NULL || bssid == NULL)
 		return NULL;
+	wpa_blacklist_update(wpa_s);
 	e = wpa_s->blacklist;
 	while (e) {
 		if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0)
@@ -171,3 +173,40 @@  void wpa_blacklist_clear(struct wpa_supplicant *wpa_s)
+ * wpa_blacklist_update - Update the entries in the blacklist,
+ * deleting entries that have been expired for over an hour.
+ * @wpa_s: Pointer to wpa_supplicant data
+ */
+void wpa_blacklist_update(struct wpa_supplicant *wpa_s)
+	struct wpa_blacklist *e, *prev = NULL, *to_delete = NULL;
+	struct os_reltime now;
+	if (wpa_s == NULL)
+		return;
+	e = wpa_s->blacklist;
+	os_get_reltime(&now);
+	while (e) {
+		if (os_reltime_expired(&now, &e->blacklist_start,
+			               e->timeout_secs + 3600)) {
+			to_delete = e;
+			if (prev) {
+				prev->next = e->next;
+				e = prev->next;
+			} else {
+				wpa_s->blacklist = e->next;
+				e = wpa_s->blacklist;
+			}
+			wpa_printf(MSG_INFO, "Removed BSSID " MACSTR " from "
+				   "blacklist (expired)", MAC2STR(to_delete->bssid));
+			os_free(to_delete);
+		} else {
+			prev = e;
+			e = e->next;
+		}
+	}
diff --git a/wpa_supplicant/blacklist.h b/wpa_supplicant/blacklist.h
index 92990fb6d..bb473d465 100644
--- a/wpa_supplicant/blacklist.h
+++ b/wpa_supplicant/blacklist.h
@@ -28,5 +28,6 @@  int wpa_blacklist_add(struct wpa_supplicant *wpa_s, const u8 *bssid);
 int wpa_blacklist_del(struct wpa_supplicant *wpa_s, const u8 *bssid);
 int wpa_blacklist_is_blacklisted(struct wpa_supplicant *wpa_s, const u8 *bssid);
 void wpa_blacklist_clear(struct wpa_supplicant *wpa_s);
+void wpa_blacklist_update(struct wpa_supplicant *wpa_s);
 #endif /* BLACKLIST_H */