From 21cd366b50e030a23eafb65cfedceb28fb4d2595 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 1 Feb 2024 19:04:54 -0800 Subject: [PATCH] [routing-manager] fix `IsDeprecated()` to handle large preferred lifetime (#9822) This commit fixes `DiscoveredPrefixTable::Entry::IsDeprecated()` to properly handle larger preferred lifetime values. It uses the method `CalculateExpireDelay()` to handle time delay calculation, avoiding overflow. The `test_routing_manager` test has also been updated to check for larger preferred/valid lifetime values. --- src/core/border_router/routing_manager.cpp | 2 +- tests/unit/test_routing_manager.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 4173626e4e6..81f2d9abbbf 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -1838,7 +1838,7 @@ bool RoutingManager::DiscoveredPrefixTable::Entry::IsDeprecated(void) const { OT_ASSERT(IsOnLinkPrefix()); - return mLastUpdateTime + TimeMilli::SecToMsec(GetPreferredLifetime()) <= TimerMilli::GetNow(); + return mLastUpdateTime + CalculateExpireDelay(GetPreferredLifetime()) <= TimerMilli::GetNow(); } RoutingManager::RoutePreference RoutingManager::DiscoveredPrefixTable::Entry::GetPreference(void) const diff --git a/tests/unit/test_routing_manager.cpp b/tests/unit/test_routing_manager.cpp index 6fc0a37d5dc..df7c2b22536 100644 --- a/tests/unit/test_routing_manager.cpp +++ b/tests/unit/test_routing_manager.cpp @@ -38,6 +38,7 @@ #include "border_router/routing_manager.hpp" #include "common/arg_macros.hpp" #include "common/array.hpp" +#include "common/numeric_limits.hpp" #include "common/time.hpp" #include "instance/instance.hpp" #include "net/icmp6.hpp" @@ -57,6 +58,7 @@ static const char kInfraIfAddress[] = "fe80::1"; static constexpr uint32_t kValidLitime = 2000; static constexpr uint32_t kPreferredLifetime = 1800; +static constexpr uint32_t kInfiniteLifetime = NumericLimits::kMax; static constexpr uint32_t kRioValidLifetime = 1800; static constexpr uint32_t kRioDeprecatingLifetime = 300; @@ -1876,7 +1878,7 @@ void TestLocalOnLinkPrefixDeprecation(void) // Send an RA from router A with a new on-link (PIO) which is preferred over // the local on-link prefix. - SendRouterAdvert(routerAddressA, {Pio(onLinkPrefix, kValidLitime, kPreferredLifetime)}); + SendRouterAdvert(routerAddressA, {Pio(onLinkPrefix, kInfiniteLifetime, kInfiniteLifetime)}); //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Check that the local on-link prefix is now deprecating in the new RA.