diff options
author | Thomas Haller <thaller@redhat.com> | 2017-02-15 13:20:06 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-02-17 14:41:27 +0100 |
commit | c9dc0eba65565d361e32200894386da5e5c2d001 (patch) | |
tree | 6cf9d115a0609c351eb633b5147f296607b68201 | |
parent | e0f96770188eeaada70a299bd6dab7a50ec34a53 (diff) | |
download | NetworkManager-c9dc0eba65565d361e32200894386da5e5c2d001.tar.gz |
wifi: only react on AP update signal when there are actual changes
Since we emit BSS_UPDATED signal before SCAN_DONE, it is very likely
that nothing actually changed. This clutters the logs with update
messages.
Also move the added/removed logging messages inside ap_add_remove().
We would call ap_add_remove() at several places without logging the
change.
-rw-r--r-- | src/devices/wifi/nm-device-wifi.c | 29 | ||||
-rw-r--r-- | src/devices/wifi/nm-wifi-ap.c | 133 | ||||
-rw-r--r-- | src/devices/wifi/nm-wifi-ap.h | 14 |
3 files changed, 109 insertions, 67 deletions
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 6af76b598a..1d1eb47d7e 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -444,7 +444,8 @@ periodic_update (NMDeviceWifi *self) /* Smooth out the strength to work around crappy drivers */ percent = nm_platform_wifi_get_quality (NM_PLATFORM_GET, ifindex); if (percent >= 0 || ++priv->invalid_strength_counter > 3) { - nm_wifi_ap_set_strength (priv->current_ap, (gint8) percent); + if (nm_wifi_ap_set_strength (priv->current_ap, (gint8) percent)) + _ap_dump (self, priv->current_ap, "updated", 0); priv->invalid_strength_counter = 0; } } @@ -477,7 +478,9 @@ ap_add_remove (NMDeviceWifi *self, g_hash_table_insert (priv->aps, (gpointer) nm_exported_object_export ((NMExportedObject *) ap), g_object_ref (ap)); - } + _ap_dump (self, ap, "added", 0); + } else + _ap_dump (self, ap, "removed", 0); g_signal_emit (self, signals[signum], 0, ap); @@ -1648,7 +1651,8 @@ supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface, found_ap = get_ap_by_supplicant_path (self, object_path); if (found_ap) { - nm_wifi_ap_update_from_properties (found_ap, object_path, properties); + if (!nm_wifi_ap_update_from_properties (found_ap, object_path, properties)) + return; _ap_dump (self, found_ap, "updated", 0); } else { gs_unref_object NMWifiAP *ap = NULL; @@ -1678,7 +1682,6 @@ supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface, } ap_add_remove (self, ACCESS_POINT_ADDED, ap, TRUE); - _ap_dump (self, ap, "added", 0); } /* Update the current AP if the supplicant notified a current BSS change @@ -1712,9 +1715,9 @@ supplicant_iface_bss_removed_cb (NMSupplicantInterface *iface, * when the current AP is changed or cleared. Set 'fake' to * indicate that this AP is now unknown to the supplicant. */ - nm_wifi_ap_set_fake (ap, TRUE); + if (nm_wifi_ap_set_fake (ap, TRUE)) + _ap_dump (self, ap, "updated", 0); } else { - _ap_dump (self, ap, "removed", 0); ap_add_remove (self, ACCESS_POINT_REMOVED, ap, TRUE); schedule_ap_list_dump (self); } @@ -2505,7 +2508,8 @@ ensure_hotspot_frequency (NMDeviceWifi *self, if (!freq) freq = (g_strcmp0 (band, "a") == 0) ? 5180 : 2462; - nm_wifi_ap_set_freq (ap, freq); + if (nm_wifi_ap_set_freq (ap, freq)) + _ap_dump (self, ap, "updated", 0); } static void @@ -2854,6 +2858,8 @@ activation_success_handler (NMDevice *device) g_warn_if_fail (priv->current_ap); if (priv->current_ap) { if (nm_wifi_ap_get_fake (priv->current_ap)) { + gboolean ap_changed = FALSE; + /* If the activation AP hasn't been seen by the supplicant in a scan * yet, it will be "fake". This usually happens for Ad-Hoc and * AP-mode connections. Fill in the details from the device itself @@ -2866,13 +2872,16 @@ activation_success_handler (NMDevice *device) if ( nm_platform_wifi_get_bssid (NM_PLATFORM_GET, ifindex, bssid) && nm_ethernet_address_is_valid (bssid, ETH_ALEN)) { bssid_str = nm_utils_hwaddr_ntoa (bssid, ETH_ALEN); - nm_wifi_ap_set_address (priv->current_ap, bssid_str); + ap_changed |= nm_wifi_ap_set_address (priv->current_ap, bssid_str); } } if (!nm_wifi_ap_get_freq (priv->current_ap)) - nm_wifi_ap_set_freq (priv->current_ap, nm_platform_wifi_get_frequency (NM_PLATFORM_GET, ifindex)); + ap_changed |= nm_wifi_ap_set_freq (priv->current_ap, nm_platform_wifi_get_frequency (NM_PLATFORM_GET, ifindex)); if (!nm_wifi_ap_get_max_bitrate (priv->current_ap)) - nm_wifi_ap_set_max_bitrate (priv->current_ap, nm_platform_wifi_get_rate (NM_PLATFORM_GET, ifindex)); + ap_changed |= nm_wifi_ap_set_max_bitrate (priv->current_ap, nm_platform_wifi_get_rate (NM_PLATFORM_GET, ifindex)); + + if (ap_changed) + _ap_dump (self, priv->current_ap, "updated", 0); } nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 8c041374fa..b60020ac3c 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -69,8 +69,8 @@ typedef struct { NM80211ApSecurityFlags rsn_flags; /* RSN (WPA2) -related flags */ /* Non-scanned attributes */ - bool fake; /* Whether or not the AP is from a scan */ - bool hotspot; /* Whether the AP is a local device's hotspot network */ + bool fake:1; /* Whether or not the AP is from a scan */ + bool hotspot:1; /* Whether the AP is a local device's hotspot network */ gint32 last_seen; /* Timestamp when the AP was seen lastly (obtained via nm_utils_get_monotonic_timestamp_s()) */ } NMWifiAPPrivate; @@ -123,20 +123,20 @@ const GByteArray * nm_wifi_ap_get_ssid (const NMWifiAP *ap) return NM_WIFI_AP_GET_PRIVATE (ap)->ssid; } -void +gboolean nm_wifi_ap_set_ssid (NMWifiAP *ap, const guint8 *ssid, gsize len) { NMWifiAPPrivate *priv; - g_return_if_fail (NM_IS_WIFI_AP (ap)); - g_return_if_fail (ssid == NULL || len > 0); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); + g_return_val_if_fail (ssid == NULL || len > 0, FALSE); priv = NM_WIFI_AP_GET_PRIVATE (ap); /* same SSID */ if ((ssid && priv->ssid) && (len == priv->ssid->len)) { if (!memcmp (ssid, priv->ssid->data, len)) - return; + return FALSE; } if (priv->ssid) { @@ -150,49 +150,56 @@ nm_wifi_ap_set_ssid (NMWifiAP *ap, const guint8 *ssid, gsize len) } _notify (ap, PROP_SSID); + return TRUE; } -static void +static gboolean nm_wifi_ap_set_flags (NMWifiAP *ap, NM80211ApFlags flags) { NMWifiAPPrivate *priv; - g_return_if_fail (NM_IS_WIFI_AP (ap)); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); priv = NM_WIFI_AP_GET_PRIVATE (ap); if (priv->flags != flags) { priv->flags = flags; _notify (ap, PROP_FLAGS); + return TRUE; } + return FALSE; } -static void +static gboolean nm_wifi_ap_set_wpa_flags (NMWifiAP *ap, NM80211ApSecurityFlags flags) { NMWifiAPPrivate *priv; - g_return_if_fail (NM_IS_WIFI_AP (ap)); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); priv = NM_WIFI_AP_GET_PRIVATE (ap); if (priv->wpa_flags != flags) { priv->wpa_flags = flags; _notify (ap, PROP_WPA_FLAGS); + return TRUE; } + return FALSE; } -static void +static gboolean nm_wifi_ap_set_rsn_flags (NMWifiAP *ap, NM80211ApSecurityFlags flags) { NMWifiAPPrivate *priv; - g_return_if_fail (NM_IS_WIFI_AP (ap)); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); priv = NM_WIFI_AP_GET_PRIVATE (ap); if (priv->rsn_flags != flags) { priv->rsn_flags = flags; _notify (ap, PROP_RSN_FLAGS); + return TRUE; } + return FALSE; } const char * @@ -203,7 +210,7 @@ nm_wifi_ap_get_address (const NMWifiAP *ap) return NM_WIFI_AP_GET_PRIVATE (ap)->address; } -static void +static gboolean nm_wifi_ap_set_address_bin (NMWifiAP *ap, const guint8 *addr /* ETH_ALEN bytes */) { NMWifiAPPrivate *priv; @@ -215,20 +222,22 @@ nm_wifi_ap_set_address_bin (NMWifiAP *ap, const guint8 *addr /* ETH_ALEN bytes * g_free (priv->address); priv->address = nm_utils_hwaddr_ntoa (addr, ETH_ALEN); _notify (ap, PROP_HW_ADDRESS); + return TRUE; } + return FALSE; } -void +gboolean nm_wifi_ap_set_address (NMWifiAP *ap, const char *addr) { guint8 addr_buf[ETH_ALEN]; - g_return_if_fail (NM_IS_WIFI_AP (ap)); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); if ( !addr || !nm_utils_hwaddr_aton (addr, addr_buf, sizeof (addr_buf))) - g_return_if_reached (); + g_return_val_if_reached (FALSE); - nm_wifi_ap_set_address_bin (ap, addr_buf); + return nm_wifi_ap_set_address_bin (ap, addr_buf); } NM80211Mode @@ -239,21 +248,23 @@ nm_wifi_ap_get_mode (NMWifiAP *ap) return NM_WIFI_AP_GET_PRIVATE (ap)->mode; } -static void +static gboolean nm_wifi_ap_set_mode (NMWifiAP *ap, const NM80211Mode mode) { NMWifiAPPrivate *priv; - g_return_if_fail (NM_IS_WIFI_AP (ap)); - g_return_if_fail ( mode == NM_802_11_MODE_ADHOC - || mode == NM_802_11_MODE_INFRA); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); + g_return_val_if_fail ( mode == NM_802_11_MODE_ADHOC + || mode == NM_802_11_MODE_INFRA, FALSE); priv = NM_WIFI_AP_GET_PRIVATE (ap); if (priv->mode != mode) { priv->mode = mode; _notify (ap, PROP_MODE); + return TRUE; } + return FALSE; } gboolean @@ -272,19 +283,21 @@ nm_wifi_ap_get_strength (NMWifiAP *ap) return NM_WIFI_AP_GET_PRIVATE (ap)->strength; } -void +gboolean nm_wifi_ap_set_strength (NMWifiAP *ap, const gint8 strength) { NMWifiAPPrivate *priv; - g_return_if_fail (NM_IS_WIFI_AP (ap)); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); priv = NM_WIFI_AP_GET_PRIVATE (ap); if (priv->strength != strength) { priv->strength = strength; _notify (ap, PROP_STRENGTH); + return TRUE; } + return FALSE; } guint32 @@ -295,20 +308,22 @@ nm_wifi_ap_get_freq (NMWifiAP *ap) return NM_WIFI_AP_GET_PRIVATE (ap)->freq; } -void +gboolean nm_wifi_ap_set_freq (NMWifiAP *ap, const guint32 freq) { NMWifiAPPrivate *priv; - g_return_if_fail (NM_IS_WIFI_AP (ap)); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); priv = NM_WIFI_AP_GET_PRIVATE (ap); if (priv->freq != freq) { priv->freq = freq; _notify (ap, PROP_FREQUENCY); + return TRUE; } + return FALSE; } guint32 @@ -320,19 +335,21 @@ nm_wifi_ap_get_max_bitrate (NMWifiAP *ap) return NM_WIFI_AP_GET_PRIVATE (ap)->max_bitrate; } -void +gboolean nm_wifi_ap_set_max_bitrate (NMWifiAP *ap, guint32 bitrate) { NMWifiAPPrivate *priv; - g_return_if_fail (NM_IS_WIFI_AP (ap)); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); priv = NM_WIFI_AP_GET_PRIVATE (ap); if (priv->max_bitrate != bitrate) { priv->max_bitrate = bitrate; _notify (ap, PROP_MAX_BITRATE); + return TRUE; } + return FALSE; } gboolean @@ -343,27 +360,37 @@ nm_wifi_ap_get_fake (const NMWifiAP *ap) return NM_WIFI_AP_GET_PRIVATE (ap)->fake; } -void +gboolean nm_wifi_ap_set_fake (NMWifiAP *ap, gboolean fake) { - g_return_if_fail (NM_IS_WIFI_AP (ap)); + NMWifiAPPrivate *priv; + + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); - NM_WIFI_AP_GET_PRIVATE (ap)->fake = fake; + priv = NM_WIFI_AP_GET_PRIVATE (ap); + + if (priv->fake != !!fake) { + priv->fake = fake; + return TRUE; + } + return FALSE; } -static void +static gboolean nm_wifi_ap_set_last_seen (NMWifiAP *ap, gint32 last_seen) { NMWifiAPPrivate *priv; - g_return_if_fail (NM_IS_WIFI_AP (ap)); + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); priv = NM_WIFI_AP_GET_PRIVATE (ap); if (priv->last_seen != last_seen) { priv->last_seen = last_seen; _notify (ap, PROP_LAST_SEEN); + return TRUE; } + return FALSE; } /*****************************************************************************/ @@ -408,7 +435,7 @@ security_from_vardict (GVariant *security) return flags; } -void +gboolean nm_wifi_ap_update_from_properties (NMWifiAP *ap, const char *supplicant_path, GVariant *properties) @@ -421,28 +448,30 @@ nm_wifi_ap_update_from_properties (NMWifiAP *ap, const char *s; gint16 i16; guint16 u16; + gboolean changed = FALSE; + + g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE); + g_return_val_if_fail (properties, FALSE); - g_return_if_fail (ap != NULL); - g_return_if_fail (properties != NULL); priv = NM_WIFI_AP_GET_PRIVATE (ap); g_object_freeze_notify (G_OBJECT (ap)); if (g_variant_lookup (properties, "Privacy", "b", &b) && b) - nm_wifi_ap_set_flags (ap, priv->flags | NM_802_11_AP_FLAGS_PRIVACY); + changed |= nm_wifi_ap_set_flags (ap, priv->flags | NM_802_11_AP_FLAGS_PRIVACY); if (g_variant_lookup (properties, "Mode", "&s", &s)) { if (!g_strcmp0 (s, "infrastructure")) - nm_wifi_ap_set_mode (ap, NM_802_11_MODE_INFRA); + changed |= nm_wifi_ap_set_mode (ap, NM_802_11_MODE_INFRA); else if (!g_strcmp0 (s, "ad-hoc")) - nm_wifi_ap_set_mode (ap, NM_802_11_MODE_ADHOC); + changed |= nm_wifi_ap_set_mode (ap, NM_802_11_MODE_ADHOC); } if (g_variant_lookup (properties, "Signal", "n", &i16)) - nm_wifi_ap_set_strength (ap, nm_wifi_utils_level_to_quality (i16)); + changed |= nm_wifi_ap_set_strength (ap, nm_wifi_utils_level_to_quality (i16)); if (g_variant_lookup (properties, "Frequency", "q", &u16)) - nm_wifi_ap_set_freq (ap, u16); + changed |= nm_wifi_ap_set_freq (ap, u16); v = g_variant_lookup_value (properties, "SSID", G_VARIANT_TYPE_BYTESTRING); if (v) { @@ -453,7 +482,7 @@ nm_wifi_ap_update_from_properties (NMWifiAP *ap, if ( bytes && len && !(((len == 8) || (len == 9)) && !memcmp (bytes, "<hidden>", 8)) && !nm_utils_is_empty_ssid (bytes, len)) - nm_wifi_ap_set_ssid (ap, bytes, len); + changed |= nm_wifi_ap_set_ssid (ap, bytes, len); g_variant_unref (v); } @@ -464,7 +493,7 @@ nm_wifi_ap_update_from_properties (NMWifiAP *ap, if ( len == ETH_ALEN && memcmp (bytes, nm_ip_addr_zero.addr_eth, ETH_ALEN) != 0 && memcmp (bytes, (char[ETH_ALEN]) { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, ETH_ALEN) != 0) - nm_wifi_ap_set_address_bin (ap, bytes); + changed |= nm_wifi_ap_set_address_bin (ap, bytes); g_variant_unref (v); } @@ -476,33 +505,37 @@ nm_wifi_ap_update_from_properties (NMWifiAP *ap, /* Find the max AP rate */ for (i = 0; i < len; i++) { - if (rates[i] > maxrate) { + if (rates[i] > maxrate) maxrate = rates[i]; - nm_wifi_ap_set_max_bitrate (ap, rates[i] / 1000); - } } + if (maxrate) + changed |= nm_wifi_ap_set_max_bitrate (ap, maxrate / 1000); g_variant_unref (v); } v = g_variant_lookup_value (properties, "WPA", G_VARIANT_TYPE_VARDICT); if (v) { - nm_wifi_ap_set_wpa_flags (ap, priv->wpa_flags | security_from_vardict (v)); + changed |= nm_wifi_ap_set_wpa_flags (ap, priv->wpa_flags | security_from_vardict (v)); g_variant_unref (v); } v = g_variant_lookup_value (properties, "RSN", G_VARIANT_TYPE_VARDICT); if (v) { - nm_wifi_ap_set_rsn_flags (ap, priv->rsn_flags | security_from_vardict (v)); + changed |= nm_wifi_ap_set_rsn_flags (ap, priv->rsn_flags | security_from_vardict (v)); g_variant_unref (v); } - if (!priv->supplicant_path) + if (!priv->supplicant_path) { priv->supplicant_path = g_strdup (supplicant_path); + changed = TRUE; + } - nm_wifi_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ()); - priv->fake = FALSE; + changed |= nm_wifi_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ()); + changed |= nm_wifi_ap_set_fake (ap, FALSE); g_object_thaw_notify (G_OBJECT (ap)); + + return changed; } static gboolean diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h index a68aece8a8..5e64087cca 100644 --- a/src/devices/wifi/nm-wifi-ap.h +++ b/src/devices/wifi/nm-wifi-ap.h @@ -53,7 +53,7 @@ NMWifiAP * nm_wifi_ap_new_from_properties (const char *supplicant_path, GVariant *properties); NMWifiAP * nm_wifi_ap_new_fake_from_connection (NMConnection *connection); -void nm_wifi_ap_update_from_properties (NMWifiAP *ap, +gboolean nm_wifi_ap_update_from_properties (NMWifiAP *ap, const char *supplicant_path, GVariant *properties); @@ -68,25 +68,25 @@ gboolean nm_wifi_ap_complete_connection (NMWifiAP *self, const char * nm_wifi_ap_get_supplicant_path (NMWifiAP *ap); guint64 nm_wifi_ap_get_id (NMWifiAP *ap); const GByteArray *nm_wifi_ap_get_ssid (const NMWifiAP *ap); -void nm_wifi_ap_set_ssid (NMWifiAP *ap, +gboolean nm_wifi_ap_set_ssid (NMWifiAP *ap, const guint8 *ssid, gsize len); const char * nm_wifi_ap_get_address (const NMWifiAP *ap); -void nm_wifi_ap_set_address (NMWifiAP *ap, +gboolean nm_wifi_ap_set_address (NMWifiAP *ap, const char *addr); NM80211Mode nm_wifi_ap_get_mode (NMWifiAP *ap); gboolean nm_wifi_ap_is_hotspot (NMWifiAP *ap); gint8 nm_wifi_ap_get_strength (NMWifiAP *ap); -void nm_wifi_ap_set_strength (NMWifiAP *ap, +gboolean nm_wifi_ap_set_strength (NMWifiAP *ap, gint8 strength); guint32 nm_wifi_ap_get_freq (NMWifiAP *ap); -void nm_wifi_ap_set_freq (NMWifiAP *ap, +gboolean nm_wifi_ap_set_freq (NMWifiAP *ap, guint32 freq); guint32 nm_wifi_ap_get_max_bitrate (NMWifiAP *ap); -void nm_wifi_ap_set_max_bitrate (NMWifiAP *ap, +gboolean nm_wifi_ap_set_max_bitrate (NMWifiAP *ap, guint32 bitrate); gboolean nm_wifi_ap_get_fake (const NMWifiAP *ap); -void nm_wifi_ap_set_fake (NMWifiAP *ap, +gboolean nm_wifi_ap_set_fake (NMWifiAP *ap, gboolean fake); const char *nm_wifi_ap_to_string (const NMWifiAP *self, |