[ip6] fix default source address selection (#4082)

Thread defines a mesh-local scope for IPv6 unicast addresses. However,
the mesh-local scope can only be inferred by inclusion of the
mesh-local prefix.

This commit updates the IPv6 source address selection to infer the
destination address scope based on a prefix match with currently
assigned addresses.
This commit is contained in:
Jonathan Hui
2019-08-14 12:33:36 -07:00
committed by GitHub
parent 89dca58915
commit d0214bffe6
+22
View File
@@ -1026,6 +1026,10 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
rvalAddr = addr;
rvalPrefixMatched = candidatePrefixMatched;
}
else
{
continue;
}
}
else if (addr->GetScope() > rvalAddr->GetScope())
{
@@ -1034,6 +1038,10 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
rvalAddr = addr;
rvalPrefixMatched = candidatePrefixMatched;
}
else
{
continue;
}
}
else if ((rvalAddr->GetScope() == Address::kRealmLocalScope) && (addr->GetScope() == Address::kRealmLocalScope))
{
@@ -1043,6 +1051,10 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
rvalAddr = addr;
rvalPrefixMatched = candidatePrefixMatched;
}
else
{
continue;
}
}
else if (addr->mPreferred && !rvalAddr->mPreferred)
{
@@ -1058,6 +1070,16 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
rvalAddr = addr;
rvalPrefixMatched = candidatePrefixMatched;
}
else
{
continue;
}
// infer destination scope based on prefix match
if (rvalPrefixMatched >= rvalAddr->mPrefixLength)
{
destinationScope = rvalAddr->GetScope();
}
}
exit: