commit 3bb2221: [Feature] Add more verbosity for SPF caching

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Apr 5 15:21:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-04-05 16:14:28 +0100
URL: https://github.com/rspamd/rspamd/commit/3bb2221337743a15ea2663ab92292be3b6a9546e (HEAD -> master)

[Feature] Add more verbosity for SPF caching

---
 src/plugins/spf.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/plugins/spf.c b/src/plugins/spf.c
index dfdf110a1..4c5dff124 100644
--- a/src/plugins/spf.c
+++ b/src/plugins/spf.c
@@ -361,7 +361,7 @@ spf_module_reconfig (struct rspamd_config *cfg)
 
 static gboolean
 spf_check_element (struct spf_resolved *rec, struct spf_addr *addr,
-		struct rspamd_task *task)
+		struct rspamd_task *task, gboolean cached)
 {
 	gboolean res = FALSE;
 	const guint8 *s, *d;
@@ -426,7 +426,7 @@ spf_check_element (struct spf_resolved *rec, struct spf_addr *addr,
 
 	if (res) {
 		spf_result = rspamd_mempool_alloc (task->task_pool,
-				strlen (addr->spf_string) + 2);
+				strlen (addr->spf_string) + 5);
 
 		switch (addr->mech) {
 		case SPF_FAIL:
@@ -478,9 +478,13 @@ spf_check_element (struct spf_resolved *rec, struct spf_addr *addr,
 			break;
 		}
 
-		rspamd_strlcpy (spf_result + 1, addr->spf_string,
+		gint r = rspamd_strlcpy (spf_result + 1, addr->spf_string,
 				strlen (addr->spf_string) + 1);
 
+		if (cached) {
+			rspamd_strlcpy (spf_result + r + 1, ":c", 3);
+		}
+
 		rspamd_task_insert_result (task,
 				spf_symbol,
 				1,
@@ -496,14 +500,14 @@ spf_check_element (struct spf_resolved *rec, struct spf_addr *addr,
 }
 
 static void
-spf_check_list (struct spf_resolved *rec, struct rspamd_task *task)
+spf_check_list (struct spf_resolved *rec, struct rspamd_task *task, gboolean cached)
 {
 	guint i;
 	struct spf_addr *addr;
 
 	for (i = 0; i < rec->elts->len; i ++) {
 		addr = &g_array_index (rec->elts, struct spf_addr, i);
-		if (spf_check_element (rec, addr, task)) {
+		if (spf_check_element (rec, addr, task, cached)) {
 			break;
 		}
 	}
@@ -557,12 +561,19 @@ spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task,
 				rspamd_lru_hash_insert (spf_module_ctx->spf_hash,
 						record->domain, spf_record_ref (l),
 						task->tv.tv_sec, record->ttl);
+
+				msg_info_task ("stored record for %s in LRU cache for %d seconds, "
+							   "%d/%d elements in the cache",
+						record->domain,
+						record->ttl,
+						rspamd_lru_hash_size (spf_module_ctx->spf_hash),
+						rspamd_lru_hash_capacity (spf_module_ctx->spf_hash));
 			}
 
 		}
 
 		spf_record_ref (l);
-		spf_check_list (l, task);
+		spf_check_list (l, task, FALSE);
 		spf_record_unref (l);
 
 		spf_record_unref (record);
@@ -621,7 +632,7 @@ spf_symbol_callback (struct rspamd_task *task,
 			rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, domain,
 			task->tv.tv_sec)) != NULL) {
 			spf_record_ref (l);
-			spf_check_list (l, task);
+			spf_check_list (l, task, TRUE);
 			spf_record_unref (l);
 		}
 		else {


More information about the Commits mailing list