cache: send multiple queries in a single packet
authorFelix Fietkau <[email protected]>
Wed, 28 May 2025 19:58:59 +0000 (21:58 +0200)
committerFelix Fietkau <[email protected]>
Wed, 28 May 2025 21:11:27 +0000 (23:11 +0200)
Signed-off-by: Felix Fietkau <[email protected]>
cache.c
dns.c
dns.h

diff --git a/cache.c b/cache.c
index 55a0e1634bd9348a478d24d786f82ab6ad5c932f..19577b23117871034f1583455c14083f4d48ec59 100644 (file)
--- a/cache.c
+++ b/cache.c
@@ -143,16 +143,21 @@ 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, 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));
+       int count = 2;
+
+       dns_packet_init();
+       dns_packet_question(C_DNS_SD, TYPE_ANY);
+       dns_packet_question(C_DNS_SD, TYPE_PTR);
+       avl_for_each_element(&services, s, avl) {
+               dns_packet_question(s->entry, TYPE_PTR);
+               if (++count < 16)
+                       continue;
+               dns_packet_broadcast();
+               count = 0;
        }
+
+       if (count)
+               dns_packet_broadcast();
 }
 
 static struct cache_service*
diff --git a/dns.c b/dns.c
index ffa61ba4acd0e80c8e0081167a68d30bbbbfc67b..715125b8b782bf6016ac5dcda9509a48d33bd0bf 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -185,6 +185,14 @@ void dns_packet_send(struct interface *iface, struct sockaddr *to, bool query, i
                perror("failed to send answer");
 }
 
+void dns_packet_broadcast(void)
+{
+       struct interface *iface;
+
+       vlist_for_each_element(&interfaces, iface, node)
+               dns_packet_send(iface, NULL, 1, -1);
+}
+
 void
 dns_send_question(struct interface *iface, struct sockaddr *to,
                  const char *question, int type, int multicast)
diff --git a/dns.h b/dns.h
index d6991e06423e43f0e3ec51c73a50fa4294e8cf6e..65efcf7be1a89b917307957b9f4ef4b734294d66 100644 (file)
--- a/dns.h
+++ b/dns.h
@@ -77,6 +77,7 @@ void dns_packet_init(void);
 bool dns_packet_question(const char *name, int type);
 void dns_packet_answer(const char *name, int type, const uint8_t *rdata, uint16_t rdlength, int ttl);
 void dns_packet_send(struct interface *iface, struct sockaddr *to, bool query, int multicast);
+void dns_packet_broadcast(void);
 
 void dns_send_question(struct interface *iface, struct sockaddr *to,
                       const char *question, int type, int multicast);