commit 8529cf6: [Minor] Show real ttl for records
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Oct 30 17:28:06 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-10-30 17:24:52 +0000
URL: https://github.com/rspamd/rspamd/commit/8529cf63e6f25e6bc913412b0b38518e19e6cf6d (HEAD -> master)
[Minor] Show real ttl for records
---
src/libserver/spf.c | 24 +++++++++++-------------
src/libserver/spf.h | 12 +++++++++---
src/plugins/spf.c | 23 ++++++++++-------------
3 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/src/libserver/spf.c b/src/libserver/spf.c
index b085467db..46a6dd0a3 100644
--- a/src/libserver/spf.c
+++ b/src/libserver/spf.c
@@ -392,15 +392,15 @@ rspamd_spf_process_reference (struct spf_resolved *target,
cur = g_ptr_array_index (elt->elts, i);
if (cur->flags & RSPAMD_SPF_FLAG_TEMPFAIL) {
- target->temp_failed = TRUE;
+ target->flags |= RSPAMD_SPF_RESOLVED_TEMP_FAILED;
continue;
}
if (cur->flags & RSPAMD_SPF_FLAG_PERMFAIL) {
- target->perm_failed = TRUE;
+ target->flags |= RSPAMD_SPF_RESOLVED_PERM_FAILED;
continue;
}
if (cur->flags & RSPAMD_SPF_FLAG_NA) {
- target->na = TRUE;
+ target->flags |= RSPAMD_SPF_RESOLVED_NA;
continue;
}
if (cur->flags & RSPAMD_SPF_FLAG_INVALID) {
@@ -448,26 +448,24 @@ rspamd_spf_record_flatten (struct spf_record *rec)
g_assert (rec != NULL);
+ res = g_malloc0 (sizeof (*res));
+ res->domain = g_strdup (rec->sender_domain);
+ res->ttl = rec->ttl;
+ /* Not precise but okay */
+ res->timestamp = rec->task->task_timestamp;
+ res->digest = mum_hash_init (0xa4aa40bbeec59e2bULL);
+ REF_INIT_RETAIN (res, rspamd_flatten_record_dtor);
+
if (rec->resolved) {
- res = g_malloc0 (sizeof (*res));
res->elts = g_array_sized_new (FALSE, FALSE, sizeof (struct spf_addr),
rec->resolved->len);
- res->domain = g_strdup (rec->sender_domain);
- res->ttl = rec->ttl;
- res->digest = mum_hash_init (0xa4aa40bbeec59e2bULL);
- REF_INIT_RETAIN (res, rspamd_flatten_record_dtor);
if (rec->resolved->len > 0) {
rspamd_spf_process_reference (res, NULL, rec, TRUE);
}
}
else {
- res = g_malloc0 (sizeof (*res));
res->elts = g_array_new (FALSE, FALSE, sizeof (struct spf_addr));
- res->domain = g_strdup (rec->sender_domain);
- res->ttl = rec->ttl;
- res->digest = mum_hash_init (0xa4aa40bbeec59e2bULL);
- REF_INIT_RETAIN (res, rspamd_flatten_record_dtor);
}
return res;
diff --git a/src/libserver/spf.h b/src/libserver/spf.h
index e9ebbbdf9..9fcb01d1e 100644
--- a/src/libserver/spf.h
+++ b/src/libserver/spf.h
@@ -67,12 +67,18 @@ struct spf_addr {
struct spf_addr *prev, *next;
};
+enum rspamd_spf_resolved_flags {
+ RSPAMD_SPF_RESOLVED_NORMAL = 0,
+ RSPAMD_SPF_RESOLVED_TEMP_FAILED = (1u << 0u),
+ RSPAMD_SPF_RESOLVED_PERM_FAILED = (1u << 1u),
+ RSPAMD_SPF_RESOLVED_NA = (1u << 2u),
+};
+
struct spf_resolved {
gchar *domain;
guint ttl;
- gboolean temp_failed;
- gboolean na;
- gboolean perm_failed;
+ gint flags;
+ gdouble timestamp;
guint64 digest;
GArray *elts; /* Flat list of struct spf_addr */
ref_entry_t ref; /* Refcounting */
diff --git a/src/plugins/spf.c b/src/plugins/spf.c
index cc9dd7dd2..14b2c375a 100644
--- a/src/plugins/spf.c
+++ b/src/plugins/spf.c
@@ -490,12 +490,12 @@ spf_check_element (struct spf_resolved *rec, struct spf_addr *addr,
spf_result[0] = '-';
spf_message = "(SPF): spf fail";
if (addr->flags & RSPAMD_SPF_FLAG_ANY) {
- if (rec->perm_failed) {
+ if (rec->flags & RSPAMD_SPF_RESOLVED_PERM_FAILED) {
msg_info_task ("do not apply SPF failed policy, as we have "
"some addresses unresolved");
spf_symbol = spf_module_ctx->symbol_permfail;
}
- else if (rec->temp_failed) {
+ else if (rec->flags & RSPAMD_SPF_RESOLVED_TEMP_FAILED) {
msg_info_task ("do not apply SPF failed policy, as we have "
"some addresses unresolved");
spf_symbol = spf_module_ctx->symbol_dnsfail;
@@ -509,12 +509,12 @@ spf_check_element (struct spf_resolved *rec, struct spf_addr *addr,
spf_result[0] = '~';
if (addr->flags & RSPAMD_SPF_FLAG_ANY) {
- if (rec->perm_failed) {
+ if (rec->flags & RSPAMD_SPF_RESOLVED_PERM_FAILED) {
msg_info_task ("do not apply SPF failed policy, as we have "
"some addresses unresolved");
spf_symbol = spf_module_ctx->symbol_permfail;
}
- else if (rec->temp_failed) {
+ else if (rec->flags & RSPAMD_SPF_RESOLVED_TEMP_FAILED) {
msg_info_task ("do not apply SPF failed policy, as we have "
"some addresses unresolved");
spf_symbol = spf_module_ctx->symbol_dnsfail;
@@ -567,7 +567,7 @@ spf_check_list (struct spf_resolved *rec, struct rspamd_task *task, gboolean cac
"%d/%d elements in the cache",
rec->domain,
rec->digest,
- rec->ttl,
+ rec->ttl - (task->task_timestamp - rec->timestamp),
rspamd_lru_hash_size (spf_module_ctx->spf_hash),
rspamd_lru_hash_capacity (spf_module_ctx->spf_hash));
}
@@ -588,19 +588,19 @@ spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task,
struct rspamd_symcache_item *item = (struct rspamd_symcache_item *)ud;
struct spf_ctx *spf_module_ctx = spf_get_context (task->cfg);
- if (record && record->na) {
+ if (record && (record->flags & RSPAMD_SPF_RESOLVED_NA)) {
rspamd_task_insert_result (task,
spf_module_ctx->symbol_na,
1,
NULL);
}
- else if (record && record->elts->len == 0 && record->temp_failed) {
+ else if (record && record->elts->len == 0 && (record->flags & RSPAMD_SPF_RESOLVED_TEMP_FAILED)) {
rspamd_task_insert_result (task,
spf_module_ctx->symbol_dnsfail,
1,
NULL);
}
- else if (record && record->elts->len == 0 && record->perm_failed) {
+ else if (record && record->elts->len == 0 && (record->flags & RSPAMD_SPF_RESOLVED_PERM_FAILED)) {
rspamd_task_insert_result (task,
spf_module_ctx->symbol_permfail,
1,
@@ -621,15 +621,12 @@ spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task,
record->domain, task->task_timestamp)) == NULL) {
l = record;
- if (record->ttl > 0 &&
- !record->temp_failed &&
- !record->perm_failed &&
- !record->na) {
+ if (record->ttl > 0 && record->flags == 0) {
if (spf_module_ctx->spf_hash) {
rspamd_lru_hash_insert (spf_module_ctx->spf_hash,
record->domain, spf_record_ref (l),
- task->task_timestamp, record->ttl);
+ record->timestamp, record->ttl);
msg_info_task ("stored record for %s (0x%xuL) in LRU cache for %d seconds, "
"%d/%d elements in the cache",
More information about the Commits
mailing list