Hi,

This patch should fix github issue 971. I was not able to reproduce the bug
myself, but the behavior of HAProxy in Hynek's environment makes me think
this is a good candidate.

In short, when a server returns an SRV response with multiple SRV records
sharing the same target field value (the destination hostname) with a
different service port, and also provide the A/AAAA resolution in the
Additional section, then the first occurrence of the hostname is managed by
the Addtional section, while the second (and next) occurrence(s) will be
managed by a designated A/AAAA resolution.
This can lead to a divergence of resolution at some point, and in Hyneck's
case, the server managed via the A/AAAA resolution was not updated.

This patch ensures that every SRV record is linked to its Additional
records, so no divergence could happen anymore.

This should be backported to 2.2 and 2.3.
From b3c9ba9a7bf207c7f648a9885decc2631308850c Mon Sep 17 00:00:00 2001
From: Baptiste Assmann <[email protected]>
Date: Wed, 25 Nov 2020 08:17:59 +0100
Subject: [PATCH] BUG/MINOR: dns: SRV records ignores duplicated AR records

This bug happens when a service has multiple records on the same host
and the server provides the A/AAAA resolution in the response as AR
(Additional Records).

In such condition, the first occurence of the host will be taken from
the Additional section, while the second (and next ones) will be process
by an independent resolution task (like we used to do before 2.2).
This can lead to a situation where the "synchronisation" of the
resolution may diverge, like described in github issue #971.

Because of this behavior, HAProxy mixes various type of requests to
resolve the full list of servers: SRV+AR for all "first" occurences and
A/AAAA for all other occurences of an existing hostname.
IE: with the following type of response:

   ;; ANSWER SECTION:
   _http._tcp.be2.tld.     3600    IN      SRV     5 500 80 A2.tld.
   _http._tcp.be2.tld.     3600    IN      SRV     5 500 86 A3.tld.
   _http._tcp.be2.tld.     3600    IN      SRV     5 500 80 A1.tld.
   _http._tcp.be2.tld.     3600    IN      SRV     5 500 85 A3.tld.

   ;; ADDITIONAL SECTION:
   A2.tld.                 3600    IN      A       192.168.0.2
   A3.tld.                 3600    IN      A       192.168.0.3
   A1.tld.                 3600    IN      A       192.168.0.1
   A3.tld.                 3600    IN      A       192.168.0.3

the first A3 host is resolved using the Additional Section and the
second one through a dedicated A request.

When linking the SRV records to their respective Additional one, a
condition was missing (chek if said SRV record is already attached to an
Additional one), leading to stop processing SRV only when the target
SRV field matches the Additional record name. Hence only the first
occurence of a target was managed by an additional record.
This patch adds a condition in this loop to ensure the record being
parsed is not already linked to an Additional Record. If so, we can
carry on the parsing to find a possible next one with the same target
field value.

backport status: down to 2.2

---
 src/dns.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/dns.c b/src/dns.c
index 3d484263c..63faf1561 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -1027,6 +1027,7 @@ static int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend,
 				dns_answer_record->data_len = len;
 				memcpy(dns_answer_record->target, tmpname, len);
 				dns_answer_record->target[len] = 0;
+				dns_answer_record->ar_item = NULL;
 				break;
 
 			case DNS_RTYPE_AAAA:
@@ -1276,6 +1277,7 @@ static int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend,
 			// looking for the SRV record in the response list linked to this additional record
 			list_for_each_entry(tmp_record, &dns_p->answer_list, list) {
 				if (tmp_record->type == DNS_RTYPE_SRV &&
+				    tmp_record->ar_item == NULL &&
 				    !dns_hostname_cmp(tmp_record->target, dns_answer_record->name, tmp_record->data_len)) {
 					/* Always use the received additional record to refresh info */
 					if (tmp_record->ar_item)
-- 
2.25.1

Reply via email to