[mle] simplify logic for multicast address registration (#11872)

This change introduces `ShouldRegisterMulticastAddrsWithParent()` to
consolidate the logic for determining when a child should register
its multicast addresses with its parent, thereby avoiding repeated
code.

The criteria for registration remain the same: a child registers its
multicast addresses if it is a Sleepy End Device (SED), or if it is a
Minimal End Device (MED) and its parent is running Thread 1.2 or a
later version.
This commit is contained in:
Abtin Keshavarzian
2025-08-28 08:35:15 -07:00
committed by GitHub
parent c192351e20
commit 579d693295
2 changed files with 23 additions and 21 deletions
+22 -21
View File
@@ -1001,23 +1001,10 @@ void Mle::HandleNotifierEvents(Events aEvents)
ScheduleChildUpdateRequestIfMtdChild();
}
if (aEvents.ContainsAny(kEventIp6MulticastSubscribed | kEventIp6MulticastUnsubscribed))
if (aEvents.ContainsAny(kEventIp6MulticastSubscribed | kEventIp6MulticastUnsubscribed) &&
ShouldRegisterMulticastAddrsWithParent())
{
// When multicast subscription changes, SED always notifies
// its parent as it depends on its parent for indirect
// transmission. Since Thread 1.2, MED MAY also notify its
// parent of 1.2 or higher version as it could depend on its
// parent to perform Multicast Listener Report.
if (!IsRxOnWhenIdle()
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|| !GetParent().IsThreadVersion1p1()
#endif
)
{
ScheduleChildUpdateRequestIfMtdChild();
}
ScheduleChildUpdateRequestIfMtdChild();
}
if (aEvents.Contains(kEventThreadNetdataChanged))
@@ -1071,6 +1058,23 @@ exit:
return;
}
bool Mle::ShouldRegisterMulticastAddrsWithParent(void) const
{
// When multicast subscription changes, SED always notifies
// its parent as it depends on its parent for indirect
// transmission. Since Thread 1.2, MED MAY also notify its
// parent of 1.2 or higher version as it could depend on its
// parent to perform Multicast Listener Report.
bool shouldRegister = !IsRxOnWhenIdle();
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
shouldRegister |= !IsFullThreadDevice() && GetParent().IsThreadVersion1p2OrHigher();
#endif
return shouldRegister;
}
Error Mle::SendDataRequestToParent(void)
{
Ip6::Address destination;
@@ -3564,11 +3568,8 @@ Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode
// indirect transmission. Since Thread 1.2, non-sleepy MED should
// also register external multicast addresses of scope larger than
// realm with a 1.2 or higher parent.
if (!Get<Mle>().IsRxOnWhenIdle()
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|| !Get<Mle>().GetParent().IsThreadVersion1p1()
#endif
)
if (Get<Mle>().ShouldRegisterMulticastAddrsWithParent())
{
for (const Ip6::Netif::MulticastAddress &addr : Get<ThreadNetif>().IterateExternalMulticastAddresses())
{
+1
View File
@@ -2132,6 +2132,7 @@ private:
void SendAnnounce(uint8_t aChannel, AnnounceMode aMode);
void SendAnnounce(uint8_t aChannel, const Ip6::Address &aDestination, AnnounceMode aMode = kNormalAnnounce);
bool IsNetworkDataNewer(const LeaderData &aLeaderData);
bool ShouldRegisterMulticastAddrsWithParent(void) const;
Error ProcessMessageSecurity(Crypto::AesCcm::Mode aMode,
Message &aMessage,
const Ip6::MessageInfo &aMessageInfo,