]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp proxy: Avoid DNS lookup for "host" if passdb also returns "hostip"
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 8 Sep 2017 08:02:07 +0000 (11:02 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 8 Sep 2017 08:39:53 +0000 (11:39 +0300)
src/lmtp/commands.c
src/lmtp/lmtp-proxy.c
src/lmtp/lmtp-proxy.h

index 469d82d01ba4aa12bd735dec1855142ac7162cae..cd75210f0c07c1bf9992656e907cfbe2cc844861 100644 (file)
@@ -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;
@@ -299,8 +304,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;
index 22399c842acb53fcc77a53dcb51e2f2b49aa9f51..4c3c88b63117eeb348c2aa8ceb8176fccfb987e0 100644 (file)
@@ -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);
index 1ad0b61ae48f13b306400cb3e06a5a8e9f1a8fa4..d5c80e8a1cc1359728c45b6286c6c09a513a4099 100644 (file)
@@ -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;