summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau2025-05-28 19:58:59 +0000
committerFelix Fietkau2025-05-28 21:11:27 +0000
commitea40cfdf7eb05d845576d6acdddc449294b83e19 (patch)
treec37f5c2dd049b0909a2b0914ffcec43337e0c8ce
parentca9b8765aea3a7d22d1fd941aaf653f72628556b (diff)
downloadmdnsd-ea40cfdf7eb05d845576d6acdddc449294b83e19.tar.gz
cache: send multiple queries in a single packet
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--cache.c23
-rw-r--r--dns.c8
-rw-r--r--dns.h1
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);