Skip to content

Commit 2d41d0e

Browse files
authored
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
1 parent 7182d46 commit 2d41d0e

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

doc/admin-guide/plugins/lua.en.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,73 @@ Here is an example:
452452

453453
:ref:`TOP <admin-plugins-ts-lua>`
454454

455+
ts.connection_limit_exempt_list_add
456+
------------------------------------
457+
**syntax:** *success = ts.connection_limit_exempt_list_add(IP_RANGES)*
458+
459+
**context:** global
460+
461+
**description**: Add IP ranges to the per-client connection limit exempt list. This function wraps the TSConnectionLimitExemptListAdd API.
462+
463+
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.
464+
465+
Returns true on success, false on failure.
466+
467+
Here is an example:
468+
469+
::
470+
471+
if ts.connection_limit_exempt_list_add('10.0.0.0/8,192.168.1.0/24') then
472+
ts.debug('Successfully added IP ranges to exempt list')
473+
else
474+
ts.error('Failed to add IP ranges to exempt list')
475+
end
476+
477+
:ref:`TOP <admin-plugins-ts-lua>`
478+
479+
ts.connection_limit_exempt_list_remove
480+
---------------------------------------
481+
**syntax:** *success = ts.connection_limit_exempt_list_remove(IP_RANGES)*
482+
483+
**context:** global
484+
485+
**description**: Remove IP ranges from the per-client connection limit exempt list. This function wraps the TSConnectionLimitExemptListRemove API.
486+
487+
The IP_RANGES parameter should be a string containing one or more IP address ranges in CIDR notation, separated by commas.
488+
489+
Returns true on success, false on failure.
490+
491+
Here is an example:
492+
493+
::
494+
495+
if ts.connection_limit_exempt_list_remove('192.168.1.0/24') then
496+
ts.debug('Successfully removed IP range from exempt list')
497+
else
498+
ts.error('Failed to remove IP range from exempt list')
499+
end
500+
501+
:ref:`TOP <admin-plugins-ts-lua>`
502+
503+
ts.connection_limit_exempt_list_clear
504+
--------------------------------------
505+
**syntax:** *ts.connection_limit_exempt_list_clear()*
506+
507+
**context:** global
508+
509+
**description**: Clear all IP ranges from the per-client connection limit exempt list. This function wraps the TSConnectionLimitExemptListClear API.
510+
511+
This function removes all entries from the exempt list.
512+
513+
Here is an example:
514+
515+
::
516+
517+
ts.connection_limit_exempt_list_clear()
518+
ts.debug('Cleared connection limit exempt list')
519+
520+
:ref:`TOP <admin-plugins-ts-lua>`
521+
455522
Remap status constants
456523
----------------------
457524
**context:** do_remap

plugins/lua/ts_lua_misc.cc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ static int ts_lua_get_config_dir(lua_State *L);
4040
static int ts_lua_get_runtime_dir(lua_State *L);
4141
static int ts_lua_get_plugin_dir(lua_State *L);
4242
static int ts_lua_get_traffic_server_version(lua_State *L);
43+
static int ts_lua_connection_limit_exempt_list_add(lua_State *L);
44+
static int ts_lua_connection_limit_exempt_list_remove(lua_State *L);
45+
static int ts_lua_connection_limit_exempt_list_clear(lua_State *L);
4346

4447
static int ts_lua_sleep_cleanup(ts_lua_async_item *ai);
4548
static int ts_lua_sleep_handler(TSCont contp, TSEvent event, void *edata);
@@ -136,6 +139,18 @@ ts_lua_inject_misc_api(lua_State *L)
136139
lua_pushcfunction(L, ts_lua_get_traffic_server_version);
137140
lua_setfield(L, -2, "get_traffic_server_version");
138141

142+
/* ts.connection_limit_exempt_list_add(...) */
143+
lua_pushcfunction(L, ts_lua_connection_limit_exempt_list_add);
144+
lua_setfield(L, -2, "connection_limit_exempt_list_add");
145+
146+
/* ts.connection_limit_exempt_list_remove(...) */
147+
lua_pushcfunction(L, ts_lua_connection_limit_exempt_list_remove);
148+
lua_setfield(L, -2, "connection_limit_exempt_list_remove");
149+
150+
/* ts.connection_limit_exempt_list_clear(...) */
151+
lua_pushcfunction(L, ts_lua_connection_limit_exempt_list_clear);
152+
lua_setfield(L, -2, "connection_limit_exempt_list_clear");
153+
139154
ts_lua_inject_misc_variables(L);
140155
}
141156

@@ -631,3 +646,54 @@ ts_lua_get_traffic_server_version(lua_State *L)
631646
lua_pushstring(L, s);
632647
return 1;
633648
}
649+
650+
static int
651+
ts_lua_connection_limit_exempt_list_add(lua_State *L)
652+
{
653+
size_t len;
654+
const char *ip_ranges;
655+
656+
ip_ranges = luaL_checklstring(L, 1, &len);
657+
658+
if (ip_ranges && len > 0) {
659+
TSReturnCode ret = TSConnectionLimitExemptListAdd(std::string_view(ip_ranges, len));
660+
if (ret == TS_SUCCESS) {
661+
lua_pushboolean(L, 1);
662+
} else {
663+
lua_pushboolean(L, 0);
664+
}
665+
} else {
666+
lua_pushboolean(L, 0);
667+
}
668+
669+
return 1;
670+
}
671+
672+
static int
673+
ts_lua_connection_limit_exempt_list_remove(lua_State *L)
674+
{
675+
size_t len;
676+
const char *ip_ranges;
677+
678+
ip_ranges = luaL_checklstring(L, 1, &len);
679+
680+
if (ip_ranges && len > 0) {
681+
TSReturnCode ret = TSConnectionLimitExemptListRemove(std::string_view(ip_ranges, len));
682+
if (ret == TS_SUCCESS) {
683+
lua_pushboolean(L, 1);
684+
} else {
685+
lua_pushboolean(L, 0);
686+
}
687+
} else {
688+
lua_pushboolean(L, 0);
689+
}
690+
691+
return 1;
692+
}
693+
694+
static int
695+
ts_lua_connection_limit_exempt_list_clear(lua_State * /* L ATS_UNUSED */)
696+
{
697+
TSConnectionLimitExemptListClear();
698+
return 0;
699+
}

0 commit comments

Comments
 (0)