Browse Source

net: dns: Introduce resolver function that avoids using the cache

Introduce dns_resolve_name_internal() that allows resolving a name
and not use DNS cache if caching is enabled.

This is needed in mDNS probing (RFC 6762 chapter 8.1) which needs
to send a mDNS query and not get any results from cache.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
pull/85655/head
Jukka Rissanen 6 months ago committed by Benjamin Cabé
parent
commit
af758e51a2
  1. 12
      subsys/net/ip/net_private.h
  2. 53
      subsys/net/lib/dns/resolve.c

12
subsys/net/ip/net_private.h

@ -154,6 +154,18 @@ extern void mdns_init_responder(void); @@ -154,6 +154,18 @@ extern void mdns_init_responder(void);
static inline void mdns_init_responder(void) { }
#endif /* CONFIG_MDNS_RESPONDER */
#if defined(CONFIG_DNS_RESOLVER)
#include <zephyr/net/dns_resolve.h>
extern int dns_resolve_name_internal(struct dns_resolve_context *ctx,
const char *query,
enum dns_query_type type,
uint16_t *dns_id,
dns_resolve_cb_t cb,
void *user_data,
int32_t timeout,
bool use_cache);
#endif /* CONFIG_DNS_RESOLVER */
#if defined(CONFIG_NET_TEST)
extern void loopback_enable_address_swap(bool swap_addresses);
#endif /* CONFIG_NET_TEST */

53
subsys/net/lib/dns/resolve.c

@ -1340,13 +1340,14 @@ static void query_timeout(struct k_work *work) @@ -1340,13 +1340,14 @@ static void query_timeout(struct k_work *work)
k_mutex_unlock(&pending_query->ctx->lock);
}
int dns_resolve_name(struct dns_resolve_context *ctx,
const char *query,
enum dns_query_type type,
uint16_t *dns_id,
dns_resolve_cb_t cb,
void *user_data,
int32_t timeout)
int dns_resolve_name_internal(struct dns_resolve_context *ctx,
const char *query,
enum dns_query_type type,
uint16_t *dns_id,
dns_resolve_cb_t cb,
void *user_data,
int32_t timeout,
bool use_cache)
{
k_timeout_t tout;
struct net_buf *dns_data = NULL;
@ -1421,18 +1422,24 @@ int dns_resolve_name(struct dns_resolve_context *ctx, @@ -1421,18 +1422,24 @@ int dns_resolve_name(struct dns_resolve_context *ctx,
try_resolve:
#ifdef CONFIG_DNS_RESOLVER_CACHE
ret = dns_cache_find(&dns_cache, query, type, cached_info, ARRAY_SIZE(cached_info));
if (ret > 0) {
/* The query was cached, no
* need to continue further.
*/
for (size_t cache_index = 0; cache_index < ret; cache_index++) {
cb(DNS_EAI_INPROGRESS, &cached_info[cache_index], user_data);
}
cb(DNS_EAI_ALLDONE, NULL, user_data);
if (use_cache) {
ret = dns_cache_find(&dns_cache, query, type, cached_info,
ARRAY_SIZE(cached_info));
if (ret > 0) {
/* The query was cached, no
* need to continue further.
*/
for (size_t cache_index = 0; cache_index < ret; cache_index++) {
cb(DNS_EAI_INPROGRESS, &cached_info[cache_index], user_data);
}
return 0;
cb(DNS_EAI_ALLDONE, NULL, user_data);
return 0;
}
}
#else
ARG_UNUSED(use_cache);
#endif /* CONFIG_DNS_RESOLVER_CACHE */
k_mutex_lock(&ctx->lock, K_FOREVER);
@ -1580,6 +1587,18 @@ fail: @@ -1580,6 +1587,18 @@ fail:
return ret;
}
int dns_resolve_name(struct dns_resolve_context *ctx,
const char *query,
enum dns_query_type type,
uint16_t *dns_id,
dns_resolve_cb_t cb,
void *user_data,
int32_t timeout)
{
return dns_resolve_name_internal(ctx, query, type, dns_id, cb,
user_data, timeout, true);
}
/* Must be invoked with context lock held */
static int dns_resolve_close_locked(struct dns_resolve_context *ctx)
{

Loading…
Cancel
Save