diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index bf5564144..8ad3f65d5 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -298,6 +298,7 @@ if(OT_FULL_LOGS) target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_BR=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_CLI=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_COAP=1") + target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_DNS=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_DUA=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_ICMP=1") target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_LOG_IP6=1") diff --git a/examples/common-switches.mk b/examples/common-switches.mk index b5f545487..2f041f90c 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -327,6 +327,7 @@ LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_BBR=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_BR=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_CLI=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_COAP=1 +LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_DNS=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_DUA=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_ICMP=1 LOG_FLAGS += -DOPENTHREAD_CONFIG_LOG_IP6=1 diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 22e887fdf..6c0ae8dff 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (61) +#define OPENTHREAD_API_VERSION (62) /** * @addtogroup api-instance diff --git a/include/openthread/platform/logging.h b/include/openthread/platform/logging.h index 48f0c8acc..bfa1eee51 100644 --- a/include/openthread/platform/logging.h +++ b/include/openthread/platform/logging.h @@ -139,6 +139,7 @@ typedef enum otLogRegion OT_LOG_REGION_DUA = 19, ///< Domain Unicast Address (available since Thread 1.2) OT_LOG_REGION_BR = 20, ///< Border Router OT_LOG_REGION_SRP = 21, ///< Service Registration Protocol (SRP) + OT_LOG_REGION_DNS = 22, ///< DNS } otLogRegion; /** diff --git a/src/core/BUILD.gn b/src/core/BUILD.gn index 0dc011bde..6890ab189 100644 --- a/src/core/BUILD.gn +++ b/src/core/BUILD.gn @@ -241,6 +241,7 @@ if (openthread_enable_core_config_args) { "OPENTHREAD_CONFIG_LOG_BR=1", "OPENTHREAD_CONFIG_LOG_CLI=1", "OPENTHREAD_CONFIG_LOG_COAP=1", + "OPENTHREAD_CONFIG_LOG_DNS=1", "OPENTHREAD_CONFIG_LOG_DUA=1", "OPENTHREAD_CONFIG_LOG_ICMP=1", "OPENTHREAD_CONFIG_LOG_IP6=1", diff --git a/src/core/common/logging.hpp b/src/core/common/logging.hpp index 5716a9f4e..c258d2acb 100644 --- a/src/core/common/logging.hpp +++ b/src/core/common/logging.hpp @@ -96,6 +96,7 @@ extern "C" { #define _OT_REGION_DUA_PREFIX "-DUA-----: " #define _OT_REGION_BR_PREFIX "-BR------: " #define _OT_REGION_SRP_PREFIX "-SRP-----: " +#define _OT_REGION_DNS_PREFIX "-DNS-----: " #else #define _OT_REGION_API_PREFIX _OT_REGION_SUFFIX #define _OT_REGION_MLE_PREFIX _OT_REGION_SUFFIX @@ -118,6 +119,7 @@ extern "C" { #define _OT_REGION_DUA_PREFIX _OT_REGION_SUFFIX #define _OT_REGION_BR_PREFIX _OT_REGION_SUFFIX #define _OT_REGION_SRP_PREFIX _OT_REGION_SUFFIX +#define _OT_REGION_DNS_PREFIX _OT_REGION_SUFFIX #endif /** @@ -1362,6 +1364,64 @@ void otLogCertMeshCoP(const char *aFormat, ...); #define otLogDebgSrp(...) #endif +/** + * @def otLogCritDns + * + * This function generates a log with level critical for the DNS region. + * + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogWarnDns + * + * This function generates a log with level warning for the DNS region. + * + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogNoteDns + * + * This function generates a log with level note for the DNS region. + * + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogInfoDns + * + * This function generates a log with level info for the DNS region. + * + * @param[in] ... Arguments for the format specification. + * + */ + +/** + * @def otLogDebgDns + * + * This function generates a log with level debug for the DNS region. + * + * @param[in] ... Arguments for the format specification. + * + */ +#if OPENTHREAD_CONFIG_LOG_DNS +#define otLogCritDns(...) otLogCrit(OT_LOG_REGION_DNS, _OT_REGION_DNS_PREFIX, __VA_ARGS__) +#define otLogWarnDns(...) otLogWarn(OT_LOG_REGION_DNS, _OT_REGION_DNS_PREFIX, __VA_ARGS__) +#define otLogNoteDns(...) otLogNote(OT_LOG_REGION_DNS, _OT_REGION_DNS_PREFIX, __VA_ARGS__) +#define otLogInfoDns(...) otLogInfo(OT_LOG_REGION_DNS, _OT_REGION_DNS_PREFIX, __VA_ARGS__) +#define otLogDebgDns(...) otLogDebg(OT_LOG_REGION_DNS, _OT_REGION_DNS_PREFIX, __VA_ARGS__) +#else +#define otLogCritDns(...) +#define otLogWarnDns(...) +#define otLogNoteDns(...) +#define otLogInfoDns(...) +#define otLogDebgDns(...) +#endif + /** * @def otLogCritPlat * @@ -2265,6 +2325,74 @@ void otLogOtns(const char *aFormat, ...); #define otDumpDebgSrp(aId, aBuf, aLength) #endif +/** + * @def otDumpCritDns + * + * This function generates a memory dump with log level critical and region DNS. + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ + +/** + * @def otDumpWarnDns + * + * This function generates a memory dump with log level warning and region DNS. + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ + +/** + * @def otDumpNoteDns + * + * This function generates a memory dump with log level note and region DNS. + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ + +/** + * @def otDumpInfoDns + * + * This function generates a memory dump with log level info and region DNS. + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ + +/** + * @def otDumpDebgDns + * + * This function generates a memory dump with log level debug and region DNS. + * + * @param[in] aId A pointer to a NULL-terminated string that is printed before the bytes. + * @param[in] aBuf A pointer to the buffer. + * @param[in] aLength Number of bytes to print. + * + */ +#if OPENTHREAD_CONFIG_LOG_SRP +#define otDumpCritDns(aId, aBuf, aLength) otDumpCrit(OT_LOG_REGION_SRP, aId, aBuf, aLength) +#define otDumpWarnDns(aId, aBuf, aLength) otDumpWarn(OT_LOG_REGION_SRP, aId, aBuf, aLength) +#define otDumpNoteDns(aId, aBuf, aLength) otDumpNote(OT_LOG_REGION_SRP, aId, aBuf, aLength) +#define otDumpInfoDns(aId, aBuf, aLength) otDumpInfo(OT_LOG_REGION_SRP, aId, aBuf, aLength) +#define otDumpDebgDns(aId, aBuf, aLength) otDumpDebg(OT_LOG_REGION_SRP, aId, aBuf, aLength) +#else +#define otDumpCritDns(aId, aBuf, aLength) +#define otDumpWarnDns(aId, aBuf, aLength) +#define otDumpNoteDns(aId, aBuf, aLength) +#define otDumpInfoDns(aId, aBuf, aLength) +#define otDumpDebgDns(aId, aBuf, aLength) +#endif + /** * @def otDumpCritMem * diff --git a/src/core/config/logging.h b/src/core/config/logging.h index 818426862..3ab709696 100644 --- a/src/core/config/logging.h +++ b/src/core/config/logging.h @@ -319,6 +319,16 @@ #define OPENTHREAD_CONFIG_LOG_SRP 1 #endif +/** + * @def OPENTHREAD_CONFIG_LOG_DNS + * + * Define to enable DNS region logging. + * + */ +#ifndef OPENTHREAD_CONFIG_LOG_DNS +#define OPENTHREAD_CONFIG_LOG_DNS 1 +#endif + /** * @def OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL * diff --git a/src/core/net/dns_client.cpp b/src/core/net/dns_client.cpp index ae2b6fad2..cddefc0df 100644 --- a/src/core/net/dns_client.cpp +++ b/src/core/net/dns_client.cpp @@ -198,7 +198,7 @@ exit: if (error != OT_ERROR_NONE) { FreeMessage(messageCopy); - otLogWarnIp6("Failed to send DNS request: %s", otThreadErrorToString(error)); + otLogWarnDns("Failed to send DNS request: %s", otThreadErrorToString(error)); } } diff --git a/src/lib/spinel/spinel.h b/src/lib/spinel/spinel.h index d156c9375..d7bf258bc 100644 --- a/src/lib/spinel/spinel.h +++ b/src/lib/spinel/spinel.h @@ -694,6 +694,7 @@ enum SPINEL_NCP_LOG_REGION_OT_DUA = 19, SPINEL_NCP_LOG_REGION_OT_BR = 20, SPINEL_NCP_LOG_REGION_OT_SRP = 21, + SPINEL_NCP_LOG_REGION_OT_DNS = 22, }; enum diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index d13c40c48..5908c6663 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -632,6 +632,10 @@ unsigned int NcpBase::ConvertLogRegion(otLogRegion aLogRegion) case OT_LOG_REGION_SRP: spinelLogRegion = SPINEL_NCP_LOG_REGION_OT_SRP; break; + + case OT_LOG_REGION_DNS: + spinelLogRegion = SPINEL_NCP_LOG_REGION_OT_DNS; + break; } return spinelLogRegion;