From 0d0655ded94ec34ddc3b2484e9445e6b89612a1e Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 10 Oct 2023 14:14:44 -0700 Subject: [PATCH] [ip6-mpl] remove `aIsOutbound` input and use `aMessage.GetOrigin()` (#9510) With the recent addition of `GetOrigin()`, the origin of a message is tracked by `Message` itself. With this change, we no longer need to pass `aIsOutbound` to `Ip6::Mpl` methods, as it can be determined from the origin of `aMessage`. This commit simplifies the code by removing the `aIsOutbound` input parameter. --- src/core/net/ip6.cpp | 12 ++++++------ src/core/net/ip6.hpp | 2 +- src/core/net/ip6_mpl.cpp | 19 +++++++++++++------ src/core/net/ip6_mpl.hpp | 5 ++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index b97995cf834..6d96ccf998c 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -516,7 +516,7 @@ void Ip6::HandleSendQueue(void) } } -Error Ip6::HandleOptions(Message &aMessage, Header &aHeader, bool aIsOutbound, bool &aReceive) +Error Ip6::HandleOptions(Message &aMessage, Header &aHeader, bool &aReceive) { Error error = kErrorNone; HopByHopHeader hbhHeader; @@ -542,7 +542,7 @@ Error Ip6::HandleOptions(Message &aMessage, Header &aHeader, bool aIsOutbound, b if (option.GetType() == MplOption::kType) { - SuccessOrExit(error = mMpl.ProcessOption(aMessage, offset, aHeader.GetSource(), aIsOutbound, aReceive)); + SuccessOrExit(error = mMpl.ProcessOption(aMessage, offset, aHeader.GetSource(), aReceive)); continue; } @@ -829,8 +829,8 @@ Error Ip6::HandleExtensionHeaders(Message &aMessage, uint8_t &aNextHeader, bool &aReceive) { - Error error = kErrorNone; - bool isOutbound = !aMessage.IsOriginThreadNetif(); + Error error = kErrorNone; + ExtensionHeader extHeader; while (aReceive || aNextHeader == kProtoHopOpts) @@ -840,7 +840,7 @@ Error Ip6::HandleExtensionHeaders(Message &aMessage, switch (aNextHeader) { case kProtoHopOpts: - SuccessOrExit(error = HandleOptions(aMessage, aHeader, isOutbound, aReceive)); + SuccessOrExit(error = HandleOptions(aMessage, aHeader, aReceive)); break; case kProtoFragment: @@ -850,7 +850,7 @@ Error Ip6::HandleExtensionHeaders(Message &aMessage, break; case kProtoDstOpts: - SuccessOrExit(error = HandleOptions(aMessage, aHeader, isOutbound, aReceive)); + SuccessOrExit(error = HandleOptions(aMessage, aHeader, aReceive)); break; case kProtoIp6: diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index ff5c1fd0ccb..46e0b05f7ca 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -390,7 +390,7 @@ class Ip6 : public InstanceLocator, private NonCopyable Error AddTunneledMplOption(Message &aMessage, Header &aHeader); Error InsertMplOption(Message &aMessage, Header &aHeader); Error RemoveMplOption(Message &aMessage); - Error HandleOptions(Message &aMessage, Header &aHeader, bool aIsOutbound, bool &aReceive); + Error HandleOptions(Message &aMessage, Header &aHeader, bool &aReceive); Error HandlePayload(Header &aIp6Header, Message &aMessage, MessageInfo &aMessageInfo, diff --git a/src/core/net/ip6_mpl.cpp b/src/core/net/ip6_mpl.cpp index 70a37c211cd..6fbdf385b36 100644 --- a/src/core/net/ip6_mpl.cpp +++ b/src/core/net/ip6_mpl.cpp @@ -90,7 +90,7 @@ void Mpl::InitOption(MplOption &aOption, const Address &aAddress) aOption.SetSequence(mSequence++); } -Error Mpl::ProcessOption(Message &aMessage, uint16_t aOffset, const Address &aAddress, bool aIsOutbound, bool &aReceive) +Error Mpl::ProcessOption(Message &aMessage, uint16_t aOffset, const Address &aAddress, bool &aReceive) { Error error; MplOption option; @@ -122,10 +122,10 @@ Error Mpl::ProcessOption(Message &aMessage, uint16_t aOffset, const Address &aAd if (error == kErrorNone) { #if OPENTHREAD_FTD - AddBufferedMessage(aMessage, option.GetSeedId(), option.GetSequence(), aIsOutbound); + AddBufferedMessage(aMessage, option.GetSeedId(), option.GetSequence()); #endif } - else if (aIsOutbound) + else if (!aMessage.IsOriginThreadNetif()) { aReceive = false; // In case MPL Data Message is generated locally, ignore potential error of the MPL Seed Set @@ -334,7 +334,7 @@ uint8_t Mpl::DetermineMaxRetransmissions(void) const return maxRetx; } -void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence, bool aIsOutbound) +void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence) { Error error = kErrorNone; Message *messageCopy = nullptr; @@ -352,16 +352,23 @@ void Mpl::AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSeque VerifyOrExit(DetermineMaxRetransmissions() > 0); VerifyOrExit((messageCopy = aMessage.Clone()) != nullptr, error = kErrorNoBufs); - if (!aIsOutbound) + if (aMessage.IsOriginThreadNetif()) { IgnoreError(aMessage.Read(Header::kHopLimitFieldOffset, hopLimit)); VerifyOrExit(hopLimit-- > 1, error = kErrorDrop); messageCopy->Write(Header::kHopLimitFieldOffset, hopLimit); } + // If the message originates from Thread Netif (i.e., it was + // received over Thread radio), set the `mTransmissionCount` to + // zero. Otherwise, the message originates from the host and will + // be forwarded by `Ip6` to the Thread mesh, so the message itself + // will be the first transmission and we set `mTransmissionCount` + // to one. + metadata.mSeedId = aSeedId; metadata.mSequence = aSequence; - metadata.mTransmissionCount = aIsOutbound ? 1 : 0; + metadata.mTransmissionCount = aMessage.IsOriginThreadNetif() ? 0 : 1; metadata.mIntervalOffset = 0; metadata.GenerateNextTransmissionTime(TimerMilli::GetNow(), interval); diff --git a/src/core/net/ip6_mpl.hpp b/src/core/net/ip6_mpl.hpp index 8ad9ed45314..35953b53fe5 100644 --- a/src/core/net/ip6_mpl.hpp +++ b/src/core/net/ip6_mpl.hpp @@ -194,7 +194,6 @@ class Mpl : public InstanceLocator, private NonCopyable * @param[in] aMessage A reference to the message. * @param[in] aOffset The offset in @p aMessage to read the MPL option. * @param[in] aAddress A reference to the IPv6 Source Address. - * @param[in] aIsOutbound TRUE if this message was locally generated, FALSE otherwise. * @param[out] aReceive Set to FALSE if the MPL message is a duplicate and must not * go through the receiving process again, untouched otherwise. * @@ -202,7 +201,7 @@ class Mpl : public InstanceLocator, private NonCopyable * @retval kErrorDrop The MPL message is a duplicate and should be dropped. * */ - Error ProcessOption(Message &aMessage, uint16_t aOffset, const Address &aAddress, bool aIsOutbound, bool &aReceive); + Error ProcessOption(Message &aMessage, uint16_t aOffset, const Address &aAddress, bool &aReceive); #if OPENTHREAD_FTD /** @@ -254,7 +253,7 @@ class Mpl : public InstanceLocator, private NonCopyable uint8_t DetermineMaxRetransmissions(void) const; void HandleRetransmissionTimer(void); - void AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence, bool aIsOutbound); + void AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence); using RetxTimer = TimerMilliIn;