MINOR: dns: make 'ancount' field to match the number of saved records
ancount is the number of answers available in a DNS response.
Before this patch, HAProxy used to store the ancount found in the buffer
(sent by the DNS server).
Unfortunately, this is now inaccurate and does not correspond to the
number of records effectively stored in our local version of the
response. In Example, the CNAMEs are not stored.
This patch updates ancount field in to make it match what is effectively
stored in our version.
diff --git a/src/dns.c b/src/dns.c
index 45444fd..0193f73 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -467,6 +467,7 @@
char *previous_dname, tmpname[DNS_MAX_NAME_SIZE];
int len, flags, offset, ret;
int dns_query_record_id, dns_answer_record_id;
+ int nb_saved_records;
struct dns_query_item *dns_query;
struct dns_answer_item *dns_answer_record;
struct dns_response_packet *dns_p;
@@ -591,6 +592,7 @@
/* now parsing response records */
LIST_INIT(&dns_p->answer_list);
+ nb_saved_records = 0;
for (dns_answer_record_id = 0; dns_answer_record_id < dns_p->header.ancount; dns_answer_record_id++) {
if (reader >= bufend)
return DNS_RESP_INVALID;
@@ -717,6 +719,9 @@
} /* switch (record type) */
+ /* increment the counter for number of records saved into our local response */
+ nb_saved_records += 1;
+
/* move forward dns_answer_record->data_len for analyzing next record in the response */
reader += dns_answer_record->data_len;
} /* for i 0 to ancount */
@@ -726,6 +731,9 @@
if (ret == 0)
return DNS_RESP_INVALID;
+ /* save the number of records we really own */
+ dns_p->header.ancount = nb_saved_records;
+
return DNS_RESP_VALID;
}