[routing-manager] directly remove on-link prefix from discovered list on advert start (#7764)

This commit changes `EvaluteOnLinkPrefix()` so that when we decide to
start advertising the local on-link prefix, we go through the list of
discovered prefixes to check if the local prefix was previously discovered
and included in the list, and remove it from the list (without
unpublishing it from Thread Network Data). This change allows us to
simplify `InvalidateDiscoveredPrefixes()` which was earlier called and
was in charge of removing the local prefix.

This helps align the logic that when we are advertising the on-link
prefix, we do not allow it to be added in the discovered prefix list
from `UpdateDiscoveredOnLinkPrefix()`.
This commit is contained in:
Abtin Keshavarzian
2022-05-30 22:06:00 -07:00
committed by GitHub
parent bfb60204fc
commit 40484c9468
+23 -16
View File
@@ -578,11 +578,25 @@ void RoutingManager::EvaluateOnLinkPrefix(void)
LogInfo("Start advertising on-link prefix %s on %s", mLocalOnLinkPrefix.ToString().AsCString(),
mInfraIf.ToString().AsCString());
// Call `InvalidateDiscoveredPrefixes()` after setting
// `mIsAdvertisingLocalOnLinkPrefix` to remove on-link
// prefix in case it was discovered and included in
// `mDiscoveredPrefixes` list earlier.
InvalidateDiscoveredPrefixes();
// We go through `mDiscoveredPrefixes` list to check if the
// local on-link prefix was previously discovered and
// included in the list and if so we remove it from list.
//
// Note that `UpdateDiscoveredOnLinkPrefix()` will also
// check and not add local on-link prefix in the discovered
// prefix list while we are advertising the local on-link
// prefix.
for (ExternalPrefix &prefix : mDiscoveredPrefixes)
{
if (prefix.IsOnLinkPrefix() && mLocalOnLinkPrefix == prefix.GetPrefix())
{
// To remove the prefix from the list, we copy the
// popped last entry into `prefix` entry.
prefix = *mDiscoveredPrefixes.PopBack();
break;
}
}
}
mOnLinkPrefixDeprecateTimer.Stop();
@@ -1297,23 +1311,16 @@ void RoutingManager::InvalidateDiscoveredPrefixes(void)
for (ExternalPrefixArray::IndexType index = 0; index < mDiscoveredPrefixes.GetLength();)
{
ExternalPrefix &prefix = mDiscoveredPrefixes[index];
bool isAdvertisedLocalOnLinkPrefix =
mIsAdvertisingLocalOnLinkPrefix && prefix.IsOnLinkPrefix() && mLocalOnLinkPrefix == prefix.GetPrefix();
// We invalidate expired prefixes, or local OMR prefixes
// (either in `mAdvertisedOmrPrefixes` or in Thread Network
// Data), or if the prefix matches the local on-link prefix
// (when local on-link prefix is being advertised).
// Data).
if ((prefix.GetExpireTime() <= now) ||
(!prefix.IsOnLinkPrefix() && (mAdvertisedOmrPrefixes.Contains(prefix.GetPrefix()) ||
NetworkDataContainsOmrPrefix(prefix.GetPrefix()))) ||
isAdvertisedLocalOnLinkPrefix)
(!prefix.IsOnLinkPrefix() &&
(mAdvertisedOmrPrefixes.Contains(prefix.GetPrefix()) || NetworkDataContainsOmrPrefix(prefix.GetPrefix()))))
{
if (!isAdvertisedLocalOnLinkPrefix)
{
UnpublishExternalRoute(prefix.GetPrefix());
}
UnpublishExternalRoute(prefix.GetPrefix());
// Remove the prefix from the array by replacing it with
// last entry in the array (we copy the popped last entry