From 387831b697097ba71b982fffc26655761c1b07e9 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 20 Jun 2024 20:11:27 -0700 Subject: [PATCH] [routing-manager] simplify `RxRaTracker::HandleRouterTimer()` (#10382) This commit simplifies `RxRaTracker::HandleRouterTimer()`. When all NS probes to a router fail and it is marked as unreachable, `HandleRouterTimer()` now directly removes/deprecates its route/on-link prefixes, replacing a separate method previously used for this purpose. Additionally, a new helper method, `ShouldCheckReachability()`, is added to check if a reachability check (sending NS probes) is needed. This check is performed only if the router is not already marked as unreachable and is not the local device itself. --- src/core/border_router/routing_manager.cpp | 93 +++++++++------------- src/core/border_router/routing_manager.hpp | 2 +- 2 files changed, 39 insertions(+), 56 deletions(-) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 5e4dd2d08..b3ec00fe4 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -1459,37 +1459,6 @@ void RoutingManager::RxRaTracker::RemoveOrDeprecateOldEntries(TimeMilli aTimeThr RemoveExpiredEntries(); } -void RoutingManager::RxRaTracker::RemoveOrDeprecateEntriesFromUnreachableRouters(void) -{ - // Remove route prefix entries and deprecate on-link prefix entries - // in the table for routers that have reached the max NS probe - // attempts and considered unreachable. - - for (Router &router : mRouters) - { - if (router.IsReachable()) - { - continue; - } - - for (OnLinkPrefix &entry : router.mOnLinkPrefixes) - { - if (!entry.IsDeprecated()) - { - entry.ClearPreferredLifetime(); - SignalTableChanged(); - } - } - - for (RoutePrefix &entry : router.mRoutePrefixes) - { - entry.ClearValidLifetime(); - } - } - - RemoveExpiredEntries(); -} - void RoutingManager::RxRaTracker::ScheduleAllTimers(void) { TimeMilli now = TimerMilli::GetNow(); @@ -1522,10 +1491,8 @@ void RoutingManager::RxRaTracker::ScheduleAllTimers(void) for (const Router &router : mRouters) { - if (router.IsReachable() && !router.mIsLocalDevice) + if (router.ShouldCheckReachability()) { - // Skip if router is this device or has failed all - // earlier NS probes. routerTimeout.UpdateIfEarlier(router.mTimeout); } @@ -1708,39 +1675,45 @@ void RoutingManager::RxRaTracker::HandleRouterTimer(void) for (Router &router : mRouters) { - if (!router.IsReachable()) + if (!router.ShouldCheckReachability() || (router.mTimeout > now)) { continue; } - // Skip NS probes if the router is this device. This prevents - // issues where the platform might not be able to receive and - // process the NA messages from the local device itself. + router.mNsProbeCount++; - if (router.mIsLocalDevice) + if (router.IsReachable()) { - continue; - } - - if (router.mTimeout <= now) - { - router.mNsProbeCount++; - - if (!router.IsReachable()) - { - LogInfo("No response to all Neighbor Solicitations attempts from router %s", - router.mAddress.ToString().AsCString()); - continue; - } - router.mTimeout = now + ((router.mNsProbeCount < Router::kMaxNsProbes) ? Router::kNsProbeRetryInterval : Router::kNsProbeTimeout); - SendNeighborSolicitToRouter(router); } + else + { + LogInfo("No response to all Neighbor Solicitations attempts from router %s - marking it unreachable", + router.mAddress.ToString().AsCString()); + + // Remove route prefix entries and deprecate on-link prefix entries + // of the unreachable router. + + for (OnLinkPrefix &entry : router.mOnLinkPrefixes) + { + if (!entry.IsDeprecated()) + { + entry.ClearPreferredLifetime(); + SignalTableChanged(); + } + } + + for (RoutePrefix &entry : router.mRoutePrefixes) + { + entry.ClearValidLifetime(); + SignalTableChanged(); + } + } } - RemoveOrDeprecateEntriesFromUnreachableRouters(); + RemoveExpiredEntries(); ScheduleAllTimers(); } @@ -1940,6 +1913,16 @@ exit: //--------------------------------------------------------------------------------------------------------------------- // RxRaTracker::Router +bool RoutingManager::RxRaTracker::Router::ShouldCheckReachability(void) const +{ + // Perform reachability check (send NS probes) only if the router: + // - Is not already marked as unreachable (due to failed NS probes) + // - Is not the local device itself (to avoid potential issues with + // the platform receiving/processing NAs from itself). + + return IsReachable() && !mIsLocalDevice; +} + bool RoutingManager::RxRaTracker::Router::Matches(EmptyChecker aChecker) const { // Checks whether or not a `Router` instance has any useful info. An diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index 41160638f..16286658b 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -828,6 +828,7 @@ private: }; bool IsReachable(void) const { return mNsProbeCount <= kMaxNsProbes; } + bool ShouldCheckReachability(void) const; bool Matches(const Ip6::Address &aAddress) const { return aAddress == mAddress; } bool Matches(EmptyChecker aChecker) const; void CopyInfoTo(RouterEntry &aEntry, TimeMilli aNow) const; @@ -915,7 +916,6 @@ private: void ProcessRouteInfoOption(const RouteInfoOption &aRio, Router &aRouter); void ProcessRaFlagsExtOption(const RaFlagsExtOption &aFlagsOption, Router &aRouter); bool ContainsOnLinkPrefix(OnLinkPrefix::UlaChecker aUlaChecker) const; - void RemoveOrDeprecateEntriesFromUnreachableRouters(void); void RemoveRoutersWithNoEntriesOrFlags(void); void RemoveExpiredEntries(void); void SignalTableChanged(void);