diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 1a7d2e8f2..443e81854 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -1022,7 +1022,7 @@ void RoutingManager::HandleRouterAdvertisement(const Ip6::Address &aSrcAddress, if (pio->IsValid()) { - needReevaluate |= UpdateDiscoveredPrefixes(*pio); + needReevaluate |= UpdateDiscoveredOnLinkPrefix(*pio); } } break; @@ -1033,7 +1033,7 @@ void RoutingManager::HandleRouterAdvertisement(const Ip6::Address &aSrcAddress, if (rio->IsValid()) { - needReevaluate |= UpdateDiscoveredPrefixes(*rio); + UpdateDiscoveredOmrPrefix(*rio); } } break; @@ -1059,7 +1059,10 @@ exit: return; } -bool RoutingManager::UpdateDiscoveredPrefixes(const RouterAdv::PrefixInfoOption &aPio) +// Adds or deprecates a discovered on-link prefix (new external routes may be added +// to the Thread network). Returns a boolean which indicates whether we need to do +// routing policy evaluation. +bool RoutingManager::UpdateDiscoveredOnLinkPrefix(const RouterAdv::PrefixInfoOption &aPio) { Ip6::Prefix prefix = aPio.GetPrefix(); bool needReevaluate = false; @@ -1153,10 +1156,11 @@ exit: return needReevaluate; } -bool RoutingManager::UpdateDiscoveredPrefixes(const RouterAdv::RouteInfoOption &aRio) +// Adds or removes a discovered OMR prefix (external route will be added to or removed +// from the Thread network). +void RoutingManager::UpdateDiscoveredOmrPrefix(const RouterAdv::RouteInfoOption &aRio) { - Ip6::Prefix prefix = aRio.GetPrefix(); - bool needReevaluate = false; + Ip6::Prefix prefix = aRio.GetPrefix(); ExternalPrefix omrPrefix; ExternalPrefix *existingPrefix = nullptr; @@ -1184,7 +1188,7 @@ bool RoutingManager::UpdateDiscoveredPrefixes(const RouterAdv::RouteInfoOption & if (aRio.GetRouteLifetime() == 0) { - needReevaluate = InvalidateDiscoveredPrefixes(&prefix, /* aIsOnLinkPrefix */ false); + InvalidateDiscoveredPrefixes(&prefix, /* aIsOnLinkPrefix */ false); ExitNow(); } @@ -1215,7 +1219,6 @@ bool RoutingManager::UpdateDiscoveredPrefixes(const RouterAdv::RouteInfoOption & { SuccessOrExit(AddExternalRoute(prefix, omrPrefix.mRoutePreference)); existingPrefix = mDiscoveredPrefixes.PushBack(); - needReevaluate = true; } else { @@ -1230,12 +1233,11 @@ bool RoutingManager::UpdateDiscoveredPrefixes(const RouterAdv::RouteInfoOption & mDiscoveredPrefixStaleTimer.FireAtIfEarlier(existingPrefix->GetStaleTime()); exit: - return needReevaluate; + return; } -bool RoutingManager::InvalidateDiscoveredPrefixes(const Ip6::Prefix *aPrefix, bool aIsOnLinkPrefix) +void RoutingManager::InvalidateDiscoveredPrefixes(const Ip6::Prefix *aPrefix, bool aIsOnLinkPrefix) { - bool didRemove = false; TimeMilli now = TimerMilli::GetNow(); uint8_t remainingOnLinkPrefixNum = 0; ExternalPrefixArray remainingPrefixes; @@ -1248,7 +1250,6 @@ bool RoutingManager::InvalidateDiscoveredPrefixes(const Ip6::Prefix *aPrefix, bo (prefix.GetExpireTime() <= now)) { RemoveExternalRoute(prefix.mPrefix); - didRemove = true; } else { @@ -1271,8 +1272,6 @@ bool RoutingManager::InvalidateDiscoveredPrefixes(const Ip6::Prefix *aPrefix, bo // To discover more on-link prefixes or timeout to advertise my local on-link prefix. StartRouterSolicitationDelay(); } - - return didRemove; // If anything was removed we need to reevaluate. } void RoutingManager::InvalidateAllDiscoveredPrefixes(void) diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index ec60fdd6b..ab383b6da 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -307,9 +307,9 @@ private: void DeprecateOnLinkPrefix(void); void HandleRouterSolicit(const Ip6::Address &aSrcAddress, const uint8_t *aBuffer, uint16_t aBufferLength); void HandleRouterAdvertisement(const Ip6::Address &aSrcAddress, const uint8_t *aBuffer, uint16_t aBufferLength); - bool UpdateDiscoveredPrefixes(const RouterAdv::PrefixInfoOption &aPio); - bool UpdateDiscoveredPrefixes(const RouterAdv::RouteInfoOption &aRio); - bool InvalidateDiscoveredPrefixes(const Ip6::Prefix *aPrefix = nullptr, bool aIsOnLinkPrefix = true); + bool UpdateDiscoveredOnLinkPrefix(const RouterAdv::PrefixInfoOption &aPio); + void UpdateDiscoveredOmrPrefix(const RouterAdv::RouteInfoOption &aRio); + void InvalidateDiscoveredPrefixes(const Ip6::Prefix *aPrefix = nullptr, bool aIsOnLinkPrefix = true); void InvalidateAllDiscoveredPrefixes(void); bool NetworkDataContainsOmrPrefix(const Ip6::Prefix &aPrefix) const; bool UpdateRouterAdvMessage(const RouterAdv::RouterAdvMessage *aRouterAdvMessage);