mirror of
https://github.com/espressif/openthread.git
synced 2026-07-28 06:37:46 +00:00
[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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user