From bb0cd0e883c90e551110e79638b8bd017eac1a66 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 14 Jul 2016 13:15:31 +0200 Subject: [PATCH] prefilter: rename PatternMatcherQueue datatype In preparation of the introduction of more general purpose prefilter engines, rename PatternMatcherQueue to PrefilterRuleStore. The new engines will fill this structure a similar way to the current mpm prefilters. --- src/Makefile.am | 1 + src/app-layer-detect-proto.c | 2 +- src/app-layer-smtp.c | 2 +- src/detect.h | 5 +- src/threadvars.h | 1 - src/util-mpm-ac-bs.c | 74 ++++++++++---------- src/util-mpm-ac-tile-small.c | 2 +- src/util-mpm-ac-tile.c | 92 ++++++++++++------------ src/util-mpm-ac-tile.h | 4 +- src/util-mpm-ac.c | 80 +++++++++++---------- src/util-mpm-ac.h | 2 +- src/util-mpm-hs.c | 64 ++++++++--------- src/util-mpm.c | 106 ---------------------------- src/util-mpm.h | 63 ++--------------- src/util-prefilter.c | 132 +++++++++++++++++++++++++++++++++++ src/util-prefilter.h | 80 +++++++++++++++++++++ 16 files changed, 388 insertions(+), 322 deletions(-) create mode 100644 src/util-prefilter.c create mode 100644 src/util-prefilter.h diff --git a/src/Makefile.am b/src/Makefile.am index 2e805a28df..9f0f7e64f1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -389,6 +389,7 @@ util-path.c util-path.h \ util-pidfile.c util-pidfile.h \ util-pool.c util-pool.h \ util-pool-thread.c util-pool-thread.h \ +util-prefilter.c util-prefilter.h \ util-print.c util-print.h \ util-privs.c util-privs.h \ util-profiling.c util-profiling.h \ diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index 68690441d8..cca1ae7a8f 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -157,7 +157,7 @@ typedef struct AppLayerProtoDetectCtx_ { * \brief The app layer protocol detection thread context. */ struct AppLayerProtoDetectThreadCtx_ { - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; /* The value 2 is for direction(0 - toserver, 1 - toclient). */ MpmThreadCtx mpm_tctx[FLOW_PROTO_DEFAULT][2]; SpmThreadCtx *spm_thread_ctx; diff --git a/src/app-layer-smtp.c b/src/app-layer-smtp.c index 1224b54ade..8462cc366d 100644 --- a/src/app-layer-smtp.c +++ b/src/app-layer-smtp.c @@ -154,7 +154,7 @@ SCEnumCharMap smtp_decoder_event_table[ ] = { typedef struct SMTPThreadCtx_ { MpmThreadCtx *smtp_mpm_thread_ctx; - PatternMatcherQueue *pmq; + PrefilterRuleStore *pmq; } SMTPThreadCtx; #define SMTP_MPM DEFAULT_MPM diff --git a/src/detect.h b/src/detect.h index 142ca40c04..014a1c1acf 100644 --- a/src/detect.h +++ b/src/detect.h @@ -30,8 +30,9 @@ #include "detect-engine-proto.h" #include "detect-reference.h" - #include "packet-queue.h" + +#include "util-prefilter.h" #include "util-mpm.h" #include "util-spm.h" #include "util-hash.h" @@ -831,7 +832,7 @@ typedef struct DetectEngineThreadCtx_ { MpmThreadCtx mtc; /**< thread ctx for the mpm */ MpmThreadCtx mtcu; /**< thread ctx for uricontent mpm */ MpmThreadCtx mtcs; /**< thread ctx for stream mpm */ - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; /** SPM thread context used for scanning. This has been cloned from the * prototype held by DetectEngineCtx. */ diff --git a/src/threadvars.h b/src/threadvars.h index 389f22a14e..80c61cfa08 100644 --- a/src/threadvars.h +++ b/src/threadvars.h @@ -24,7 +24,6 @@ #ifndef __THREADVARS_H__ #define __THREADVARS_H__ -#include "util-mpm.h" #include "util-affinity.h" #include "tm-queues.h" #include "counters.h" diff --git a/src/util-mpm-ac-bs.c b/src/util-mpm-ac-bs.c index 6e88c27089..07bbd08d8e 100644 --- a/src/util-mpm-ac-bs.c +++ b/src/util-mpm-ac-bs.c @@ -70,7 +70,7 @@ int SCACBSAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCACBSPreparePatterns(MpmCtx *mpm_ctx); uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, const uint8_t *buf, uint16_t buflen); + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); void SCACBSPrintInfo(MpmCtx *mpm_ctx); void SCACBSPrintSearchStats(MpmThreadCtx *mpm_thread_ctx); void SCACBSRegisterTests(void); @@ -1147,7 +1147,7 @@ void SCACBSDestroyCtx(MpmCtx *mpm_ctx) * \retval matches Match count. */ uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, const uint8_t *buf, uint16_t buflen) + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen) { const SCACBSCtx *ctx = (SCACBSCtx *)mpm_ctx->ctx; int i = 0; @@ -1226,7 +1226,8 @@ uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, ; } else { bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8)); - MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size); + PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids, + pid_pat_list[lower_pid].sids_size); } matches++; } else { @@ -1234,7 +1235,8 @@ uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, ; } else { bitarray[pids[k] / 8] |= (1 << (pids[k] % 8)); - MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size); + PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids, + pid_pat_list[pids[k]].sids_size); } matches++; } @@ -1308,7 +1310,8 @@ uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, ; } else { bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8)); - MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size); + PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids, + pid_pat_list[lower_pid].sids_size); } matches++; } else { @@ -1316,7 +1319,8 @@ uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, ; } else { bitarray[pids[k] / 8] |= (1 << (pids[k] % 8)); - MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size); + PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids, + pid_pat_list[pids[k]].sids_size); } matches++; } @@ -1422,7 +1426,7 @@ static int SCACBSTest01(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1456,7 +1460,7 @@ static int SCACBSTest02(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1489,7 +1493,7 @@ static int SCACBSTest03(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1526,7 +1530,7 @@ static int SCACBSTest04(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1560,7 +1564,7 @@ static int SCACBSTest05(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1594,7 +1598,7 @@ static int SCACBSTest06(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1626,7 +1630,7 @@ static int SCACBSTest07(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1671,7 +1675,7 @@ static int SCACBSTest08(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1703,7 +1707,7 @@ static int SCACBSTest09(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1735,7 +1739,7 @@ static int SCACBSTest10(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1772,7 +1776,7 @@ static int SCACBSTest11(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1819,7 +1823,7 @@ static int SCACBSTest12(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1854,7 +1858,7 @@ static int SCACBSTest13(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1888,7 +1892,7 @@ static int SCACBSTest14(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1922,7 +1926,7 @@ static int SCACBSTest15(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1956,7 +1960,7 @@ static int SCACBSTest16(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1990,7 +1994,7 @@ static int SCACBSTest17(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2024,7 +2028,7 @@ static int SCACBSTest18(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2058,7 +2062,7 @@ static int SCACBSTest19(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2091,7 +2095,7 @@ static int SCACBSTest20(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2125,7 +2129,7 @@ static int SCACBSTest21(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2157,7 +2161,7 @@ static int SCACBSTest22(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2192,7 +2196,7 @@ static int SCACBSTest23(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2224,7 +2228,7 @@ static int SCACBSTest24(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2256,7 +2260,7 @@ static int SCACBSTest25(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2290,7 +2294,7 @@ static int SCACBSTest26(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2323,7 +2327,7 @@ static int SCACBSTest27(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2356,7 +2360,7 @@ static int SCACBSTest28(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2389,7 +2393,7 @@ static int SCACBSTest29(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); diff --git a/src/util-mpm-ac-tile-small.c b/src/util-mpm-ac-tile-small.c index 0a875778d6..a5e1ef0eac 100644 --- a/src/util-mpm-ac-tile-small.c +++ b/src/util-mpm-ac-tile-small.c @@ -32,7 +32,7 @@ /* This function handles (ctx->state_count < 32767) */ uint32_t FUNC_NAME(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, const uint8_t *buf, uint16_t buflen) + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen) { int i = 0; int matches = 0; diff --git a/src/util-mpm-ac-tile.c b/src/util-mpm-ac-tile.c index 27c4e5b7a1..e6b3d1ed53 100644 --- a/src/util-mpm-ac-tile.c +++ b/src/util-mpm-ac-tile.c @@ -92,51 +92,51 @@ int SCACTileAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCACTilePreparePatterns(MpmCtx *mpm_ctx); uint32_t SCACTileSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, const uint8_t *buf, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); void SCACTilePrintInfo(MpmCtx *mpm_ctx); void SCACTilePrintSearchStats(MpmThreadCtx *mpm_thread_ctx); void SCACTileRegisterTests(void); uint32_t SCACTileSearchLarge(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchSmall256(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchSmall128(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchSmall64(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchSmall32(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchSmall16(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchSmall8(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchTiny256(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchTiny128(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchTiny64(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchTiny32(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchTiny16(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); uint32_t SCACTileSearchTiny8(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); @@ -1172,7 +1172,7 @@ void SCACTileDestroyCtx(MpmCtx *mpm_ctx) #define EXTRA 4 // need 4 extra bytes to avoid OOB reads #endif -int CheckMatch(const SCACTileSearchCtx *ctx, PatternMatcherQueue *pmq, +int CheckMatch(const SCACTileSearchCtx *ctx, PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen, uint16_t state, int i, int matches, uint8_t *mpm_bitarray) @@ -1214,7 +1214,7 @@ int CheckMatch(const SCACTileSearchCtx *ctx, PatternMatcherQueue *pmq, /* Always add the Signature IDs, since they could be different in the current MPM * than in a previous MPM on the same PMQ when finding the same pattern. */ - MpmAddSids(pmq, pattern_list[pindex].sids, + PrefilterAddSids(pmq, pattern_list[pindex].sids, pattern_list[pindex].sids_size); matches++; } @@ -1235,7 +1235,7 @@ int CheckMatch(const SCACTileSearchCtx *ctx, PatternMatcherQueue *pmq, * \retval matches Match count. */ uint32_t SCACTileSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, const uint8_t *buf, uint16_t buflen) + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen) { const SCACTileSearchCtx *search_ctx = (SCACTileSearchCtx *)mpm_ctx->ctx; @@ -1248,7 +1248,7 @@ uint32_t SCACTileSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, /* This function handles (ctx->state_count >= 32767) */ uint32_t SCACTileSearchLarge(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen) { int i = 0; @@ -1515,7 +1515,7 @@ static int SCACTileTest01(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1549,7 +1549,7 @@ static int SCACTileTest02(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1582,7 +1582,7 @@ static int SCACTileTest03(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1619,7 +1619,7 @@ static int SCACTileTest04(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1653,7 +1653,7 @@ static int SCACTileTest05(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1687,7 +1687,7 @@ static int SCACTileTest06(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1719,7 +1719,7 @@ static int SCACTileTest07(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1764,7 +1764,7 @@ static int SCACTileTest08(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1796,7 +1796,7 @@ static int SCACTileTest09(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1828,7 +1828,7 @@ static int SCACTileTest10(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1865,7 +1865,7 @@ static int SCACTileTest11(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1912,7 +1912,7 @@ static int SCACTileTest12(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1947,7 +1947,7 @@ static int SCACTileTest13(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1981,7 +1981,7 @@ static int SCACTileTest14(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2015,7 +2015,7 @@ static int SCACTileTest15(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2049,7 +2049,7 @@ static int SCACTileTest16(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2083,7 +2083,7 @@ static int SCACTileTest17(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2117,7 +2117,7 @@ static int SCACTileTest18(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2151,7 +2151,7 @@ static int SCACTileTest19(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2185,7 +2185,7 @@ static int SCACTileTest20(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2219,7 +2219,7 @@ static int SCACTileTest21(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2251,7 +2251,7 @@ static int SCACTileTest22(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2286,7 +2286,7 @@ static int SCACTileTest23(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2318,7 +2318,7 @@ static int SCACTileTest24(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2350,7 +2350,7 @@ static int SCACTileTest25(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2384,7 +2384,7 @@ static int SCACTileTest26(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2417,7 +2417,7 @@ static int SCACTileTest27(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2450,7 +2450,7 @@ static int SCACTileTest28(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); diff --git a/src/util-mpm-ac-tile.h b/src/util-mpm-ac-tile.h index 5f47f23018..1f9ba4e5ec 100644 --- a/src/util-mpm-ac-tile.h +++ b/src/util-mpm-ac-tile.h @@ -64,7 +64,7 @@ typedef struct SCACTileCtx_ { * 32 bits. */ uint32_t (*search)(const struct SCACTileSearchCtx_ *ctx, struct MpmThreadCtx_ *, - PatternMatcherQueue *, const uint8_t *, uint16_t); + PrefilterRuleStore *, const uint8_t *, uint16_t); /* Function to set the next state based on size of next state * (bytes_per_state). @@ -117,7 +117,7 @@ typedef struct SCACTileSearchCtx_ { * 32 bits. */ uint32_t (*search)(const struct SCACTileSearchCtx_ *ctx, struct MpmThreadCtx_ *, - PatternMatcherQueue *, const uint8_t *, uint16_t); + PrefilterRuleStore *, const uint8_t *, uint16_t); /* Convert input character to matching alphabet */ uint8_t translate_table[256]; diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 70142fed41..45d5372586 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -79,7 +79,7 @@ int SCACAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCACPreparePatterns(MpmCtx *mpm_ctx); uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, const uint8_t *buf, uint16_t buflen); + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen); void SCACPrintInfo(MpmCtx *mpm_ctx); void SCACPrintSearchStats(MpmThreadCtx *mpm_thread_ctx); void SCACRegisterTests(void); @@ -1027,7 +1027,7 @@ void SCACDestroyCtx(MpmCtx *mpm_ctx) * \retval matches Match count. */ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, const uint8_t *buf, uint16_t buflen) + PrefilterRuleStore *pmq, const uint8_t *buf, uint16_t buflen) { const SCACCtx *ctx = (SCACCtx *)mpm_ctx->ctx; int i = 0; @@ -1063,7 +1063,8 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, ; } else { bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8)); - MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size); + PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids, + pid_pat_list[lower_pid].sids_size); } matches++; } else { @@ -1071,7 +1072,8 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, ; } else { bitarray[pids[k] / 8] |= (1 << (pids[k] % 8)); - MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size); + PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids, + pid_pat_list[pids[k]].sids_size); } matches++; } @@ -1103,7 +1105,8 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, ; } else { bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8)); - MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size); + PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids, + pid_pat_list[lower_pid].sids_size); } matches++; } else { @@ -1111,7 +1114,8 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, ; } else { bitarray[pids[k] / 8] |= (1 << (pids[k] % 8)); - MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size); + PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids, + pid_pat_list[pids[k]].sids_size); } matches++; } @@ -1546,7 +1550,7 @@ static void *SCACCudaDispatcher(void *arg) } uint32_t SCACCudaPacketResultsProcessing(Packet *p, const MpmCtx *mpm_ctx, - PatternMatcherQueue *pmq) + PrefilterRuleStore *pmq) { uint32_t u = 0; @@ -1603,7 +1607,8 @@ uint32_t SCACCudaPacketResultsProcessing(Packet *p, const MpmCtx *mpm_ctx, ; } else { bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8)); - MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size); + PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids, + pid_pat_list[lower_pid].sids_size); } matches++; } else { @@ -1611,7 +1616,8 @@ uint32_t SCACCudaPacketResultsProcessing(Packet *p, const MpmCtx *mpm_ctx, ; } else { bitarray[pids[k] / 8] |= (1 << (pids[k] % 8)); - MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size); + PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids, + pid_pat_list[pids[k]].sids_size); } matches++; } @@ -1808,7 +1814,7 @@ static int SCACTest01(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1842,7 +1848,7 @@ static int SCACTest02(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1875,7 +1881,7 @@ static int SCACTest03(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1912,7 +1918,7 @@ static int SCACTest04(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1946,7 +1952,7 @@ static int SCACTest05(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1980,7 +1986,7 @@ static int SCACTest06(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2012,7 +2018,7 @@ static int SCACTest07(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2057,7 +2063,7 @@ static int SCACTest08(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2089,7 +2095,7 @@ static int SCACTest09(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2121,7 +2127,7 @@ static int SCACTest10(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2158,7 +2164,7 @@ static int SCACTest11(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2205,7 +2211,7 @@ static int SCACTest12(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2240,7 +2246,7 @@ static int SCACTest13(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2274,7 +2280,7 @@ static int SCACTest14(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2308,7 +2314,7 @@ static int SCACTest15(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2342,7 +2348,7 @@ static int SCACTest16(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2376,7 +2382,7 @@ static int SCACTest17(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2410,7 +2416,7 @@ static int SCACTest18(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2444,7 +2450,7 @@ static int SCACTest19(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2478,7 +2484,7 @@ static int SCACTest20(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2512,7 +2518,7 @@ static int SCACTest21(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2544,7 +2550,7 @@ static int SCACTest22(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2579,7 +2585,7 @@ static int SCACTest23(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2611,7 +2617,7 @@ static int SCACTest24(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2643,7 +2649,7 @@ static int SCACTest25(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2677,7 +2683,7 @@ static int SCACTest26(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2710,7 +2716,7 @@ static int SCACTest27(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2743,7 +2749,7 @@ static int SCACTest28(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); diff --git a/src/util-mpm-ac.h b/src/util-mpm-ac.h index 97ae48e8d7..490ebfdfb9 100644 --- a/src/util-mpm-ac.h +++ b/src/util-mpm-ac.h @@ -188,7 +188,7 @@ int MpmCudaBufferDeSetup(void); void SCACCudaStartDispatcher(void); void SCACCudaKillDispatcher(void); uint32_t SCACCudaPacketResultsProcessing(Packet *p, const MpmCtx *mpm_ctx, - PatternMatcherQueue *pmq); + PrefilterRuleStore *pmq); void DetermineCudaStateTableSize(DetectEngineCtx *de_ctx); void CudaReleasePacket(Packet *p); diff --git a/src/util-mpm-hs.c b/src/util-mpm-hs.c index e0153a4748..61224d743c 100644 --- a/src/util-mpm-hs.c +++ b/src/util-mpm-hs.c @@ -56,7 +56,7 @@ int SCHSAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCHSPreparePatterns(MpmCtx *mpm_ctx); uint32_t SCHSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, const uint8_t *buf, const uint16_t buflen); + PrefilterRuleStore *pmq, const uint8_t *buf, const uint16_t buflen); void SCHSPrintInfo(MpmCtx *mpm_ctx); void SCHSPrintSearchStats(MpmThreadCtx *mpm_thread_ctx); void SCHSRegisterTests(void); @@ -885,7 +885,7 @@ static int SCHSMatchEvent(unsigned int id, unsigned long long from, void *ctx) { SCHSCallbackCtx *cctx = ctx; - PatternMatcherQueue *pmq = cctx->pmq; + PrefilterRuleStore *pmq = cctx->pmq; const PatternDatabase *pd = cctx->ctx->pattern_db; const SCHSPattern *pat = pd->parray[id]; @@ -893,7 +893,7 @@ static int SCHSMatchEvent(unsigned int id, unsigned long long from, " (pat id=%" PRIu32 ")", cctx->match_count, (uint32_t)id, (uintmax_t)to, pat->id); - MpmAddSids(pmq, pat->sids, pat->sids_size); + PrefilterAddSids(pmq, pat->sids, pat->sids_size); cctx->match_count++; return 0; @@ -912,7 +912,7 @@ static int SCHSMatchEvent(unsigned int id, unsigned long long from, * \retval matches Match count. */ uint32_t SCHSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, - PatternMatcherQueue *pmq, const uint8_t *buf, const uint16_t buflen) + PrefilterRuleStore *pmq, const uint8_t *buf, const uint16_t buflen) { uint32_t ret = 0; SCHSCtx *ctx = (SCHSCtx *)mpm_ctx->ctx; @@ -1086,7 +1086,7 @@ static int SCHSTest01(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1120,7 +1120,7 @@ static int SCHSTest02(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1153,7 +1153,7 @@ static int SCHSTest03(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1190,7 +1190,7 @@ static int SCHSTest04(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1224,7 +1224,7 @@ static int SCHSTest05(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1258,7 +1258,7 @@ static int SCHSTest06(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1290,7 +1290,7 @@ static int SCHSTest07(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1334,7 +1334,7 @@ static int SCHSTest08(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1366,7 +1366,7 @@ static int SCHSTest09(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1398,7 +1398,7 @@ static int SCHSTest10(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1435,7 +1435,7 @@ static int SCHSTest11(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1483,7 +1483,7 @@ static int SCHSTest12(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1518,7 +1518,7 @@ static int SCHSTest13(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1552,7 +1552,7 @@ static int SCHSTest14(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1586,7 +1586,7 @@ static int SCHSTest15(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1620,7 +1620,7 @@ static int SCHSTest16(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1654,7 +1654,7 @@ static int SCHSTest17(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1688,7 +1688,7 @@ static int SCHSTest18(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1732,7 +1732,7 @@ static int SCHSTest19(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1766,7 +1766,7 @@ static int SCHSTest20(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1812,7 +1812,7 @@ static int SCHSTest21(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1844,7 +1844,7 @@ static int SCHSTest22(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1879,7 +1879,7 @@ static int SCHSTest23(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1911,7 +1911,7 @@ static int SCHSTest24(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1943,7 +1943,7 @@ static int SCHSTest25(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -1977,7 +1977,7 @@ static int SCHSTest26(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2010,7 +2010,7 @@ static int SCHSTest27(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); @@ -2043,7 +2043,7 @@ static int SCHSTest28(void) int result = 0; MpmCtx mpm_ctx; MpmThreadCtx mpm_thread_ctx; - PatternMatcherQueue pmq; + PrefilterRuleStore pmq; memset(&mpm_ctx, 0, sizeof(MpmCtx)); memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); diff --git a/src/util-mpm.c b/src/util-mpm.c index af2ecffc4a..b4e728ba8b 100644 --- a/src/util-mpm.c +++ b/src/util-mpm.c @@ -391,112 +391,6 @@ void MpmCudaEnvironmentSetup() #endif -/** - * \brief Setup a pmq - * - * \param pmq Pattern matcher queue to be initialized - * - * \retval -1 error - * \retval 0 ok - */ -int PmqSetup(PatternMatcherQueue *pmq) -{ - SCEnter(); - - if (pmq == NULL) { - SCReturnInt(-1); - } - - memset(pmq, 0, sizeof(PatternMatcherQueue)); - - pmq->rule_id_array_size = 128; /* Initial size, TODO: Make configure option. */ - pmq->rule_id_array_cnt = 0; - - size_t bytes = pmq->rule_id_array_size * sizeof(SigIntId); - pmq->rule_id_array = (SigIntId*)SCMalloc(bytes); - if (pmq->rule_id_array == NULL) { - pmq->rule_id_array_size = 0; - SCReturnInt(-1); - } - // Don't need to zero memory since it is always written first. - - SCReturnInt(0); -} - -/** \brief Add array of Signature IDs to rule ID array. - * - * Checks size of the array first - * - * \param pmq storage for match results - * \param new_size number of Signature IDs needing to be stored. - * - */ -int -MpmAddSidsResize(PatternMatcherQueue *pmq, uint32_t new_size) -{ - /* Need to make the array bigger. Double the size needed to - * also handle the case that sids_size might still be - * larger than the old size. - */ - new_size = new_size * 2; - SigIntId *new_array = (SigIntId*)SCRealloc(pmq->rule_id_array, - new_size * sizeof(SigIntId)); - if (unlikely(new_array == NULL)) { - /* Try again just big enough. */ - new_size = new_size / 2; - new_array = (SigIntId*)SCRealloc(pmq->rule_id_array, - new_size * sizeof(SigIntId)); - if (unlikely(new_array == NULL)) { - - SCLogError(SC_ERR_MEM_ALLOC, "Failed to realloc PatternMatchQueue" - " rule ID array. Some signature ID matches lost"); - return 0; - } - } - pmq->rule_id_array = new_array; - pmq->rule_id_array_size = new_size; - - return new_size; -} - -/** \brief Reset a Pmq for reusage. Meant to be called after a single search. - * \param pmq Pattern matcher to be reset. - * \todo memset is expensive, but we need it as we merge pmq's. We might use - * a flag so we can clear pmq's the old way if we can. - */ -void PmqReset(PatternMatcherQueue *pmq) -{ - if (pmq == NULL) - return; - - pmq->rule_id_array_cnt = 0; - /* TODO: Realloc the rule id array smaller at some size? */ -} - -/** \brief Cleanup a Pmq - * \param pmq Pattern matcher queue to be cleaned up. - */ -void PmqCleanup(PatternMatcherQueue *pmq) -{ - if (pmq == NULL) - return; - if (pmq->rule_id_array != NULL) { - SCFree(pmq->rule_id_array); - pmq->rule_id_array = NULL; - } -} - -/** \brief Cleanup and free a Pmq - * \param pmq Pattern matcher queue to be free'd. - */ -void PmqFree(PatternMatcherQueue *pmq) -{ - if (pmq == NULL) - return; - - PmqCleanup(pmq); -} - void MpmInitThreadCtx(MpmThreadCtx *mpm_thread_ctx, uint16_t matcher) { mpm_table[matcher].InitThreadCtx(NULL, mpm_thread_ctx); diff --git a/src/util-mpm.h b/src/util-mpm.h index 60634c45ef..fe161c12c1 100644 --- a/src/util-mpm.h +++ b/src/util-mpm.h @@ -23,8 +23,8 @@ #ifndef __UTIL_MPM_H__ #define __UTIL_MPM_H__ -#include "suricata-common.h" +#include "util-prefilter.h" #define MPM_INIT_HASH_SIZE 65536 @@ -66,21 +66,6 @@ typedef struct MpmThreadCtx_ { } MpmThreadCtx; -/** \brief helper structure for the pattern matcher engine. The Pattern Matcher - * thread has this and passes a pointer to it to the pattern matcher. - * The actual pattern matcher will fill the structure. */ -typedef struct PatternMatcherQueue_ { - /* used for storing rule id's */ - - /* Array of rule IDs found. */ - SigIntId *rule_id_array; - /* Number of rule IDs in the array. */ - uint32_t rule_id_array_cnt; - /* The number of slots allocated for storing rule IDs */ - uint32_t rule_id_array_size; - -} PatternMatcherQueue; - typedef struct MpmPattern_ { /* length of the pattern */ uint16_t len; @@ -178,7 +163,7 @@ typedef struct MpmTableElmt_ { int (*AddPattern)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int (*AddPatternNocase)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int (*Prepare)(struct MpmCtx_ *); - uint32_t (*Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, const uint8_t *, uint16_t); + uint32_t (*Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint16_t); void (*PrintCtx)(struct MpmCtx_ *); void (*PrintThreadCtx)(struct MpmThreadCtx_ *); void (*RegisterUnittests)(void); @@ -231,10 +216,10 @@ MpmCtx *MpmFactoryGetMpmCtxForProfile(const struct DetectEngineCtx_ *, int32_t, void MpmFactoryDeRegisterAllMpmCtxProfiles(struct DetectEngineCtx_ *); int32_t MpmFactoryIsMpmCtxAvailable(const struct DetectEngineCtx_ *, const MpmCtx *); -int PmqSetup(PatternMatcherQueue *); -void PmqReset(PatternMatcherQueue *); -void PmqCleanup(PatternMatcherQueue *); -void PmqFree(PatternMatcherQueue *); +int PmqSetup(PrefilterRuleStore *); +void PmqReset(PrefilterRuleStore *); +void PmqCleanup(PrefilterRuleStore *); +void PmqFree(PrefilterRuleStore *); void MpmTableSetup(void); void MpmRegisterTests(void); @@ -255,40 +240,4 @@ int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags); -/* Resize Signature ID array. Only called from MpmAddSids(). */ -int MpmAddSidsResize(PatternMatcherQueue *pmq, uint32_t new_size); - -/** \brief Add array of Signature IDs to rule ID array. - * - * Checks size of the array first. Calls MpmAddSidsResize to increase - * The size of the array, since that is the slow path. - * - * \param pmq storage for match results - * \param sids pointer to array of Signature IDs - * \param sids_size number of Signature IDs in sids array. - * - */ -static inline void -MpmAddSids(PatternMatcherQueue *pmq, SigIntId *sids, uint32_t sids_size) -{ - if (sids_size == 0) - return; - - uint32_t new_size = pmq->rule_id_array_cnt + sids_size; - if (new_size > pmq->rule_id_array_size) { - if (MpmAddSidsResize(pmq, new_size) == 0) { - // Failed to allocate larger memory for all the SIDS, but - // keep as many as we can. - sids_size = pmq->rule_id_array_size - pmq->rule_id_array_cnt; - } - } - SCLogDebug("Adding %u sids", sids_size); - // Add SIDs for this pattern to the end of the array - SigIntId *ptr = pmq->rule_id_array + pmq->rule_id_array_cnt; - SigIntId *end = ptr + sids_size; - do { - *ptr++ = *sids++; - } while (ptr != end); - pmq->rule_id_array_cnt += sids_size; -} #endif /* __UTIL_MPM_H__ */ diff --git a/src/util-prefilter.c b/src/util-prefilter.c new file mode 100644 index 0000000000..406cee6bfb --- /dev/null +++ b/src/util-prefilter.c @@ -0,0 +1,132 @@ +/* Copyright (C) 2007-2014 Open Information Security Foundation + * + * You can copy, redistribute or modify this Program under the terms of + * the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * \file + * + * \author Victor Julien + * + * Pattern matcher utility Functions + */ + +#include "suricata-common.h" + +/** + * \brief Setup a pmq + * + * \param pmq Pattern matcher queue to be initialized + * + * \retval -1 error + * \retval 0 ok + */ +int PmqSetup(PrefilterRuleStore *pmq) +{ + SCEnter(); + + if (pmq == NULL) { + SCReturnInt(-1); + } + + memset(pmq, 0, sizeof(PrefilterRuleStore)); + + pmq->rule_id_array_size = 128; /* Initial size, TODO: Make configure option. */ + pmq->rule_id_array_cnt = 0; + + size_t bytes = pmq->rule_id_array_size * sizeof(SigIntId); + pmq->rule_id_array = (SigIntId*)SCMalloc(bytes); + if (pmq->rule_id_array == NULL) { + pmq->rule_id_array_size = 0; + SCReturnInt(-1); + } + // Don't need to zero memory since it is always written first. + + SCReturnInt(0); +} + +/** \brief Add array of Signature IDs to rule ID array. + * + * Checks size of the array first + * + * \param pmq storage for match results + * \param new_size number of Signature IDs needing to be stored. + * + */ +int +PrefilterAddSidsResize(PrefilterRuleStore *pmq, uint32_t new_size) +{ + /* Need to make the array bigger. Double the size needed to + * also handle the case that sids_size might still be + * larger than the old size. + */ + new_size = new_size * 2; + SigIntId *new_array = (SigIntId*)SCRealloc(pmq->rule_id_array, + new_size * sizeof(SigIntId)); + if (unlikely(new_array == NULL)) { + /* Try again just big enough. */ + new_size = new_size / 2; + new_array = (SigIntId*)SCRealloc(pmq->rule_id_array, + new_size * sizeof(SigIntId)); + if (unlikely(new_array == NULL)) { + + SCLogError(SC_ERR_MEM_ALLOC, "Failed to realloc PatternMatchQueue" + " rule ID array. Some signature ID matches lost"); + return 0; + } + } + pmq->rule_id_array = new_array; + pmq->rule_id_array_size = new_size; + + return new_size; +} + +/** \brief Reset a Pmq for reusage. Meant to be called after a single search. + * \param pmq Pattern matcher to be reset. + * \todo memset is expensive, but we need it as we merge pmq's. We might use + * a flag so we can clear pmq's the old way if we can. + */ +void PmqReset(PrefilterRuleStore *pmq) +{ + if (pmq == NULL) + return; + + pmq->rule_id_array_cnt = 0; + /* TODO: Realloc the rule id array smaller at some size? */ +} + +/** \brief Cleanup a Pmq + * \param pmq Pattern matcher queue to be cleaned up. + */ +void PmqCleanup(PrefilterRuleStore *pmq) +{ + if (pmq == NULL) + return; + if (pmq->rule_id_array != NULL) { + SCFree(pmq->rule_id_array); + pmq->rule_id_array = NULL; + } +} + +/** \brief Cleanup and free a Pmq + * \param pmq Pattern matcher queue to be free'd. + */ +void PmqFree(PrefilterRuleStore *pmq) +{ + if (pmq == NULL) + return; + + PmqCleanup(pmq); +} diff --git a/src/util-prefilter.h b/src/util-prefilter.h new file mode 100644 index 0000000000..1106795d3d --- /dev/null +++ b/src/util-prefilter.h @@ -0,0 +1,80 @@ +/* Copyright (C) 2016 Open Information Security Foundation + * + * You can copy, redistribute or modify this Program under the terms of + * the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * \file + * + * \author Victor Julien + */ + +#ifndef __UTIL_PREFILTER_H__ +#define __UTIL_PREFILTER_H__ + +/** \brief structure for storing potential rule matches + * + * Helper structure for the prefilter engine. The Pattern Matchers + * and other prefilter engines will add rule id's for potential + * rule matches */ +typedef struct PrefilterRuleStore_ { + /* used for storing rule id's */ + + /* Array of rule IDs found. */ + SigIntId *rule_id_array; + /* Number of rule IDs in the array. */ + uint32_t rule_id_array_cnt; + /* The number of slots allocated for storing rule IDs */ + uint32_t rule_id_array_size; + +} PrefilterRuleStore; + +/* Resize Signature ID array. Only called from MpmAddSids(). */ +int PrefilterAddSidsResize(PrefilterRuleStore *pmq, uint32_t new_size); + +/** \brief Add array of Signature IDs to rule ID array. + * + * Checks size of the array first. Calls PrefilterAddSidsResize to increase + * The size of the array, since that is the slow path. + * + * \param pmq storage for match results + * \param sids pointer to array of Signature IDs + * \param sids_size number of Signature IDs in sids array. + * + */ +static inline void +PrefilterAddSids(PrefilterRuleStore *pmq, SigIntId *sids, uint32_t sids_size) +{ + if (sids_size == 0) + return; + + uint32_t new_size = pmq->rule_id_array_cnt + sids_size; + if (new_size > pmq->rule_id_array_size) { + if (PrefilterAddSidsResize(pmq, new_size) == 0) { + // Failed to allocate larger memory for all the SIDS, but + // keep as many as we can. + sids_size = pmq->rule_id_array_size - pmq->rule_id_array_cnt; + } + } + SCLogDebug("Adding %u sids", sids_size); + // Add SIDs for this pattern to the end of the array + SigIntId *ptr = pmq->rule_id_array + pmq->rule_id_array_cnt; + SigIntId *end = ptr + sids_size; + do { + *ptr++ = *sids++; + } while (ptr != end); + pmq->rule_id_array_cnt += sids_size; +} +#endif /* __UTIL_PREFILTER_H__ */