mirror of
https://github.com/espressif/openthread.git
synced 2026-08-06 10:47:46 +00:00
[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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user