Skip to content

Commit

Permalink
lmtp proxy: Avoid DNS lookup for "host" if passdb also returns "hostip"
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Sep 8, 2017
1 parent dbe43c8 commit 31434f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/lmtp/commands.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/lmtp/lmtp-proxy.c
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/lmtp/lmtp-proxy.h
Expand Up @@ -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;
Expand Down

0 comments on commit 31434f7

Please sign in to comment.