]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
spm: add SinglePatternMatchDefaultMatcher
authorJustin Viiret <justin.viiret@intel.com>
Thu, 28 Apr 2016 05:23:05 +0000 (15:23 +1000)
committerVictor Julien <victor@inliniac.net>
Wed, 18 May 2016 07:58:33 +0000 (09:58 +0200)
Allows selecting SPM algorithm with the 'spm-algo' value in the YAML
config file.

src/detect-engine.c
src/detect.h
src/util-spm.c
src/util-spm.h

index c19afc2f331828541b22373260ceed5388e36771..0912167293ad7ed25c24e2dab66a0d733c3f0642 100644 (file)
@@ -84,6 +84,7 @@
 #include "util-action.h"
 #include "util-magic.h"
 #include "util-signal.h"
+#include "util-spm.h"
 
 #include "util-var-name.h"
 
@@ -829,6 +830,7 @@ static DetectEngineCtx *DetectEngineCtxInitReal(int minimal, const char *prefix)
     }
 
     de_ctx->mpm_matcher = PatternMatchDefaultMatcher();
+    de_ctx->spm_matcher = SinglePatternMatchDefaultMatcher();
     DetectEngineCtxLoadConf(de_ctx);
 
     SigGroupHeadHashInit(de_ctx);
index e321d5ca1d2a178c5c0298d644b52d6cc44ad1f0..67dee32db253582df14554d6d87c8db926f4751b 100644 (file)
@@ -587,6 +587,7 @@ typedef struct DetectEngineCtx_ {
     ThresholdCtx ths_ctx;
 
     uint16_t mpm_matcher; /**< mpm matcher this ctx uses */
+    uint16_t spm_matcher; /**< spm matcher this ctx uses */
 
     /* Config options */
 
index f4e03e288e2d40dcfa24eacd416c1e63aad32b79..97c5587ec57d5cd4943e934f6ebe094e592406af 100644 (file)
 #include "suricata.h"
 #include "util-unittest.h"
 
+#include "conf.h"
+
 #include "util-spm.h"
 #include "util-spm-bs.h"
 #include "util-spm-bs2bm.h"
 #include "util-spm-bm.h"
 #include "util-clock.h"
 
+/**
+ * \brief Returns the single pattern matcher algorithm to be used, based on the
+ * spm-algo setting in yaml.
+ */
+uint16_t SinglePatternMatchDefaultMatcher(void) {
+    char *spm_algo;
+    if ((ConfGet("spm-algo", &spm_algo)) == 1) {
+        if (strcmp("bm", spm_algo) == 0) {
+            return SPM_BM;
+        }
+
+        SCLogError(SC_ERR_INVALID_YAML_CONF_ENTRY,
+                   "Invalid spm algo supplied "
+                   "in the yaml conf file: \"%s\"",
+                   spm_algo);
+        exit(EXIT_FAILURE);
+    }
+
+    return SPM_BM; /* default to Boyer-Moore */
+}
 
 /**
  * Wrappers for building context and searching (Bs2Bm and boyermoore)
index bd1826923143a255ca89d757de134379998b147c..11149867a1bfac5fb755b2d1465dfb5deecbddfc 100644 (file)
 #include "util-spm-bs2bm.h"
 #include "util-spm-bm.h"
 
+enum {
+    SPM_BM, /* Boyer-Moore */
+    /* Other SPM matchers will go here. */
+};
+
+uint16_t SinglePatternMatchDefaultMatcher(void);
+
 /** Default algorithm to use: Boyer Moore */
 uint8_t *Bs2bmSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
 uint8_t *Bs2bmNocaseSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);