diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-19 15:14:58 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-19 15:14:58 +0100 |
commit | b87eb86a42e7d450a71e4b73b4910649b2d34c4e (patch) | |
tree | 71513eb3c2ce36dffe939ec68ebd617ec3877e3c | |
parent | 7604819ab9e65d0177ab35888c49ec791b98b649 (diff) | |
download | rspamd-b87eb86a42e7d450a71e4b73b4910649b2d34c4e.tar.gz rspamd-b87eb86a42e7d450a71e4b73b4910649b2d34c4e.zip |
[Project] Ressurect empty prefilters as connection filters
-rw-r--r-- | src/libserver/rspamd_symcache.c | 59 | ||||
-rw-r--r-- | src/libserver/rspamd_symcache.h | 9 | ||||
-rw-r--r-- | src/libserver/task.c | 5 | ||||
-rw-r--r-- | src/libserver/task.h | 5 |
4 files changed, 66 insertions, 12 deletions
diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c index 3236a5e5e..831b98a3d 100644 --- a/src/libserver/rspamd_symcache.c +++ b/src/libserver/rspamd_symcache.c @@ -151,8 +151,9 @@ struct rspamd_symcache { GHashTable *items_by_symbol; GPtrArray *items_by_id; struct symcache_order *items_by_order; - GPtrArray *filters; + GPtrArray *connfilters; GPtrArray *prefilters; + GPtrArray *filters; GPtrArray *postfilters; GPtrArray *composites; GPtrArray *idempotent; @@ -744,6 +745,7 @@ rspamd_symcache_post_init (struct rspamd_symcache *cache) } } + g_ptr_array_sort_with_data (cache->connfilters, prefilters_cmp, cache); g_ptr_array_sort_with_data (cache->prefilters, prefilters_cmp, cache); g_ptr_array_sort_with_data (cache->postfilters, postfilters_cmp, cache); g_ptr_array_sort_with_data (cache->idempotent, postfilters_cmp, cache); @@ -1116,6 +1118,11 @@ rspamd_symcache_add_symbol (struct rspamd_symcache *cache, g_ptr_array_add (cache->postfilters, item); item->container = cache->postfilters; } + else if (item->type & SYMBOL_TYPE_CONNFILTER) { + type_str = "connfilter"; + g_ptr_array_add (cache->connfilters, item); + item->container = cache->connfilters; + } else { item->is_filter = TRUE; g_ptr_array_add (cache->filters, item); @@ -1301,8 +1308,9 @@ rspamd_symcache_destroy (struct rspamd_symcache *cache) g_hash_table_destroy (cache->items_by_symbol); g_ptr_array_free (cache->items_by_id, TRUE); rspamd_mempool_delete (cache->static_pool); - g_ptr_array_free (cache->filters, TRUE); + g_ptr_array_free (cache->connfilters, TRUE); g_ptr_array_free (cache->prefilters, TRUE); + g_ptr_array_free (cache->filters, TRUE); g_ptr_array_free (cache->postfilters, TRUE); g_ptr_array_free (cache->idempotent, TRUE); g_ptr_array_free (cache->composites, TRUE); @@ -1328,8 +1336,9 @@ rspamd_symcache_new (struct rspamd_config *cfg) cache->items_by_symbol = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); cache->items_by_id = g_ptr_array_new (); - cache->filters = g_ptr_array_new (); + cache->connfilters = g_ptr_array_new (); cache->prefilters = g_ptr_array_new (); + cache->filters = g_ptr_array_new (); cache->postfilters = g_ptr_array_new (); cache->idempotent = g_ptr_array_new (); cache->composites = g_ptr_array_new (); @@ -2069,6 +2078,50 @@ rspamd_symcache_process_symbols (struct rspamd_task *task, start_events_pending = rspamd_session_events_pending (task->s); switch (stage) { + case RSPAMD_TASK_STAGE_CONNFILTERS: + /* Check for connection filters */ + saved_priority = G_MININT; + all_done = TRUE; + + for (i = 0; i < (gint) cache->connfilters->len; i++) { + item = g_ptr_array_index (cache->connfilters, i); + dyn_item = rspamd_symcache_get_dynamic (checkpoint, item); + + if (RSPAMD_TASK_IS_SKIPPED (task)) { + return TRUE; + } + + if (!CHECK_START_BIT (checkpoint, dyn_item) && + !CHECK_FINISH_BIT (checkpoint, dyn_item)) { + + if (checkpoint->has_slow) { + /* Delay */ + checkpoint->has_slow = FALSE; + + return FALSE; + } + /* Check priorities */ + if (saved_priority == G_MININT) { + saved_priority = item->priority; + } + else { + if (item->priority < saved_priority && + rspamd_session_events_pending (task->s) > start_events_pending) { + /* + * Delay further checks as we have higher + * priority filters to be processed + */ + return FALSE; + } + } + + rspamd_symcache_check_symbol (task, cache, item, + checkpoint); + all_done = FALSE; + } + } + break; + case RSPAMD_TASK_STAGE_PRE_FILTERS: /* Check for prefilters */ saved_priority = G_MININT; diff --git a/src/libserver/rspamd_symcache.h b/src/libserver/rspamd_symcache.h index c220b1ccc..67c753e39 100644 --- a/src/libserver/rspamd_symcache.h +++ b/src/libserver/rspamd_symcache.h @@ -48,10 +48,11 @@ enum rspamd_symbol_type { SYMBOL_TYPE_CLASSIFIER = (1u << 6u), SYMBOL_TYPE_FINE = (1u << 7u), SYMBOL_TYPE_EMPTY = (1u << 8u), /* Allow execution on empty tasks */ - SYMBOL_TYPE_PREFILTER = (1u << 9u), - SYMBOL_TYPE_POSTFILTER = (1u << 10u), - SYMBOL_TYPE_NOSTAT = (1u << 11u), /* Skip as statistical symbol */ - SYMBOL_TYPE_IDEMPOTENT = (1u << 12u), /* Symbol cannot change metric */ + SYMBOL_TYPE_CONNFILTER = (1u << 9u), /* Connection stage filter */ + SYMBOL_TYPE_PREFILTER = (1u << 10u), + SYMBOL_TYPE_POSTFILTER = (1u << 11u), + SYMBOL_TYPE_NOSTAT = (1u << 12u), /* Skip as statistical symbol */ + SYMBOL_TYPE_IDEMPOTENT = (1u << 13u), /* Symbol cannot change metric */ SYMBOL_TYPE_TRIVIAL = (1u << 14u), /* Symbol is trivial */ SYMBOL_TYPE_MIME_ONLY = (1u << 15u), /* Symbol is mime only */ SYMBOL_TYPE_EXPLICIT_DISABLE = (1u << 16u), /* Symbol should be disabled explicitly only */ diff --git a/src/libserver/task.c b/src/libserver/task.c index 6b93ac810..e7a83a603 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -727,6 +727,7 @@ rspamd_task_process (struct rspamd_task *task, guint stages) } break; + case RSPAMD_TASK_STAGE_CONNFILTERS: case RSPAMD_TASK_STAGE_PRE_FILTERS: case RSPAMD_TASK_STAGE_FILTERS: all_done = rspamd_symcache_process_symbols (task, task->cfg->cache, st); @@ -1806,8 +1807,8 @@ rspamd_task_stage_name (enum rspamd_task_stage stg) case RSPAMD_TASK_STAGE_CONNECT: ret = "connect"; break; - case RSPAMD_TASK_STAGE_ENVELOPE: - ret = "envelope"; + case RSPAMD_TASK_STAGE_CONNFILTERS: + ret = "connection_filter"; break; case RSPAMD_TASK_STAGE_READ_MESSAGE: ret = "read_message"; diff --git a/src/libserver/task.h b/src/libserver/task.h index 0e23ea55d..ca49ed1e0 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -40,7 +40,7 @@ enum rspamd_command { enum rspamd_task_stage { RSPAMD_TASK_STAGE_CONNECT = (1u << 0u), - RSPAMD_TASK_STAGE_ENVELOPE = (1u << 1u), + RSPAMD_TASK_STAGE_CONNFILTERS = (1u << 1u), RSPAMD_TASK_STAGE_READ_MESSAGE = (1u << 2u), RSPAMD_TASK_STAGE_PROCESS_MESSAGE = (1u << 3u), RSPAMD_TASK_STAGE_PRE_FILTERS = (1u << 4u), @@ -60,7 +60,7 @@ enum rspamd_task_stage { }; #define RSPAMD_TASK_PROCESS_ALL (RSPAMD_TASK_STAGE_CONNECT | \ - RSPAMD_TASK_STAGE_ENVELOPE | \ + RSPAMD_TASK_STAGE_CONNFILTERS | \ RSPAMD_TASK_STAGE_READ_MESSAGE | \ RSPAMD_TASK_STAGE_PRE_FILTERS | \ RSPAMD_TASK_STAGE_PROCESS_MESSAGE | \ @@ -77,7 +77,6 @@ enum rspamd_task_stage { RSPAMD_TASK_STAGE_IDEMPOTENT | \ RSPAMD_TASK_STAGE_DONE) #define RSPAMD_TASK_PROCESS_LEARN (RSPAMD_TASK_STAGE_CONNECT | \ - RSPAMD_TASK_STAGE_ENVELOPE | \ RSPAMD_TASK_STAGE_READ_MESSAGE | \ RSPAMD_TASK_STAGE_PROCESS_MESSAGE | \ RSPAMD_TASK_STAGE_CLASSIFIERS_PRE | \ |