From: Timo Sirainen Date: Mon, 17 Aug 2020 10:07:49 +0000 (+0300) Subject: imap-hibernate: Preserve local_port and remote_port during hibernation X-Git-Tag: 2.3.13~366 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0665e883e3dd8ad237a67dad12e32b64373d586c;p=thirdparty%2Fdovecot%2Fcore.git imap-hibernate: Preserve local_port and remote_port during hibernation --- diff --git a/src/imap-hibernate/imap-client.c b/src/imap-hibernate/imap-client.c index fc158f154d..49f9be1180 100644 --- a/src/imap-hibernate/imap-client.c +++ b/src/imap-hibernate/imap-client.c @@ -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); diff --git a/src/imap-hibernate/imap-client.h b/src/imap-hibernate/imap-client.h index ce7e479585..9df708af5f 100644 --- a/src/imap-hibernate/imap-client.h +++ b/src/imap-hibernate/imap-client.h @@ -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; diff --git a/src/imap-hibernate/imap-hibernate-client.c b/src/imap-hibernate/imap-hibernate-client.c index fe2bbf7426..6421637d51 100644 --- a/src/imap-hibernate/imap-hibernate-client.c +++ b/src/imap-hibernate/imap-hibernate-client.c @@ -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( diff --git a/src/imap/imap-client-hibernate.c b/src/imap/imap-client-hibernate.c index f892d47df8..ae7b7b1844 100644 --- a/src/imap/imap-client-hibernate.c +++ b/src/imap/imap-client-hibernate.c @@ -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; diff --git a/src/imap/imap-master-client.c b/src/imap/imap-master-client.c index 14fe260965..fb16788b4b 100644 --- a/src/imap/imap-master-client.c +++ b/src/imap/imap-master-client.c @@ -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(