diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 33bd615e5..ac7c300a1 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -2770,7 +2770,7 @@ void Mle::HandleAdvertisement(RxInfo &aRxInfo) case kRoleRouter: case kRoleLeader: - VerifyOrExit(aRxInfo.mNeighbor && aRxInfo.mNeighbor->IsStateValid()); + VerifyOrExit(aRxInfo.IsNeighborStateValid()); break; } @@ -2792,7 +2792,7 @@ void Mle::HandleDataResponse(RxInfo &aRxInfo) Log(kMessageReceive, kTypeDataResponse, aRxInfo.mMessageInfo.GetPeerAddr()); - VerifyOrExit(aRxInfo.mNeighbor && aRxInfo.mNeighbor->IsStateValid(), error = kErrorDrop); + VerifyOrExit(aRxInfo.IsNeighborStateValid(), error = kErrorDrop); #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE { @@ -3299,7 +3299,7 @@ void Mle::HandleChildIdResponse(RxInfo &aRxInfo) Log(kMessageReceive, kTypeChildIdResponse, aRxInfo.mMessageInfo.GetPeerAddr(), sourceAddress); - VerifyOrExit(aRxInfo.mNeighbor && aRxInfo.mNeighbor->IsStateValid(), error = kErrorSecurity); + VerifyOrExit(aRxInfo.IsNeighborStateValid(), error = kErrorSecurity); VerifyOrExit(mAttachState == kAttachStateChildIdRequest); diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index bb80873ec..e8611dd58 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1395,6 +1395,16 @@ protected: { } + /** + * This method indicates whether the `mNeighbor` (neighbor from which message was received) is non-null and + * in valid state. + * + * @retval TRUE If `mNeighbor` is non-null and in valid state. + * @retval FALSE If `mNeighbor` is `nullptr` or not in valid state. + * + */ + bool IsNeighborStateValid(void) const { return (mNeighbor != nullptr) && mNeighbor->IsStateValid(); } + RxMessage &mMessage; ///< The MLE message. const Ip6::MessageInfo &mMessageInfo; ///< The `MessageInfo` associated with the message. uint32_t mFrameCounter; ///< The frame counter from aux security header. diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 318f41851..324501109 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -679,8 +679,7 @@ void MleRouter::HandleLinkRequest(RxInfo &aRxInfo) case kErrorNotFound: // lack of source address indicates router coming out of reset - VerifyOrExit(aRxInfo.mNeighbor && aRxInfo.mNeighbor->IsStateValid() && - IsActiveRouter(aRxInfo.mNeighbor->GetRloc16()), + VerifyOrExit(aRxInfo.IsNeighborStateValid() && IsActiveRouter(aRxInfo.mNeighbor->GetRloc16()), error = kErrorDrop); neighbor = aRxInfo.mNeighbor; break; @@ -1213,7 +1212,7 @@ Error MleRouter::HandleAdvertisement(RxInfo &aRxInfo) } else if (leaderData.GetLeaderRouterId() != GetLeaderId()) { - VerifyOrExit(aRxInfo.mNeighbor && aRxInfo.mNeighbor->IsStateValid()); + VerifyOrExit(aRxInfo.IsNeighborStateValid()); if (!IsChild()) { @@ -1232,7 +1231,7 @@ Error MleRouter::HandleAdvertisement(RxInfo &aRxInfo) Get().HandleTimeSyncMessage(aRxInfo.mMessage); #endif - if (IsFullThreadDevice() && (aRxInfo.mNeighbor && aRxInfo.mNeighbor->IsStateValid()) && + if (IsFullThreadDevice() && aRxInfo.IsNeighborStateValid() && ((mRouterTable.GetActiveRouterCount() == 0) || SerialNumber::IsGreater(routeTlv.GetRouterIdSequence(), mRouterTable.GetRouterIdSequence()))) { @@ -2738,7 +2737,7 @@ void MleRouter::HandleDataRequest(RxInfo &aRxInfo) Log(kMessageReceive, kTypeDataRequest, aRxInfo.mMessageInfo.GetPeerAddr()); - VerifyOrExit(aRxInfo.mNeighbor && aRxInfo.mNeighbor->IsStateValid(), error = kErrorSecurity); + VerifyOrExit(aRxInfo.IsNeighborStateValid(), error = kErrorSecurity); // TLV Request SuccessOrExit(error = aRxInfo.mMessage.ReadTlvRequestTlv(tlvList)); @@ -4304,7 +4303,7 @@ void MleRouter::HandleTimeSync(RxInfo &aRxInfo) { Log(kMessageReceive, kTypeTimeSync, aRxInfo.mMessageInfo.GetPeerAddr()); - VerifyOrExit(aRxInfo.mNeighbor && aRxInfo.mNeighbor->IsStateValid()); + VerifyOrExit(aRxInfo.IsNeighborStateValid()); aRxInfo.mClass = RxInfo::kPeerMessage;