[ip6] limit to source prefix length in SelectSourceAddress() (#4377)

RFC 6724 Section 2.2 states:

   We define the common prefix length CommonPrefixLen(S, D) of a source
   address S and a destination address D as the length of the longest
   prefix (looking at the most significant, or leftmost, bits) that the
   two addresses have in common, up to the length of S's prefix (i.e.,
   the portion of the address not including the interface ID).  For
   example, CommonPrefixLen(fe80::1, fe80::2) is 64.
This commit is contained in:
Jonathan Hui
2019-12-04 08:23:00 -08:00
parent d12246d2ee
commit b22f00aea9
+10 -1
View File
@@ -1316,7 +1316,16 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
}
candidatePrefixMatched = destination->PrefixMatch(*candidateAddr);
overrideScope = (candidatePrefixMatched >= addr->mPrefixLength) ? addr->GetScope() : destinationScope;
if (candidatePrefixMatched >= addr->mPrefixLength)
{
candidatePrefixMatched = addr->mPrefixLength;
overrideScope = addr->GetScope();
}
else
{
overrideScope = destinationScope;
}
if (rvalAddr == NULL)
{