[dua] MTD prioritizes DUA in Address Registration TLV (#4862)

Thread 1.2 spec requires prioritizing DUA in Address Registration TLV
to ensure DUA could be stored in the limited addresses space for Child
on the parent.
This commit is contained in:
Rongli Sun
2020-05-05 18:16:59 -07:00
committed by GitHub
parent 2153f5a4f4
commit 6e8f2c9913
4 changed files with 39 additions and 3 deletions
+1 -1
View File
@@ -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
+3 -2
View File
@@ -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<ThreadNetif>().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<Utils::Slaac>().GenerateIid(mDomainUnicastAddress, NULL, 0, &mDadCounter) == OT_ERROR_NONE)
{
mDomainUnicastAddress.mValid = true;
Get<ThreadNetif>().AddUnicastAddress(mDomainUnicastAddress);
}
else
{
mDomainUnicastAddress.GetAddress().Clear();
otLogWarnCore("Failed to generate valid DUA");
}
+8
View File
@@ -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;
+27
View File
@@ -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<DuaManager>().GetDomainUnicastAddress();
if (Get<ThreadNetif>().IsUnicastAddress(address))
{
error = Get<NetworkData::Leader>().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<ThreadNetif>().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<NetworkData::Leader>().GetContext(addr->GetAddress(), context) == OT_ERROR_NONE)
{
// compressed entry