guint max_dns_nesting;
guint max_dns_requests;
guint min_cache_ttl;
+ gboolean disable_ipv6;
};
struct rspamd_spf_library_ctx *spf_lib_ctx = NULL;
spf_lib_ctx->max_dns_nesting = SPF_MAX_NESTING;
spf_lib_ctx->max_dns_requests = SPF_MAX_DNS_REQUESTS;
spf_lib_ctx->min_cache_ttl = SPF_MIN_CACHE_TTL;
+ spf_lib_ctx->disable_ipv6 = FALSE;
}
RSPAMD_DESTRUCTOR(rspamd_spf_lib_ctx_dtor) {
}
void
-spf_library_config (gint max_dns_nesting, gint max_dns_requests,
- gint min_cache_ttl)
+spf_library_config (const ucl_object_t *obj)
{
- if (max_dns_nesting >= 0) {
- spf_lib_ctx->max_dns_nesting = max_dns_nesting;
+ const ucl_object_t *value;
+ guint64 ival;
+ bool bval;
+
+ if (obj == NULL) {
+ /* No specific config */
+ return;
+ }
+
+ if ((value = ucl_object_find_key (obj, "min_cache_ttl")) != NULL) {
+ if (ucl_object_toint_safe (value, &ival) && ival >= 0) {
+ spf_lib_ctx->min_cache_ttl = ival;
+ }
}
- if (max_dns_requests >= 0) {
- spf_lib_ctx->max_dns_requests = max_dns_requests;
+ if ((value = ucl_object_find_key (obj, "max_dns_nesting")) != NULL) {
+ if (ucl_object_toint_safe (value, &ival) && ival >= 0) {
+ spf_lib_ctx->max_dns_nesting = ival;
+ }
}
- if (min_cache_ttl >= 0) {
- spf_lib_ctx->min_cache_ttl = min_cache_ttl;
+ if ((value = ucl_object_find_key (obj, "max_dns_requests")) != NULL) {
+ if (ucl_object_toint_safe (value, &ival) && ival >= 0) {
+ spf_lib_ctx->max_dns_requests = ival;
+ }
+ }
+ if ((value = ucl_object_find_key (obj, "disable_ipv6")) != NULL) {
+ if (ucl_object_toboolean_safe (value, &bval)) {
+ spf_lib_ctx->disable_ipv6 = bval;
+ }
}
+
}
static gboolean start_spf_parse (struct spf_record *rec,
cb->rec->requests_inflight++;
}
- if (rspamd_dns_resolver_request_task_forced (task,
- spf_record_dns_callback, (void *) cb,
- RDNS_REQUEST_AAAA,
- elt_data->content.mx.name)) {
- cb->rec->requests_inflight++;
+ if (!spf_lib_ctx->disable_ipv6) {
+ if (rspamd_dns_resolver_request_task_forced (task,
+ spf_record_dns_callback, (void *) cb,
+ RDNS_REQUEST_AAAA,
+ elt_data->content.mx.name)) {
+ cb->rec->requests_inflight++;
+ }
+ }
+ else {
+ msg_debug_spf ("skip AAAA request for MX resolution");
}
}
else {
/* Validate returned records prior to making A requests */
if (spf_check_ptr_host (cb,
elt_data->content.ptr.name)) {
- msg_debug_spf ("resolve %s after resolving of PTR",
+ msg_debug_spf ("resolve PTR %s after resolving of PTR",
elt_data->content.ptr.name);
if (rspamd_dns_resolver_request_task_forced (task,
spf_record_dns_callback, (void *) cb,
elt_data->content.ptr.name)) {
cb->rec->requests_inflight++;
}
- if (rspamd_dns_resolver_request_task_forced (task,
- spf_record_dns_callback, (void *) cb,
- RDNS_REQUEST_AAAA,
- elt_data->content.ptr.name)) {
- cb->rec->requests_inflight++;
+
+ if (!spf_lib_ctx->disable_ipv6) {
+ if (rspamd_dns_resolver_request_task_forced (task,
+ spf_record_dns_callback, (void *) cb,
+ RDNS_REQUEST_AAAA,
+ elt_data->content.ptr.name)) {
+ cb->rec->requests_inflight++;
+ }
+ }
+ else {
+ msg_debug_spf ("skip AAAA request for PTR resolution");
}
}
else {
cb->addr = addr;
cb->cur_action = SPF_RESOLVE_AAA;
cb->resolved = resolved;
- msg_debug_spf ("resolve aaa %s", host);
- if (rspamd_dns_resolver_request_task_forced (task,
- spf_record_dns_callback, (void *) cb, RDNS_REQUEST_AAAA, host)) {
- rec->requests_inflight++;
+ if (!spf_lib_ctx->disable_ipv6) {
+ if (rspamd_dns_resolver_request_task_forced (task,
+ spf_record_dns_callback, (void *) cb, RDNS_REQUEST_AAAA, host)) {
+ rec->requests_inflight++;
+ }
+ }
+ else {
+ msg_debug_spf ("skip AAAA request for a record resolution");
}
return TRUE;
gboolean check_local;
gboolean check_authed;
-
- guint max_dns_nesting;
- guint max_dns_requests;
- guint min_cache_ttl;
};
static void spf_symbol_callback (struct rspamd_task *task,
spf_module_ctx = rspamd_mempool_alloc0 (cfg->cfg_pool,
sizeof (*spf_module_ctx));
*ctx = (struct module_ctx *)spf_module_ctx;
- spf_module_ctx->min_cache_ttl = SPF_MIN_CACHE_TTL;
- spf_module_ctx->max_dns_nesting = SPF_MAX_NESTING;
- spf_module_ctx->max_dns_requests = SPF_MAX_DNS_REQUESTS;
rspamd_rcl_add_doc_by_path (cfg,
NULL,
RSPAMD_CL_FLAG_UINT,
NULL,
0);
+ rspamd_rcl_add_doc_by_path (cfg,
+ "spf",
+ "Disable ipv6 resolving when doing SPF resolution",
+ "disable_ipv6",
+ UCL_BOOLEAN,
+ NULL,
+ 0,
+ NULL,
+ 0);
return 0;
}
cache_size = DEFAULT_CACHE_SIZE;
}
- if ((value =
- rspamd_config_get_module_opt (cfg, "spf", "min_cache_ttl")) != NULL) {
- spf_module_ctx->min_cache_ttl = ucl_obj_toint (value);
- }
- if ((value =
- rspamd_config_get_module_opt (cfg, "spf", "max_dns_nesting")) != NULL) {
- spf_module_ctx->max_dns_nesting = ucl_obj_toint (value);
- }
- if ((value =
- rspamd_config_get_module_opt (cfg, "spf", "max_dns_requests")) != NULL) {
- spf_module_ctx->max_dns_requests = ucl_obj_toint (value);
- }
-
- spf_library_config (spf_module_ctx->max_dns_nesting,
- spf_module_ctx->max_dns_requests,
- spf_module_ctx->min_cache_ttl);
+ spf_library_config (ucl_obj_get_key (cfg->rcl_obj, "spf"));
if ((value =
rspamd_config_get_module_opt (cfg, "spf", "whitelist")) != NULL) {