From 9222388d61d94edcc1176d18bd708a63dddc63a3 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 8 Sep 2017 11:02:07 +0300 Subject: [PATCH] lmtp proxy: Avoid DNS lookup for "host" if passdb also returns "hostip" --- src/lmtp/commands.c | 15 ++++++++++++--- src/lmtp/lmtp-proxy.c | 5 ++++- src/lmtp/lmtp-proxy.h | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/lmtp/commands.c b/src/lmtp/commands.c index 2496c1f8a9..55e7f0f7a2 100644 --- a/src/lmtp/commands.c +++ b/src/lmtp/commands.c @@ -250,7 +250,12 @@ client_proxy_rcpt_parse_fields(struct lmtp_proxy_rcpt_settings *set, proxying = TRUE; else if (strcmp(key, "host") == 0) set->host = value; - else if (strcmp(key, "port") == 0) { + else if (strcmp(key, "hostip") == 0) { + if (net_addr2ip(value, &set->hostip) < 0) { + i_error("proxy: Invalid hostip %s", value); + return FALSE; + } + } else if (strcmp(key, "port") == 0) { if (net_str2port(value, &set->port) < 0) { i_error("proxy: Invalid port number %s", value); return FALSE; @@ -297,8 +302,12 @@ client_proxy_is_ourself(const struct client *client, if (set->port != client->local_port) return FALSE; - if (net_addr2ip(set->host, &ip) < 0) - return FALSE; + if (set->hostip.family != 0) + ip = set->hostip; + else { + if (net_addr2ip(set->host, &ip) < 0) + return FALSE; + } if (!net_ip_compare(&ip, &client->local_ip)) return FALSE; return TRUE; diff --git a/src/lmtp/lmtp-proxy.c b/src/lmtp/lmtp-proxy.c index 1293d25c0e..f717c06874 100644 --- a/src/lmtp/lmtp-proxy.c +++ b/src/lmtp/lmtp-proxy.c @@ -146,7 +146,10 @@ lmtp_proxy_get_connection(struct lmtp_proxy *proxy, conn = p_new(proxy->pool, struct lmtp_proxy_connection, 1); conn->proxy = proxy; - conn->set.host = p_strdup(proxy->pool, set->host); + if (set->hostip.family == 0) + conn->set.host = p_strdup(proxy->pool, set->host); + else + conn->set.host = p_strdup(proxy->pool, net_ip2addr(&set->hostip)); conn->set.port = set->port; conn->set.timeout_msecs = set->timeout_msecs; array_append(&proxy->connections, &conn, 1); diff --git a/src/lmtp/lmtp-proxy.h b/src/lmtp/lmtp-proxy.h index 1ad0b61ae4..d5c80e8a1c 100644 --- a/src/lmtp/lmtp-proxy.h +++ b/src/lmtp/lmtp-proxy.h @@ -19,6 +19,7 @@ struct lmtp_proxy_settings { struct lmtp_proxy_rcpt_settings { const char *host; + struct ip_addr hostip; in_port_t port; unsigned int timeout_msecs; enum lmtp_client_protocol protocol; -- 2.47.3