From a5d39c3ec32b74350a648b25b38d39ba23e680b9 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 16 Jun 2022 21:22:02 -0700 Subject: [PATCH] [routing-manager] fix calculation if an entry's stale time is in past (#7818) This commit updates the calculation of the next stale time in `ResetDiscoveredPrefixStaleTimer()` in (unlikely) cases where the stale time of a discovered prefix or RA header happens to be in past (compared to `GetNow()`). In such a case, we use `now` as the stale time of the entry. This then ensures that the we can correctly compare the stale time with `now.GetDistantFuture()`. --- src/core/border_router/routing_manager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index dfdf971fa..ad073c25a 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -1371,14 +1371,15 @@ void RoutingManager::ResetDiscoveredPrefixStaleTimer(void) // Check for stale Router Advertisement Message if learnt from Host. if (mLearntRouterAdvMessageFromHost) { - TimeMilli routerAdvMessageStaleTime = mTimeRouterAdvMessageLastUpdate + Time::SecToMsec(kRtrAdvStaleTime); + TimeMilli routerAdvMessageStaleTime = + OT_MAX(mTimeRouterAdvMessageLastUpdate + Time::SecToMsec(kRtrAdvStaleTime), now); nextStaleTime = OT_MIN(nextStaleTime, routerAdvMessageStaleTime); } for (ExternalPrefix &externalPrefix : mDiscoveredPrefixes) { - TimeMilli prefixStaleTime = externalPrefix.GetStaleTime(); + TimeMilli prefixStaleTime = OT_MAX(externalPrefix.GetStaleTime(), now); if (externalPrefix.IsOnLinkPrefix()) {