[routing-manager] update stale time calculation for local RA header (#10316)

This commit updates the calculation of stale time for a discovered
local RA header (to mirror), incorporating the default route lifetime
specified in the header when it is non-zero, in addition to the RA
stale time constant. This ensures proper behavior even if the RA
header default route lifetime is shorter than the RA stale time.

Additionally, this commit adds `CalculateExpirationTime()` to
determine the expiration time from a given update time and lifetime
duration in seconds. If the given lifetime exceeds the supported
range of `TimeMilli` (~24 days), it clamps the value to ensure time
calculations remain within the valid `TimeMilli` range.
This commit is contained in:
Abtin Keshavarzian
2024-05-31 12:10:04 -07:00
committed by GitHub
parent 7b08e9a9b1
commit 4951dee753
2 changed files with 25 additions and 6 deletions
+23 -6
View File
@@ -648,6 +648,18 @@ exit:
}
}
TimeMilli RoutingManager::CalculateExpirationTime(TimeMilli aUpdateTime, uint32_t aLifetime)
{
// `aLifetime` is in unit of seconds. We clamp the lifetime to max
// interval supported by `Timer` (`2^31` msec or ~24.8 days).
// This ensures that the time calculation fits within `TimeMilli`
// range.
static constexpr uint32_t kMaxLifetime = Time::MsecToSec(Timer::kMaxDelay);
return aUpdateTime + Time::SecToMsec(Min(aLifetime, kMaxLifetime));
}
bool RoutingManager::IsValidBrUlaPrefix(const Ip6::Prefix &aBrUlaPrefix)
{
return aBrUlaPrefix.mLength == kBrUlaPrefixLength && aBrUlaPrefix.mPrefix.mFields.m8[0] == 0xfd;
@@ -841,12 +853,10 @@ void RoutingManager::LogRouteInfoOption(const Ip6::Prefix &, uint32_t, RoutePref
TimeMilli RoutingManager::LifetimedPrefix::CalculateExpirationTime(uint32_t aLifetime) const
{
// `aLifetime` is in unit of seconds. We clamp the lifetime to max
// interval supported by `Timer` (`2^31` msec or ~24.8 days).
// `aLifetime` is in unit of seconds. This method ensures
// that the time calculation fits with `TimeMilli` range.
static constexpr uint32_t kMaxLifetime = Time::MsecToSec(Timer::kMaxDelay);
return mLastUpdateTime + Time::SecToMsec(Min(aLifetime, kMaxLifetime));
return RoutingManager::CalculateExpirationTime(mLastUpdateTime, aLifetime);
}
//---------------------------------------------------------------------------------------------------------------------
@@ -1514,7 +1524,14 @@ void RoutingManager::RxRaTracker::ScheduleStaleTimer(void)
if (mLocalRaHeader.IsValid())
{
staleTime.UpdateIfEarlier(mLocalRaHeaderUpdateTime + Time::SecToMsec(kRtrAdvStaleTime));
uint16_t interval = kRtrAdvStaleTime;
if (mLocalRaHeader.GetRouterLifetime() > 0)
{
interval = Min(interval, mLocalRaHeader.GetRouterLifetime());
}
staleTime.UpdateIfEarlier(CalculateExpirationTime(mLocalRaHeaderUpdateTime, interval));
}
mStaleTimer.FireAt(staleTime);
@@ -1397,6 +1397,8 @@ private:
void HandleRaPrefixTableChanged(void);
void HandleLocalOnLinkPrefixChanged(void);
static TimeMilli CalculateExpirationTime(TimeMilli aUpdateTime, uint32_t aLifetime);
static bool IsValidBrUlaPrefix(const Ip6::Prefix &aBrUlaPrefix);
static bool IsValidOnLinkPrefix(const PrefixInfoOption &aPio);
static bool IsValidOnLinkPrefix(const Ip6::Prefix &aOnLinkPrefix);