[mesh-forwarder] move CheckReachability() to MeshForwarder (#10421)

This commit moves the `CheckReachability()` & `ResolveRoutingLoops()`
methods from the `MleRouter` class to the `MeshForwarder` class
now as `private` methods. This consolidates all `CheckReachability()`
overloads within the `MeshForwarder` class.
This commit is contained in:
Abtin Keshavarzian
2024-06-24 08:43:17 -04:00
committed by GitHub
parent 35847e19af
commit ea25f0954b
4 changed files with 65 additions and 81 deletions
+2
View File
@@ -492,6 +492,7 @@ private:
void SendIcmpErrorIfDstUnreach(const Message &aMessage, const Mac::Addresses &aMacAddrs);
Error CheckReachability(const FrameData &aFrameData, const Mac::Addresses &aMeshAddrs);
Error CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header);
void UpdateRoutes(const FrameData &aFrameData, const Mac::Addresses &aMeshAddrs);
Error FrameToMessage(const FrameData &aFrameData,
uint16_t aDatagramSize,
@@ -501,6 +502,7 @@ private:
void GetMacSourceAddress(const Ip6::Address &aIp6Addr, Mac::Address &aMacAddr);
Message *PrepareNextDirectTransmission(void);
void HandleMesh(FrameData &aFrameData, const Mac::Address &aMacSource, const ThreadLinkInfo &aLinkInfo);
void ResolveRoutingLoops(uint16_t aSourceRloc16, uint16_t aDestRloc16);
void HandleFragment(FrameData &aFrameData, const Mac::Addresses &aMacAddrs, const ThreadLinkInfo &aLinkInfo);
void HandleLowpanHC(const FrameData &aFrameData, const Mac::Addresses &aMacAddrs, const ThreadLinkInfo &aLinkInfo);
+63 -4
View File
@@ -575,7 +575,7 @@ Error MeshForwarder::UpdateIp6RouteFtd(const Ip6::Header &aIp6Header, Message &a
mMeshSource = Get<Mac::Mac>().GetShortAddress();
SuccessOrExit(error = mle.CheckReachability(mMeshDest, aIp6Header));
SuccessOrExit(error = CheckReachability(mMeshDest, aIp6Header));
aMessage.SetMeshDest(mMeshDest);
mMacAddrs.mDestination.SetShort(Get<RouterTable>().GetNextHop(mMeshDest));
@@ -609,7 +609,7 @@ void MeshForwarder::SendIcmpErrorIfDstUnreach(const Message &aMessage, const Mac
VerifyOrExit(!ip6Headers.GetDestinationAddress().IsMulticast() &&
Get<NetworkData::Leader>().IsOnMesh(ip6Headers.GetDestinationAddress()));
error = Get<Mle::MleRouter>().CheckReachability(aMacAddrs.mDestination.GetShort(), ip6Headers.GetIp6Header());
error = CheckReachability(aMacAddrs.mDestination.GetShort(), ip6Headers.GetIp6Header());
if (error == kErrorNoRoute)
{
@@ -639,7 +639,7 @@ Error MeshForwarder::CheckReachability(const FrameData &aFrameData, const Mac::A
ExitNow();
}
error = Get<Mle::MleRouter>().CheckReachability(aMeshAddrs.mDestination.GetShort(), ip6Headers.GetIp6Header());
error = CheckReachability(aMeshAddrs.mDestination.GetShort(), ip6Headers.GetIp6Header());
if (error == kErrorNoRoute)
{
@@ -650,6 +650,44 @@ exit:
return error;
}
Error MeshForwarder::CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header)
{
bool isReachable = false;
uint16_t deviceRloc16 = Get<Mle::Mle>().GetRloc16();
if (Get<Mle::Mle>().IsChild())
{
if (aMeshDest == deviceRloc16)
{
isReachable = Get<ThreadNetif>().HasUnicastAddress(aIp6Header.GetDestination());
}
else
{
isReachable = true;
}
ExitNow();
}
if (aMeshDest == deviceRloc16)
{
isReachable = Get<ThreadNetif>().HasUnicastAddress(aIp6Header.GetDestination()) ||
(Get<NeighborTable>().FindNeighbor(aIp6Header.GetDestination()) != nullptr);
ExitNow();
}
if (Mle::RouterIdMatch(aMeshDest, deviceRloc16))
{
isReachable = (Get<ChildTable>().FindChild(aMeshDest, Child::kInStateValidOrRestoring) != nullptr);
ExitNow();
}
isReachable = (Get<RouterTable>().GetNextHop(aMeshDest) != Mac::kShortAddrInvalid);
exit:
return isReachable ? kErrorNone : kErrorNoRoute;
}
void MeshForwarder::SendDestinationUnreachable(uint16_t aMeshSource, const Ip6::Headers &aIp6Headers)
{
Ip6::MessageInfo messageInfo;
@@ -697,7 +735,7 @@ void MeshForwarder::HandleMesh(FrameData &aFrameData, const Mac::Address &aMacSo
OwnedPtr<Message> messagePtr;
Message::Priority priority = Message::kPriorityNormal;
Get<Mle::MleRouter>().ResolveRoutingLoops(aMacSource.GetShort(), meshAddrs.mDestination.GetShort());
ResolveRoutingLoops(aMacSource.GetShort(), meshAddrs.mDestination.GetShort());
SuccessOrExit(error = CheckReachability(aFrameData, meshAddrs));
@@ -735,6 +773,27 @@ exit:
}
}
void MeshForwarder::ResolveRoutingLoops(uint16_t aSourceRloc16, uint16_t aDestRloc16)
{
// Resolves 2-hop routing loops.
Router *router;
if (aSourceRloc16 != Get<RouterTable>().GetNextHop(aDestRloc16))
{
ExitNow();
}
router = Get<RouterTable>().FindRouterByRloc16(aDestRloc16);
VerifyOrExit(router != nullptr);
router->SetNextHopToInvalid();
Get<Mle::MleRouter>().ResetAdvertiseInterval();
exit:
return;
}
void MeshForwarder::UpdateRoutes(const FrameData &aFrameData, const Mac::Addresses &aMeshAddrs)
{
Ip6::Headers ip6Headers;
-56
View File
@@ -3197,62 +3197,6 @@ void MleRouter::SetRouterId(uint8_t aRouterId)
mPreviousRouterId = mRouterId;
}
void MleRouter::ResolveRoutingLoops(uint16_t aSourceMac, uint16_t aDestRloc16)
{
Router *router;
if (aSourceMac != mRouterTable.GetNextHop(aDestRloc16))
{
ExitNow();
}
router = mRouterTable.FindRouterByRloc16(aDestRloc16);
VerifyOrExit(router != nullptr);
router->SetNextHopToInvalid();
ResetAdvertiseInterval();
exit:
return;
}
Error MleRouter::CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header)
{
bool isReachable = false;
if (IsChild())
{
if (aMeshDest == GetRloc16())
{
isReachable = Get<ThreadNetif>().HasUnicastAddress(aIp6Header.GetDestination());
}
else
{
isReachable = true;
}
ExitNow();
}
if (aMeshDest == GetRloc16())
{
isReachable = Get<ThreadNetif>().HasUnicastAddress(aIp6Header.GetDestination()) ||
(mNeighborTable.FindNeighbor(aIp6Header.GetDestination()) != nullptr);
ExitNow();
}
if (RouterIdFromRloc16(aMeshDest) == mRouterId)
{
isReachable = (mChildTable.FindChild(aMeshDest, Child::kInStateValidOrRestoring) != nullptr);
ExitNow();
}
isReachable = (mRouterTable.GetNextHop(aMeshDest) != Mac::kShortAddrInvalid);
exit:
return isReachable ? kErrorNone : kErrorNoRoute;
}
Error MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus)
{
Error error = kErrorNone;
-21
View File
@@ -379,27 +379,6 @@ public:
bool aSingletonB,
const LeaderData &aLeaderDataB);
/**
* Checks if the destination is reachable.
*
* @param[in] aMeshDest The RLOC16 of the destination.
* @param[in] aIp6Header A reference to the IPv6 header of the message.
*
* @retval kErrorNone The destination is reachable.
* @retval kErrorNoRoute The destination is not reachable and the message should be dropped.
*
*/
Error CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header);
/**
* Resolves 2-hop routing loops.
*
* @param[in] aSourceMac The RLOC16 of the previous hop.
* @param[in] aDestRloc16 The RLOC16 of the final destination.
*
*/
void ResolveRoutingLoops(uint16_t aSourceMac, uint16_t aDestRloc16);
/**
* Fills an ConnectivityTlv.
*