BUG/MAJOR: servers state: server port is erased when dns resolution is enabled on a server

Servers state function save and apply server IP when DNS resolution is
enabled on a server.
Purpose is to prevent switching traffic from one server to an other one
when multiple IPs are returned by the DNS server for the A or AAAA
record.

That said, a bug in current code lead to erase the service port while
copying the IP found in the file into the server structure in HAProxy's
memory.
This patch fix this bug.

The bug was reported on the ML by Robert Samuel Newson and fix proposed
by Nenad Merdanovic.
Thank you both!!!

backport: can be backported to 1.6
This commit is contained in:
Baptiste Assmann 2016-01-21 00:17:09 +01:00 committed by Willy Tarreau
parent 7f43fa9b2c
commit a875b1f92e

View File

@ -1921,7 +1921,6 @@ static void srv_update_state(struct server *srv, int version, char **params)
/* fields since version 1
* and common to all other upcoming versions
*/
struct sockaddr_storage addr;
enum srv_state srv_op_state;
enum srv_admin srv_admin_state;
unsigned srv_uweight, srv_iweight;
@ -2155,9 +2154,19 @@ static void srv_update_state(struct server *srv, int version, char **params)
/* update server IP only if DNS resolution is used on the server */
if (srv->resolution) {
struct sockaddr_storage addr;
memset(&addr, 0, sizeof(struct sockaddr_storage));
if (str2ip2(params[0], &addr, 0))
memcpy(&srv->addr, &addr, sizeof(struct sockaddr_storage));
if (str2ip2(params[0], &addr, AF_UNSPEC)) {
int port;
/* save the port, applies the new IP then reconfigure the port */
get_host_port(&srv->addr);
srv->addr.ss_family = addr.ss_family;
str2ip2(params[0], &srv->addr, srv->addr.ss_family);
set_host_port(&srv->addr, port);
}
else
chunk_appendf(msg, ", can't parse IP: %s", params[0]);
}