]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: dns: trigger a DNS query type change on resolution timeout
authorBaptiste Assmann <bedis9@gmail.com>
Wed, 6 Jan 2016 01:01:59 +0000 (02:01 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 5 Apr 2016 03:56:11 +0000 (05:56 +0200)
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

index 97f9f0ac0d26bdbf5b38f4838d65a9142123e5c3..4603e21f70f48183f106fedf25928f2ecceefebd 100644 (file)
--- 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);