[mesh-forwarder] move ICMPv6 Dst Unreach call to mesh-forwarder (#4800)

This commit is contained in:
Jonathan Hui
2020-04-09 09:52:47 -07:00
parent 737f7e349d
commit 130e5b6a88
6 changed files with 43 additions and 44 deletions
+1
View File
@@ -384,6 +384,7 @@ private:
uint16_t aMeshDest = 0xffff);
void SendMesh(Message &aMessage, Mac::TxFrame &aFrame);
void SendDestinationUnreachable(uint16_t aMeshSource, const Ip6::Header &aIp6Header);
otError UpdateIp6Route(Message &aMessage);
otError UpdateIp6RouteFtd(Ip6::Header &ip6Header);
otError UpdateMeshRoute(Message &aMessage);
+20 -4
View File
@@ -484,7 +484,7 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header)
mMeshSource = Get<Mac::Mac>().GetShortAddress();
SuccessOrExit(error = mle.CheckReachability(mMeshSource, mMeshDest, ip6Header));
SuccessOrExit(error = mle.CheckReachability(mMeshDest, ip6Header));
mMacDest.SetShort(mle.GetNextHop(mMeshDest));
if (mMacDest.GetShort() != mMeshDest)
@@ -495,6 +495,11 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header)
}
exit:
if (error == OT_ERROR_NO_ROUTE)
{
SendDestinationUnreachable(mMeshSource, ip6Header);
}
return error;
}
@@ -520,7 +525,7 @@ otError MeshForwarder::CheckReachability(uint8_t * aFrame,
Ip6::Header ip6Header;
SuccessOrExit(error = GetIp6Header(aFrame, aFrameLength, aMeshSource, aMeshDest, ip6Header));
error = Get<Mle::MleRouter>().CheckReachability(aMeshSource.GetShort(), aMeshDest.GetShort(), ip6Header);
error = Get<Mle::MleRouter>().CheckReachability(aMeshDest.GetShort(), ip6Header);
exit:
// the message may not contain an IPv6 header
@@ -528,14 +533,25 @@ exit:
{
error = OT_ERROR_NONE;
}
else if (error != OT_ERROR_NONE)
else if (error == OT_ERROR_NO_ROUTE)
{
error = OT_ERROR_DROP;
SendDestinationUnreachable(aMeshSource.GetShort(), ip6Header);
}
return error;
}
void MeshForwarder::SendDestinationUnreachable(uint16_t aMeshSource, const Ip6::Header &aIp6Header)
{
Ip6::MessageInfo messageInfo;
messageInfo.GetPeerAddr() = Get<Mle::MleRouter>().GetMeshLocal16();
messageInfo.GetPeerAddr().SetLocator(aMeshSource);
Get<Ip6::Icmp>().SendError(Ip6::IcmpHeader::kTypeDstUnreach, Ip6::IcmpHeader::kCodeDstUnreachNoRoute, messageInfo,
aIp6Header);
}
void MeshForwarder::HandleMesh(uint8_t * aFrame,
uint16_t aFrameLength,
const Mac::Address & aMacSource,
+8 -17
View File
@@ -4106,28 +4106,19 @@ bool Mle::IsMeshLocalAddress(const Ip6::Address &aAddress) const
return aAddress.PrefixMatch(GetMeshLocal16()) >= MeshLocalPrefix::kLength;
}
otError Mle::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::Header &aIp6Header)
otError Mle::CheckReachability(uint16_t aMeshDest, Ip6::Header &aIp6Header)
{
otError error = OT_ERROR_DROP;
Ip6::MessageInfo messageInfo;
otError error;
if (aMeshDest != GetRloc16())
if ((aMeshDest != GetRloc16()) || Get<ThreadNetif>().IsUnicastAddress(aIp6Header.GetDestination()))
{
ExitNow(error = OT_ERROR_NONE);
error = OT_ERROR_NONE;
}
else
{
error = OT_ERROR_NO_ROUTE;
}
if (Get<ThreadNetif>().IsUnicastAddress(aIp6Header.GetDestination()))
{
ExitNow(error = OT_ERROR_NONE);
}
messageInfo.GetPeerAddr() = GetMeshLocal16();
messageInfo.GetPeerAddr().SetLocator(aMeshSource);
Get<Ip6::Icmp>().SendError(Ip6::IcmpHeader::kTypeDstUnreach, Ip6::IcmpHeader::kCodeDstUnreachNoRoute, messageInfo,
aIp6Header);
exit:
return error;
}
+5 -6
View File
@@ -1420,15 +1420,14 @@ protected:
/**
* This method checks if the destination is reachable.
*
* @param[in] aMeshSource The RLOC16 of the source.
* @param[in] aMeshDest The RLOC16 of the destination.
* @param[in] aIp6Header The IPv6 header of the message.
* @param[in] aMeshDest The RLOC16 of the destination.
* @param[in] aIp6Header The IPv6 header of the message.
*
* @retval OT_ERROR_NONE The destination is reachable.
* @retval OT_ERROR_DROP The destination is not reachable and the message should be dropped.
* @retval OT_ERROR_NONE The destination is reachable.
* @retval OT_ERROR_NO_ROUTE The destination is not reachable and the message should be dropped.
*
*/
otError CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::Header &aIp6Header);
otError CheckReachability(uint16_t aMeshDest, Ip6::Header &aIp6Header);
/**
* This method returns a pointer to the neighbor object.
+4 -11
View File
@@ -3886,14 +3886,13 @@ exit:
return;
}
otError MleRouter::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::Header &aIp6Header)
otError MleRouter::CheckReachability(uint16_t aMeshDest, Ip6::Header &aIp6Header)
{
Ip6::MessageInfo messageInfo;
otError error = OT_ERROR_NONE;
otError error = OT_ERROR_NONE;
if (IsChild())
{
error = Mle::CheckReachability(aMeshSource, aMeshDest, aIp6Header);
error = Mle::CheckReachability(aMeshDest, aIp6Header);
ExitNow();
}
@@ -3925,13 +3924,7 @@ otError MleRouter::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, I
ExitNow();
}
messageInfo.GetPeerAddr() = GetMeshLocal16();
messageInfo.GetPeerAddr().SetLocator(aMeshSource);
Get<Ip6::Icmp>().SendError(Ip6::IcmpHeader::kTypeDstUnreach, Ip6::IcmpHeader::kCodeDstUnreachNoRoute, messageInfo,
aIp6Header);
error = OT_ERROR_DROP;
error = OT_ERROR_NO_ROUTE;
exit:
return error;
+5 -6
View File
@@ -493,15 +493,14 @@ public:
/**
* This method checks if the destination is reachable.
*
* @param[in] aMeshSource The RLOC16 of the source.
* @param[in] aMeshDest The RLOC16 of the destination.
* @param[in] aIp6Header A reference to the IPv6 header of the message.
* @param[in] aMeshDest The RLOC16 of the destination.
* @param[in] aIp6Header A reference to the IPv6 header of the message.
*
* @retval OT_ERROR_NONE The destination is reachable.
* @retval OT_ERROR_DROP The destination is not reachable and the message should be dropped.
* @retval OT_ERROR_NONE The destination is reachable.
* @retval OT_ERROR_NO_ROUTE The destination is not reachable and the message should be dropped.
*
*/
otError CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::Header &aIp6Header);
otError CheckReachability(uint16_t aMeshDest, Ip6::Header &aIp6Header);
/**
* This method resolves 2-hop routing loops.