From: Baptiste Assmann Date: Wed, 20 Jan 2016 23:17:09 +0000 (+0100) Subject: BUG/MAJOR: servers state: server port is erased when dns resolution is enabled on... X-Git-Tag: v1.7-dev2~141 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a875b1f92e1c3796779dcdddd2fa494771acc705;p=thirdparty%2Fhaproxy.git 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 --- diff --git a/src/server.c b/src/server.c index f465e16cec..ab309abce5 100644 --- a/src/server.c +++ b/src/server.c @@ -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]); }