diff --git a/net/mld/mld.h b/net/mld/mld.h index 50b5ebb99e4..c67711c50cc 100644 --- a/net/mld/mld.h +++ b/net/mld/mld.h @@ -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 * diff --git a/net/mld/mld_group.c b/net/mld/mld_group.c index 588de815665..d5152f21970 100644 --- a/net/mld/mld_group.c +++ b/net/mld/mld_group.c @@ -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 */ diff --git a/net/netdev/netdev_unregister.c b/net/netdev/netdev_unregister.c index fea06799588..57f59a9dee2 100644 --- a/net/netdev/netdev_unregister.c +++ b/net/netdev/netdev_unregister.c @@ -37,6 +37,7 @@ #include #include +#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