Skip to content

Commit

Permalink
[routing-manager] fix IsDeprecated() to handle large preferred life…
Browse files Browse the repository at this point in the history
…time (openthread#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.
  • Loading branch information
abtink authored Feb 2, 2024
1 parent 686eb30 commit 21cd366
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/border_router/routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<uint32_t>::kMax;

static constexpr uint32_t kRioValidLifetime = 1800;
static constexpr uint32_t kRioDeprecatingLifetime = 300;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 21cd366

Please sign in to comment.