diff options
author | Michael Kuron <mkuron@users.noreply.github.com> | 2017-07-15 16:11:51 +0200 |
---|---|---|
committer | Michael Kuron <mkuron@users.noreply.github.com> | 2017-07-15 16:20:55 +0200 |
commit | cbc1bbf4cbac59c9b9bb3ed6ba95f7bd883baa24 (patch) | |
tree | f5120e2b9134cc40faed0a30a04cf5564a09a45f /src | |
parent | e5cefe177e6ab388c5dd12f507786c6c10fbb73c (diff) | |
download | rspamd-cbc1bbf4cbac59c9b9bb3ed6ba95f7bd883baa24.tar.gz rspamd-cbc1bbf4cbac59c9b9bb3ed6ba95f7bd883baa24.zip |
IP netmask support for multimap
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/lua/multimap.lua | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index 0e7da23e1..e6f6f044f 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -35,7 +35,12 @@ local urls = {} local value_types = { ip = { - get_value = function(ip) return ip:to_string() end, + get_value = function(ip) + if type(ip) == 'string' then + return ip + end + return ip:to_string() + end, }, from = { get_value = function(val) return val end, @@ -373,14 +378,14 @@ local function multimap_callback(task, rule) if r['cdb'] then local srch = value if r['type'] == 'ip' then - srch = value:to_string() + srch = value_types['ip'].get_value(value) end ret = r['cdb']:lookup(srch) elseif r['redis_key'] then local srch = value 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_types['ip'].get_value(value) end ret = rspamd_redis_make_request(task, redis_params, -- connect params @@ -636,6 +641,14 @@ local function multimap_callback(task, rule) if ip:is_valid() then if rt == 'ip' then match_rule(rule, ip) + local bits = 128 + if ip:get_version() == 4 then + bits = 32 + end + for i=bits,1,-1 do + local nip = ip:apply_mask(i):to_string() .. "/" .. i + match_rule(rule, nip) + end else local cb = function (_, to_resolve, results, err) task:inc_dns_req() |