network: do not partially update wlan information on failure

This commit is contained in:
Yu Watanabe 2021-06-14 06:34:01 +09:00
parent 7149bde4ba
commit ecb3deccdc

View file

@ -18,8 +18,9 @@
int wifi_get_info(Link *link) {
_cleanup_free_ char *ssid = NULL;
enum nl80211_iftype iftype;
bool updated = false;
const char *type;
int r, s = 0;
int r;
assert(link);
@ -38,23 +39,26 @@ int wifi_get_info(Link *link) {
r = wifi_get_interface(link->manager->genl, link->ifindex, &iftype, &ssid);
if (r < 0)
return r;
if (r > 0 && link->wlan_iftype == iftype && streq_ptr(link->ssid, ssid))
r = 0;
if (r == 0)
iftype = link->wlan_iftype; /* Assume iftype is not changed. */
link->wlan_iftype = iftype;
free_and_replace(link->ssid, ssid);
if (iftype == NL80211_IFTYPE_STATION) {
struct ether_addr bssid;
if (link->wlan_iftype == NL80211_IFTYPE_STATION) {
struct ether_addr old_bssid = link->bssid;
r = wifi_get_station(link->manager->genl, link->ifindex, &bssid);
if (r < 0)
return r;
s = wifi_get_station(link->manager->genl, link->ifindex, &link->bssid);
if (s < 0)
return s;
if (s > 0 && memcmp(&old_bssid, &link->bssid, sizeof old_bssid) == 0)
s = 0;
updated = !ether_addr_equal(&link->bssid, &bssid);
link->bssid = bssid;
}
if (r > 0 || s > 0) {
updated = updated || link->wlan_iftype != iftype;
link->wlan_iftype = iftype;
updated = updated || !streq_ptr(link->ssid, ssid);
free_and_replace(link->ssid, ssid);
if (updated) {
if (link->wlan_iftype == NL80211_IFTYPE_STATION && link->ssid)
log_link_info(link, "Connected WiFi access point: %s (%s)",
link->ssid, ETHER_ADDR_TO_STR(&link->bssid));