]> 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)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Wed, 27 Sep 2017 11:36:51 +0000 (14:36 +0300)
src/lmtp/commands.c
src/lmtp/lmtp-proxy.c
src/lmtp/lmtp-proxy.h

index 2496c1f8a9466fefd1be36dd3fbc60c22c9c3cca..55e7f0f7a23d10c36612382f0113c98581271d79 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;
@@ -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;
index 1293d25c0e2168d629d736b92f9aaf085c0c6459..f717c068746027ccff07c1216a1dc525ac16ac6a 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;