From 002f09f2da88c125c6620be46ac93aaddbc80a50 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 11 Nov 2018 12:43:03 -0600 Subject: [PATCH] net/mld: Fix logic error when testing for the case where all members have left. Still does not work. The end result is that the query timer no longer stops. Not when another another querier with a lower IP is present or when all of the members have left. Basically just can't stop querying under any condition. --- net/mld/mld_group.c | 41 ++++++++++++++++++++++++++++++++++++++-- net/mld/mld_initialize.c | 5 ++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/net/mld/mld_group.c b/net/mld/mld_group.c index 80fce37b8e..5a4dbf2c4a 100644 --- a/net/mld/mld_group.c +++ b/net/mld/mld_group.c @@ -60,6 +60,40 @@ #ifdef CONFIG_NET_MLD +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mld_ngroups + * + * Description: + * Return the number of groups joined by applications. + * + ****************************************************************************/ + +static int mld_ngroups(FAR struct net_driver_s *dev) +{ + FAR struct mld_group_s *group; + int ngroups; + + /* Count the number of groups in the group list */ + + for (group = (FAR struct mld_group_s *)dev->d_mld.grplist.head; + group != NULL; + group = group->next) + { + ngroups++; + } + + /* REVISIT: Subtract one for the IPv6 allnodes group. Why is this here? + * what do we need it for? It was cloned from IGMP and is probably not + * needed. + */ + + return ngroups - 1; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -118,7 +152,7 @@ FAR struct mld_group_s *mld_grpalloc(FAR struct net_driver_s *dev, * group member of the group. */ - if (dev->d_mld.grplist.head == NULL) + if (mld_ngroups(dev) < 1) { mld_start_gentimer(dev, MSEC2TICK(MLD_QUERY_MSEC)); } @@ -240,9 +274,12 @@ void mld_grpfree(FAR struct net_driver_s *dev, FAR struct mld_group_s *group) #ifndef CONFIG_CONFIG_NET_MLD_ROUTER /* If there are no longer any groups, then stop the general query and v1 * compatibility timers. + * + * REVISIT: Does not work. Continues to query after the last group + * leaves. */ - if (dev->d_mld.grplist.head == NULL) + if (mld_ngroups(dev) < 1) { wd_cancel(dev->d_mld.gendog); wd_cancel(dev->d_mld.v1dog); diff --git a/net/mld/mld_initialize.c b/net/mld/mld_initialize.c index 912bc4f7f0..cfe3b1f381 100644 --- a/net/mld/mld_initialize.c +++ b/net/mld/mld_initialize.c @@ -92,7 +92,10 @@ void mld_devinit(struct net_driver_s *dev) SET_MLD_QUERIER(dev->d_mld.flags); - /* Add the all nodes address to the group */ + /* Add the all nodes address to the group + * REVISIT: Do we need this? What is it for? It is clone from IGMP and + * probably is not relevant here. + */ (void)mld_grpalloc(dev, g_ipv6_allnodes);