From ea40cfdf7eb05d845576d6acdddc449294b83e19 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 28 May 2025 21:58:59 +0200 Subject: [PATCH] cache: send multiple queries in a single packet Signed-off-by: Felix Fietkau --- cache.c | 23 ++++++++++++++--------- dns.c | 8 ++++++++ dns.h | 1 + 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cache.c b/cache.c index 55a0e16..19577b2 100644 --- 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 ffa61ba..715125b 100644 --- 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 d6991e0..65efcf7 100644 --- 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); -- 2.30.2