From: Timo Sirainen Date: Wed, 13 Apr 2011 09:23:35 +0000 (+0300) Subject: config: Abort local/remote block DNS lookups after 30s and warn after 5s. X-Git-Tag: 2.0.13~59 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a865d46c3704c7d9781f5f249d87796ec5d3591;p=thirdparty%2Fdovecot%2Fcore.git config: Abort local/remote block DNS lookups after 30s and warn after 5s. --- diff --git a/src/config/config-parser.c b/src/config/config-parser.c index 7976c49b3a..606e843a45 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef HAVE_GLOB_H # include #endif @@ -27,6 +28,9 @@ # define GLOB_BRACE 0 #endif +#define DNS_LOOKUP_TIMEOUT_SECS 30 +#define DNS_LOOKUP_WARN_SECS 5 + static const enum settings_parser_flags settings_parser_flags = SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS | SETTINGS_PARSER_FLAG_TRACK_CHANGES; @@ -209,6 +213,7 @@ int config_parse_net(const char *value, struct ip_addr *ip_r, struct ip_addr *ips; const char *p; unsigned int ip_count, bits, max_bits; + time_t t1, t2; int ret; if (net_parse_range(value, ip_r, bits_r) == 0) @@ -220,7 +225,11 @@ int config_parse_net(const char *value, struct ip_addr *ip_r, p++; } + t1 = time(NULL); + alarm(DNS_LOOKUP_TIMEOUT_SECS); ret = net_gethostbyname(value, &ips, &ip_count); + alarm(0); + t2 = time(NULL); if (ret != 0) { *error_r = t_strdup_printf("gethostbyname(%s) failed: %s", value, net_gethosterror(ret)); @@ -228,6 +237,11 @@ int config_parse_net(const char *value, struct ip_addr *ip_r, } *ip_r = ips[0]; + if (t2 - t1 >= DNS_LOOKUP_WARN_SECS) { + i_warning("gethostbyname(%s) took %d seconds", + value, (int)(t2-t1)); + } + max_bits = IPADDR_IS_V4(&ips[0]) ? 32 : 128; if (p == NULL || str_to_uint(p, &bits) < 0 || bits > max_bits) *bits_r = max_bits;