]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-hibernate: Preserve local_port and remote_port during hibernation
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 17 Aug 2020 10:07:49 +0000 (13:07 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 21 Aug 2020 08:51:13 +0000 (08:51 +0000)
src/imap-hibernate/imap-client.c
src/imap-hibernate/imap-client.h
src/imap-hibernate/imap-hibernate-client.c
src/imap/imap-client-hibernate.c
src/imap/imap-master-client.c

index fc158f154db08db97a40a135269470b6f28f890d..49f9be118087a4fd91fa082deed50006ddfc1cac 100644 (file)
@@ -141,8 +141,12 @@ imap_client_move_back_send_callback(void *context, struct ostream *output)
                str_printfa(str, "\ttag=%s", client->state.tag);
        if (state->local_ip.family != 0)
                str_printfa(str, "\tlip=%s", net_ip2addr(&state->local_ip));
+       if (state->local_port != 0)
+               str_printfa(str, "\tlport=%u", state->local_port);
        if (state->remote_ip.family != 0)
                str_printfa(str, "\trip=%s", net_ip2addr(&state->remote_ip));
+       if (state->remote_port != 0)
+               str_printfa(str, "\trport=%u", state->remote_port);
        if (state->userdb_fields != NULL) {
                str_append(str, "\tuserdb_fields=");
                str_append_tabescaped(str, state->userdb_fields);
index ce7e479585993d3c67347264629d9394db2afef6..9df708af5f68b800a588794e4a8730dfbaefc561 100644 (file)
@@ -9,6 +9,7 @@ struct imap_client_state {
        /* optional: */
        const char *session_id, *userdb_fields, *stats;
        struct ip_addr local_ip, remote_ip;
+       in_port_t local_port, remote_port;
        time_t session_created;
 
        uid_t uid;
index fe2bbf74260b277b04275a63089ade74363c3e2d..6421637d510595071e837dbd0d0b04b968d08eee 100644 (file)
@@ -75,12 +75,24 @@ imap_hibernate_client_parse_input(const char *const *args, pool_t pool,
                                        "Invalid lip value: %s", value);
                                return -1;
                        }
+               } else if (strcmp(key, "lport") == 0) {
+                       if (net_str2port(value, &state_r->local_port) < 0) {
+                               *error_r = t_strdup_printf(
+                                       "Invalid lport value: %s", value);
+                               return -1;
+                       }
                } else if (strcmp(key, "rip") == 0) {
                        if (net_addr2ip(value, &state_r->remote_ip) < 0) {
                                *error_r = t_strdup_printf(
                                        "Invalid rip value: %s", value);
                                return -1;
                        }
+               } else if (strcmp(key, "rport") == 0) {
+                       if (net_str2port(value, &state_r->remote_port) < 0) {
+                               *error_r = t_strdup_printf(
+                                       "Invalid rport value: %s", value);
+                               return -1;
+                       }
                } else if (strcmp(key, "peer_dev_major") == 0) {
                        if (str_to_uint(value, &peer_dev_major) < 0) {
                                *error_r = t_strdup_printf(
index f892d47df889ca048a9895673c00b898ff92dbca..ae7b7b184446113b4657b68a200ffd40dca5e200 100644 (file)
@@ -71,8 +71,12 @@ static void imap_hibernate_write_cmd(struct client *client, string_t *cmd,
        }
        if (user->conn.local_ip != NULL)
                str_printfa(cmd, "\tlip=%s", net_ip2addr(user->conn.local_ip));
+       if (user->conn.local_port != 0)
+               str_printfa(cmd, "\tlport=%u", user->conn.local_port);
        if (user->conn.remote_ip != NULL)
                str_printfa(cmd, "\trip=%s", net_ip2addr(user->conn.remote_ip));
+       if (user->conn.remote_port != 0)
+               str_printfa(cmd, "\trport=%u", user->conn.remote_port);
        if (client->userdb_fields != NULL) {
                string_t *userdb_fields = t_str_new(256);
                unsigned int i;
index 14fe260965b093bab815ad1e18b28f72c1db09f5..fb16788b4b2ca8b2646751041009f365fae24a70 100644 (file)
@@ -90,12 +90,24 @@ imap_master_client_parse_input(const char *const *args, pool_t pool,
                                        "Invalid lip value: %s", value);
                                return -1;
                        }
+               } else if (strcmp(key, "lport") == 0) {
+                       if (net_str2port(value, &input_r->local_port) < 0) {
+                               *error_r = t_strdup_printf(
+                                       "Invalid lport value: %s", value);
+                               return -1;
+                       }
                } else if (strcmp(key, "rip") == 0) {
                        if (net_addr2ip(value, &input_r->remote_ip) < 0) {
                                *error_r = t_strdup_printf(
                                        "Invalid rip value: %s", value);
                                return -1;
                        }
+               } else if (strcmp(key, "rport") == 0) {
+                       if (net_str2port(value, &input_r->remote_port) < 0) {
+                               *error_r = t_strdup_printf(
+                                       "Invalid rport value: %s", value);
+                               return -1;
+                       }
                } else if (strcmp(key, "peer_dev_major") == 0) {
                        if (str_to_uint(value, &peer_dev_major) < 0) {
                                *error_r = t_strdup_printf(