mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[dns] signal an error immediately when no upstream DNS server available (#11480)
Currently, if the platform has no upstream DNS server configured, upstream DNS query will eventually time out. This can lead to delays in responding to the DNS client. The new otPlatDnsIsUpstreamQueryAvailable API provides a mechanism for the platform to proactively signal the unavailability of upstream DNS.
This commit is contained in:
@@ -32,6 +32,13 @@
|
||||
|
||||
#if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE
|
||||
|
||||
bool otPlatDnsIsUpstreamQueryAvailable(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void otPlatDnsStartUpstreamQuery(otInstance *aInstance, otPlatDnsUpstreamQuery *aTxn, const otMessage *aQuery)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
@@ -52,7 +52,7 @@ extern "C" {
|
||||
*
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (508)
|
||||
#define OPENTHREAD_API_VERSION (509)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -56,6 +56,23 @@ extern "C" {
|
||||
*/
|
||||
typedef struct otPlatDnsUpstreamQuery otPlatDnsUpstreamQuery;
|
||||
|
||||
/**
|
||||
* Indicates whether upstream DNS query functionality is available on the platform.
|
||||
*
|
||||
* This function allows the platform to inform the OpenThread stack if no upstream DNS server is
|
||||
* available.
|
||||
*
|
||||
* This function is used to optimize query handling. If this function returns `false` (e.g., no upstream DNS server is
|
||||
* currently available), one can avoid attempting an upstream resolution (which would likely time out) and instead
|
||||
* immediately send an appropriate negative response (e.g., `SERVFAIL`) to the DNS client.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance.
|
||||
*
|
||||
* @retval TRUE Upstream DNS query functionality is available.
|
||||
* @retval FALSE Upstream DNS query functionality is not available.
|
||||
*/
|
||||
bool otPlatDnsIsUpstreamQueryAvailable(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* Starts an upstream query transaction.
|
||||
*
|
||||
|
||||
@@ -1012,6 +1012,8 @@ Error Server::ResolveByUpstream(const Request &aRequest)
|
||||
txn = AllocateUpstreamQueryTransaction(*aRequest.mMessageInfo);
|
||||
VerifyOrExit(txn != nullptr, error = kErrorNoBufs);
|
||||
|
||||
VerifyOrExit(otPlatDnsIsUpstreamQueryAvailable(&GetInstance()), error = kErrorInvalidState);
|
||||
|
||||
otPlatDnsStartUpstreamQuery(&GetInstance(), txn, aRequest.mMessage);
|
||||
mCounters.mUpstreamDnsCounters.mQueries++;
|
||||
|
||||
@@ -2397,6 +2399,14 @@ bool Server::IsProxyAddressValid(const Ip6::Address &aAddress)
|
||||
} // namespace ot
|
||||
|
||||
#if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE && OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_MOCK_PLAT_APIS_ENABLE
|
||||
|
||||
bool otPlatDnsIsUpstreamQueryAvailable(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void otPlatDnsStartUpstreamQuery(otInstance *aInstance, otPlatDnsUpstreamQuery *aTxn, const otMessage *aQuery)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
@@ -97,6 +97,13 @@ void Resolver::TryRefreshDnsServerList(void)
|
||||
}
|
||||
}
|
||||
|
||||
bool Resolver::IsUpstreamQueryAvailable(void)
|
||||
{
|
||||
TryRefreshDnsServerList();
|
||||
|
||||
return mUpstreamDnsServerCount + mRecursiveDnsServerCount > 0;
|
||||
}
|
||||
|
||||
void Resolver::LoadDnsServerListFromConf(void)
|
||||
{
|
||||
std::string line;
|
||||
@@ -502,6 +509,13 @@ void platformResolverSetUp(void) { gResolver.Setup(); }
|
||||
|
||||
void platformResolverInit(void) { gResolver.Init(); }
|
||||
|
||||
bool otPlatDnsIsUpstreamQueryAvailable(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
return gResolver.IsUpstreamQueryAvailable();
|
||||
}
|
||||
|
||||
void otPlatDnsStartUpstreamQuery(otInstance *aInstance, otPlatDnsUpstreamQuery *aTxn, const otMessage *aQuery)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
@@ -64,6 +64,14 @@ public:
|
||||
*/
|
||||
void Setup(void);
|
||||
|
||||
/**
|
||||
* Indicates whether an upstream DNS server is available for queries.
|
||||
*
|
||||
* @retval TRUE An upstream DNS server is available.
|
||||
* @retval FALSE An upstream DNS server is not available.
|
||||
*/
|
||||
bool IsUpstreamQueryAvailable(void);
|
||||
|
||||
/**
|
||||
* Sends the query to the upstream.
|
||||
*
|
||||
|
||||
@@ -700,6 +700,13 @@ otError otPlatUdpLeaveMulticastGroup(otUdpSocket *aUdpSocket,
|
||||
#endif // OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
|
||||
|
||||
#if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE
|
||||
bool otPlatDnsIsUpstreamQueryAvailable(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void otPlatDnsStartUpstreamQuery(otInstance *aInstance, otPlatDnsUpstreamQuery *aTxn, const otMessage *aQuery)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
Reference in New Issue
Block a user