This is an automated email from the ASF dual-hosted git repository.
kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new c69a5e1ed3 lua: minimal support for Unix socket incoming connections
(#12510)
c69a5e1ed3 is described below
commit c69a5e1ed36f14697f0abcd3e9592eeecc2cd3d9
Author: vuori <[email protected]>
AuthorDate: Wed Oct 22 03:25:55 2025 +0300
lua: minimal support for Unix socket incoming connections (#12510)
* lua: minimal support for Unix socket incoming connections.
* lua: check address family value for server_request calls.
---
doc/admin-guide/plugins/lua.en.rst | 1 +
plugins/lua/ts_lua_client_request.cc | 10 ++++++----
plugins/lua/ts_lua_http.cc | 2 ++
plugins/lua/ts_lua_server_request.cc | 29 ++++++++++++++++++++++-------
plugins/lua/ts_lua_vconn.cc | 10 ++++++----
5 files changed, 37 insertions(+), 15 deletions(-)
diff --git a/doc/admin-guide/plugins/lua.en.rst
b/doc/admin-guide/plugins/lua.en.rst
index aba1ff7db3..dae206f1de 100644
--- a/doc/admin-guide/plugins/lua.en.rst
+++ b/doc/admin-guide/plugins/lua.en.rst
@@ -1838,6 +1838,7 @@ Socket address family
TS_LUA_AF_INET (2)
TS_LUA_AF_INET6 (10)
+ TS_LUA_AF_UNIX (1)
:ref:`TOP <admin-plugins-ts-lua>`
diff --git a/plugins/lua/ts_lua_client_request.cc
b/plugins/lua/ts_lua_client_request.cc
index ac2671cf10..0fc9e534ba 100644
--- a/plugins/lua/ts_lua_client_request.cc
+++ b/plugins/lua/ts_lua_client_request.cc
@@ -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);
@@ -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;
}
@@ -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);
@@ -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;
}
@@ -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);
diff --git a/plugins/lua/ts_lua_http.cc b/plugins/lua/ts_lua_http.cc
index b1bc7c104a..cac64dc44c 100644
--- a/plugins/lua/ts_lua_http.cc
+++ b/plugins/lua/ts_lua_http.cc
@@ -1151,6 +1151,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);
diff --git a/plugins/lua/ts_lua_server_request.cc
b/plugins/lua/ts_lua_server_request.cc
index 26c2897436..913b7fba47 100644
--- a/plugins/lua/ts_lua_server_request.cc
+++ b/plugins/lua/ts_lua_server_request.cc
@@ -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");
}
static void
@@ -768,7 +771,11 @@ ts_lua_server_request_server_addr_get_ip(lua_State *L)
inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6
*)server_ip)->sin6_addr, sip, sizeof(sip));
}
- lua_pushstring(L, sip);
+ if (sip[0] == '\0') {
+ lua_pushnil(L);
+ } else {
+ lua_pushstring(L, sip);
+ }
}
return 1;
@@ -779,7 +786,7 @@ ts_lua_server_request_server_addr_get_port(lua_State *L)
{
struct sockaddr const *server_ip;
ts_lua_http_ctx *http_ctx;
- int port;
+ int port = 0;
GET_HTTP_CONTEXT(http_ctx, L);
@@ -791,7 +798,7 @@ ts_lua_server_request_server_addr_get_port(lua_State *L)
} else {
if (server_ip->sa_family == AF_INET) {
port = ((struct sockaddr_in *)server_ip)->sin_port;
- } else {
+ } else if (server_ip->sa_family == AF_INET6) {
port = ((struct sockaddr_in6 *)server_ip)->sin6_port;
}
@@ -806,7 +813,7 @@
ts_lua_server_request_server_addr_get_outgoing_port(lua_State *L)
{
struct sockaddr const *outgoing_addr;
ts_lua_http_ctx *http_ctx;
- int port;
+ int port = 0;
GET_HTTP_CONTEXT(http_ctx, L);
@@ -818,7 +825,7 @@
ts_lua_server_request_server_addr_get_outgoing_port(lua_State *L)
} else {
if (outgoing_addr->sa_family == AF_INET) {
port = ((struct sockaddr_in *)outgoing_addr)->sin_port;
- } else {
+ } else if (outgoing_addr->sa_family == AF_INET6) {
port = ((struct sockaddr_in6 *)outgoing_addr)->sin6_port;
}
@@ -855,6 +862,8 @@ ts_lua_server_request_server_addr_get_addr(lua_State *L)
port = ntohs(((struct sockaddr_in6 *)server_ip)->sin6_port);
inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6
*)server_ip)->sin6_addr, sip, sizeof(sip));
family = AF_INET6;
+ } else if (server_ip->sa_family == AF_UNIX) {
+ family = AF_UNIX;
}
lua_pushstring(L, sip);
@@ -892,6 +901,8 @@
ts_lua_server_request_server_addr_get_nexthop_addr(lua_State *L)
port = ntohs(((struct sockaddr_in6 *)server_ip)->sin6_port);
inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6
*)server_ip)->sin6_addr, sip, sizeof(sip));
family = AF_INET6;
+ } else if (server_ip->sa_family == AF_UNIX) {
+ family = AF_UNIX;
}
lua_pushstring(L, sip);
@@ -963,12 +974,14 @@ ts_lua_server_request_server_addr_set_addr(lua_State *L)
if (!inet_pton(family, sip, &addr.sin4.sin_addr)) {
return luaL_error(L, "invalid ipv4 address");
}
- } else {
+ } else if (family == AF_INET6) {
addr.sin6.sin6_family = AF_INET6;
addr.sin6.sin6_port = htons(port);
if (!inet_pton(family, sip, &addr.sin6.sin6_addr)) {
return luaL_error(L, "invalid ipv6 address");
}
+ } else {
+ return luaL_error(L, "invalid address family");
}
TSHttpTxnServerAddrSet(http_ctx->txnp, &addr.sa);
@@ -1009,12 +1022,14 @@
ts_lua_server_request_server_addr_set_outgoing_addr(lua_State *L)
if (!inet_pton(family, sip, &addr.sin4.sin_addr)) {
return luaL_error(L, "invalid ipv4 address");
}
- } else {
+ } else if (family == AF_INET6) {
addr.sin6.sin6_family = AF_INET6;
addr.sin6.sin6_port = htons(port);
if (!inet_pton(family, sip, &addr.sin6.sin6_addr)) {
return luaL_error(L, "invalid ipv6 address");
}
+ } else {
+ return luaL_error(L, "invalid address family");
}
TSHttpTxnOutgoingAddrSet(http_ctx->txnp, &addr.sa);
diff --git a/plugins/lua/ts_lua_vconn.cc b/plugins/lua/ts_lua_vconn.cc
index 0c7dd4d34f..62781be430 100644
--- a/plugins/lua/ts_lua_vconn.cc
+++ b/plugins/lua/ts_lua_vconn.cc
@@ -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);
@@ -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);