From e4339c5939c758136fc009075239990ff8dc1d77 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 3 Apr 2025 08:32:10 -0700 Subject: [PATCH] [mesh-forwarder] simplify destination MAC address determination (#11391) This commit simplifies the process of determining the destination MAC address. Specifically, when the destination is a link-local unicast address, the MAC address is derived directly from its Interface Identifier (IID). This commit replaces and removes the `GetMacDestinationAddress()` method, with the calling code now directly determining the destination MAC address. --- src/core/thread/indirect_sender.cpp | 2 +- src/core/thread/mesh_forwarder.cpp | 26 +++++++------------------- src/core/thread/mesh_forwarder.hpp | 1 - 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/core/thread/indirect_sender.cpp b/src/core/thread/indirect_sender.cpp index b465c8de8..500d3179b 100644 --- a/src/core/thread/indirect_sender.cpp +++ b/src/core/thread/indirect_sender.cpp @@ -371,7 +371,7 @@ uint16_t IndirectSender::PrepareDataFrame(Mac::TxFrame &aFrame, Child &aChild, M if (ip6Header.GetDestination().IsLinkLocalUnicast()) { - Get().GetMacDestinationAddress(ip6Header.GetDestination(), macAddrs.mDestination); + macAddrs.mDestination.SetExtendedFromIid(ip6Header.GetDestination().GetIid()); } else { diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index ae126fedd..60e7ce684 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -632,9 +632,13 @@ Error MeshForwarder::UpdateIp6Route(Message &aMessage) if (mle.IsDisabled() || mle.IsDetached()) { - if (ip6Header.GetDestination().IsLinkLocalUnicastOrMulticast()) + if (ip6Header.GetDestination().IsLinkLocalMulticast()) { - GetMacDestinationAddress(ip6Header.GetDestination(), mMacAddrs.mDestination); + mMacAddrs.mDestination.SetShort(Mac::kShortAddrBroadcast); + } + else if (ip6Header.GetDestination().IsLinkLocalUnicast()) + { + mMacAddrs.mDestination.SetExtendedFromIid(ip6Header.GetDestination().GetIid()); } else { @@ -661,7 +665,7 @@ Error MeshForwarder::UpdateIp6Route(Message &aMessage) } else if (ip6Header.GetDestination().IsLinkLocalUnicast()) { - GetMacDestinationAddress(ip6Header.GetDestination(), mMacAddrs.mDestination); + mMacAddrs.mDestination.SetExtendedFromIid(ip6Header.GetDestination().GetIid()); } else if (mle.IsMinimalEndDevice()) { @@ -708,22 +712,6 @@ void MeshForwarder::GetMacSourceAddress(const Ip6::Address &aIp6Addr, Mac::Addre } } -void MeshForwarder::GetMacDestinationAddress(const Ip6::Address &aIp6Addr, Mac::Address &aMacAddr) -{ - if (aIp6Addr.IsMulticast()) - { - aMacAddr.SetShort(Mac::kShortAddrBroadcast); - } - else if (Get().IsRoutingLocator(aIp6Addr)) - { - aMacAddr.SetShort(aIp6Addr.GetIid().GetLocator()); - } - else - { - aMacAddr.SetExtendedFromIid(aIp6Addr.GetIid()); - } -} - Mac::TxFrame *MeshForwarder::HandleFrameRequest(Mac::TxFrames &aTxFrames) { Mac::TxFrame *frame = nullptr; diff --git a/src/core/thread/mesh_forwarder.hpp b/src/core/thread/mesh_forwarder.hpp index 4a27db389..22dd6be10 100644 --- a/src/core/thread/mesh_forwarder.hpp +++ b/src/core/thread/mesh_forwarder.hpp @@ -491,7 +491,6 @@ private: Error CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header); void UpdateRoutes(RxInfo &aRxInfo); Error FrameToMessage(RxInfo &aRxInfo, uint16_t aDatagramSize, Message *&aMessage); - void GetMacDestinationAddress(const Ip6::Address &aIp6Addr, Mac::Address &aMacAddr); void GetMacSourceAddress(const Ip6::Address &aIp6Addr, Mac::Address &aMacAddr); Message *PrepareNextDirectTransmission(void); void HandleMesh(RxInfo &aRxInfo);