[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.
This commit is contained in:
Rongli Sun
2019-06-20 22:19:40 -07:00
committed by Jonathan Hui
parent 7e28a2317a
commit ea9a6d2b14
+27 -3
View File
@@ -115,7 +115,15 @@ otError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination,
SuccessOrExit(error = message->Append(aTlvTypes, aCount));
}
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
if (aDestination.IsLinkLocal() || aDestination.IsLinkLocalMulticast())
{
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetLinkLocalAddress());
}
else
{
messageInfo.SetSockAddr(Get<Mle::MleRouter>().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<Mle::MleRouter>().GetMeshLocal16());
if (aMessageInfo.GetSockAddr().IsLinkLocal() || aMessageInfo.GetSockAddr().IsLinkLocalMulticast())
{
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetLinkLocalAddress());
}
else
{
messageInfo.SetSockAddr(Get<Mle::MleRouter>().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<Mle::MleRouter>().GetMeshLocal16());
if (aDestination.IsLinkLocal() || aDestination.IsLinkLocalMulticast())
{
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetLinkLocalAddress());
}
else
{
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
}
messageInfo.SetPeerAddr(aDestination);
messageInfo.SetPeerPort(kCoapUdpPort);