From: Stephan Bosch Date: Fri, 29 Dec 2017 01:15:06 +0000 (+0100) Subject: lib-http: client: Use merged DNS settings from all clients connected to a shared... X-Git-Tag: 2.3.9~2555 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee90a96c4f47ff9c1e56451201386ca8a0b48124;p=thirdparty%2Fdovecot%2Fcore.git lib-http: client: Use merged DNS settings from all clients connected to a shared context for DNS lookups. --- diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index 3ab0a49e19..9de3437b75 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -90,7 +90,7 @@ static void http_client_host_shared_dns_callback(const struct dns_lookup_result *result, struct http_client_host_shared *hshared) { - const struct http_client_settings *set = &hshared->cctx->set; + struct http_client_context *cctx = hshared->cctx; struct http_client_host *host; hshared->dns_lookup = NULL; @@ -111,7 +111,8 @@ http_client_host_shared_dns_callback(const struct dns_lookup_result *result, memcpy(hshared->ips, result->ips, sizeof(*hshared->ips) * hshared->ips_count); hshared->ips_timeout = ioloop_timeval; - timeval_add_msecs(&hshared->ips_timeout, set->dns_ttl_msecs); + i_assert(cctx->dns_ttl_msecs > 0); + timeval_add_msecs(&hshared->ips_timeout, cctx->dns_ttl_msecs); /* notify all sessions */ host = hshared->hosts_list; @@ -124,7 +125,7 @@ http_client_host_shared_dns_callback(const struct dns_lookup_result *result, static void http_client_host_shared_lookup (struct http_client_host_shared *hshared) { - const struct http_client_settings *set = &hshared->cctx->set; + struct http_client_context *cctx = hshared->cctx; struct dns_lookup_settings dns_set; struct ip_addr *ips; int ret; @@ -132,22 +133,16 @@ static void http_client_host_shared_lookup i_assert(!hshared->explicit_ip); i_assert(hshared->dns_lookup == NULL); - if (set->dns_client != NULL) { + if (cctx->dns_client != NULL) { e_debug(hshared->event, "Performing asynchronous DNS lookup"); - (void)dns_client_lookup(set->dns_client, hshared->name, + (void)dns_client_lookup(cctx->dns_client, hshared->name, http_client_host_shared_dns_callback, hshared, &hshared->dns_lookup); - } else if (set->dns_client_socket_path != NULL) { + } else if (cctx->dns_client_socket_path != NULL) { + i_assert(cctx->dns_lookup_timeout_msecs > 0); e_debug(hshared->event, "Performing asynchronous DNS lookup"); i_zero(&dns_set); - dns_set.dns_client_socket_path = set->dns_client_socket_path; - if (set->connect_timeout_msecs > 0) - dns_set.timeout_msecs = set->connect_timeout_msecs; - else if (set->request_timeout_msecs > 0) - dns_set.timeout_msecs = set->request_timeout_msecs; - else { - dns_set.timeout_msecs = - HTTP_CLIENT_DEFAULT_DNS_LOOKUP_TIMEOUT_MSECS; - } + dns_set.dns_client_socket_path = cctx->dns_client_socket_path; + dns_set.timeout_msecs = cctx->dns_lookup_timeout_msecs; (void)dns_lookup(hshared->name, &dns_set, http_client_host_shared_dns_callback, hshared, &hshared->dns_lookup); } else { @@ -170,7 +165,8 @@ static void http_client_host_shared_lookup if (hshared->ips_count > 0) { hshared->ips_timeout = ioloop_timeval; - timeval_add_msecs(&hshared->ips_timeout, set->dns_ttl_msecs); + i_assert(cctx->dns_ttl_msecs > 0); + timeval_add_msecs(&hshared->ips_timeout, cctx->dns_ttl_msecs); } } @@ -304,9 +300,9 @@ http_client_host_shared_request_submitted( void http_client_host_shared_switch_ioloop( struct http_client_host_shared *hshared) { - const struct http_client_settings *set = &hshared->cctx->set; + struct http_client_context *cctx = hshared->cctx; - if (hshared->dns_lookup != NULL && set->dns_client == NULL) + if (hshared->dns_lookup != NULL && cctx->dns_client == NULL) dns_lookup_switch_ioloop(hshared->dns_lookup); if (hshared->to_idle != NULL) hshared->to_idle = io_loop_move_timeout(&hshared->to_idle); diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index 09d99a8b90..ef40ada011 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -390,6 +390,11 @@ struct http_client_context { struct http_client_settings set; + struct dns_client *dns_client; + const char *dns_client_socket_path; + unsigned int dns_ttl_msecs; + unsigned int dns_lookup_timeout_msecs; + struct http_client *clients_list; struct connection_list *conn_list; diff --git a/src/lib-http/http-client.c b/src/lib-http/http-client.c index a967126293..380f98a9bf 100644 --- a/src/lib-http/http-client.c +++ b/src/lib-http/http-client.c @@ -144,6 +144,11 @@ http_client_init_shared(struct http_client_context *cctx, /* merge provided settings with context defaults */ client->set = cctx->set; if (set != NULL) { + client->set.dns_client = set->dns_client; + client->set.dns_client_socket_path = + p_strdup_empty(pool, set->dns_client_socket_path); + client->set.dns_ttl_msecs = set->dns_ttl_msecs; + if (set->user_agent != NULL && *set->user_agent != '\0') client->set.user_agent = p_strdup_empty(pool, set->user_agent); if (set->rawlog_dir != NULL && *set->rawlog_dir != '\0') @@ -537,6 +542,16 @@ void http_client_context_unref(struct http_client_context **_cctx) pool_unref(&cctx->pool); } +static unsigned int +http_client_get_dns_lookup_timeout_msecs(const struct http_client_settings *set) +{ + if (set->connect_timeout_msecs > 0) + return set->connect_timeout_msecs; + if (set->request_timeout_msecs > 0) + return set->request_timeout_msecs; + return HTTP_CLIENT_DEFAULT_DNS_LOOKUP_TIMEOUT_MSECS; +} + static void http_client_context_update_settings(struct http_client_context *cctx) { @@ -544,11 +559,36 @@ http_client_context_update_settings(struct http_client_context *cctx) bool debug; /* revert back to context settings */ + cctx->dns_client = cctx->set.dns_client; + cctx->dns_client_socket_path = cctx->set.dns_client_socket_path; + cctx->dns_ttl_msecs = cctx->set.dns_ttl_msecs; + cctx->dns_lookup_timeout_msecs = + http_client_get_dns_lookup_timeout_msecs(&cctx->set); debug = cctx->set.debug; - /* merge with available client settings */ + i_assert(cctx->dns_ttl_msecs > 0); + i_assert(cctx->dns_lookup_timeout_msecs > 0); + + /* override with available client settings */ for (client = cctx->clients_list; client != NULL; client = client->next) { + unsigned dns_lookup_timeout_msecs = + http_client_get_dns_lookup_timeout_msecs(&client->set); + + if (cctx->dns_client == NULL) + cctx->dns_client = client->set.dns_client; + if (cctx->dns_client_socket_path == NULL) { + cctx->dns_client_socket_path = + client->set.dns_client_socket_path; + } + if (client->set.dns_ttl_msecs != 0 && + cctx->dns_ttl_msecs > client->set.dns_ttl_msecs) + cctx->dns_ttl_msecs = client->set.dns_ttl_msecs; + if (dns_lookup_timeout_msecs != 0 && + cctx->dns_lookup_timeout_msecs > dns_lookup_timeout_msecs) { + cctx->dns_lookup_timeout_msecs = + dns_lookup_timeout_msecs; + } debug = debug || client->set.debug; }