From: Justin Viiret Date: Thu, 28 Apr 2016 05:23:05 +0000 (+1000) Subject: spm: add SinglePatternMatchDefaultMatcher X-Git-Tag: suricata-3.1RC1~146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce408c4d107342c6c078a9fc8e7d047f8abac398;p=thirdparty%2Fsuricata.git spm: add SinglePatternMatchDefaultMatcher Allows selecting SPM algorithm with the 'spm-algo' value in the YAML config file. --- diff --git a/src/detect-engine.c b/src/detect-engine.c index c19afc2f33..0912167293 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -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); diff --git a/src/detect.h b/src/detect.h index e321d5ca1d..67dee32db2 100644 --- a/src/detect.h +++ b/src/detect.h @@ -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 */ diff --git a/src/util-spm.c b/src/util-spm.c index f4e03e288e..97c5587ec5 100644 --- a/src/util-spm.c +++ b/src/util-spm.c @@ -47,12 +47,34 @@ #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) diff --git a/src/util-spm.h b/src/util-spm.h index bd18269231..11149867a1 100644 --- a/src/util-spm.h +++ b/src/util-spm.h @@ -28,6 +28,13 @@ #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);