mac802154: Avoid new associations while disassociating

While disassociating from a PAN ourselves, let's set the maximum number
of associations temporarily to zero to be sure no new device tries to
associate with us.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Acked-by: Stefan Schmidt <stefan@datenfreihafen.org>
Acked-by: Alexander Aring <aahringo@redhat.com>
Link: https://lore.kernel.org/linux-wpan/20231128111655.507479-6-miquel.raynal@bootlin.com
This commit is contained in:
Miquel Raynal 2023-11-28 12:16:55 +01:00
parent b720383ab1
commit 2373699560
3 changed files with 18 additions and 5 deletions

View File

@ -589,8 +589,10 @@ cfg802154_device_is_child(struct wpan_dev *wpan_dev,
* cfg802154_set_max_associations - Limit the number of future associations * cfg802154_set_max_associations - Limit the number of future associations
* @wpan_dev: the wpan device * @wpan_dev: the wpan device
* @max: the maximum number of devices we accept to associate * @max: the maximum number of devices we accept to associate
* @return: the old maximum value
*/ */
void cfg802154_set_max_associations(struct wpan_dev *wpan_dev, unsigned int max); unsigned int cfg802154_set_max_associations(struct wpan_dev *wpan_dev,
unsigned int max);
/** /**
* cfg802154_get_free_short_addr - Get a free address among the known devices * cfg802154_get_free_short_addr - Get a free address among the known devices

View File

@ -94,10 +94,16 @@ __le16 cfg802154_get_free_short_addr(struct wpan_dev *wpan_dev)
} }
EXPORT_SYMBOL_GPL(cfg802154_get_free_short_addr); EXPORT_SYMBOL_GPL(cfg802154_get_free_short_addr);
void cfg802154_set_max_associations(struct wpan_dev *wpan_dev, unsigned int max) unsigned int cfg802154_set_max_associations(struct wpan_dev *wpan_dev,
unsigned int max)
{ {
unsigned int old_max;
lockdep_assert_held(&wpan_dev->association_lock); lockdep_assert_held(&wpan_dev->association_lock);
old_max = wpan_dev->max_associations;
wpan_dev->max_associations = max; wpan_dev->max_associations = max;
return old_max;
} }
EXPORT_SYMBOL_GPL(cfg802154_set_max_associations); EXPORT_SYMBOL_GPL(cfg802154_set_max_associations);

View File

@ -389,6 +389,7 @@ static int mac802154_disassociate_from_parent(struct wpan_phy *wpan_phy,
struct ieee802154_local *local = wpan_phy_priv(wpan_phy); struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
struct ieee802154_pan_device *child, *tmp; struct ieee802154_pan_device *child, *tmp;
struct ieee802154_sub_if_data *sdata; struct ieee802154_sub_if_data *sdata;
unsigned int max_assoc;
u64 eaddr; u64 eaddr;
int ret; int ret;
@ -397,6 +398,7 @@ static int mac802154_disassociate_from_parent(struct wpan_phy *wpan_phy,
/* Start by disassociating all the children and preventing new ones to /* Start by disassociating all the children and preventing new ones to
* attempt associations. * attempt associations.
*/ */
max_assoc = cfg802154_set_max_associations(wpan_dev, 0);
list_for_each_entry_safe(child, tmp, &wpan_dev->children, node) { list_for_each_entry_safe(child, tmp, &wpan_dev->children, node) {
ret = mac802154_send_disassociation_notif(sdata, child, ret = mac802154_send_disassociation_notif(sdata, child,
IEEE802154_COORD_WISHES_DEVICE_TO_LEAVE); IEEE802154_COORD_WISHES_DEVICE_TO_LEAVE);
@ -429,14 +431,17 @@ static int mac802154_disassociate_from_parent(struct wpan_phy *wpan_phy,
if (local->hw.flags & IEEE802154_HW_AFILT) { if (local->hw.flags & IEEE802154_HW_AFILT) {
ret = drv_set_pan_id(local, wpan_dev->pan_id); ret = drv_set_pan_id(local, wpan_dev->pan_id);
if (ret < 0) if (ret < 0)
return ret; goto reset_mac_assoc;
ret = drv_set_short_addr(local, wpan_dev->short_addr); ret = drv_set_short_addr(local, wpan_dev->short_addr);
if (ret < 0) if (ret < 0)
return ret; goto reset_mac_assoc;
} }
return 0; reset_mac_assoc:
cfg802154_set_max_associations(wpan_dev, max_assoc);
return ret;
} }
static int mac802154_disassociate_child(struct wpan_phy *wpan_phy, static int mac802154_disassociate_child(struct wpan_phy *wpan_phy,