mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +00:00
[mdns] add verbose logging (#11793)
This commit introduces a verbose logging feature in the mDNS module to aid in development and debugging by providing detailed logs of mDNS traffic. The feature is enabled at build-time via the config option `OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE` (mapping to the `OT_MDNS_VERBOSE` CMake option). When enabled, logging can be controlled at run-time using the new `otMdnsSetVerboseLoggingEnabled()` API and the corresponding `mdns verboselogging` CLI command. The initial state on startup can be configured using `OPENTHREAD_CONFIG_MULTICAST_DNS_DEFAULT_VERBOSE_LOGGING_STATE` (mapping to the `OT_MDNS_VERBOSE_STATE` CMake option). When active, this feature logs the content of every sent and received mDNS message, including the header, questions, and all resource records. The logs are emitted at the `OT_LOG_LEVEL_NONE` level to ensure they are always captured, regardless of the active log level configuration.
This commit is contained in:
committed by
GitHub
parent
4fb1a5da74
commit
736808828d
@@ -222,6 +222,8 @@ ot_option(OT_LINK_RAW OPENTHREAD_CONFIG_LINK_RAW_ENABLE "link raw service")
|
||||
ot_option(OT_LOG_LEVEL_DYNAMIC OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE "dynamic log level control")
|
||||
ot_option(OT_MAC_FILTER OPENTHREAD_CONFIG_MAC_FILTER_ENABLE "mac filter")
|
||||
ot_option(OT_MDNS OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE "multicast DNS (mDNS)")
|
||||
ot_option(OT_MDNS_VERBOSE OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE "mDNS verbose logging")
|
||||
ot_option(OT_MDNS_VERBOSE_STATE OPENTHREAD_CONFIG_MULTICAST_DEFAULT_DNS_VERBOSE_LOGGING_STATE "mDNS verbose state on start")
|
||||
ot_option(OT_MESH_DIAG OPENTHREAD_CONFIG_MESH_DIAG_ENABLE "mesh diag")
|
||||
ot_option(OT_MESSAGE_USE_HEAP OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE "heap allocator for message buffers")
|
||||
ot_option(OT_MLE_LONG_ROUTES OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE "MLE long routes extension (experimental)")
|
||||
|
||||
@@ -52,7 +52,7 @@ extern "C" {
|
||||
*
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (524)
|
||||
#define OPENTHREAD_API_VERSION (525)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -1052,6 +1052,38 @@ otError otMdnsGetNextRecordQuerier(otInstance *aInstance,
|
||||
otMdnsRecordQuerier *aQuerier,
|
||||
otMdnsCacheInfo *aInfo);
|
||||
|
||||
/**
|
||||
* Enables or disables verbose logging for the mDNS module at run-time.
|
||||
*
|
||||
* Requires `OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE`.
|
||||
*
|
||||
* The initial state of verbose logging (enabled or disabled at startup) is determined by the configuration
|
||||
* `OPENTHREAD_CONFIG_MULTICAST_DEFAULT_DNS_VERBOSE_LOGGING_STATE`.
|
||||
*
|
||||
* When enabled, the mDNS module emits verbose logs for every sent or received mDNS message, including the header and
|
||||
* all question and resource records. These logs are generated regardless of the current log level configured on the
|
||||
* device.
|
||||
*
|
||||
* This feature can generate a large volume of logs, so its use is recommended only during development, integration,
|
||||
* or debugging.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aEnable TRUE to enable verbose logging, FALSE to disable.
|
||||
*/
|
||||
void otMdnsSetVerboseLoggingEnabled(otInstance *aInstance, bool aEnable);
|
||||
|
||||
/**
|
||||
* Indicates whether verbose logging is enabled for the mDNS module.
|
||||
*
|
||||
* Requires `OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE`.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
*
|
||||
* @retval TRUE If verbose logging is enabled.
|
||||
* @retval FALSE If verbose logging is disabled.
|
||||
*/
|
||||
bool otMdnsIsVerboseLoggingEnabled(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1255,6 +1255,13 @@ exit:
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_MULTICAST_DNS_ENTRY_ITERATION_API_ENABLE
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
template <> otError Mdns::Process<Cmd("verboselogging")>(Arg aArgs[])
|
||||
{
|
||||
return ProcessEnableDisable(aArgs, otMdnsIsVerboseLoggingEnabled, otMdnsSetVerboseLoggingEnabled);
|
||||
}
|
||||
#endif
|
||||
|
||||
otError Mdns::Process(Arg aArgs[])
|
||||
{
|
||||
#define CmdEntry(aCommandString) {aCommandString, &Mdns::Process<Cmd(aCommandString)>}
|
||||
@@ -1304,6 +1311,9 @@ otError Mdns::Process(Arg aArgs[])
|
||||
#endif
|
||||
CmdEntry("unicastquestion"),
|
||||
CmdEntry("unregister"),
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
CmdEntry("verboselogging"),
|
||||
#endif
|
||||
};
|
||||
|
||||
#undef CmdEntry
|
||||
|
||||
@@ -351,4 +351,18 @@ otError otMdnsGetNextRecordQuerier(otInstance *aInstance,
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_MULTICAST_DNS_ENTRY_ITERATION_API_ENABLE
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
|
||||
void otMdnsSetVerboseLoggingEnabled(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
AsCoreType(aInstance).Get<Dns::Multicast::Core>().SetVerboseLoggingEnabled(aEnable);
|
||||
}
|
||||
|
||||
bool otMdnsIsVerboseLoggingEnabled(otInstance *aInstance)
|
||||
{
|
||||
return AsCoreType(aInstance).Get<Dns::Multicast::Core>().IsVerboseLoggingEnabled();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE && OPENTHREAD_CONFIG_MULTICAST_DNS_PUBLIC_API_ENABLE
|
||||
|
||||
@@ -95,6 +95,32 @@
|
||||
#define OPENTHREAD_CONFIG_MULTICAST_DNS_DEFAULT_QUESTION_UNICAST_ALLOWED 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
*
|
||||
* Define as 1 to enable the multicast DNS (mDNS) verbose logging feature at build-time.
|
||||
*
|
||||
* When this feature is enabled, verbose logging can be dynamically turned on or off at run-time using
|
||||
* `otMdnsSetVerboseLoggingEnabled()`.
|
||||
*
|
||||
* When disabled, the verbose logging code is not included in the build, which reduces code size.
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
#define OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MULTICAST_DEFAULT_DNS_VERBOSE_LOGGING_STATE
|
||||
*
|
||||
* Defines the default run-time state of mDNS verbose logging (turned on/off) on startup.
|
||||
*
|
||||
* This applies only when `OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE` is enabled. Set to 1 to turn on
|
||||
* verbose logging by default on startup, or 0 to turn it off.
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MULTICAST_DEFAULT_DNS_VERBOSE_LOGGING_STATE
|
||||
#define OPENTHREAD_CONFIG_MULTICAST_DEFAULT_DNS_VERBOSE_LOGGING_STATE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MULTICAST_DNS_MOCK_PLAT_APIS_ENABLE
|
||||
*
|
||||
|
||||
@@ -2845,7 +2845,7 @@ public:
|
||||
*
|
||||
* @returns The Bitmap length
|
||||
*/
|
||||
uint8_t GetBitmapLength(void) { return mBitmapLength; }
|
||||
uint8_t GetBitmapLength(void) const { return mBitmapLength; }
|
||||
|
||||
/**
|
||||
* Gets the total size (number of bytes) of the `TypeBitMap` field.
|
||||
|
||||
+329
-2
@@ -44,6 +44,14 @@ namespace Multicast {
|
||||
|
||||
RegisterLogModule("MulticastDns");
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
#define LogVerbose(...) \
|
||||
if (Get<Core>().mVerboseLogging) \
|
||||
LogAt(kLogLevelNone, __VA_ARGS__)
|
||||
#else
|
||||
#define LogVerbose(...)
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// otPlatMdns callbacks
|
||||
|
||||
@@ -94,6 +102,9 @@ Core::Core(Instance &aInstance)
|
||||
, mNextQueryTxTime(TimerMilli::GetNow() - 1)
|
||||
, mCacheTimer(aInstance)
|
||||
, mCacheTask(aInstance)
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
, mVerboseLogging(kDefaultVerboseLog)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
@@ -529,6 +540,51 @@ bool Core::RrClassIsInternetOrAny(uint16_t aRrClass)
|
||||
return (aRrClass == ResourceRecord::kClassInternet) || (aRrClass == ResourceRecord::kClassAny);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
|
||||
void Core::SetVerboseLoggingEnabled(bool aEnable)
|
||||
{
|
||||
VerifyOrExit(mVerboseLogging != aEnable);
|
||||
|
||||
if (aEnable)
|
||||
{
|
||||
mVerboseLogging = true;
|
||||
LogVerbose("Verbose logging enabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogVerbose("Verbose logging disabled");
|
||||
mVerboseLogging = false;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Core::LogMessage(const Message &aMessage)
|
||||
{
|
||||
if (mVerboseLogging)
|
||||
{
|
||||
MsgLogger logger(GetInstance(), aMessage);
|
||||
|
||||
logger.Log();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// Core::AddressInfo
|
||||
|
||||
Core::AddressInfo::InfoString Core::AddressInfo::ToString(void) const
|
||||
{
|
||||
InfoString string;
|
||||
|
||||
string.Append("[%s]:%u if-index:%lu", GetAddress().ToString().AsCString(), mPort, ToUlong(mInfraIfIndex));
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// Core::Callback
|
||||
|
||||
@@ -3460,6 +3516,7 @@ Core::TxMessage::TxMessage(Instance &aInstance, Type aType, uint16_t aQueryId)
|
||||
: InstanceLocator(aInstance)
|
||||
{
|
||||
Init(aType, aQueryId);
|
||||
mUnicastDest.Clear();
|
||||
}
|
||||
|
||||
Core::TxMessage::TxMessage(Instance &aInstance, Type aType, const AddressInfo &aUnicastDest, uint16_t aQueryId)
|
||||
@@ -3812,6 +3869,15 @@ void Core::TxMessage::Send(void)
|
||||
|
||||
Get<Core>().mTxMessageHistory.Add(*mMsgPtr);
|
||||
|
||||
LogVerbose("Sending %s message len:%u", TypeToString(mType), mMsgPtr->GetLength());
|
||||
|
||||
if (!mUnicastDest.GetAddress().IsUnspecified())
|
||||
{
|
||||
LogVerbose(" dst: %s", mUnicastDest.ToString().AsCString());
|
||||
}
|
||||
|
||||
Get<Core>().LogMessage(*mMsgPtr);
|
||||
|
||||
// We pass ownership of message to the platform layer.
|
||||
|
||||
switch (mType)
|
||||
@@ -3926,6 +3992,29 @@ bool Core::TxMessage::ShouldClearAppendStateOnReinit(const Entry &aEntry) const
|
||||
return shouldClear;
|
||||
}
|
||||
|
||||
const char *Core::TxMessage::TypeToString(Type aType)
|
||||
{
|
||||
static const char *const kTypeStrings[] = {
|
||||
"multicast probe", // kMulticastProbe
|
||||
"multicast query", // kMulticastQuery
|
||||
"multicast response", // kMulticastResponse
|
||||
"unicast response", // kUnicastResponse
|
||||
"legacy-unicast response", // kLegacyUnicastResponse
|
||||
};
|
||||
|
||||
struct EnumCheck
|
||||
{
|
||||
InitEnumValidatorCounter();
|
||||
ValidateNextEnum(kMulticastProbe);
|
||||
ValidateNextEnum(kMulticastQuery);
|
||||
ValidateNextEnum(kMulticastResponse);
|
||||
ValidateNextEnum(kUnicastResponse);
|
||||
ValidateNextEnum(kLegacyUnicastResponse);
|
||||
};
|
||||
|
||||
return kTypeStrings[aType];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// Core::EntryContext
|
||||
|
||||
@@ -3968,6 +4057,19 @@ Error Core::RxMessage::Init(Instance &aInstance,
|
||||
|
||||
VerifyOrExit(!aMessagePtr.IsNull(), error = kErrorInvalidArgs);
|
||||
|
||||
mIsSelfOriginating = Get<Core>().mTxMessageHistory.Contains(*aMessagePtr);
|
||||
|
||||
if (mIsSelfOriginating)
|
||||
{
|
||||
LogVerbose("Received message len:%u (self-originated)", aMessagePtr->GetLength());
|
||||
}
|
||||
else
|
||||
{
|
||||
LogVerbose("Received message len:%u", aMessagePtr->GetLength());
|
||||
LogVerbose(" sender:%s", mSenderAddress.ToString().AsCString());
|
||||
Get<Core>().LogMessage(*aMessagePtr);
|
||||
}
|
||||
|
||||
offset = aMessagePtr->GetOffset();
|
||||
|
||||
SuccessOrExit(error = aMessagePtr->Read(offset, header));
|
||||
@@ -4068,8 +4170,6 @@ Error Core::RxMessage::Init(Instance &aInstance,
|
||||
}
|
||||
}
|
||||
|
||||
mIsSelfOriginating = Get<Core>().mTxMessageHistory.Contains(*aMessagePtr);
|
||||
|
||||
mMessagePtr = aMessagePtr.PassOwnership();
|
||||
|
||||
exit:
|
||||
@@ -7673,6 +7773,233 @@ exit:
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_MULTICAST_DNS_ENTRY_ITERATION_API_ENABLE
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// Core::MsgLogger
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
|
||||
Core::MsgLogger::MsgLogger(Instance &aInstance, const Message &aMessage)
|
||||
: InstanceLocator(aInstance)
|
||||
, mMessage(aMessage)
|
||||
{
|
||||
}
|
||||
|
||||
void Core::MsgLogger::Log(void)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
mOffset = mMessage.GetOffset();
|
||||
|
||||
SuccessOrExit(error = mMessage.Read(mOffset, mHeader));
|
||||
mOffset += sizeof(Header);
|
||||
|
||||
LogVerbose("- %s id:%u qt:%u t:%u rcode:%u [q:%u ans:%u auth:%u addn:%u]",
|
||||
mHeader.GetType() == Header::kTypeQuery ? "Query" : "Response", mHeader.GetMessageId(),
|
||||
mHeader.GetQueryType(), mHeader.IsTruncationFlagSet(), mHeader.GetResponseCode(),
|
||||
mHeader.GetQuestionCount(), mHeader.GetAnswerCount(), mHeader.GetAuthorityRecordCount(),
|
||||
mHeader.GetAdditionalRecordCount());
|
||||
|
||||
SuccessOrExit(LogQuestions());
|
||||
SuccessOrExit(error = LogSectionRecords("Answer", mHeader.GetAnswerCount()));
|
||||
SuccessOrExit(error = LogSectionRecords("Authority", mHeader.GetAuthorityRecordCount()));
|
||||
SuccessOrExit(error = LogSectionRecords("Additional", mHeader.GetAdditionalRecordCount()));
|
||||
|
||||
exit:
|
||||
if (error != kErrorNone)
|
||||
{
|
||||
LogVerbose("Failed to parse message, error:%s", ErrorToString(error));
|
||||
}
|
||||
}
|
||||
|
||||
Error Core::MsgLogger::LogQuestions(void)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
uint16_t questionCount = mHeader.GetQuestionCount();
|
||||
|
||||
VerifyOrExit(questionCount > 0);
|
||||
|
||||
LogVerbose("- Question");
|
||||
|
||||
for (; questionCount > 0; questionCount--)
|
||||
{
|
||||
Question question;
|
||||
Name::Buffer name;
|
||||
|
||||
SuccessOrExit(error = Name::ReadName(mMessage, mOffset, name));
|
||||
SuccessOrExit(error = mMessage.Read(mOffset, question));
|
||||
mOffset += sizeof(Question);
|
||||
|
||||
LogVerbose(" %s", name);
|
||||
LogVerbose(" %s %s class:%u", ResourceRecord::TypeToString(question.GetType()).AsCString(),
|
||||
question.GetClass() & kClassQuestionUnicastFlag ? "QU" : "QM", question.GetClass() & kClassMask);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Core::MsgLogger::LogSectionRecords(const char *aSectionName, uint16_t aNumRecords)
|
||||
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
VerifyOrExit(aNumRecords > 0);
|
||||
|
||||
LogVerbose("- %s", aSectionName);
|
||||
|
||||
for (; aNumRecords > 0; aNumRecords--)
|
||||
{
|
||||
SuccessOrExit(error = LogRecord());
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Core::MsgLogger::LogRecord(void)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
ResourceRecord record;
|
||||
Name::Buffer name;
|
||||
|
||||
SuccessOrExit(error = Name::ReadName(mMessage, mOffset, name));
|
||||
SuccessOrExit(error = mMessage.Read(mOffset, record));
|
||||
mOffset += sizeof(ResourceRecord);
|
||||
|
||||
LogVerbose(" %s%s cls:%u ttl:%lu data-len:%u", ResourceRecord::TypeToString(record.GetType()).AsCString(),
|
||||
record.GetClass() & kClassCacheFlushFlag ? " cache-flush" : "", record.GetClass() & kClassMask,
|
||||
ToUlong(record.GetTtl()), record.GetLength());
|
||||
LogVerbose(" %s", name);
|
||||
|
||||
LogRecordData(record);
|
||||
|
||||
mOffset += record.GetLength();
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Core::MsgLogger::LogRecordData(const ResourceRecord &aRecord)
|
||||
{
|
||||
uint16_t offset = mOffset;
|
||||
Name::Buffer name;
|
||||
Ip4::Address ip4Address;
|
||||
Ip6::Address ip6Address;
|
||||
SrvRecord srvRecord;
|
||||
NsecRecord::TypeBitMap bitMap;
|
||||
|
||||
switch (aRecord.GetType())
|
||||
{
|
||||
case ResourceRecord::kTypeA:
|
||||
VerifyOrExit(aRecord.GetLength() >= sizeof(Ip4::Address));
|
||||
SuccessOrExit(mMessage.Read(offset, ip4Address));
|
||||
LogVerbose(" %s", ip4Address.ToString().AsCString());
|
||||
break;
|
||||
case ResourceRecord::kTypeAaaa:
|
||||
VerifyOrExit(aRecord.GetLength() >= sizeof(Ip6::Address));
|
||||
SuccessOrExit(mMessage.Read(offset, ip6Address));
|
||||
LogVerbose(" %s", ip6Address.ToString().AsCString());
|
||||
break;
|
||||
|
||||
case ResourceRecord::kTypePtr:
|
||||
SuccessOrExit(Name::ReadName(mMessage, offset, name));
|
||||
LogVerbose(" %s", name);
|
||||
break;
|
||||
|
||||
case ResourceRecord::kTypeSrv:
|
||||
offset -= sizeof(ResourceRecord);
|
||||
SuccessOrExit(mMessage.Read(offset, srvRecord));
|
||||
offset += sizeof(srvRecord);
|
||||
SuccessOrExit(Name::ReadName(mMessage, offset, name));
|
||||
LogVerbose(" port:%u w:%u prio:%u", srvRecord.GetPort(), srvRecord.GetWeight(), srvRecord.GetPriority());
|
||||
LogVerbose(" host:%s", name);
|
||||
break;
|
||||
|
||||
case ResourceRecord::kTypeNsec:
|
||||
SuccessOrExit(Name::ReadName(mMessage, offset, name));
|
||||
LogVerbose(" domain-name:%s", name);
|
||||
SuccessOrExit(mMessage.Read(offset, &bitMap, NsecRecord::TypeBitMap::kMinSize));
|
||||
VerifyOrExit(bitMap.GetBlockNumber() == 0);
|
||||
VerifyOrExit(bitMap.GetBitmapLength() <= NsecRecord::TypeBitMap::kMaxLength);
|
||||
SuccessOrExit(mMessage.Read(offset, &bitMap, bitMap.GetSize()));
|
||||
LogNsecBitMap(bitMap);
|
||||
break;
|
||||
|
||||
case ResourceRecord::kTypeKey:
|
||||
case ResourceRecord::kTypeTxt:
|
||||
default:
|
||||
LogRawData(aRecord.GetLength());
|
||||
break;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Core::MsgLogger::LogRawData(uint16_t aLength)
|
||||
{
|
||||
static constexpr uint16_t kStringSize = 200;
|
||||
static constexpr uint16_t kDataSize = 32;
|
||||
|
||||
uint16_t offset = mOffset;
|
||||
bool isFirstLine = true;
|
||||
|
||||
while (aLength > 0)
|
||||
{
|
||||
uint16_t readLength = Min(aLength, kDataSize);
|
||||
uint8_t data[kDataSize];
|
||||
String<kStringSize> string;
|
||||
|
||||
if (isFirstLine)
|
||||
{
|
||||
string.Append("[ ");
|
||||
isFirstLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
string.Append(" ");
|
||||
}
|
||||
|
||||
SuccessOrExit(mMessage.Read(offset, data, readLength));
|
||||
string.AppendHexBytes(data, readLength);
|
||||
|
||||
offset += readLength;
|
||||
aLength -= readLength;
|
||||
|
||||
if (aLength == 0)
|
||||
{
|
||||
string.Append(" ]");
|
||||
}
|
||||
|
||||
LogVerbose(" %s", string.AsCString());
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Core::MsgLogger::LogNsecBitMap(const NsecRecord::TypeBitMap &aBitMap)
|
||||
{
|
||||
static constexpr uint16_t kStringSize = 200;
|
||||
|
||||
String<kStringSize> string;
|
||||
|
||||
string.Append("[ ");
|
||||
|
||||
for (uint16_t type = 0; type < aBitMap.GetBitmapLength() * kBitsPerByte; type++)
|
||||
{
|
||||
if (aBitMap.ContainsType(type))
|
||||
{
|
||||
string.Append("%s ", ResourceRecord::TypeToString(type).AsCString());
|
||||
}
|
||||
}
|
||||
|
||||
string.Append("]");
|
||||
|
||||
LogVerbose(" %s", string.AsCString());
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
|
||||
} // namespace Multicast
|
||||
} // namespace Dns
|
||||
} // namespace ot
|
||||
|
||||
@@ -150,6 +150,13 @@ public:
|
||||
class AddressInfo : public otPlatMdnsAddressInfo, public Clearable<AddressInfo>, public Equatable<AddressInfo>
|
||||
{
|
||||
public:
|
||||
static constexpr uint16_t kInfoStringSize = 100; ///< Max chars for the info string (`ToString()`).
|
||||
|
||||
/**
|
||||
* Defines the fixed-length `String` object returned from `ToString()`.
|
||||
*/
|
||||
typedef String<kInfoStringSize> InfoString;
|
||||
|
||||
/**
|
||||
* Initializes the `AddressInfo` clearing all the fields.
|
||||
*/
|
||||
@@ -161,6 +168,13 @@ public:
|
||||
* @returns the IPv6 address.
|
||||
*/
|
||||
const Ip6::Address &GetAddress(void) const { return AsCoreType(&mAddress); }
|
||||
|
||||
/**
|
||||
* Converts the `AddressInfo` to human-readable string.
|
||||
*
|
||||
* @return A string representation of the `AddressInfo`
|
||||
*/
|
||||
InfoString ToString(void) const;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -840,6 +854,23 @@ public:
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_MULTICAST_DNS_ENTRY_ITERATION_API_ENABLE
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
/**
|
||||
* Enables or disables verbose logging.
|
||||
*
|
||||
* @param[in] aEnable TRUE to enable verbose logging, FALSE to disable.
|
||||
*/
|
||||
void SetVerboseLoggingEnabled(bool aEnable);
|
||||
|
||||
/**
|
||||
* Indicates whether verbose logging is enabled.
|
||||
*
|
||||
* @retval TRUE If verbose logging is enabled.
|
||||
* @retval FALSE If verbose logging is disabled.
|
||||
*/
|
||||
bool IsVerboseLoggingEnabled(void) const { return mVerboseLogging; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
@@ -847,6 +878,7 @@ private:
|
||||
|
||||
static constexpr bool kDefaultAutoEnable = OPENTHREAD_CONFIG_MULTICAST_DNS_AUTO_ENABLE_ON_INFRA_IF;
|
||||
static constexpr bool kDefaultQuAllowed = OPENTHREAD_CONFIG_MULTICAST_DNS_DEFAULT_QUESTION_UNICAST_ALLOWED;
|
||||
static constexpr bool kDefaultVerboseLog = OPENTHREAD_CONFIG_MULTICAST_DEFAULT_DNS_VERBOSE_LOGGING_STATE;
|
||||
|
||||
static constexpr uint32_t kMaxMessageSize = 1200;
|
||||
|
||||
@@ -1480,6 +1512,8 @@ private:
|
||||
|
||||
static void SaveOffset(uint16_t &aCompressOffset, const Message &aMessage, Section aSection);
|
||||
|
||||
static const char *TypeToString(Type aType);
|
||||
|
||||
RecordCounts mRecordCounts;
|
||||
OwnedPtr<Message> mMsgPtr;
|
||||
OwnedPtr<Message> mExtraMsgPtr;
|
||||
@@ -2253,6 +2287,29 @@ private:
|
||||
#endif // OPENTHREAD_CONFIG_MULTICAST_DNS_ENTRY_ITERATION_API_ENABLE
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
class MsgLogger : InstanceLocator
|
||||
{
|
||||
public:
|
||||
MsgLogger(Instance &aInstance, const Message &aMessage);
|
||||
|
||||
void Log(void);
|
||||
|
||||
private:
|
||||
Error LogQuestions(void);
|
||||
Error LogSectionRecords(const char *aSectionName, uint16_t aNumRecords);
|
||||
Error LogRecord(void);
|
||||
void LogRecordData(const ResourceRecord &aRecord);
|
||||
void LogRawData(uint16_t aLength);
|
||||
void LogNsecBitMap(const NsecRecord::TypeBitMap &aBitMap);
|
||||
|
||||
const Message &mMessage;
|
||||
uint16_t mOffset;
|
||||
Header mHeader;
|
||||
};
|
||||
#endif // OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
template <typename EntryType> OwningList<EntryType> &GetEntryList(void);
|
||||
template <typename EntryType, typename ItemInfo>
|
||||
@@ -2293,6 +2350,12 @@ private:
|
||||
static bool QuestionMatches(uint16_t aQuestionRrType, uint16_t aRrType);
|
||||
static bool RrClassIsInternetOrAny(uint16_t aRrClass);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
void LogMessage(const Message &aMessage);
|
||||
#else
|
||||
void LogMessage(const Message &) {}
|
||||
#endif
|
||||
|
||||
using EntryTimer = TimerMilliIn<Core, &Core::HandleEntryTimer>;
|
||||
using CacheTimer = TimerMilliIn<Core, &Core::HandleCacheTimer>;
|
||||
using EntryTask = TaskletIn<Core, &Core::HandleEntryTask>;
|
||||
@@ -2329,6 +2392,9 @@ private:
|
||||
TimeMilli mNextQueryTxTime;
|
||||
CacheTimer mCacheTimer;
|
||||
CacheTask mCacheTask;
|
||||
#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE
|
||||
bool mVerboseLogging;
|
||||
#endif
|
||||
};
|
||||
|
||||
// Specializations of `Core::GetEntryList()` for `HostEntry` and `ServiceEntry`:
|
||||
|
||||
@@ -42,6 +42,10 @@
|
||||
|
||||
#define OPENTHREAD_CONFIG_MULTICAST_DNS_PUBLIC_API_ENABLE 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE 0
|
||||
|
||||
#define OPENTHREAD_CONFIG_MULTICAST_DEFAULT_DNS_VERBOSE_LOGGING_STATE 0
|
||||
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE 0
|
||||
|
||||
#define OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE 1
|
||||
|
||||
@@ -61,6 +61,10 @@
|
||||
|
||||
#define OPENTHREAD_CONFIG_MULTICAST_DNS_AUTO_ENABLE_ON_INFRA_IF 0
|
||||
|
||||
#define OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_MULTICAST_DEFAULT_DNS_VERBOSE_LOGGING_STATE 0
|
||||
|
||||
#define OPENTHREAD_SIMULATION_MDNS_SOCKET_IMPLEMENT_POSIX 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 0
|
||||
|
||||
Reference in New Issue
Block a user