]> source.dussan.org Git - rspamd.git/commitdiff
Allow to disable hyperscan and use pcre only
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Dec 2015 17:03:51 +0000 (17:03 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Dec 2015 17:03:51 +0000 (17:03 +0000)
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libserver/re_cache.c
src/libserver/re_cache.h

index 511b18b2570c6053c4cfbdaa7eade4eeb48c4514..3c2b14da05fc0c318ffba24ea56461e8a0ed1d2d 100644 (file)
@@ -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                                   */
 
index 1999dd3519effbf6522190b2c7eeabec412ff57b..751fa6964fd6ff6bb72ce1891717aec281e28019 100644 (file)
@@ -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,
index 012cec1c34686eb7beff049810b1d6fafe9b8c3a..11be0287991ccdd71b54bbe35009ceb9746c08a5 100644 (file)
@@ -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) {
index 11ad7ba0af0ca5a840a9b18b025069d775369350..b231928a7b055bb673c1a9b78f96949f011b2346 100644 (file)
@@ -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;
 }
index 8e3505ba7502c232ed9aee023aea4a69f3784e54..062982df2d2207820bee2f86f6b9d46dd385ed2e 100644 (file)
@@ -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