[ip6] SelectSourceAddress() rule 1 on preferring same address (#9830)

This commit moves the check for rule 1 on preferring same address as
the destination before the `(bestAddr == nullptr)` check. This
ensures that rule 1 will be correctly applied even when the address
happens to be first one in the `GetUnicastAddresses()` list.
This commit is contained in:
Abtin Keshavarzian
2024-02-05 10:23:57 -08:00
committed by GitHub
parent cf357d70be
commit 0c0cedc481
+7 -7
View File
@@ -1330,18 +1330,18 @@ const Address *Ip6::SelectSourceAddress(const Address &aDestination) const
overrideScope = destScope;
}
if (bestAddr == nullptr)
{
// Rule 0: Prefer any address
bestAddr = &addr;
bestMatchLen = matchLen;
}
else if (addr.GetAddress() == aDestination)
if (addr.GetAddress() == aDestination)
{
// Rule 1: Prefer same address
bestAddr = &addr;
ExitNow();
}
if (bestAddr == nullptr)
{
bestAddr = &addr;
bestMatchLen = matchLen;
}
else if (addr.GetScope() < bestAddr->GetScope())
{
// Rule 2: Prefer appropriate scope