Skip to content

Commit 58e329a

Browse files
yuwatakeszybz
authored andcommitted
resolve/mdns: do not append packets without records
Previously, if we have only max_rr cached entries, then an empty packet is appended. Prompted by #29168. (cherry picked from commit 6cfa4fc) (cherry picked from commit 05e31c7)
1 parent c92df55 commit 58e329a

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/resolve/resolved-dns-cache.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,19 @@ int dns_cache_export_shared_to_packet(DnsCache *cache, DnsPacket *p, usec_t ts,
12711271
if (usec_sub_unsigned(j->until, ts) < j->rr->ttl * USEC_PER_SEC / 2)
12721272
continue;
12731273

1274+
if (max_rr > 0 && ancount >= max_rr) {
1275+
DNS_PACKET_HEADER(p)->ancount = htobe16(ancount);
1276+
ancount = 0;
1277+
1278+
r = dns_packet_new_query(&p->more, p->protocol, 0, true);
1279+
if (r < 0)
1280+
return r;
1281+
1282+
p = p->more;
1283+
1284+
max_rr = UINT_MAX;
1285+
}
1286+
12741287
r = dns_packet_append_rr(p, j->rr, 0, NULL, NULL);
12751288
if (r == -EMSGSIZE) {
12761289
if (max_rr == 0)
@@ -1296,18 +1309,6 @@ int dns_cache_export_shared_to_packet(DnsCache *cache, DnsPacket *p, usec_t ts,
12961309
return r;
12971310

12981311
ancount++;
1299-
if (max_rr > 0 && ancount >= max_rr) {
1300-
DNS_PACKET_HEADER(p)->ancount = htobe16(ancount);
1301-
ancount = 0;
1302-
1303-
r = dns_packet_new_query(&p->more, p->protocol, 0, true);
1304-
if (r < 0)
1305-
return r;
1306-
1307-
p = p->more;
1308-
1309-
max_rr = UINT_MAX;
1310-
}
13111312
}
13121313

13131314
finalize:

0 commit comments

Comments
 (0)