From: Yu Watanabe Date: Wed, 17 Jun 2020 04:54:56 +0000 (+0900) Subject: network: do not fail to configure non-nl80211 wifi interfaces X-Git-Tag: v246-rc1~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc17c4c9a16e4409a566840a68c530165375a221;p=thirdparty%2Fsystemd.git network: do not fail to configure non-nl80211 wifi interfaces Also, make wifi_get_interface() and wifi_get_station() initialize destination buffer when they return a non-negatinve value. Closes #16160. --- diff --git a/src/shared/wifi-util.c b/src/shared/wifi-util.c index 2717db65075..22bb3041fbb 100644 --- a/src/shared/wifi-util.c +++ b/src/shared/wifi-util.c @@ -14,6 +14,9 @@ int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *iftyp sd_genl_family family; int r; + assert(genl); + assert(ifindex > 0); + r = sd_genl_message_new(genl, SD_GENL_NL80211, NL80211_CMD_GET_INTERFACE, &m); if (r < 0) return log_debug_errno(r, "Failed to create generic netlink message: %m"); @@ -23,10 +26,17 @@ int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *iftyp return log_debug_errno(r, "Could not append NL80211_ATTR_IFINDEX attribute: %m"); r = sd_netlink_call(genl, m, 0, &reply); + if (r == -ENODEV) { + /* For obsolete WEXT driver. */ + log_debug_errno(r, "Failed to request information about wifi interface %d. " + "The device doesn't seem to have nl80211 interface. Ignoring.", + ifindex); + goto nodata; + } if (r < 0) return log_debug_errno(r, "Failed to request information about wifi interface %d: %m", ifindex); if (!reply) - return 0; + goto nodata; r = sd_netlink_message_get_errno(reply); if (r < 0) @@ -37,7 +47,7 @@ int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *iftyp return log_debug_errno(r, "Failed to determine genl family: %m"); if (family != SD_GENL_NL80211) { log_debug("Received message of unexpected genl family %u, ignoring.", family); - return 0; + goto nodata; } if (iftype) { @@ -51,11 +61,20 @@ int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *iftyp if (ssid) { r = sd_netlink_message_read_string_strdup(reply, NL80211_ATTR_SSID, ssid); - if (r < 0 && r != -ENODATA) + if (r == -ENODATA) + goto nodata; + if (r < 0) return log_debug_errno(r, "Failed to get NL80211_ATTR_SSID attribute: %m"); } - return r == -ENODATA ? 0 : 1; + return 1; + +nodata: + if (iftype) + *iftype = 0; + if (ssid) + *ssid = NULL; + return 0; } int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *bssid) { @@ -63,6 +82,10 @@ int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *bssid) { sd_genl_family family; int r; + assert(genl); + assert(ifindex > 0); + assert(bssid); + r = sd_genl_message_new(genl, SD_GENL_NL80211, NL80211_CMD_GET_STATION, &m); if (r < 0) return log_debug_errno(r, "Failed to create generic netlink message: %m"); @@ -79,7 +102,7 @@ int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *bssid) { if (r < 0) return log_debug_errno(r, "Failed to request information about wifi station: %m"); if (!reply) - return 0; + goto nodata; r = sd_netlink_message_get_errno(reply); if (r < 0) @@ -90,12 +113,18 @@ int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *bssid) { return log_debug_errno(r, "Failed to determine genl family: %m"); if (family != SD_GENL_NL80211) { log_debug("Received message of unexpected genl family %u, ignoring.", family); - return 0; + goto nodata; } r = sd_netlink_message_read_ether_addr(reply, NL80211_ATTR_MAC, bssid); - if (r < 0 && r != -ENODATA) + if (r == -ENODATA) + goto nodata; + if (r < 0) return log_debug_errno(r, "Failed to get NL80211_ATTR_MAC attribute: %m"); - return r == -ENODATA ? 0 : 1; + return 1; + +nodata: + *bssid = (struct ether_addr) {}; + return 0; }