From ed95672bc04174185d62934fbfa19884394a5502 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 13 Aug 2025 10:17:55 -0700 Subject: [PATCH] [netdata] use `Mle` constants in `RemoveTemporaryData()` methods (#11813) This commit replaces hardcoded magic numbers for RLOC addresses with their corresponding named constants from the `Mle` namespace. - The DHCP Agent RLOC is now set using `Mle::kAloc16DhcpAgentStart`. - The invalid RLOC address `0xfffe` is replaced by `Mle::kInvalidRloc16`. This change improves code readability and maintainability. Redundant comments were also removed. --- src/core/thread/network_data.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/core/thread/network_data.cpp b/src/core/thread/network_data.cpp index d0e145ba8..9a4440ad0 100644 --- a/src/core/thread/network_data.cpp +++ b/src/core/thread/network_data.cpp @@ -581,17 +581,16 @@ bool MutableNetworkData::RemoveTemporaryDataIn(PrefixTlv &aPrefix) BorderRouterTlv *borderRouter = As(cur); ContextTlv *context = aPrefix.FindSubTlv(); - // Replace p_border_router_16 for (BorderRouterEntry *entry = borderRouter->GetFirstEntry(); entry <= borderRouter->GetLastEntry(); entry = entry->GetNext()) { if ((entry->IsDhcp() || entry->IsConfigure()) && (context != nullptr)) { - entry->SetRloc(0xfc00 | context->GetContextId()); + entry->SetRloc(Mle::kAloc16DhcpAgentStart + context->GetContextId() - 1); } else { - entry->SetRloc(0xfffe); + entry->SetRloc(Mle::kInvalidRloc16); } } @@ -602,11 +601,10 @@ bool MutableNetworkData::RemoveTemporaryDataIn(PrefixTlv &aPrefix) { HasRouteTlv *hasRoute = As(cur); - // Replace r_border_router_16 for (HasRouteEntry *entry = hasRoute->GetFirstEntry(); entry <= hasRoute->GetLastEntry(); entry = entry->GetNext()) { - entry->SetRloc(0xfffe); + entry->SetRloc(Mle::kInvalidRloc16); } break; @@ -616,13 +614,12 @@ bool MutableNetworkData::RemoveTemporaryDataIn(PrefixTlv &aPrefix) break; } - // keep stable tlv cur = cur->GetNext(); } else { - // remove temporary tlv uint8_t subTlvSize = cur->GetSize(); + RemoveTlv(cur); aPrefix.SetSubTlvsLength(aPrefix.GetSubTlvsLength() - subTlvSize); } @@ -649,13 +646,12 @@ bool MutableNetworkData::RemoveTemporaryDataIn(ServiceTlv &aService) break; } - // keep stable tlv cur = cur->GetNext(); } else { - // remove temporary tlv uint8_t subTlvSize = cur->GetSize(); + RemoveTlv(cur); aService.SetSubTlvsLength(aService.GetSubTlvsLength() - subTlvSize); }