Skip to content

Commit

Permalink
[routing-manager] rename PrefixEntry to PdPrefix (openthread#11241)
Browse files Browse the repository at this point in the history
This commit renames `PrefixEntry` to `PdPrefix` within the
`PdPrefixManager` class. Associated variables are also updated,
improving readability.
  • Loading branch information
abtink authored Feb 12, 2025
1 parent fd16f45 commit 260193a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
44 changes: 22 additions & 22 deletions src/core/border_router/routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4115,10 +4115,10 @@ void RoutingManager::PdPrefixManager::Process(const InfraIf::Icmp6Packet *aRaPac
// an RA message or directly set. Requires either `aRaPacket` or
// `aPrefixTableEntry` to be non-null.

bool currentPrefixUpdated = false;
Error error = kErrorNone;
PrefixEntry favoredEntry;
PrefixEntry entry;
bool currentPrefixUpdated = false;
Error error = kErrorNone;
PdPrefix favoredPrefix;
PdPrefix prefix;

VerifyOrExit(mEnabled, error = kErrorInvalidState);

Expand All @@ -4136,17 +4136,17 @@ void RoutingManager::PdPrefixManager::Process(const InfraIf::Icmp6Packet *aRaPac
}

mNumPlatformPioProcessed++;
entry.SetFrom(static_cast<const PrefixInfoOption &>(option));
currentPrefixUpdated |= ProcessPrefixEntry(entry, favoredEntry);
prefix.SetFrom(static_cast<const PrefixInfoOption &>(option));
currentPrefixUpdated |= ProcessPdPrefix(prefix, favoredPrefix);
}

mNumPlatformRaReceived++;
mLastPlatformRaTime = TimerMilli::GetNow();
}
else // aPrefixTableEntry != nullptr
{
entry.SetFrom(*aPrefixTableEntry);
currentPrefixUpdated = ProcessPrefixEntry(entry, favoredEntry);
prefix.SetFrom(*aPrefixTableEntry);
currentPrefixUpdated = ProcessPdPrefix(prefix, favoredPrefix);
}

if (currentPrefixUpdated && mPrefix.IsDeprecated())
Expand All @@ -4156,9 +4156,9 @@ void RoutingManager::PdPrefixManager::Process(const InfraIf::Icmp6Packet *aRaPac
Get<RoutingManager>().ScheduleRoutingPolicyEvaluation(kImmediately);
}

if (favoredEntry.IsFavoredOver(mPrefix))
if (favoredPrefix.IsFavoredOver(mPrefix))
{
mPrefix = favoredEntry;
mPrefix = favoredPrefix;
currentPrefixUpdated = true;
LogInfo("DHCPv6 PD prefix set to %s", mPrefix.GetPrefix().ToString().AsCString());
Get<RoutingManager>().ScheduleRoutingPolicyEvaluation(kImmediately);
Expand All @@ -4178,53 +4178,53 @@ void RoutingManager::PdPrefixManager::Process(const InfraIf::Icmp6Packet *aRaPac
OT_UNUSED_VARIABLE(error);
}

bool RoutingManager::PdPrefixManager::ProcessPrefixEntry(PrefixEntry &aEntry, PrefixEntry &aFavoredEntry)
bool RoutingManager::PdPrefixManager::ProcessPdPrefix(PdPrefix &aPrefix, PdPrefix &aFavoredPrefix)
{
bool currentPrefixUpdated = false;

if (!aEntry.IsValidPdPrefix())
if (!aPrefix.IsValidPdPrefix())
{
LogWarn("Ignore invalid DHCPv6 PD prefix %s", aEntry.GetPrefix().ToString().AsCString());
LogWarn("Ignore invalid DHCPv6 PD prefix %s", aPrefix.GetPrefix().ToString().AsCString());
ExitNow();
}

aEntry.GetPrefix().Tidy();
aEntry.GetPrefix().SetLength(kOmrPrefixLength);
aPrefix.GetPrefix().Tidy();
aPrefix.GetPrefix().SetLength(kOmrPrefixLength);

// Check if there is an update to the current prefix. The valid or
// preferred lifetime may have changed.

if (HasPrefix() && (mPrefix.GetPrefix() == aEntry.GetPrefix()))
if (HasPrefix() && (mPrefix.GetPrefix() == aPrefix.GetPrefix()))
{
currentPrefixUpdated = true;
mPrefix = aEntry;
mPrefix = aPrefix;
}

VerifyOrExit(!aEntry.IsDeprecated());
VerifyOrExit(!aPrefix.IsDeprecated());

// Some platforms may delegate multiple prefixes. We'll select the
// smallest one, as GUA prefixes (`2000::/3`) are inherently
// smaller than ULA prefixes (`fc00::/7`). This rule prefers GUA
// prefixes over ULA.

if (aEntry.IsFavoredOver(aFavoredEntry))
if (aPrefix.IsFavoredOver(aFavoredPrefix))
{
aFavoredEntry = aEntry;
aFavoredPrefix = aPrefix;
}

exit:
return currentPrefixUpdated;
}

bool RoutingManager::PdPrefixManager::PrefixEntry::IsValidPdPrefix(void) const
bool RoutingManager::PdPrefixManager::PdPrefix::IsValidPdPrefix(void) const
{
// We should accept ULA prefix since it could be used by the internet infrastructure like NAT64.

return !IsEmpty() && (GetPrefix().GetLength() <= kOmrPrefixLength) && !GetPrefix().IsLinkLocal() &&
!GetPrefix().IsMulticast();
}

bool RoutingManager::PdPrefixManager::PrefixEntry::IsFavoredOver(const PrefixEntry &aOther) const
bool RoutingManager::PdPrefixManager::PdPrefix::IsFavoredOver(const PdPrefix &aOther) const
{
bool isFavored;

Expand Down
10 changes: 5 additions & 5 deletions src/core/border_router/routing_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,17 +1487,17 @@ class RoutingManager : public InstanceLocator
void Evaluate(void);

private:
class PrefixEntry : public OnLinkPrefix
class PdPrefix : public OnLinkPrefix
{
public:
PrefixEntry(void) { Clear(); }
PdPrefix(void) { Clear(); }
bool IsEmpty(void) const { return (GetPrefix().GetLength() == 0); }
bool IsValidPdPrefix(void) const;
bool IsFavoredOver(const PrefixEntry &aOther) const;
bool IsFavoredOver(const PdPrefix &aOther) const;
};

void Process(const InfraIf::Icmp6Packet *aRaPacket, const PrefixTableEntry *aPrefixTableEntry);
bool ProcessPrefixEntry(PrefixEntry &aEntry, PrefixEntry &aFavoredEntry);
bool ProcessPdPrefix(PdPrefix &aPrefix, PdPrefix &aFavoredPrefix);
void EvaluateStateChange(State aOldState);
void WithdrawPrefix(void);
void StartStop(bool aStart);
Expand All @@ -1517,7 +1517,7 @@ class RoutingManager : public InstanceLocator
TimeMilli mLastPlatformRaTime;
StateCallback mStateCallback;
PrefixTimer mTimer;
PrefixEntry mPrefix;
PdPrefix mPrefix;
};

#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE
Expand Down

0 comments on commit 260193a

Please sign in to comment.