From a3e804101ea333c3c64ec4b53fe7097f563c15f0 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 3 Apr 2024 13:56:25 -0700 Subject: [PATCH] [mle] simplify `CheckReachablity()` (#9989) This commit simplifies `MleRouter::CheckReachablity()`: - Remove and inline `Mle::CheckReachability()` which is used when `IsChild()`. - Uses local `isReachable` boolean variable. --- src/core/thread/mle.cpp | 16 ------------ src/core/thread/mle.hpp | 1 - src/core/thread/mle_router.cpp | 47 +++++++++++++++------------------- 3 files changed, 21 insertions(+), 43 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 234f405d9..9f3e58810 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -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().HasUnicastAddress(aIp6Header.GetDestination())) - { - error = kErrorNone; - } - else - { - error = kErrorNoRoute; - } - - return error; -} - #if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH void Mle::InformPreviousParent(void) { diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 33d0920cf..208922bcd 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -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); diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 40894798a..b7489e651 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -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().HasUnicastAddress(aIp6Header.GetDestination()); + } + else + { + isReachable = true; + } + ExitNow(); } - if (aMeshDest == Get().GetShortAddress()) - { - if (Get().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().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)