From: Felix Fietkau Date: Wed, 28 May 2025 21:50:50 +0000 (+0200) Subject: cache: improve service refresh behavior X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=083be33749b17468993fbc40e0646c1b0690e837;p=project%2Fmdnsd.git cache: improve service refresh behavior - query services on all interfaces (in case they moved) - query both PTR and A/AAAA records Signed-off-by: Felix Fietkau --- diff --git a/cache.c b/cache.c index 0ccac49..36fee9c 100644 --- a/cache.c +++ b/cache.c @@ -75,6 +75,18 @@ cache_is_expired(time_t t, uint32_t ttl, int frac) return 0; } +static void +cache_refresh_service(struct cache_service *s) +{ + dns_query(s->entry, TYPE_PTR); + + if (!s->host) + return; + + dns_query(s->host, TYPE_A); + dns_query(s->host, TYPE_AAAA); +} + static void cache_gc_timer(struct uloop_timeout *timeout) { @@ -108,7 +120,7 @@ cache_gc_timer(struct uloop_timeout *timeout) continue; } s->refresh += 50; - dns_send_question(s->iface, NULL, s->entry, TYPE_PTR, 0); + cache_refresh_service(s); } uloop_timeout_set(timeout, 10000); @@ -146,14 +158,8 @@ cache_update(void) dns_query(C_DNS_SD, TYPE_ANY); dns_query(C_DNS_SD, TYPE_PTR); - avl_for_each_element(&services, s, avl) { - if (s->host) { - dns_query(s->host, TYPE_A); - dns_query(s->host, TYPE_AAAA); - } else { - dns_query(s->entry, TYPE_PTR); - } - } + avl_for_each_element(&services, s, avl) + cache_refresh_service(s); } static struct cache_service* @@ -194,12 +200,7 @@ cache_service(struct interface *iface, char *entry, int hlen, int ttl) s->avl.key = type; avl_insert(&services, &s->avl); - if (hlen) { - dns_query(s->host, TYPE_A); - dns_query(s->host, TYPE_AAAA); - } else { - dns_query(entry, TYPE_PTR); - } + cache_refresh_service(s); return s; }