diff --git a/src/core/backbone_router/leader.hpp b/src/core/backbone_router/leader.hpp index aac702529..65403bb5a 100644 --- a/src/core/backbone_router/leader.hpp +++ b/src/core/backbone_router/leader.hpp @@ -166,7 +166,7 @@ private: #endif BackboneRouterConfig mConfig; ///< Primary Backbone Router information. - otIp6Prefix mDomainPrefix; ///< Domain Prefix on the Thread Network. + otIp6Prefix mDomainPrefix; ///< Domain Prefix in the Thread network. }; } // namespace BackboneRouter diff --git a/src/core/thread/dua_manager.cpp b/src/core/thread/dua_manager.cpp index b1336541b..f7f3f0f32 100644 --- a/src/core/thread/dua_manager.cpp +++ b/src/core/thread/dua_manager.cpp @@ -51,6 +51,7 @@ DuaManager::DuaManager(Instance &aInstance) { mDomainUnicastAddress.Clear(); mDomainUnicastAddress.mPreferred = true; + mDomainUnicastAddress.mValid = true; mDomainUnicastAddress.mScopeOverride = Ip6::Address::kGlobalScope; mDomainUnicastAddress.mScopeOverrideValid = true; } @@ -63,6 +64,7 @@ void DuaManager::UpdateDomainUnicastAddress(BackboneRouter::Leader::DomainPrefix (aState == BackboneRouter::Leader::kDomainPrefixRefreshed)) { Get().RemoveUnicastAddress(mDomainUnicastAddress); + mDomainUnicastAddress.GetAddress().Clear(); } VerifyOrExit((aState == BackboneRouter::Leader::kDomainPrefixAdded) || @@ -73,17 +75,16 @@ void DuaManager::UpdateDomainUnicastAddress(BackboneRouter::Leader::DomainPrefix OT_ASSERT(prefix != NULL); - mDomainUnicastAddress.GetAddress().Clear(); mDomainUnicastAddress.GetAddress().SetPrefix(prefix->mPrefix.mFields.m8, prefix->mLength); mDomainUnicastAddress.mPrefixLength = prefix->mLength; if (Get().GenerateIid(mDomainUnicastAddress, NULL, 0, &mDadCounter) == OT_ERROR_NONE) { - mDomainUnicastAddress.mValid = true; Get().AddUnicastAddress(mDomainUnicastAddress); } else { + mDomainUnicastAddress.GetAddress().Clear(); otLogWarnCore("Failed to generate valid DUA"); } diff --git a/src/core/thread/dua_manager.hpp b/src/core/thread/dua_manager.hpp index 09f3635b9..16046140b 100644 --- a/src/core/thread/dua_manager.hpp +++ b/src/core/thread/dua_manager.hpp @@ -81,6 +81,14 @@ public: */ void UpdateDomainUnicastAddress(BackboneRouter::Leader::DomainPrefixState aState); + /** + * This method returns a reference to the Domain Unicast Address. + * + * @returns A reference to the Domain Unicast Address. + * + */ + const Ip6::Address &GetDomainUnicastAddress(void) const { return mDomainUnicastAddress.GetAddress(); } + private: Ip6::NetifUnicastAddress mDomainUnicastAddress; uint8_t mDadCounter; diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 238b6c3c4..e8c2badb8 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -1360,6 +1360,25 @@ otError Mle::AppendAddressRegistration(Message &aMessage, AddressRegistrationMod VerifyOrExit(aMode != kAppendMeshLocalOnly, OT_NOOP); counter++; +#if OPENTHREAD_CONFIG_DUA_ENABLE + // Cache Domain Unicast Address. + address = Get().GetDomainUnicastAddress(); + + if (Get().IsUnicastAddress(address)) + { + error = Get().GetContext(address, context); + + OT_ASSERT(error == OT_ERROR_NONE); + + // Prioritize DUA, compressed entry + entry.SetContextId(context.mContextId); + entry.SetIid(address.GetIid()); + SuccessOrExit(error = aMessage.Append(&entry, entry.GetLength())); + length += entry.GetLength(); + counter++; + } +#endif // OPENTHREAD_CONFIG_DUA_ENABLE + for (const Ip6::NetifUnicastAddress *addr = Get().GetUnicastAddresses(); addr; addr = addr->GetNext()) { if (addr->GetAddress().IsLinkLocal() || IsRoutingLocator(addr->GetAddress()) || @@ -1368,6 +1387,14 @@ otError Mle::AppendAddressRegistration(Message &aMessage, AddressRegistrationMod continue; } +#if OPENTHREAD_CONFIG_DUA_ENABLE + // Skip DUA that was already appended above. + if (addr->GetAddress() == address) + { + continue; + } +#endif + if (Get().GetContext(addr->GetAddress(), context) == OT_ERROR_NONE) { // compressed entry