mirror of
https://github.com/espressif/openthread.git
synced 2026-08-02 00:57:47 +00:00
[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).
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user