Browse Source

[Minor] Add default limit for rbl requests

tags/2.0
Vsevolod Stakhov 4 years ago
parent
commit
b38a1ad26b
2 changed files with 28 additions and 0 deletions
  1. 24
    0
      src/lua/lua_config.c
  2. 4
    0
      src/plugins/lua/rbl.lua

+ 24
- 0
src/lua/lua_config.c View File

@@ -810,6 +810,13 @@ LUA_FUNCTION_DEF (config, init_subsystem);
*/
LUA_FUNCTION_DEF (config, get_tld_path);

/***
* @method rspamd_config:get_dns_max_requests()
* Returns limit of DNS requests per task
* @return {number} number of dns requests allowed
*/
LUA_FUNCTION_DEF (config, get_dns_max_requests);

static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_module_opt),
LUA_INTERFACE_DEF (config, get_mempool),
@@ -882,6 +889,7 @@ static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, init_modules),
LUA_INTERFACE_DEF (config, init_subsystem),
LUA_INTERFACE_DEF (config, get_tld_path),
LUA_INTERFACE_DEF (config, get_dns_max_requests),
{"__tostring", rspamd_lua_class_tostring},
{"__newindex", lua_config_newindex},
{NULL, NULL}
@@ -4301,6 +4309,22 @@ lua_config_get_tld_path (lua_State *L)
return 1;
}

static gint
lua_config_get_dns_max_requests (lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_config *cfg = lua_check_config (L, 1);

if (cfg != NULL) {
lua_pushinteger (L, cfg->dns_max_requests);
}
else {
return luaL_error (L, "invalid arguments");
}

return 1;
}

static gint
lua_monitored_alive (lua_State *L)
{

+ 4
- 0
src/plugins/lua/rbl.lua View File

@@ -1097,6 +1097,10 @@ for key,rbl in pairs(opts.rbls or opts.rules) do
end
end

if not rbl.requests_limit then
rbl.requests_limit = rspamd_config:get_dns_max_requests()
end

local res,err = rule_schema:transform(rbl)
if not res then
rspamd_logger.errx(rspamd_config, 'invalid config for %s: %s, RBL is DISABLED',

Loading…
Cancel
Save