Re: [PATCH 1/2] BUG/MINOR: lua: Fix Server.get_addr() port values

2017-07-23 Thread Willy Tarreau
Hi Nenad,

On Sun, Jul 23, 2017 at 10:04:58PM -0400, Nenad Merdanovic wrote:
> The get_addr() method of the Lua Server class was using the
> 'sockaddr_storage addr' member to get the port value. HAProxy does not
> store ports in this member as it uses a separate member, called
> 'svc_port'.

Hmmm good catch. I was the one changing this with commit 04276f3 ("MEDIUM:
server: split the address and the port into two different fields") to fix
a DNS problem, and it was backported into 1.7.2. Too bad I didn't spot this
use case :-/

Both patches merged, thanks!
Willy



[PATCH 1/2] BUG/MINOR: lua: Fix Server.get_addr() port values

2017-07-23 Thread Nenad Merdanovic
The get_addr() method of the Lua Server class was using the
'sockaddr_storage addr' member to get the port value. HAProxy does not
store ports in this member as it uses a separate member, called
'svc_port'.

This fix should be backported to 1.7.
---
 src/hlua_fcn.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c
index 8406bfe5..0df9025c 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -545,8 +545,7 @@ int hlua_server_get_addr(lua_State *L)
  addr, INET_ADDRSTRLEN);
luaL_addstring(&b, addr);
luaL_addstring(&b, ":");
-   snprintf(addr, INET_ADDRSTRLEN, "%d",
-ntohs(((struct sockaddr_in *)&srv->addr)->sin_port));
+   snprintf(addr, INET_ADDRSTRLEN, "%d", srv->svc_port);
luaL_addstring(&b, addr);
break;
case AF_INET6:
@@ -554,8 +553,7 @@ int hlua_server_get_addr(lua_State *L)
  addr, INET_ADDRSTRLEN);
luaL_addstring(&b, addr);
luaL_addstring(&b, ":");
-   snprintf(addr, INET_ADDRSTRLEN, "%d",
-ntohs(((struct sockaddr_in6 *)&srv->addr)->sin6_port));
+   snprintf(addr, INET_ADDRSTRLEN, "%d", srv->svc_port);
luaL_addstring(&b, addr);
break;
case AF_UNIX:
-- 
2.11.0