diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-16 14:53:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-16 14:53:00 +0100 |
commit | 811455baad4c6fc47d824b25d357add2e62c1664 (patch) | |
tree | 398b10d8d8bd56d00039df14ba5289e67f620d1f | |
parent | e97e120cd2d57337401e9524807c7ec6eb35a2ac (diff) | |
parent | e01285b6ceab5b85942fa0c1445a5eeeb8dda401 (diff) | |
download | rspamd-811455baad4c6fc47d824b25d357add2e62c1664.tar.gz rspamd-811455baad4c6fc47d824b25d357add2e62c1664.zip |
Merge pull request #1753 from mkuron/multimap_cidr
IP netmask support for Redis multimap
-rw-r--r-- | src/plugins/lua/multimap.lua | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index 0e7da23e1..ca32a8d21 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -377,18 +377,31 @@ local function multimap_callback(task, rule) end ret = r['cdb']:lookup(srch) elseif r['redis_key'] then - local srch = value + local srch = {value} + local cmd = 'HGET' if r['type'] == 'ip' or (r['type'] == 'received' and (r['filter'] == 'real_ip' or r['filter'] == 'from_ip' or not r['filter'])) then - srch = value:to_string() + srch = {value:to_string()} + cmd = 'HMGET' + local maxbits = 128 + local minbits = 32 + if value:get_version() == 4 then + maxbits = 32 + minbits = 8 + end + for i=maxbits,minbits,-1 do + local nip = value:apply_mask(i):to_string() .. "/" .. i + table.insert(srch, nip) + end end + table.insert(srch, 1, r['redis_key']) ret = rspamd_redis_make_request(task, redis_params, -- connect params r['redis_key'], -- hash key false, -- is write redis_map_cb, --callback - 'HGET', -- command - {r['redis_key'], srch} -- arguments + cmd, -- command + srch -- arguments ) return ret @@ -470,6 +483,14 @@ local function multimap_callback(task, rule) local function match_rule(r, value) local function rule_callback(result) if result then + if type(result) == 'table' then + for _,rs in ipairs(result) do + if type(rs) ~= 'userdata' then + rule_callback(rs) + end + end + return + end local _,symbol,score = parse_ret(r, result) if symbol and r['symbols_set'] then if not r['symbols_set'][symbol] then |