From 23c3bd432356cfbd3d37b0b4207a478d2dba135c Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 6 Oct 2025 13:14:48 -0700 Subject: [PATCH] [mle] improve `DelayedSender::Match()` and logging (#11997) This change enhances the `DelayedSender::Match()` method to support a wildcard destination address. When the unspecified address (`::`) is provided, the address check is skipped, allowing a match against any destination. A new private helper method, `LogRemove()`, is introduced to ensure accurate logging when removing a delayed message schedule. Previously, `RemoveMatchingSchedules()` would log the address passed to it, which could be the wildcard `::` address. The new `LogRemove()` method logs the actual destination from the scheduled message header before it is removed. --- src/core/thread/mle.cpp | 31 +++++++++++++++++++++++++++++-- src/core/thread/mle.hpp | 1 + 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 30d7d66a9..1ed8e04bc 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -3386,11 +3386,26 @@ void Mle::DelayedSender::Execute(const Schedule &aSchedule) bool Mle::DelayedSender::Match(const Schedule &aSchedule, MessageType aMessageType, const Ip6::Address &aDestination) { + // If `aDestination` is `::` (the unspecified address), the + // address check is skipped, effectively accepting any + // destination address. + + bool matches = false; Header header; header.ReadFrom(aSchedule); - return (header.mMessageType == aMessageType) && (header.mDestination == aDestination); + VerifyOrExit(header.mMessageType == aMessageType); + + if (!aDestination.IsUnspecified()) + { + VerifyOrExit(header.mDestination == aDestination); + } + + matches = true; + +exit: + return matches; } bool Mle::DelayedSender::HasMatchingSchedule(MessageType aMessageType, const Ip6::Address &aDestination) const @@ -3415,12 +3430,24 @@ void Mle::DelayedSender::RemoveMatchingSchedules(MessageType aMessageType, const { if (Match(schedule, aMessageType, aDestination)) { + LogRemove(schedule); mSchedules.DequeueAndFree(schedule); - Log(kMessageRemoveDelayed, aMessageType, aDestination); } } } +#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) +void Mle::DelayedSender::LogRemove(const Schedule &aSchedule) +{ + Header header; + + header.ReadFrom(aSchedule); + Log(kMessageRemoveDelayed, header.mMessageType, header.mDestination); +} +#else +void Mle::DelayedSender::LogRemove(const Schedule &) {} +#endif + //--------------------------------------------------------------------------------------------------------------------- // TxMessage diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 1e62c5fbe..75af8864f 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1733,6 +1733,7 @@ private: void Execute(const Schedule &aSchedule); bool HasMatchingSchedule(MessageType aMessageType, const Ip6::Address &aDestination) const; void RemoveMatchingSchedules(MessageType aMessageType, const Ip6::Address &aDestination); + void LogRemove(const Schedule &aSchedule); static bool Match(const Schedule &aSchedule, MessageType aMessageType, const Ip6::Address &aDestination);