From ea9a6d2b14f794c756575bbbea668ac029acb1bb Mon Sep 17 00:00:00 2001 From: Rongli Sun Date: Fri, 21 Jun 2019 13:19:40 +0800 Subject: [PATCH] [network-diagnostic] specify link-local source for link-local destination (#3935) In #3284, the source for network diagnostic is explicitly specified as RLOC. However when link-local address is the destination, link-local source is preferred. --- src/core/thread/network_diagnostic.cpp | 30 +++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index 193a60be7..f82ce3eda 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -115,7 +115,15 @@ otError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination, SuccessOrExit(error = message->Append(aTlvTypes, aCount)); } - messageInfo.SetSockAddr(Get().GetMeshLocal16()); + if (aDestination.IsLinkLocal() || aDestination.IsLinkLocalMulticast()) + { + messageInfo.SetSockAddr(Get().GetLinkLocalAddress()); + } + else + { + messageInfo.SetSockAddr(Get().GetMeshLocal16()); + } + messageInfo.SetPeerAddr(aDestination); messageInfo.SetPeerPort(kCoapUdpPort); @@ -499,7 +507,15 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Message &aMessage, const SuccessOrExit(error = message->SetPayloadMarker()); } - messageInfo.SetSockAddr(Get().GetMeshLocal16()); + if (aMessageInfo.GetSockAddr().IsLinkLocal() || aMessageInfo.GetSockAddr().IsLinkLocalMulticast()) + { + messageInfo.SetSockAddr(Get().GetLinkLocalAddress()); + } + else + { + messageInfo.SetSockAddr(Get().GetMeshLocal16()); + } + messageInfo.SetPeerAddr(aMessageInfo.GetPeerAddr()); messageInfo.SetPeerPort(kCoapUdpPort); @@ -601,7 +617,15 @@ otError NetworkDiagnostic::SendDiagnosticReset(const Ip6::Address &aDestination, SuccessOrExit(error = message->Append(aTlvTypes, aCount)); } - messageInfo.SetSockAddr(Get().GetMeshLocal16()); + if (aDestination.IsLinkLocal() || aDestination.IsLinkLocalMulticast()) + { + messageInfo.SetSockAddr(Get().GetLinkLocalAddress()); + } + else + { + messageInfo.SetSockAddr(Get().GetMeshLocal16()); + } + messageInfo.SetPeerAddr(aDestination); messageInfo.SetPeerPort(kCoapUdpPort);