}
if (elt && (elt->flags & KV_ELT_INTEGER) != 0) {
lp = &ELT_LONG (elt);
- *lp += *value;
- *value = *lp;
+ /* Handle need expire here */
+ if (elt->flags & KV_ELT_NEED_EXPIRE) {
+ *lp = *value;
+ }
+ else {
+ *lp += *value;
+ *value = *lp;
+ }
elt->age = time (NULL);
if (storage->backend) {
if (storage->backend->replace_func (storage->backend, key, keylen, elt)) {
if (elt && (elt->flags & KV_ELT_PERSISTENT) == 0 && elt->expire > 0) {
/* Check expiration */
if (now - elt->age > elt->expire) {
+ /* Set need expire as we have no write lock here */
+ elt->flags |= KV_ELT_NEED_EXPIRE;
elt = NULL;
}
}
local symbol = 'IP_SCORE'
-- This score is used for normalization of scores from keystorage
local normalize_score = 100
+local whitelist = nil
+local expire = 240
-- Set score based on metric's action
local ip_score_set = function(task)
end
end
end
- rspamd_redis.make_request(task, 'localhost', 6050, cb_set, 'SET %b %b %b', ip, '100', '0')
+ rspamd_redis.make_request(task, keystorage_host, keystorage_port, cb_set, 'SET %b %b %b', ip, expire, '0')
else
rspamd_logger.info('got error while incrementing: ' .. err)
end
end
local action = task:get_metric_action(metric)
if action then
+ -- Check whitelist
+ if whitelist then
+ local ipnum = task:get_from_ip_num()
+ if ipnum and whitelist:get_key(ipnum) then
+ -- Address is whitelisted
+ return
+ end
+ end
+ -- Now check action
if action == 'reject' then
local ip = task:get_from_ip()
if ip then
local ip_score_check = function(task)
local cb = function(task, err, data)
if err then
- -- Key is not found
+ -- Key is not found or error occured
return
elseif data then
local score = tonumber(data)
end
local ip = task:get_from_ip()
if ip then
+ if whitelist then
+ local ipnum = task:get_from_ip_num()
+ if whitelist:get_key(ipnum) then
+ -- Address is whitelisted
+ return
+ end
+ end
rspamd_redis.make_request(task, keystorage_host, keystorage_port, cb, 'GET %b', ip)
end
end
if opts['normalize_score'] then
normalize_score = opts['normalize_score']
end
+ if opts['whitelist'] then
+ whitelist = rspamd_config:add_radix_map(opts['whitelist'])
+ end
+ if opts['expire'] then
+ expire = opts['expire']
+ end
end
end
rspamd_config:register_module_option('ip_score', 'no_action_score', 'int')
rspamd_config:register_module_option('ip_score', 'symbol', 'string')
rspamd_config:register_module_option('ip_score', 'normalize_score', 'uint')
+ rspamd_config:register_module_option('ip_score', 'whitelist', 'map')
+ rspamd_config:register_module_option('ip_score', 'expire', 'uint')
configure_ip_score_module()
if keystorage_host and keystorage_port and normalize_score > 0 then