mirror of
https://github.com/espressif/openthread.git
synced 2026-09-14 05:00:11 +00:00
[mle] introduce TxMessage::AppendAddressRegistrationEntry() (#11205)
This commit introduces `TxMessage::AppendAddressRegistrationEntry()` which appends an address entry in an MLE Address Registration TLV. The new helper method determines whether a given address can be appended as a compressed (using a lowpan context ID) or as an uncompressed entry. This simplifies the code by moving all checks into a common method. It also adds an explicit check to ensure the associated Context TLV has the "compress" flag set before using the compressed format.
This commit is contained in:
+35
-53
@@ -4963,29 +4963,26 @@ Error Mle::TxMessage::AppendVersionTlv(void) { return Tlv::Append<VersionTlv>(*t
|
|||||||
|
|
||||||
Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode)
|
Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode)
|
||||||
{
|
{
|
||||||
Error error = kErrorNone;
|
Error error = kErrorNone;
|
||||||
Tlv tlv;
|
Tlv tlv;
|
||||||
Lowpan::Context context;
|
uint8_t counter = 0;
|
||||||
uint8_t counter = 0;
|
uint16_t startOffset = GetLength();
|
||||||
uint16_t startOffset = GetLength();
|
|
||||||
|
|
||||||
tlv.SetType(Tlv::kAddressRegistration);
|
tlv.SetType(Tlv::kAddressRegistration);
|
||||||
SuccessOrExit(error = Append(tlv));
|
SuccessOrExit(error = Append(tlv));
|
||||||
|
|
||||||
// Prioritize ML-EID
|
// Prioritize ML-EID
|
||||||
SuccessOrExit(error = AppendCompressedAddressEntry(kMeshLocalPrefixContextId, Get<Mle>().GetMeshLocalEid()));
|
SuccessOrExit(error = AppendAddressRegistrationEntry(Get<Mle>().GetMeshLocalEid()));
|
||||||
|
|
||||||
// Continue to append the other addresses if not `kAppendMeshLocalOnly` mode
|
// Continue to append the other addresses if not `kAppendMeshLocalOnly` mode
|
||||||
VerifyOrExit(aMode != kAppendMeshLocalOnly);
|
VerifyOrExit(aMode != kAppendMeshLocalOnly);
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
||||||
if (Get<ThreadNetif>().HasUnicastAddress(Get<DuaManager>().GetDomainUnicastAddress()) &&
|
if (Get<ThreadNetif>().HasUnicastAddress(Get<DuaManager>().GetDomainUnicastAddress()))
|
||||||
(Get<NetworkData::Leader>().GetContext(Get<DuaManager>().GetDomainUnicastAddress(), context) == kErrorNone))
|
|
||||||
{
|
{
|
||||||
// Prioritize DUA, compressed entry
|
// Prioritize DUA, compressed entry
|
||||||
SuccessOrExit(
|
SuccessOrExit(error = AppendAddressRegistrationEntry(Get<DuaManager>().GetDomainUnicastAddress()));
|
||||||
error = AppendCompressedAddressEntry(context.mContextId, Get<DuaManager>().GetDomainUnicastAddress()));
|
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -5006,15 +5003,7 @@ Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (Get<NetworkData::Leader>().GetContext(addr.GetAddress(), context) == kErrorNone)
|
SuccessOrExit(error = AppendAddressRegistrationEntry(addr.GetAddress()));
|
||||||
{
|
|
||||||
SuccessOrExit(error = AppendCompressedAddressEntry(context.mContextId, addr.GetAddress()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SuccessOrExit(error = AppendAddressEntry(addr.GetAddress()));
|
|
||||||
}
|
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
// only continue to append if there is available entry.
|
// only continue to append if there is available entry.
|
||||||
VerifyOrExit(counter < kMaxIpAddressesToRegister);
|
VerifyOrExit(counter < kMaxIpAddressesToRegister);
|
||||||
@@ -5042,7 +5031,7 @@ Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SuccessOrExit(error = AppendAddressEntry(addr.GetAddress()));
|
SuccessOrExit(error = AppendAddressRegistrationEntry(addr.GetAddress()));
|
||||||
counter++;
|
counter++;
|
||||||
// only continue to append if there is available entry.
|
// only continue to append if there is available entry.
|
||||||
VerifyOrExit(counter < kMaxIpAddressesToRegister);
|
VerifyOrExit(counter < kMaxIpAddressesToRegister);
|
||||||
@@ -5060,30 +5049,31 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error Mle::TxMessage::AppendCompressedAddressEntry(uint8_t aContextId, const Ip6::Address &aAddress)
|
Error Mle::TxMessage::AppendAddressRegistrationEntry(const Ip6::Address &aAddress)
|
||||||
{
|
{
|
||||||
// Append an IPv6 address entry in an Address Registration TLV
|
uint8_t ctlByte = AddressRegistrationTlv::kControlByteUncompressed;
|
||||||
// using compressed format (context ID with IID).
|
|
||||||
|
|
||||||
Error error;
|
|
||||||
|
|
||||||
SuccessOrExit(error = Append<uint8_t>(AddressRegistrationTlv::ControlByteFor(aContextId)));
|
|
||||||
error = Append(aAddress.GetIid());
|
|
||||||
|
|
||||||
exit:
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
Error Mle::TxMessage::AppendAddressEntry(const Ip6::Address &aAddress)
|
|
||||||
{
|
|
||||||
// Append an IPv6 address entry in an Address Registration TLV
|
|
||||||
// using uncompressed format
|
|
||||||
|
|
||||||
Error error;
|
Error error;
|
||||||
uint8_t controlByte = AddressRegistrationTlv::kControlByteUncompressed;
|
|
||||||
|
|
||||||
SuccessOrExit(error = Append(controlByte));
|
if (!aAddress.IsMulticast())
|
||||||
error = Append(aAddress);
|
{
|
||||||
|
Lowpan::Context context;
|
||||||
|
|
||||||
|
if ((Get<NetworkData::Leader>().GetContext(aAddress, context) == kErrorNone) && context.mCompressFlag)
|
||||||
|
{
|
||||||
|
ctlByte = AddressRegistrationTlv::ControlByteFor(context.mContextId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SuccessOrExit(error = Append(ctlByte));
|
||||||
|
|
||||||
|
if (ctlByte == AddressRegistrationTlv::kControlByteUncompressed)
|
||||||
|
{
|
||||||
|
error = Append(aAddress);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error = Append(aAddress.GetIid());
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -5252,10 +5242,9 @@ Error Mle::TxMessage::AppendConnectivityTlv(void)
|
|||||||
|
|
||||||
Error Mle::TxMessage::AppendAddressRegistrationTlv(Child &aChild)
|
Error Mle::TxMessage::AppendAddressRegistrationTlv(Child &aChild)
|
||||||
{
|
{
|
||||||
Error error;
|
Error error;
|
||||||
Tlv tlv;
|
Tlv tlv;
|
||||||
Lowpan::Context context;
|
uint16_t startOffset = GetLength();
|
||||||
uint16_t startOffset = GetLength();
|
|
||||||
|
|
||||||
tlv.SetType(Tlv::kAddressRegistration);
|
tlv.SetType(Tlv::kAddressRegistration);
|
||||||
SuccessOrExit(error = Append(tlv));
|
SuccessOrExit(error = Append(tlv));
|
||||||
@@ -5265,14 +5254,7 @@ Error Mle::TxMessage::AppendAddressRegistrationTlv(Child &aChild)
|
|||||||
|
|
||||||
for (const Ip6::Address &address : aChild.GetIp6Addresses())
|
for (const Ip6::Address &address : aChild.GetIp6Addresses())
|
||||||
{
|
{
|
||||||
if (address.IsMulticast() || Get<NetworkData::Leader>().GetContext(address, context) != kErrorNone)
|
SuccessOrExit(error = AppendAddressRegistrationEntry(address));
|
||||||
{
|
|
||||||
SuccessOrExit(error = AppendAddressEntry(address));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SuccessOrExit(error = AppendCompressedAddressEntry(context.mContextId, address));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tlv.SetLength(static_cast<uint8_t>(GetLength() - startOffset - sizeof(Tlv)));
|
tlv.SetLength(static_cast<uint8_t>(GetLength() - startOffset - sizeof(Tlv)));
|
||||||
|
|||||||
@@ -1032,8 +1032,7 @@ private:
|
|||||||
Error SendTo(const Ip6::Address &aDestination);
|
Error SendTo(const Ip6::Address &aDestination);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Error AppendCompressedAddressEntry(uint8_t aContextId, const Ip6::Address &aAddress);
|
Error AppendAddressRegistrationEntry(const Ip6::Address &aAddress);
|
||||||
Error AppendAddressEntry(const Ip6::Address &aAddress);
|
|
||||||
Error AppendDatasetTlv(MeshCoP::Dataset::Type aDatasetType);
|
Error AppendDatasetTlv(MeshCoP::Dataset::Type aDatasetType);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user