From 4e73575703c10aa2317460a4f372c5881fecccc2 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Tue, 3 Dec 2019 08:52:38 -0800 Subject: [PATCH] [ip6] prefer RLOC source with RLOC dest in SelectSourceAddress() (#4377) Prefer ML-EID for any mesh-local traffic that does not have RLOC destination. Credit to Rongli Sun for identifying this issue. --- src/core/net/ip6.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 23836592c..4c495c1b1 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1364,19 +1364,6 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo) continue; } } - else if ((rvalAddr->GetScope() == Address::kRealmLocalScope) && (addr->GetScope() == Address::kRealmLocalScope)) - { - // Additional rule: Prefer EID - if (rvalAddr->GetAddress().IsRoutingLocator()) - { - rvalAddr = addr; - rvalPrefixMatched = candidatePrefixMatched; - } - else - { - continue; - } - } else if (addr->mPreferred && !rvalAddr->mPreferred) { // Rule 3: Avoid deprecated addresses @@ -1391,6 +1378,13 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo) rvalAddr = addr; rvalPrefixMatched = candidatePrefixMatched; } + else if ((candidatePrefixMatched == rvalPrefixMatched) && + (destination->IsRoutingLocator() == candidateAddr->IsRoutingLocator())) + { + // Additional rule: Prefer RLOC source for RLOC destination, EID source for anything else + rvalAddr = addr; + rvalPrefixMatched = candidatePrefixMatched; + } else { continue;