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 2d41d0e018 Lua plugin support for connection exempt list (#12849)
2d41d0e018 is described below
commit 2d41d0e01889507d6aae908eac226403f137470d
Author: Kit Chan <[email protected]>
AuthorDate: Tue Feb 17 16:55:46 2026 -0800
Lua plugin support for connection exempt list (#12849)
* Update ts_lua_misc.cc to add connection limit exempt list functions.
* Add Lua plugin documentation for connection limit exempt list APIs
* Update lua.en.rst
* Update ts_lua_misc.cc
* Refactor ts_lua_connection_limit_exempt_list_clear function
---
doc/admin-guide/plugins/lua.en.rst | 67 ++++++++++++++++++++++++++++++++++++++
plugins/lua/ts_lua_misc.cc | 66 +++++++++++++++++++++++++++++++++++++
2 files changed, 133 insertions(+)
diff --git a/doc/admin-guide/plugins/lua.en.rst
b/doc/admin-guide/plugins/lua.en.rst
index 08970e340e..bc6f7423ac 100644
--- a/doc/admin-guide/plugins/lua.en.rst
+++ b/doc/admin-guide/plugins/lua.en.rst
@@ -452,6 +452,73 @@ Here is an example:
:ref:`TOP <admin-plugins-ts-lua>`
+ts.connection_limit_exempt_list_add
+------------------------------------
+**syntax:** *success = ts.connection_limit_exempt_list_add(IP_RANGES)*
+
+**context:** global
+
+**description**: Add IP ranges to the per-client connection limit exempt list.
This function wraps the TSConnectionLimitExemptListAdd API.
+
+The IP_RANGES parameter should be a string containing one or more IP address
ranges in CIDR notation, separated by commas. Client connections from these IP
ranges will be exempt from per-client connection limits.
+
+Returns true on success, false on failure.
+
+Here is an example:
+
+::
+
+ if ts.connection_limit_exempt_list_add('10.0.0.0/8,192.168.1.0/24') then
+ ts.debug('Successfully added IP ranges to exempt list')
+ else
+ ts.error('Failed to add IP ranges to exempt list')
+ end
+
+:ref:`TOP <admin-plugins-ts-lua>`
+
+ts.connection_limit_exempt_list_remove
+---------------------------------------
+**syntax:** *success = ts.connection_limit_exempt_list_remove(IP_RANGES)*
+
+**context:** global
+
+**description**: Remove IP ranges from the per-client connection limit exempt
list. This function wraps the TSConnectionLimitExemptListRemove API.
+
+The IP_RANGES parameter should be a string containing one or more IP address
ranges in CIDR notation, separated by commas.
+
+Returns true on success, false on failure.
+
+Here is an example:
+
+::
+
+ if ts.connection_limit_exempt_list_remove('192.168.1.0/24') then
+ ts.debug('Successfully removed IP range from exempt list')
+ else
+ ts.error('Failed to remove IP range from exempt list')
+ end
+
+:ref:`TOP <admin-plugins-ts-lua>`
+
+ts.connection_limit_exempt_list_clear
+--------------------------------------
+**syntax:** *ts.connection_limit_exempt_list_clear()*
+
+**context:** global
+
+**description**: Clear all IP ranges from the per-client connection limit
exempt list. This function wraps the TSConnectionLimitExemptListClear API.
+
+This function removes all entries from the exempt list.
+
+Here is an example:
+
+::
+
+ ts.connection_limit_exempt_list_clear()
+ ts.debug('Cleared connection limit exempt list')
+
+:ref:`TOP <admin-plugins-ts-lua>`
+
Remap status constants
----------------------
**context:** do_remap
diff --git a/plugins/lua/ts_lua_misc.cc b/plugins/lua/ts_lua_misc.cc
index ffbb9d3a80..ce3fc8c99b 100644
--- a/plugins/lua/ts_lua_misc.cc
+++ b/plugins/lua/ts_lua_misc.cc
@@ -40,6 +40,9 @@ static int ts_lua_get_config_dir(lua_State *L);
static int ts_lua_get_runtime_dir(lua_State *L);
static int ts_lua_get_plugin_dir(lua_State *L);
static int ts_lua_get_traffic_server_version(lua_State *L);
+static int ts_lua_connection_limit_exempt_list_add(lua_State *L);
+static int ts_lua_connection_limit_exempt_list_remove(lua_State *L);
+static int ts_lua_connection_limit_exempt_list_clear(lua_State *L);
static int ts_lua_sleep_cleanup(ts_lua_async_item *ai);
static int ts_lua_sleep_handler(TSCont contp, TSEvent event, void *edata);
@@ -136,6 +139,18 @@ ts_lua_inject_misc_api(lua_State *L)
lua_pushcfunction(L, ts_lua_get_traffic_server_version);
lua_setfield(L, -2, "get_traffic_server_version");
+ /* ts.connection_limit_exempt_list_add(...) */
+ lua_pushcfunction(L, ts_lua_connection_limit_exempt_list_add);
+ lua_setfield(L, -2, "connection_limit_exempt_list_add");
+
+ /* ts.connection_limit_exempt_list_remove(...) */
+ lua_pushcfunction(L, ts_lua_connection_limit_exempt_list_remove);
+ lua_setfield(L, -2, "connection_limit_exempt_list_remove");
+
+ /* ts.connection_limit_exempt_list_clear(...) */
+ lua_pushcfunction(L, ts_lua_connection_limit_exempt_list_clear);
+ lua_setfield(L, -2, "connection_limit_exempt_list_clear");
+
ts_lua_inject_misc_variables(L);
}
@@ -631,3 +646,54 @@ ts_lua_get_traffic_server_version(lua_State *L)
lua_pushstring(L, s);
return 1;
}
+
+static int
+ts_lua_connection_limit_exempt_list_add(lua_State *L)
+{
+ size_t len;
+ const char *ip_ranges;
+
+ ip_ranges = luaL_checklstring(L, 1, &len);
+
+ if (ip_ranges && len > 0) {
+ TSReturnCode ret =
TSConnectionLimitExemptListAdd(std::string_view(ip_ranges, len));
+ if (ret == TS_SUCCESS) {
+ lua_pushboolean(L, 1);
+ } else {
+ lua_pushboolean(L, 0);
+ }
+ } else {
+ lua_pushboolean(L, 0);
+ }
+
+ return 1;
+}
+
+static int
+ts_lua_connection_limit_exempt_list_remove(lua_State *L)
+{
+ size_t len;
+ const char *ip_ranges;
+
+ ip_ranges = luaL_checklstring(L, 1, &len);
+
+ if (ip_ranges && len > 0) {
+ TSReturnCode ret =
TSConnectionLimitExemptListRemove(std::string_view(ip_ranges, len));
+ if (ret == TS_SUCCESS) {
+ lua_pushboolean(L, 1);
+ } else {
+ lua_pushboolean(L, 0);
+ }
+ } else {
+ lua_pushboolean(L, 0);
+ }
+
+ return 1;
+}
+
+static int
+ts_lua_connection_limit_exempt_list_clear(lua_State * /* L ATS_UNUSED */)
+{
+ TSConnectionLimitExemptListClear();
+ return 0;
+}