From: Vsevolod Stakhov Date: Thu, 10 Dec 2015 17:03:51 +0000 (+0000) Subject: Allow to disable hyperscan and use pcre only X-Git-Tag: 1.1.0~339 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=335ab27a5f6c0f393248d5b545c075f60d4cb623;p=rspamd.git Allow to disable hyperscan and use pcre only --- diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 511b18b25..3c2b14da0 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -231,6 +231,7 @@ struct rspamd_config { gboolean strict_protocol_headers; /**< strictly check protocol headers */ gboolean check_all_filters; /**< check all filters */ gboolean allow_raw_input; /**< scan messages with invalid mime */ + gboolean disable_hyperscan; /**< disable hyperscan usage */ gsize max_diff; /**< maximum diff size for text parts */ diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 1999dd351..751fa6964 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -1465,6 +1465,11 @@ rspamd_rcl_config_init (void) rspamd_rcl_parse_struct_integer, G_STRUCT_OFFSET (struct rspamd_config, history_rows), RSPAMD_CL_FLAG_UINT); + rspamd_rcl_add_default_handler (sub, + "disable_hyperscan", + rspamd_rcl_parse_struct_boolean, + G_STRUCT_OFFSET (struct rspamd_config, disable_hyperscan), + 0); /* New DNS configuration */ ssub = rspamd_rcl_add_section (&sub->subsections, "dns", NULL, NULL, diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 012cec1c3..11be02879 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -671,7 +671,7 @@ rspamd_config_post_load (struct rspamd_config *cfg, gboolean validate_cache) rspamd_symbols_cache_init (cfg->cache); /* Init re cache */ - rspamd_re_cache_init (cfg->re_cache); + rspamd_re_cache_init (cfg->re_cache, cfg); /* Validate cache */ if (validate_cache) { diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 11ad7ba0a..b231928a7 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -29,6 +29,7 @@ #include "ref.h" #include "libserver/url.h" #include "libserver/task.h" +#include "libserver/cfg_file.h" #include "libutil/util.h" #ifdef WITH_HYPERSCAN #include "hs.h" @@ -99,6 +100,7 @@ struct rspamd_re_cache { guint max_re_data; gchar hash[rspamd_cryptobox_HASHBYTES + 1]; #ifdef WITH_HYPERSCAN + gboolean disable_hyperscan; hs_platform_info_t plt; #endif }; @@ -286,7 +288,7 @@ rspamd_re_cache_sort_func (gconstpointer a, gconstpointer b) } void -rspamd_re_cache_init (struct rspamd_re_cache *cache) +rspamd_re_cache_init (struct rspamd_re_cache *cache, struct rspamd_config *cfg) { guint i, fl; GHashTableIter it; @@ -364,6 +366,8 @@ rspamd_re_cache_init (struct rspamd_re_cache *cache) const gchar *platform = "generic"; rspamd_fstring_t *features = rspamd_fstring_new (); + cache->disable_hyperscan = cfg->disable_hyperscan; + g_assert (hs_populate_platform (&cache->plt) == HS_SUCCESS); /* Now decode what we do have */ @@ -541,7 +545,7 @@ rspamd_re_cache_process_regexp_data (struct rspamd_re_runtime *rt, #else struct rspamd_re_hyperscan_cbdata cbdata; - if (elt->match_type == RSPAMD_RE_CACHE_PCRE) { + if (rt->cache->disable_hyperscan || elt->match_type == RSPAMD_RE_CACHE_PCRE) { ret = rspamd_re_cache_process_pcre (rt, re, in, len, is_raw); setbit (rt->checked, re_id); rt->results[re_id] = ret; @@ -751,7 +755,9 @@ rspamd_re_cache_exec_re (struct rspamd_task *task, break; } - rspamd_re_cache_finish_class (rt, re_class); + if (!rt->cache->disable_hyperscan) { + rspamd_re_cache_finish_class (rt, re_class); + } return ret; } diff --git a/src/libserver/re_cache.h b/src/libserver/re_cache.h index 8e3505ba7..062982df2 100644 --- a/src/libserver/re_cache.h +++ b/src/libserver/re_cache.h @@ -30,6 +30,7 @@ struct rspamd_re_cache; struct rspamd_re_runtime; struct rspamd_task; +struct rspamd_config; enum rspamd_re_type { RSPAMD_RE_HEADER, @@ -78,7 +79,8 @@ void rspamd_re_cache_replace (struct rspamd_re_cache *cache, /** * Initialize and optimize re cache structure */ -void rspamd_re_cache_init (struct rspamd_re_cache *cache); +void rspamd_re_cache_init (struct rspamd_re_cache *cache, + struct rspamd_config *cfg); /** * Get runtime data for a cache