]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve/mdns: do not append packets without records
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 8 Nov 2023 11:53:39 +0000 (20:53 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 8 Nov 2023 12:38:22 +0000 (21:38 +0900)
Previously, if we have only max_rr cached entries, then an empty packet
is appended.

Prompted by #29168.

src/resolve/resolved-dns-cache.c

index 7a1a1620afff8ed45077dd58ecfcf393c80b3210..78665bc93be6ad50651184e77d2e761b3f3d56f4 100644 (file)
@@ -1308,6 +1308,19 @@ int dns_cache_export_shared_to_packet(DnsCache *cache, DnsPacket *p, usec_t ts,
                         if (usec_sub_unsigned(j->until, ts) < j->rr->ttl * USEC_PER_SEC / 2)
                                 continue;
 
+                        if (max_rr > 0 && ancount >= max_rr) {
+                                DNS_PACKET_HEADER(p)->ancount = htobe16(ancount);
+                                ancount = 0;
+
+                                r = dns_packet_new_query(&p->more, p->protocol, 0, true);
+                                if (r < 0)
+                                        return r;
+
+                                p = p->more;
+
+                                max_rr = UINT_MAX;
+                        }
+
                         r = dns_packet_append_rr(p, j->rr, 0, NULL, NULL);
                         if (r == -EMSGSIZE) {
                                 if (max_rr == 0)
@@ -1333,18 +1346,6 @@ int dns_cache_export_shared_to_packet(DnsCache *cache, DnsPacket *p, usec_t ts,
                                 return r;
 
                         ancount++;
-                        if (max_rr > 0 && ancount >= max_rr) {
-                                DNS_PACKET_HEADER(p)->ancount = htobe16(ancount);
-                                ancount = 0;
-
-                                r = dns_packet_new_query(&p->more, p->protocol, 0, true);
-                                if (r < 0)
-                                        return r;
-
-                                p = p->more;
-
-                                max_rr = UINT_MAX;
-                        }
                 }
 
 finalize: