From: Stephan Bosch Date: Sun, 11 Sep 2016 15:46:10 +0000 (+0200) Subject: lib-http: client: Improved handling of hosts with explicit IP address. X-Git-Tag: 2.2.27~241 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=17ec7e616644eb627e8eda290742daa8b722a97e;p=thirdparty%2Fdovecot%2Fcore.git lib-http: client: Improved handling of hosts with explicit IP address. --- diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index 5c3c7d242c..f23ade0ce1 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -99,15 +99,13 @@ static void http_client_host_lookup { struct http_client *client = host->client; struct dns_lookup_settings dns_set; - struct ip_addr ip, *ips; + struct ip_addr *ips; unsigned int ips_count; int ret; - if (net_addr2ip(host->name, &ip) == 0) { - host->ips_count = 1; - host->ips = i_new(struct ip_addr, host->ips_count); - host->ips[0] = ip; - } else if (client->set.dns_client != NULL) { + i_assert(!host->explicit_ip); + + if (client->set.dns_client != NULL) { http_client_host_debug(host, "Performing asynchronous DNS lookup"); (void)dns_client_lookup(client->set.dns_client, host->name, @@ -177,6 +175,7 @@ struct http_client_host *http_client_host_get } else { const char *hostname = host_url->host_name; + struct ip_addr ip = host_url->host_ip; host = hash_table_lookup(client->hosts, hostname); if (host == NULL) { @@ -185,10 +184,11 @@ struct http_client_host *http_client_host_get hostname = host->name; hash_table_insert(client->hosts, hostname, host); - if (host_url->have_host_ip) { + if (ip.family != 0 || net_addr2ip(host->name, &ip) == 0) { host->ips_count = 1; host->ips = i_new(struct ip_addr, host->ips_count); - host->ips[0] = host_url->host_ip; + host->ips[0] = ip; + host->explicit_ip = TRUE; } http_client_host_debug(host, "Host created"); diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index 0090e41127..f5fbe25777 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -252,6 +252,7 @@ struct http_client_host { struct dns_lookup *dns_lookup; unsigned int unix_local:1; + unsigned int explicit_ip:1; }; struct http_client {