[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.
This commit is contained in:
Abtin Keshavarzian
2024-05-30 11:36:48 -07:00
committed by GitHub
parent bef804c6be
commit d2e74dc705
3 changed files with 32 additions and 16 deletions
+5 -14
View File
@@ -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
{
+1 -1
View File
@@ -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;
+26 -1
View File
@@ -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);