diff --git a/config/mbed/chip-gn/args.gni b/config/mbed/chip-gn/args.gni index b458740c9512b5..91ecf2aa53cceb 100644 --- a/config/mbed/chip-gn/args.gni +++ b/config/mbed/chip-gn/args.gni @@ -23,7 +23,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_inet_config_enable_async_dns_sockets = false chip_custom_build_cflags = [] diff --git a/src/inet/AsyncDNSResolverSockets.cpp b/src/inet/AsyncDNSResolverSockets.cpp deleted file mode 100644 index 45a7440601b792..00000000000000 --- a/src/inet/AsyncDNSResolverSockets.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 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 AsyncDNSResolverSockets, the object that implements - * Asynchronous Domain Name System (DNS) resolution in InetLayer. - * - */ -#include -#include -#include - -#include -#include -#include - -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS -#if INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - -#include "AsyncDNSResolverSockets.h" - -namespace chip { -namespace Inet { - -/** - * The explicit initializer for the AsynchronousDNSResolverSockets class. - * This initializes the mutex and semaphore variables and creates the - * threads for handling the asynchronous DNS resolution. - * - * @param[in] aInet A pointer to the InetLayer object. - * - * @retval #CHIP_NO_ERROR if initialization is - * successful. - * @retval other appropriate POSIX network or OS error. - */ -CHIP_ERROR AsyncDNSResolverSockets::Init(InetLayer * aInet) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int pthreadErr; - - mInet = aInet; - - mAsyncDNSQueueHead = nullptr; - mAsyncDNSQueueTail = nullptr; - - pthreadErr = pthread_cond_init(&mAsyncDNSCondVar, nullptr); - VerifyOrDie(pthreadErr == 0); - - pthreadErr = pthread_mutex_init(&mAsyncDNSMutex, nullptr); - VerifyOrDie(pthreadErr == 0); - - // Create the thread pool for asynchronous DNS resolution. - for (int i = 0; i < INET_CONFIG_DNS_ASYNC_MAX_THREAD_COUNT; i++) - { - pthreadErr = pthread_create(&mAsyncDNSThreadHandle[i], nullptr, &AsyncDNSThreadRun, this); - VerifyOrDie(pthreadErr == 0); - } - - return err; -} - -/** - * This is the explicit deinitializer of the AsyncDNSResolverSockets class - * and it takes care of shutting the threads down and destroying the mutex - * and semaphore variables. - * - * @retval #CHIP_NO_ERROR if shutdown is successful. - * @retval other appropriate POSIX network or OS error. - */ -CHIP_ERROR AsyncDNSResolverSockets::Shutdown() -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int pthreadErr; - - AsyncMutexLock(); - - mInet->State = InetLayer::kState_ShutdownInProgress; - - pthreadErr = pthread_cond_broadcast(&mAsyncDNSCondVar); - VerifyOrDie(pthreadErr == 0); - - AsyncMutexUnlock(); - - // Have the CHIP thread join the thread pool for asynchronous DNS resolution. - for (pthread_t thread : mAsyncDNSThreadHandle) - { - pthreadErr = pthread_join(thread, nullptr); - VerifyOrDie(pthreadErr == 0); - } - - pthreadErr = pthread_mutex_destroy(&mAsyncDNSMutex); - VerifyOrDie(pthreadErr == 0); - - pthreadErr = pthread_cond_destroy(&mAsyncDNSCondVar); - VerifyOrDie(pthreadErr == 0); - - return err; -} - -/** - * This method prepares a DNSResolver object prior to asynchronous resolution. - * - * @param[in] resolver A reference to an allocated DNSResolver object. - * - * @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] options An integer value controlling how host name address - * resolution is performed. Values are from the #DNSOptions - * enumeration. - * @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. - * - */ -CHIP_ERROR AsyncDNSResolverSockets::PrepareDNSResolver(DNSResolver & resolver, const char * hostName, uint16_t hostNameLen, - uint8_t options, uint8_t maxAddrs, IPAddress * addrArray, - DNSResolver::OnResolveCompleteFunct onComplete, void * appState) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - memcpy(resolver.asyncHostNameBuf, hostName, hostNameLen); - resolver.asyncHostNameBuf[hostNameLen] = 0; - resolver.MaxAddrs = maxAddrs; - resolver.NumAddrs = 0; - resolver.DNSOptions = options; - resolver.AddrArray = addrArray; - resolver.AppState = appState; - resolver.OnComplete = onComplete; - resolver.asyncDNSResolveResult = CHIP_NO_ERROR; - resolver.mState = DNSResolver::kState_Active; - resolver.pNextAsyncDNSResolver = nullptr; - - return err; -} - -/** - * Enqueue a DNSResolver object for asynchronous IP address resolution of a specified hostname. - * - * @param[in] resolver A reference to the DNSResolver object. - * - * @retval #CHIP_NO_ERROR if a DNS request is queued - * successfully. - * @retval #CHIP_ERROR_NO_MEMORY if the Inet layer resolver pool - * is full. - * @retval other appropriate POSIX network or OS error. - * - */ -CHIP_ERROR AsyncDNSResolverSockets::EnqueueRequest(DNSResolver & resolver) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int pthreadErr; - - AsyncMutexLock(); - - // Add the DNSResolver object to the queue. - if (mAsyncDNSQueueHead == nullptr) - { - mAsyncDNSQueueHead = &resolver; - } - - if (mAsyncDNSQueueTail != nullptr) - { - mAsyncDNSQueueTail->pNextAsyncDNSResolver = &resolver; - } - - mAsyncDNSQueueTail = &resolver; - - pthreadErr = pthread_cond_signal(&mAsyncDNSCondVar); - VerifyOrDie(pthreadErr == 0); - - AsyncMutexUnlock(); - - return err; -} - -/** - * Dequeue a DNSResolver object from the queue if there is one. - * Make the worker thread block if there is no item in the queue. - * - */ -CHIP_ERROR AsyncDNSResolverSockets::DequeueRequest(DNSResolver ** outResolver) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int pthreadErr; - - AsyncMutexLock(); - - // block until there is work to do or we detect a shutdown - while ((mAsyncDNSQueueHead == nullptr) && (mInet->State == InetLayer::kState_Initialized)) - { - pthreadErr = pthread_cond_wait(&mAsyncDNSCondVar, &mAsyncDNSMutex); - VerifyOrDie(pthreadErr == 0); - } - - ChipLogDetail(Inet, "Async DNS worker thread woke up."); - - // on shutdown, return NULL. Otherwise, pop the head of the DNS request queue - if (mInet->State != InetLayer::kState_Initialized) - { - *outResolver = nullptr; - } - else - { - *outResolver = const_cast(mAsyncDNSQueueHead); - - mAsyncDNSQueueHead = mAsyncDNSQueueHead->pNextAsyncDNSResolver; - - if (mAsyncDNSQueueHead == nullptr) - { - // Queue is empty - mAsyncDNSQueueTail = nullptr; - } - } - - AsyncMutexUnlock(); - - return err; -} - -/** - * Cancel an outstanding DNS query that may still be active. - * - * @param[in] resolver A reference to the DNSResolver object. - */ -CHIP_ERROR AsyncDNSResolverSockets::Cancel(DNSResolver & resolver) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - AsyncMutexLock(); - - resolver.mState = DNSResolver::kState_Canceled; - - AsyncMutexUnlock(); - - return err; -} - -void AsyncDNSResolverSockets::UpdateDNSResult(DNSResolver & resolver, struct addrinfo * inLookupRes) -{ - resolver.NumAddrs = 0; - - for (struct addrinfo * addr = inLookupRes; addr != nullptr && resolver.NumAddrs < resolver.MaxAddrs; - addr = addr->ai_next, resolver.NumAddrs++) - { - resolver.AddrArray[resolver.NumAddrs] = IPAddress::FromSockAddr(*addr->ai_addr); - } -} - -void AsyncDNSResolverSockets::Resolve(DNSResolver & resolver) -{ - struct addrinfo gaiHints; - struct addrinfo * gaiResults = nullptr; - int gaiReturnCode; - - // Configure the hints argument for getaddrinfo() - resolver.InitAddrInfoHints(gaiHints); - - // Call getaddrinfo() to perform the name resolution. - gaiReturnCode = getaddrinfo(resolver.asyncHostNameBuf, nullptr, &gaiHints, &gaiResults); - - // Mutex protects the read and write operation on resolver->mState - AsyncMutexLock(); - - // 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. - resolver.asyncDNSResolveResult = resolver.ProcessGetAddrInfoResult(gaiReturnCode, gaiResults); - - // Set the DNS resolver state. - resolver.mState = DNSResolver::kState_Complete; - - // Release lock. - AsyncMutexUnlock(); -} - -/* Event handler function for asynchronous DNS notification */ -void AsyncDNSResolverSockets::DNSResultEventHandler(chip::System::Layer * aLayer, void * aAppState) -{ - DNSResolver * resolver = static_cast(aAppState); - - if (resolver) - { - resolver->HandleAsyncResolveComplete(); - } -} - -void AsyncDNSResolverSockets::NotifyChipThread(DNSResolver * resolver) -{ - // Post work item via Timer Event for the CHIP thread - chip::System::Layer * lSystemLayer = resolver->Layer().SystemLayer(); - - ChipLogDetail(Inet, "Posting DNS completion event to CHIP thread."); - lSystemLayer->ScheduleWork(AsyncDNSResolverSockets::DNSResultEventHandler, resolver); -} - -void * AsyncDNSResolverSockets::AsyncDNSThreadRun(void * args) -{ - - CHIP_ERROR err = CHIP_NO_ERROR; - AsyncDNSResolverSockets * asyncResolver = static_cast(args); - - while (true) - { - DNSResolver * request = nullptr; - - // Dequeue a DNSResolver for resolution. This function would block until there - // is an item in the queue or shutdown has been called. - err = asyncResolver->DequeueRequest(&request); - - // If shutdown has been called, DeQueue would return with an empty request. - // In that case, break out of the loop and exit thread. - VerifyOrExit(err == CHIP_NO_ERROR && request != nullptr, ); - - if (request->mState != DNSResolver::kState_Canceled) - { - asyncResolver->Resolve(*request); - } - - asyncResolver->NotifyChipThread(request); - } - -exit: - ChipLogDetail(Inet, "Async DNS worker thread exiting."); - return nullptr; -} - -void AsyncDNSResolverSockets::AsyncMutexLock() -{ - int pthreadErr; - - pthreadErr = pthread_mutex_lock(&mAsyncDNSMutex); - VerifyOrDie(pthreadErr == 0); -} - -void AsyncDNSResolverSockets::AsyncMutexUnlock() -{ - int pthreadErr; - - pthreadErr = pthread_mutex_unlock(&mAsyncDNSMutex); - VerifyOrDie(pthreadErr == 0); -} - -} // namespace Inet -} // namespace chip -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS diff --git a/src/inet/AsyncDNSResolverSockets.h b/src/inet/AsyncDNSResolverSockets.h deleted file mode 100644 index 336e49caffc613..00000000000000 --- a/src/inet/AsyncDNSResolverSockets.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 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 the AsyncDNSResolver, the object that performs - * Asynchronous Domain Name System (DNS) resolution in InetLayer. - * - */ -#pragma once - -#include -#include - -#if INET_CONFIG_ENABLE_DNS_RESOLVER -#include -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER - -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS -#if INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS -#include -#include -#include - -namespace chip { -namespace Inet { - -/** - * @class AsyncDNSResolverSockets - * - * @brief - * This is an internal class to InetLayer that provides helper APIs for - * Asynchronous Domain Name System (DNS) resolution in InetLayer. - * There is no public interface available for the application layer. - * - */ -class AsyncDNSResolverSockets -{ - friend class InetLayer; - friend class DNSResolver; - -public: - CHIP_ERROR EnqueueRequest(DNSResolver & resolver); - - CHIP_ERROR Init(InetLayer * inet); - - CHIP_ERROR Cancel(DNSResolver & resolver); - - CHIP_ERROR Shutdown(); - - CHIP_ERROR PrepareDNSResolver(DNSResolver & resolver, const char * hostName, uint16_t hostNameLen, uint8_t options, - uint8_t maxAddrs, IPAddress * addrArray, DNSResolver::OnResolveCompleteFunct onComplete, - void * appState); - -private: - pthread_t mAsyncDNSThreadHandle[INET_CONFIG_DNS_ASYNC_MAX_THREAD_COUNT]; - pthread_mutex_t mAsyncDNSMutex; /* Mutex for accessing the DNSResolver queue. */ - pthread_cond_t mAsyncDNSCondVar; /* Condition Variable for thread synchronization. */ - volatile DNSResolver * mAsyncDNSQueueHead; /* The head of the asynchronous DNSResolver object queue. */ - volatile DNSResolver * mAsyncDNSQueueTail; /* The tail of the asynchronous DNSResolver object queue. */ - InetLayer * mInet; /* The pointer to the InetLayer. */ - static void DNSResultEventHandler(chip::System::Layer * aLayer, - void * aAppState); /* Timer event handler function for asynchronous DNS notification */ - - CHIP_ERROR DequeueRequest(DNSResolver ** outResolver); - - bool ShouldThreadShutdown(); - - void Resolve(DNSResolver & resolver); - - void UpdateDNSResult(DNSResolver & resolver, struct addrinfo * lookupRes); - - static void * AsyncDNSThreadRun(void * args); - - static void NotifyChipThread(DNSResolver * resolver); - - void AsyncMutexLock(); - - void AsyncMutexUnlock(); -}; - -} // namespace Inet -} // namespace chip -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn index ce0bbf50cc802e..2f73a091174939 100644 --- a/src/inet/BUILD.gn +++ b/src/inet/BUILD.gn @@ -37,7 +37,6 @@ buildconfig_header("inet_buildconfig") { "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_ASYNC_DNS_SOCKETS=${chip_inet_config_enable_async_dns_sockets}", "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", @@ -126,13 +125,6 @@ static_library("inet") { ] } - if (chip_inet_config_enable_async_dns_sockets) { - sources += [ - "AsyncDNSResolverSockets.cpp", - "AsyncDNSResolverSockets.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 index e80cc5c09ab8a1..f22e5e1aa3f34f 100644 --- a/src/inet/DNSResolver.cpp +++ b/src/inet/DNSResolver.cpp @@ -251,17 +251,6 @@ CHIP_ERROR DNSResolver::ResolveImpl(char * hostNameBuf) CHIP_ERROR DNSResolver::Cancel() { -#if INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - // NOTE: DNS lookups can be canceled only when using the asynchronous mode. - - InetLayer & inet = Layer(); - - OnComplete = nullptr; - AppState = nullptr; - inet.mAsyncDNSResolver.Cancel(*this); - -#endif // INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - return CHIP_NO_ERROR; } @@ -440,19 +429,6 @@ uint8_t DNSResolver::CountAddresses(int family, const struct addrinfo * addrs) return count; } -#if INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS -void DNSResolver::HandleAsyncResolveComplete() -{ - // Copy the resolved address to the application supplied buffer, but only if the request hasn't been canceled. - if (OnComplete && mState != kState_Canceled) - { - OnComplete(AppState, asyncDNSResolveResult, NumAddrs, AddrArray); - } - - Release(); -} -#endif // INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS CHIP_ERROR DNSResolver::Resolve(const char * hostName, uint16_t hostNameLen, uint8_t options, uint8_t maxAddrs, diff --git a/src/inet/DNSResolver.h b/src/inet/DNSResolver.h index 6d1edf98533d48..327e799d34ceaf 100644 --- a/src/inet/DNSResolver.h +++ b/src/inet/DNSResolver.h @@ -75,20 +75,6 @@ class DNSResolver : public InetLayerBasis private: friend class InetLayer; -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS -#if INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - friend class AsyncDNSResolverSockets; - - /// States of the DNSResolver object with respect to hostname resolution. - typedef enum DNSResolverState{ - kState_Unused = 0, ///< Used to indicate that the DNSResolver object is not used. - kState_Active = 2, ///< Used to indicate that a DNS resolution is being performed on the DNSResolver object. - kState_Complete = 3, ///< Used to indicate that the DNS resolution on the DNSResolver object is complete. - kState_Canceled = 4, ///< Used to indicate that the DNS resolution on the DNSResolver has been canceled. - } DNSResolverState; -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS -#endif // INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - /** * @brief Type of event handling function called when a DNS request completes. * @@ -177,21 +163,6 @@ class DNSResolver : public InetLayerBasis void CopyAddresses(int family, uint8_t maxAddrs, const struct addrinfo * addrs); uint8_t CountAddresses(int family, const struct addrinfo * addrs); -#if INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - - /* Hostname that requires resolution */ - char asyncHostNameBuf[NL_DNS_HOSTNAME_MAX_LEN + 1]; // DNS limits hostnames to 253 max characters. - - CHIP_ERROR asyncDNSResolveResult; - /* The next DNSResolver object in the asynchronous DNS resolution queue. */ - DNSResolver * pNextAsyncDNSResolver; - - DNSResolverState mState; - - void HandleAsyncResolveComplete(); - -#endif // INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS #if CHIP_SYSTEM_CONFIG_USE_LWIP diff --git a/src/inet/InetConfig.h b/src/inet/InetConfig.h index 04533c08abef17..01b77c2ed24344 100644 --- a/src/inet/InetConfig.h +++ b/src/inet/InetConfig.h @@ -278,25 +278,6 @@ #define INET_CONFIG_TEST 0 #endif -/** - * @def INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - * - * @brief Enable asynchronous dns name resolution for Linux sockets. - */ -#ifndef INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS -#define INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS 1 -#endif // INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - -/** - * @def INET_CONFIG_DNS_ASYNC_MAX_THREAD_COUNT - * - * @brief The maximum number of POSIX threads that would be performing - * asynchronous DNS resolution. - */ -#ifndef INET_CONFIG_DNS_ASYNC_MAX_THREAD_COUNT -#define INET_CONFIG_DNS_ASYNC_MAX_THREAD_COUNT 2 -#endif // INET_CONFIG_DNS_ASYNC_MAX_THREAD_COUNT - /** * @def INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT * diff --git a/src/inet/InetLayer.cpp b/src/inet/InetLayer.cpp index 4ffeabf9152827..51c00b6d194ea5 100644 --- a/src/inet/InetLayer.cpp +++ b/src/inet/InetLayer.cpp @@ -262,10 +262,6 @@ CHIP_ERROR InetLayer::Init(chip::System::Layer & aSystemLayer, void * aContext) State = kState_Initialized; -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - ReturnErrorOnFailure(mAsyncDNSResolver.Init(this)); -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - return CHIP_NO_ERROR; } @@ -292,12 +288,6 @@ CHIP_ERROR InetLayer::Shutdown() } return true; }); - -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - - err = mAsyncDNSResolver.Shutdown(); - -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS #endif // INET_CONFIG_ENABLE_DNS_RESOLVER #if INET_CONFIG_ENABLE_TCP_ENDPOINT @@ -686,16 +676,15 @@ CHIP_ERROR InetLayer::ResolveHostAddress(const char * hostName, uint16_t hostNam { assertChipStackLockedByCurrentThread(); - CHIP_ERROR err = CHIP_NO_ERROR; DNSResolver * resolver = nullptr; - VerifyOrExit(State == kState_Initialized, err = CHIP_ERROR_INCORRECT_STATE); + 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. - VerifyOrExit(hostNameLen <= NL_DNS_HOSTNAME_MAX_LEN, err = INET_ERROR_HOST_NAME_TOO_LONG); - VerifyOrExit(maxAddrs > 0, err = CHIP_ERROR_NO_MEMORY); + 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) @@ -705,13 +694,14 @@ CHIP_ERROR InetLayer::ResolveHostAddress(const char * hostName, uint16_t hostNam else { ChipLogError(Inet, "%s resolver pool FULL", "DNS"); - ExitNow(err = CHIP_ERROR_NO_MEMORY); + 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(); @@ -732,30 +722,14 @@ CHIP_ERROR InetLayer::ResolveHostAddress(const char * hostName, uint16_t hostNam resolver->Release(); resolver = nullptr; - ExitNow(err = CHIP_NO_ERROR); + return CHIP_NO_ERROR; } // After this point, the resolver will be released by: - // - mAsyncDNSResolver (in case of ASYNC_DNS_SOCKETS) // - resolver->Resolve() (in case of synchronous resolving) // - the event handlers (in case of LwIP) -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - - err = - mAsyncDNSResolver.PrepareDNSResolver(*resolver, hostName, hostNameLen, options, maxAddrs, addrArray, onComplete, appState); - SuccessOrExit(err); - - mAsyncDNSResolver.EnqueueRequest(*resolver); - -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - -#if !INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - err = resolver->Resolve(hostName, hostNameLen, options, maxAddrs, addrArray, onComplete, appState); -#endif // !INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS -exit: - - return err; + return resolver->Resolve(hostName, hostNameLen, options, maxAddrs, addrArray, onComplete, appState); } /** @@ -797,13 +771,6 @@ void InetLayer::CancelResolveHostAddress(DNSResolveCompleteFunct onComplete, voi return true; } -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - if (lResolver->mState == DNSResolver::kState_Canceled) - { - return true; - } -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - lResolver->Cancel(); return false; }); diff --git a/src/inet/InetLayer.h b/src/inet/InetLayer.h index b557cc01a2259e..521ecb7cc4f6a1 100644 --- a/src/inet/InetLayer.h +++ b/src/inet/InetLayer.h @@ -69,14 +69,6 @@ #include #endif // INET_CONFIG_ENABLE_UDP_ENDPOINT -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS - -#if INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS -#include -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - #include #include @@ -129,9 +121,6 @@ class DLL_EXPORT InetLayer { #if INET_CONFIG_ENABLE_DNS_RESOLVER friend class DNSResolver; -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - friend class AsyncDNSResolverSockets; -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS #endif // INET_CONFIG_ENABLE_DNS_RESOLVER #if INET_CONFIG_ENABLE_TCP_ENDPOINT @@ -261,13 +250,6 @@ class DLL_EXPORT InetLayer void * mPlatformData; chip::System::Layer * mSystemLayer; -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS -#if INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - AsyncDNSResolverSockets mAsyncDNSResolver; -#endif // INET_CONFIG_ENABLE_DNS_RESOLVER && INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS - -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS - bool IsIdleTimerRunning(); }; diff --git a/src/inet/inet.gni b/src/inet/inet.gni index ed1199c27b00df..de476e86a47654 100644 --- a/src/inet/inet.gni +++ b/src/inet/inet.gni @@ -29,10 +29,3 @@ declare_args() { # Enable TCP endpoint. chip_inet_config_enable_tcp_endpoint = true } - -declare_args() { - # Enable async DNS. - chip_inet_config_enable_async_dns_sockets = - chip_inet_config_enable_dns_resolver && chip_system_config_use_sockets && - !chip_system_config_use_dispatch -}