commit 3d2cadb: [Project] Implement concept of adaptive disabling of the rules

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Feb 12 15:07:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-02-12 11:59:25 +0000
URL: https://github.com/rspamd/rspamd/commit/3d2cadb16676133ac3007da65630996168be3c91

[Project] Implement concept of adaptive disabling of the rules

---
 src/libserver/rspamd_symcache.c | 15 ++++++++-------
 src/libserver/rspamd_symcache.h | 12 ++++++++++++
 src/lua/lua_task.c              |  6 ++++--
 3 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c
index f6487f4d8..92f75ecbb 100644
--- a/src/libserver/rspamd_symcache.c
+++ b/src/libserver/rspamd_symcache.c
@@ -235,8 +235,6 @@ static void rspamd_symcache_disable_symbol_checkpoint (struct rspamd_task *task,
 		struct rspamd_symcache *cache, const gchar *symbol);
 static void rspamd_symcache_enable_symbol_checkpoint (struct rspamd_task *task,
 		struct rspamd_symcache *cache, const gchar *symbol);
-static void rspamd_symcache_disable_all_symbols (struct rspamd_task *task,
-		struct rspamd_symcache *cache);
 
 static void
 rspamd_symcache_order_dtor (gpointer p)
@@ -1598,7 +1596,8 @@ rspamd_symcache_process_settings (struct rspamd_task *task,
 
 	if (enabled) {
 		/* Disable all symbols but selected */
-		rspamd_symcache_disable_all_symbols (task, cache);
+		rspamd_symcache_disable_all_symbols (task, cache,
+				SYMBOL_TYPE_EXPLICIT_DISABLE);
 		already_disabled = TRUE;
 		it = NULL;
 
@@ -1615,7 +1614,8 @@ rspamd_symcache_process_settings (struct rspamd_task *task,
 		it = NULL;
 
 		if (!already_disabled) {
-			rspamd_symcache_disable_all_symbols (task, cache);
+			rspamd_symcache_disable_all_symbols (task, cache,
+					SYMBOL_TYPE_EXPLICIT_DISABLE);
 		}
 
 		while ((cur = ucl_iterate_object (enabled, &it, true)) != NULL) {
@@ -2274,9 +2274,10 @@ rspamd_symcache_stats_symbols_count (struct rspamd_symcache *cache)
 }
 
 
-static void
+void
 rspamd_symcache_disable_all_symbols (struct rspamd_task *task,
-		struct rspamd_symcache *cache)
+									 struct rspamd_symcache *cache,
+									 guint skip_mask)
 {
 	struct cache_savepoint *checkpoint;
 	guint i;
@@ -2295,7 +2296,7 @@ rspamd_symcache_disable_all_symbols (struct rspamd_task *task,
 	PTR_ARRAY_FOREACH (cache->items_by_id, i, item) {
 		dyn_item = rspamd_symcache_get_dynamic (checkpoint, item);
 
-		if (!(item->type & SYMBOL_TYPE_SQUEEZED)) {
+		if (!(item->type & (SYMBOL_TYPE_SQUEEZED|skip_mask))) {
 			SET_FINISH_BIT (checkpoint, dyn_item);
 			SET_START_BIT (checkpoint, dyn_item);
 		}
diff --git a/src/libserver/rspamd_symcache.h b/src/libserver/rspamd_symcache.h
index ab9c568e1..b5e029a6b 100644
--- a/src/libserver/rspamd_symcache.h
+++ b/src/libserver/rspamd_symcache.h
@@ -48,6 +48,8 @@ enum rspamd_symbol_type {
 	SYMBOL_TYPE_SQUEEZED = (1 << 13), /* Symbol is squeezed inside Lua */
 	SYMBOL_TYPE_TRIVIAL = (1 << 14), /* Symbol is trivial */
 	SYMBOL_TYPE_MIME_ONLY = (1 << 15), /* Symbol is mime only */
+	SYMBOL_TYPE_EXPLICIT_DISABLE = (1 << 16), /* Symbol should be disabled explicitly only */
+	SYMBOL_TYPE_IGNORE_PASSTHROUGH = (1 << 17), /* Symbol ignores passthrough result */
 };
 
 /**
@@ -374,4 +376,14 @@ gboolean rspamd_symcache_item_async_dec_check_full (struct rspamd_task *task,
 											   const gchar *loc);
 #define rspamd_symcache_item_async_dec_check(task, item, subsystem) \
 	rspamd_symcache_item_async_dec_check_full(task, item, subsystem, G_STRLOC)
+
+/**
+ * Disables execution of all symbols, excluding those specified in `skip_mask`
+ * @param task
+ * @param cache
+ * @param skip_mask
+ */
+void rspamd_symcache_disable_all_symbols (struct rspamd_task *task,
+										  struct rspamd_symcache *cache,
+										  guint skip_mask);
 #endif
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 90cb1f689..b6c5c1fb7 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1771,10 +1771,12 @@ lua_task_set_pre_result (lua_State * L)
 				rspamd_mempool_strdup (task->task_pool, module));
 
 		/* Don't classify or filter message if pre-filter sets results */
-		task->processed_stages |= (RSPAMD_TASK_STAGE_FILTERS |
-								   RSPAMD_TASK_STAGE_CLASSIFIERS |
+		task->processed_stages |= (RSPAMD_TASK_STAGE_CLASSIFIERS |
 								   RSPAMD_TASK_STAGE_CLASSIFIERS_PRE |
 								   RSPAMD_TASK_STAGE_CLASSIFIERS_POST);
+		rspamd_symcache_disable_all_symbols (task, task->cfg->cache,
+				SYMBOL_TYPE_IDEMPOTENT|SYMBOL_TYPE_IGNORE_PASSTHROUGH|
+				SYMBOL_TYPE_POSTFILTER);
 	}
 	else {
 		return luaL_error (L, "invalid arguments");


More information about the Commits mailing list