Hi,

I ran into the following problem: I have a server specified by hostname,
using the new DNS feature. I initially did not specify the "resolve-prefer"
parameter. The initial lookup of the server succeeded and produced an IPv4
address. Unfortunately, that address was then never updated because of the
following situation:

 - In server.c:1034, resolve-prefer silently defaults to ipv6
 - The DNS server gave no records in response to ANY query
 - Resolvers check resolve-prefer, try again with AAAA query
 - Query yields no results

This was a little unexpected, because the initial resolution works just
fine. I think there are at least two possible options to improve this
behaviour:

 - Document the defaulting to ipv6 and only allow ipv6 for the initial
   lookup as well (in my scenario, this would have lead to failure to
   start, leading to me adding resolve-prefer ipv4, an acceptable solution
 - Do not default to ipv6, leave as unspecified instead. If ANY query
   doesn't produce results, check current address type if no resolve-
   prefer is specified

The attached patch is merely to demonstrate the latter solution. It worked
for me, but I didn't check too hard if leaving resolver_family_priority set
to AF_UNSPEC might lead to other problems elsewhere.

Maybe there is even other/better solutions?

Regards,
Conrad
-- 
Conrad Hoffmann
Traffic Engineer

SoundCloud Ltd. | Rheinsberger Str. 76/77, 10115 Berlin, Germany

Managing Director: Alexander Ljung | Incorporated in England & Wales
with Company No. 6343600 | Local Branch Office | AG Charlottenburg |
HRB 110657B
diff --git a/src/server.c b/src/server.c
index f3b0f16..02085ec 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1030,8 +1030,6 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
 			newsrv->agent.health	= newsrv->agent.rise;	/* up, but will fall down at first failure */
 			newsrv->agent.server	= newsrv;
 			newsrv->resolver_family_priority = curproxy->defsrv.resolver_family_priority;
-			if (newsrv->resolver_family_priority == AF_UNSPEC)
-				newsrv->resolver_family_priority = AF_INET6;
 
 			cur_arg = 3;
 		} else {
@@ -2138,8 +2136,14 @@ int snr_resolution_error_cb(struct dns_resolution *resolution, int error_code)
 				/* let's change the query type */
 				if (resolution->resolver_family_priority == AF_INET6)
 					resolution->query_type = DNS_RTYPE_AAAA;
-				else
+				else if (resolution->resolver_family_priority == AF_INET)
 					resolution->query_type = DNS_RTYPE_A;
+				else if (resolution->resolver_family_priority == AF_UNSPEC) {
+					if (s->addr.ss_family == AF_INET)
+						resolution->query_type = DNS_RTYPE_A;
+					else
+						resolution->query_type = DNS_RTYPE_AAAA;
+				}
 
 				dns_send_query(resolution);
 

Reply via email to