From 69fce67b56f2fda613604e0520adb64d209041a8 Mon Sep 17 00:00:00 2001 From: Baptiste Assmann Date: Thu, 4 May 2017 08:37:45 +0200 Subject: [PATCH] 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. --- src/dns.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/dns.c b/src/dns.c index 45444fdb3..0193f7396 100644 --- a/src/dns.c +++ b/src/dns.c @@ -467,6 +467,7 @@ int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, struct 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 @@ int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, struct /* 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 @@ int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, struct } /* 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 @@ int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, struct 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; }