Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/admin-guide/plugins/lua.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,7 @@ Socket address family

TS_LUA_AF_INET (2)
TS_LUA_AF_INET6 (10)
TS_LUA_AF_UNIX (1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these variables are really used when we are making changes to the outgoing address. So there is no need to support AF_UNIX here



:ref:`TOP <admin-plugins-ts-lua>`
Expand Down
10 changes: 6 additions & 4 deletions plugins/lua/ts_lua_client_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ ts_lua_client_request_client_addr_get_port(lua_State *L)
{
struct sockaddr const *client_ip;
ts_lua_http_ctx *http_ctx;
int port;
int port = 0;

GET_HTTP_CONTEXT(http_ctx, L);

Expand All @@ -802,7 +802,7 @@ ts_lua_client_request_client_addr_get_port(lua_State *L)
} else {
if (client_ip->sa_family == AF_INET) {
port = ((struct sockaddr_in *)client_ip)->sin_port;
} else {
} else if (client_ip->sa_family == AF_INET6) {
port = ((struct sockaddr_in6 *)client_ip)->sin6_port;
}

Expand All @@ -817,7 +817,7 @@ ts_lua_client_request_client_addr_get_incoming_port(lua_State *L)
{
struct sockaddr const *incoming_addr;
ts_lua_http_ctx *http_ctx;
int port;
int port = 0;

GET_HTTP_CONTEXT(http_ctx, L);

Expand All @@ -829,7 +829,7 @@ ts_lua_client_request_client_addr_get_incoming_port(lua_State *L)
} else {
if (incoming_addr->sa_family == AF_INET) {
port = ((struct sockaddr_in *)incoming_addr)->sin_port;
} else {
} else if (incoming_addr->sa_family == AF_INET6) {
port = ((struct sockaddr_in6 *)incoming_addr)->sin6_port;
}

Expand Down Expand Up @@ -866,6 +866,8 @@ ts_lua_client_request_client_addr_get_addr(lua_State *L)
port = ntohs(((struct sockaddr_in6 *)client_ip)->sin6_port);
inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6 *)client_ip)->sin6_addr, cip, sizeof(cip));
family = AF_INET6;
} else if (client_ip->sa_family == AF_UNIX) {
family = AF_UNIX;
}

lua_pushstring(L, cip);
Expand Down
2 changes: 2 additions & 0 deletions plugins/lua/ts_lua_http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,8 @@ ts_lua_http_get_ssn_remote_addr(lua_State *L)
port = ntohs(((struct sockaddr_in6 *)client_ip)->sin6_port);
inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6 *)client_ip)->sin6_addr, cip, sizeof(cip));
family = AF_INET6;
} else if (client_ip->sa_family == AF_UNIX) {
family = AF_UNIX;
}

lua_pushstring(L, cip);
Expand Down
3 changes: 3 additions & 0 deletions plugins/lua/ts_lua_server_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ ts_lua_inject_server_request_server_addr_api(lua_State *L)

lua_pushinteger(L, AF_INET6);
lua_setglobal(L, "TS_LUA_AF_INET6");

lua_pushinteger(L, AF_UNIX);
lua_setglobal(L, "TS_LUA_AF_UNIX");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these variables are really used when we are making changes to the outgoing address. So there is no need to support AF_UNIX here

}

static void
Expand Down
10 changes: 6 additions & 4 deletions plugins/lua/ts_lua_vconn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ static int
ts_lua_vconn_get_remote_addr(lua_State *L)
{
ts_lua_vconn_ctx *vconn_ctx;
int port;
int family;
char sip[128];
int port = 0;
int family = AF_UNSPEC;
char sip[128] = "";

GET_VCONN_CONTEXT(vconn_ctx, L);

Expand All @@ -73,10 +73,12 @@ ts_lua_vconn_get_remote_addr(lua_State *L)
port = ntohs(((struct sockaddr_in *)addr)->sin_port);
inet_ntop(AF_INET, (const void *)&((struct sockaddr_in *)addr)->sin_addr, sip, sizeof(sip));
family = AF_INET;
} else {
} else if (addr->sa_family == AF_INET6) {
port = ntohs(((struct sockaddr_in6 *)addr)->sin6_port);
inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6 *)addr)->sin6_addr, sip, sizeof(sip));
family = AF_INET6;
} else if (addr->sa_family == AF_UNIX) {
family = AF_UNIX;
}

lua_pushstring(L, sip);
Expand Down