From fa687ca63177a2531078d0efa158ccafe5599573 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 11 Mar 2016 16:44:06 +0000 Subject: [PATCH] [Feature] Override DNS requests limits for SPF and DKIM --- src/libserver/dkim.c | 2 +- src/libserver/dns.c | 30 ++++++++++++++++++++++++++---- src/libserver/dns.h | 6 ++++++ src/libserver/spf.c | 24 ++++++++++++------------ 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c index 2114065c3..d99ce6ff7 100644 --- a/src/libserver/dkim.c +++ b/src/libserver/dkim.c @@ -1042,7 +1042,7 @@ rspamd_get_dkim_key (rspamd_dkim_context_t *ctx, cbdata->handler = handler; cbdata->ud = ud; - return make_dns_request_task (task, + return make_dns_request_task_forced (task, rspamd_dkim_dns_cb, cbdata, RDNS_REQUEST_TXT, diff --git a/src/libserver/dns.c b/src/libserver/dns.c index 937b1c030..3c67411a0 100644 --- a/src/libserver/dns.c +++ b/src/libserver/dns.c @@ -114,15 +114,17 @@ make_dns_request (struct rspamd_dns_resolver *resolver, return TRUE; } -gboolean make_dns_request_task (struct rspamd_task *task, +static gboolean +make_dns_request_task_common (struct rspamd_task *task, dns_callback_type cb, gpointer ud, enum rdns_request_type type, - const char *name) + const char *name, + gboolean forced) { gboolean ret; - if (task->dns_requests >= task->cfg->dns_max_requests) { + if (!forced && task->dns_requests >= task->cfg->dns_max_requests) { return FALSE; } @@ -132,7 +134,7 @@ gboolean make_dns_request_task (struct rspamd_task *task, if (ret) { task->dns_requests ++; - if (task->dns_requests >= task->cfg->dns_max_requests) { + if (!forced && task->dns_requests >= task->cfg->dns_max_requests) { msg_info_task ("<%s> stop resolving on reaching %ud requests", task->message_id, task->dns_requests); } @@ -141,6 +143,26 @@ gboolean make_dns_request_task (struct rspamd_task *task, return ret; } +gboolean +make_dns_request_task (struct rspamd_task *task, + dns_callback_type cb, + gpointer ud, + enum rdns_request_type type, + const char *name) +{ + return make_dns_request_task_common (task, cb, ud, type, name, FALSE); +} + +gboolean +make_dns_request_task_forced (struct rspamd_task *task, + dns_callback_type cb, + gpointer ud, + enum rdns_request_type type, + const char *name) +{ + return make_dns_request_task_common (task, cb, ud, type, name, TRUE); +} + static void rspamd_rnds_log_bridge ( void *log_data, enum rdns_log_level level, diff --git a/src/libserver/dns.h b/src/libserver/dns.h index 775f41a75..e465de82d 100644 --- a/src/libserver/dns.h +++ b/src/libserver/dns.h @@ -63,4 +63,10 @@ gboolean make_dns_request_task (struct rspamd_task *task, enum rdns_request_type type, const char *name); +gboolean make_dns_request_task_forced (struct rspamd_task *task, + dns_callback_type cb, + gpointer ud, + enum rdns_request_type type, + const char *name); + #endif diff --git a/src/libserver/spf.c b/src/libserver/spf.c index 052e024e0..7f404efb4 100644 --- a/src/libserver/spf.c +++ b/src/libserver/spf.c @@ -561,14 +561,14 @@ spf_record_dns_callback (struct rdns_reply *reply, gpointer arg) /* Now resolve A record for this MX */ msg_debug_spf ("resolve %s after resolving of MX", elt_data->content.mx.name); - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_A, elt_data->content.mx.name)) { cb->rec->requests_inflight++; } - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_AAAA, elt_data->content.mx.name)) { @@ -590,13 +590,13 @@ spf_record_dns_callback (struct rdns_reply *reply, gpointer arg) elt_data->content.ptr.name)) { msg_debug_spf ("resolve %s after resolving of PTR", elt_data->content.ptr.name); - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_A, elt_data->content.ptr.name)) { cb->rec->requests_inflight++; } - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_AAAA, elt_data->content.ptr.name)) { @@ -875,11 +875,11 @@ parse_spf_a (struct spf_record *rec, cb->resolved = resolved; msg_debug_spf ("resolve a %s", host); - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_A, host)) { rec->requests_inflight++; - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_AAAA, host)) { rec->requests_inflight++; } @@ -921,7 +921,7 @@ parse_spf_ptr (struct spf_record *rec, rspamd_mempool_add_destructor (task->task_pool, free, ptr); msg_debug_spf ("resolve ptr %s for %s", ptr, host); - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_PTR, ptr)) { rec->requests_inflight++; @@ -955,7 +955,7 @@ parse_spf_mx (struct spf_record *rec, cb->resolved = resolved; msg_debug_spf ("resolve mx for %s", host); - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_MX, host)) { rec->requests_inflight++; @@ -1108,7 +1108,7 @@ parse_spf_include (struct spf_record *rec, struct spf_addr *addr) addr->flags |= RSPAMD_SPF_FLAG_REFRENCE; msg_debug_spf ("resolve include %s", domain); - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_TXT, domain)) { rec->requests_inflight++; @@ -1160,7 +1160,7 @@ parse_spf_redirect (struct spf_record *rec, cb->resolved = rspamd_spf_new_addr_list (rec, domain); msg_debug_spf ("resolve redirect %s", domain); - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_TXT, domain)) { rec->requests_inflight++; @@ -1197,7 +1197,7 @@ parse_spf_exists (struct spf_record *rec, struct spf_addr *addr) cb->resolved = resolved; msg_debug_spf ("resolve exists %s", host); - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_record_dns_callback, (void *) cb, RDNS_REQUEST_A, host)) { rec->requests_inflight++; @@ -1808,7 +1808,7 @@ resolve_spf (struct rspamd_task *task, spf_cb_t callback) return FALSE; } - if (make_dns_request_task (task, + if (make_dns_request_task_forced (task, spf_dns_callback, (void *) rec, RDNS_REQUEST_TXT, rec->sender_domain)) { rec->requests_inflight++; -- 2.39.5