From 060e57301db98853eef91b344b6ace187b657190 Mon Sep 17 00:00:00 2001 From: Baptiste Assmann Date: Wed, 6 Jan 2016 02:01:59 +0100 Subject: [PATCH] BUG/MINOR: dns: trigger a DNS query type change on resolution timeout After Cedric Jeanneret reported an issue with HAProxy and DNS resolution when multiple servers are in use, I saw that the implementation of DNS query type update on resolution timeout was not implemented, even if it is documented. backport: 1.6 and above --- src/dns.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/dns.c b/src/dns.c index 97f9f0ac0..4603e21f7 100644 --- a/src/dns.c +++ b/src/dns.c @@ -1164,6 +1164,7 @@ struct task *dns_process_resolve(struct task *t) { struct dns_resolvers *resolvers = t->context; struct dns_resolution *resolution, *res_back; + int res_preferred_afinet, res_preferred_afinet6; /* timeout occurs inevitably for the first element of the FIFO queue */ if (LIST_ISEMPTY(&resolvers->curr_resolution)) { @@ -1193,6 +1194,19 @@ struct task *dns_process_resolve(struct task *t) resolution->try -= 1; + res_preferred_afinet = resolution->resolver_family_priority == AF_INET && resolution->query_type == DNS_RTYPE_A; + res_preferred_afinet6 = resolution->resolver_family_priority == AF_INET6 && resolution->query_type == DNS_RTYPE_AAAA; + + /* let's change the query type if needed */ + if (res_preferred_afinet6) { + /* fallback from AAAA to A */ + resolution->query_type = DNS_RTYPE_A; + } + else if (res_preferred_afinet) { + /* fallback from A to AAAA */ + resolution->query_type = DNS_RTYPE_AAAA; + } + /* resend the DNS query */ dns_send_query(resolution);