mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 07:37:46 +00:00
[mesh-forwarder] limit mesh header message logging to FTD build (#2827)
This commit moves the methods related to logging mesh header messages in `mesh_forwarder_ftd.cpp` and limit their scope to FTD build. This helps reduce the code size of MTD build with logs enabled.
This commit is contained in:
committed by
Jonathan Hui
parent
8cc6848d67
commit
d99a2cea8f
@@ -1587,179 +1587,6 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
otError MeshForwarder::LogMeshFragmentHeader(MessageAction aAction,
|
||||
const Message & aMessage,
|
||||
const Mac::Address *aMacAddress,
|
||||
otError aError,
|
||||
uint16_t & aOffset,
|
||||
Mac::Address & aMeshSource,
|
||||
Mac::Address & aMeshDest)
|
||||
{
|
||||
otError error = OT_ERROR_FAILED;
|
||||
bool hasFragmentHeader = false;
|
||||
bool shouldLogRss;
|
||||
Lowpan::MeshHeader meshHeader;
|
||||
Lowpan::FragmentHeader fragmentHeader;
|
||||
|
||||
SuccessOrExit(meshHeader.Init(aMessage));
|
||||
VerifyOrExit(meshHeader.IsMeshHeader());
|
||||
|
||||
aMeshSource.SetShort(meshHeader.GetSource());
|
||||
aMeshDest.SetShort(meshHeader.GetDestination());
|
||||
|
||||
aOffset = meshHeader.GetHeaderLength();
|
||||
|
||||
if (fragmentHeader.Init(aMessage, aOffset) == OT_ERROR_NONE)
|
||||
{
|
||||
hasFragmentHeader = true;
|
||||
aOffset += fragmentHeader.GetHeaderLength();
|
||||
}
|
||||
|
||||
shouldLogRss = (aAction == kMessageReceive) || (aAction == kMessageReassemblyDrop);
|
||||
|
||||
otLogInfoMac(
|
||||
GetInstance(), "%s mesh frame, len:%d%s%s, msrc:%s, mdst:%s, hops:%d, frag:%s, sec:%s%s%s%s%s",
|
||||
MessageActionToString(aAction, aError), aMessage.GetLength(),
|
||||
(aMacAddress == NULL) ? "" : ((aAction == kMessageReceive) ? ", from:" : ", to:"),
|
||||
(aMacAddress == NULL) ? "" : aMacAddress->ToString().AsCString(), aMeshSource.ToString().AsCString(),
|
||||
aMeshDest.ToString().AsCString(), meshHeader.GetHopsLeft() + ((aAction == kMessageReceive) ? 1 : 0),
|
||||
hasFragmentHeader ? "yes" : "no", aMessage.IsLinkSecurityEnabled() ? "yes" : "no",
|
||||
(aError == OT_ERROR_NONE) ? "" : ", error:", (aError == OT_ERROR_NONE) ? "" : otThreadErrorToString(aError),
|
||||
shouldLogRss ? ", rss:" : "", shouldLogRss ? aMessage.GetRssAverager().ToString().AsCString() : "");
|
||||
|
||||
if (hasFragmentHeader)
|
||||
{
|
||||
otLogInfoMac(GetInstance(), "\tFrag tag:%04x, offset:%d, size:%d", fragmentHeader.GetDatagramTag(),
|
||||
fragmentHeader.GetDatagramOffset(), fragmentHeader.GetDatagramSize());
|
||||
|
||||
VerifyOrExit(fragmentHeader.GetDatagramOffset() == 0);
|
||||
}
|
||||
|
||||
error = OT_ERROR_NONE;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError MeshForwarder::DecompressIp6UdpTcpHeader(const Message & aMessage,
|
||||
uint16_t aOffset,
|
||||
const Mac::Address &aMeshSource,
|
||||
const Mac::Address &aMeshDest,
|
||||
Ip6::Header & aIp6Header,
|
||||
uint16_t & aChecksum,
|
||||
uint16_t & aSourcePort,
|
||||
uint16_t & aDestPort)
|
||||
{
|
||||
otError error = OT_ERROR_PARSE;
|
||||
Lowpan::Lowpan &lowpan = GetNetif().GetLowpan();
|
||||
int headerLength;
|
||||
bool nextHeaderCompressed;
|
||||
uint8_t frameBuffer[sizeof(Ip6::Header)];
|
||||
uint16_t frameLength;
|
||||
union
|
||||
{
|
||||
Ip6::UdpHeader udp;
|
||||
Ip6::TcpHeader tcp;
|
||||
} header;
|
||||
|
||||
aChecksum = 0;
|
||||
aSourcePort = 0;
|
||||
aDestPort = 0;
|
||||
|
||||
// Read and decompress the IPv6 header
|
||||
|
||||
frameLength = aMessage.Read(aOffset, sizeof(frameBuffer), frameBuffer);
|
||||
|
||||
headerLength =
|
||||
lowpan.DecompressBaseHeader(aIp6Header, nextHeaderCompressed, aMeshSource, aMeshDest, frameBuffer, frameLength);
|
||||
VerifyOrExit(headerLength >= 0);
|
||||
|
||||
aOffset += headerLength;
|
||||
|
||||
// Read and decompress UDP or TCP header
|
||||
|
||||
switch (aIp6Header.GetNextHeader())
|
||||
{
|
||||
case Ip6::kProtoUdp:
|
||||
if (nextHeaderCompressed)
|
||||
{
|
||||
frameLength = aMessage.Read(aOffset, sizeof(Ip6::UdpHeader), frameBuffer);
|
||||
headerLength = lowpan.DecompressUdpHeader(header.udp, frameBuffer, frameLength);
|
||||
VerifyOrExit(headerLength >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyOrExit(sizeof(Ip6::UdpHeader) == aMessage.Read(aOffset, sizeof(Ip6::UdpHeader), &header.udp));
|
||||
}
|
||||
|
||||
aChecksum = header.udp.GetChecksum();
|
||||
aSourcePort = header.udp.GetSourcePort();
|
||||
aDestPort = header.udp.GetDestinationPort();
|
||||
break;
|
||||
|
||||
case Ip6::kProtoTcp:
|
||||
VerifyOrExit(sizeof(Ip6::TcpHeader) == aMessage.Read(aOffset, sizeof(Ip6::TcpHeader), &header.tcp));
|
||||
aChecksum = header.tcp.GetChecksum();
|
||||
aSourcePort = header.tcp.GetSourcePort();
|
||||
aDestPort = header.tcp.GetDestinationPort();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
error = OT_ERROR_NONE;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void MeshForwarder::LogMeshIpHeader(const Message & aMessage,
|
||||
uint16_t aOffset,
|
||||
const Mac::Address &aMeshSource,
|
||||
const Mac::Address &aMeshDest)
|
||||
{
|
||||
uint16_t checksum;
|
||||
uint16_t sourcePort;
|
||||
uint16_t destPort;
|
||||
Ip6::Header ip6Header;
|
||||
|
||||
SuccessOrExit(DecompressIp6UdpTcpHeader(aMessage, aOffset, aMeshSource, aMeshDest, ip6Header, checksum, sourcePort,
|
||||
destPort));
|
||||
|
||||
otLogInfoMac(GetInstance(), "\tIPv6 %s msg, chksum:%04x, prio:%s",
|
||||
Ip6::Ip6::IpProtoToString(ip6Header.GetNextHeader()), checksum, MessagePriorityToString(aMessage));
|
||||
|
||||
LogIp6SourceDestAddresses(ip6Header, sourcePort, destPort);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void MeshForwarder::LogMeshMessage(MessageAction aAction,
|
||||
const Message & aMessage,
|
||||
const Mac::Address *aMacAddress,
|
||||
otError aError)
|
||||
{
|
||||
uint16_t offset;
|
||||
Mac::Address meshSource;
|
||||
Mac::Address meshDest;
|
||||
|
||||
SuccessOrExit(LogMeshFragmentHeader(aAction, aMessage, aMacAddress, aError, offset, meshSource, meshDest));
|
||||
|
||||
// When log action is `kMessageTransmit` we do not include
|
||||
// the IPv6 header info in the logs, as the same info is
|
||||
// logged when the same Mesh Header message was received
|
||||
// and info about it was logged.
|
||||
|
||||
VerifyOrExit(aAction != kMessageTransmit);
|
||||
|
||||
LogMeshIpHeader(aMessage, offset, meshSource, meshDest);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void MeshForwarder::LogMessage(MessageAction aAction,
|
||||
const Message & aMessage,
|
||||
const Mac::Address *aMacAddress,
|
||||
@@ -1771,9 +1598,11 @@ void MeshForwarder::LogMessage(MessageAction aAction,
|
||||
LogIp6Message(aAction, aMessage, aMacAddress, aError);
|
||||
break;
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
case Message::kType6lowpan:
|
||||
LogMeshMessage(aAction, aMessage, aMacAddress, aError);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -349,6 +349,7 @@ private:
|
||||
uint16_t & aChecksum,
|
||||
uint16_t & aSourcePort,
|
||||
uint16_t & aDestPort);
|
||||
#if OPENTHREAD_FTD
|
||||
otError DecompressIp6UdpTcpHeader(const Message & aMessage,
|
||||
uint16_t aOffset,
|
||||
const Mac::Address &aMeshSource,
|
||||
@@ -364,15 +365,15 @@ private:
|
||||
uint16_t & aOffset,
|
||||
Mac::Address & aMeshSource,
|
||||
Mac::Address & aMeshDest);
|
||||
|
||||
void LogIp6SourceDestAddresses(Ip6::Header &aIp6Header, uint16_t aSourcePort, uint16_t aDestPort);
|
||||
void LogMeshIpHeader(const Message & aMessage,
|
||||
uint16_t aOffset,
|
||||
const Mac::Address &aMeshSource,
|
||||
const Mac::Address &aMeshDest);
|
||||
void LogMeshIpHeader(const Message & aMessage,
|
||||
uint16_t aOffset,
|
||||
const Mac::Address &aMeshSource,
|
||||
const Mac::Address &aMeshDest);
|
||||
void LogMeshMessage(MessageAction aAction, const Message &aMessage, const Mac::Address *aAddress, otError aError);
|
||||
void LogIp6Message(MessageAction aAction, const Message &aMessage, const Mac::Address *aAddress, otError aError);
|
||||
#endif
|
||||
void LogIp6SourceDestAddresses(Ip6::Header &aIp6Header, uint16_t aSourcePort, uint16_t aDestPort);
|
||||
void LogIp6Message(MessageAction aAction, const Message &aMessage, const Mac::Address *aAddress, otError aError);
|
||||
#endif // #if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
|
||||
|
||||
Mac::Receiver mMacReceiver;
|
||||
Mac::Sender mMacSender;
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
|
||||
#include "common/logging.hpp"
|
||||
#include "common/owner-locator.hpp"
|
||||
#include "net/ip6.hpp"
|
||||
#include "net/tcp.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
@@ -1049,6 +1052,183 @@ exit:
|
||||
}
|
||||
#endif // OPENTHREAD_ENABLE_SERVICE
|
||||
|
||||
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
|
||||
|
||||
otError MeshForwarder::LogMeshFragmentHeader(MessageAction aAction,
|
||||
const Message & aMessage,
|
||||
const Mac::Address *aMacAddress,
|
||||
otError aError,
|
||||
uint16_t & aOffset,
|
||||
Mac::Address & aMeshSource,
|
||||
Mac::Address & aMeshDest)
|
||||
{
|
||||
otError error = OT_ERROR_FAILED;
|
||||
bool hasFragmentHeader = false;
|
||||
bool shouldLogRss;
|
||||
Lowpan::MeshHeader meshHeader;
|
||||
Lowpan::FragmentHeader fragmentHeader;
|
||||
|
||||
SuccessOrExit(meshHeader.Init(aMessage));
|
||||
VerifyOrExit(meshHeader.IsMeshHeader());
|
||||
|
||||
aMeshSource.SetShort(meshHeader.GetSource());
|
||||
aMeshDest.SetShort(meshHeader.GetDestination());
|
||||
|
||||
aOffset = meshHeader.GetHeaderLength();
|
||||
|
||||
if (fragmentHeader.Init(aMessage, aOffset) == OT_ERROR_NONE)
|
||||
{
|
||||
hasFragmentHeader = true;
|
||||
aOffset += fragmentHeader.GetHeaderLength();
|
||||
}
|
||||
|
||||
shouldLogRss = (aAction == kMessageReceive) || (aAction == kMessageReassemblyDrop);
|
||||
|
||||
otLogInfoMac(
|
||||
GetInstance(), "%s mesh frame, len:%d%s%s, msrc:%s, mdst:%s, hops:%d, frag:%s, sec:%s%s%s%s%s",
|
||||
MessageActionToString(aAction, aError), aMessage.GetLength(),
|
||||
(aMacAddress == NULL) ? "" : ((aAction == kMessageReceive) ? ", from:" : ", to:"),
|
||||
(aMacAddress == NULL) ? "" : aMacAddress->ToString().AsCString(), aMeshSource.ToString().AsCString(),
|
||||
aMeshDest.ToString().AsCString(), meshHeader.GetHopsLeft() + ((aAction == kMessageReceive) ? 1 : 0),
|
||||
hasFragmentHeader ? "yes" : "no", aMessage.IsLinkSecurityEnabled() ? "yes" : "no",
|
||||
(aError == OT_ERROR_NONE) ? "" : ", error:", (aError == OT_ERROR_NONE) ? "" : otThreadErrorToString(aError),
|
||||
shouldLogRss ? ", rss:" : "", shouldLogRss ? aMessage.GetRssAverager().ToString().AsCString() : "");
|
||||
|
||||
if (hasFragmentHeader)
|
||||
{
|
||||
otLogInfoMac(GetInstance(), "\tFrag tag:%04x, offset:%d, size:%d", fragmentHeader.GetDatagramTag(),
|
||||
fragmentHeader.GetDatagramOffset(), fragmentHeader.GetDatagramSize());
|
||||
|
||||
VerifyOrExit(fragmentHeader.GetDatagramOffset() == 0);
|
||||
}
|
||||
|
||||
error = OT_ERROR_NONE;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError MeshForwarder::DecompressIp6UdpTcpHeader(const Message & aMessage,
|
||||
uint16_t aOffset,
|
||||
const Mac::Address &aMeshSource,
|
||||
const Mac::Address &aMeshDest,
|
||||
Ip6::Header & aIp6Header,
|
||||
uint16_t & aChecksum,
|
||||
uint16_t & aSourcePort,
|
||||
uint16_t & aDestPort)
|
||||
{
|
||||
otError error = OT_ERROR_PARSE;
|
||||
Lowpan::Lowpan &lowpan = GetNetif().GetLowpan();
|
||||
int headerLength;
|
||||
bool nextHeaderCompressed;
|
||||
uint8_t frameBuffer[sizeof(Ip6::Header)];
|
||||
uint16_t frameLength;
|
||||
union
|
||||
{
|
||||
Ip6::UdpHeader udp;
|
||||
Ip6::TcpHeader tcp;
|
||||
} header;
|
||||
|
||||
aChecksum = 0;
|
||||
aSourcePort = 0;
|
||||
aDestPort = 0;
|
||||
|
||||
// Read and decompress the IPv6 header
|
||||
|
||||
frameLength = aMessage.Read(aOffset, sizeof(frameBuffer), frameBuffer);
|
||||
|
||||
headerLength =
|
||||
lowpan.DecompressBaseHeader(aIp6Header, nextHeaderCompressed, aMeshSource, aMeshDest, frameBuffer, frameLength);
|
||||
VerifyOrExit(headerLength >= 0);
|
||||
|
||||
aOffset += headerLength;
|
||||
|
||||
// Read and decompress UDP or TCP header
|
||||
|
||||
switch (aIp6Header.GetNextHeader())
|
||||
{
|
||||
case Ip6::kProtoUdp:
|
||||
if (nextHeaderCompressed)
|
||||
{
|
||||
frameLength = aMessage.Read(aOffset, sizeof(Ip6::UdpHeader), frameBuffer);
|
||||
headerLength = lowpan.DecompressUdpHeader(header.udp, frameBuffer, frameLength);
|
||||
VerifyOrExit(headerLength >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyOrExit(sizeof(Ip6::UdpHeader) == aMessage.Read(aOffset, sizeof(Ip6::UdpHeader), &header.udp));
|
||||
}
|
||||
|
||||
aChecksum = header.udp.GetChecksum();
|
||||
aSourcePort = header.udp.GetSourcePort();
|
||||
aDestPort = header.udp.GetDestinationPort();
|
||||
break;
|
||||
|
||||
case Ip6::kProtoTcp:
|
||||
VerifyOrExit(sizeof(Ip6::TcpHeader) == aMessage.Read(aOffset, sizeof(Ip6::TcpHeader), &header.tcp));
|
||||
aChecksum = header.tcp.GetChecksum();
|
||||
aSourcePort = header.tcp.GetSourcePort();
|
||||
aDestPort = header.tcp.GetDestinationPort();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
error = OT_ERROR_NONE;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void MeshForwarder::LogMeshIpHeader(const Message & aMessage,
|
||||
uint16_t aOffset,
|
||||
const Mac::Address &aMeshSource,
|
||||
const Mac::Address &aMeshDest)
|
||||
{
|
||||
uint16_t checksum;
|
||||
uint16_t sourcePort;
|
||||
uint16_t destPort;
|
||||
Ip6::Header ip6Header;
|
||||
|
||||
SuccessOrExit(DecompressIp6UdpTcpHeader(aMessage, aOffset, aMeshSource, aMeshDest, ip6Header, checksum, sourcePort,
|
||||
destPort));
|
||||
|
||||
otLogInfoMac(GetInstance(), "\tIPv6 %s msg, chksum:%04x, prio:%s",
|
||||
Ip6::Ip6::IpProtoToString(ip6Header.GetNextHeader()), checksum, MessagePriorityToString(aMessage));
|
||||
|
||||
LogIp6SourceDestAddresses(ip6Header, sourcePort, destPort);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void MeshForwarder::LogMeshMessage(MessageAction aAction,
|
||||
const Message & aMessage,
|
||||
const Mac::Address *aMacAddress,
|
||||
otError aError)
|
||||
{
|
||||
uint16_t offset;
|
||||
Mac::Address meshSource;
|
||||
Mac::Address meshDest;
|
||||
|
||||
SuccessOrExit(LogMeshFragmentHeader(aAction, aMessage, aMacAddress, aError, offset, meshSource, meshDest));
|
||||
|
||||
// When log action is `kMessageTransmit` we do not include
|
||||
// the IPv6 header info in the logs, as the same info is
|
||||
// logged when the same Mesh Header message was received
|
||||
// and info about it was logged.
|
||||
|
||||
VerifyOrExit(aAction != kMessageTransmit);
|
||||
|
||||
LogMeshIpHeader(aMessage, offset, meshSource, meshDest);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
#endif // #if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
|
||||
|
||||
} // namespace ot
|
||||
|
||||
#endif // OPENTHREAD_FTD
|
||||
|
||||
Reference in New Issue
Block a user