[thread] simplify ThreadNetworkDataTlv definition (#12770)

This commit simplifies the definition of `ThreadNetworkDataTlv`.
Previously, `ThreadNetworkDataTlv` included a 255-byte array to store
the Network Data TLVs. The code now relies on standard TLV parsing
methods like `Tlv::FindTlvValueOffsetRange()` and `Message::ReadBytes()`
to access the Network Data directly from the message payload.
This commit is contained in:
Abtin Keshavarzian
2026-03-27 00:48:05 -05:00
committed by GitHub
parent cb4b28313b
commit e2e36d61e7
3 changed files with 13 additions and 40 deletions
+9 -5
View File
@@ -221,8 +221,8 @@ void Leader::RemoveBorderRouter(uint16_t aRloc16, MatchMode aMatchMode)
template <> void Leader::HandleTmf<kUriServerData>(Coap::Msg &aMsg)
{
ThreadNetworkDataTlv networkDataTlv;
uint16_t rloc16;
uint16_t rloc16;
OffsetRange offsetRange;
VerifyOrExit(Get<Mle::Mle>().IsLeader() && !mWaitingForNetDataSync);
@@ -241,12 +241,16 @@ template <> void Leader::HandleTmf<kUriServerData>(Coap::Msg &aMsg)
ExitNow();
}
if (Tlv::FindTlv(aMsg.mMessage, networkDataTlv) == kErrorNone)
if (Tlv::FindTlvValueOffsetRange(aMsg.mMessage, ThreadNetworkDataTlv::kType, offsetRange) == kErrorNone)
{
VerifyOrExit(networkDataTlv.IsValid());
uint8_t bytes[kMaxSize];
VerifyOrExit(offsetRange.GetLength() <= kMaxSize);
aMsg.mMessage.ReadBytes(offsetRange, bytes);
{
NetworkData networkData(GetInstance(), networkDataTlv.GetTlvs(), networkDataTlv.GetLength());
NetworkData networkData(GetInstance(), bytes, static_cast<uint8_t>(offsetRange.GetLength()));
RegisterNetworkData(aMsg.mMessageInfo.GetPeerAddr().GetIid().GetLocator(), networkData);
}
+2 -2
View File
@@ -191,8 +191,8 @@ Error Notifier::SendServerDataNotification(uint16_t aOldRloc16, const NetworkDat
if (aNetworkData != nullptr)
{
SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kThreadNetworkData, aNetworkData->GetBytes(),
aNetworkData->GetLength()));
SuccessOrExit(
error = Tlv::Append<ThreadNetworkDataTlv>(*message, aNetworkData->GetBytes(), aNetworkData->GetLength()));
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BORDER_ROUTER_SIGNAL_NETWORK_DATA_FULL
Get<Leader>().CheckForNetDataGettingFull(*aNetworkData, aOldRloc16);
+2 -33
View File
@@ -202,40 +202,9 @@ private:
} OT_TOOL_PACKED_END;
/**
* Implements Thread Network Data TLV generation and parsing.
* Defines Thread Network Data TLV constants and types.
*/
OT_TOOL_PACKED_BEGIN
class ThreadNetworkDataTlv : public ThreadTlv, public TlvInfo<ThreadTlv::kThreadNetworkData>
{
public:
/**
* Initializes the TLV.
*/
void Init(void)
{
SetType(kThreadNetworkData);
SetLength(0);
}
/**
* Overrides same method of the base class
*
* @retval TRUE the TLV appears to be well-formed.
*/
bool IsValid(void) const { return true; }
/**
* Returns a pointer to the Network Data TLVs.
*
* @returns A pointer to the Network Data TLVs.
*/
uint8_t *GetTlvs(void) { return mTlvs; }
private:
static constexpr uint8_t kMaxSize = 255;
uint8_t mTlvs[kMaxSize];
} OT_TOOL_PACKED_END;
typedef TlvInfo<ThreadTlv::kThreadNetworkData> ThreadNetworkDataTlv;
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2