From d0214bffe630e7d03aa5264d697644619724f92e Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 14 Aug 2019 12:33:36 -0700 Subject: [PATCH] [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. --- src/core/net/ip6.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 2c6f304d5..894bd7e8c 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -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: