Skip to content

Commit

Permalink
[ip6-mpl] remove aIsOutbound input and use aMessage.GetOrigin() (o…
Browse files Browse the repository at this point in the history
…penthread#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.
  • Loading branch information
abtink authored Oct 10, 2023
1 parent ca97cf7 commit 0d0655d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/core/net/ip6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/core/net/ip6.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 13 additions & 6 deletions src/core/net/ip6_mpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions src/core/net/ip6_mpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,14 @@ 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.
*
* @retval kErrorNone Successfully processed the MPL option.
* @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
/**
Expand Down Expand Up @@ -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<Mpl, &Mpl::HandleRetransmissionTimer>;

Expand Down

0 comments on commit 0d0655d

Please sign in to comment.