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);
static inline void mdns_init_responder(void) { } static inline void mdns_init_responder(void) { }
#endif /* CONFIG_MDNS_RESPONDER */ #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) #if defined(CONFIG_NET_TEST)
extern void loopback_enable_address_swap(bool swap_addresses); extern void loopback_enable_address_swap(bool swap_addresses);
#endif /* CONFIG_NET_TEST */ #endif /* CONFIG_NET_TEST */

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

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

Loading…
Cancel
Save