mld: free all mld group when netdev unregister

otherwise, if the mld timers are not cancelled, an illegal address will
be accessed after timeout. to avoid this scenario, when the network card
is unregistered, all MLD timers must be attempted to be synchronously
cancelled.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-07-01 11:48:32 +08:00
committed by Alan C. Assis
parent c2a4899941
commit a0bd741387
3 changed files with 46 additions and 0 deletions
+10
View File
@@ -330,6 +330,16 @@ FAR struct mld_group_s *mld_grpallocfind(FAR struct net_driver_s *dev,
void mld_grpfree(FAR struct net_driver_s *dev,
FAR struct mld_group_s *group);
/****************************************************************************
* Name: mld_grpfree_all
*
* Description:
* Release all previously allocated groups for a device.
*
****************************************************************************/
void mld_grpfree_all(FAR struct net_driver_s *dev);
/****************************************************************************
* Name: mld_new_pollcycle
*
+25
View File
@@ -285,4 +285,29 @@ void mld_new_pollcycle(FAR struct net_driver_s *dev)
}
#endif
/****************************************************************************
* Name: mld_grpfree_all
*
* Description:
* Release all previously allocated groups for a device.
*
* Assumptions:
* The network is locked.
*
****************************************************************************/
void mld_grpfree_all(FAR struct net_driver_s *dev)
{
FAR struct mld_group_s *group =
(FAR struct mld_group_s *)dev->d_mld.grplist.head;
FAR struct mld_group_s *next;
while (group != NULL)
{
next = group->next;
mld_grpfree(dev, group);
group = next;
}
}
#endif /* CONFIG_NET_MLD */
+11
View File
@@ -37,6 +37,7 @@
#include <net/ethernet.h>
#include <nuttx/net/netdev.h>
#include "mld/mld.h"
#include "utils/utils.h"
#include "netdev/netdev.h"
@@ -150,6 +151,16 @@ int netdev_unregister(FAR struct net_driver_s *dev)
#ifdef CONFIG_NETDEV_IFINDEX
free_ifindex(dev->d_ifindex);
#endif
#ifdef CONFIG_NET_MLD
if ((dev->d_flags & IFF_MULTICAST) != 0)
{
/* MLD is only supported on multicast capable devices */
mld_grpfree_all(dev);
}
#endif
net_unlock();
#if CONFIG_NETDEV_STATISTICS_LOG_PERIOD > 0