diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index d11cbe632..b429408dc 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -750,6 +750,22 @@ exit: return; } +void RoutingManager::HandleLocalOnLinkPrefixChanged(void) +{ + // This is a callback from `OnLinkPrefixManager` indicating + // that the local on-link prefix is changed. The local on-link + // prefix is derived from extended PAN ID. + + VerifyOrExit(mIsRunning); + + mRoutePublisher.Evaluate(); + mRxRaTracker.HandleLocalOnLinkPrefixChanged(); + ScheduleRoutingPolicyEvaluation(kAfterRandomDelay); + +exit: + return; +} + bool RoutingManager::NetworkDataContainsUlaRoute(void) const { // Determine whether leader Network Data contains a route @@ -1123,10 +1139,7 @@ void RoutingManager::RxRaTracker::ProcessPrefixInfoOption(const PrefixInfoOption ExitNow(); } - if (Get().mOnLinkPrefixManager.IsPublishingOrAdvertising()) - { - VerifyOrExit(prefix != Get().mOnLinkPrefixManager.GetLocalPrefix()); - } + VerifyOrExit(prefix != Get().mOnLinkPrefixManager.GetLocalPrefix()); LogPrefixInfoOption(prefix, aPio.GetValidLifetime(), aPio.GetPreferredLifetime()); @@ -1348,13 +1361,14 @@ void RoutingManager::RxRaTracker::FindFavoredOnLinkPrefix(Ip6::Prefix &aPrefix) } } -void RoutingManager::RxRaTracker::RemoveOnLinkPrefix(const Ip6::Prefix &aPrefix) +void RoutingManager::RxRaTracker::HandleLocalOnLinkPrefixChanged(void) { - bool didRemove = false; + const Ip6::Prefix &prefix = Get().mOnLinkPrefixManager.GetLocalPrefix(); + bool didRemove = false; for (Router &router : mRouters) { - didRemove |= router.mOnLinkPrefixes.RemoveAndFreeAllMatching(aPrefix); + didRemove |= router.mOnLinkPrefixes.RemoveAndFreeAllMatching(prefix); } VerifyOrExit(didRemove); @@ -2315,13 +2329,6 @@ void RoutingManager::OnLinkPrefixManager::Evaluate(void) PublishAndAdvertise(); - // We remove the local on-link prefix from the discovered prefix - // table, in case it was previously discovered and is now - // deprecating. `ShouldProcessPrefixInfoOption()` also prevents - // adding the local prefix to the table while we're advertising it. - - Get().mRxRaTracker.RemoveOnLinkPrefix(mLocalPrefix); - mFavoredDiscoveredPrefix.Clear(); } else if (IsPublishingOrAdvertising()) @@ -2566,11 +2573,7 @@ void RoutingManager::OnLinkPrefixManager::HandleExtPanIdChange(void) break; } - if (Get().mIsRunning) - { - Get().mRoutePublisher.Evaluate(); - Get().ScheduleRoutingPolicyEvaluation(kAfterRandomDelay); - } + Get().HandleLocalOnLinkPrefixChanged(); exit: return; diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index 25b71f15c..85f9cb944 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -755,8 +755,8 @@ private: void FindFavoredOnLinkPrefix(Ip6::Prefix &aPrefix) const; + void HandleLocalOnLinkPrefixChanged(void); void HandleNetDataChange(void); - void RemoveOnLinkPrefix(const Ip6::Prefix &aPrefix); void RemoveOrDeprecateOldEntries(TimeMilli aTimeThreshold); @@ -1028,7 +1028,6 @@ private: void HandleRaPrefixTableChanged(void); bool ShouldPublishUlaRoute(void) const; Error AppendAsPiosTo(RouterAdvert::TxMessage &aRaMessage); - bool IsPublishingOrAdvertising(void) const; void HandleNetDataChange(void); void HandleExtPanIdChange(void); void HandleTimer(void); @@ -1052,6 +1051,7 @@ private: State GetState(void) const { return mState; } void SetState(State aState); + bool IsPublishingOrAdvertising(void) const; void GenerateLocalPrefix(void); void PublishAndAdvertise(void); void Deprecate(void); @@ -1392,6 +1392,7 @@ private: bool NetworkDataContainsUlaRoute(void) const; void HandleRaPrefixTableChanged(void); + void HandleLocalOnLinkPrefixChanged(void); static bool IsValidBrUlaPrefix(const Ip6::Prefix &aBrUlaPrefix); static bool IsValidOnLinkPrefix(const PrefixInfoOption &aPio);