[ip6] update Ip6::SelectSourceAddress() to prefer non-deprecated addresses (#9634)

This commit updates `SelectSourceAddress()` to ensure that
non-deprecated addresses are always preferred over deprecated ones.
When iterating over addresses, the best option is tracked in
`bestAddr`. If the new address is not preferred and the currently
selected `bestAddr` is, the new address is skipped to ensure that it
is not picked.
This commit is contained in:
Abtin Keshavarzian
2023-11-24 09:11:19 -08:00
committed by GitHub
parent 0044def122
commit 6c84ccad25
+11 -3
View File
@@ -1366,11 +1366,19 @@ const Address *Ip6::SelectSourceAddress(const Address &aDestination) const
continue;
}
}
else if (addr.mPreferred && !bestAddr->mPreferred)
else if (addr.mPreferred != bestAddr->mPreferred)
{
// Rule 3: Avoid deprecated addresses
bestAddr = &addr;
bestMatchLen = matchLen;
if (addr.mPreferred)
{
bestAddr = &addr;
bestMatchLen = matchLen;
}
else
{
continue;
}
}
else if (matchLen > bestMatchLen)
{