diff --git a/src/netdev.c b/src/netdev.c index ce7c7a24..a48c76c6 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -30,6 +30,7 @@ #include #include +#include "src/wiphy.h" #include "src/netdev.h" struct netdev_data { @@ -92,6 +93,8 @@ static void dellink_notify(const struct ifinfomsg *ifi, int bytes) struct netdev_data *netdev; uint32_t index = ifi->ifi_index; + wiphy_notify_dellink(index); + netdev = l_hashmap_remove(netdev_list, L_UINT_TO_PTR(index)); if (!netdev) return; diff --git a/src/wiphy.c b/src/wiphy.c index b6b4f6bb..f485263c 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -443,3 +443,25 @@ bool wiphy_exit(void) return true; } + +static void wiphy_check_dellink(void *data, void *user_data) +{ + uint32_t index = L_PTR_TO_UINT(user_data); + struct wiphy *wiphy = data; + struct netdev *netdev; + + netdev = l_queue_remove_if(wiphy->netdev_list, netdev_match, + L_UINT_TO_PTR(index)); + if (netdev) { + l_warn("Removing leftover interface %s", netdev->name); + netdev_free(netdev); + } +} + +void wiphy_notify_dellink(uint32_t index) +{ + if (!wiphy_list) + return; + + l_queue_foreach(wiphy_list, wiphy_check_dellink, L_UINT_TO_PTR(index)); +} diff --git a/src/wiphy.h b/src/wiphy.h index b1d75505..13535a33 100644 --- a/src/wiphy.h +++ b/src/wiphy.h @@ -20,7 +20,10 @@ * */ +#include #include bool wiphy_init(void); bool wiphy_exit(void); + +void wiphy_notify_dellink(uint32_t index);