From: Christopher Faulet Date: Fri, 12 Mar 2021 09:23:05 +0000 (+0100) Subject: BUG/MEDIUM: resolvers: Skip DNS resolution at startup if SRV resolution is set X-Git-Tag: v2.3.7~4 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=558102698c296c4aaeb32d9add8bc54c817a3cd1;p=haproxy-2.3.git BUG/MEDIUM: resolvers: Skip DNS resolution at startup if SRV resolution is set At startup, if a SRV resolution is set for a server, no DNS resolution is created. We must wait the first SRV resolution to know if it must be triggered. It is important to do so for two reasons. First, during a "classical" startup, a server based on a SRV resolution has no hostname. Thus the created DNS resolution is useless. Best waiting the first SRV resolution. It is not really a bug at this stage, it is just useless. Second, in the same situation, if the server state is loaded from a file, its hosname will be set a bit later. Thus, if there is no additionnal record for this server, because there is already a DNS resolution, it inhibits any new DNS resolution. But there is no hostname attached to the existing DNS resolution. So no resolution is performed at all for this server. To avoid any problem, it is fairly easier to handle this special case during startup. But this means we must be prepared to have no "resolv_requester" field for a server at runtime. This patch must be backported as far as 2.2. (cherry picked from commit d83a6df5cde5f2e5417e9f995ab966ba01d17501) Signed-off-by: Christopher Faulet --- diff --git a/src/dns.c b/src/dns.c index 0dc1ff1..a628c5c 100644 --- a/src/dns.c +++ b/src/dns.c @@ -2437,7 +2437,7 @@ static int dns_finalize_config(void) continue; } } - if (dns_link_resolution(srv, OBJ_TYPE_SERVER, 0) == -1) { + if (!srv->srvrq && dns_link_resolution(srv, OBJ_TYPE_SERVER, 0) == -1) { ha_alert("config : %s '%s', unable to set DNS resolution for server '%s'.\n", proxy_type_str(px), px->id, srv->id); err_code |= (ERR_ALERT|ERR_ABORT); diff --git a/src/server.c b/src/server.c index db31149..7c1dd98 100644 --- a/src/server.c +++ b/src/server.c @@ -3729,7 +3729,7 @@ int srvrq_update_srv_status(struct server *s, int has_no_ip) int snr_update_srv_status(struct server *s, int has_no_ip) { struct dns_resolvers *resolvers = s->resolvers; - struct dns_resolution *resolution = s->dns_requester->resolution; + struct dns_resolution *resolution = (s->dns_requester ? s->dns_requester->resolution : NULL); int exp; /* If resolution is NULL we're dealing with SRV records Additional records */ @@ -3858,7 +3858,7 @@ int snr_resolution_cb(struct dns_requester *requester, struct dns_nameserver *na return 1; } - resolution = s->dns_requester->resolution; + resolution = (s->dns_requester ? s->dns_requester->resolution : NULL); if (!resolution) return 1; @@ -4130,10 +4130,10 @@ int srv_set_fqdn(struct server *srv, const char *hostname, int dns_locked) if (!dns_locked) HA_SPIN_LOCK(DNS_LOCK, &srv->resolvers->lock); - /* run time DNS resolution was not active for this server + /* run time DNS/SRV resolution was not active for this server * and we can't enable it at run time for now. */ - if (!srv->dns_requester) + if (!srv->dns_requester && !srv->srvrq) goto err; chunk_reset(&trash); @@ -4144,7 +4144,7 @@ int srv_set_fqdn(struct server *srv, const char *hostname, int dns_locked) if (hostname_dn_len == -1) goto err; - resolution = srv->dns_requester->resolution; + resolution = (srv->dns_requester ? srv->dns_requester->resolution : NULL); if (resolution && resolution->hostname_dn && !strcmp(resolution->hostname_dn, hostname_dn))