[mle] simplify CheckReachablity() (#9989)

This commit simplifies `MleRouter::CheckReachablity()`:

- Remove and inline `Mle::CheckReachability()` which is used
  when `IsChild()`.
- Uses local `isReachable` boolean variable.
This commit is contained in:
Abtin Keshavarzian
2024-04-03 13:56:25 -07:00
committed by GitHub
parent 843db1e82d
commit a3e804101e
3 changed files with 21 additions and 43 deletions
-16
View File
@@ -3889,22 +3889,6 @@ bool Mle::IsAnycastLocator(const Ip6::Address &aAddress) const
bool Mle::IsMeshLocalAddress(const Ip6::Address &aAddress) const { return (aAddress.GetPrefix() == mMeshLocalPrefix); }
Error Mle::CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header)
{
Error error;
if ((aMeshDest != GetRloc16()) || Get<ThreadNetif>().HasUnicastAddress(aIp6Header.GetDestination()))
{
error = kErrorNone;
}
else
{
error = kErrorNoRoute;
}
return error;
}
#if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH
void Mle::InformPreviousParent(void)
{
-1
View File
@@ -1240,7 +1240,6 @@ private:
void SetAttachState(AttachState aState);
void InitNeighbor(Neighbor &aNeighbor, const RxInfo &aRxInfo);
void ClearParentCandidate(void) { mParentCandidate.Clear(); }
Error CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header);
Error SendDataRequest(const Ip6::Address &aDestination);
void HandleNotifierEvents(Events aEvents);
void SendDelayedResponse(TxMessage &aMessage, const DelayedResponseMetadata &aMetadata);
+21 -26
View File
@@ -3238,44 +3238,39 @@ exit:
Error MleRouter::CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header)
{
Error error = kErrorNone;
bool isReachable = false;
if (IsChild())
{
error = Mle::CheckReachability(aMeshDest, aIp6Header);
if (aMeshDest == GetRloc16())
{
isReachable = Get<ThreadNetif>().HasUnicastAddress(aIp6Header.GetDestination());
}
else
{
isReachable = true;
}
ExitNow();
}
if (aMeshDest == Get<Mac::Mac>().GetShortAddress())
{
if (Get<ThreadNetif>().HasUnicastAddress(aIp6Header.GetDestination()))
{
// IPv6 destination is this device
ExitNow();
}
else if (mNeighborTable.FindNeighbor(aIp6Header.GetDestination()) != nullptr)
{
// IPv6 destination is an RFD child
ExitNow();
}
}
else if (RouterIdFromRloc16(aMeshDest) == mRouterId)
{
if (mChildTable.FindChild(aMeshDest, Child::kInStateValidOrRestoring))
{
// Mesh destination is a child of this device
ExitNow();
}
}
else if (GetNextHop(aMeshDest) != Mac::kShortAddrInvalid)
if (aMeshDest == GetRloc16())
{
isReachable = Get<ThreadNetif>().HasUnicastAddress(aIp6Header.GetDestination()) ||
(mNeighborTable.FindNeighbor(aIp6Header.GetDestination()) != nullptr);
ExitNow();
}
error = kErrorNoRoute;
if (RouterIdFromRloc16(aMeshDest) == mRouterId)
{
isReachable = (mChildTable.FindChild(aMeshDest, Child::kInStateValidOrRestoring) != nullptr);
ExitNow();
}
isReachable = (GetNextHop(aMeshDest) != Mac::kShortAddrInvalid);
exit:
return error;
return isReachable ? kErrorNone : kErrorNoRoute;
}
Error MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus)