From 579d693295f4dfc1c5f9a679454af455f788306d Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 28 Aug 2025 08:35:15 -0700 Subject: [PATCH] [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. --- src/core/thread/mle.cpp | 43 +++++++++++++++++++++-------------------- src/core/thread/mle.hpp | 1 + 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index fd8656056..d9f410246 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -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().IsRxOnWhenIdle() -#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) - || !Get().GetParent().IsThreadVersion1p1() -#endif - ) + + if (Get().ShouldRegisterMulticastAddrsWithParent()) { for (const Ip6::Netif::MulticastAddress &addr : Get().IterateExternalMulticastAddresses()) { diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index bb75a38f8..90a014b96 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -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,