cache: improve service discovery reliability master
authorFelix Fietkau <nbd@nbd.name>
Mon, 10 Feb 2025 20:25:54 +0000 (21:25 +0100)
committerFelix Fietkau <nbd@nbd.name>
Mon, 10 Feb 2025 20:28:32 +0000 (21:28 +0100)
Send queries for non-host PTR services out to all interfaces instead of
just the one that they were first discovered on.
When updating, go through all non-host service entries and send a query.
When host records expire while non-host service entries remain, queries
were not automatically re-sent, causing some services with lower TTL to
be missed.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
cache.c

diff --git a/cache.c b/cache.c
index 2412ed2c8b733ba5c9be03b6a4a068a05bc31f58..55a0e1634bd9348a478d24d786f82ab6ad5c932f 100644 (file)
--- a/cache.c
+++ b/cache.c
@@ -142,11 +142,16 @@ void cache_cleanup(struct interface *iface)
 void
 cache_update(void)
 {
+       struct cache_service *s;
        struct interface *iface;
 
        vlist_for_each_element(&interfaces, iface, node) {
-               dns_send_question(iface, NULL, C_DNS_SD, TYPE_ANY, 0);
-               dns_send_question(iface, NULL, C_DNS_SD, TYPE_PTR, 0);
+               dns_send_question(iface, NULL, C_DNS_SD, TYPE_ANY, interface_multicast(iface));
+               dns_send_question(iface, NULL, C_DNS_SD, TYPE_PTR, interface_multicast(iface));
+               avl_for_each_element(&services, s, avl)
+                       if (!s->host)
+                               dns_send_question(iface, NULL, s->entry, TYPE_PTR,
+                                                 interface_multicast(iface));
        }
 }
 
@@ -186,7 +191,10 @@ cache_service(struct interface *iface, char *entry, int hlen, int ttl)
                s->avl.key = type;
        avl_insert(&services, &s->avl);
 
-       if (!hlen)
+       if (hlen)
+               return s;
+
+       vlist_for_each_element(&interfaces, iface, node)
                dns_send_question(iface, NULL, entry, TYPE_PTR, interface_multicast(iface));
 
        return s;