diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index 4900d45c1..f85384f59 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -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)") diff --git a/include/openthread/instance.h b/include/openthread/instance.h index a87dd1b9d..56f938da3 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -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 diff --git a/include/openthread/mdns.h b/include/openthread/mdns.h index b3795367e..fddf9ee91 100644 --- a/include/openthread/mdns.h +++ b/include/openthread/mdns.h @@ -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); + /** * @} */ diff --git a/src/cli/cli_mdns.cpp b/src/cli/cli_mdns.cpp index 8f085eed8..d74f91db1 100644 --- a/src/cli/cli_mdns.cpp +++ b/src/cli/cli_mdns.cpp @@ -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(Arg aArgs[]) +{ + return ProcessEnableDisable(aArgs, otMdnsIsVerboseLoggingEnabled, otMdnsSetVerboseLoggingEnabled); +} +#endif + otError Mdns::Process(Arg aArgs[]) { #define CmdEntry(aCommandString) {aCommandString, &Mdns::Process} @@ -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 diff --git a/src/core/api/mdns_api.cpp b/src/core/api/mdns_api.cpp index 6a44b2826..1fc4b26b5 100644 --- a/src/core/api/mdns_api.cpp +++ b/src/core/api/mdns_api.cpp @@ -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().SetVerboseLoggingEnabled(aEnable); +} + +bool otMdnsIsVerboseLoggingEnabled(otInstance *aInstance) +{ + return AsCoreType(aInstance).Get().IsVerboseLoggingEnabled(); +} + +#endif + #endif // OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE && OPENTHREAD_CONFIG_MULTICAST_DNS_PUBLIC_API_ENABLE diff --git a/src/core/config/mdns.h b/src/core/config/mdns.h index 6e985e51c..61d82a685 100644 --- a/src/core/config/mdns.h +++ b/src/core/config/mdns.h @@ -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 * diff --git a/src/core/net/dns_types.hpp b/src/core/net/dns_types.hpp index 9c8b93d5a..0187f981c 100644 --- a/src/core/net/dns_types.hpp +++ b/src/core/net/dns_types.hpp @@ -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. diff --git a/src/core/net/mdns.cpp b/src/core/net/mdns.cpp index 07347aaba..a629d1111 100644 --- a/src/core/net/mdns.cpp +++ b/src/core/net/mdns.cpp @@ -44,6 +44,14 @@ namespace Multicast { RegisterLogModule("MulticastDns"); +#if OPENTHREAD_CONFIG_MULTICAST_DNS_VERBOSE_LOGGING_ENABLE +#define LogVerbose(...) \ + if (Get().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().mTxMessageHistory.Add(*mMsgPtr); + LogVerbose("Sending %s message len:%u", TypeToString(mType), mMsgPtr->GetLength()); + + if (!mUnicastDest.GetAddress().IsUnspecified()) + { + LogVerbose(" dst: %s", mUnicastDest.ToString().AsCString()); + } + + Get().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().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().LogMessage(*aMessagePtr); + } + offset = aMessagePtr->GetOffset(); SuccessOrExit(error = aMessagePtr->Read(offset, header)); @@ -4068,8 +4170,6 @@ Error Core::RxMessage::Init(Instance &aInstance, } } - mIsSelfOriginating = Get().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 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 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 diff --git a/src/core/net/mdns.hpp b/src/core/net/mdns.hpp index 5fe345bc3..7cf200d3b 100644 --- a/src/core/net/mdns.hpp +++ b/src/core/net/mdns.hpp @@ -150,6 +150,13 @@ public: class AddressInfo : public otPlatMdnsAddressInfo, public Clearable, public Equatable { 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 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 mMsgPtr; OwnedPtr 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 OwningList &GetEntryList(void); template @@ -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; using CacheTimer = TimerMilliIn; using EntryTask = TaskletIn; @@ -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`: diff --git a/tests/toranj/openthread-core-toranj-config-posix.h b/tests/toranj/openthread-core-toranj-config-posix.h index 48ad85f0e..e9ed1bdff 100644 --- a/tests/toranj/openthread-core-toranj-config-posix.h +++ b/tests/toranj/openthread-core-toranj-config-posix.h @@ -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 diff --git a/tests/toranj/openthread-core-toranj-config-simulation.h b/tests/toranj/openthread-core-toranj-config-simulation.h index 51358c3b3..fdac31723 100644 --- a/tests/toranj/openthread-core-toranj-config-simulation.h +++ b/tests/toranj/openthread-core-toranj-config-simulation.h @@ -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