commit ac15531: [Minor] Mx_check: Limit number of A requests per MX
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Nov 10 22:42:06 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-11-10 22:41:10 +0000
URL: https://github.com/rspamd/rspamd/commit/ac155317a5014716c9fb106f4feb54aeb16bbea6 (HEAD -> master)
[Minor] Mx_check: Limit number of A requests per MX
---
src/plugins/lua/mx_check.lua | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/src/plugins/lua/mx_check.lua b/src/plugins/lua/mx_check.lua
index d67524c21..e5ac13f4e 100644
--- a/src/plugins/lua/mx_check.lua
+++ b/src/plugins/lua/mx_check.lua
@@ -37,6 +37,7 @@ local settings = {
expire_novalid = 7200, -- 2 hours by default for no valid mxes
greylist_invalid = true, -- Greylist first message with invalid MX (require greylist plugin)
key_prefix = 'rmx',
+ max_mx_a_records = 5, -- Maximum number of A records to check per MX request
}
local redis_params
local exclude_domains
@@ -189,20 +190,22 @@ local function mx_check(task)
})
task:insert_result(settings.symbol_no_mx, 1.0, err)
else
+ -- Inverse sort by priority
table.sort(results, function(r1, r2)
- return r1['priority'] < r2['priority']
+ return r1['priority'] > r2['priority']
end)
- for _,mx in ipairs(results) do
- -- Not checked
- mxes[mx['name']] = {checked = false, working = false, ips = {}}
- end
- for _,mx in ipairs(results) do
+ local max_mx_to_resolve = math.min(#results, settings.max_mx_a_records)
+ lua_util.debugm(N, task,'check %s MX records (%d actually returned)',
+ max_mx_to_resolve, #results)
+ for i=1,max_mx_to_resolve do
+ local mx = results[i]
+ mxes[mx.name] = {checked = false, working = false, ips = {}}
local r = task:get_resolver()
-- XXX: maybe add ipv6?
r:resolve('a', {
- name = mx['name'],
- callback = gen_mx_a_callback(mx['name'], mxes),
+ name = mx.name,
+ callback = gen_mx_a_callback(mx.name, mxes),
task = task,
forced = true
})
More information about the Commits
mailing list