mirror of
https://github.com/espressif/openthread.git
synced 2026-08-07 19:27:46 +00:00
[ip6] rename Option sub-classes (#8709)
This commit renames the `Ip6::Option` and its sub-classes, e.g., we use `MplOption` instead of `OptionMpl` to follow similar naming pattern as `Tlv`s.
This commit is contained in:
@@ -945,7 +945,7 @@ private:
|
||||
Message *operator->(void) { return static_cast<Message *>(ot::Message::Iterator::operator->()); }
|
||||
};
|
||||
|
||||
static_assert(sizeof(HelpData) <= sizeof(Ip6::Header) + sizeof(Ip6::HopByHopHeader) + sizeof(Ip6::OptionMpl) +
|
||||
static_assert(sizeof(HelpData) <= sizeof(Ip6::Header) + sizeof(Ip6::HopByHopHeader) + sizeof(Ip6::MplOption) +
|
||||
sizeof(Ip6::Udp::Header),
|
||||
"HelpData size exceeds the size of the reserved region in the message");
|
||||
|
||||
|
||||
+27
-27
@@ -84,7 +84,7 @@ Ip6::Ip6(Instance &aInstance)
|
||||
Message *Ip6::NewMessage(uint16_t aReserved, const Message::Settings &aSettings)
|
||||
{
|
||||
return Get<MessagePool>().Allocate(
|
||||
Message::kTypeIp6, sizeof(Header) + sizeof(HopByHopHeader) + sizeof(OptionMpl) + aReserved, aSettings);
|
||||
Message::kTypeIp6, sizeof(Header) + sizeof(HopByHopHeader) + sizeof(MplOption) + aReserved, aSettings);
|
||||
}
|
||||
|
||||
Message *Ip6::NewMessage(const uint8_t *aData, uint16_t aDataLength, const Message::Settings &aSettings)
|
||||
@@ -191,7 +191,7 @@ Error Ip6::AddMplOption(Message &aMessage, Header &aHeader)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
HopByHopHeader hbhHeader;
|
||||
OptionMpl mplOption;
|
||||
MplOption mplOption;
|
||||
|
||||
hbhHeader.SetNextHeader(aHeader.GetNextHeader());
|
||||
hbhHeader.SetLength(0);
|
||||
@@ -200,7 +200,7 @@ Error Ip6::AddMplOption(Message &aMessage, Header &aHeader)
|
||||
// Mpl option may require two bytes padding.
|
||||
if ((mplOption.GetSize() + sizeof(hbhHeader)) % 8)
|
||||
{
|
||||
OptionPadN padOption;
|
||||
PadNOption padOption;
|
||||
|
||||
padOption.Init(2);
|
||||
SuccessOrExit(error = aMessage.PrependBytes(&padOption, padOption.GetSize()));
|
||||
@@ -255,7 +255,7 @@ Error Ip6::InsertMplOption(Message &aMessage, Header &aHeader)
|
||||
{
|
||||
HopByHopHeader hbh;
|
||||
uint16_t hbhSize;
|
||||
OptionMpl mplOption;
|
||||
MplOption mplOption;
|
||||
|
||||
// read existing hop-by-hop option header
|
||||
SuccessOrExit(error = aMessage.Read(0, hbh));
|
||||
@@ -278,7 +278,7 @@ Error Ip6::InsertMplOption(Message &aMessage, Header &aHeader)
|
||||
// insert Pad Option (if needed)
|
||||
if (mplOption.GetSize() % 8)
|
||||
{
|
||||
OptionPadN padOption;
|
||||
PadNOption padOption;
|
||||
|
||||
padOption.Init(8 - (mplOption.GetSize() % 8));
|
||||
aMessage.WriteBytes(hbhSize + mplOption.GetSize(), &padOption, padOption.GetSize());
|
||||
@@ -345,20 +345,20 @@ Error Ip6::RemoveMplOption(Message &aMessage)
|
||||
|
||||
while (offset < endOffset)
|
||||
{
|
||||
OptionHeader option;
|
||||
Option option;
|
||||
|
||||
IgnoreError(aMessage.Read(offset, option));
|
||||
|
||||
switch (option.GetType())
|
||||
{
|
||||
case OptionMpl::kType:
|
||||
case MplOption::kType:
|
||||
// if multiple MPL options exist, discard packet
|
||||
VerifyOrExit(mplOffset == 0, error = kErrorParse);
|
||||
|
||||
mplOffset = offset;
|
||||
mplLength = option.GetLength();
|
||||
|
||||
VerifyOrExit(mplLength <= sizeof(OptionMpl) - sizeof(OptionHeader), error = kErrorParse);
|
||||
VerifyOrExit(mplLength <= sizeof(MplOption) - sizeof(Option), error = kErrorParse);
|
||||
|
||||
if (mplOffset == sizeof(ip6Header) + sizeof(hbh) && hbh.GetLength() == 0)
|
||||
{
|
||||
@@ -374,11 +374,11 @@ Error Ip6::RemoveMplOption(Message &aMessage)
|
||||
offset += option.GetSize();
|
||||
break;
|
||||
|
||||
case OptionPad1::kType:
|
||||
offset += sizeof(OptionPad1);
|
||||
case Pad1Option::kType:
|
||||
offset += sizeof(Pad1Option);
|
||||
break;
|
||||
|
||||
case OptionPadN::kType:
|
||||
case PadNOption::kType:
|
||||
offset += option.GetSize();
|
||||
break;
|
||||
|
||||
@@ -427,9 +427,9 @@ Error Ip6::RemoveMplOption(Message &aMessage)
|
||||
else if (mplOffset != 0)
|
||||
{
|
||||
// replace MPL Option with PadN Option
|
||||
OptionPadN padOption;
|
||||
PadNOption padOption;
|
||||
|
||||
padOption.Init(sizeof(OptionHeader) + mplLength);
|
||||
padOption.Init(sizeof(Option) + mplLength);
|
||||
aMessage.WriteBytes(mplOffset, &padOption, padOption.GetSize());
|
||||
}
|
||||
|
||||
@@ -540,7 +540,7 @@ Error Ip6::HandleOptions(Message &aMessage, Header &aHeader, bool aIsOutbound, b
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
HopByHopHeader hbhHeader;
|
||||
OptionHeader optionHeader;
|
||||
Option option;
|
||||
uint16_t endOffset;
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), hbhHeader));
|
||||
@@ -548,40 +548,40 @@ Error Ip6::HandleOptions(Message &aMessage, Header &aHeader, bool aIsOutbound, b
|
||||
|
||||
VerifyOrExit(endOffset <= aMessage.GetLength(), error = kErrorParse);
|
||||
|
||||
aMessage.MoveOffset(sizeof(optionHeader));
|
||||
aMessage.MoveOffset(sizeof(option));
|
||||
|
||||
while (aMessage.GetOffset() < endOffset)
|
||||
{
|
||||
SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), optionHeader));
|
||||
SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), option));
|
||||
|
||||
if (optionHeader.GetType() == OptionPad1::kType)
|
||||
if (option.GetType() == Pad1Option::kType)
|
||||
{
|
||||
aMessage.MoveOffset(sizeof(OptionPad1));
|
||||
aMessage.MoveOffset(sizeof(Pad1Option));
|
||||
continue;
|
||||
}
|
||||
|
||||
VerifyOrExit(aMessage.GetOffset() + optionHeader.GetSize() <= endOffset, error = kErrorParse);
|
||||
VerifyOrExit(aMessage.GetOffset() + option.GetSize() <= endOffset, error = kErrorParse);
|
||||
|
||||
switch (optionHeader.GetType())
|
||||
switch (option.GetType())
|
||||
{
|
||||
case OptionMpl::kType:
|
||||
case MplOption::kType:
|
||||
SuccessOrExit(error = mMpl.ProcessOption(aMessage, aHeader.GetSource(), aIsOutbound, aReceive));
|
||||
break;
|
||||
|
||||
default:
|
||||
switch (optionHeader.GetAction())
|
||||
switch (option.GetAction())
|
||||
{
|
||||
case OptionHeader::kActionSkip:
|
||||
case Option::kActionSkip:
|
||||
break;
|
||||
|
||||
case OptionHeader::kActionDiscard:
|
||||
case Option::kActionDiscard:
|
||||
ExitNow(error = kErrorDrop);
|
||||
|
||||
case OptionHeader::kActionForceIcmp:
|
||||
case Option::kActionForceIcmp:
|
||||
// TODO: send icmp error
|
||||
ExitNow(error = kErrorDrop);
|
||||
|
||||
case OptionHeader::kActionIcmp:
|
||||
case Option::kActionIcmp:
|
||||
// TODO: send icmp error
|
||||
ExitNow(error = kErrorDrop);
|
||||
}
|
||||
@@ -589,7 +589,7 @@ Error Ip6::HandleOptions(Message &aMessage, Header &aHeader, bool aIsOutbound, b
|
||||
break;
|
||||
}
|
||||
|
||||
aMessage.MoveOffset(optionHeader.GetSize());
|
||||
aMessage.MoveOffset(option.GetSize());
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
@@ -447,14 +447,14 @@ class HopByHopHeader : public ExtensionHeader
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class OptionHeader
|
||||
class Option
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
*/
|
||||
OptionHeader(void)
|
||||
Option(void)
|
||||
: mType(0)
|
||||
, mLength(0)
|
||||
{
|
||||
@@ -518,7 +518,7 @@ public:
|
||||
* @returns The size of the Option.
|
||||
*
|
||||
*/
|
||||
uint16_t GetSize(void) const { return static_cast<uint16_t>(mLength) + sizeof(OptionHeader); }
|
||||
uint16_t GetSize(void) const { return static_cast<uint16_t>(mLength) + sizeof(Option); }
|
||||
|
||||
private:
|
||||
static constexpr uint8_t kActionMask = 0xc0;
|
||||
@@ -532,7 +532,7 @@ private:
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class OptionPadN : public OptionHeader
|
||||
class PadNOption : public Option
|
||||
{
|
||||
public:
|
||||
static constexpr uint8_t kType = 0x01; ///< PadN type
|
||||
@@ -548,8 +548,8 @@ public:
|
||||
void Init(uint8_t aPadLength)
|
||||
{
|
||||
SetType(kType);
|
||||
SetLength(aPadLength - sizeof(OptionHeader));
|
||||
memset(mPad, kData, aPadLength - sizeof(OptionHeader));
|
||||
SetLength(aPadLength - sizeof(Option));
|
||||
memset(mPad, kData, aPadLength - sizeof(Option));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -561,7 +561,7 @@ private:
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class OptionPad1
|
||||
class Pad1Option
|
||||
{
|
||||
public:
|
||||
static constexpr uint8_t kType = 0x00;
|
||||
|
||||
+10
-10
@@ -54,7 +54,7 @@ Mpl::Mpl(Instance &aInstance)
|
||||
memset(mSeedSet, 0, sizeof(mSeedSet));
|
||||
}
|
||||
|
||||
void Mpl::InitOption(OptionMpl &aOption, const Address &aAddress)
|
||||
void Mpl::InitOption(MplOption &aOption, const Address &aAddress)
|
||||
{
|
||||
aOption.Init();
|
||||
aOption.SetSequence(mSequence++);
|
||||
@@ -62,14 +62,14 @@ void Mpl::InitOption(OptionMpl &aOption, const Address &aAddress)
|
||||
// Seed ID can be elided when `aAddress` is RLOC.
|
||||
if (aAddress == Get<Mle::Mle>().GetMeshLocal16())
|
||||
{
|
||||
aOption.SetSeedIdLength(OptionMpl::kSeedIdLength0);
|
||||
aOption.SetSeedIdLength(MplOption::kSeedIdLength0);
|
||||
|
||||
// Decrease default option length.
|
||||
aOption.SetLength(aOption.GetLength() - sizeof(uint16_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
aOption.SetSeedIdLength(OptionMpl::kSeedIdLength2);
|
||||
aOption.SetSeedIdLength(MplOption::kSeedIdLength2);
|
||||
aOption.SetSeedId(Get<Mle::Mle>().GetRloc16());
|
||||
}
|
||||
}
|
||||
@@ -77,26 +77,26 @@ void Mpl::InitOption(OptionMpl &aOption, const Address &aAddress)
|
||||
Error Mpl::ProcessOption(Message &aMessage, const Address &aAddress, bool aIsOutbound, bool &aReceive)
|
||||
{
|
||||
Error error;
|
||||
OptionMpl option;
|
||||
MplOption option;
|
||||
|
||||
// Read the min size bytes first, then check the expected
|
||||
// `SeedIdLength` and read the full `OptionMpl` if needed.
|
||||
SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), &option, OptionMpl::kMinSize));
|
||||
// `SeedIdLength` and read the full `MplOption` if needed.
|
||||
SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), &option, MplOption::kMinSize));
|
||||
|
||||
switch (option.GetSeedIdLength())
|
||||
{
|
||||
case OptionMpl::kSeedIdLength0:
|
||||
case MplOption::kSeedIdLength0:
|
||||
// Retrieve Seed ID from the IPv6 Source Address RLOC.
|
||||
VerifyOrExit(aAddress.GetIid().IsLocator(), error = kErrorDrop);
|
||||
option.SetSeedId(aAddress.GetIid().GetLocator());
|
||||
break;
|
||||
|
||||
case OptionMpl::kSeedIdLength2:
|
||||
case MplOption::kSeedIdLength2:
|
||||
SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), option));
|
||||
break;
|
||||
|
||||
case OptionMpl::kSeedIdLength8:
|
||||
case OptionMpl::kSeedIdLength16:
|
||||
case MplOption::kSeedIdLength8:
|
||||
case MplOption::kSeedIdLength16:
|
||||
ExitNow(error = kErrorParse);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,11 +61,11 @@ namespace Ip6 {
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class OptionMpl : public OptionHeader
|
||||
class MplOption : public Option
|
||||
{
|
||||
public:
|
||||
static constexpr uint8_t kType = 0x6d; ///< MPL option type - 01 1 01101
|
||||
static constexpr uint8_t kMinSize = (2 + sizeof(OptionHeader)); ///< Minimum size (num of bytes) of `OptionMpl`
|
||||
static constexpr uint8_t kType = 0x6d; ///< MPL option type - 01 1 01101
|
||||
static constexpr uint8_t kMinSize = (2 + sizeof(Option)); ///< Minimum size (num of bytes) of `MplOption`
|
||||
|
||||
/**
|
||||
* This method initializes the MPL header.
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
void Init(void)
|
||||
{
|
||||
SetType(kType);
|
||||
SetLength(sizeof(*this) - sizeof(OptionHeader));
|
||||
SetLength(sizeof(*this) - sizeof(Option));
|
||||
mControl = 0;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
* @param[in] aAddress A reference to the IPv6 Source Address.
|
||||
*
|
||||
*/
|
||||
void InitOption(OptionMpl &aOption, const Address &aAddress);
|
||||
void InitOption(MplOption &aOption, const Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method processes an MPL option. When the MPL module acts as an MPL Forwarder
|
||||
|
||||
+16
-16
@@ -472,31 +472,31 @@ Error Lowpan::CompressExtensionHeader(Message &aMessage, FrameBuilder &aFrameBui
|
||||
// Pad1 or PadN option MAY be elided by the compressor."
|
||||
if (aNextHeader == Ip6::kProtoHopOpts || aNextHeader == Ip6::kProtoDstOpts)
|
||||
{
|
||||
uint16_t offset = aMessage.GetOffset();
|
||||
Ip6::OptionHeader optionHeader;
|
||||
uint16_t offset = aMessage.GetOffset();
|
||||
Ip6::Option option;
|
||||
|
||||
while ((offset - aMessage.GetOffset()) < len)
|
||||
{
|
||||
SuccessOrExit(error = aMessage.Read(offset, optionHeader));
|
||||
SuccessOrExit(error = aMessage.Read(offset, option));
|
||||
|
||||
if (optionHeader.GetType() == Ip6::OptionPad1::kType)
|
||||
if (option.GetType() == Ip6::Pad1Option::kType)
|
||||
{
|
||||
offset += sizeof(Ip6::OptionPad1);
|
||||
offset += sizeof(Ip6::Pad1Option);
|
||||
}
|
||||
else
|
||||
{
|
||||
offset += optionHeader.GetSize();
|
||||
offset += option.GetSize();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the last option can be compressed.
|
||||
if (optionHeader.GetType() == Ip6::OptionPad1::kType)
|
||||
if (option.GetType() == Ip6::Pad1Option::kType)
|
||||
{
|
||||
padLength = sizeof(Ip6::OptionPad1);
|
||||
padLength = sizeof(Ip6::Pad1Option);
|
||||
}
|
||||
else if (optionHeader.GetType() == Ip6::OptionPadN::kType)
|
||||
else if (option.GetType() == Ip6::PadNOption::kType)
|
||||
{
|
||||
padLength = optionHeader.GetSize();
|
||||
padLength = option.GetSize();
|
||||
}
|
||||
|
||||
len -= padLength;
|
||||
@@ -888,17 +888,17 @@ Error Lowpan::DecompressExtensionHeader(Message &aMessage, FrameData &aFrameData
|
||||
{
|
||||
if (padLength == 1)
|
||||
{
|
||||
Ip6::OptionPad1 optionPad1;
|
||||
Ip6::Pad1Option pad1;
|
||||
|
||||
optionPad1.Init();
|
||||
SuccessOrExit(aMessage.AppendBytes(&optionPad1, padLength));
|
||||
pad1.Init();
|
||||
SuccessOrExit(aMessage.AppendBytes(&pad1, padLength));
|
||||
}
|
||||
else
|
||||
{
|
||||
Ip6::OptionPadN optionPadN;
|
||||
Ip6::PadNOption padn;
|
||||
|
||||
optionPadN.Init(padLength);
|
||||
SuccessOrExit(aMessage.AppendBytes(&optionPadN, padLength));
|
||||
padn.Init(padLength);
|
||||
SuccessOrExit(aMessage.AppendBytes(&padn, padLength));
|
||||
}
|
||||
|
||||
aMessage.MoveOffset(padLength);
|
||||
|
||||
Reference in New Issue
Block a user