mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-05-07 18:28:01 +00:00
MINOR: lua: extend socket address to support non-IP families
The HAProxy Lua socket respects the Lua Socket tcp specs. these specs are a little bit limited, it not permits to connect to unix socket. this patch extends a little it the specs. It permit to accept a syntax that begin with "unix@", "ipv4@", "ipv6@", "fd@" or "abns@".
This commit is contained in:
parent
7fe3be7281
commit
c2f5653452
34
src/hlua.c
34
src/hlua.c
@ -2189,18 +2189,22 @@ __LJMP static int hlua_socket_connect_yield(struct lua_State *L, int status, lua
|
|||||||
__LJMP static int hlua_socket_connect(struct lua_State *L)
|
__LJMP static int hlua_socket_connect(struct lua_State *L)
|
||||||
{
|
{
|
||||||
struct hlua_socket *socket;
|
struct hlua_socket *socket;
|
||||||
int port;
|
int port = -1;
|
||||||
const char *ip;
|
const char *ip;
|
||||||
struct connection *conn;
|
struct connection *conn;
|
||||||
struct hlua *hlua;
|
struct hlua *hlua;
|
||||||
struct appctx *appctx;
|
struct appctx *appctx;
|
||||||
|
int low, high;
|
||||||
|
struct sockaddr_storage *addr;
|
||||||
|
|
||||||
MAY_LJMP(check_args(L, 3, "connect"));
|
if (lua_gettop(L) < 2)
|
||||||
|
WILL_LJMP(luaL_error(L, "connect: need at least 2 arguments"));
|
||||||
|
|
||||||
/* Get args. */
|
/* Get args. */
|
||||||
socket = MAY_LJMP(hlua_checksocket(L, 1));
|
socket = MAY_LJMP(hlua_checksocket(L, 1));
|
||||||
ip = MAY_LJMP(luaL_checkstring(L, 2));
|
ip = MAY_LJMP(luaL_checkstring(L, 2));
|
||||||
port = MAY_LJMP(luaL_checkinteger(L, 3));
|
if (lua_gettop(L) >= 3)
|
||||||
|
port = MAY_LJMP(luaL_checkinteger(L, 3));
|
||||||
|
|
||||||
conn = si_alloc_conn(&socket->s->si[1]);
|
conn = si_alloc_conn(&socket->s->si[1]);
|
||||||
if (!conn)
|
if (!conn)
|
||||||
@ -2210,15 +2214,25 @@ __LJMP static int hlua_socket_connect(struct lua_State *L)
|
|||||||
conn->target = socket->s->target;
|
conn->target = socket->s->target;
|
||||||
|
|
||||||
/* Parse ip address. */
|
/* Parse ip address. */
|
||||||
conn->addr.to.ss_family = AF_UNSPEC;
|
addr = str2sa_range(ip, &low, &high, NULL, NULL, NULL, 0);
|
||||||
if (!str2ip2(ip, &conn->addr.to, 0))
|
if (!addr)
|
||||||
WILL_LJMP(luaL_error(L, "connect: cannot parse ip address '%s'", ip));
|
WILL_LJMP(luaL_error(L, "connect: cannot parse destination address '%s'", ip));
|
||||||
|
if (low != high)
|
||||||
|
WILL_LJMP(luaL_error(L, "connect: port ranges not supported : address '%s'", ip));
|
||||||
|
memcpy(&conn->addr.to, addr, sizeof(struct sockaddr_storage));
|
||||||
|
|
||||||
/* Set port. */
|
/* Set port. */
|
||||||
if (conn->addr.to.ss_family == AF_INET)
|
if (low == 0) {
|
||||||
((struct sockaddr_in *)&conn->addr.to)->sin_port = htons(port);
|
if (conn->addr.to.ss_family == AF_INET) {
|
||||||
else if (conn->addr.to.ss_family == AF_INET6)
|
if (port == -1)
|
||||||
((struct sockaddr_in6 *)&conn->addr.to)->sin6_port = htons(port);
|
WILL_LJMP(luaL_error(L, "connect: port missing"));
|
||||||
|
((struct sockaddr_in *)&conn->addr.to)->sin_port = htons(port);
|
||||||
|
} else if (conn->addr.to.ss_family == AF_INET6) {
|
||||||
|
if (port == -1)
|
||||||
|
WILL_LJMP(luaL_error(L, "connect: port missing"));
|
||||||
|
((struct sockaddr_in6 *)&conn->addr.to)->sin6_port = htons(port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* it is important not to call the wakeup function directly but to
|
/* it is important not to call the wakeup function directly but to
|
||||||
* pass through task_wakeup(), because this one knows how to apply
|
* pass through task_wakeup(), because this one knows how to apply
|
||||||
|
Loading…
Reference in New Issue
Block a user