diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index cab5c6211..0c9eaaaf5 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -2877,8 +2877,7 @@ otError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo break; } - if (mRetrieveNewNetworkData || - (static_cast(leaderData.GetDataVersion() - Get().GetVersion()) > 0)) + if (mRetrieveNewNetworkData || IsNetworkDataNewer(leaderData)) { delay = Random::NonCrypto::GetUint16InRange(0, kMleMaxResponseDelay); SendDataRequest(aMessageInfo.GetPeerAddr(), tlvs, sizeof(tlvs), delay); @@ -2919,6 +2918,22 @@ exit: return error; } +bool Mle::IsNetworkDataNewer(const LeaderDataTlv &aLeaderData) +{ + int8_t diff; + + if (IsFullNetworkData()) + { + diff = static_cast(aLeaderData.GetDataVersion() - Get().GetVersion()); + } + else + { + diff = static_cast(aLeaderData.GetStableDataVersion() - Get().GetStableVersion()); + } + + return (diff > 0); +} + otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { otError error = OT_ERROR_NONE; @@ -2950,19 +2965,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a } else if (!mRetrieveNewNetworkData) { - int8_t diff; - - if (IsFullNetworkData()) - { - diff = static_cast(leaderData.GetDataVersion() - Get().GetVersion()); - } - else - { - diff = - static_cast(leaderData.GetStableDataVersion() - Get().GetStableVersion()); - } - - VerifyOrExit(diff > 0); + VerifyOrExit(IsNetworkDataNewer(leaderData)); } // Active Timestamp diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index f818e6aab..040ff77b8 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1713,6 +1713,7 @@ private: uint32_t Reattach(void); bool IsBetterParent(uint16_t aRloc16, uint8_t aLinkQuality, uint8_t aLinkMargin, ConnectivityTlv &aConnectivityTlv); + bool IsNetworkDataNewer(const LeaderDataTlv &aLeaderData); void ResetParentCandidate(void); otError GetAlocAddress(Ip6::Address &aAddress, uint16_t aAloc16) const;