From 6f76e68a3c2a986600bc1bbdce957b9415b06db7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 5 Nov 2020 09:53:02 +0100 Subject: resolved: if dns_packet_append_answer() fails count how many RRs were successfully added This is useful later when handling the truncation case: if we can't add all RRs we'd like to add we need to set the TC bit, but still report the number of RRs we added (and not the number of RRs we would have liked to add) to the packet. --- src/resolve/resolved-dns-scope.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/resolve/resolved-dns-scope.c') diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index 7db906b0ad..15a3120e1a 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -765,6 +765,7 @@ int dns_scope_make_reply_packet( DnsPacket **ret) { _cleanup_(dns_packet_unrefp) DnsPacket *p = NULL; + unsigned n_answer = 0, n_soa = 0; int r; assert(s); @@ -796,15 +797,15 @@ int dns_scope_make_reply_packet( return r; DNS_PACKET_HEADER(p)->qdcount = htobe16(dns_question_size(q)); - r = dns_packet_append_answer(p, answer); + r = dns_packet_append_answer(p, answer, &n_answer); if (r < 0) return r; - DNS_PACKET_HEADER(p)->ancount = htobe16(dns_answer_size(answer)); + DNS_PACKET_HEADER(p)->ancount = htobe16(n_answer); - r = dns_packet_append_answer(p, soa); + r = dns_packet_append_answer(p, soa, &n_soa); if (r < 0) return r; - DNS_PACKET_HEADER(p)->arcount = htobe16(dns_answer_size(soa)); + DNS_PACKET_HEADER(p)->arcount = htobe16(n_soa); *ret = TAKE_PTR(p); -- cgit v1.2.3