[mle] add helper RxInfo::IsNeighborStateValid() (#8610)

This commit adds a new helper method in `RxInfo` to check whether or
not the `mNeighbor` field (the neighbor from which message was
received) is non-null and in valid state.
This commit is contained in:
Abtin Keshavarzian
2023-01-03 17:09:53 -08:00
committed by GitHub
parent 41275372d3
commit beb8a9040b
3 changed files with 18 additions and 9 deletions
+3 -3
View File
@@ -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);
+10
View File
@@ -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.
+5 -6
View File
@@ -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<TimeSync>().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;