From 2da3f98e0d00cd5cd63e8a50e6eac624a7196c4b Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Mon, 15 Mar 2021 13:50:52 +0800 Subject: [PATCH] [dua] fix assert failure (#6282) This commit fix a potential DUA assertion failure. --- src/core/thread/dua_manager.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/core/thread/dua_manager.cpp b/src/core/thread/dua_manager.cpp index 17f23fd14..acbe72265 100644 --- a/src/core/thread/dua_manager.cpp +++ b/src/core/thread/dua_manager.cpp @@ -429,18 +429,25 @@ void DuaManager::PerformNextRegistration(void) // Only send DUA.req when necessary #if OPENTHREAD_CONFIG_DUA_ENABLE -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE +#if OPENTHREAD_FTD VerifyOrExit(mle.IsRouterOrLeader() || !mle.IsExpectedToBecomeRouter(), error = OT_ERROR_INVALID_STATE); - VerifyOrExit((mDuaState == kToRegister && mDelay.mFields.mRegistrationDelay == 0) || - (mChildDuaMask.HasAny() && mChildDuaMask != mChildDuaRegisteredMask), - error = OT_ERROR_NOT_FOUND); -#else - VerifyOrExit(mDuaState == kToRegister && mDelay.mFields.mRegistrationDelay == 0, error = OT_ERROR_NOT_FOUND); -#endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE - +#endif VerifyOrExit(mle.IsFullThreadDevice() || mle.GetParent().IsThreadVersion1p1(), error = OT_ERROR_INVALID_STATE); #endif // OPENTHREAD_CONFIG_DUA_ENABLE + { + bool needReg = false; + +#if OPENTHREAD_CONFIG_DUA_ENABLE + needReg = (mDuaState == kToRegister && mDelay.mFields.mRegistrationDelay == 0); +#endif + +#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE + needReg = needReg || (mChildDuaMask.HasAny() && mChildDuaMask != mChildDuaRegisteredMask); +#endif + VerifyOrExit(needReg, error = OT_ERROR_NOT_FOUND); + } + // Prepare DUA.req VerifyOrExit((message = Get().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);