Skip to content

Commit

Permalink
[mlr] use Array<> to track old registered MLR addresses (#9134)
Browse files Browse the repository at this point in the history
  • Loading branch information
abtink committed Jun 7, 2023
1 parent 6a549d1 commit b69dfef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
9 changes: 4 additions & 5 deletions src/core/thread/mle_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,8 +1802,7 @@ Error MleRouter::ProcessAddressRegistrationTlv(RxInfo &aRxInfo, Child &aChild)
Ip6::Address oldDua;
#endif
#if OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE
Ip6::Address oldMlrRegisteredAddresses[kMaxChildIpAddresses - 1];
uint16_t oldMlrRegisteredAddressNum = 0;
MlrManager::MlrAddressArray oldMlrRegisteredAddresses;
#endif

SuccessOrExit(error = Tlv::FindTlvValueOffset(aRxInfo.mMessage, Tlv::kAddressRegistration, offset, length));
Expand Down Expand Up @@ -1833,7 +1832,7 @@ Error MleRouter::ProcessAddressRegistrationTlv(RxInfo &aRxInfo, Child &aChild)
{
if (aChild.GetAddressMlrState(childAddress) == kMlrStateRegistered)
{
oldMlrRegisteredAddresses[oldMlrRegisteredAddressNum++] = childAddress;
IgnoreError(oldMlrRegisteredAddresses.PushBack(childAddress));
}
}
}
Expand Down Expand Up @@ -1975,7 +1974,7 @@ Error MleRouter::ProcessAddressRegistrationTlv(RxInfo &aRxInfo, Child &aChild)
#endif

#if OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE
Get<MlrManager>().UpdateProxiedSubscriptions(aChild, oldMlrRegisteredAddresses, oldMlrRegisteredAddressNum);
Get<MlrManager>().UpdateProxiedSubscriptions(aChild, oldMlrRegisteredAddresses);
#endif

if (count == 0)
Expand Down Expand Up @@ -3942,7 +3941,7 @@ void MleRouter::SetChildStateToValid(Child &aChild)
IgnoreError(mChildTable.StoreChild(aChild));

#if OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE
Get<MlrManager>().UpdateProxiedSubscriptions(aChild, nullptr, 0);
Get<MlrManager>().UpdateProxiedSubscriptions(aChild, MlrManager::MlrAddressArray());
#endif

mNeighborTable.Signal(NeighborTable::kChildAdded, aChild);
Expand Down
16 changes: 2 additions & 14 deletions src/core/thread/mlr_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,14 @@ bool MlrManager::IsAddressMlrRegisteredByAnyChildExcept(const Ip6::Address &aAdd
return ret;
}

void MlrManager::UpdateProxiedSubscriptions(Child &aChild,
const Ip6::Address *aOldMlrRegisteredAddresses,
uint16_t aOldMlrRegisteredAddressNum)
void MlrManager::UpdateProxiedSubscriptions(Child &aChild, const MlrAddressArray &aOldMlrRegisteredAddresses)
{
VerifyOrExit(aChild.IsStateValid());

// Search the new multicast addresses and set its flag accordingly
for (const Ip6::Address &address : aChild.IterateIp6Addresses(Ip6::Address::kTypeMulticastLargerThanRealmLocal))
{
bool isMlrRegistered = false;

// Check if it's a new multicast address against old addresses
for (size_t i = 0; i < aOldMlrRegisteredAddressNum; i++)
{
if (aOldMlrRegisteredAddresses[i] == address)
{
isMlrRegistered = true;
break;
}
}
bool isMlrRegistered = aOldMlrRegisteredAddresses.Contains(address);

#if OPENTHREAD_CONFIG_MLR_ENABLE
// Check if it's a new multicast address against parent Netif
Expand Down
11 changes: 6 additions & 5 deletions src/core/thread/mlr_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,18 @@ class MlrManager : public InstanceLocator, private NonCopyable
void HandleBackboneRouterPrimaryUpdate(BackboneRouter::Leader::State aState, const BackboneRouter::Config &aConfig);

#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE
static constexpr uint16_t kMaxMlrAddresses = OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD - 1; ///< Max MLR addresses

typedef Array<Ip6::Address, kMaxMlrAddresses> MlrAddressArray; ///< Registered MLR addresses array.

/**
* Updates the Multicast Subscription Table according to the Child information.
*
* @param[in] aChild A reference to the child information.
* @param[in] aOldMlrRegisteredAddresses Pointer to an array of the Child's previously registered IPv6 addresses.
* @param[in] aOldMlrRegisteredAddressNum The number of previously registered IPv6 addresses.
* @param[in] aOldMlrRegisteredAddresses Array of the Child's previously registered IPv6 addresses.
*
*/
void UpdateProxiedSubscriptions(Child &aChild,
const Ip6::Address *aOldMlrRegisteredAddresses,
uint16_t aOldMlrRegisteredAddressNum);
void UpdateProxiedSubscriptions(Child &aChild, const MlrAddressArray &aOldMlrRegisteredAddresses);
#endif

#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
Expand Down

0 comments on commit b69dfef

Please sign in to comment.