mirror of
https://github.com/espressif/openthread.git
synced 2026-08-19 08:59:52 +00:00
[lowpan] avoid backward goto statement in Compress() (#4725)
This commit is contained in:
+22
-15
@@ -246,12 +246,29 @@ otError Lowpan::Compress(Message & aMessage,
|
||||
const Mac::Address &aMacSource,
|
||||
const Mac::Address &aMacDest,
|
||||
BufferWriter & aBuf)
|
||||
{
|
||||
otError error;
|
||||
uint8_t headerDepth = 0xff;
|
||||
|
||||
do
|
||||
{
|
||||
error = Compress(aMessage, aMacSource, aMacDest, aBuf, headerDepth);
|
||||
} while ((error != OT_ERROR_NONE) && (headerDepth > 0));
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Lowpan::Compress(Message & aMessage,
|
||||
const Mac::Address &aMacSource,
|
||||
const Mac::Address &aMacDest,
|
||||
BufferWriter & aBuf,
|
||||
uint8_t & aHeaderDepth)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
NetworkData::Leader &networkData = Get<NetworkData::Leader>();
|
||||
uint16_t startOffset = aMessage.GetOffset();
|
||||
BufferWriter buf = aBuf;
|
||||
uint16_t hcCtl;
|
||||
uint16_t hcCtl = kHcDispatch;
|
||||
Ip6::Header ip6Header;
|
||||
uint8_t * ip6HeaderBytes = reinterpret_cast<uint8_t *>(&ip6Header);
|
||||
Context srcContext, dstContext;
|
||||
@@ -259,13 +276,8 @@ otError Lowpan::Compress(Message & aMessage,
|
||||
uint8_t nextHeader;
|
||||
uint8_t ecn;
|
||||
uint8_t dscp;
|
||||
uint8_t headerDepth;
|
||||
uint8_t headerMaxDepth = 0xff;
|
||||
|
||||
compress:
|
||||
|
||||
headerDepth = 0;
|
||||
hcCtl = kHcDispatch;
|
||||
uint8_t headerDepth = 0;
|
||||
uint8_t headerMaxDepth = aHeaderDepth;
|
||||
|
||||
VerifyOrExit(aMessage.Read(aMessage.GetOffset(), sizeof(ip6Header), &ip6Header) == sizeof(ip6Header),
|
||||
error = OT_ERROR_PARSE);
|
||||
@@ -441,6 +453,8 @@ compress:
|
||||
}
|
||||
|
||||
exit:
|
||||
aHeaderDepth = headerDepth;
|
||||
|
||||
if (error == OT_ERROR_NONE)
|
||||
{
|
||||
IgnoreReturnValue(aBuf.Write(hcCtl >> 8));
|
||||
@@ -450,13 +464,6 @@ exit:
|
||||
else
|
||||
{
|
||||
aMessage.SetOffset(startOffset);
|
||||
|
||||
if (headerDepth > 0)
|
||||
{
|
||||
buf = aBuf;
|
||||
headerMaxDepth = headerDepth;
|
||||
goto compress;
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
|
||||
@@ -360,6 +360,12 @@ private:
|
||||
kUdpPortMask = 3 << 0,
|
||||
};
|
||||
|
||||
otError Compress(Message & aMessage,
|
||||
const Mac::Address &aMacSource,
|
||||
const Mac::Address &aMacDest,
|
||||
BufferWriter & aBuf,
|
||||
uint8_t & aHeaderDepth);
|
||||
|
||||
otError CompressExtensionHeader(Message &aMessage, BufferWriter &aBuf, uint8_t &aNextHeader);
|
||||
otError CompressSourceIid(const Mac::Address &aMacAddr,
|
||||
const Ip6::Address &aIpAddr,
|
||||
|
||||
Reference in New Issue
Block a user