nl80211: Check if_indextoname() return value for bridge events
authorJouni Malinen <j@w1.fi>
Tue, 23 Dec 2014 17:35:34 +0000 (19:35 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 23 Dec 2014 17:43:24 +0000 (19:43 +0200)
It would be at least theoretically possible for the bridge netdev to
have disappeared at the time hostapd processes the RTM newlink/dellink
message. As such, it is better to verify that if_indextoname() actually
returned success before printing the bridge ifname in debug. In
addition, there is not much point trying to add the bridge ifindex into
the list of own ifindexes in case the interface has already been
removed, so skip that part as well.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/drivers/driver_nl80211.c

index 3861ec0..9e005e2 100644 (file)
@@ -740,7 +740,7 @@ static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
 
 
 static void wpa_driver_nl80211_event_newlink(
-       struct wpa_driver_nl80211_data *drv, char *ifname)
+       struct wpa_driver_nl80211_data *drv, const char *ifname)
 {
        union wpa_event_data event;
 
@@ -766,7 +766,7 @@ static void wpa_driver_nl80211_event_newlink(
 
 
 static void wpa_driver_nl80211_event_dellink(
-       struct wpa_driver_nl80211_data *drv, char *ifname)
+       struct wpa_driver_nl80211_data *drv, const char *ifname)
 {
        union wpa_event_data event;
 
@@ -1008,7 +1008,12 @@ static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
                struct i802_bss *bss;
 
                /* device has been added to bridge */
-               if_indextoname(brid, namebuf);
+               if (!if_indextoname(brid, namebuf)) {
+                       wpa_printf(MSG_DEBUG,
+                                  "nl80211: Could not find bridge ifname for ifindex %u",
+                                  brid);
+                       return;
+               }
                wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
                           brid, namebuf);
                add_ifidx(drv, brid);
@@ -1088,9 +1093,16 @@ static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
        if (ifi->ifi_family == AF_BRIDGE && brid) {
                /* device has been removed from bridge */
                char namebuf[IFNAMSIZ];
-               if_indextoname(brid, namebuf);
-               wpa_printf(MSG_DEBUG, "nl80211: Remove ifindex %u for bridge "
-                          "%s", brid, namebuf);
+
+               if (!if_indextoname(brid, namebuf)) {
+                       wpa_printf(MSG_DEBUG,
+                                  "nl80211: Could not find bridge ifname for ifindex %u",
+                                  brid);
+               } else {
+                       wpa_printf(MSG_DEBUG,
+                                  "nl80211: Remove ifindex %u for bridge %s",
+                                  brid, namebuf);
+               }
                del_ifidx(drv, brid);
        }
 }