From 61ecd9053158ef61b3afca75a8606e237f8cac8f Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 25 May 2022 11:23:09 -0700 Subject: [PATCH] [routing-manager] simplify invalidation of specific prefix (#7747) This commit simplifies the mechanism to invalidate/remove a specific prefix entry in `mDiscoveredPrefixes` list. Instead of passing the prefix to invalidate as an input to `InvalidateDiscoveredPrefixes()` method, we directly set the valid lifetime to zero on the entry in the list before calling the `InvalidateDiscoveredPrefixes()` to then remove all expired entries. This change addresses an issue in `HandleRouterSolicitTimer()` where while iterating over the `mDiscoveredPrefixes` list we could call `InvalidateDiscoveredPrefixes()` which then removed an entry from the list (thus changing the list). --- src/core/border_router/routing_manager.cpp | 26 +++++++++++----------- src/core/border_router/routing_manager.hpp | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 9605a1643..de636a02b 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -1015,11 +1015,13 @@ void RoutingManager::HandleRouterSolicitTimer(void) } else { - InvalidateDiscoveredPrefixes(&prefix.GetPrefix(), prefix.IsOnLinkPrefix()); + prefix.ClearValidLifetime(); } } } + InvalidateDiscoveredPrefixes(); + // Invalidate the learned RA message if it is not refreshed during Router Solicitation. if (mTimeRouterAdvMessageLastUpdate <= mTimeRouterSolicitStart) { @@ -1246,23 +1248,23 @@ void RoutingManager::UpdateDiscoveredOmrPrefix(const RouterAdv::RouteInfoOption LogInfo("Discovered OMR prefix (%s, %u seconds) from %s", prefix.ToString().AsCString(), aRio.GetRouteLifetime(), mInfraIf.ToString().AsCString()); - if (aRio.GetRouteLifetime() == 0) - { - InvalidateDiscoveredPrefixes(&prefix, /* aIsOnLinkPrefix */ false); - ExitNow(); - } - omrPrefix.InitFrom(aRio); existingPrefix = mDiscoveredPrefixes.Find(omrPrefix); - if (existingPrefix == nullptr) + if (omrPrefix.GetValidLifetime() == 0) { - if (omrPrefix.GetValidLifetime() == 0) + if (existingPrefix != nullptr) { - ExitNow(); + existingPrefix->ClearValidLifetime(); + InvalidateDiscoveredPrefixes(); } + ExitNow(); + } + + if (existingPrefix == nullptr) + { if (!mDiscoveredPrefixes.IsFull()) { SuccessOrExit(PublishExternalRoute(prefix, omrPrefix.GetRoutePreference())); @@ -1284,7 +1286,7 @@ exit: return; } -void RoutingManager::InvalidateDiscoveredPrefixes(const Ip6::Prefix *aPrefix, bool aIsOnLinkPrefix) +void RoutingManager::InvalidateDiscoveredPrefixes(void) { TimeMilli now = TimerMilli::GetNow(); uint8_t remainingOnLinkPrefixNum = 0; @@ -1298,8 +1300,6 @@ void RoutingManager::InvalidateDiscoveredPrefixes(const Ip6::Prefix *aPrefix, bo mIsAdvertisingLocalOnLinkPrefix && prefix.IsOnLinkPrefix() && mLocalOnLinkPrefix == prefix.GetPrefix(); if ( - // Invalidate specified prefix - (aPrefix != nullptr && prefix.GetPrefix() == *aPrefix && prefix.IsOnLinkPrefix() == aIsOnLinkPrefix) || // Invalidate expired prefix (prefix.GetExpireTime() <= now) || // Invalidate Local OMR prefixes diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index 299c3ed51..b4b501460 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -327,7 +327,7 @@ private: void HandleRouterAdvertisement(const InfraIf::Icmp6Packet &aPacket, const Ip6::Address &aSrcAddress); bool UpdateDiscoveredOnLinkPrefix(const RouterAdv::PrefixInfoOption &aPio); void UpdateDiscoveredOmrPrefix(const RouterAdv::RouteInfoOption &aRio); - void InvalidateDiscoveredPrefixes(const Ip6::Prefix *aPrefix = nullptr, bool aIsOnLinkPrefix = true); + void InvalidateDiscoveredPrefixes(void); void InvalidateAllDiscoveredPrefixes(void); bool NetworkDataContainsOmrPrefix(const Ip6::Prefix &aPrefix) const; bool UpdateRouterAdvMessage(const RouterAdv::RouterAdvMessage *aRouterAdvMessage);