]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: allow changing port with set_addr
authorJoseph C. Sible <josephcsible@gmail.com>
Tue, 5 May 2020 02:20:32 +0000 (22:20 -0400)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 5 May 2020 09:24:39 +0000 (11:24 +0200)
Add an optional port parameter, which can be either a number or a
string (to support '+' and '-' for port mapping).

This fixes issue #586.

doc/lua-api/index.rst
src/hlua_fcn.c

index 9a578ee299f152fa5ead6c02688fa918e80cf437..f3e5cb786b88b91f66fbe1eccf4a2009cfed950a 100644 (file)
@@ -976,7 +976,7 @@ Server class
     server.
   :returns: an integer.
 
-.. js:function:: Server.set_addr(sv, addr)
+.. js:function:: Server.set_addr(sv, addr[, port])
 
   Dynamically change the address of the server. See the management socket
   documentation for more information about the format of the string.
index a9c7fe507fda3e404a3ce0770224a280118966f6..e6f4d7379c5ddb98fa7ffcc226a72018ddc48391 100644 (file)
@@ -1034,13 +1034,18 @@ int hlua_server_set_addr(lua_State *L)
 {
        struct server *srv;
        const char *addr;
+       const char *port;
        const char *err;
 
        srv = hlua_check_server(L, 1);
        addr = luaL_checkstring(L, 2);
+       if (lua_gettop(L) >= 3)
+               port = luaL_checkstring(L, 3);
+       else
+               port = NULL;
 
        HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
-       err = server_parse_addr_change_request(srv, addr, "Lua script");
+       err = update_server_addr_port(srv, addr, port, "Lua script");
        HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
        if (!err)
                lua_pushnil(L);