]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: client: Add support for connecting from an explicit source IP.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 27 Feb 2018 20:58:17 +0000 (21:58 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 16 Apr 2018 07:41:28 +0000 (10:41 +0300)
src/lib-smtp/smtp-client-connection.c
src/lib-smtp/smtp-client.c
src/lib-smtp/smtp-client.h

index 1b442c4113f8561db1655460b5b807d92fd73cfa..272cebaa88595154b6012e6b6e71617d23d5ee28 100644 (file)
@@ -1405,19 +1405,25 @@ smtp_client_connection_do_connect(struct smtp_client_connection *conn)
 static void
 smtp_client_connection_connect_next_ip(struct smtp_client_connection *conn)
 {
-       const struct ip_addr *ip;
+       const struct ip_addr *ip, *my_ip = &conn->set.my_ip;
 
        timeout_remove(&conn->to_connect);
 
        conn->prev_connect_idx = (conn->prev_connect_idx+1) % conn->ips_count;
        ip = &conn->ips[conn->prev_connect_idx];
 
-       smtp_client_connection_debug(conn,
-               "Connecting to %s:%u",
-               net_ip2addr(ip), conn->port);
+       if (my_ip->family != 0) {
+               smtp_client_connection_debug(conn,
+                       "Connecting to %s:%u (from %s)",
+                       net_ip2addr(ip), conn->port, net_ip2addr(my_ip));
+       } else {
+               smtp_client_connection_debug(conn,
+                       "Connecting to %s:%u",
+                       net_ip2addr(ip), conn->port);
+       }
 
-       connection_init_client_ip
-               (conn->client->conn_list, &conn->conn, ip, conn->port);
+       connection_init_client_ip_from(conn->client->conn_list,
+                                      &conn->conn, ip, conn->port, my_ip);
 
        smtp_client_connection_do_connect(conn);
 }
@@ -1624,6 +1630,8 @@ smtp_client_connection_create(struct smtp_client *client,
 
        conn->set = client->set;
        if (set != NULL) {
+               if (set->my_ip.family != 0)
+                       conn->set.my_ip = set->my_ip;
                if (set->my_hostname != NULL && *set->my_hostname != '\0')
                        conn->set.my_hostname = p_strdup(pool, set->my_hostname);
 
index 5ee5a291100460f79a23515fc5339566541e5ba1..6e5049133391ca99dcf3c438eb287d883d0f49e4 100644 (file)
@@ -31,6 +31,7 @@ struct smtp_client *smtp_client_init(const struct smtp_client_settings *set)
        client = p_new(pool, struct smtp_client, 1);
        client->pool = pool;
 
+       client->set.my_ip = set->my_ip;
        client->set.my_hostname = p_strdup(pool, set->my_hostname);
 
        client->set.forced_capabilities = set->forced_capabilities;
index b0c8a3e9faa73ab37e4ecbe471fae7e37334738c..8914935ff824b2a75ae0e082e143d6a0be4f5510 100644 (file)
@@ -38,6 +38,7 @@ enum smtp_client_command_error {
 };
 
 struct smtp_client_settings {
+       struct ip_addr my_ip;
        const char *my_hostname;
        const char *temp_path_prefix;