From 7bd3d26f911731a4ad944b08a8e952136b4e3533 Mon Sep 17 00:00:00 2001 From: Baptiste Assmann Date: Thu, 21 Jan 2016 00:17:09 +0100 Subject: 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 (cherry picked from commit a875b1f92e1c3796779dcdddd2fa494771acc705) --- src/server.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/server.c b/src/server.c index 7f88a12..efa3747 100644 --- a/src/server.c +++ b/src/server.c @@ -1910,7 +1910,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; @@ -2144,9 +2143,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]); } -- 1.7.12.1