]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: lua: avoid directly calling getsockname/getpeername()
authorWilly Tarreau <w@1wt.eu>
Wed, 16 Nov 2016 16:00:14 +0000 (17:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Nov 2016 16:32:57 +0000 (17:32 +0100)
We already have per-protocol functions for this, and they already
take care of properly setting the CO_FL_ADDR_*_SET flags.

src/hlua.c

index deff4cc83095dc2d2b0bbc65db83e924acd605bb..7e56b7544dd6cb9e6f669899fff2618bc818b574 100644 (file)
@@ -10,8 +10,6 @@
  *
  */
 
-#include <sys/socket.h>
-
 #include <ctype.h>
 #include <setjmp.h>
 
 
 #include <common/cfgparse.h>
 
-#include <types/connection.h>
 #include <types/hlua.h>
 #include <types/proxy.h>
 
 #include <proto/arg.h>
 #include <proto/applet.h>
 #include <proto/channel.h>
+#include <proto/connection.h>
 #include <proto/hdr_idx.h>
 #include <proto/hlua.h>
 #include <proto/hlua_fcn.h>
@@ -2083,13 +2081,10 @@ __LJMP static int hlua_socket_getpeername(struct lua_State *L)
                return 1;
        }
 
+       conn_get_to_addr(conn);
        if (!(conn->flags & CO_FL_ADDR_TO_SET)) {
-               unsigned int salen = sizeof(conn->addr.to);
-               if (getpeername(conn->t.sock.fd, (struct sockaddr *)&conn->addr.to, &salen) == -1) {
-                       lua_pushnil(L);
-                       return 1;
-               }
-               conn->flags |= CO_FL_ADDR_TO_SET;
+               lua_pushnil(L);
+               return 1;
        }
 
        return MAY_LJMP(hlua_socket_info(L, &conn->addr.to));
@@ -2117,13 +2112,10 @@ static int hlua_socket_getsockname(struct lua_State *L)
                return 1;
        }
 
+       conn_get_from_addr(conn);
        if (!(conn->flags & CO_FL_ADDR_FROM_SET)) {
-               unsigned int salen = sizeof(conn->addr.from);
-               if (getsockname(conn->t.sock.fd, (struct sockaddr *)&conn->addr.from, &salen) == -1) {
-                       lua_pushnil(L);
-                       return 1;
-               }
-               conn->flags |= CO_FL_ADDR_FROM_SET;
+               lua_pushnil(L);
+               return 1;
        }
 
        return hlua_socket_info(L, &conn->addr.from);