]> 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)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 27 Feb 2018 21:55:02 +0000 (22:55 +0100)
src/lib-smtp/smtp-client-connection.c
src/lib-smtp/smtp-client.c
src/lib-smtp/smtp-client.h

index 8de8ffc4dbe6e5366d6577136bc68be58b485d44..677bdf1b28b2d0ce6cd61165b0a23d825eb04f5f 100644 (file)
@@ -1404,19 +1404,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);
 }
@@ -1623,6 +1629,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 4f92e395a94c38ecd892f08517a01609b97a7bb0..c5f5fe39372b2e71b31d6a85e04218b138301c3a 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.dns_client = set->dns_client;
        client->set.dns_client_socket_path =
index cbc9ddfc2466f06b0865db57e945079e3970614b..3aaa39be0a2e778e5614821132a544e3648cc67d 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;