From 60b44c47906302ea50fb1c0692828eaf50f5b50e Mon Sep 17 00:00:00 2001 From: Kevin Schoedel <67607049+kpschoedel@users.noreply.github.com> Date: Wed, 20 Oct 2021 17:23:35 -0400 Subject: [PATCH] Remove Inet DNSResolver (#10725) * Remove DNSResolver #### Problem `DNSResolver` is unused. #### Change overview Remove it. #### Testing CI. * restyle --- config/ameba/args.gni | 1 - config/esp32/args.gni | 1 - config/mbed/chip-gn/args.gni | 1 - config/nrfconnect/chip-module/CMakeLists.txt | 1 - config/qpg/chip-gn/args.gni | 1 - config/standalone/args.gni | 1 - config/telink/chip-module/CMakeLists.txt | 1 - config/tizen/chip-gn/args.gni | 1 - src/inet/BUILD.gn | 8 - src/inet/DNSResolver.cpp | 468 ------------ src/inet/DNSResolver.h | 179 ----- src/inet/Inet.h | 4 - src/inet/InetConfig.h | 38 - src/inet/InetLayer.cpp | 273 ------- src/inet/InetLayer.h | 22 - src/inet/inet.gni | 3 - src/inet/tests/BUILD.gn | 2 - src/inet/tests/TestInetCommonPosix.cpp | 21 - src/inet/tests/TestInetEndPoint.cpp | 71 -- src/inet/tests/TestInetLayerDNS.cpp | 753 ------------------- src/lib/core/CHIPConfig.h | 10 - src/platform/Ameba/args.gni | 1 - src/platform/EFR32/args.gni | 1 - src/platform/P6/args.gni | 2 - src/platform/cc13x2_26x2/args.gni | 1 - src/platform/nxp/k32w/k32w0/args.gni | 1 - src/platform/qpg/args.gni | 1 - src/system/SystemLayerImplSelect.h | 3 +- src/system/SystemStats.cpp | 6 +- src/system/SystemStats.h | 3 - 30 files changed, 2 insertions(+), 1877 deletions(-) delete mode 100644 src/inet/DNSResolver.cpp delete mode 100644 src/inet/DNSResolver.h delete mode 100644 src/inet/tests/TestInetLayerDNS.cpp diff --git a/config/ameba/args.gni b/config/ameba/args.gni index 0019b1483f909d..772c7a01a3582e 100755 --- a/config/ameba/args.gni +++ b/config/ameba/args.gni @@ -25,7 +25,6 @@ mbedtls_target = "//mbedtls:mbedtls" lwip_platform = "external" chip_build_tests = true -chip_inet_config_enable_dns_resolver = false chip_inet_config_enable_tcp_endpoint = true chip_inet_config_enable_udp_endpoint = true diff --git a/config/esp32/args.gni b/config/esp32/args.gni index 5b4a5ef1457aba..0d3946b3289aff 100644 --- a/config/esp32/args.gni +++ b/config/esp32/args.gni @@ -25,7 +25,6 @@ mbedtls_target = "//mbedtls:mbedtls" lwip_platform = "external" chip_build_tests = true -chip_inet_config_enable_dns_resolver = false #Enabling this causes some error #chip_inet_config_enable_tun_endpoint = false diff --git a/config/mbed/chip-gn/args.gni b/config/mbed/chip-gn/args.gni index 91ecf2aa53cceb..5990bef354bd10 100644 --- a/config/mbed/chip-gn/args.gni +++ b/config/mbed/chip-gn/args.gni @@ -22,7 +22,6 @@ chip_device_project_config_include = "" chip_inet_config_enable_udp_endpoint = true chip_inet_config_enable_tcp_endpoint = true -chip_inet_config_enable_dns_resolver = true chip_custom_build_cflags = [] diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt index 87a54154e22c1d..89ceeef75930b7 100644 --- a/config/nrfconnect/chip-module/CMakeLists.txt +++ b/config/nrfconnect/chip-module/CMakeLists.txt @@ -199,7 +199,6 @@ chip_gn_arg_bool ("chip_enable_nfc" CONFIG_CHIP_NFC_COMM chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS) chip_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TESTS) chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) -chip_gn_arg_bool ("chip_inet_config_enable_dns_resolver" CONFIG_CHIP_BUILD_TESTS) chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL) chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC) diff --git a/config/qpg/chip-gn/args.gni b/config/qpg/chip-gn/args.gni index e059f665545a4d..3290ad55f4f098 100644 --- a/config/qpg/chip-gn/args.gni +++ b/config/qpg/chip-gn/args.gni @@ -26,7 +26,6 @@ chip_enable_nfc = false chip_build_tests = false chip_monolithic_tests = false chip_inet_config_enable_tcp_endpoint = false -chip_inet_config_enable_dns_resolver = false chip_build_libshell = false qpg_ar = "arm-none-eabi-ar" qpg_cc = "arm-none-eabi-gcc" diff --git a/config/standalone/args.gni b/config/standalone/args.gni index 40caf42ee37b50..426c9c8cd8a4c4 100644 --- a/config/standalone/args.gni +++ b/config/standalone/args.gni @@ -15,4 +15,3 @@ # Options from standalone-chip.mk that differ from configure defaults. These # options are used from examples/. chip_build_tests = false -chip_inet_config_enable_dns_resolver = false diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 9afb00b6269e83..1e7c32e137c359 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -197,7 +197,6 @@ chip_gn_arg_bool ("chip_enable_openthread" CONFIG_NET_L2_OPENTH chip_gn_arg_bool ("chip_inet_config_enable_ipv4" CONFIG_NET_IPV4) chip_gn_arg_bool ("chip_build_tests" CONFIG_CHIP_BUILD_TESTS) chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) -chip_gn_arg_bool ("chip_inet_config_enable_dns_resolver" CONFIG_CHIP_BUILD_TESTS) chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL) chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC) diff --git a/config/tizen/chip-gn/args.gni b/config/tizen/chip-gn/args.gni index b344bf8ff37db7..dc94bef5509fcb 100644 --- a/config/tizen/chip-gn/args.gni +++ b/config/tizen/chip-gn/args.gni @@ -24,4 +24,3 @@ chip_device_platform = "tizen" chip_build_tests = false chip_inet_config_enable_raw_endpoint = false -chip_inet_config_enable_dns_resolver = false diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn index 2f73a091174939..3e17783ca8da3d 100644 --- a/src/inet/BUILD.gn +++ b/src/inet/BUILD.gn @@ -36,7 +36,6 @@ buildconfig_header("inet_buildconfig") { defines = [ "INET_CONFIG_TEST=${chip_build_tests}", "INET_CONFIG_ENABLE_IPV4=${chip_inet_config_enable_ipv4}", - "INET_CONFIG_ENABLE_DNS_RESOLVER=${chip_inet_config_enable_dns_resolver}", "INET_CONFIG_ENABLE_TCP_ENDPOINT=${chip_inet_config_enable_tcp_endpoint}", "INET_CONFIG_ENABLE_UDP_ENDPOINT=${chip_inet_config_enable_udp_endpoint}", "HAVE_LWIP_RAW_BIND_NETIF=true", @@ -118,13 +117,6 @@ static_library("inet") { ] } - if (chip_inet_config_enable_dns_resolver) { - sources += [ - "DNSResolver.cpp", - "DNSResolver.h", - ] - } - if (chip_with_nlfaultinjection) { sources += [ "InetFaultInjection.cpp" ] public_deps += [ "${nlfaultinjection_root}:nlfaultinjection" ] diff --git a/src/inet/DNSResolver.cpp b/src/inet/DNSResolver.cpp deleted file mode 100644 index f22e5e1aa3f34f..00000000000000 --- a/src/inet/DNSResolver.cpp +++ /dev/null @@ -1,468 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2013-2017 Nest Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file implements DNSResolver, the object that abstracts - * Domain Name System (DNS) resolution in InetLayer. - * - */ - -#include - -#include -#include - -#include - -#include - -#if CHIP_SYSTEM_CONFIG_USE_LWIP -#include -#include -#include - -#if LWIP_VERSION_MAJOR < 2 -#define LWIP_DNS_FOUND_CALLBACK_TYPE dns_found_callback -#endif // LWIP_VERSION_MAJOR < 2 -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP - -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS -#include -#include -#include -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - -namespace chip { -namespace Inet { - -chip::System::ObjectPool DNSResolver::sPool; - -#if CHIP_SYSTEM_CONFIG_USE_LWIP - -CHIP_ERROR DNSResolver::ResolveImpl(char * hostNameBuf) -{ -#if LWIP_DNS -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - - u8_t lwipAddrType; - -#if INET_CONFIG_ENABLE_IPV4 - switch (addrFamilyOption) - { - case kDNSOption_AddrFamily_IPv4Only: - lwipAddrType = LWIP_DNS_ADDRTYPE_IPV4; - break; - case kDNSOption_AddrFamily_Any: - case kDNSOption_AddrFamily_IPv4Preferred: - lwipAddrType = LWIP_DNS_ADDRTYPE_IPV4_IPV6; - break; - case kDNSOption_AddrFamily_IPv6Only: - lwipAddrType = LWIP_DNS_ADDRTYPE_IPV6; - break; - case kDNSOption_AddrFamily_IPv6Preferred: - lwipAddrType = LWIP_DNS_ADDRTYPE_IPV6_IPV4; - break; - default: - chipDie(); - } -#else // INET_CONFIG_ENABLE_IPV4 - lwipAddrType = LWIP_DNS_ADDRTYPE_IPV6; -#endif // INET_CONFIG_ENABLE_IPV4 - -#else // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR < 5 - -#if INET_CONFIG_ENABLE_IPV4 - if (addrFamilyOption == kDNSOption_AddrFamily_IPv6Only) -#endif - { - Release(); - return CHIP_ERROR_NOT_IMPLEMENTED; - } - -#endif // LWIP_VERSION_MAJOR <= 1 || LWIP_VERSION_MINOR < 5 - - // Lock LwIP stack - LOCK_TCPIP_CORE(); - - ip_addr_t lwipAddr; - LWIP_DNS_FOUND_CALLBACK_TYPE lwipCallback = reinterpret_cast(LwIPHandleResolveComplete); - - err_t lwipErr = -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - dns_gethostbyname_addrtype(hostNameBuf, &lwipAddr, lwipCallback, this, lwipAddrType); -#else - dns_gethostbyname(hostNameBuf, &lwipAddr, lwipCallback, this); -#endif - - // Unlock LwIP stack - UNLOCK_TCPIP_CORE(); - - if (lwipErr == ERR_OK) - { - chip::System::Layer & lSystemLayer = SystemLayer(); - -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - AddrArray[0] = IPAddress::FromLwIPAddr(lwipAddr); -#else - AddrArray[0] = IPAddress::FromIPv4(lwipAddr); -#endif - NumAddrs = 1; - - lSystemLayer.PostEvent(*this, kInetEvent_DNSResolveComplete, 0); - } - else if (lwipErr != ERR_INPROGRESS) - { - res = chip::System::MapErrorLwIP(lwipErr); - Release(); - } - - return res; -#else // LWIP_DNS - Release(); - return CHIP_ERROR_NOT_IMPLEMENTED; -#endif // LWIP_DNS -} - -CHIP_ERROR DNSResolver::Cancel() -{ - // NOTE: LwIP does not support canceling DNS requests that are in progress. As a consequence, - // we can't release the DNSResolver object until LwIP calls us back (because LwIP retains a - // pointer to the DNSResolver object while the request is active). However, now that the - // application has called Cancel() we have to make sure to NOT call their OnComplete function - // when the request completes. - // - // To ensure the right thing happens, we NULL the OnComplete pointer here, which signals the - // code in HandleResolveComplete() and LwIPHandleResolveComplete() to not interact with the - // application's state data (AddrArray) and to not call the application's callback. This has - // to happen with the LwIP lock held, since LwIPHandleResolveComplete() runs on LwIP's thread. - - // Lock LwIP stack - LOCK_TCPIP_CORE(); - - // Signal that the request has been canceled by clearing the state of the resolver object. - OnComplete = NULL; - AddrArray = NULL; - MaxAddrs = 0; - NumAddrs = 0; - - // Unlock LwIP stack - UNLOCK_TCPIP_CORE(); - - return CHIP_NO_ERROR; -} - -/** - * This method is called by InetLayer on success, failure, or timeout of a - * DNS request. - * - */ -void DNSResolver::HandleResolveComplete() -{ - // Call the application's completion handler if the request hasn't been canceled. - if (OnComplete != NULL) - OnComplete(AppState, (NumAddrs > 0) ? CHIP_NO_ERROR : INET_ERROR_HOST_NOT_FOUND, NumAddrs, AddrArray); - - // Release the resolver object. - Release(); -} - -/** - * This method is called by LwIP network stack on success, failure, or timeout - * of a DNS request. - * - * @param[in] name A pointer to a NULL-terminated C string - * representing the host name that is queried. - * @param[in] ipaddr A pointer to a list of resolved IP addresses. - * @param[in] callback_arg A pointer to the arguments that are passed to - * the callback function. - * - */ -#if LWIP_VERSION_MAJOR > 1 -void DNSResolver::LwIPHandleResolveComplete(const char * name, const ip_addr_t * ipaddr, void * callback_arg) -#else // LWIP_VERSION_MAJOR <= 1 -void DNSResolver::LwIPHandleResolveComplete(const char * name, ip_addr_t * ipaddr, void * callback_arg) -#endif // LWIP_VERSION_MAJOR <= 1 -{ - DNSResolver * resolver = (DNSResolver *) callback_arg; - - if (resolver != NULL) - { - chip::System::Layer & lSystemLayer = resolver->SystemLayer(); - - // Copy the resolved address to the application supplied buffer, but only if the request hasn't been canceled. - if (resolver->OnComplete != NULL && ipaddr != NULL) - { -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - resolver->AddrArray[0] = IPAddress::FromLwIPAddr(*ipaddr); -#else - resolver->AddrArray[0] = IPAddress::FromIPv4(*ipaddr); -#endif - resolver->NumAddrs = 1; - } - - lSystemLayer.PostEvent(*resolver, kInetEvent_DNSResolveComplete, 0); - } -} - -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP - -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS - -CHIP_ERROR DNSResolver::ResolveImpl(char * hostNameBuf) -{ - struct addrinfo gaiHints; - struct addrinfo * gaiResults = nullptr; - int gaiReturnCode; - - // Configure the hints argument for getaddrinfo() - InitAddrInfoHints(gaiHints); - - // Call getaddrinfo() to perform the name resolution. - gaiReturnCode = getaddrinfo(hostNameBuf, nullptr, &gaiHints, &gaiResults); - - // Process the return code and results list returned by getaddrinfo(). If the call - // was successful this will copy the resultant addresses into the caller's array. - CHIP_ERROR res = ProcessGetAddrInfoResult(gaiReturnCode, gaiResults); - - // Invoke the caller's completion function. - OnComplete(AppState, res, NumAddrs, AddrArray); - - // Release DNSResolver object. - Release(); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR DNSResolver::Cancel() -{ - return CHIP_NO_ERROR; -} - -void DNSResolver::InitAddrInfoHints(struct addrinfo & hints) -{ - memset(&hints, 0, sizeof(hints)); - -#if INET_CONFIG_ENABLE_IPV4 - uint8_t addrFamilyOption = (DNSOptions & kDNSOption_AddrFamily_Mask); - - if (addrFamilyOption == kDNSOption_AddrFamily_IPv4Only) - { - hints.ai_family = AF_INET; - } - else if (addrFamilyOption == kDNSOption_AddrFamily_IPv6Only) - { - hints.ai_family = AF_INET6; - } - else - { - hints.ai_family = AF_UNSPEC; - } -#else // INET_CONFIG_ENABLE_IPV4 - hints.ai_family = AF_INET6; -#endif // INET_CONFIG_ENABLE_IPV4 - hints.ai_flags = AI_ADDRCONFIG; -} - -CHIP_ERROR DNSResolver::ProcessGetAddrInfoResult(int returnCode, struct addrinfo * results) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - // If getaddrinfo() succeeded, copy addresses in the returned addrinfo structures into the - // application's output array... - if (returnCode == 0) - { - NumAddrs = 0; - -#if INET_CONFIG_ENABLE_IPV4 - - // Based on the address family option specified by the application, determine which - // types of addresses should be returned and the order in which they should appear. - uint8_t addrFamilyOption = (DNSOptions & kDNSOption_AddrFamily_Mask); - int primaryFamily, secondaryFamily; - switch (addrFamilyOption) - { - case kDNSOption_AddrFamily_Any: - primaryFamily = AF_UNSPEC; - secondaryFamily = AF_UNSPEC; - break; - case kDNSOption_AddrFamily_IPv4Only: - primaryFamily = AF_INET; - secondaryFamily = AF_UNSPEC; - break; - case kDNSOption_AddrFamily_IPv4Preferred: - primaryFamily = AF_INET; - secondaryFamily = AF_INET6; - break; - case kDNSOption_AddrFamily_IPv6Only: - primaryFamily = AF_INET6; - secondaryFamily = AF_UNSPEC; - break; - case kDNSOption_AddrFamily_IPv6Preferred: - primaryFamily = AF_INET6; - secondaryFamily = AF_INET; - break; - default: - chipDie(); - } - - // Determine the number of addresses of each family present in the results. - // In the case of the secondary address family, only count these if they are - // to be returned in the results. - uint8_t numPrimaryAddrs = CountAddresses(primaryFamily, results); - uint8_t numSecondaryAddrs = (secondaryFamily != AF_UNSPEC) ? CountAddresses(secondaryFamily, results) : 0; - // Make sure numAddrs can actually fit the sum. - uint16_t numAddrs = static_cast(numPrimaryAddrs + numSecondaryAddrs); - - // If the total number of addresses to be returned exceeds the application - // specified max, ensure that at least 1 address from the secondary family - // appears in the result (unless of course there are no such addresses or - // the max is set to 1). - // This ensures the application will try at least one secondary address - // when attempting to communicate with the host. - if (numAddrs > MaxAddrs && MaxAddrs > 1 && numPrimaryAddrs > 0 && numSecondaryAddrs > 0) - { - numPrimaryAddrs = ::chip::min(numPrimaryAddrs, static_cast(MaxAddrs - 1)); - } - - // Copy the primary addresses into the beginning of the application's output array, - // up to the limit determined above. - CopyAddresses(primaryFamily, numPrimaryAddrs, results); - - // If secondary addresses are being returned, copy them into the output array after - // the primary addresses. - if (numSecondaryAddrs != 0) - { - CopyAddresses(secondaryFamily, numSecondaryAddrs, results); - } - -#else // INET_CONFIG_ENABLE_IPV4 - - // Copy IPv6 addresses into the application's output array. - CopyAddresses(AF_INET6, UINT8_MAX, results); - -#endif // INET_CONFIG_ENABLE_IPV4 - - // If in the end no addresses were returned, treat this as a "host not found" error. - if (NumAddrs == 0) - { - err = INET_ERROR_HOST_NOT_FOUND; - } - } - - // Otherwise, getaddrinfo() failed, so translate the return code to an appropriate - // Inet error... - else - { - switch (returnCode) - { - case EAI_NONAME: - case EAI_NODATA: - case EAI_ADDRFAMILY: - // Each of these errors is translated to "host not found" for simplicity at the - // application layer. On most systems, the errors have the following meanings: - // EAI_NONAME is returned when there are no DNS records for the requested host name. - // EAI_NODATA is returned when there are no host records (A or AAAA) for the requested - // name, but other records do exist (e.g. MX or TXT). - // EAI_ADDRFAMILY is returned when a text-form address is given as the name, but its - // address family (IPv4 or IPv6) does not match the value specified in hints.ai_family. - err = INET_ERROR_HOST_NOT_FOUND; - break; - case EAI_AGAIN: - err = INET_ERROR_DNS_TRY_AGAIN; - break; - case EAI_SYSTEM: - err = CHIP_ERROR_POSIX(errno); - break; - default: - err = INET_ERROR_DNS_NO_RECOVERY; - break; - } - } - - // Free the results structure. - if (results != nullptr) - freeaddrinfo(results); - - return err; -} - -void DNSResolver::CopyAddresses(int family, uint8_t count, const struct addrinfo * addrs) -{ - for (const struct addrinfo * addr = addrs; addr != nullptr && NumAddrs < MaxAddrs && count > 0; addr = addr->ai_next) - { - if (family == AF_UNSPEC || addr->ai_addr->sa_family == family) - { - AddrArray[NumAddrs++] = IPAddress::FromSockAddr(*addr->ai_addr); - count--; - } - } -} - -uint8_t DNSResolver::CountAddresses(int family, const struct addrinfo * addrs) -{ - uint8_t count = 0; - - for (const struct addrinfo * addr = addrs; addr != nullptr && count < UINT8_MAX; addr = addr->ai_next) - { - if (family == AF_UNSPEC || addr->ai_addr->sa_family == family) - { - count++; - } - } - - return count; -} - -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - -CHIP_ERROR DNSResolver::Resolve(const char * hostName, uint16_t hostNameLen, uint8_t options, uint8_t maxAddrs, - IPAddress * addrArray, DNSResolver::OnResolveCompleteFunct onComplete, void * appState) -{ - uint8_t addrFamilyOption = (options & kDNSOption_AddrFamily_Mask); - uint8_t optionFlags = (options & kDNSOption_Flags_Mask); - - // Check that the supplied options are valid. - if ((addrFamilyOption != kDNSOption_AddrFamily_Any -#if INET_CONFIG_ENABLE_IPV4 - && addrFamilyOption != kDNSOption_AddrFamily_IPv4Only && addrFamilyOption != kDNSOption_AddrFamily_IPv4Preferred -#endif - && addrFamilyOption != kDNSOption_AddrFamily_IPv6Only && addrFamilyOption != kDNSOption_AddrFamily_IPv6Preferred) || - (optionFlags & ~kDNSOption_ValidFlags) != 0) - { - Release(); - return CHIP_ERROR_INVALID_ARGUMENT; - } - - char hostNameBuf[NL_DNS_HOSTNAME_MAX_LEN + 1]; // DNS limits hostnames to 253 max characters. - - memcpy(hostNameBuf, hostName, hostNameLen); - hostNameBuf[hostNameLen] = 0; - - AppState = appState; - AddrArray = addrArray; - MaxAddrs = maxAddrs; - NumAddrs = 0; - DNSOptions = options; - OnComplete = onComplete; - - return ResolveImpl(hostNameBuf); -} - -} // namespace Inet -} // namespace chip diff --git a/src/inet/DNSResolver.h b/src/inet/DNSResolver.h deleted file mode 100644 index 327e799d34ceaf..00000000000000 --- a/src/inet/DNSResolver.h +++ /dev/null @@ -1,179 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2013-2017 Nest Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file defines DNSResolver, the object that abstracts - * Domain Name System (DNS) resolution in InetLayer. - * - */ - -#pragma once - -#include -#include -#include - -#define NL_DNS_HOSTNAME_MAX_LEN (253) - -struct addrinfo; - -namespace chip { -namespace Inet { - -class InetLayer; - -/** - * Options controlling how IP address resolution is performed. - */ -enum DNSOptions -{ - kDNSOption_AddrFamily_Mask = 0x07, ///< Bits within a DNSOptions integer value representing the desired address family. - kDNSOption_Flags_Mask = 0xF8, ///< Bits within a DNSOptions integer value reserved for flags. - - // Address Family Choices - kDNSOption_AddrFamily_Any = 0x00, ///< Return IPv4 and/or IPv6 addresses in the order returned by the nameserver. -#if INET_CONFIG_ENABLE_IPV4 - kDNSOption_AddrFamily_IPv4Only = 0x01, ///< Return only IPv4 addresses. - kDNSOption_AddrFamily_IPv4Preferred = 0x02, ///< Return IPv4 and/or IPv6 addresses, with IPv4 addresses listed first. -#endif - kDNSOption_AddrFamily_IPv6Only = 0x03, ///< Return only IPv6 addresses. - kDNSOption_AddrFamily_IPv6Preferred = 0x04, ///< Return IPv4 and/or IPv6 addresses, with IPv6 addresses listed first. - - // NOTE: At present there are no DNSOption flags define. - kDNSOption_ValidFlags = 0, ///< Set of all valid DNSOption flags. - - kDNSOption_Default = kDNSOption_AddrFamily_Any -}; - -/** - * @class DNSResolver - * - * @brief - * This is an internal class to InetLayer that provides the abstraction of - * Domain Name System (DNS) resolution in InetLayer. There is no public - * interface available for the application layer. - * - */ -class DNSResolver : public InetLayerBasis -{ -private: - friend class InetLayer; - - /** - * @brief Type of event handling function called when a DNS request completes. - * - * @param[in] appState Application state pointer. - * @param[in] err Error code. - * @param[in] addrCount Number of IP addresses in the \c addrArray list. - * @param[in] addrArray List of addresses in the answer. - * - * @details - * Provide a function of this type to the \c Resolve method to process - * completion events. - */ - typedef void (*OnResolveCompleteFunct)(void * appState, CHIP_ERROR err, uint8_t addrCount, IPAddress * addrArray); - - /** - * This method revolves a host name into a list of IP addresses. - * - * @note - * Even if the operation completes successfully, the result might be a zero-length list of IP addresses. - * Most of the error generated are returned via the application callback. - * - * @param[in] hostName A pointer to a C string representing the host name - * to be queried. - * @param[in] hostNameLen The string length of host name. - * @param[in] maxAddrs The maximum number of addresses to store in the DNS - * table. - * @param[in] options An integer value controlling how host name address - * resolution is performed. Values are from the #DNSOptions - * enumeration. - * @param[in] addrArray A pointer to the DNS table. - * @param[in] onComplete A pointer to the callback function when a DNS - * request is complete. - * @param[in] appState A pointer to the application state to be passed to - * onComplete when a DNS request is complete. - * - * @retval CHIP_NO_ERROR if a DNS request is handled - * successfully. - * @retval CHIP_ERROR_NOT_IMPLEMENTED if DNS resolution is not enabled on - * the underlying platform. - * @retval _other_ if other POSIX network or OS error - * was returned by the underlying DNS - * resolver implementation. - * - */ - CHIP_ERROR Resolve(const char * hostName, uint16_t hostNameLen, uint8_t options, uint8_t maxAddrs, IPAddress * addrArray, - OnResolveCompleteFunct onComplete, void * appState); - - /** - * This method cancels DNS requests that are in progress. - */ - CHIP_ERROR Cancel(); - - static chip::System::ObjectPool sPool; - - /** - * A pointer to the callback function when a DNS request is complete. - */ - OnResolveCompleteFunct OnComplete; - - /** - * A pointer to the DNS table that stores a list of resolved addresses. - */ - IPAddress * AddrArray; - - /** - * The maximum number of addresses that could be stored in the DNS table. - */ - uint8_t MaxAddrs; - - /** - * The actual number of addresses that are stored in the DNS table. - */ - uint8_t NumAddrs; - - /** - * DNS options for the current request. - */ - uint8_t DNSOptions; - - CHIP_ERROR ResolveImpl(char * hostNameBuf); - -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS - - void InitAddrInfoHints(struct addrinfo & hints); - CHIP_ERROR ProcessGetAddrInfoResult(int returnCode, struct addrinfo * results); - void CopyAddresses(int family, uint8_t maxAddrs, const struct addrinfo * addrs); - uint8_t CountAddresses(int family, const struct addrinfo * addrs); - -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - -#if CHIP_SYSTEM_CONFIG_USE_LWIP - void HandleResolveComplete(void); -#if LWIP_VERSION_MAJOR > 1 - static void LwIPHandleResolveComplete(const char * name, const ip_addr_t * ipaddr, void * callback_arg); -#else // LWIP_VERSION_MAJOR <= 1 - static void LwIPHandleResolveComplete(const char * name, ip_addr_t * ipaddr, void * callback_arg); -#endif // LWIP_VERSION_MAJOR <= 1 -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP -}; - -} // namespace Inet -} // namespace chip diff --git a/src/inet/Inet.h b/src/inet/Inet.h index 60eae475acf536..3c94b4813016c2 100644 --- a/src/inet/Inet.h +++ b/src/inet/Inet.h @@ -34,10 +34,6 @@ #include #include -#if INET_CONFIG_ENABLE_DNS_RESOLVER -#include -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - #if INET_CONFIG_ENABLE_TCP_ENDPOINT #include #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT diff --git a/src/inet/InetConfig.h b/src/inet/InetConfig.h index 01b77c2ed24344..dc994ebd977268 100644 --- a/src/inet/InetConfig.h +++ b/src/inet/InetConfig.h @@ -168,32 +168,6 @@ #define INET_CONFIG_NUM_UDP_ENDPOINTS 64 #endif // INET_CONFIG_NUM_UDP_ENDPOINTS -/** - * @def INET_CONFIG_NUM_DNS_RESOLVERS - * - * @brief - * This is the total number of outstanding DNS resolution request - * contexts. - * - * Up to this many DNS resolution requests may be in in use. - * - */ -#ifndef INET_CONFIG_NUM_DNS_RESOLVERS -#define INET_CONFIG_NUM_DNS_RESOLVERS 4 -#endif // INET_CONFIG_NUM_DNS_RESOLVERS - -/** - * @def INET_CONFIG_MAX_DNS_ADDRS - * - * @brief - * This is the maximum allowable number of addresses that may - * be returned in a single DNS hostname lookup. - * - */ -#ifndef INET_CONFIG_MAX_DNS_ADDRS -#define INET_CONFIG_MAX_DNS_ADDRS 16 -#endif // INET_CONFIG_MAX_DNS_ADDRS - /** * @def INET_TCP_IDLE_CHECK_INTERVAL * @@ -206,18 +180,6 @@ #define INET_TCP_IDLE_CHECK_INTERVAL 100 #endif // INET_TCP_IDLE_CHECK_INTERVAL -/** - * @def INET_CONFIG_ENABLE_DNS_RESOLVER - * - * @brief - * Defines whether (1) or not (0) to enable the ability - * to instantiate the DNS resolver. - * - */ -#ifndef INET_CONFIG_ENABLE_DNS_RESOLVER -#define INET_CONFIG_ENABLE_DNS_RESOLVER 0 -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - /** * @def INET_CONFIG_ENABLE_TCP_ENDPOINT * diff --git a/src/inet/InetLayer.cpp b/src/inet/InetLayer.cpp index 51c00b6d194ea5..ca80bdc08cff5d 100644 --- a/src/inet/InetLayer.cpp +++ b/src/inet/InetLayer.cpp @@ -81,10 +81,6 @@ namespace Inet { void InetLayer::UpdateSnapshot(chip::System::Stats::Snapshot & aSnapshot) { -#if INET_CONFIG_ENABLE_DNS_RESOLVER - DNSResolver::sPool.GetStatistics(aSnapshot.mResourcesInUse[chip::System::Stats::kInetLayer_NumDNSResolvers], - aSnapshot.mHighWatermarks[chip::System::Stats::kInetLayer_NumDNSResolvers]); -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER #if INET_CONFIG_ENABLE_TCP_ENDPOINT TCPEndPoint::sPool.GetStatistics(aSnapshot.mResourcesInUse[chip::System::Stats::kInetLayer_NumTCPEps], aSnapshot.mHighWatermarks[chip::System::Stats::kInetLayer_NumTCPEps]); @@ -279,17 +275,6 @@ CHIP_ERROR InetLayer::Shutdown() if (State == kState_Initialized) { -#if INET_CONFIG_ENABLE_DNS_RESOLVER - // Cancel all DNS resolution requests owned by this instance. - DNSResolver::sPool.ForEachActiveObject([&](DNSResolver * lResolver) { - if ((lResolver != nullptr) && lResolver->IsCreatedByInetLayer(*this)) - { - lResolver->Cancel(); - } - return true; - }); -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - #if INET_CONFIG_ENABLE_TCP_ENDPOINT // Abort all TCP endpoints owned by this instance. TCPEndPoint::sPool.ForEachActiveObject([&](TCPEndPoint * lEndPoint) { @@ -526,258 +511,6 @@ CHIP_ERROR InetLayer::NewUDPEndPoint(UDPEndPoint ** retEndPoint) } #endif // INET_CONFIG_ENABLE_UDP_ENDPOINT -#if INET_CONFIG_ENABLE_DNS_RESOLVER -/** - * Perform an IP address resolution of a specified hostname. - * - * @note - * This is an asynchronous operation and the result will be communicated back - * via the OnComplete() callback. - * - * @param[in] hostName A pointer to a NULL-terminated C string representing - * the host name to be queried. - * - * @param[in] maxAddrs The maximum number of addresses to store in the DNS - * table. - * - * @param[in] addrArray A pointer to the DNS table. - * - * @param[in] onComplete A pointer to the callback function when a DNS - * request is complete. - * - * @param[in] appState A pointer to the application state to be passed to - * onComplete when a DNS request is complete. - * - * @retval #CHIP_NO_ERROR if a DNS request is handled - * successfully. - * @retval #CHIP_ERROR_NO_MEMORY if the Inet layer resolver pool - * is full. - * @retval #INET_ERROR_HOST_NAME_TOO_LONG if a requested host name is too - * long. - * @retval #INET_ERROR_HOST_NOT_FOUND if a request host name could not be - * resolved to an address. - * @retval #INET_ERROR_DNS_TRY_AGAIN if a name server returned a - * temporary failure indication; - * try again later. - * @retval #INET_ERROR_DNS_NO_RECOVERY if a name server returned an - * unrecoverable error. - * @retval #CHIP_ERROR_NOT_IMPLEMENTED if DNS resolution is not enabled on - * the underlying platform. - * @retval other POSIX network or OS error returned by the underlying DNS - * resolver implementation. - * - */ -CHIP_ERROR InetLayer::ResolveHostAddress(const char * hostName, uint8_t maxAddrs, IPAddress * addrArray, - DNSResolveCompleteFunct onComplete, void * appState) -{ - size_t hostNameLength = strlen(hostName); - if (hostNameLength > UINT16_MAX) - { - return INET_ERROR_HOST_NAME_TOO_LONG; - } - return ResolveHostAddress(hostName, static_cast(hostNameLength), maxAddrs, addrArray, onComplete, appState); -} - -/** - * Perform an IP address resolution of a specified hostname. - * - * @param[in] hostName A pointer to a non NULL-terminated C string representing the host name - * to be queried. - * - * @param[in] hostNameLen The string length of host name. - * - * @param[in] maxAddrs The maximum number of addresses to store in the DNS - * table. - * - * @param[in] addrArray A pointer to the DNS table. - * - * @param[in] onComplete A pointer to the callback function when a DNS - * request is complete. - * - * @param[in] appState A pointer to the application state to be passed to - * onComplete when a DNS request is complete. - * - * @retval #CHIP_NO_ERROR if a DNS request is handled - * successfully. - * @retval #CHIP_ERROR_NO_MEMORY if the Inet layer resolver pool - * is full. - * @retval #INET_ERROR_HOST_NAME_TOO_LONG if a requested host name is too - * long. - * @retval #INET_ERROR_HOST_NOT_FOUND if a request host name could not be - * resolved to an address. - * @retval #INET_ERROR_DNS_TRY_AGAIN if a name server returned a - * temporary failure indication; - * try again later. - * @retval #INET_ERROR_DNS_NO_RECOVERY if a name server returned an - * unrecoverable error. - * @retval #CHIP_ERROR_NOT_IMPLEMENTED if DNS resolution is not enabled on - * the underlying platform. - * @retval other POSIX network or OS error returned by the underlying DNS - * resolver implementation. - * - */ -CHIP_ERROR InetLayer::ResolveHostAddress(const char * hostName, uint16_t hostNameLen, uint8_t maxAddrs, IPAddress * addrArray, - DNSResolveCompleteFunct onComplete, void * appState) -{ - return ResolveHostAddress(hostName, hostNameLen, kDNSOption_Default, maxAddrs, addrArray, onComplete, appState); -} - -/** - * Perform an IP address resolution of a specified hostname. - * - * @param[in] hostName A pointer to a non NULL-terminated C string representing the host name - * to be queried. - * - * @param[in] hostNameLen The string length of host name. - * - * @param[in] options An integer value controlling how host name resolution is performed. - * - * Value should be one of the address family values from the - * #DNSOptions enumeration: - * - * #kDNSOption_AddrFamily_Any - * #kDNSOption_AddrFamily_IPv4Only - * #kDNSOption_AddrFamily_IPv6Only - * #kDNSOption_AddrFamily_IPv4Preferred - * #kDNSOption_AddrFamily_IPv6Preferred - * - * @param[in] maxAddrs The maximum number of addresses to store in the DNS - * table. - * - * @param[in] addrArray A pointer to the DNS table. - * - * @param[in] onComplete A pointer to the callback function when a DNS - * request is complete. - * - * @param[in] appState A pointer to the application state to be passed to - * onComplete when a DNS request is complete. - * - * @retval #CHIP_NO_ERROR if a DNS request is handled - * successfully. - * @retval #CHIP_ERROR_NO_MEMORY if the Inet layer resolver pool - * is full. - * @retval #INET_ERROR_HOST_NAME_TOO_LONG if a requested host name is too - * long. - * @retval #INET_ERROR_HOST_NOT_FOUND if a request host name could not be - * resolved to an address. - * @retval #INET_ERROR_DNS_TRY_AGAIN if a name server returned a - * temporary failure indication; - * try again later. - * @retval #INET_ERROR_DNS_NO_RECOVERY if a name server returned an - * unrecoverable error. - * @retval #CHIP_ERROR_NOT_IMPLEMENTED if DNS resolution is not enabled on - * the underlying platform. - * @retval other POSIX network or OS error returned by the underlying DNS - * resolver implementation. - * - */ -CHIP_ERROR InetLayer::ResolveHostAddress(const char * hostName, uint16_t hostNameLen, uint8_t options, uint8_t maxAddrs, - IPAddress * addrArray, DNSResolveCompleteFunct onComplete, void * appState) -{ - assertChipStackLockedByCurrentThread(); - - DNSResolver * resolver = nullptr; - - VerifyOrReturnError(State == kState_Initialized, CHIP_ERROR_INCORRECT_STATE); - - INET_FAULT_INJECT(FaultInjection::kFault_DNSResolverNew, return CHIP_ERROR_NO_MEMORY); - - // Store context information and set the resolver state. - VerifyOrReturnError(hostNameLen <= NL_DNS_HOSTNAME_MAX_LEN, INET_ERROR_HOST_NAME_TOO_LONG); - VerifyOrReturnError(maxAddrs > 0, CHIP_ERROR_NO_MEMORY); - - resolver = DNSResolver::sPool.TryCreate(); - if (resolver != nullptr) - { - resolver->InitInetLayerBasis(*this); - } - else - { - ChipLogError(Inet, "%s resolver pool FULL", "DNS"); - return CHIP_ERROR_NO_MEMORY; - } - - // Short-circuit full address resolution if the supplied host name is a text-form - // IP address... - if (IPAddress::FromString(hostName, hostNameLen, *addrArray)) - { - CHIP_ERROR err = CHIP_NO_ERROR; - uint8_t addrTypeOption = (options & kDNSOption_AddrFamily_Mask); - IPAddressType addrType = addrArray->Type(); - - if ((addrTypeOption == kDNSOption_AddrFamily_IPv6Only && addrType != kIPAddressType_IPv6) -#if INET_CONFIG_ENABLE_IPV4 - || (addrTypeOption == kDNSOption_AddrFamily_IPv4Only && addrType != kIPAddressType_IPv4) -#endif - ) - { - err = INET_ERROR_INCOMPATIBLE_IP_ADDRESS_TYPE; - } - - if (onComplete) - { - onComplete(appState, err, (err == CHIP_NO_ERROR) ? 1 : 0, addrArray); - } - - resolver->Release(); - resolver = nullptr; - - return CHIP_NO_ERROR; - } - - // After this point, the resolver will be released by: - // - resolver->Resolve() (in case of synchronous resolving) - // - the event handlers (in case of LwIP) - - return resolver->Resolve(hostName, hostNameLen, options, maxAddrs, addrArray, onComplete, appState); -} - -/** - * Cancel any outstanding DNS query (for a matching completion callback and - * application state) that may still be active. - * - * @note - * This situation can arise if the application initiates a connection - * to a peer using a hostname and then aborts/closes the connection - * before the hostname resolution completes. - * - * @param[in] onComplete A pointer to the callback function when a DNS - * request is complete. - * - * @param[in] appState A pointer to an application state object to be passed - * to the callback function as argument. - * - */ -void InetLayer::CancelResolveHostAddress(DNSResolveCompleteFunct onComplete, void * appState) -{ - assertChipStackLockedByCurrentThread(); - - if (State != kState_Initialized) - return; - - DNSResolver::sPool.ForEachActiveObject([&](DNSResolver * lResolver) { - if (!lResolver->IsCreatedByInetLayer(*this)) - { - return true; - } - - if (lResolver->OnComplete != onComplete) - { - return true; - } - - if (lResolver->AppState != appState) - { - return true; - } - - lResolver->Cancel(); - return false; - }); -} - -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - /** * Get the interface identifier for the specified IP address. If the * interface identifier cannot be derived it is set to the @@ -919,12 +652,6 @@ CHIP_ERROR InetLayer::HandleInetLayerEvent(chip::System::Object & aTarget, chip: break; #endif // INET_CONFIG_ENABLE_UDP_ENDPOINT -#if INET_CONFIG_ENABLE_DNS_RESOLVER - case kInetEvent_DNSResolveComplete: - static_cast(aTarget).HandleResolveComplete(); - break; -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - default: return CHIP_ERROR_UNEXPECTED_EVENT; } diff --git a/src/inet/InetLayer.h b/src/inet/InetLayer.h index 521ecb7cc4f6a1..d48f64c483eab1 100644 --- a/src/inet/InetLayer.h +++ b/src/inet/InetLayer.h @@ -57,10 +57,6 @@ #include #include -#if INET_CONFIG_ENABLE_DNS_RESOLVER -#include -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - #if INET_CONFIG_ENABLE_TCP_ENDPOINT #include #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT @@ -119,10 +115,6 @@ class InetLayer; */ class DLL_EXPORT InetLayer { -#if INET_CONFIG_ENABLE_DNS_RESOLVER - friend class DNSResolver; -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - #if INET_CONFIG_ENABLE_TCP_ENDPOINT friend class TCPEndPoint; #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT @@ -163,20 +155,6 @@ class DLL_EXPORT InetLayer // DNS Resolution -#if INET_CONFIG_ENABLE_DNS_RESOLVER - - typedef DNSResolver::OnResolveCompleteFunct DNSResolveCompleteFunct; - - CHIP_ERROR ResolveHostAddress(const char * hostName, uint16_t hostNameLen, uint8_t options, uint8_t maxAddrs, - IPAddress * addrArray, DNSResolveCompleteFunct onComplete, void * appState); - CHIP_ERROR ResolveHostAddress(const char * hostName, uint16_t hostNameLen, uint8_t maxAddrs, IPAddress * addrArray, - DNSResolveCompleteFunct onComplete, void * appState); - CHIP_ERROR ResolveHostAddress(const char * hostName, uint8_t maxAddrs, IPAddress * addrArray, - DNSResolveCompleteFunct onComplete, void * appState); - void CancelResolveHostAddress(DNSResolveCompleteFunct onComplete, void * appState); - -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - CHIP_ERROR GetInterfaceFromAddr(const IPAddress & addr, InterfaceId & intfId); CHIP_ERROR GetLinkLocalAddr(InterfaceId link, IPAddress * llAddr); diff --git a/src/inet/inet.gni b/src/inet/inet.gni index de476e86a47654..382ba477c7351b 100644 --- a/src/inet/inet.gni +++ b/src/inet/inet.gni @@ -20,9 +20,6 @@ declare_args() { # Enable IPv4 support. chip_inet_config_enable_ipv4 = true - # Enable DNS resolver. - chip_inet_config_enable_dns_resolver = true - # Enable UDP endpoint. chip_inet_config_enable_udp_endpoint = true diff --git a/src/inet/tests/BUILD.gn b/src/inet/tests/BUILD.gn index 63160739e4b1ab..dc78d690da115e 100644 --- a/src/inet/tests/BUILD.gn +++ b/src/inet/tests/BUILD.gn @@ -82,8 +82,6 @@ chip_test_suite("tests") { if (current_os != "mac" && current_os != "zephyr" && chip_device_platform != "esp32" && current_cpu == "x64" && chip_device_platform != "ameba") { - test_sources += [ "TestInetLayerDNS.cpp" ] - # TODO: This test does not seem executed sources += [ "TestLwIPDNS.cpp" ] } diff --git a/src/inet/tests/TestInetCommonPosix.cpp b/src/inet/tests/TestInetCommonPosix.cpp index feeaffb5ecac16..1cdb9a241e0214 100644 --- a/src/inet/tests/TestInetCommonPosix.cpp +++ b/src/inet/tests/TestInetCommonPosix.cpp @@ -215,10 +215,6 @@ static void PrintNetworkState() } } } -#if INET_CONFIG_ENABLE_DNS_RESOLVER - char dnsServerAddrStr[DNS_MAX_NAME_LENGTH]; - printf(" DNS Server: %s\n", gNetworkOptions.DNSServerAddr.ToString(dnsServerAddrStr, sizeof(dnsServerAddrStr))); -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER } #endif // CHIP_SYSTEM_CONFIG_USE_LWIP @@ -418,23 +414,6 @@ void InitNetwork() } } -#if INET_CONFIG_ENABLE_DNS_RESOLVER - if (gNetworkOptions.DNSServerAddr != IPAddress::Any) - { -#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - ip_addr_t dnsServerAddr = gNetworkOptions.DNSServerAddr.ToLwIPAddr(); -#else // LWIP_VERSION_MAJOR <= 1 -#if INET_CONFIG_ENABLE_IPV4 - ip_addr_t dnsServerAddr = gNetworkOptions.DNSServerAddr.ToIPv4(); -#else // !INET_CONFIG_ENABLE_IPV4 -#error "No support for DNS Resolver without IPv4!" -#endif // !INET_CONFIG_ENABLE_IPV4 -#endif // LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5 - - dns_setserver(0, &dnsServerAddr); - } -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - PrintNetworkState(); AcquireLwIP(); diff --git a/src/inet/tests/TestInetEndPoint.cpp b/src/inet/tests/TestInetEndPoint.cpp index d5b809a86162b9..91d74d67276b0f 100644 --- a/src/inet/tests/TestInetEndPoint.cpp +++ b/src/inet/tests/TestInetEndPoint.cpp @@ -87,10 +87,6 @@ static void TestInetPre(nlTestSuite * inSuite, void * inContext) TCPEndPoint * testTCPEP = nullptr; #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT CHIP_ERROR err = CHIP_NO_ERROR; -#if INET_CONFIG_ENABLE_DNS_RESOLVER - IPAddress testDestAddr = IPAddress::Any; - char testHostName[20] = "www.nest.com"; -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER // Deinit system layer and network ShutdownNetwork(); @@ -112,75 +108,11 @@ static void TestInetPre(nlTestSuite * inSuite, void * inContext) err = gSystemLayer.StartTimer(10, HandleTimer, nullptr); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); -#if INET_CONFIG_ENABLE_DNS_RESOLVER - err = gInet.ResolveHostAddress(testHostName, 1, &testDestAddr, HandleDNSResolveComplete, nullptr); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - // then init network InitSystemLayer(); InitNetwork(); } -#if INET_CONFIG_ENABLE_DNS_RESOLVER -// Test Inet ResolveHostAddress functionality -static void TestResolveHostAddress(nlTestSuite * inSuite, void * inContext) -{ - char testHostName1[20] = "www.google.com"; - char testHostName2[20] = "127.0.0.1"; - char testHostName3[20] = ""; - char testHostName4[260]; - IPAddress testDestAddr[1] = { IPAddress::Any }; - CHIP_ERROR err; - constexpr uint32_t kSleepTimeMilliseconds = 10; - - memset(testHostName4, 'w', sizeof(testHostName4)); - testHostName4[259] = '\0'; - - callbackHandlerCalled = false; - err = gInet.ResolveHostAddress(testHostName1, 1, testDestAddr, HandleDNSResolveComplete, &callbackHandlerCalled); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - - if (err == CHIP_NO_ERROR) - { - while (!callbackHandlerCalled) - { - ServiceNetwork(kSleepTimeMilliseconds); - } - } - - callbackHandlerCalled = false; - err = gInet.ResolveHostAddress(testHostName2, 1, testDestAddr, HandleDNSResolveComplete, &callbackHandlerCalled); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - - if (err == CHIP_NO_ERROR) - { - while (!callbackHandlerCalled) - { - ServiceNetwork(kSleepTimeMilliseconds); - } - } - - callbackHandlerCalled = false; - err = gInet.ResolveHostAddress(testHostName3, 1, testDestAddr, HandleDNSResolveComplete, &callbackHandlerCalled); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - - if (err == CHIP_NO_ERROR) - { - while (!callbackHandlerCalled) - { - ServiceNetwork(kSleepTimeMilliseconds); - } - } - - err = gInet.ResolveHostAddress(testHostName2, 0, testDestAddr, HandleDNSResolveComplete, &callbackHandlerCalled); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_NO_MEMORY); - - err = gInet.ResolveHostAddress(testHostName4, 1, testDestAddr, HandleDNSResolveComplete, &callbackHandlerCalled); - NL_TEST_ASSERT(inSuite, err == INET_ERROR_HOST_NAME_TOO_LONG); -} -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - static void TestInetError(nlTestSuite * inSuite, void * inContext) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -441,9 +373,6 @@ static void TestInetEndPointLimit(nlTestSuite * inSuite, void * inContext) * Test Suite. It lists all the test functions. */ static const nlTest sTests[] = { NL_TEST_DEF("InetEndPoint::PreTest", TestInetPre), -#if INET_CONFIG_ENABLE_DNS_RESOLVER - NL_TEST_DEF("InetEndPoint::ResolveHostAddress", TestResolveHostAddress), -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER NL_TEST_DEF("InetEndPoint::TestInetError", TestInetError), NL_TEST_DEF("InetEndPoint::TestInetInterface", TestInetInterface), NL_TEST_DEF("InetEndPoint::TestInetEndPoint", TestInetEndPointInternal), diff --git a/src/inet/tests/TestInetLayerDNS.cpp b/src/inet/tests/TestInetLayerDNS.cpp deleted file mode 100644 index 3430f91fa6a2fc..00000000000000 --- a/src/inet/tests/TestInetLayerDNS.cpp +++ /dev/null @@ -1,753 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2013-2017 Nest Labs, Inc. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * This file tests DNS resolution using the CHIP Inet Layer APIs. - * - */ - -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS -#endif - -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include - -#include - -#include "TestInetCommon.h" -#include "TestSetupSignalling.h" - -using namespace chip; -using namespace chip::Inet; - -#if INET_CONFIG_ENABLE_DNS_RESOLVER - -#define TOOL_NAME "TestInetLayerDNS" - -#define DISABLE_BROKEN_DNS_TESTS 1 // https://github.com/project-chip/connectedhomeip/issues/4670 - -#define DEFAULT_TEST_DURATION_MILLISECS (20000) -#define DEFAULT_CANCEL_TEST_DURATION_MILLISECS (2000) - -static uint32_t sNumResInProgress = 0; -constexpr uint8_t kMaxResults = 20; - -struct DNSResolutionTestCase -{ - const char * hostName; - uint8_t dnsOptions; - uint8_t maxResults; - CHIP_ERROR expectErr; - bool expectIPv4Addrs; - bool expectIPv6Addrs; -}; - -struct DNSResolutionTestContext -{ - nlTestSuite * testSuite; - DNSResolutionTestCase testCase; - bool callbackCalled; - IPAddress resultsBuf[kMaxResults]; -}; - -static void RunTestCase(nlTestSuite * testSuite, const DNSResolutionTestCase & testCase); -static void StartTestCase(DNSResolutionTestContext & testContext); -static void HandleResolutionComplete(void * appState, CHIP_ERROR err, uint8_t addrCount, IPAddress * addrArray); -static void ServiceNetworkUntilDone(uint32_t timeoutMS); -static void HandleSIGUSR1(int sig); - -/** - * Test basic name resolution functionality. - */ -static void TestDNSResolution_Basic(nlTestSuite * testSuite, void * testContext) -{ - // clang-format off - -#ifndef DISABLE_BROKEN_DNS_TESTS -#if INET_CONFIG_ENABLE_IPV4 - // Test resolving a name with only IPv4 addresses. - RunTestCase(testSuite, - DNSResolutionTestCase - { - "ipv4.google.com", - kDNSOption_Default, - kMaxResults, - CHIP_NO_ERROR, - true, - false - } - ); -#endif - - // Test resolving a name with only IPv6 addresses. - RunTestCase(testSuite, - DNSResolutionTestCase - { - "ipv6.google.com", - kDNSOption_Default, - kMaxResults, - CHIP_NO_ERROR, - false, - true - } - ); - -#if INET_CONFIG_ENABLE_IPV4 - // Test resolving a name with IPv4 and IPv6 addresses. - RunTestCase(testSuite, - DNSResolutionTestCase - { - "google.com", - kDNSOption_Default, - kMaxResults, - CHIP_NO_ERROR, - true, - true - } - ); -#endif -#endif - // clang-format on -} - -/** - * Test resolving a name using various address type options. - */ -static void TestDNSResolution_AddressTypeOption(nlTestSuite * testSuite, void * testContext) -{ - // clang-format off -#ifndef DISABLE_BROKEN_DNS_TESTS - - // Test requesting IPv4 addresses only. -#if INET_CONFIG_ENABLE_IPV4 - RunTestCase(testSuite, - DNSResolutionTestCase - { - "google.com", - kDNSOption_AddrFamily_IPv4Only, - kMaxResults, - CHIP_NO_ERROR, - true, - false - } - ); -#endif // INET_CONFIG_ENABLE_IPV4 - - // Test requesting IPv6 addresses only. - RunTestCase(testSuite, - DNSResolutionTestCase - { - "google.com", - kDNSOption_AddrFamily_IPv6Only, - kMaxResults, - CHIP_NO_ERROR, - false, - true - } - ); - - // Test requesting IPv4 address preferentially. -#if INET_CONFIG_ENABLE_IPV4 - RunTestCase(testSuite, - DNSResolutionTestCase - { - "google.com", - kDNSOption_AddrFamily_IPv4Preferred, - kMaxResults, - CHIP_NO_ERROR, - true, - true - } - ); - - // Test requesting IPv6 address preferentially. - RunTestCase(testSuite, - DNSResolutionTestCase - { - "google.com", - kDNSOption_AddrFamily_IPv6Preferred, - kMaxResults, - CHIP_NO_ERROR, - true, - true - } - ); -#endif // INET_CONFIG_ENABLE_IPV4 - -#endif - // clang-format on -} - -/** - * Test resolving a name with a limited number of results. - */ -static void TestDNSResolution_RestrictedResults(nlTestSuite * testSuite, void * testContext) -{ - // clang-format off - - // Test requesting 2 IPv4 addresses. This should result in, at most, 2 IPv4 addresses. -#if INET_CONFIG_ENABLE_IPV4 - RunTestCase(testSuite, - DNSResolutionTestCase - { - "google.com", - kDNSOption_AddrFamily_IPv4Only, - 2, - CHIP_NO_ERROR, - true, - false - } - ); -#endif // INET_CONFIG_ENABLE_IPV4 - - // Test requesting 2 IPv6 addresses. This should result in, at most, 2 IPv6 addresses. - RunTestCase(testSuite, - DNSResolutionTestCase - { - "google.com", - kDNSOption_AddrFamily_IPv6Only, - 2, - CHIP_NO_ERROR, - false, - true - } - ); - - // Test requesting 2 addresses, preferring IPv4. This should result in 1 IPv4 address - // followed by 1 IPv6 address. -#if INET_CONFIG_ENABLE_IPV4 - RunTestCase(testSuite, - DNSResolutionTestCase - { - "google.com", - kDNSOption_AddrFamily_IPv4Preferred, - 2, - CHIP_NO_ERROR, - true, - true - } - ); - - // Test requesting 2 addresses, preferring IPv6. This should result in 1 IPv6 address - // followed by 1 IPv4 address. - RunTestCase(testSuite, - DNSResolutionTestCase - { - "google.com", - kDNSOption_AddrFamily_IPv6Preferred, - 2, - CHIP_NO_ERROR, - true, - true - } - ); - // clang-format on -#endif // INET_CONFIG_ENABLE_IPV4 -} - -/** - * Test resolving a non-existant name. - */ -static void TestDNSResolution_NoRecord(nlTestSuite * testSuite, void * testContext) -{ - // clang-format off -#ifndef DISABLE_BROKEN_DNS_TESTS - RunTestCase(testSuite, - DNSResolutionTestCase - { - "www.google.invalid.", - kDNSOption_AddrFamily_Any, - 1, - INET_ERROR_HOST_NOT_FOUND, - false, - false - } - ); -#endif - // clang-format on -} - -/** - * Test resolving a name where the resultant DNS entry lacks an A or AAAA record. - */ -static void TestDNSResolution_NoHostRecord(nlTestSuite * testSuite, void * testContext) -{ - // clang-format off -#ifndef DISABLE_BROKEN_DNS_TESTS - - // Test resolving a name that has no host records (A or AAAA). - RunTestCase(testSuite, - DNSResolutionTestCase - { - "_spf.google.com", - kDNSOption_AddrFamily_Any, - kMaxResults, - INET_ERROR_HOST_NOT_FOUND, - false, - false - } - ); - - // Test resolving a name that has only AAAA records, while requesting IPv4 addresses only. -#if INET_CONFIG_ENABLE_IPV4 - RunTestCase(testSuite, - DNSResolutionTestCase - { - "ipv6.google.com", - kDNSOption_AddrFamily_IPv4Only, - kMaxResults, - INET_ERROR_HOST_NOT_FOUND, - true, - false - } - ); -#endif // INET_CONFIG_ENABLE_IPV4 - - // Test resolving a name that has only A records, while requesting IPv6 addresses only. - RunTestCase(testSuite, - DNSResolutionTestCase - { - "ipv4.google.com", - kDNSOption_AddrFamily_IPv6Only, - kMaxResults, - INET_ERROR_HOST_NOT_FOUND, - false, - false - } - ); - #endif - - // clang-format on -} - -/** - * Test resolving text form IP addresses. - */ -static void TestDNSResolution_TextForm(nlTestSuite * testSuite, void * testContext) -{ - // clang-format off -#if INET_CONFIG_ENABLE_IPV4 - RunTestCase(testSuite, - DNSResolutionTestCase - { - "216.58.194.174", - kDNSOption_AddrFamily_Any, - 1, - CHIP_NO_ERROR, - true, - false - } - ); -#endif - - RunTestCase(testSuite, - DNSResolutionTestCase - { - "2607:f8b0:4005:804::200e", - kDNSOption_AddrFamily_Any, - 1, - CHIP_NO_ERROR, - false, - true - } - ); - - // Test resolving text form IPv4 and IPv6 addresses while requesting an - // incompatible address type. - -#if INET_CONFIG_ENABLE_IPV4 - RunTestCase(testSuite, - DNSResolutionTestCase - { - "216.58.194.174", - kDNSOption_AddrFamily_IPv6Only, - 1, - INET_ERROR_INCOMPATIBLE_IP_ADDRESS_TYPE, - false, - false - } - ); - - RunTestCase(testSuite, - DNSResolutionTestCase - { - "2607:f8b0:4005:804::200e", - kDNSOption_AddrFamily_IPv4Only, - 1, - INET_ERROR_INCOMPATIBLE_IP_ADDRESS_TYPE, - false, - false - } - ); -#endif - // clang-format on -} - -static void TestDNSResolution_Cancel(nlTestSuite * testSuite, void * inContext) -{ - DNSResolutionTestContext testContext{ - testSuite, DNSResolutionTestCase{ "ipv6.google.com", kDNSOption_Default, kMaxResults, CHIP_NO_ERROR, false, true } - }; - - // Start DNS resolution. - StartTestCase(testContext); - - // If address resolution did NOT complete synchronously... - // (NOTE: If address resolution completes synchronously then this test is effectively - // void, as there's no opportunity to cancel the request). - if (!testContext.callbackCalled) - { - // Cancel the resolution before it completes. - gInet.CancelResolveHostAddress(HandleResolutionComplete, &testContext); - - // Service the network for awhile to see what happens (should timeout). - ServiceNetworkUntilDone(DEFAULT_CANCEL_TEST_DURATION_MILLISECS); - - // Verify that the completion function was NOT called. - NL_TEST_ASSERT(testSuite, testContext.callbackCalled == false); - } - - gDone = true; - sNumResInProgress = 0; -} - -static void TestDNSResolution_Simultaneous(nlTestSuite * testSuite, void * inContext) -{ - // clang-format off - DNSResolutionTestContext tests[] = - { - { - testSuite, - DNSResolutionTestCase - { - "example.net", - kDNSOption_AddrFamily_IPv6Only, - kMaxResults, - CHIP_NO_ERROR, - false, - true - } - }, - { - testSuite, - DNSResolutionTestCase - { - "2607:f8b0:4005:804::200e", - kDNSOption_Default, - kMaxResults, - CHIP_NO_ERROR, - false, - true - } - }, - { - testSuite, - DNSResolutionTestCase - { - "ipv6.google.com", - kDNSOption_Default, - kMaxResults, - CHIP_NO_ERROR, - false, - true - } - }, - { - testSuite, - DNSResolutionTestCase - { - "ibm.com", - kDNSOption_AddrFamily_IPv6Only, - kMaxResults, - CHIP_NO_ERROR, - false, - true - } - } - }; - // clang-format on - - // Start multiple DNS resolutions simultaneously. - for (DNSResolutionTestContext & testContext : tests) - { - StartTestCase(testContext); - } - - // Service the network until each completes, or a timeout occurs. - ServiceNetworkUntilDone(DEFAULT_TEST_DURATION_MILLISECS); - - // Verify no timeout occurred. - NL_TEST_ASSERT(testSuite, gDone == true); - - // Sanity check test logic. - NL_TEST_ASSERT(testSuite, sNumResInProgress == 0); -} - -static void RunTestCase(nlTestSuite * testSuite, const DNSResolutionTestCase & testCase) -{ - DNSResolutionTestContext testContext{ testSuite, testCase }; - - // Start DNS resolution. - StartTestCase(testContext); - - // Service the network until the completion callback is called. - ServiceNetworkUntilDone(DEFAULT_TEST_DURATION_MILLISECS); - - // Verify no timeout occurred. - NL_TEST_ASSERT(testSuite, gDone == true); - - // Sanity check test logic. - NL_TEST_ASSERT(testSuite, sNumResInProgress == 0); -} - -static void StartTestCase(DNSResolutionTestContext & testContext) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - DNSResolutionTestCase & testCase = testContext.testCase; - nlTestSuite * testSuite = testContext.testSuite; - - gDone = false; - sNumResInProgress++; - - printf("Resolving hostname %s\n", testCase.hostName); - err = gInet.ResolveHostAddress(testCase.hostName, strlen(testCase.hostName), testCase.dnsOptions, testCase.maxResults, - testContext.resultsBuf, HandleResolutionComplete, &testContext); - - if (err != CHIP_NO_ERROR) - { - printf("ResolveHostAddress failed for %s: %s\n", testCase.hostName, ::chip::ErrorStr(err)); - - // Verify the expected error - NL_TEST_ASSERT(testSuite, err == testCase.expectErr); - - // Verify the callback WASN'T called - NL_TEST_ASSERT(testSuite, testContext.callbackCalled == false); // - - sNumResInProgress--; - if (sNumResInProgress == 0) - { - gDone = true; - } - } -} - -static void HandleResolutionComplete(void * appState, CHIP_ERROR err, uint8_t addrCount, IPAddress * addrArray) -{ - DNSResolutionTestContext & testContext = *static_cast(appState); - DNSResolutionTestCase & testCase = testContext.testCase; - nlTestSuite * testSuite = testContext.testSuite; - - if (err == CHIP_NO_ERROR) - { - printf("DNS resolution complete for %s: %" PRIu8 " result%s returned\n", testCase.hostName, addrCount, - (addrCount != 1) ? "s" : ""); - for (uint8_t i = 0; i < addrCount; i++) - { - char ipAddrStr[INET6_ADDRSTRLEN]; - - printf(" %s\n", addrArray[i].ToString(ipAddrStr, sizeof(ipAddrStr))); - } - } - else - { - printf("DNS resolution complete for %s: %s\n", testCase.hostName, ::chip::ErrorStr(err)); - } - - // Verify the expected result. - NL_TEST_ASSERT(testSuite, err == testCase.expectErr); - - if (err == CHIP_NO_ERROR) - { - // Make sure the number of addresses is within the max expected. - NL_TEST_ASSERT(testSuite, addrCount <= testCase.maxResults); - - // Determine the types of addresses in the response and their relative ordering. - bool respContainsIPv4Addrs = false; - bool respContainsIPv6Addrs = false; - - for (uint8_t i = 0; i < addrCount; i++) - { -#if INET_CONFIG_ENABLE_IPV4 - respContainsIPv4Addrs = respContainsIPv4Addrs || (addrArray[i].Type() == kIPAddressType_IPv4); -#endif - respContainsIPv6Addrs = respContainsIPv6Addrs || (addrArray[i].Type() == kIPAddressType_IPv6); - } - - // Verify the expected address types were returned. - // The current LwIP DNS implementation returns at most one address. So if the test expects - // both IPv4 and IPv6 addresses, relax this to accept either. -#if CHIP_SYSTEM_CONFIG_USE_LWIP - if (testCase.expectIPv4Addrs && testCase.expectIPv6Addrs) - { - NL_TEST_ASSERT(testSuite, respContainsIPv4Addrs || respContainsIPv6Addrs); - } - else -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP - { - if (testCase.expectIPv4Addrs) - { -#if INET_CONFIG_ENABLE_IPV4 - NL_TEST_ASSERT(testSuite, respContainsIPv4Addrs); -#else - // IP-v4 test ran without IPv4 support - NL_TEST_ASSERT(testSuite, false); -#endif - } - - if (testCase.expectIPv6Addrs) - { - NL_TEST_ASSERT(testSuite, respContainsIPv6Addrs); - } - } - - // Verify that only the requested address types were returned, and that the - // addresses were returned in the correct order. - switch (testCase.dnsOptions & kDNSOption_AddrFamily_Mask) - { - case kDNSOption_AddrFamily_Any: - break; -#if INET_CONFIG_ENABLE_IPV4 - case kDNSOption_AddrFamily_IPv4Only: - NL_TEST_ASSERT(testSuite, !respContainsIPv6Addrs); - break; - case kDNSOption_AddrFamily_IPv4Preferred: - if (respContainsIPv4Addrs) - { - NL_TEST_ASSERT(testSuite, addrArray[0].Type() == kIPAddressType_IPv4); - } - break; -#endif - case kDNSOption_AddrFamily_IPv6Only: - NL_TEST_ASSERT(testSuite, !respContainsIPv4Addrs); - break; - case kDNSOption_AddrFamily_IPv6Preferred: - if (respContainsIPv6Addrs) - { - NL_TEST_ASSERT(testSuite, addrArray[0].Type() == kIPAddressType_IPv6); - } - break; - default: - constexpr bool UnexpectedAddressTypeValue = true; - NL_TEST_ASSERT(testSuite, !UnexpectedAddressTypeValue); - } - } - - testContext.callbackCalled = true; - - sNumResInProgress--; - if (sNumResInProgress == 0) - { - gDone = true; - } -} - -static void ServiceNetworkUntilDone(uint32_t timeoutMilliseconds) -{ - uint64_t timeoutTimeMilliseconds = System::SystemClock().GetMonotonicMilliseconds() + timeoutMilliseconds; - constexpr uint32_t kSleepTimeMilliseconds = 10; - - while (!gDone) - { - ServiceNetwork(kSleepTimeMilliseconds); - - if (System::SystemClock().GetMonotonicMilliseconds() >= timeoutTimeMilliseconds) - { - break; - } - } -} - -static void HandleSIGUSR1(int sig) -{ - gInet.Shutdown(); - - exit(0); -} - -int TestInetLayerDNSInternal() -{ - // clang-format off - const nlTest DNSTests[] = - { - NL_TEST_DEF("TestDNSResolution:Basic", TestDNSResolution_Basic), - NL_TEST_DEF("TestDNSResolution:AddressTypeOption", TestDNSResolution_AddressTypeOption), - NL_TEST_DEF("TestDNSResolution:RestrictedResults", TestDNSResolution_RestrictedResults), - NL_TEST_DEF("TestDNSResolution:TextForm", TestDNSResolution_TextForm), - NL_TEST_DEF("TestDNSResolution:NoRecord", TestDNSResolution_NoRecord), - NL_TEST_DEF("TestDNSResolution:NoHostRecord", TestDNSResolution_NoHostRecord), - NL_TEST_DEF("TestDNSResolution:Cancel", TestDNSResolution_Cancel), - NL_TEST_DEF("TestDNSResolution:Simultaneous", TestDNSResolution_Simultaneous), - NL_TEST_SENTINEL() }; - - nlTestSuite DNSTestSuite = - { - "DNS", - &DNSTests[0], - nullptr, - nullptr - }; - // clang-format on - - InitTestInetCommon(); - - InitSystemLayer(); - InitNetwork(); - - // Run all tests in Suite - - nlTestRunner(&DNSTestSuite, nullptr); - - ShutdownNetwork(); - ShutdownSystemLayer(); - - return nlTestRunnerStats(&DNSTestSuite); -} - -CHIP_REGISTER_TEST_SUITE(TestInetLayerDNSInternal) -#else // !INET_CONFIG_ENABLE_DNS_RESOLVER - -int TestInetLayerDNSInternal(void) -{ - fprintf(stderr, "Please assert INET_CONFIG_ENABLE_DNS_RESOLVER to use this test.\n"); - - return (EXIT_SUCCESS); -} - -#endif // !INET_CONFIG_ENABLE_DNS_RESOLVER - -int TestInetLayerDNS() -{ - SetSignalHandler(HandleSIGUSR1); - - nlTestSetOutputStyle(OUTPUT_CSV); - - return (TestInetLayerDNSInternal()); -} diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index b09283b05e5122..60116d4958e953 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -1425,16 +1425,6 @@ #define CHIP_CONFIG_TEST_SHARED_SECRET_VALUE "Test secret for key derivation." #endif // CHIP_CONFIG_TEST_SHARED_SECRET_VALUE -/** - * @def CHIP_CONFIG_ENABLE_DNS_RESOLVER - * - * @brief - * Enable support for resolving hostnames with a DNS resolver. - */ -#ifndef CHIP_CONFIG_ENABLE_DNS_RESOLVER -#define CHIP_CONFIG_ENABLE_DNS_RESOLVER (INET_CONFIG_ENABLE_DNS_RESOLVER) -#endif // CHIP_CONFIG_ENABLE_DNS_RESOLVER - /** * @def CHIP_CONFIG_RESOLVE_IPADDR_LITERAL * diff --git a/src/platform/Ameba/args.gni b/src/platform/Ameba/args.gni index ec9564464efd68..dd6b1bcdb9ca8f 100755 --- a/src/platform/Ameba/args.gni +++ b/src/platform/Ameba/args.gni @@ -20,7 +20,6 @@ lwip_platform = "external" mbedtls_target = "//mbedtls:mbedtls" chip_build_tests = false -chip_inet_config_enable_dns_resolver = false chip_inet_config_enable_tun_endpoint = false chip_inet_config_enable_tcp_endpoint = true chip_inet_config_enable_udp_endpoint = true diff --git a/src/platform/EFR32/args.gni b/src/platform/EFR32/args.gni index 0e96994af4b6d9..73e2fc12c4be01 100644 --- a/src/platform/EFR32/args.gni +++ b/src/platform/EFR32/args.gni @@ -31,7 +31,6 @@ chip_mdns = "platform" lwip_platform = "efr32" chip_inet_config_enable_ipv4 = false -chip_inet_config_enable_dns_resolver = false chip_build_tests = false diff --git a/src/platform/P6/args.gni b/src/platform/P6/args.gni index f547b5575d44d4..e16170a519e15e 100644 --- a/src/platform/P6/args.gni +++ b/src/platform/P6/args.gni @@ -26,6 +26,4 @@ chip_device_platform = "p6" lwip_platform = "p6" -chip_inet_config_enable_dns_resolver = false - chip_build_tests = false diff --git a/src/platform/cc13x2_26x2/args.gni b/src/platform/cc13x2_26x2/args.gni index 3669b05afacfb8..7963e911e3e648 100644 --- a/src/platform/cc13x2_26x2/args.gni +++ b/src/platform/cc13x2_26x2/args.gni @@ -29,7 +29,6 @@ openthread_external_platform = lwip_platform = "cc13x2_26x2" chip_inet_config_enable_ipv4 = false -chip_inet_config_enable_dns_resolver = false chip_build_tests = false diff --git a/src/platform/nxp/k32w/k32w0/args.gni b/src/platform/nxp/k32w/k32w0/args.gni index 5565dea1ee9dba..74d4b41b49c486 100644 --- a/src/platform/nxp/k32w/k32w0/args.gni +++ b/src/platform/nxp/k32w/k32w0/args.gni @@ -21,7 +21,6 @@ chip_device_platform = "k32w0" lwip_platform = "k32w0" chip_inet_config_enable_ipv4 = false -chip_inet_config_enable_dns_resolver = false chip_inet_config_enable_tcp_endpoint = false diff --git a/src/platform/qpg/args.gni b/src/platform/qpg/args.gni index 386dc90cebe1d9..28525a023d8256 100644 --- a/src/platform/qpg/args.gni +++ b/src/platform/qpg/args.gni @@ -26,7 +26,6 @@ chip_mdns = "platform" lwip_platform = "qpg" chip_inet_config_enable_ipv4 = false -chip_inet_config_enable_dns_resolver = false chip_inet_config_enable_tcp_endpoint = false # Size opt's diff --git a/src/system/SystemLayerImplSelect.h b/src/system/SystemLayerImplSelect.h index 6db3abcef30b60..8b2c29c808a81d 100644 --- a/src/system/SystemLayerImplSelect.h +++ b/src/system/SystemLayerImplSelect.h @@ -78,8 +78,7 @@ class LayerImplSelect : public LayerSocketsLoop static SocketEvents SocketEventsFromFDs(int socket, const fd_set & readfds, const fd_set & writefds, const fd_set & exceptfds); static constexpr int kSocketWatchMax = (INET_CONFIG_ENABLE_TCP_ENDPOINT ? INET_CONFIG_NUM_TCP_ENDPOINTS : 0) + - (INET_CONFIG_ENABLE_UDP_ENDPOINT ? INET_CONFIG_NUM_UDP_ENDPOINTS : 0) + - (INET_CONFIG_ENABLE_DNS_RESOLVER ? INET_CONFIG_NUM_DNS_RESOLVERS : 0); + (INET_CONFIG_ENABLE_UDP_ENDPOINT ? INET_CONFIG_NUM_UDP_ENDPOINTS : 0); struct SocketWatch { diff --git a/src/system/SystemStats.cpp b/src/system/SystemStats.cpp index 20169719db4f4f..57f6a4ee475f9e 100644 --- a/src/system/SystemStats.cpp +++ b/src/system/SystemStats.cpp @@ -51,11 +51,7 @@ static const Label sStatsStrings[chip::System::Stats::kNumEntries] = { #if INET_CONFIG_NUM_UDP_ENDPOINTS "InetLayer_NumUDPEpsInUse", #endif -#if INET_CONFIG_NUM_DNS_RESOLVERS - "InetLayer_NumDNSResolversInUse", -#endif - "ExchangeMgr_NumContextsInUse", "ExchangeMgr_NumUMHandlersInUse", - "ExchangeMgr_NumBindings", "MessageLayer_NumConnectionsInUse", + "ExchangeMgr_NumContextsInUse", "ExchangeMgr_NumUMHandlersInUse", "ExchangeMgr_NumBindings", "MessageLayer_NumConnectionsInUse", }; count_t sResourcesInUse[kNumEntries]; diff --git a/src/system/SystemStats.h b/src/system/SystemStats.h index f80cf93b7738ca..78bc5b7c57a779 100644 --- a/src/system/SystemStats.h +++ b/src/system/SystemStats.h @@ -65,9 +65,6 @@ enum #endif #if INET_CONFIG_NUM_UDP_ENDPOINTS kInetLayer_NumUDPEps, -#endif -#if INET_CONFIG_NUM_DNS_RESOLVERS - kInetLayer_NumDNSResolvers, #endif kExchangeMgr_NumContexts, kExchangeMgr_NumUMHandlers,