From d2e74dc705066a41dd291d7e7b757e7535c57206 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 30 May 2024 11:36:48 -0700 Subject: [PATCH] [routing-manager] fix lifetime management of PD prefix (#10310) This commit updates `PdPrefixManager` to use the newly added `GetDeprecationTime()` method for managing the lifetime of a DHCPv6 PD prefix. This method calculates the deprecation time using the prefix preferred lifetime directly, instead of relying on the RA stale time constant `GetStaleTime()`. While the PD prefix may be determined by processing RA messages received on the Thread interface, the RA stale time is not relevant in this context. The RA stale time is only applicable to RA messages received over infra-if. It specifies the time that can pass after the last RA from a particular router on infra-if before assuming the router might be unavailable and triggering Router Solicitation (RS) messages. --- src/core/border_router/routing_manager.cpp | 19 ++++----------- src/core/border_router/routing_manager.hpp | 2 +- tests/unit/test_routing_manager.cpp | 27 +++++++++++++++++++++- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 761ae63ff..e5ffe1464 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -858,9 +858,11 @@ void RoutingManager::OnLinkPrefix::SetFrom(const PrefixTableEntry &aPrefixTableE mLastUpdateTime = TimerMilli::GetNow(); } -bool RoutingManager::OnLinkPrefix::IsDeprecated(void) const +bool RoutingManager::OnLinkPrefix::IsDeprecated(void) const { return GetDeprecationTime() <= TimerMilli::GetNow(); } + +TimeMilli RoutingManager::OnLinkPrefix::GetDeprecationTime(void) const { - return CalculateExpirationTime(mPreferredLifetime) <= TimerMilli::GetNow(); + return CalculateExpirationTime(mPreferredLifetime); } TimeMilli RoutingManager::OnLinkPrefix::GetStaleTime(void) const @@ -868,11 +870,6 @@ TimeMilli RoutingManager::OnLinkPrefix::GetStaleTime(void) const return CalculateExpirationTime(Min(kRtrAdvStaleTime, mPreferredLifetime)); } -TimeMilli RoutingManager::OnLinkPrefix::GetStaleTimeFromPreferredLifetime(void) const -{ - return CalculateExpirationTime(mPreferredLifetime); -} - void RoutingManager::OnLinkPrefix::AdoptValidAndPreferredLifetimesFrom(const OnLinkPrefix &aPrefix) { constexpr uint32_t kTwoHoursInSeconds = 2 * 3600; @@ -3728,13 +3725,7 @@ void RoutingManager::PdPrefixManager::Process(const RouterAdvert::Icmp6Packet *a if (HasPrefix() && currentPrefixUpdated) { - // If the prefix is obtained from an RA message, use - // `GetStaleTime()` to apply the minimum `RA_STABLE_TIME`. - // Otherwise, calculate it directly from the prefix's - // preferred lifetime. - - mTimer.FireAt((aPrefixTableEntry != nullptr) ? mPrefix.GetStaleTimeFromPreferredLifetime() - : mPrefix.GetStaleTime()); + mTimer.FireAt(mPrefix.GetDeprecationTime()); } else { diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index 85f9cb944..f627f8be5 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -692,8 +692,8 @@ private: uint32_t GetPreferredLifetime(void) const { return mPreferredLifetime; } void ClearPreferredLifetime(void) { mPreferredLifetime = 0; } bool IsDeprecated(void) const; + TimeMilli GetDeprecationTime(void) const; TimeMilli GetStaleTime(void) const; - TimeMilli GetStaleTimeFromPreferredLifetime(void) const; void AdoptValidAndPreferredLifetimesFrom(const OnLinkPrefix &aPrefix); void CopyInfoTo(PrefixTableEntry &aEntry, TimeMilli aNow) const; diff --git a/tests/unit/test_routing_manager.cpp b/tests/unit/test_routing_manager.cpp index b6040b7af..cf80ca3b3 100644 --- a/tests/unit/test_routing_manager.cpp +++ b/tests/unit/test_routing_manager.cpp @@ -3977,7 +3977,7 @@ void TestBorderRoutingProcessPlatfromGeneratedNd(void) } // 4. Short prefix will be extended to /64. - Log("Short prefix"); + Log("4. Short prefix"); { // The prefix will be padded to a /64 prefix. Ip6::Prefix raPrefix = PrefixFromString("2001:db8:cafe:0::", 64); @@ -4004,6 +4004,31 @@ void TestBorderRoutingProcessPlatfromGeneratedNd(void) VerifyOmrPrefixInNetData(localOmr, /* aDefaultRoute */ false); } + // 5. Publish a prefix with long lifetime, and wait until it expired. + Log("5. RA message with long prefix lifetime"); + { + Ip6::Prefix raPrefix = PrefixFromString("2001:db8:dead:beef::", 64); + + SendRouterAdvertToBorderRoutingProcessIcmp6Ra({Pio(raPrefix, 5000, 5000)}); + + sExpectedRios.Add(raPrefix); + AdvanceTime(10 * 1000); + + VerifyPdOmrPrefix(raPrefix); + VerifyOrQuit(sExpectedRios.SawAll()); + VerifyOmrPrefixInNetData(raPrefix, /* aDefaultRoute */ false); + + AdvanceTime(4900 * 1000); + sExpectedRios.Clear(); + VerifyPdOmrPrefix(raPrefix); + VerifyOmrPrefixInNetData(raPrefix, /* aDefaultRoute */ false); + + AdvanceTime(200 * 1000); + // Deprecated prefixes will be removed. + VerifyNoPdOmrPrefix(); + VerifyOmrPrefixInNetData(localOmr, /* aDefaultRoute */ false); + } + SuccessOrQuit(otBorderRoutingSetEnabled(sInstance, false)); VerifyOrQuit(sHeapAllocatedPtrs.GetLength() <= heapAllocations);