diff options
| author | Felix Fietkau | 2025-05-28 19:58:59 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2025-05-28 21:11:27 +0000 |
| commit | ea40cfdf7eb05d845576d6acdddc449294b83e19 (patch) | |
| tree | c37f5c2dd049b0909a2b0914ffcec43337e0c8ce | |
| parent | ca9b8765aea3a7d22d1fd941aaf653f72628556b (diff) | |
| download | mdnsd-ea40cfdf7eb05d845576d6acdddc449294b83e19.tar.gz | |
cache: send multiple queries in a single packet
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | cache.c | 23 | ||||
| -rw-r--r-- | dns.c | 8 | ||||
| -rw-r--r-- | dns.h | 1 |
3 files changed, 23 insertions, 9 deletions
@@ -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* @@ -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) @@ -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); |