From 1e01fd613c7e0ed92203bc8fda7b0c654a9da5ba Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 20 Mar 2010 11:59:42 +0100 Subject: [PATCH] Remove all references to the scan phase from the pattern matchers and it's api. --- src/app-layer-detect-proto.c | 8 +- src/detect-content.c | 6 +- src/detect-engine-mpm.c | 16 +- src/util-mpm-b2g.c | 669 +++++++++++++------------ src/util-mpm-b2g.h | 64 +-- src/util-mpm-b3g.c | 601 +++++++++++------------ src/util-mpm-b3g.h | 58 +-- src/util-mpm-wumanber.c | 923 +++++++++++++++++------------------ src/util-mpm-wumanber.h | 36 +- src/util-mpm.h | 13 +- 10 files changed, 1192 insertions(+), 1202 deletions(-) diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index 4f340b4097..158d43f4df 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -126,7 +126,7 @@ void AlpProtoAdd(AlpProtoDetectCtx *ctx, uint16_t ip_proto, uint16_t al_proto, c dir = &ctx->toserver; } - mpm_table[dir->mpm_ctx.mpm_type].AddScanPattern(&dir->mpm_ctx, cd->content, cd->content_len, + mpm_table[dir->mpm_ctx.mpm_type].AddPattern(&dir->mpm_ctx, cd->content, cd->content_len, cd->offset, cd->depth, dir->id, dir->id, 0); dir->map[dir->id] = al_proto; dir->id++; @@ -301,7 +301,7 @@ uint16_t AppLayerDetectGetProto(AlpProtoDetectCtx *ctx, AlpProtoDetectThreadCtx uint16_t proto = ALPROTO_UNKNOWN; uint32_t cnt = 0; #ifndef __SC_CUDA_SUPPORT__ - cnt = mpm_table[dir->mpm_ctx.mpm_type].Scan(&dir->mpm_ctx, + cnt = mpm_table[dir->mpm_ctx.mpm_type].Search(&dir->mpm_ctx, &tdir->mpm_ctx, &tdir->pmq, buf, scanlen); @@ -666,7 +666,7 @@ int AlpDetectTest03(void) { } #endif - uint32_t cnt = mpm_table[ctx.toclient.mpm_ctx.mpm_type].Scan(&ctx.toclient.mpm_ctx, &tctx.toclient.mpm_ctx, NULL, l7data, sizeof(l7data)); + uint32_t cnt = mpm_table[ctx.toclient.mpm_ctx.mpm_type].Search(&ctx.toclient.mpm_ctx, &tctx.toclient.mpm_ctx, NULL, l7data, sizeof(l7data)); if (cnt != 1) { printf("cnt %u != 1: ", cnt); r = 0; @@ -723,7 +723,7 @@ int AlpDetectTest04(void) { } #endif - uint32_t cnt = mpm_table[ctx.toclient.mpm_ctx.mpm_type].Scan(&ctx.toclient.mpm_ctx, &tctx.toclient.mpm_ctx, NULL, l7data, sizeof(l7data)); + uint32_t cnt = mpm_table[ctx.toclient.mpm_ctx.mpm_type].Search(&ctx.toclient.mpm_ctx, &tctx.toclient.mpm_ctx, NULL, l7data, sizeof(l7data)); if (cnt != 0) { printf("cnt %u != 0: ", cnt); r = 0; diff --git a/src/detect-content.c b/src/detect-content.c index 5c2de27f8f..0bc954542a 100644 --- a/src/detect-content.c +++ b/src/detect-content.c @@ -1088,6 +1088,8 @@ static uint32_t DetectContentTableHash(HashTable *ht, void *p, uint16_t len) { } static void DetectContentTableElmtFree(void *e) { + DetectContentTableElmt *c = (DetectContentTableElmt *)e; + free(c->pattern); free(e); } @@ -1125,7 +1127,9 @@ uint32_t DetectContentGetId(DetectEngineCtx *de_ctx, DetectContentData *co) { e = malloc(sizeof(DetectContentTableElmt)); BUG_ON(e == NULL); - e->pattern = co->content; + e->pattern = SCMalloc(co->content_len); + BUG_ON(e->pattern == NULL); + memcpy(e->pattern, co->content, co->content_len); e->pattern_len = co->content_len; e->id = 0; diff --git a/src/detect-engine-mpm.c b/src/detect-engine-mpm.c index 2e142e415d..bcd998ae84 100644 --- a/src/detect-engine-mpm.c +++ b/src/detect-engine-mpm.c @@ -81,7 +81,7 @@ uint32_t PacketPatternScan(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, uint32_t ret; #ifndef __SC_CUDA_SUPPORT__ - ret = mpm_table[det_ctx->sgh->mpm_ctx->mpm_type].Scan(det_ctx->sgh->mpm_ctx, + ret = mpm_table[det_ctx->sgh->mpm_ctx->mpm_type].Search(det_ctx->sgh->mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, p->payload, @@ -91,7 +91,7 @@ uint32_t PacketPatternScan(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, * algo, then we shouldn't take the path of the dispatcher. Call the mpm * directly */ if (det_ctx->sgh->mpm_ctx->mpm_type != MPM_B2G_CUDA) { - ret = mpm_table[det_ctx->sgh->mpm_ctx->mpm_type].Scan(det_ctx->sgh->mpm_ctx, + ret = mpm_table[det_ctx->sgh->mpm_ctx->mpm_type].Search(det_ctx->sgh->mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, p->payload, @@ -121,7 +121,7 @@ uint32_t UriPatternScan(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, uint32_t ret; #ifndef __SC_CUDA_SUPPORT__ - ret = mpm_table[det_ctx->sgh->mpm_uri_ctx->mpm_type].Scan + ret = mpm_table[det_ctx->sgh->mpm_uri_ctx->mpm_type].Search (det_ctx->sgh->mpm_uri_ctx, &det_ctx->mtcu, &det_ctx->pmq, uri, uri_len); #else @@ -129,7 +129,7 @@ uint32_t UriPatternScan(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, * algo, then we shouldn't take the path of the dispatcher. Call the mpm * directly */ if (det_ctx->sgh->mpm_uri_ctx->mpm_type != MPM_B2G_CUDA) { - ret = mpm_table[det_ctx->sgh->mpm_uri_ctx->mpm_type].Scan + ret = mpm_table[det_ctx->sgh->mpm_uri_ctx->mpm_type].Search (det_ctx->sgh->mpm_uri_ctx, &det_ctx->mtcu, &det_ctx->pmq, uri, uri_len); SCReturnUInt(ret); @@ -535,9 +535,9 @@ static int PatternMatchPreprarePopulateMpm(DetectEngineCtx *de_ctx, SigGroupHead depth = scan_ch->cnt ? 0 : depth; if (co->flags & DETECT_CONTENT_NOCASE) { - mpm_table[sgh->mpm_ctx->mpm_type].AddScanPatternNocase(sgh->mpm_ctx, co->content, co->content_len, offset, depth, co->id, s->num, scan_ch->nosearch); + mpm_table[sgh->mpm_ctx->mpm_type].AddPatternNocase(sgh->mpm_ctx, co->content, co->content_len, offset, depth, co->id, s->num, scan_ch->nosearch); } else { - mpm_table[sgh->mpm_ctx->mpm_type].AddScanPattern(sgh->mpm_ctx, co->content, co->content_len, offset, depth, co->id, s->num, scan_ch->nosearch); + mpm_table[sgh->mpm_ctx->mpm_type].AddPattern(sgh->mpm_ctx, co->content, co->content_len, offset, depth, co->id, s->num, scan_ch->nosearch); } SCLogDebug("%"PRIu32" adding co->id %"PRIu32" to the scan phase (s->num %"PRIu32")", s->id, co->id, s->num); @@ -868,9 +868,9 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh) * length is the same as maxlen (ie we only add the longest pattern) */ if (!uricontent_scanadded && uricontent_maxlen == ud->uricontent_len) { if (ud->flags & DETECT_URICONTENT_NOCASE) { - mpm_table[sh->mpm_uri_ctx->mpm_type].AddScanPatternNocase(sh->mpm_uri_ctx, ud->uricontent, ud->uricontent_len, 0, 0, ud->id, s->num, 0); + mpm_table[sh->mpm_uri_ctx->mpm_type].AddPatternNocase(sh->mpm_uri_ctx, ud->uricontent, ud->uricontent_len, 0, 0, ud->id, s->num, 0); } else { - mpm_table[sh->mpm_uri_ctx->mpm_type].AddScanPattern(sh->mpm_uri_ctx, ud->uricontent, ud->uricontent_len, 0, 0, ud->id, s->num, 0); + mpm_table[sh->mpm_uri_ctx->mpm_type].AddPattern(sh->mpm_uri_ctx, ud->uricontent, ud->uricontent_len, 0, 0, ud->id, s->num, 0); } uricontent_scanadded = 1; diff --git a/src/util-mpm-b2g.c b/src/util-mpm-b2g.c index 65c1d25e4d..c23ec47ad7 100644 --- a/src/util-mpm-b2g.c +++ b/src/util-mpm-b2g.c @@ -36,22 +36,22 @@ static uint32_t b2g_hash_size = 0; static uint32_t b2g_bloom_size = 0; -static void *b2g_scan_func; +static void *b2g_func; void B2gInitCtx (MpmCtx *, int); void B2gThreadInitCtx(MpmCtx *, MpmThreadCtx *, uint32_t); void B2gDestroyCtx(MpmCtx *); void B2gThreadDestroyCtx(MpmCtx *, MpmThreadCtx *); -int B2gAddScanPatternCI(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, uint8_t); -int B2gAddScanPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, uint8_t); +int B2gAddPatternCI(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, uint8_t); +int B2gAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, uint8_t); int B2gPreparePatterns(MpmCtx *mpm_ctx); -inline uint32_t B2gScanWrap(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *, uint8_t *buf, uint16_t buflen); -uint32_t B2gScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *, uint8_t *buf, uint16_t buflen); -#ifdef B2G_SCAN2 -uint32_t B2gScan2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *, uint8_t *buf, uint16_t buflen); +inline uint32_t B2gSearchWrap(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *, uint8_t *buf, uint16_t buflen); +uint32_t B2gSearch1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *, uint8_t *buf, uint16_t buflen); +#ifdef B2G_SEARCH2 +uint32_t B2gSearch2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *, uint8_t *buf, uint16_t buflen); #endif -uint32_t B2gScan(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *, uint8_t *buf, uint16_t buflen); -uint32_t B2gScanBNDMq(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen); +uint32_t B2gSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *, uint8_t *buf, uint16_t buflen); +uint32_t B2gSearchBNDMq(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen); void B2gPrintInfo(MpmCtx *mpm_ctx); void B2gPrintSearchStats(MpmThreadCtx *mpm_thread_ctx); void B2gRegisterTests(void); @@ -63,14 +63,11 @@ void MpmB2gRegister (void) { mpm_table[MPM_B2G].InitThreadCtx = B2gThreadInitCtx; mpm_table[MPM_B2G].DestroyCtx = B2gDestroyCtx; mpm_table[MPM_B2G].DestroyThreadCtx = B2gThreadDestroyCtx; - mpm_table[MPM_B2G].AddScanPattern = B2gAddScanPatternCS; - mpm_table[MPM_B2G].AddScanPatternNocase = B2gAddScanPatternCI; - //mpm_table[MPM_B2G].AddPattern = B2gAddPatternCS; - //mpm_table[MPM_B2G].AddPatternNocase = B2gAddPatternCI; + mpm_table[MPM_B2G].AddPattern = B2gAddPatternCS; + mpm_table[MPM_B2G].AddPatternNocase = B2gAddPatternCI; mpm_table[MPM_B2G].Prepare = B2gPreparePatterns; - mpm_table[MPM_B2G].Scan = B2gScanWrap; - //mpm_table[MPM_B2G].Search = B2gSearchWrap; - //mpm_table[MPM_B2G].Cleanup = MpmMatchCleanup; + mpm_table[MPM_B2G].Search = B2gSearchWrap; + mpm_table[MPM_B2G].Cleanup = NULL; mpm_table[MPM_B2G].PrintCtx = B2gPrintInfo; mpm_table[MPM_B2G].PrintThreadCtx = B2gPrintSearchStats; mpm_table[MPM_B2G].RegisterUnittests = B2gRegisterTests; @@ -146,11 +143,11 @@ void B2gPrintInfo(MpmCtx *mpm_ctx) { printf(" B2gPattern %" PRIuMAX "\n", (uintmax_t)sizeof(B2gPattern)); printf(" B2gHashItem %" PRIuMAX "\n", (uintmax_t)sizeof(B2gHashItem)); printf("Unique Patterns: %" PRIu32 "\n", mpm_ctx->pattern_cnt); - printf("Scan Patterns: %" PRIu32 "\n", mpm_ctx->scan_pattern_cnt); + printf("Scan Patterns: %" PRIu32 "\n", mpm_ctx->pattern_cnt); printf("Total Patterns: %" PRIu32 "\n", mpm_ctx->total_pattern_cnt); - printf("Smallest: %" PRIu32 "\n", mpm_ctx->scan_minlen); - printf("Largest: %" PRIu32 "\n", mpm_ctx->scan_maxlen); - printf("Hash size: %" PRIu32 "\n", ctx->scan_hash_size); + printf("Smallest: %" PRIu32 "\n", mpm_ctx->minlen); + printf("Largest: %" PRIu32 "\n", mpm_ctx->maxlen); + printf("Hash size: %" PRIu32 "\n", ctx->hash_size); printf("\n"); } @@ -370,12 +367,11 @@ static inline int B2gAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, printf("Max search words reached\n"); exit(1); } - if (scan) mpm_ctx->scan_pattern_cnt++; mpm_ctx->pattern_cnt++; - if (mpm_ctx->scan_maxlen < patlen) mpm_ctx->scan_maxlen = patlen; - if (mpm_ctx->scan_minlen == 0) mpm_ctx->scan_minlen = patlen; - else if (mpm_ctx->scan_minlen > patlen) mpm_ctx->scan_minlen = patlen; + if (mpm_ctx->maxlen < patlen) mpm_ctx->maxlen = patlen; + if (mpm_ctx->minlen == 0) mpm_ctx->minlen = patlen; + else if (mpm_ctx->minlen > patlen) mpm_ctx->minlen = patlen; } /* we need a match */ @@ -389,13 +385,13 @@ error: return -1; } -int B2gAddScanPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, +int B2gAddPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, uint32_t sid, uint8_t nosearch) { return B2gAddPattern(mpm_ctx, pat, patlen, offset, depth, /* nocase */1, /* scan */1, pid, sid, nosearch); } -int B2gAddScanPatternCS(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, +int B2gAddPatternCS(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, uint32_t sid, uint8_t nosearch) { return B2gAddPattern(mpm_ctx, pat, patlen, offset, depth, /* nocase */0, /* scan */1, pid, sid, nosearch); @@ -416,131 +412,131 @@ static inline uint32_t B2gBloomHash(void *data, uint16_t datalen, uint8_t iter, return hash; } -static void B2gPrepareScanHash(MpmCtx *mpm_ctx) { +static void B2gPrepareHash(MpmCtx *mpm_ctx) { B2gCtx *ctx = (B2gCtx *)mpm_ctx->ctx; uint16_t i; uint16_t idx = 0; uint8_t idx8 = 0; - ctx->scan_hash = (B2gHashItem **)SCMalloc(sizeof(B2gHashItem *) * ctx->scan_hash_size); - if (ctx->scan_hash == NULL) goto error; - memset(ctx->scan_hash, 0, sizeof(B2gHashItem *) * ctx->scan_hash_size); + ctx->hash = (B2gHashItem **)SCMalloc(sizeof(B2gHashItem *) * ctx->hash_size); + if (ctx->hash == NULL) goto error; + memset(ctx->hash, 0, sizeof(B2gHashItem *) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(B2gHashItem *) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(B2gHashItem *) * ctx->hash_size); -#ifdef B2G_SCAN2 - ctx->scan_hash2 = (B2gHashItem **)SCMalloc(sizeof(B2gHashItem *) * ctx->scan_hash_size); - if (ctx->scan_hash2 == NULL) goto error; - memset(ctx->scan_hash2, 0, sizeof(B2gHashItem *) * ctx->scan_hash_size); +#ifdef B2G_SEARCH2 + ctx->hash2 = (B2gHashItem **)SCMalloc(sizeof(B2gHashItem *) * ctx->hash_size); + if (ctx->hash2 == NULL) goto error; + memset(ctx->hash2, 0, sizeof(B2gHashItem *) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(B2gHashItem *) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(B2gHashItem *) * ctx->hash_size); #endif /* alloc the pminlen array */ - ctx->scan_pminlen = (uint8_t *)SCMalloc(sizeof(uint8_t) * ctx->scan_hash_size); - if (ctx->scan_pminlen == NULL) goto error; - memset(ctx->scan_pminlen, 0, sizeof(uint8_t) * ctx->scan_hash_size); + ctx->pminlen = (uint8_t *)SCMalloc(sizeof(uint8_t) * ctx->hash_size); + if (ctx->pminlen == NULL) goto error; + memset(ctx->pminlen, 0, sizeof(uint8_t) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(uint8_t) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(uint8_t) * ctx->hash_size); for (i = 0; i < mpm_ctx->pattern_cnt; i++) { if(ctx->parray[i]->len == 1) { idx8 = (uint8_t)ctx->parray[i]->ci[0]; - if (ctx->scan_hash1[idx8].flags == 0) { - ctx->scan_hash1[idx8].idx = i; - ctx->scan_hash1[idx8].flags |= 0x01; + if (ctx->hash1[idx8].flags == 0) { + ctx->hash1[idx8].idx = i; + ctx->hash1[idx8].flags |= 0x01; } else { B2gHashItem *hi = B2gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; /* Append this HashItem to the list */ - B2gHashItem *thi = &ctx->scan_hash1[idx8]; + B2gHashItem *thi = &ctx->hash1[idx8]; while (thi->nxt) thi = thi->nxt; thi->nxt = hi; } - ctx->scan_1_pat_cnt++; -#ifdef B2G_SCAN2 + ctx->pat_1_cnt++; +#ifdef B2G_SEARCH2 } else if(ctx->parray[i]->len == 2) { idx = B2G_HASH16(ctx->parray[i]->ci[0],ctx->parray[i]->ci[1]); - if (ctx->scan_hash2[idx] == NULL) { + if (ctx->hash2[idx] == NULL) { B2gHashItem *hi = B2gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; - ctx->scan_hash2[idx] = hi; + ctx->hash2[idx] = hi; } else { B2gHashItem *hi = B2gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; /* Append this HashItem to the list */ - B2gHashItem *thi = ctx->scan_hash2[idx]; + B2gHashItem *thi = ctx->hash2[idx]; while (thi->nxt) thi = thi->nxt; thi->nxt = hi; } - ctx->scan_2_pat_cnt++; + ctx->pat_2_cnt++; #endif } else { - idx = B2G_HASH16(ctx->parray[i]->ci[ctx->scan_m - 2], ctx->parray[i]->ci[ctx->scan_m - 1]); - SCLogDebug("idx %" PRIu32 ", %c.%c", idx, ctx->parray[i]->ci[ctx->scan_m - 2], ctx->parray[i]->ci[ctx->scan_m - 1]); + idx = B2G_HASH16(ctx->parray[i]->ci[ctx->m - 2], ctx->parray[i]->ci[ctx->m - 1]); + SCLogDebug("idx %" PRIu32 ", %c.%c", idx, ctx->parray[i]->ci[ctx->m - 2], ctx->parray[i]->ci[ctx->m - 1]); - if (ctx->scan_hash[idx] == NULL) { + if (ctx->hash[idx] == NULL) { B2gHashItem *hi = B2gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; - ctx->scan_pminlen[idx] = ctx->parray[i]->len; + ctx->pminlen[idx] = ctx->parray[i]->len; - ctx->scan_hash[idx] = hi; + ctx->hash[idx] = hi; } else { B2gHashItem *hi = B2gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; - if (ctx->parray[i]->len < ctx->scan_pminlen[idx]) - ctx->scan_pminlen[idx] = ctx->parray[i]->len; + if (ctx->parray[i]->len < ctx->pminlen[idx]) + ctx->pminlen[idx] = ctx->parray[i]->len; /* Append this HashItem to the list */ - B2gHashItem *thi = ctx->scan_hash[idx]; + B2gHashItem *thi = ctx->hash[idx]; while (thi->nxt) thi = thi->nxt; thi->nxt = hi; } - ctx->scan_x_pat_cnt++; + ctx->pat_x_cnt++; } } /* alloc the bloom array */ - ctx->scan_bloom = (BloomFilter **)SCMalloc(sizeof(BloomFilter *) * ctx->scan_hash_size); - if (ctx->scan_bloom == NULL) goto error; - memset(ctx->scan_bloom, 0, sizeof(BloomFilter *) * ctx->scan_hash_size); + ctx->bloom = (BloomFilter **)SCMalloc(sizeof(BloomFilter *) * ctx->hash_size); + if (ctx->bloom == NULL) goto error; + memset(ctx->bloom, 0, sizeof(BloomFilter *) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(BloomFilter *) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(BloomFilter *) * ctx->hash_size); uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - B2gHashItem *hi = ctx->scan_hash[h]; + for (h = 0; h < ctx->hash_size; h++) { + B2gHashItem *hi = ctx->hash[h]; if (hi == NULL) continue; - ctx->scan_bloom[h] = BloomFilterInit(b2g_bloom_size, 2, B2gBloomHash); - if (ctx->scan_bloom[h] == NULL) + ctx->bloom[h] = BloomFilterInit(b2g_bloom_size, 2, B2gBloomHash); + if (ctx->bloom[h] == NULL) continue; - mpm_ctx->memory_cnt += BloomFilterMemoryCnt(ctx->scan_bloom[h]); - mpm_ctx->memory_size += BloomFilterMemorySize(ctx->scan_bloom[h]); + mpm_ctx->memory_cnt += BloomFilterMemoryCnt(ctx->bloom[h]); + mpm_ctx->memory_size += BloomFilterMemorySize(ctx->bloom[h]); - if (ctx->scan_pminlen[h] > 8) - ctx->scan_pminlen[h] = 8; + if (ctx->pminlen[h] > 8) + ctx->pminlen[h] = 8; B2gHashItem *thi = hi; do { SCLogDebug("adding \"%c%c\" to the bloom", ctx->parray[thi->idx]->ci[0], ctx->parray[thi->idx]->ci[1]); - BloomFilterAdd(ctx->scan_bloom[h], ctx->parray[thi->idx]->ci, ctx->scan_pminlen[h]); + BloomFilterAdd(ctx->bloom[h], ctx->parray[thi->idx]->ci, ctx->pminlen[h]); thi = thi->nxt; } while (thi != NULL); } @@ -550,36 +546,36 @@ error: return; } -int B2gBuildScanMatchArray(MpmCtx *mpm_ctx) { +int B2gBuildMatchArray(MpmCtx *mpm_ctx) { SCEnter(); B2gCtx *ctx = (B2gCtx *)mpm_ctx->ctx; - ctx->scan_B2G = SCMalloc(sizeof(B2G_TYPE) * ctx->scan_hash_size); - if (ctx->scan_B2G == NULL) + ctx->B2G = SCMalloc(sizeof(B2G_TYPE) * ctx->hash_size); + if (ctx->B2G == NULL) return -1; mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(B2G_TYPE) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(B2G_TYPE) * ctx->hash_size); - memset(ctx->scan_B2G,0, b2g_hash_size * sizeof(B2G_TYPE)); + memset(ctx->B2G,0, b2g_hash_size * sizeof(B2G_TYPE)); uint32_t j; uint32_t a; /* fill the match array */ - for (j = 0; j <= (ctx->scan_m - B2G_Q); j++) { + for (j = 0; j <= (ctx->m - B2G_Q); j++) { for (a = 0; a < mpm_ctx->pattern_cnt; a++) { - if (ctx->parray[a]->len < ctx->scan_m) + if (ctx->parray[a]->len < ctx->m) continue; uint16_t h = B2G_HASH16(u8_tolower(ctx->parray[a]->ci[j]),u8_tolower(ctx->parray[a]->ci[j+1])); - ctx->scan_B2G[h] = ctx->scan_B2G[h] | (1 << (ctx->scan_m - j)); + ctx->B2G[h] = ctx->B2G[h] | (1 << (ctx->m - j)); - SCLogDebug("h %"PRIu16", ctx->scan_B2G[h] %"PRIu32"", h, ctx->scan_B2G[h]); + SCLogDebug("h %"PRIu16", ctx->B2G[h] %"PRIu32"", h, ctx->B2G[h]); } } - ctx->scan_s0 = 1; + ctx->s0 = 1; SCReturnInt(0); } @@ -613,33 +609,33 @@ int B2gPreparePatterns(MpmCtx *mpm_ctx) { ctx->init_hash = NULL; /* set 'm' to the smallest pattern size */ - ctx->scan_m = mpm_ctx->scan_minlen; + ctx->m = mpm_ctx->minlen; /* make sure 'm' stays in bounds m can be max WORD_SIZE - 1 */ - if (ctx->scan_m >= B2G_WORD_SIZE) { - ctx->scan_m = B2G_WORD_SIZE - 1; + if (ctx->m >= B2G_WORD_SIZE) { + ctx->m = B2G_WORD_SIZE - 1; } - if (ctx->scan_m < 2) ctx->scan_m = 2; - - ctx->scan_hash_size = b2g_hash_size; - B2gPrepareScanHash(mpm_ctx); - B2gBuildScanMatchArray(mpm_ctx); - - SCLogDebug("ctx->scan_1_pat_cnt %"PRIu16"", ctx->scan_1_pat_cnt); - if (ctx->scan_1_pat_cnt) { - ctx->Scan = B2gScan1; -#ifdef B2G_SCAN2 - ctx->Scan = B2gScan2; - if (ctx->scan_2_pat_cnt) { - ctx->MBScan2 = B2gScan2; + if (ctx->m < 2) ctx->m = 2; + + ctx->hash_size = b2g_hash_size; + B2gPrepareHash(mpm_ctx); + B2gBuildMatchArray(mpm_ctx); + + SCLogDebug("ctx->pat_1_cnt %"PRIu16"", ctx->pat_1_cnt); + if (ctx->pat_1_cnt) { + ctx->Search = B2gSearch1; +#ifdef B2G_SEARCH2 + ctx->Search = B2gSearch2; + if (ctx->pat_2_cnt) { + ctx->MBSearch2 = B2gSearch2; } #endif - ctx->MBScan = b2g_scan_func; -#ifdef B2G_SCAN2 - } else if (ctx->scan_2_pat_cnt) { - ctx->Scan = B2gScan2; - ctx->MBScan = b2g_scan_func; + ctx->MBSearch = b2g_func; +#ifdef B2G_SEARCH2 + } else if (ctx->pat_2_cnt) { + ctx->Search = B2gSearch2; + ctx->MBSearch = b2g_func; #endif } @@ -653,19 +649,18 @@ void B2gPrintSearchStats(MpmThreadCtx *mpm_thread_ctx) { B2gThreadCtx *tctx = (B2gThreadCtx *)mpm_thread_ctx->ctx; printf("B2g Thread Search stats (tctx %p)\n", tctx); - printf("Scan phase:\n"); - printf("Total calls/scans: %" PRIu32 "\n", tctx->scan_stat_calls); - printf("Avg m/scan: %0.2f\n", tctx->scan_stat_calls ? (float)((float)tctx->scan_stat_m_total / (float)tctx->scan_stat_calls) : 0); - printf("D != 0 (possible match): %" PRIu32 "\n", tctx->scan_stat_d0); - printf("Avg hash items per bucket %0.2f (%" PRIu32 ")\n", tctx->scan_stat_d0 ? (float)((float)tctx->scan_stat_d0_hashloop / (float)tctx->scan_stat_d0) : 0, tctx->scan_stat_d0_hashloop); - printf("Loop match: %" PRIu32 "\n", tctx->scan_stat_loop_match); - printf("Loop no match: %" PRIu32 "\n", tctx->scan_stat_loop_no_match); - printf("Num shifts: %" PRIu32 "\n", tctx->scan_stat_num_shift); - printf("Total shifts: %" PRIu32 "\n", tctx->scan_stat_total_shift); - printf("Avg shifts: %0.2f\n", tctx->scan_stat_num_shift ? (float)((float)tctx->scan_stat_total_shift / (float)tctx->scan_stat_num_shift) : 0); - printf("Total BloomFilter checks: %" PRIu32 "\n", tctx->scan_stat_bloom_calls); - printf("BloomFilter hits: %0.4f%% (%" PRIu32 ")\n", tctx->scan_stat_bloom_calls ? (float)((float)((float)tctx->scan_stat_bloom_hits / (float)tctx->scan_stat_bloom_calls)*(float)100) : 0, tctx->scan_stat_bloom_hits); - printf("Avg pminlen: %0.2f\n\n", tctx->scan_stat_pminlen_calls ? (float)((float)tctx->scan_stat_pminlen_total / (float)tctx->scan_stat_pminlen_calls) : 0); + printf("Total calls/scans: %" PRIu32 "\n", tctx->stat_calls); + printf("Avg m/scan: %0.2f\n", tctx->stat_calls ? (float)((float)tctx->stat_m_total / (float)tctx->stat_calls) : 0); + printf("D != 0 (possible match): %" PRIu32 "\n", tctx->stat_d0); + printf("Avg hash items per bucket %0.2f (%" PRIu32 ")\n", tctx->stat_d0 ? (float)((float)tctx->stat_d0_hashloop / (float)tctx->stat_d0) : 0, tctx->stat_d0_hashloop); + printf("Loop match: %" PRIu32 "\n", tctx->stat_loop_match); + printf("Loop no match: %" PRIu32 "\n", tctx->stat_loop_no_match); + printf("Num shifts: %" PRIu32 "\n", tctx->stat_num_shift); + printf("Total shifts: %" PRIu32 "\n", tctx->stat_total_shift); + printf("Avg shifts: %0.2f\n", tctx->stat_num_shift ? (float)((float)tctx->stat_total_shift / (float)tctx->stat_num_shift) : 0); + printf("Total BloomFilter checks: %" PRIu32 "\n", tctx->stat_bloom_calls); + printf("BloomFilter hits: %0.4f%% (%" PRIu32 ")\n", tctx->stat_bloom_calls ? (float)((float)((float)tctx->stat_bloom_hits / (float)tctx->stat_bloom_calls)*(float)100) : 0, tctx->stat_bloom_hits); + printf("Avg pminlen: %0.2f\n\n", tctx->stat_pminlen_calls ? (float)((float)tctx->stat_pminlen_total / (float)tctx->stat_pminlen_calls) : 0); #endif /* B2G_COUNTERS */ } @@ -693,12 +688,12 @@ static void B2gGetConfig() ConfNode *b2g_conf; const char *hash_val = NULL; const char *bloom_val = NULL; - const char *scan_algo = NULL; + const char *algo = NULL; /* init defaults */ b2g_hash_size = HASHSIZE_LOW; b2g_bloom_size = BLOOMSIZE_MEDIUM; - b2g_scan_func = B2G_SCANFUNC; + b2g_func = B2G_SEARCHFUNC; ConfNode *pm = ConfGetNode("pattern-matcher"); @@ -707,18 +702,18 @@ static void B2gGetConfig() TAILQ_FOREACH(b2g_conf, &pm->head, next) { if (strncmp(b2g_conf->val, "b2g", 3) == 0) { - scan_algo = ConfNodeLookupChildValue - (b2g_conf->head.tqh_first, "scan_algo"); + algo = ConfNodeLookupChildValue + (b2g_conf->head.tqh_first, "algo"); hash_val = ConfNodeLookupChildValue (b2g_conf->head.tqh_first, "hash_size"); bloom_val = ConfNodeLookupChildValue (b2g_conf->head.tqh_first, "bf_size"); - if (scan_algo != NULL) { - if (strcmp(scan_algo, "B2gScan") == 0) { - b2g_scan_func = B2gScan; - } else if (strcmp(scan_algo, "B2gScanBNDMq") == 0) { - b2g_scan_func = B2gScanBNDMq; + if (algo != NULL) { + if (strcmp(algo, "B2gSearch") == 0) { + b2g_func = B2gSearch; + } else if (strcmp(algo, "B2gSearchBNDMq") == 0) { + b2g_func = B2gSearchBNDMq; } } @@ -763,7 +758,7 @@ void B2gInitCtx (MpmCtx *mpm_ctx, int module_handle) { B2gGetConfig(); /* init defaults scan/search functions */ - ctx->Scan = b2g_scan_func; + ctx->Search = b2g_func; SCReturn; } @@ -794,48 +789,48 @@ void B2gDestroyCtx(MpmCtx *mpm_ctx) { mpm_ctx->memory_size -= (mpm_ctx->pattern_cnt * sizeof(B2gPattern)); } - if (ctx->scan_B2G) { - SCFree(ctx->scan_B2G); + if (ctx->B2G) { + SCFree(ctx->B2G); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(B2G_TYPE) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(B2G_TYPE) * ctx->hash_size); } - if (ctx->scan_bloom) { + if (ctx->bloom) { uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - if (ctx->scan_bloom[h] == NULL) + for (h = 0; h < ctx->hash_size; h++) { + if (ctx->bloom[h] == NULL) continue; - mpm_ctx->memory_cnt -= BloomFilterMemoryCnt(ctx->scan_bloom[h]); - mpm_ctx->memory_size -= BloomFilterMemorySize(ctx->scan_bloom[h]); + mpm_ctx->memory_cnt -= BloomFilterMemoryCnt(ctx->bloom[h]); + mpm_ctx->memory_size -= BloomFilterMemorySize(ctx->bloom[h]); - BloomFilterFree(ctx->scan_bloom[h]); + BloomFilterFree(ctx->bloom[h]); } - SCFree(ctx->scan_bloom); + SCFree(ctx->bloom); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(BloomFilter *) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(BloomFilter *) * ctx->hash_size); } - if (ctx->scan_hash) { + if (ctx->hash) { uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - if (ctx->scan_hash[h] == NULL) + for (h = 0; h < ctx->hash_size; h++) { + if (ctx->hash[h] == NULL) continue; - B2gHashFree(mpm_ctx, ctx->scan_hash[h]); + B2gHashFree(mpm_ctx, ctx->hash[h]); } - SCFree(ctx->scan_hash); + SCFree(ctx->hash); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(B2gHashItem) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(B2gHashItem) * ctx->hash_size); } - if (ctx->scan_pminlen) { - SCFree(ctx->scan_pminlen); + if (ctx->pminlen) { + SCFree(ctx->pminlen); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(uint8_t) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(uint8_t) * ctx->hash_size); } SCFree(mpm_ctx->ctx); @@ -870,70 +865,70 @@ void B2gThreadDestroyCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx) { } } -inline uint32_t B2gScanWrap(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +inline uint32_t B2gSearchWrap(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B2gCtx *ctx = (B2gCtx *)mpm_ctx->ctx; - return ctx ? ctx->Scan(mpm_ctx, mpm_thread_ctx, pmq, buf, buflen) : 0; + return ctx ? ctx->Search(mpm_ctx, mpm_thread_ctx, pmq, buf, buflen) : 0; } -uint32_t B2gScanBNDMq(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t B2gSearchBNDMq(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B2gCtx *ctx = (B2gCtx *)mpm_ctx->ctx; #ifdef B2G_COUNTERS B2gThreadCtx *tctx = (B2gThreadCtx *)mpm_thread_ctx->ctx; #endif - uint32_t pos = ctx->scan_m - B2G_Q + 1, matches = 0; + uint32_t pos = ctx->m - B2G_Q + 1, matches = 0; B2G_TYPE d; //printf("\n"); //PrintRawDataFp(stdout, buf, buflen); - SCLogDebug("buflen %"PRIu32", ctx->scan_m %"PRIu32", pos %"PRIu32"", buflen, ctx->scan_m, pos); + SCLogDebug("buflen %"PRIu32", ctx->m %"PRIu32", pos %"PRIu32"", buflen, ctx->m, pos); - COUNT(tctx->scan_stat_calls++); - COUNT(tctx->scan_stat_m_total+=ctx->scan_m); + COUNT(tctx->stat_calls++); + COUNT(tctx->stat_m_total+=ctx->m); - if (buflen < ctx->scan_m) + if (buflen < ctx->m) return 0; while (pos <= (uint32_t)(buflen - B2G_Q + 1)) { uint16_t h = B2G_HASH16(u8_tolower(buf[pos - 1]),u8_tolower(buf[pos])); - d = ctx->scan_B2G[h]; + d = ctx->B2G[h]; if (d != 0) { - COUNT(tctx->scan_stat_d0++); + COUNT(tctx->stat_d0++); uint32_t j = pos; - uint32_t first = pos - (ctx->scan_m - B2G_Q + 1); + uint32_t first = pos - (ctx->m - B2G_Q + 1); do { j = j - 1; - if (d >= (uint32_t)(1 << (ctx->scan_m - 1))) { + if (d >= (uint32_t)(1 << (ctx->m - 1))) { if (j > first) pos = j; else { /* get our patterns from the hash */ - h = B2G_HASH16(u8_tolower(buf[j + ctx->scan_m - 2]),u8_tolower(buf[j + ctx->scan_m - 1])); + h = B2G_HASH16(u8_tolower(buf[j + ctx->m - 2]),u8_tolower(buf[j + ctx->m - 1])); - if (ctx->scan_bloom[h] != NULL) { - COUNT(tctx->scan_stat_pminlen_calls++); - COUNT(tctx->scan_stat_pminlen_total+=ctx->scan_pminlen[h]); + if (ctx->bloom[h] != NULL) { + COUNT(tctx->stat_pminlen_calls++); + COUNT(tctx->stat_pminlen_total+=ctx->pminlen[h]); - if ((buflen - j) < ctx->scan_pminlen[h]) { + if ((buflen - j) < ctx->pminlen[h]) { goto skip_loop; } else { - COUNT(tctx->scan_stat_bloom_calls++); + COUNT(tctx->stat_bloom_calls++); - if (BloomFilterTest(ctx->scan_bloom[h], buf+j, ctx->scan_pminlen[h]) == 0) { - COUNT(tctx->scan_stat_bloom_hits++); + if (BloomFilterTest(ctx->bloom[h], buf+j, ctx->pminlen[h]) == 0) { + COUNT(tctx->stat_bloom_hits++); SCLogDebug("Bloom: %p, buflen %" PRIu32 ", pos %" PRIu32 ", p_min_len %" PRIu32 "", - ctx->scan_bloom[h], buflen, pos, ctx->scan_pminlen[h]); + ctx->bloom[h], buflen, pos, ctx->pminlen[h]); goto skip_loop; } } } - B2gHashItem *hi = ctx->scan_hash[h], *thi; + B2gHashItem *hi = ctx->hash[h], *thi; for (thi = hi; thi != NULL; thi = thi->nxt) { - COUNT(tctx->scan_stat_d0_hashloop++); + COUNT(tctx->stat_d0_hashloop++); B2gPattern *p = ctx->parray[thi->idx]; if (p->flags & B2G_NOCASE) { @@ -945,11 +940,11 @@ uint32_t B2gScanBNDMq(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatc #ifdef PRINTMATCH printf("CI Exact match: "); prt(p->ci, p->len); printf("\n"); #endif - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); matches += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, j, p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } else { if (buflen - j < p->len) @@ -959,17 +954,17 @@ uint32_t B2gScanBNDMq(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatc #ifdef PRINTMATCH printf("CS Exact match: "); prt(p->cs, p->len); printf("\n"); #endif - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); matches += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, j, p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } } skip_loop: SCLogDebug("skipped"); - //SCLogDebug("output at pos %" PRIu32 ": ", j); prt(buf + (j), ctx->scan_m); printf("\n"); + //SCLogDebug("output at pos %" PRIu32 ": ", j); prt(buf + (j), ctx->m); printf("\n"); ; } } @@ -979,12 +974,12 @@ skip_loop: } h = B2G_HASH16(u8_tolower(buf[j - 1]),u8_tolower(buf[j])); - d = (d << 1) & ctx->scan_B2G[h]; + d = (d << 1) & ctx->B2G[h]; } while (d != 0); } - COUNT(tctx->scan_stat_num_shift++); - COUNT(tctx->scan_stat_total_shift += (ctx->scan_m - B2G_Q + 1)); - pos = pos + ctx->scan_m - B2G_Q + 1; + COUNT(tctx->stat_num_shift++); + COUNT(tctx->stat_total_shift += (ctx->m - B2G_Q + 1)); + pos = pos + ctx->m - B2G_Q + 1; SCLogDebug("pos %"PRIu32"", pos); } @@ -993,7 +988,7 @@ skip_loop: return matches; } -uint32_t B2gScan(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t B2gSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B2gCtx *ctx = (B2gCtx *)mpm_ctx->ctx; #ifdef B2G_COUNTERS B2gThreadCtx *tctx = (B2gThreadCtx *)mpm_thread_ctx->ctx; @@ -1002,52 +997,52 @@ uint32_t B2gScan(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQu B2G_TYPE d; uint32_t j; - COUNT(tctx->scan_stat_calls++); - COUNT(tctx->scan_stat_m_total+=ctx->scan_m); + COUNT(tctx->stat_calls++); + COUNT(tctx->stat_m_total+=ctx->m); - if (buflen < ctx->scan_m) + if (buflen < ctx->m) return 0; - while (pos <= (buflen - ctx->scan_m)) { - j = ctx->scan_m - 1; + while (pos <= (buflen - ctx->m)) { + j = ctx->m - 1; d = ~0; do { uint16_t h = B2G_HASH16(u8_tolower(buf[pos + j - 1]),u8_tolower(buf[pos + j])); - d = ((d << 1) & ctx->scan_B2G[h]); + d = ((d << 1) & ctx->B2G[h]); j = j - 1; } while (d != 0 && j != 0); //printf("scan: d %" PRIu32 ", j %" PRIu32 "\n", d, j); /* (partial) match, move on to verification */ if (d != 0) { - COUNT(tctx->scan_stat_d0++); - //printf("output at pos %" PRIu32 ": ", pos); prt(buf + pos, ctx->scan_m); printf("\n"); + COUNT(tctx->stat_d0++); + //printf("output at pos %" PRIu32 ": ", pos); prt(buf + pos, ctx->m); printf("\n"); /* get our patterns from the hash */ - uint16_t h = B2G_HASH16(u8_tolower(buf[pos + ctx->scan_m - 2]),u8_tolower(buf[pos + ctx->scan_m - 1])); + uint16_t h = B2G_HASH16(u8_tolower(buf[pos + ctx->m - 2]),u8_tolower(buf[pos + ctx->m - 1])); - if (ctx->scan_bloom[h] != NULL) { - COUNT(tctx->scan_stat_pminlen_calls++); - COUNT(tctx->scan_stat_pminlen_total+=ctx->scan_pminlen[h]); + if (ctx->bloom[h] != NULL) { + COUNT(tctx->stat_pminlen_calls++); + COUNT(tctx->stat_pminlen_total+=ctx->pminlen[h]); - if ((buflen - pos) < ctx->scan_pminlen[h]) { + if ((buflen - pos) < ctx->pminlen[h]) { goto skip_loop; } else { - COUNT(tctx->scan_stat_bloom_calls++); + COUNT(tctx->stat_bloom_calls++); - if (BloomFilterTest(ctx->scan_bloom[h], buf+pos, ctx->scan_pminlen[h]) == 0) { - COUNT(tctx->scan_stat_bloom_hits++); + if (BloomFilterTest(ctx->bloom[h], buf+pos, ctx->pminlen[h]) == 0) { + COUNT(tctx->stat_bloom_hits++); - //printf("Bloom: %p, buflen %" PRIu32 ", pos %" PRIu32 ", p_min_len %" PRIu32 "\n", ctx->scan_bloom[h], buflen, pos, ctx->scan_pminlen[h]); + //printf("Bloom: %p, buflen %" PRIu32 ", pos %" PRIu32 ", p_min_len %" PRIu32 "\n", ctx->bloom[h], buflen, pos, ctx->pminlen[h]); goto skip_loop; } } } - B2gHashItem *hi = ctx->scan_hash[h], *thi; + B2gHashItem *hi = ctx->hash[h], *thi; for (thi = hi; thi != NULL; thi = thi->nxt) { - COUNT(tctx->scan_stat_d0_hashloop++); + COUNT(tctx->stat_d0_hashloop++); B2gPattern *p = ctx->parray[thi->idx]; if (p->flags & B2G_NOCASE) { @@ -1055,31 +1050,31 @@ uint32_t B2gScan(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQu continue; if (memcmp_lowercase(p->ci, buf+pos, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); matches += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, pos, p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } else { if (buflen - pos < p->len) continue; if (memcmp(p->cs, buf+pos, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); matches += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, pos, p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } } skip_loop: - //pos = pos + ctx->scan_s0; + //pos = pos + ctx->s0; pos = pos + 1; } else { - COUNT(tctx->scan_stat_num_shift++); - COUNT(tctx->scan_stat_total_shift += (j + 1)); + COUNT(tctx->stat_num_shift++); + COUNT(tctx->stat_total_shift += (j + 1)); pos = pos + j + 1; } @@ -1089,8 +1084,8 @@ skip_loop: return matches; } -#ifdef B2G_SCAN2 -uint32_t B2gScan2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +#ifdef B2G_SEARCH2 +uint32_t B2gSearch2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B2gCtx *ctx = (B2gCtx *)mpm_ctx->ctx; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; @@ -1106,7 +1101,7 @@ uint32_t B2gScan2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQ while (buf <= bufend) { uint8_t h8 = u8_tolower(*buf); - hi = &ctx->scan_hash1[h8]; + hi = &ctx->hash1[h8]; if (hi->flags & 0x01) { for (thi = hi; thi != NULL; thi = thi->nxt) { @@ -1126,7 +1121,7 @@ uint32_t B2gScan2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQ /* save one conversion by reusing h8 */ uint16_t h16 = B2G_HASH16(h8, u8_tolower(*(buf+1))); - hi = ctx->scan_hash2[h16]; + hi = ctx->hash2[h16]; for (thi = hi; thi != NULL; thi = thi->nxt) { p = ctx->parray[thi->idx]; @@ -1153,17 +1148,17 @@ uint32_t B2gScan2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQ } //printf("B2gSearch2: after 2byte cnt %" PRIu32 "\n", cnt); - if (ctx->scan_x_pat_cnt > 0) { + if (ctx->pat_x_cnt > 0) { /* Pass bufmin on because buf no longer points to the * start of the buffer. */ - cnt += ctx->MBScan(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); + cnt += ctx->MBSearch(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); //printf("B2gSearch1: after 2+byte cnt %" PRIu32 "\n", cnt); } return cnt; } #endif -uint32_t B2gScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t B2gSearch1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { SCEnter(); B2gCtx *ctx = (B2gCtx *)mpm_ctx->ctx; @@ -1180,7 +1175,7 @@ uint32_t B2gScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQ while (buf <= bufend) { uint8_t h = u8_tolower(*buf); - hi = &ctx->scan_hash1[h]; + hi = &ctx->hash1[h]; if (hi->flags & 0x01) { for (thi = hi; thi != NULL; thi = thi->nxt) { @@ -1204,16 +1199,16 @@ uint32_t B2gScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQ } //printf("B2gSearch1: after 1byte cnt %" PRIu32 "\n", cnt); -#ifdef B2G_SCAN2 - if (ctx->scan_2_pat_cnt) { +#ifdef B2G_SEARCH2 + if (ctx->pat_2_cnt) { /* Pass bufmin on because buf no longer points to the * start of the buffer. */ - cnt += ctx->MBScan2(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); + cnt += ctx->MBSearch2(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); //printf("B2gSearch1: after 2+byte cnt %" PRIu32 "\n", cnt); } else #endif - if (ctx->scan_x_pat_cnt) { - cnt += ctx->MBScan(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); + if (ctx->pat_x_cnt) { + cnt += ctx->MBSearch(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); } SCReturnUInt(cnt); } @@ -1230,14 +1225,14 @@ static int B2gTestInit01 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); - if (ctx->scan_m == 4) + if (ctx->m == 4) result = 1; else - printf("4 != %" PRIu32 " ", ctx->scan_m); + printf("4 != %" PRIu32 " ", ctx->m); B2gDestroyCtx(&mpm_ctx); return result; @@ -1250,14 +1245,14 @@ static int B2gTestS0Init01 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 4) + if (ctx->s0 == 4) result = 1; else - printf("4 != %" PRIu32 " ", ctx->scan_s0); + printf("4 != %" PRIu32 " ", ctx->s0); B2gDestroyCtx(&mpm_ctx); return result; @@ -1269,15 +1264,15 @@ static int B2gTestS0Init02 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"cdef", 4, 0, 0, 1, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"cdef", 4, 0, 0, 1, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 2) + if (ctx->s0 == 2) result = 1; else - printf("2 != %" PRIu32 " ", ctx->scan_s0); + printf("2 != %" PRIu32 " ", ctx->s0); B2gDestroyCtx(&mpm_ctx); return result; @@ -1289,15 +1284,15 @@ static int B2gTestS0Init03 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 1) + if (ctx->s0 == 1) result = 1; else - printf("1 != %" PRIu32 " ", ctx->scan_s0); + printf("1 != %" PRIu32 " ", ctx->s0); B2gDestroyCtx(&mpm_ctx); return result; @@ -1309,14 +1304,14 @@ static int B2gTestS0Init04 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abab", 4, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abab", 4, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 2) + if (ctx->s0 == 2) result = 1; else - printf("2 != %" PRIu32 " ", ctx->scan_s0); + printf("2 != %" PRIu32 " ", ctx->s0); B2gDestroyCtx(&mpm_ctx); return result; @@ -1328,21 +1323,21 @@ static int B2gTestS0Init05 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcab", 5, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcab", 5, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 3) + if (ctx->s0 == 3) result = 1; else - printf("3 != %" PRIu32 " ", ctx->scan_s0); + printf("3 != %" PRIu32 " ", ctx->s0); B2gDestroyCtx(&mpm_ctx); return result; } #endif -static int B2gTestScan01 (void) { +static int B2gTestSearch01 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1350,12 +1345,12 @@ static int B2gTestScan01 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 1) result = 1; @@ -1367,7 +1362,7 @@ static int B2gTestScan01 (void) { return result; } -static int B2gTestScan02 (void) { +static int B2gTestSearch02 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1375,12 +1370,12 @@ static int B2gTestScan02 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abce", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abce", 4, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 0) result = 1; @@ -1392,7 +1387,7 @@ static int B2gTestScan02 (void) { return result; } -static int B2gTestScan03 (void) { +static int B2gTestSearch03 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1400,14 +1395,14 @@ static int B2gTestScan03 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0, 0); /* 1 match */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"fghj", 4, 0, 0, 2, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"fghj", 4, 0, 0, 2, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3 /* 3 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 3) result = 1; @@ -1420,7 +1415,7 @@ static int B2gTestScan03 (void) { } /* test patterns longer than 'm'. M is 4 here. */ -static int B2gTestScan04 (void) { +static int B2gTestSearch04 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1428,14 +1423,14 @@ static int B2gTestScan04 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"bcdegh", 6, 0, 0, 1, 0, 0); /* 1 match */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"fghjxyz", 7, 0, 0, 2, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"bcdegh", 6, 0, 0, 1, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"fghjxyz", 7, 0, 0, 2, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3 /* 3 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 1) result = 1; @@ -1448,7 +1443,7 @@ static int B2gTestScan04 (void) { } /* case insensitive test patterns longer than 'm'. M is 4 here. */ -static int B2gTestScan05 (void) { +static int B2gTestSearch05 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1456,14 +1451,14 @@ static int B2gTestScan05 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0); /* 1 match */ - B2gAddScanPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0); /* 1 match */ - B2gAddScanPatternCI(&mpm_ctx, (uint8_t *)"fghJikl", 7, 0, 0, 2, 0, 0); /* 1 match */ + B2gAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0); /* 1 match */ + B2gAddPatternCI(&mpm_ctx, (uint8_t *)"fghJikl", 7, 0, 0, 2, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3 /* 3 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 3) result = 1; @@ -1475,7 +1470,7 @@ static int B2gTestScan05 (void) { return result; } -static int B2gTestScan06 (void) { +static int B2gTestSearch06 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1483,12 +1478,12 @@ static int B2gTestScan06 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); if (cnt == 1) result = 1; @@ -1500,7 +1495,7 @@ static int B2gTestScan06 (void) { return result; } -static int B2gTestScan07 (void) { +static int B2gTestSearch07 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1508,18 +1503,18 @@ static int B2gTestScan07 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ /* total matches: 135 */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 6 /* 6 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); if (cnt == 135) result = 1; @@ -1531,7 +1526,7 @@ static int B2gTestScan07 (void) { return result; } -static int B2gTestScan08 (void) { +static int B2gTestSearch08 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1539,12 +1534,12 @@ static int B2gTestScan08 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"a", 1); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"a", 1); if (cnt == 0) result = 1; @@ -1556,7 +1551,7 @@ static int B2gTestScan08 (void) { return result; } -static int B2gTestScan09 (void) { +static int B2gTestSearch09 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1564,12 +1559,12 @@ static int B2gTestScan09 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"ab", 2, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"ab", 2, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"ab", 2); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"ab", 2); if (cnt == 1) result = 1; @@ -1581,7 +1576,7 @@ static int B2gTestScan09 (void) { return result; } -static int B2gTestScan10 (void) { +static int B2gTestSearch10 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1589,7 +1584,7 @@ static int B2gTestScan10 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcdefgh", 8, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefgh", 8, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); @@ -1599,7 +1594,7 @@ static int B2gTestScan10 (void) { "abcdefgh" "01234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456789"; - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)buf, strlen(buf)); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)buf, strlen(buf)); if (cnt == 1) result = 1; @@ -1611,7 +1606,7 @@ static int B2gTestScan10 (void) { return result; } -static int B2gTestScan11 (void) { +static int B2gTestSearch11 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1619,13 +1614,13 @@ static int B2gTestScan11 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcde", 5, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcde", 5, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2 /* 2 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyz", 26); if (cnt == 2) result = 1; @@ -1637,7 +1632,7 @@ static int B2gTestScan11 (void) { return result; } -static int B2gTestScan12 (void) { +static int B2gTestSearch12 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1645,13 +1640,13 @@ static int B2gTestScan12 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"wxyz", 4, 0, 0, 0, 0, 0); /* 1 match */ - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"vwxyz", 5, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"wxyz", 4, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"vwxyz", 5, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2 /* 2 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyz", 26); if (cnt == 2) result = 1; @@ -1663,7 +1658,7 @@ static int B2gTestScan12 (void) { return result; } -static int B2gTestScan13 (void) { +static int B2gTestSearch13 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1671,12 +1666,12 @@ static int B2gTestScan13 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCD", 30, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCD", 30, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCD", 30); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCD", 30); if (cnt == 1) result = 1; @@ -1688,7 +1683,7 @@ static int B2gTestScan13 (void) { return result; } -static int B2gTestScan14 (void) { +static int B2gTestSearch14 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1696,12 +1691,12 @@ static int B2gTestScan14 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCDE", 31, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCDE", 31, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCDE", 31); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCDE", 31); if (cnt == 1) result = 1; @@ -1713,7 +1708,7 @@ static int B2gTestScan14 (void) { return result; } -static int B2gTestScan15 (void) { +static int B2gTestSearch15 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1721,12 +1716,12 @@ static int B2gTestScan15 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCDEF", 32, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCDEF", 32, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCDEF", 32); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABCDEF", 32); if (cnt == 1) result = 1; @@ -1738,7 +1733,7 @@ static int B2gTestScan15 (void) { return result; } -static int B2gTestScan16 (void) { +static int B2gTestSearch16 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1746,12 +1741,12 @@ static int B2gTestScan16 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABC", 29, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABC", 29, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABC", 29); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzABC", 29); if (cnt == 1) result = 1; @@ -1763,7 +1758,7 @@ static int B2gTestScan16 (void) { return result; } -static int B2gTestScan17 (void) { +static int B2gTestSearch17 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1771,12 +1766,12 @@ static int B2gTestScan17 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzAB", 28, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefghijklmnopqrstuvwxyzAB", 28, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzAB", 28); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghijklmnopqrstuvwxyzAB", 28); if (cnt == 1) result = 1; @@ -1788,7 +1783,7 @@ static int B2gTestScan17 (void) { return result; } -static int B2gTestScan18 (void) { +static int B2gTestSearch18 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1796,12 +1791,12 @@ static int B2gTestScan18 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcde""fghij""klmno""pqrst""uvwxy""z", 26, 0, 0, 0, 0, 0); /* 1 match */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"abcde""fghij""klmno""pqrst""uvwxy""z", 26, 0, 0, 0, 0, 0); /* 1 match */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcde""fghij""klmno""pqrst""uvwxy""z", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcde""fghij""klmno""pqrst""uvwxy""z", 26); if (cnt == 1) result = 1; @@ -1813,7 +1808,7 @@ static int B2gTestScan18 (void) { return result; } -static int B2gTestScan19 (void) { +static int B2gTestSearch19 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1821,12 +1816,12 @@ static int B2gTestScan19 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 0, 0, 0); /* 1 */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 0, 0, 0); /* 1 */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); if (cnt == 1) result = 1; @@ -1838,7 +1833,7 @@ static int B2gTestScan19 (void) { return result; } -static int B2gTestScan20 (void) { +static int B2gTestSearch20 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1846,14 +1841,14 @@ static int B2gTestScan20 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA", 32, 0, 0, 0, 0, 0); /* 1 */ - //B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 32, 0, 0, 0, 0, 0); /* 1 */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA", 32, 0, 0, 0, 0, 0); /* 1 */ + //B2gAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 32, 0, 0, 0, 0, 0); /* 1 */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 patterns */); - //uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 32); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA", 32); + //uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 32); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA", 32); if (cnt == 1) result = 1; @@ -1865,7 +1860,7 @@ static int B2gTestScan20 (void) { return result; } -static int B2gTestScan21 (void) { +static int B2gTestSearch21 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1873,12 +1868,12 @@ static int B2gTestScan21 (void) { MpmInitCtx(&mpm_ctx, MPM_B2G, -1); B2gCtx *ctx = (B2gCtx *)mpm_ctx.ctx; - B2gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0); /* 1 */ + B2gAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0); /* 1 */ B2gPreparePatterns(&mpm_ctx); B2gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AA", 2); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AA", 2); if (cnt == 1) result = 1; @@ -1901,27 +1896,27 @@ void B2gRegisterTests(void) { UtRegisterTest("B2gTestS0Init04", B2gTestS0Init04, 1); UtRegisterTest("B2gTestS0Init05", B2gTestS0Init05, 1); */ - UtRegisterTest("B2gTestScan01", B2gTestScan01, 1); - UtRegisterTest("B2gTestScan02", B2gTestScan02, 1); - UtRegisterTest("B2gTestScan03", B2gTestScan03, 1); - UtRegisterTest("B2gTestScan04", B2gTestScan04, 1); - UtRegisterTest("B2gTestScan05", B2gTestScan05, 1); - UtRegisterTest("B2gTestScan06", B2gTestScan06, 1); - UtRegisterTest("B2gTestScan07", B2gTestScan07, 1); - UtRegisterTest("B2gTestScan08", B2gTestScan08, 1); - UtRegisterTest("B2gTestScan09", B2gTestScan09, 1); - UtRegisterTest("B2gTestScan10", B2gTestScan10, 1); - UtRegisterTest("B2gTestScan11", B2gTestScan11, 1); - UtRegisterTest("B2gTestScan12", B2gTestScan12, 1); - UtRegisterTest("B2gTestScan13", B2gTestScan13, 1); - UtRegisterTest("B2gTestScan14", B2gTestScan14, 1); - UtRegisterTest("B2gTestScan15", B2gTestScan15, 1); - UtRegisterTest("B2gTestScan16", B2gTestScan16, 1); - UtRegisterTest("B2gTestScan17", B2gTestScan17, 1); - UtRegisterTest("B2gTestScan18", B2gTestScan18, 1); - UtRegisterTest("B2gTestScan19", B2gTestScan19, 1); - UtRegisterTest("B2gTestScan20", B2gTestScan20, 1); - UtRegisterTest("B2gTestScan21", B2gTestScan21, 1); + UtRegisterTest("B2gTestSearch01", B2gTestSearch01, 1); + UtRegisterTest("B2gTestSearch02", B2gTestSearch02, 1); + UtRegisterTest("B2gTestSearch03", B2gTestSearch03, 1); + UtRegisterTest("B2gTestSearch04", B2gTestSearch04, 1); + UtRegisterTest("B2gTestSearch05", B2gTestSearch05, 1); + UtRegisterTest("B2gTestSearch06", B2gTestSearch06, 1); + UtRegisterTest("B2gTestSearch07", B2gTestSearch07, 1); + UtRegisterTest("B2gTestSearch08", B2gTestSearch08, 1); + UtRegisterTest("B2gTestSearch09", B2gTestSearch09, 1); + UtRegisterTest("B2gTestSearch10", B2gTestSearch10, 1); + UtRegisterTest("B2gTestSearch11", B2gTestSearch11, 1); + UtRegisterTest("B2gTestSearch12", B2gTestSearch12, 1); + UtRegisterTest("B2gTestSearch13", B2gTestSearch13, 1); + UtRegisterTest("B2gTestSearch14", B2gTestSearch14, 1); + UtRegisterTest("B2gTestSearch15", B2gTestSearch15, 1); + UtRegisterTest("B2gTestSearch16", B2gTestSearch16, 1); + UtRegisterTest("B2gTestSearch17", B2gTestSearch17, 1); + UtRegisterTest("B2gTestSearch18", B2gTestSearch18, 1); + UtRegisterTest("B2gTestSearch19", B2gTestSearch19, 1); + UtRegisterTest("B2gTestSearch20", B2gTestSearch20, 1); + UtRegisterTest("B2gTestSearch21", B2gTestSearch21, 1); #endif /* UNITTESTS */ } diff --git a/src/util-mpm-b2g.h b/src/util-mpm-b2g.h index a9b97d1314..e7282c35b7 100644 --- a/src/util-mpm-b2g.h +++ b/src/util-mpm-b2g.h @@ -25,10 +25,10 @@ #define B2G_HASH16(a,b) (((a)<pattern_cnt); - printf("Scan Patterns: %" PRIu32 "\n", mpm_ctx->scan_pattern_cnt); + printf("Scan Patterns: %" PRIu32 "\n", mpm_ctx->pattern_cnt); printf("Total Patterns: %" PRIu32 "\n", mpm_ctx->total_pattern_cnt); - printf("Smallest: %" PRIu32 "\n", mpm_ctx->scan_minlen); - printf("Largest: %" PRIu32 "\n", mpm_ctx->scan_maxlen); - printf("Hash size: %" PRIu32 "\n", ctx->scan_hash_size); + printf("Smallest: %" PRIu32 "\n", mpm_ctx->minlen); + printf("Largest: %" PRIu32 "\n", mpm_ctx->maxlen); + printf("Hash size: %" PRIu32 "\n", ctx->hash_size); printf("\n"); } @@ -352,19 +349,18 @@ static inline int B3gAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, printf("Max search words reached\n"); exit(1); } - if (scan) mpm_ctx->scan_pattern_cnt++; mpm_ctx->pattern_cnt++; - if (mpm_ctx->scan_maxlen < patlen) mpm_ctx->scan_maxlen = patlen; - if (mpm_ctx->scan_minlen == 0) mpm_ctx->scan_minlen = patlen; - else if (mpm_ctx->scan_minlen > patlen) mpm_ctx->scan_minlen = patlen; + if (mpm_ctx->maxlen < patlen) mpm_ctx->maxlen = patlen; + if (mpm_ctx->minlen == 0) mpm_ctx->minlen = patlen; + else if (mpm_ctx->minlen > patlen) mpm_ctx->minlen = patlen; } else { /* if we're reusing a pattern, check we need to check that it is a * scan pattern if that is what we're adding. If so we set the pattern * to be a scan pattern. */ - if (mpm_ctx->scan_maxlen < patlen) mpm_ctx->scan_maxlen = patlen; - if (mpm_ctx->scan_minlen == 0) mpm_ctx->scan_minlen = patlen; - else if (mpm_ctx->scan_minlen > patlen) mpm_ctx->scan_minlen = patlen; + if (mpm_ctx->maxlen < patlen) mpm_ctx->maxlen = patlen; + if (mpm_ctx->minlen == 0) mpm_ctx->minlen = patlen; + else if (mpm_ctx->minlen > patlen) mpm_ctx->minlen = patlen; } /* we need a match */ @@ -378,13 +374,13 @@ error: return -1; } -int B3gAddScanPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, +int B3gAddPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, uint32_t sid, uint8_t nosearch) { return B3gAddPattern(mpm_ctx, pat, patlen, offset, depth, /* nocase */1, /* scan */1, pid, sid, nosearch); } -int B3gAddScanPatternCS(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, +int B3gAddPatternCS(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, uint32_t sid, uint8_t nosearch) { return B3gAddPattern(mpm_ctx, pat, patlen, offset, depth, /* nocase */0, /* scan */1, pid, sid, nosearch); @@ -405,127 +401,127 @@ static uint32_t B3gBloomHash(void *data, uint16_t datalen, uint8_t iter, uint32_ return hash; } -static void B3gPrepareScanHash(MpmCtx *mpm_ctx) { +static void B3gPrepareHash(MpmCtx *mpm_ctx) { B3gCtx *ctx = (B3gCtx *)mpm_ctx->ctx; uint16_t i; uint16_t idx = 0; uint8_t idx8 = 0; - ctx->scan_hash = (B3gHashItem **)SCMalloc(sizeof(B3gHashItem *) * ctx->scan_hash_size); - if (ctx->scan_hash == NULL) goto error; - memset(ctx->scan_hash, 0, sizeof(B3gHashItem *) * ctx->scan_hash_size); + ctx->hash = (B3gHashItem **)SCMalloc(sizeof(B3gHashItem *) * ctx->hash_size); + if (ctx->hash == NULL) goto error; + memset(ctx->hash, 0, sizeof(B3gHashItem *) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(B3gHashItem *) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(B3gHashItem *) * ctx->hash_size); /* 2 byte pattern hash */ - ctx->scan_hash2 = (B3gHashItem **)SCMalloc(sizeof(B3gHashItem *) * ctx->scan_hash_size); - if (ctx->scan_hash2 == NULL) goto error; - memset(ctx->scan_hash2, 0, sizeof(B3gHashItem *) * ctx->scan_hash_size); + ctx->hash2 = (B3gHashItem **)SCMalloc(sizeof(B3gHashItem *) * ctx->hash_size); + if (ctx->hash2 == NULL) goto error; + memset(ctx->hash2, 0, sizeof(B3gHashItem *) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(B3gHashItem *) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(B3gHashItem *) * ctx->hash_size); /* alloc the pminlen array */ - ctx->scan_pminlen = (uint8_t *)SCMalloc(sizeof(uint8_t) * ctx->scan_hash_size); - if (ctx->scan_pminlen == NULL) goto error; - memset(ctx->scan_pminlen, 0, sizeof(uint8_t) * ctx->scan_hash_size); + ctx->pminlen = (uint8_t *)SCMalloc(sizeof(uint8_t) * ctx->hash_size); + if (ctx->pminlen == NULL) goto error; + memset(ctx->pminlen, 0, sizeof(uint8_t) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(uint8_t) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(uint8_t) * ctx->hash_size); for (i = 0; i < mpm_ctx->pattern_cnt; i++) { if(ctx->parray[i]->len == 1) { idx8 = (uint8_t)ctx->parray[i]->ci[0]; - if (ctx->scan_hash1[idx8].flags == 0) { - ctx->scan_hash1[idx8].idx = i; - ctx->scan_hash1[idx8].flags |= 0x01; + if (ctx->hash1[idx8].flags == 0) { + ctx->hash1[idx8].idx = i; + ctx->hash1[idx8].flags |= 0x01; } else { B3gHashItem *hi = B3gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; /* Append this HashItem to the list */ - B3gHashItem *thi = &ctx->scan_hash1[idx8]; + B3gHashItem *thi = &ctx->hash1[idx8]; while (thi->nxt) thi = thi->nxt; thi->nxt = hi; } - ctx->scan_1_pat_cnt++; + ctx->pat_1_cnt++; } else if(ctx->parray[i]->len == 2) { idx = (uint16_t)(ctx->parray[i]->ci[0] << B3G_HASHSHIFT | ctx->parray[i]->ci[1]); - if (ctx->scan_hash2[idx] == NULL) { + if (ctx->hash2[idx] == NULL) { B3gHashItem *hi = B3gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; - ctx->scan_hash2[idx] = hi; + ctx->hash2[idx] = hi; } else { B3gHashItem *hi = B3gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; /* Append this HashItem to the list */ - B3gHashItem *thi = ctx->scan_hash2[idx]; + B3gHashItem *thi = ctx->hash2[idx]; while (thi->nxt) thi = thi->nxt; thi->nxt = hi; } - ctx->scan_2_pat_cnt++; + ctx->pat_2_cnt++; } else { - idx = B3G_HASH(ctx->parray[i]->ci[ctx->scan_m - 3], ctx->parray[i]->ci[ctx->scan_m - 2], ctx->parray[i]->ci[ctx->scan_m - 1]); - //printf("idx %" PRIu32 ", %c.%c.%c\n", idx, ctx->parray[i]->ci[ctx->scan_m - 3], ctx->parray[i]->ci[ctx->scan_m - 2], ctx->parray[i]->ci[ctx->scan_m - 1]); + idx = B3G_HASH(ctx->parray[i]->ci[ctx->m - 3], ctx->parray[i]->ci[ctx->m - 2], ctx->parray[i]->ci[ctx->m - 1]); + //printf("idx %" PRIu32 ", %c.%c.%c\n", idx, ctx->parray[i]->ci[ctx->m - 3], ctx->parray[i]->ci[ctx->m - 2], ctx->parray[i]->ci[ctx->m - 1]); - if (ctx->scan_hash[idx] == NULL) { + if (ctx->hash[idx] == NULL) { B3gHashItem *hi = B3gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; - ctx->scan_pminlen[idx] = ctx->parray[i]->len; + ctx->pminlen[idx] = ctx->parray[i]->len; - ctx->scan_hash[idx] = hi; + ctx->hash[idx] = hi; } else { B3gHashItem *hi = B3gAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; - if (ctx->parray[i]->len < ctx->scan_pminlen[idx]) - ctx->scan_pminlen[idx] = ctx->parray[i]->len; + if (ctx->parray[i]->len < ctx->pminlen[idx]) + ctx->pminlen[idx] = ctx->parray[i]->len; /* Append this HashItem to the list */ - B3gHashItem *thi = ctx->scan_hash[idx]; + B3gHashItem *thi = ctx->hash[idx]; while (thi->nxt) thi = thi->nxt; thi->nxt = hi; } - ctx->scan_x_pat_cnt++; + ctx->pat_x_cnt++; } } /* alloc the bloom array */ - ctx->scan_bloom = (BloomFilter **)SCMalloc(sizeof(BloomFilter *) * ctx->scan_hash_size); - if (ctx->scan_bloom == NULL) goto error; - memset(ctx->scan_bloom, 0, sizeof(BloomFilter *) * ctx->scan_hash_size); + ctx->bloom = (BloomFilter **)SCMalloc(sizeof(BloomFilter *) * ctx->hash_size); + if (ctx->bloom == NULL) goto error; + memset(ctx->bloom, 0, sizeof(BloomFilter *) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(BloomFilter *) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(BloomFilter *) * ctx->hash_size); uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - B3gHashItem *hi = ctx->scan_hash[h]; + for (h = 0; h < ctx->hash_size; h++) { + B3gHashItem *hi = ctx->hash[h]; if (hi == NULL) continue; - ctx->scan_bloom[h] = BloomFilterInit(b3g_bloom_size, 2, B3gBloomHash); - if (ctx->scan_bloom[h] == NULL) + ctx->bloom[h] = BloomFilterInit(b3g_bloom_size, 2, B3gBloomHash); + if (ctx->bloom[h] == NULL) continue; - mpm_ctx->memory_cnt += BloomFilterMemoryCnt(ctx->scan_bloom[h]); - mpm_ctx->memory_size += BloomFilterMemorySize(ctx->scan_bloom[h]); + mpm_ctx->memory_cnt += BloomFilterMemoryCnt(ctx->bloom[h]); + mpm_ctx->memory_size += BloomFilterMemorySize(ctx->bloom[h]); - if (ctx->scan_pminlen[h] > 8) - ctx->scan_pminlen[h] = 8; + if (ctx->pminlen[h] > 8) + ctx->pminlen[h] = 8; B3gHashItem *thi = hi; do { - BloomFilterAdd(ctx->scan_bloom[h], ctx->parray[thi->idx]->ci, ctx->scan_pminlen[h]); + BloomFilterAdd(ctx->bloom[h], ctx->parray[thi->idx]->ci, ctx->pminlen[h]); thi = thi->nxt; } while (thi != NULL); } @@ -535,34 +531,34 @@ error: return; } -int B3gBuildScanMatchArray(MpmCtx *mpm_ctx) { +int B3gBuildMatchArray(MpmCtx *mpm_ctx) { B3gCtx *ctx = (B3gCtx *)mpm_ctx->ctx; - ctx->scan_B3G = SCMalloc(sizeof(B3G_TYPE) * ctx->scan_hash_size); - if (ctx->scan_B3G == NULL) + ctx->B3G = SCMalloc(sizeof(B3G_TYPE) * ctx->hash_size); + if (ctx->B3G == NULL) return -1; mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(B3G_TYPE) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(B3G_TYPE) * ctx->hash_size); - memset(ctx->scan_B3G,0, b3g_hash_size * sizeof(B3G_TYPE)); + memset(ctx->B3G,0, b3g_hash_size * sizeof(B3G_TYPE)); uint32_t j; uint32_t a; /* fill the match array */ - for (j = 0; j <= (ctx->scan_m - B3G_Q); j++) { + for (j = 0; j <= (ctx->m - B3G_Q); j++) { for (a = 0; a < mpm_ctx->pattern_cnt; a++) { - if (ctx->parray[a]->len < ctx->scan_m) + if (ctx->parray[a]->len < ctx->m) continue; uint16_t h = B3G_HASH(u8_tolower(ctx->parray[a]->ci[j]),u8_tolower(ctx->parray[a]->ci[j+1]), u8_tolower(ctx->parray[a]->ci[j+2])); -//printf("B3gBuildScanMatchArray: h %" PRIu32 ", %c.%c.%c\n", h, u8_tolower(ctx->parray[a]->ci[j]),u8_tolower(ctx->parray[a]->ci[j+1]), u8_tolower(ctx->parray[a]->ci[j+2])); - ctx->scan_B3G[h] = ctx->scan_B3G[h] | (1 << (ctx->scan_m - j)); +//printf("B3gBuildMatchArray: h %" PRIu32 ", %c.%c.%c\n", h, u8_tolower(ctx->parray[a]->ci[j]),u8_tolower(ctx->parray[a]->ci[j+1]), u8_tolower(ctx->parray[a]->ci[j+2])); + ctx->B3G[h] = ctx->B3G[h] | (1 << (ctx->m - j)); } } - ctx->scan_s0 = 1; + ctx->s0 = 1; return 0; } @@ -596,30 +592,30 @@ int B3gPreparePatterns(MpmCtx *mpm_ctx) { ctx->init_hash = NULL; /* set 'm' to the smallest pattern size */ - ctx->scan_m = mpm_ctx->scan_minlen; + ctx->m = mpm_ctx->minlen; /* make sure 'm' stays in bounds m can be max WORD_SIZE - 1 */ - if (ctx->scan_m >= B3G_WORD_SIZE) { - ctx->scan_m = B3G_WORD_SIZE - 1; + if (ctx->m >= B3G_WORD_SIZE) { + ctx->m = B3G_WORD_SIZE - 1; } - if (ctx->scan_m < 3) ctx->scan_m = 3; + if (ctx->m < 3) ctx->m = 3; - ctx->scan_hash_size = b3g_hash_size; - B3gPrepareScanHash(mpm_ctx); - B3gBuildScanMatchArray(mpm_ctx); + ctx->hash_size = b3g_hash_size; + B3gPrepareHash(mpm_ctx); + B3gBuildMatchArray(mpm_ctx); - if (ctx->scan_1_pat_cnt) { - ctx->Scan = B3gScan1; - if (ctx->scan_2_pat_cnt) { - ctx->Scan = B3gScan12; - ctx->MBScan = b3g_scan_func; + if (ctx->pat_1_cnt) { + ctx->Search = B3gSearch1; + if (ctx->pat_2_cnt) { + ctx->Search = B3gSearch12; + ctx->MBSearch = b3g_func; } - ctx->MBScan = b3g_scan_func; - } else if (ctx->scan_2_pat_cnt) { - ctx->Scan = B3gScan2; - ctx->MBScan = b3g_scan_func; + ctx->MBSearch = b3g_func; + } else if (ctx->pat_2_cnt) { + ctx->Search = B3gSearch2; + ctx->MBSearch = b3g_func; } @@ -633,19 +629,18 @@ void B3gPrintSearchStats(MpmThreadCtx *mpm_thread_ctx) { B3gThreadCtx *tctx = (B3gThreadCtx *)mpm_thread_ctx->ctx; printf("B3g Thread Search stats (tctx %p)\n", tctx); - printf("Scan phase:\n"); - printf("Total calls/scans: %" PRIu32 "\n", tctx->scan_stat_calls); - printf("Avg m/scan: %0.2f\n", tctx->scan_stat_calls ? (float)((float)tctx->scan_stat_m_total / (float)tctx->scan_stat_calls) : 0); - printf("D != 0 (possible match): %" PRIu32 "\n", tctx->scan_stat_d0); - printf("Avg hash items per bucket %0.2f (%" PRIu32 ")\n", tctx->scan_stat_d0 ? (float)((float)tctx->scan_stat_d0_hashloop / (float)tctx->scan_stat_d0) : 0, tctx->scan_stat_d0_hashloop); - printf("Loop match: %" PRIu32 "\n", tctx->scan_stat_loop_match); - printf("Loop no match: %" PRIu32 "\n", tctx->scan_stat_loop_no_match); - printf("Num shifts: %" PRIu32 "\n", tctx->scan_stat_num_shift); - printf("Total shifts: %" PRIu32 "\n", tctx->scan_stat_total_shift); - printf("Avg shifts: %0.2f\n", tctx->scan_stat_num_shift ? (float)((float)tctx->scan_stat_total_shift / (float)tctx->scan_stat_num_shift) : 0); - printf("Total BloomFilter checks: %" PRIu32 "\n", tctx->scan_stat_bloom_calls); - printf("BloomFilter hits: %0.4f%% (%" PRIu32 ")\n", tctx->scan_stat_bloom_calls ? (float)((float)((float)tctx->scan_stat_bloom_hits / (float)tctx->scan_stat_bloom_calls)*(float)100) : 0, tctx->scan_stat_bloom_hits); - printf("Avg pminlen: %0.2f\n\n", tctx->scan_stat_pminlen_calls ? (float)((float)tctx->scan_stat_pminlen_total / (float)tctx->scan_stat_pminlen_calls) : 0); + printf("Total calls/scans: %" PRIu32 "\n", tctx->stat_calls); + printf("Avg m/scan: %0.2f\n", tctx->stat_calls ? (float)((float)tctx->stat_m_total / (float)tctx->stat_calls) : 0); + printf("D != 0 (possible match): %" PRIu32 "\n", tctx->stat_d0); + printf("Avg hash items per bucket %0.2f (%" PRIu32 ")\n", tctx->stat_d0 ? (float)((float)tctx->stat_d0_hashloop / (float)tctx->stat_d0) : 0, tctx->stat_d0_hashloop); + printf("Loop match: %" PRIu32 "\n", tctx->stat_loop_match); + printf("Loop no match: %" PRIu32 "\n", tctx->stat_loop_no_match); + printf("Num shifts: %" PRIu32 "\n", tctx->stat_num_shift); + printf("Total shifts: %" PRIu32 "\n", tctx->stat_total_shift); + printf("Avg shifts: %0.2f\n", tctx->stat_num_shift ? (float)((float)tctx->stat_total_shift / (float)tctx->stat_num_shift) : 0); + printf("Total BloomFilter checks: %" PRIu32 "\n", tctx->stat_bloom_calls); + printf("BloomFilter hits: %0.4f%% (%" PRIu32 ")\n", tctx->stat_bloom_calls ? (float)((float)((float)tctx->stat_bloom_hits / (float)tctx->stat_bloom_calls)*(float)100) : 0, tctx->stat_bloom_hits); + printf("Avg pminlen: %0.2f\n\n", tctx->stat_pminlen_calls ? (float)((float)tctx->stat_pminlen_total / (float)tctx->stat_pminlen_calls) : 0); #endif /* B3G_COUNTERS */ } @@ -673,12 +668,12 @@ void B3gGetConfig() ConfNode *b3g_conf; const char *hash_val = NULL; const char *bloom_val = NULL; - const char *scan_algo = NULL; + const char *algo = NULL; /* init defaults */ b3g_hash_size = HASHSIZE_LOW; b3g_bloom_size = BLOOMSIZE_MEDIUM; - b3g_scan_func = B3G_SCANFUNC; + b3g_func = B3G_SEARCHFUNC; ConfNode *pm = ConfGetNode("pattern-matcher"); @@ -686,18 +681,18 @@ void B3gGetConfig() TAILQ_FOREACH(b3g_conf, &pm->head, next) { if (strncmp(b3g_conf->val, "b3g", 3) == 0) { - scan_algo = ConfNodeLookupChildValue(b3g_conf->head.tqh_first, - "scan_algo"); + algo = ConfNodeLookupChildValue(b3g_conf->head.tqh_first, + "algo"); hash_val = ConfNodeLookupChildValue(b3g_conf->head.tqh_first, "hash_size"); bloom_val = ConfNodeLookupChildValue(b3g_conf->head.tqh_first, "bf_size"); - if (scan_algo != NULL) { - if (strcmp(scan_algo, "B3gScan") == 0) { - b3g_scan_func = B3gScan; - } else if (strcmp(scan_algo, "B3gScanBNDMq") == 0) { - b3g_scan_func = B3gScanBNDMq; + if (algo != NULL) { + if (strcmp(algo, "B3gSearch") == 0) { + b3g_func = B3gSearch; + } else if (strcmp(algo, "B3gSearchBNDMq") == 0) { + b3g_func = B3gSearchBNDMq; } } @@ -740,7 +735,7 @@ void B3gInitCtx (MpmCtx *mpm_ctx, int module_handle) { B3gGetConfig(); /* init default */ - ctx->Scan = b3g_scan_func; + ctx->Search = b3g_func; } void B3gDestroyCtx(MpmCtx *mpm_ctx) { @@ -767,61 +762,61 @@ void B3gDestroyCtx(MpmCtx *mpm_ctx) { mpm_ctx->memory_size -= (mpm_ctx->pattern_cnt * sizeof(B3gPattern)); } - if (ctx->scan_B3G) { - SCFree(ctx->scan_B3G); + if (ctx->B3G) { + SCFree(ctx->B3G); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(B3G_TYPE) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(B3G_TYPE) * ctx->hash_size); } - if (ctx->scan_bloom) { + if (ctx->bloom) { uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - if (ctx->scan_bloom[h] == NULL) + for (h = 0; h < ctx->hash_size; h++) { + if (ctx->bloom[h] == NULL) continue; - mpm_ctx->memory_cnt -= BloomFilterMemoryCnt(ctx->scan_bloom[h]); - mpm_ctx->memory_size -= BloomFilterMemorySize(ctx->scan_bloom[h]); + mpm_ctx->memory_cnt -= BloomFilterMemoryCnt(ctx->bloom[h]); + mpm_ctx->memory_size -= BloomFilterMemorySize(ctx->bloom[h]); - BloomFilterFree(ctx->scan_bloom[h]); + BloomFilterFree(ctx->bloom[h]); } - SCFree(ctx->scan_bloom); + SCFree(ctx->bloom); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(BloomFilter *) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(BloomFilter *) * ctx->hash_size); } - if (ctx->scan_hash) { + if (ctx->hash) { uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - if (ctx->scan_hash[h] == NULL) + for (h = 0; h < ctx->hash_size; h++) { + if (ctx->hash[h] == NULL) continue; - B3gHashFree(mpm_ctx, ctx->scan_hash[h]); + B3gHashFree(mpm_ctx, ctx->hash[h]); } - SCFree(ctx->scan_hash); + SCFree(ctx->hash); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(B3gHashItem) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(B3gHashItem) * ctx->hash_size); } - if (ctx->scan_hash2) { + if (ctx->hash2) { uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - if (ctx->scan_hash2[h] == NULL) + for (h = 0; h < ctx->hash_size; h++) { + if (ctx->hash2[h] == NULL) continue; - B3gHashFree(mpm_ctx, ctx->scan_hash2[h]); + B3gHashFree(mpm_ctx, ctx->hash2[h]); } - SCFree(ctx->scan_hash2); + SCFree(ctx->hash2); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(B3gHashItem) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(B3gHashItem) * ctx->hash_size); } - if (ctx->scan_pminlen) { - SCFree(ctx->scan_pminlen); + if (ctx->pminlen) { + SCFree(ctx->pminlen); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(uint8_t) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(uint8_t) * ctx->hash_size); } SCFree(mpm_ctx->ctx); @@ -856,63 +851,63 @@ void B3gThreadDestroyCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx) { } } -inline uint32_t B3gScanWrap(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +inline uint32_t B3gSearchWrap(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B3gCtx *ctx = (B3gCtx *)mpm_ctx->ctx; - return ctx->Scan(mpm_ctx, mpm_thread_ctx, pmq, buf, buflen); + return ctx->Search(mpm_ctx, mpm_thread_ctx, pmq, buf, buflen); } -uint32_t B3gScanBNDMq(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t B3gSearchBNDMq(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B3gCtx *ctx = (B3gCtx *)mpm_ctx->ctx; #ifdef B3G_COUNTERS B3gThreadCtx *tctx = (B3gThreadCtx *)mpm_thread_ctx->ctx; #endif - uint32_t pos = ctx->scan_m - B3G_Q + 1, matches = 0; + uint32_t pos = ctx->m - B3G_Q + 1, matches = 0; B3G_TYPE d; - COUNT(tctx->scan_stat_calls++); - COUNT(tctx->scan_stat_m_total+=ctx->scan_m); + COUNT(tctx->stat_calls++); + COUNT(tctx->stat_m_total+=ctx->m); - if (buflen < ctx->scan_m) + if (buflen < ctx->m) return 0; while (pos <= (uint32_t)(buflen - B3G_Q + 1)) { uint16_t h = B3G_HASH(u8_tolower(buf[pos - 1]), u8_tolower(buf[pos]),u8_tolower(buf[pos + 1])); - d = ctx->scan_B3G[h]; + d = ctx->B3G[h]; if (d != 0) { - COUNT(tctx->scan_stat_d0++); + COUNT(tctx->stat_d0++); uint32_t j = pos; - uint32_t first = pos - (ctx->scan_m - B3G_Q + 1); + uint32_t first = pos - (ctx->m - B3G_Q + 1); do { j = j - 1; - if (d >= (uint32_t)(1 << (ctx->scan_m - 1))) { + if (d >= (uint32_t)(1 << (ctx->m - 1))) { if (j > first) pos = j; else { /* get our patterns from the hash */ - h = B3G_HASH(u8_tolower(buf[j + ctx->scan_m - 3]), u8_tolower(buf[j + ctx->scan_m - 2]),u8_tolower(buf[j + ctx->scan_m - 1])); + h = B3G_HASH(u8_tolower(buf[j + ctx->m - 3]), u8_tolower(buf[j + ctx->m - 2]),u8_tolower(buf[j + ctx->m - 1])); - if (ctx->scan_bloom[h] != NULL) { - COUNT(tctx->scan_stat_pminlen_calls++); - COUNT(tctx->scan_stat_pminlen_total+=ctx->scan_pminlen[h]); + if (ctx->bloom[h] != NULL) { + COUNT(tctx->stat_pminlen_calls++); + COUNT(tctx->stat_pminlen_total+=ctx->pminlen[h]); - if ((buflen - j) < ctx->scan_pminlen[h]) { + if ((buflen - j) < ctx->pminlen[h]) { goto skip_loop; } else { - COUNT(tctx->scan_stat_bloom_calls++); + COUNT(tctx->stat_bloom_calls++); - if (BloomFilterTest(ctx->scan_bloom[h], buf+j, ctx->scan_pminlen[h]) == 0) { - COUNT(tctx->scan_stat_bloom_hits++); + if (BloomFilterTest(ctx->bloom[h], buf+j, ctx->pminlen[h]) == 0) { + COUNT(tctx->stat_bloom_hits++); - //printf("Bloom: %p, buflen %" PRIu32 ", pos %" PRIu32 ", p_min_len %" PRIu32 "\n", ctx->scan_bloom[h], buflen, pos, ctx->scan_pminlen[h]); + //printf("Bloom: %p, buflen %" PRIu32 ", pos %" PRIu32 ", p_min_len %" PRIu32 "\n", ctx->bloom[h], buflen, pos, ctx->pminlen[h]); goto skip_loop; } } } - B3gHashItem *hi = ctx->scan_hash[h], *thi; + B3gHashItem *hi = ctx->hash[h], *thi; for (thi = hi; thi != NULL; thi = thi->nxt) { - COUNT(tctx->scan_stat_d0_hashloop++); + COUNT(tctx->stat_d0_hashloop++); B3gPattern *p = ctx->parray[thi->idx]; if (p->flags & B3G_NOCASE) { @@ -920,27 +915,27 @@ uint32_t B3gScanBNDMq(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatc continue; if (memcmp_lowercase(p->ci, buf+j, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); matches += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, j, p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } else { if (buflen - j < p->len) continue; if (memcmp(p->cs, buf+j, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); matches += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, j, p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } } skip_loop: - //printf("output at pos %" PRIu32 ": ", j); prt(buf + (j), ctx->scan_m); printf("\n"); + //printf("output at pos %" PRIu32 ": ", j); prt(buf + (j), ctx->m); printf("\n"); ; // gcc doesn't like the goto label without this :-S } } @@ -949,17 +944,17 @@ skip_loop: break; h = B3G_HASH(u8_tolower(buf[j - 1]), u8_tolower(buf[j - 0]),u8_tolower(buf[j+1])); - d = (d << 1) & ctx->scan_B3G[h]; + d = (d << 1) & ctx->B3G[h]; } while (d != 0); } - COUNT(tctx->scan_stat_num_shift++); - COUNT(tctx->scan_stat_total_shift += (ctx->scan_m - B3G_Q + 1)); - pos = pos + ctx->scan_m - B3G_Q + 1; + COUNT(tctx->stat_num_shift++); + COUNT(tctx->stat_total_shift += (ctx->m - B3G_Q + 1)); + pos = pos + ctx->m - B3G_Q + 1; } return matches; } -uint32_t B3gScan(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t B3gSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B3gCtx *ctx = (B3gCtx *)mpm_ctx->ctx; #ifdef B3G_COUNTERS B3gThreadCtx *tctx = (B3gThreadCtx *)mpm_thread_ctx->ctx; @@ -968,53 +963,53 @@ uint32_t B3gScan(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQu B3G_TYPE d; uint32_t j; - COUNT(tctx->scan_stat_calls++); - COUNT(tctx->scan_stat_m_total+=ctx->scan_m); + COUNT(tctx->stat_calls++); + COUNT(tctx->stat_m_total+=ctx->m); - if (buflen < ctx->scan_m) + if (buflen < ctx->m) return 0; - while (pos <= (buflen - ctx->scan_m)) { - j = ctx->scan_m - 2; + while (pos <= (buflen - ctx->m)) { + j = ctx->m - 2; d = ~0; do { uint16_t h = B3G_HASH(u8_tolower(buf[pos + j - 1]), u8_tolower(buf[pos + j - 0]),u8_tolower(buf[pos + j + 1])); // printf("scan: h %" PRIu32 ", %c.%c.%c\n", h, u8_tolower(buf[pos + j - 1]), u8_tolower(buf[pos + j - 0]),u8_tolower(buf[pos + j + 1])); - d = ((d << 1) & ctx->scan_B3G[h]); + d = ((d << 1) & ctx->B3G[h]); j = j - 1; } while (d != 0 && j != 0); // printf("scan: d %" PRIu32 ", j %" PRIu32 "\n", d, j); /* (partial) match, move on to verification */ if (d != 0) { - COUNT(tctx->scan_stat_d0++); - //printf("output at pos %" PRIu32 ": ", pos); prt(buf + pos, ctx->scan_m); printf("\n"); + COUNT(tctx->stat_d0++); + //printf("output at pos %" PRIu32 ": ", pos); prt(buf + pos, ctx->m); printf("\n"); /* get our patterns from the hash */ - uint16_t h = B3G_HASH(u8_tolower(buf[pos + ctx->scan_m - 3]), u8_tolower(buf[pos + ctx->scan_m - 2]),u8_tolower(buf[pos + ctx->scan_m - 1])); + uint16_t h = B3G_HASH(u8_tolower(buf[pos + ctx->m - 3]), u8_tolower(buf[pos + ctx->m - 2]),u8_tolower(buf[pos + ctx->m - 1])); - if (ctx->scan_bloom[h] != NULL) { - COUNT(tctx->scan_stat_pminlen_calls++); - COUNT(tctx->scan_stat_pminlen_total+=ctx->scan_pminlen[h]); + if (ctx->bloom[h] != NULL) { + COUNT(tctx->stat_pminlen_calls++); + COUNT(tctx->stat_pminlen_total+=ctx->pminlen[h]); - if ((buflen - pos) < ctx->scan_pminlen[h]) { + if ((buflen - pos) < ctx->pminlen[h]) { goto skip_loop; } else { - COUNT(tctx->scan_stat_bloom_calls++); + COUNT(tctx->stat_bloom_calls++); - if (BloomFilterTest(ctx->scan_bloom[h], buf+pos, ctx->scan_pminlen[h]) == 0) { - COUNT(tctx->scan_stat_bloom_hits++); + if (BloomFilterTest(ctx->bloom[h], buf+pos, ctx->pminlen[h]) == 0) { + COUNT(tctx->stat_bloom_hits++); - //printf("Bloom: %p, buflen %" PRIu32 ", pos %" PRIu32 ", p_min_len %" PRIu32 "\n", ctx->scan_bloom[h], buflen, pos, ctx->scan_pminlen[h]); + //printf("Bloom: %p, buflen %" PRIu32 ", pos %" PRIu32 ", p_min_len %" PRIu32 "\n", ctx->bloom[h], buflen, pos, ctx->pminlen[h]); goto skip_loop; } } } - B3gHashItem *hi = ctx->scan_hash[h], *thi; + B3gHashItem *hi = ctx->hash[h], *thi; for (thi = hi; thi != NULL; thi = thi->nxt) { - COUNT(tctx->scan_stat_d0_hashloop++); + COUNT(tctx->stat_d0_hashloop++); B3gPattern *p = ctx->parray[thi->idx]; if (p->flags & B3G_NOCASE) { @@ -1022,31 +1017,31 @@ uint32_t B3gScan(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQu continue; if (memcmp_lowercase(p->ci, buf+pos, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); matches += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, pos, p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } else { if (buflen - pos < p->len) continue; if (memcmp(p->cs, buf+pos, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); matches += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, pos, p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } } skip_loop: pos = pos + 1; - //pos = pos + ctx->scan_s0; + //pos = pos + ctx->s0; } else { - COUNT(tctx->scan_stat_num_shift++); - COUNT(tctx->scan_stat_total_shift += (j + 1)); + COUNT(tctx->stat_num_shift++); + COUNT(tctx->stat_total_shift += (j + 1)); pos = pos + j + 1; } @@ -1056,7 +1051,7 @@ skip_loop: return matches; } -uint32_t B3gScan12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t B3gSearch12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B3gCtx *ctx = (B3gCtx *)mpm_ctx->ctx; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; @@ -1068,7 +1063,7 @@ uint32_t B3gScan12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcher while (buf <= bufend) { uint8_t h8 = u8_tolower(*buf); - hi = &ctx->scan_hash1[h8]; + hi = &ctx->hash1[h8]; if (hi->flags & 0x01) { for (thi = hi; thi != NULL; thi = thi->nxt) { @@ -1089,7 +1084,7 @@ uint32_t B3gScan12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcher if (buf != bufend) { /* save one conversion by reusing h8 */ uint16_t h16 = (uint16_t)(h8 << B3G_HASHSHIFT | u8_tolower(*(buf+1))); - hi = ctx->scan_hash2[h16]; + hi = ctx->hash2[h16]; for (thi = hi; thi != NULL; thi = thi->nxt) { p = ctx->parray[thi->idx]; @@ -1109,16 +1104,16 @@ uint32_t B3gScan12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcher } //printf("B3gSearch12: after 1/2byte cnt %" PRIu32 "\n", cnt); - if (ctx->scan_x_pat_cnt > 0) { + if (ctx->pat_x_cnt > 0) { /* Pass bufmin on because buf no longer points to the * start of the buffer. */ - cnt += ctx->MBScan(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); + cnt += ctx->MBSearch(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); //printf("B3gSearch1: after 2+byte cnt %" PRIu32 "\n", cnt); } return cnt; } -uint32_t B3gScan2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t B3gSearch2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B3gCtx *ctx = (B3gCtx *)mpm_ctx->ctx; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; @@ -1134,7 +1129,7 @@ uint32_t B3gScan2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQ while (buf <= bufend) { uint16_t h = u8_tolower(*buf) << B3G_HASHSHIFT | u8_tolower(*(buf+1)); - hi = ctx->scan_hash2[h]; + hi = ctx->hash2[h]; if (hi != NULL) { for (thi = hi; thi != NULL; thi = thi->nxt) { @@ -1166,15 +1161,15 @@ uint32_t B3gScan2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQ } //printf("B3gSearch2: after 2byte cnt %" PRIu32 "\n", cnt); - if (ctx->scan_x_pat_cnt) { + if (ctx->pat_x_cnt) { /* Pass bufmin on because buf no longer points to the * start of the buffer. */ - cnt += ctx->MBScan(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); + cnt += ctx->MBSearch(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); //printf("B3gSearch1: after 2+byte cnt %" PRIu32 "\n", cnt); } return cnt; } -uint32_t B3gScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t B3gSearch1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { B3gCtx *ctx = (B3gCtx *)mpm_ctx->ctx; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; @@ -1189,7 +1184,7 @@ uint32_t B3gScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQ while (buf <= bufend) { uint8_t h = u8_tolower(*buf); - hi = &ctx->scan_hash1[h]; + hi = &ctx->hash1[h]; if (hi->flags & 0x01) { for (thi = hi; thi != NULL; thi = thi->nxt) { @@ -1212,12 +1207,12 @@ uint32_t B3gScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQ buf += 1; } - if (ctx->scan_2_pat_cnt) { + if (ctx->pat_2_cnt) { /* Pass bufmin on because buf no longer points to the * start of the buffer. */ - cnt += ctx->MBScan2(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); - } else if (ctx->scan_x_pat_cnt) { - cnt += ctx->MBScan(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); + cnt += ctx->MBSearch2(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); + } else if (ctx->pat_x_cnt) { + cnt += ctx->MBSearch(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); } return cnt; } @@ -1234,14 +1229,14 @@ static int B3gTestInit01 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); - if (ctx->scan_m == 4) + if (ctx->m == 4) result = 1; else - printf("4 != %" PRIu32 " ", ctx->scan_m); + printf("4 != %" PRIu32 " ", ctx->m); B3gDestroyCtx(&mpm_ctx); return result; @@ -1255,14 +1250,14 @@ static int B3gTestS0Init01 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 4) + if (ctx->s0 == 4) result = 1; else - printf("4 != %" PRIu32 " ", ctx->scan_s0); + printf("4 != %" PRIu32 " ", ctx->s0); B3gDestroyCtx(&mpm_ctx); return result; @@ -1275,15 +1270,15 @@ static int B3gTestS0Init02 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"cdef", 4, 0, 0, 1, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"cdef", 4, 0, 0, 1, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 2) + if (ctx->s0 == 2) result = 1; else - printf("2 != %" PRIu32 " ", ctx->scan_s0); + printf("2 != %" PRIu32 " ", ctx->s0); B3gDestroyCtx(&mpm_ctx); return result; @@ -1296,15 +1291,15 @@ static int B3gTestS0Init03 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 1) + if (ctx->s0 == 1) result = 1; else - printf("1 != %" PRIu32 " ", ctx->scan_s0); + printf("1 != %" PRIu32 " ", ctx->s0); B3gDestroyCtx(&mpm_ctx); return result; @@ -1317,14 +1312,14 @@ static int B3gTestS0Init04 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abab", 4, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abab", 4, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 2) + if (ctx->s0 == 2) result = 1; else - printf("2 != %" PRIu32 " ", ctx->scan_s0); + printf("2 != %" PRIu32 " ", ctx->s0); B3gDestroyCtx(&mpm_ctx); return result; @@ -1337,21 +1332,21 @@ static int B3gTestS0Init05 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcab", 5, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcab", 5, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); - if (ctx->scan_s0 == 3) + if (ctx->s0 == 3) result = 1; else - printf("3 != %" PRIu32 " ", ctx->scan_s0); + printf("3 != %" PRIu32 " ", ctx->s0); B3gDestroyCtx(&mpm_ctx); return result; } #endif -static int B3gTestScan01 (void) { +static int B3gTestSearch01 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1359,12 +1354,12 @@ static int B3gTestScan01 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 1) result = 1; @@ -1376,7 +1371,7 @@ static int B3gTestScan01 (void) { return result; } -static int B3gTestScan02 (void) { +static int B3gTestSearch02 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1384,12 +1379,12 @@ static int B3gTestScan02 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abce", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abce", 4, 0, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 0) result = 1; @@ -1401,7 +1396,7 @@ static int B3gTestScan02 (void) { return result; } -static int B3gTestScan03 (void) { +static int B3gTestSearch03 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1409,14 +1404,14 @@ static int B3gTestScan03 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0, 0); /* 1 match */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"fghj", 4, 0, 0, 2, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"fghj", 4, 0, 0, 2, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3 /* 3 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 3) result = 1; @@ -1429,7 +1424,7 @@ static int B3gTestScan03 (void) { } /* test patterns longer than 'm'. M is 4 here. */ -static int B3gTestScan04 (void) { +static int B3gTestSearch04 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1437,14 +1432,14 @@ static int B3gTestScan04 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"bcdegh", 6, 0, 0, 1, 0, 0); /* 1 match */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"fghjxyz", 7, 0, 0, 2, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"bcdegh", 6, 0, 0, 1, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"fghjxyz", 7, 0, 0, 2, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3 /* 3 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 1) result = 1; @@ -1457,7 +1452,7 @@ static int B3gTestScan04 (void) { } /* case insensitive test patterns longer than 'm'. M is 4 here. */ -static int B3gTestScan05 (void) { +static int B3gTestSearch05 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1465,14 +1460,14 @@ static int B3gTestScan05 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0); /* 1 match */ - B3gAddScanPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0); /* 1 match */ - B3gAddScanPatternCI(&mpm_ctx, (uint8_t *)"fghJikl", 7, 0, 0, 2, 0, 0); /* 1 match */ + B3gAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0); /* 1 match */ + B3gAddPatternCI(&mpm_ctx, (uint8_t *)"fghJikl", 7, 0, 0, 2, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3 /* 3 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 3) result = 1; @@ -1484,7 +1479,7 @@ static int B3gTestScan05 (void) { return result; } -static int B3gTestScan06 (void) { +static int B3gTestSearch06 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1492,12 +1487,12 @@ static int B3gTestScan06 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); if (cnt == 1) result = 1; @@ -1509,7 +1504,7 @@ static int B3gTestScan06 (void) { return result; } -static int B3gTestScan07 (void) { +static int B3gTestSearch07 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1517,18 +1512,18 @@ static int B3gTestScan07 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ /* total matches: 135 */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 6 /* 6 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); if (cnt == 135) result = 1; @@ -1540,7 +1535,7 @@ static int B3gTestScan07 (void) { return result; } -static int B3gTestScan08 (void) { +static int B3gTestSearch08 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1548,12 +1543,12 @@ static int B3gTestScan08 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"a", 1); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"a", 1); if (cnt == 0) result = 1; @@ -1565,7 +1560,7 @@ static int B3gTestScan08 (void) { return result; } -static int B3gTestScan09 (void) { +static int B3gTestSearch09 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1573,12 +1568,12 @@ static int B3gTestScan09 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"ab", 2, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"ab", 2, 0, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"ab", 2); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"ab", 2); if (cnt == 1) result = 1; @@ -1590,7 +1585,7 @@ static int B3gTestScan09 (void) { return result; } -static int B3gTestScan10 (void) { +static int B3gTestSearch10 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1598,12 +1593,12 @@ static int B3gTestScan10 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcdefgh", 8, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefgh", 8, 0, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679abcdefgh012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679", 208); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679abcdefgh012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679", 208); if (cnt == 1) result = 1; @@ -1615,7 +1610,7 @@ static int B3gTestScan10 (void) { return result; } -static int B3gTestScan11 (void) { +static int B3gTestSearch11 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1623,13 +1618,13 @@ static int B3gTestScan11 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"abcde", 5, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"abcde", 5, 0, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2 /* 2 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 2) result = 1; @@ -1641,7 +1636,7 @@ static int B3gTestScan11 (void) { return result; } -static int B3gTestScan12 (void) { +static int B3gTestSearch12 (void) { int result = 0; MpmCtx mpm_ctx; memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); @@ -1649,13 +1644,13 @@ static int B3gTestScan12 (void) { MpmInitCtx(&mpm_ctx, MPM_B3G, -1); B3gCtx *ctx = (B3gCtx *)mpm_ctx.ctx; - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"wxyz", 4, 0, 0, 0, 0, 0); /* 1 match */ - B3gAddScanPatternCS(&mpm_ctx, (uint8_t *)"vwxyz", 5, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"wxyz", 4, 0, 0, 0, 0, 0); /* 1 match */ + B3gAddPatternCS(&mpm_ctx, (uint8_t *)"vwxyz", 5, 0, 0, 0, 0, 0); /* 1 match */ B3gPreparePatterns(&mpm_ctx); B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2 /* 2 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefghjiklmnopqrstuvwxyz", 26); if (cnt == 2) result = 1; @@ -1679,19 +1674,19 @@ void B3gRegisterTests(void) { UtRegisterTest("B3gTestS0Init04", B3gTestS0Init04, 1); UtRegisterTest("B3gTestS0Init05", B3gTestS0Init05, 1); */ - UtRegisterTest("B3gTestScan01", B3gTestScan01, 1); - - UtRegisterTest("B3gTestScan02", B3gTestScan02, 1); - UtRegisterTest("B3gTestScan03", B3gTestScan03, 1); - UtRegisterTest("B3gTestScan04", B3gTestScan04, 1); - UtRegisterTest("B3gTestScan05", B3gTestScan05, 1); - UtRegisterTest("B3gTestScan06", B3gTestScan06, 1); - UtRegisterTest("B3gTestScan07", B3gTestScan07, 1); - UtRegisterTest("B3gTestScan08", B3gTestScan08, 1); - UtRegisterTest("B3gTestScan09", B3gTestScan09, 1); - UtRegisterTest("B3gTestScan10", B3gTestScan10, 1); - UtRegisterTest("B3gTestScan11", B3gTestScan11, 1); - UtRegisterTest("B3gTestScan12", B3gTestScan12, 1); + UtRegisterTest("B3gTestSearch01", B3gTestSearch01, 1); + + UtRegisterTest("B3gTestSearch02", B3gTestSearch02, 1); + UtRegisterTest("B3gTestSearch03", B3gTestSearch03, 1); + UtRegisterTest("B3gTestSearch04", B3gTestSearch04, 1); + UtRegisterTest("B3gTestSearch05", B3gTestSearch05, 1); + UtRegisterTest("B3gTestSearch06", B3gTestSearch06, 1); + UtRegisterTest("B3gTestSearch07", B3gTestSearch07, 1); + UtRegisterTest("B3gTestSearch08", B3gTestSearch08, 1); + UtRegisterTest("B3gTestSearch09", B3gTestSearch09, 1); + UtRegisterTest("B3gTestSearch10", B3gTestSearch10, 1); + UtRegisterTest("B3gTestSearch11", B3gTestSearch11, 1); + UtRegisterTest("B3gTestSearch12", B3gTestSearch12, 1); #endif /* UNITTESTS */ } diff --git a/src/util-mpm-b3g.h b/src/util-mpm-b3g.h index 3f7a43de08..eb133b1a06 100644 --- a/src/util-mpm-b3g.h +++ b/src/util-mpm-b3g.h @@ -22,8 +22,8 @@ #define B3G_HASH(a,b,c) (((a)<pattern_cnt); - printf("Scan Patterns: %" PRIu32 "\n", mpm_ctx->scan_pattern_cnt); + printf("Scan Patterns: %" PRIu32 "\n", mpm_ctx->pattern_cnt); printf("Total Patterns: %" PRIu32 "\n", mpm_ctx->total_pattern_cnt); - printf("Smallest: %" PRIu32 "\n", mpm_ctx->scan_minlen); - printf("Largest: %" PRIu32 "\n", mpm_ctx->scan_maxlen); - printf("Max shiftlen: %" PRIu32 "\n", ctx->scan_shiftlen); - printf("Hash size: %" PRIu32 "\n", ctx->scan_hash_size); - printf("Scan function: "); - if (ctx->Scan == WmScan1) { - printf("WmScan1 (allows single byte patterns)\n"); - printf("MBScan funct: "); - if (ctx->MBScan == WmScan2Hash16) printf("WmSearch2Hash16\n"); - else if (ctx->MBScan == WmScan2Hash15) printf("WmSearch2Hash15\n"); - else if (ctx->MBScan == WmScan2Hash14) printf("WmSearch2Hash14\n"); - else if (ctx->MBScan == WmScan2Hash12) printf("WmSearch2Hash12\n"); - else if (ctx->MBScan == WmScan2Hash9) printf("WmSearch2Hash9\n"); + printf("Smallest: %" PRIu32 "\n", mpm_ctx->minlen); + printf("Largest: %" PRIu32 "\n", mpm_ctx->maxlen); + printf("Max shiftlen: %" PRIu32 "\n", ctx->shiftlen); + printf("Hash size: %" PRIu32 "\n", ctx->hash_size); + printf("Search function: "); + if (ctx->Search == WmSearch1) { + printf("WmSearch1 (allows single byte patterns)\n"); + printf("MBSearch funct: "); + if (ctx->MBSearch == WmSearch2Hash16) printf("WmSearch2Hash16\n"); + else if (ctx->MBSearch == WmSearch2Hash15) printf("WmSearch2Hash15\n"); + else if (ctx->MBSearch == WmSearch2Hash14) printf("WmSearch2Hash14\n"); + else if (ctx->MBSearch == WmSearch2Hash12) printf("WmSearch2Hash12\n"); + else if (ctx->MBSearch == WmSearch2Hash9) printf("WmSearch2Hash9\n"); } - if (ctx->Scan == WmScan2Hash16) printf("WmScan2Hash16 (only for multibyte patterns)\n"); - else if (ctx->Scan == WmScan2Hash15) printf("WmScan2Hash15 (only for multibyte patterns)\n"); - else if (ctx->Scan == WmScan2Hash14) printf("WmScan2Hash14 (only for multibyte patterns)\n"); - else if (ctx->Scan == WmScan2Hash12) printf("WmScan2Hash12 (only for multibyte patterns)\n"); - else if (ctx->Scan == WmScan2Hash9) printf("WmScan2Hash9 (only for multibyte patterns)\n"); + if (ctx->Search == WmSearch2Hash16) printf("WmSearch2Hash16 (only for multibyte patterns)\n"); + else if (ctx->Search == WmSearch2Hash15) printf("WmSearch2Hash15 (only for multibyte patterns)\n"); + else if (ctx->Search == WmSearch2Hash14) printf("WmSearch2Hash14 (only for multibyte patterns)\n"); + else if (ctx->Search == WmSearch2Hash12) printf("WmSearch2Hash12 (only for multibyte patterns)\n"); + else if (ctx->Search == WmSearch2Hash9) printf("WmSearch2Hash9 (only for multibyte patterns)\n"); else printf("ERROR\n"); printf("\n"); } @@ -403,9 +400,9 @@ static inline int WmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, u } mpm_ctx->pattern_cnt++; - if (mpm_ctx->scan_maxlen < patlen) mpm_ctx->scan_maxlen = patlen; - if (mpm_ctx->scan_minlen == 0) mpm_ctx->scan_minlen = patlen; - else if (mpm_ctx->scan_minlen > patlen) mpm_ctx->scan_minlen = patlen; + if (mpm_ctx->maxlen < patlen) mpm_ctx->maxlen = patlen; + if (mpm_ctx->minlen == 0) mpm_ctx->minlen = patlen; + else if (mpm_ctx->minlen > patlen) mpm_ctx->minlen = patlen; } /* we need a match */ @@ -419,13 +416,13 @@ error: return -1; } -int WmAddScanPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, +int WmAddPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, uint32_t sid, uint8_t nosearch) { return WmAddPattern(mpm_ctx, pat, patlen, offset, depth, /* nocase */1, /* scan */1, pid, sid, nosearch); } -int WmAddScanPatternCS(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, +int WmAddPatternCS(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, uint32_t sid, uint8_t nosearch) { return WmAddPattern(mpm_ctx, pat, patlen, offset, depth, /* nocase */0, /* scan */1, pid, sid, nosearch); @@ -461,72 +458,72 @@ static uint32_t BloomHash(void *data, uint16_t datalen, uint8_t iter, uint32_t h return hash; } */ -static void WmScanPrepareHash(MpmCtx *mpm_ctx) { +static void WmSearchPrepareHash(MpmCtx *mpm_ctx) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; uint16_t i; uint16_t idx = 0; uint8_t idx8 = 0; - ctx->scan_hash = (WmHashItem **)SCMalloc(sizeof(WmHashItem *) * ctx->scan_hash_size); - if (ctx->scan_hash == NULL) goto error; - memset(ctx->scan_hash, 0, sizeof(WmHashItem *) * ctx->scan_hash_size); + ctx->hash = (WmHashItem **)SCMalloc(sizeof(WmHashItem *) * ctx->hash_size); + if (ctx->hash == NULL) goto error; + memset(ctx->hash, 0, sizeof(WmHashItem *) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(WmHashItem *) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(WmHashItem *) * ctx->hash_size); /* alloc the pminlen array */ - ctx->scan_pminlen = (uint8_t *)SCMalloc(sizeof(uint8_t) * ctx->scan_hash_size); - if (ctx->scan_pminlen == NULL) goto error; - memset(ctx->scan_pminlen, 0, sizeof(uint8_t) * ctx->scan_hash_size); + ctx->pminlen = (uint8_t *)SCMalloc(sizeof(uint8_t) * ctx->hash_size); + if (ctx->pminlen == NULL) goto error; + memset(ctx->pminlen, 0, sizeof(uint8_t) * ctx->hash_size); for (i = 0; i < mpm_ctx->pattern_cnt; i++) { if(ctx->parray[i]->len == 1) { idx8 = (uint8_t)ctx->parray[i]->ci[0]; - if (ctx->scan_hash1[idx8].flags == 0) { - ctx->scan_hash1[idx8].idx = i; - ctx->scan_hash1[idx8].flags |= 0x01; + if (ctx->hash1[idx8].flags == 0) { + ctx->hash1[idx8].idx = i; + ctx->hash1[idx8].flags |= 0x01; } else { WmHashItem *hi = WmAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; /* Append this HashItem to the list */ - WmHashItem *thi = &ctx->scan_hash1[idx8]; + WmHashItem *thi = &ctx->hash1[idx8]; while (thi->nxt) thi = thi->nxt; thi->nxt = hi; } } else { - uint16_t patlen = ctx->scan_shiftlen; + uint16_t patlen = ctx->shiftlen; - if (ctx->scan_hash_size == HASH9_SIZE) + if (ctx->hash_size == HASH9_SIZE) idx = HASH9(ctx->parray[i]->ci[patlen-1], ctx->parray[i]->ci[patlen-2]); - else if (ctx->scan_hash_size == HASH12_SIZE) + else if (ctx->hash_size == HASH12_SIZE) idx = HASH12(ctx->parray[i]->ci[patlen-1], ctx->parray[i]->ci[patlen-2]); - else if (ctx->scan_hash_size == HASH14_SIZE) + else if (ctx->hash_size == HASH14_SIZE) idx = HASH14(ctx->parray[i]->ci[patlen-1], ctx->parray[i]->ci[patlen-2]); - else if (ctx->scan_hash_size == HASH15_SIZE) + else if (ctx->hash_size == HASH15_SIZE) idx = HASH15(ctx->parray[i]->ci[patlen-1], ctx->parray[i]->ci[patlen-2]); else idx = HASH16(ctx->parray[i]->ci[patlen-1], ctx->parray[i]->ci[patlen-2]); - if (ctx->scan_hash[idx] == NULL) { + if (ctx->hash[idx] == NULL) { WmHashItem *hi = WmAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; - ctx->scan_pminlen[idx] = ctx->parray[i]->len; + ctx->pminlen[idx] = ctx->parray[i]->len; - ctx->scan_hash[idx] = hi; + ctx->hash[idx] = hi; } else { WmHashItem *hi = WmAllocHashItem(mpm_ctx); hi->idx = i; hi->flags |= 0x01; - if (ctx->parray[i]->len < ctx->scan_pminlen[idx]) - ctx->scan_pminlen[idx] = ctx->parray[i]->len; + if (ctx->parray[i]->len < ctx->pminlen[idx]) + ctx->pminlen[idx] = ctx->parray[i]->len; /* Append this HashItem to the list */ - WmHashItem *thi = ctx->scan_hash[idx]; + WmHashItem *thi = ctx->hash[idx]; while (thi->nxt) thi = thi->nxt; thi->nxt = hi; } @@ -534,32 +531,32 @@ static void WmScanPrepareHash(MpmCtx *mpm_ctx) { } /* alloc the bloom array */ - ctx->scan_bloom = (BloomFilter **)SCMalloc(sizeof(BloomFilter *) * ctx->scan_hash_size); - if (ctx->scan_bloom == NULL) goto error; - memset(ctx->scan_bloom, 0, sizeof(BloomFilter *) * ctx->scan_hash_size); + ctx->bloom = (BloomFilter **)SCMalloc(sizeof(BloomFilter *) * ctx->hash_size); + if (ctx->bloom == NULL) goto error; + memset(ctx->bloom, 0, sizeof(BloomFilter *) * ctx->hash_size); mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(BloomFilter *) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(BloomFilter *) * ctx->hash_size); uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - WmHashItem *hi = ctx->scan_hash[h]; + for (h = 0; h < ctx->hash_size; h++) { + WmHashItem *hi = ctx->hash[h]; if (hi == NULL) continue; - ctx->scan_bloom[h] = BloomFilterInit(wm_bloom_size, 2, WmBloomHash); - if (ctx->scan_bloom[h] == NULL) + ctx->bloom[h] = BloomFilterInit(wm_bloom_size, 2, WmBloomHash); + if (ctx->bloom[h] == NULL) continue; - mpm_ctx->memory_cnt += BloomFilterMemoryCnt(ctx->scan_bloom[h]); - mpm_ctx->memory_size += BloomFilterMemorySize(ctx->scan_bloom[h]); + mpm_ctx->memory_cnt += BloomFilterMemoryCnt(ctx->bloom[h]); + mpm_ctx->memory_size += BloomFilterMemorySize(ctx->bloom[h]); - if (ctx->scan_pminlen[h] > 8) - ctx->scan_pminlen[h] = 8; + if (ctx->pminlen[h] > 8) + ctx->pminlen[h] = 8; WmHashItem *thi = hi; do { - BloomFilterAdd(ctx->scan_bloom[h], ctx->parray[thi->idx]->ci, ctx->scan_pminlen[h]); + BloomFilterAdd(ctx->bloom[h], ctx->parray[thi->idx]->ci, ctx->pminlen[h]); thi = thi->nxt; } while (thi != NULL); } @@ -567,29 +564,29 @@ static void WmScanPrepareHash(MpmCtx *mpm_ctx) { error: return; } -static void WmScanPrepareShiftTable(MpmCtx *mpm_ctx) +static void WmSearchPrepareShiftTable(MpmCtx *mpm_ctx) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; uint16_t shift = 0, k = 0, idx = 0; uint32_t i = 0; - uint16_t smallest = mpm_ctx->scan_minlen; + uint16_t smallest = mpm_ctx->minlen; if (smallest > 255) smallest = 255; if (smallest < 2) smallest = 2; - ctx->scan_shiftlen = smallest; + ctx->shiftlen = smallest; - ctx->scan_shifttable = SCMalloc(sizeof(uint16_t) * ctx->scan_hash_size); - if (ctx->scan_shifttable == NULL) + ctx->shifttable = SCMalloc(sizeof(uint16_t) * ctx->hash_size); + if (ctx->shifttable == NULL) return; mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (sizeof(uint16_t) * ctx->scan_hash_size); + mpm_ctx->memory_size += (sizeof(uint16_t) * ctx->hash_size); /* default shift table is set to minimal shift */ - for (i = 0; i < ctx->scan_hash_size; i++) - ctx->scan_shifttable[i] = ctx->scan_shiftlen; + for (i = 0; i < ctx->hash_size; i++) + ctx->shifttable[i] = ctx->shiftlen; for (i = 0; i < mpm_ctx->pattern_cnt; i++) { @@ -600,53 +597,53 @@ static void WmScanPrepareShiftTable(MpmCtx *mpm_ctx) /* add the first character of the pattern preceeded by * every possible other character. */ for (k = 0; k < 256; k++) { - shift = ctx->scan_shiftlen - 1; + shift = ctx->shiftlen - 1; if (shift > 255) shift = 255; - if (ctx->scan_hash_size == HASH9_SIZE) { + if (ctx->hash_size == HASH9_SIZE) { idx = HASH9(ctx->parray[i]->ci[0], (uint8_t)k); //printf("HASH9 idx %" PRIu32 "\n", idx); - } else if (ctx->scan_hash_size == HASH12_SIZE) { + } else if (ctx->hash_size == HASH12_SIZE) { idx = HASH12(ctx->parray[i]->ci[0], (uint8_t)k); //printf("HASH12 idx %" PRIu32 "\n", idx); - } else if (ctx->scan_hash_size == HASH14_SIZE) { + } else if (ctx->hash_size == HASH14_SIZE) { idx = HASH14(ctx->parray[i]->ci[0], (uint8_t)k); //printf("HASH14 idx %" PRIu32 "\n", idx); - } else if (ctx->scan_hash_size == HASH15_SIZE) { + } else if (ctx->hash_size == HASH15_SIZE) { idx = HASH15(ctx->parray[i]->ci[0], (uint8_t)k); //printf("HASH15 idx %" PRIu32 "\n", idx); } else { idx = HASH16(ctx->parray[i]->ci[0], (uint8_t)k); //printf("HASH15 idx %" PRIu32 "\n", idx); } - if (shift < ctx->scan_shifttable[idx]) { - ctx->scan_shifttable[idx] = shift; + if (shift < ctx->shifttable[idx]) { + ctx->shifttable[idx] = shift; } } - for (k = 0; k < ctx->scan_shiftlen-1; k++) + for (k = 0; k < ctx->shiftlen-1; k++) { - shift = (ctx->scan_shiftlen - 2 - k); + shift = (ctx->shiftlen - 2 - k); if (shift > 255) shift = 255; - if (ctx->scan_hash_size == HASH9_SIZE) { + if (ctx->hash_size == HASH9_SIZE) { idx = HASH9(ctx->parray[i]->ci[k+1], ctx->parray[i]->ci[k]); //printf("HASH9 idx %" PRIu32 "\n", idx); - } else if (ctx->scan_hash_size == HASH12_SIZE) { + } else if (ctx->hash_size == HASH12_SIZE) { idx = HASH12(ctx->parray[i]->ci[k+1], ctx->parray[i]->ci[k]); //printf("HASH12 idx %" PRIu32 "\n", idx); - } else if (ctx->scan_hash_size == HASH14_SIZE) { + } else if (ctx->hash_size == HASH14_SIZE) { idx = HASH14(ctx->parray[i]->ci[k+1], ctx->parray[i]->ci[k]); //printf("HASH14 idx %" PRIu32 "\n", idx); - } else if (ctx->scan_hash_size == HASH15_SIZE) { + } else if (ctx->hash_size == HASH15_SIZE) { idx = HASH15(ctx->parray[i]->ci[k+1], ctx->parray[i]->ci[k]); //printf("HASH15 idx %" PRIu32 "\n", idx); } else { idx = HASH16(ctx->parray[i]->ci[k+1], ctx->parray[i]->ci[k]); //printf("HASH15 idx %" PRIu32 "\n", idx); } - if (shift < ctx->scan_shifttable[idx]) { - ctx->scan_shifttable[idx] = shift; + if (shift < ctx->shifttable[idx]) { + ctx->shifttable[idx] = shift; } //printf("WmPrepareShiftTable: i %" PRIu32 ", k %" PRIu32 ", idx %" PRIu32 ", shift set to %" PRIu32 ": \"%c%c\"\n", // i, k, idx, shift, ctx->parray[i]->ci[k], ctx->parray[i]->ci[k+1]); @@ -654,7 +651,7 @@ static void WmScanPrepareShiftTable(MpmCtx *mpm_ctx) } } -int WmScanPreparePatterns(MpmCtx *mpm_ctx) { +int WmPreparePatterns(MpmCtx *mpm_ctx) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; /* alloc the pattern array */ @@ -688,42 +685,42 @@ int WmScanPreparePatterns(MpmCtx *mpm_ctx) { * */ /* scan */ - if (ctx->scan_hash_size == 0) { - if (mpm_ctx->scan_pattern_cnt < 50) { - ctx->scan_hash_size = HASH9_SIZE; - } else if(mpm_ctx->scan_pattern_cnt < 300) { - ctx->scan_hash_size = HASH12_SIZE; - } else if(mpm_ctx->scan_pattern_cnt < 1200) { - ctx->scan_hash_size = HASH14_SIZE; - } else if(mpm_ctx->scan_pattern_cnt < 2400) { - ctx->scan_hash_size = HASH15_SIZE; + if (ctx->hash_size == 0) { + if (mpm_ctx->pattern_cnt < 50) { + ctx->hash_size = HASH9_SIZE; + } else if(mpm_ctx->pattern_cnt < 300) { + ctx->hash_size = HASH12_SIZE; + } else if(mpm_ctx->pattern_cnt < 1200) { + ctx->hash_size = HASH14_SIZE; + } else if(mpm_ctx->pattern_cnt < 2400) { + ctx->hash_size = HASH15_SIZE; } else { - ctx->scan_hash_size = HASH16_SIZE; + ctx->hash_size = HASH16_SIZE; } } - WmScanPrepareShiftTable(mpm_ctx); - WmScanPrepareHash(mpm_ctx); - - if (ctx->scan_hash_size == HASH9_SIZE) { - ctx->MBScan = WmScan2Hash9; - ctx->Scan = WmScan2Hash9; - } else if (ctx->scan_hash_size == HASH12_SIZE) { - ctx->MBScan = WmScan2Hash12; - ctx->Scan = WmScan2Hash12; - } else if (ctx->scan_hash_size == HASH14_SIZE) { - ctx->MBScan = WmScan2Hash14; - ctx->Scan = WmScan2Hash14; - } else if (ctx->scan_hash_size == HASH15_SIZE) { - ctx->MBScan = WmScan2Hash15; - ctx->Scan = WmScan2Hash15; + WmSearchPrepareShiftTable(mpm_ctx); + WmSearchPrepareHash(mpm_ctx); + + if (ctx->hash_size == HASH9_SIZE) { + ctx->MBSearch = WmSearch2Hash9; + ctx->Search = WmSearch2Hash9; + } else if (ctx->hash_size == HASH12_SIZE) { + ctx->MBSearch = WmSearch2Hash12; + ctx->Search = WmSearch2Hash12; + } else if (ctx->hash_size == HASH14_SIZE) { + ctx->MBSearch = WmSearch2Hash14; + ctx->Search = WmSearch2Hash14; + } else if (ctx->hash_size == HASH15_SIZE) { + ctx->MBSearch = WmSearch2Hash15; + ctx->Search = WmSearch2Hash15; } else { - ctx->MBScan = WmScan2Hash16; - ctx->Scan = WmScan2Hash16; + ctx->MBSearch = WmSearch2Hash16; + ctx->Search = WmSearch2Hash16; } - if (mpm_ctx->scan_minlen == 1) { - ctx->Scan = WmScan1; + if (mpm_ctx->minlen == 1) { + ctx->Search = WmSearch1; } return 0; @@ -735,11 +732,11 @@ void WmPrintSearchStats(MpmThreadCtx *mpm_thread_ctx) { #ifdef WUMANBER_COUNTERS WmThreadCtx *tctx = (WmThreadCtx *)mpm_thread_ctx->ctx; - printf("Shift 0: %" PRIu32 "\n", tctx->scan_stat_shift_null); - printf("Loop match: %" PRIu32 "\n", tctx->scan_stat_loop_match); - printf("Loop no match: %" PRIu32 "\n", tctx->scan_stat_loop_no_match); - printf("Num shifts: %" PRIu32 "\n", tctx->scan_stat_num_shift); - printf("Total shifts: %" PRIu32 "\n", tctx->scan_stat_total_shift); + printf("Shift 0: %" PRIu32 "\n", tctx->stat_shift_null); + printf("Loop match: %" PRIu32 "\n", tctx->stat_loop_match); + printf("Loop no match: %" PRIu32 "\n", tctx->stat_loop_no_match); + printf("Num shifts: %" PRIu32 "\n", tctx->stat_num_shift); + printf("Total shifts: %" PRIu32 "\n", tctx->stat_total_shift); #endif /* WUMANBER_COUNTERS */ } @@ -758,13 +755,13 @@ memcmp_lowercase(uint8_t *s1, uint8_t *s2, uint16_t n) { return 0; } -inline uint32_t WmScan(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +inline uint32_t WmSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; - return ctx->Scan(mpm_ctx, mpm_thread_ctx, pmq, buf, buflen); + return ctx->Search(mpm_ctx, mpm_thread_ctx, pmq, buf, buflen); } /* SCAN FUNCTIONS */ -uint32_t WmScan2Hash9(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t WmSearch2Hash9(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; #ifdef WUMANBER_COUNTERS WmThreadCtx *tctx = (WmThreadCtx *)mpm_thread_ctx->ctx; @@ -772,7 +769,7 @@ uint32_t WmScan2Hash9(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatc uint32_t cnt = 0; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; - uint16_t sl = ctx->scan_shiftlen; + uint16_t sl = ctx->shiftlen; uint16_t h; uint8_t shift; WmHashItem *thi, *hi; @@ -789,27 +786,27 @@ uint32_t WmScan2Hash9(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatc while (buf <= bufend) { h = HASH9(wm_tolower(*buf),(wm_tolower(*(buf-1)))); - shift = ctx->scan_shifttable[h]; + shift = ctx->shifttable[h]; //printf("%p %" PRIu32 " search: h %" PRIu32 ", shift %" PRIu32 "\n", buf, buf - bufmin, h, shift); if (shift == 0) { - COUNT(tctx->scan_stat_shift_null++); + COUNT(tctx->stat_shift_null++); - hi = ctx->scan_hash[h]; + hi = ctx->hash[h]; //printf("search: hi %p\n", hi); if (hi != NULL) { /* get our patterns from the hash */ - if (ctx->scan_bloom[h] != NULL) { - COUNT(tctx->scan_stat_pminlen_calls++); - COUNT(tctx->scan_stat_pminlen_total+=ctx->scan_pminlen[h]); + if (ctx->bloom[h] != NULL) { + COUNT(tctx->stat_pminlen_calls++); + COUNT(tctx->stat_pminlen_total+=ctx->pminlen[h]); - if ((bufend - (buf-sl)) < ctx->scan_pminlen[h]) { + if ((bufend - (buf-sl)) < ctx->pminlen[h]) { goto skip_loop; } else { - COUNT(tctx->scan_stat_bloom_calls++); + COUNT(tctx->stat_bloom_calls++); - if (BloomFilterTest(ctx->scan_bloom[h], buf-sl+1, ctx->scan_pminlen[h]) == 0) { - COUNT(tctx->scan_stat_bloom_hits++); + if (BloomFilterTest(ctx->bloom[h], buf-sl+1, ctx->pminlen[h]) == 0) { + COUNT(tctx->stat_bloom_hits++); goto skip_loop; } } @@ -830,24 +827,24 @@ uint32_t WmScan2Hash9(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatc if (memcmp_lowercase(p->ci, buf-sl+1, p->len) == 0) { //printf("CI Exact match: "); prt(p->ci, p->len); printf("\n"); - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } else { if (p->prefix_cs != prefixcs_buf || p->len > (bufend-(buf-sl))) continue; if (memcmp(p->cs, buf-sl+1, p->len) == 0) { //printf("CS Exact match: "); prt(p->cs, p->len); printf("\n"); - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } } @@ -855,8 +852,8 @@ uint32_t WmScan2Hash9(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatc skip_loop: shift = 1; } else { - COUNT(tctx->scan_stat_total_shift += shift); - COUNT(tctx->scan_stat_num_shift++); + COUNT(tctx->stat_total_shift += shift); + COUNT(tctx->stat_num_shift++); } buf += shift; } @@ -865,7 +862,7 @@ skip_loop: return cnt; } -uint32_t WmScan2Hash12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t WmSearch2Hash12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; #ifdef WUMANBER_COUNTERS WmThreadCtx *tctx = (WmThreadCtx *)mpm_thread_ctx->ctx; @@ -873,7 +870,7 @@ uint32_t WmScan2Hash12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat uint32_t cnt = 0; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; - uint16_t sl = ctx->scan_shiftlen; + uint16_t sl = ctx->shiftlen; uint16_t h; uint8_t shift; WmHashItem *thi, *hi; @@ -892,27 +889,27 @@ uint32_t WmScan2Hash12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat while (buf <= bufend) { //h = (wm_tolower(*buf)<<8)+(wm_tolower(*(buf-1))); h = HASH12(wm_tolower(*buf),(wm_tolower(*(buf-1)))); - shift = ctx->scan_shifttable[h]; + shift = ctx->shifttable[h]; //printf("search: h %" PRIu32 ", shift %" PRIu32 "\n", h, shift); if (shift == 0) { - COUNT(tctx->scan_stat_shift_null++); + COUNT(tctx->stat_shift_null++); /* get our hash item */ - hi = ctx->scan_hash[h]; + hi = ctx->hash[h]; //printf("search: hi %p\n", hi); if (hi != NULL) { /* get our patterns from the hash */ - if (ctx->scan_bloom[h] != NULL) { - COUNT(tctx->scan_stat_pminlen_calls++); - COUNT(tctx->scan_stat_pminlen_total+=ctx->scan_pminlen[h]); + if (ctx->bloom[h] != NULL) { + COUNT(tctx->stat_pminlen_calls++); + COUNT(tctx->stat_pminlen_total+=ctx->pminlen[h]); - if ((bufend - (buf-sl)) < ctx->scan_pminlen[h]) { + if ((bufend - (buf-sl)) < ctx->pminlen[h]) { goto skip_loop; } else { - COUNT(tctx->scan_stat_bloom_calls++); + COUNT(tctx->stat_bloom_calls++); - if (BloomFilterTest(ctx->scan_bloom[h], buf-sl+1, ctx->scan_pminlen[h]) == 0) { - COUNT(tctx->scan_stat_bloom_hits++); + if (BloomFilterTest(ctx->bloom[h], buf-sl+1, ctx->pminlen[h]) == 0) { + COUNT(tctx->stat_bloom_hits++); goto skip_loop; } } @@ -933,24 +930,24 @@ uint32_t WmScan2Hash12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat if (memcmp_lowercase(p->ci, buf-sl+1, p->len) == 0) { //printf("CI Exact match: "); prt(p->ci, p->len); printf("\n"); - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } else { if (p->prefix_cs != prefixcs_buf || p->len > (bufend-(buf-sl))) continue; if (memcmp(p->cs, buf-sl+1, p->len) == 0) { //printf("CS Exact match: "); prt(p->cs, p->len); printf("\n"); - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } } @@ -958,8 +955,8 @@ uint32_t WmScan2Hash12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat skip_loop: shift = 1; } else { - COUNT(tctx->scan_stat_total_shift += shift); - COUNT(tctx->scan_stat_num_shift++); + COUNT(tctx->stat_total_shift += shift); + COUNT(tctx->stat_num_shift++); } buf += shift; } @@ -967,7 +964,7 @@ skip_loop: return cnt; } -uint32_t WmScan2Hash14(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t WmSearch2Hash14(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; #ifdef WUMANBER_COUNTERS WmThreadCtx *tctx = (WmThreadCtx *)mpm_thread_ctx->ctx; @@ -975,7 +972,7 @@ uint32_t WmScan2Hash14(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat uint32_t cnt = 0; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; - uint16_t sl = ctx->scan_shiftlen; + uint16_t sl = ctx->shiftlen; uint16_t h; uint8_t shift; WmHashItem *thi, *hi; @@ -994,27 +991,27 @@ uint32_t WmScan2Hash14(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat while (buf <= bufend) { //h = (wm_tolower(*buf)<<8)+(wm_tolower(*(buf-1))); h = HASH14(wm_tolower(*buf),(wm_tolower(*(buf-1)))); - shift = ctx->scan_shifttable[h]; + shift = ctx->shifttable[h]; //printf("search: h %" PRIu32 ", shift %" PRIu32 "\n", h, shift); if (shift == 0) { - COUNT(tctx->scan_stat_shift_null++); + COUNT(tctx->stat_shift_null++); /* get our hash item */ - hi = ctx->scan_hash[h]; + hi = ctx->hash[h]; //printf("search: hi %p\n", hi); if (hi != NULL) { /* get our patterns from the hash */ - if (ctx->scan_bloom[h] != NULL) { - COUNT(tctx->scan_stat_pminlen_calls++); - COUNT(tctx->scan_stat_pminlen_total+=ctx->scan_pminlen[h]); + if (ctx->bloom[h] != NULL) { + COUNT(tctx->stat_pminlen_calls++); + COUNT(tctx->stat_pminlen_total+=ctx->pminlen[h]); - if ((bufend - (buf-sl)) < ctx->scan_pminlen[h]) { + if ((bufend - (buf-sl)) < ctx->pminlen[h]) { goto skip_loop; } else { - COUNT(tctx->scan_stat_bloom_calls++); + COUNT(tctx->stat_bloom_calls++); - if (BloomFilterTest(ctx->scan_bloom[h], buf-sl+1, ctx->scan_pminlen[h]) == 0) { - COUNT(tctx->scan_stat_bloom_hits++); + if (BloomFilterTest(ctx->bloom[h], buf-sl+1, ctx->pminlen[h]) == 0) { + COUNT(tctx->stat_bloom_hits++); goto skip_loop; } } @@ -1034,21 +1031,21 @@ uint32_t WmScan2Hash14(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat continue; if (memcmp_lowercase(p->ci, buf-sl+1, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } else { if (p->prefix_cs != prefixcs_buf || p->len > (bufend-(buf-sl))) continue; if (memcmp(p->cs, buf-sl+1, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } } @@ -1056,8 +1053,8 @@ uint32_t WmScan2Hash14(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat skip_loop: shift = 1; } else { - COUNT(tctx->scan_stat_total_shift += shift); - COUNT(tctx->scan_stat_num_shift++); + COUNT(tctx->stat_total_shift += shift); + COUNT(tctx->stat_num_shift++); } buf += shift; } @@ -1065,7 +1062,7 @@ skip_loop: return cnt; } -uint32_t WmScan2Hash15(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t WmSearch2Hash15(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; #ifdef WUMANBER_COUNTERS WmThreadCtx *tctx = (WmThreadCtx *)mpm_thread_ctx->ctx; @@ -1073,7 +1070,7 @@ uint32_t WmScan2Hash15(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat uint32_t cnt = 0; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; - uint16_t sl = ctx->scan_shiftlen; + uint16_t sl = ctx->shiftlen; uint16_t h; uint8_t shift; WmHashItem *thi, *hi; @@ -1092,27 +1089,27 @@ uint32_t WmScan2Hash15(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat while (buf <= bufend) { //h = (wm_tolower(*buf)<<8)+(wm_tolower(*(buf-1))); h = HASH15(wm_tolower(*buf),(wm_tolower(*(buf-1)))); - shift = ctx->scan_shifttable[h]; + shift = ctx->shifttable[h]; //printf("search: h %" PRIu32 ", shift %" PRIu32 "\n", h, shift); if (shift == 0) { - COUNT(tctx->scan_stat_shift_null++); + COUNT(tctx->stat_shift_null++); /* get our hash item */ - hi = ctx->scan_hash[h]; + hi = ctx->hash[h]; //printf("search: hi %p\n", hi); if (hi != NULL) { /* get our patterns from the hash */ - if (ctx->scan_bloom[h] != NULL) { - COUNT(tctx->scan_stat_pminlen_calls++); - COUNT(tctx->scan_stat_pminlen_total+=ctx->scan_pminlen[h]); + if (ctx->bloom[h] != NULL) { + COUNT(tctx->stat_pminlen_calls++); + COUNT(tctx->stat_pminlen_total+=ctx->pminlen[h]); - if ((bufend - (buf-sl)) < ctx->scan_pminlen[h]) { + if ((bufend - (buf-sl)) < ctx->pminlen[h]) { goto skip_loop; } else { - COUNT(tctx->scan_stat_bloom_calls++); + COUNT(tctx->stat_bloom_calls++); - if (BloomFilterTest(ctx->scan_bloom[h], buf-sl+1, ctx->scan_pminlen[h]) == 0) { - COUNT(tctx->scan_stat_bloom_hits++); + if (BloomFilterTest(ctx->bloom[h], buf-sl+1, ctx->pminlen[h]) == 0) { + COUNT(tctx->stat_bloom_hits++); goto skip_loop; } } @@ -1133,22 +1130,22 @@ uint32_t WmScan2Hash15(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat if (memcmp_lowercase(p->ci, buf-sl+1, p->len) == 0) { //printf("CI Exact match: "); prt(p->ci, p->len); printf("\n"); - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } else { if (p->prefix_cs != prefixcs_buf || p->len > (bufend-(buf-sl))) continue; if (memcmp(p->cs, buf-sl+1, p->len) == 0) { //printf("CS Exact match: "); prt(p->cs, p->len); printf("\n"); - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } } @@ -1156,8 +1153,8 @@ uint32_t WmScan2Hash15(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat skip_loop: shift = 1; } else { - COUNT(tctx->scan_stat_total_shift += shift); - COUNT(tctx->scan_stat_num_shift++); + COUNT(tctx->stat_total_shift += shift); + COUNT(tctx->stat_num_shift++); } buf += shift; } @@ -1165,7 +1162,7 @@ skip_loop: return cnt; } -uint32_t WmScan2Hash16(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t WmSearch2Hash16(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; #ifdef WUMANBER_COUNTERS WmThreadCtx *tctx = (WmThreadCtx *)mpm_thread_ctx->ctx; @@ -1173,7 +1170,7 @@ uint32_t WmScan2Hash16(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat uint32_t cnt = 0; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; - uint16_t sl = ctx->scan_shiftlen; + uint16_t sl = ctx->shiftlen; uint16_t h; uint8_t shift; WmHashItem *thi, *hi; @@ -1192,27 +1189,27 @@ uint32_t WmScan2Hash16(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat while (buf <= bufend) { //h = (wm_tolower(*buf)<<8)+(wm_tolower(*(buf-1))); h = HASH16(wm_tolower(*buf),(wm_tolower(*(buf-1)))); - shift = ctx->scan_shifttable[h]; + shift = ctx->shifttable[h]; //printf("search: h %" PRIu32 ", shift %" PRIu32 "\n", h, shift); if (shift == 0) { - COUNT(tctx->scan_stat_shift_null++); + COUNT(tctx->stat_shift_null++); /* get our hash item */ - hi = ctx->scan_hash[h]; + hi = ctx->hash[h]; //printf("search: hi %p\n", hi); if (hi != NULL) { /* get our patterns from the hash */ - if (ctx->scan_bloom[h] != NULL) { - COUNT(tctx->scan_stat_pminlen_calls++); - COUNT(tctx->scan_stat_pminlen_total+=ctx->scan_pminlen[h]); + if (ctx->bloom[h] != NULL) { + COUNT(tctx->stat_pminlen_calls++); + COUNT(tctx->stat_pminlen_total+=ctx->pminlen[h]); - if ((bufend - (buf-sl)) < ctx->scan_pminlen[h]) { + if ((bufend - (buf-sl)) < ctx->pminlen[h]) { goto skip_loop; } else { - COUNT(tctx->scan_stat_bloom_calls++); + COUNT(tctx->stat_bloom_calls++); - if (BloomFilterTest(ctx->scan_bloom[h], buf-sl+1, ctx->scan_pminlen[h]) == 0) { - COUNT(tctx->scan_stat_bloom_hits++); + if (BloomFilterTest(ctx->bloom[h], buf-sl+1, ctx->pminlen[h]) == 0) { + COUNT(tctx->stat_bloom_hits++); goto skip_loop; } } @@ -1232,21 +1229,21 @@ uint32_t WmScan2Hash16(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat continue; if (memcmp_lowercase(p->ci, buf-sl+1, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } else { if (p->prefix_cs != prefixcs_buf || p->len > (bufend-(buf-sl))) continue; if (memcmp(p->cs, buf-sl+1, p->len) == 0) { - COUNT(tctx->scan_stat_loop_match++); + COUNT(tctx->stat_loop_match++); cnt += MpmVerifyMatch(mpm_thread_ctx, pmq, p->em, (buf-sl+1 - bufmin), p->len); } else { - COUNT(tctx->scan_stat_loop_no_match++); + COUNT(tctx->stat_loop_no_match++); } } } @@ -1254,8 +1251,8 @@ uint32_t WmScan2Hash16(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMat skip_loop: shift = 1; } else { - COUNT(tctx->scan_stat_total_shift += shift); - COUNT(tctx->scan_stat_num_shift++); + COUNT(tctx->stat_total_shift += shift); + COUNT(tctx->stat_num_shift++); } buf += shift; } @@ -1263,7 +1260,7 @@ skip_loop: return cnt; } -uint32_t WmScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { +uint32_t WmSearch1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen) { WmCtx *ctx = (WmCtx *)mpm_ctx->ctx; uint8_t *bufmin = buf; uint8_t *bufend = buf + buflen - 1; @@ -1276,10 +1273,10 @@ uint32_t WmScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQu //printf("BUF "); prt(buf,buflen); printf("\n"); - if (mpm_ctx->scan_minlen == 1) { + if (mpm_ctx->minlen == 1) { while (buf <= bufend) { uint8_t h = wm_tolower(*buf); - hi = &ctx->scan_hash1[h]; + hi = &ctx->hash1[h]; if (hi->flags & 0x01) { for (thi = hi; thi != NULL; thi = thi->nxt) { @@ -1302,12 +1299,12 @@ uint32_t WmScan1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatcherQu buf += 1; } } - //printf("WmScan1: after 1byte cnt %" PRIu32 "\n", cnt); - if (mpm_ctx->scan_maxlen > 1) { + //printf("WmSearch1: after 1byte cnt %" PRIu32 "\n", cnt); + if (mpm_ctx->maxlen > 1) { /* Pass bufmin on because buf no longer points to the * start of the buffer. */ - cnt += ctx->MBScan(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); - //printf("WmScan1: after 2+byte cnt %" PRIu32 "\n", cnt); + cnt += ctx->MBSearch(mpm_ctx, mpm_thread_ctx, pmq, bufmin, buflen); + //printf("WmSearch1: after 2+byte cnt %" PRIu32 "\n", cnt); } return cnt; } @@ -1401,48 +1398,48 @@ void WmDestroyCtx(MpmCtx *mpm_ctx) { mpm_ctx->memory_size -= (mpm_ctx->pattern_cnt * sizeof(WmPattern)); } - if (ctx->scan_bloom) { + if (ctx->bloom) { uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - if (ctx->scan_bloom[h] == NULL) + for (h = 0; h < ctx->hash_size; h++) { + if (ctx->bloom[h] == NULL) continue; - mpm_ctx->memory_cnt -= BloomFilterMemoryCnt(ctx->scan_bloom[h]); - mpm_ctx->memory_size -= BloomFilterMemorySize(ctx->scan_bloom[h]); + mpm_ctx->memory_cnt -= BloomFilterMemoryCnt(ctx->bloom[h]); + mpm_ctx->memory_size -= BloomFilterMemorySize(ctx->bloom[h]); - BloomFilterFree(ctx->scan_bloom[h]); + BloomFilterFree(ctx->bloom[h]); } - SCFree(ctx->scan_bloom); + SCFree(ctx->bloom); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(BloomFilter *) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(BloomFilter *) * ctx->hash_size); } - if (ctx->scan_hash) { + if (ctx->hash) { uint32_t h; - for (h = 0; h < ctx->scan_hash_size; h++) { - if (ctx->scan_hash[h] == NULL) + for (h = 0; h < ctx->hash_size; h++) { + if (ctx->hash[h] == NULL) continue; - WmHashFree(mpm_ctx, ctx->scan_hash[h]); + WmHashFree(mpm_ctx, ctx->hash[h]); } - SCFree(ctx->scan_hash); + SCFree(ctx->hash); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(WmHashItem) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(WmHashItem) * ctx->hash_size); } - if (ctx->scan_shifttable) { - SCFree(ctx->scan_shifttable); + if (ctx->shifttable) { + SCFree(ctx->shifttable); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(uint16_t) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(uint16_t) * ctx->hash_size); } - if (ctx->scan_pminlen) { - SCFree(ctx->scan_pminlen); + if (ctx->pminlen) { + SCFree(ctx->pminlen); mpm_ctx->memory_cnt--; - mpm_ctx->memory_size -= (sizeof(uint8_t) * ctx->scan_hash_size); + mpm_ctx->memory_size -= (sizeof(uint8_t) * ctx->hash_size); } SCFree(mpm_ctx->ctx); @@ -1453,16 +1450,16 @@ void WmDestroyCtx(MpmCtx *mpm_ctx) { void WmThreadInitCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, uint32_t matchsize) { memset(mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); - if (sizeof(WmThreadCtx) > 0) { /* size can be 0 when optimized */ - mpm_thread_ctx->ctx = SCMalloc(sizeof(WmThreadCtx)); - if (mpm_thread_ctx->ctx == NULL) - return; +#ifdef WUMANBER_COUNTERS + mpm_thread_ctx->ctx = SCMalloc(sizeof(WmThreadCtx)); + if (mpm_thread_ctx->ctx == NULL) + return; - memset(mpm_thread_ctx->ctx, 0, sizeof(WmThreadCtx)); + memset(mpm_thread_ctx->ctx, 0, sizeof(WmThreadCtx)); - mpm_thread_ctx->memory_cnt++; - mpm_thread_ctx->memory_size += sizeof(WmThreadCtx); - } + mpm_thread_ctx->memory_cnt++; + mpm_thread_ctx->memory_size += sizeof(WmThreadCtx); +#endif } void WmThreadDestroyCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx) { @@ -1513,7 +1510,7 @@ int WmTestInitCtx03 (void) { memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); - if (mpm_table[MPM_WUMANBER].Scan == WmScan) + if (mpm_table[MPM_WUMANBER].Search == WmSearch) result = 1; WmDestroyCtx(&mpm_ctx); @@ -1521,24 +1518,26 @@ int WmTestInitCtx03 (void) { } int WmTestThreadInitCtx01 (void) { - if (sizeof(WmThreadCtx) > 0) { - int result = 0; - MpmCtx mpm_ctx; - memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); - MpmThreadCtx mpm_thread_ctx; +#ifdef WUMANBER_COUNTERS + int result = 0; + MpmCtx mpm_ctx; + memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); + MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); - WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); + MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); + WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - if (mpm_thread_ctx.memory_cnt == 2) - result = 1; + if (mpm_thread_ctx.memory_cnt == 2) + result = 1; + else + printf("mpm_thread_ctx.memory_cnt %"PRIu32", expected 2: ", mpm_thread_ctx.memory_cnt); - WmThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - WmDestroyCtx(&mpm_ctx); - return result; - } else { - return 1; - } + WmThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); + WmDestroyCtx(&mpm_ctx); + return result; +#else + return 1; +#endif } int WmTestThreadInitCtx02 (void) { @@ -1697,9 +1696,9 @@ int WmTestPrepare01 (void) { WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; WmAddPattern(&mpm_ctx, (uint8_t *)"a", 1, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); - if (ctx->Scan == WmScan1) + if (ctx->Search == WmSearch1) result = 1; WmDestroyCtx(&mpm_ctx); @@ -1713,10 +1712,10 @@ int WmTestPrepare02 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - if (ctx->scan_shiftlen == 4) + if (ctx->shiftlen == 4) result = 1; WmDestroyCtx(&mpm_ctx); @@ -1730,13 +1729,13 @@ int WmTestPrepare03 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - if (ctx->scan_shifttable[1] == 4) + if (ctx->shifttable[1] == 4) result = 1; else - printf("4 != %" PRIu32 ": ", ctx->scan_shifttable[1]); + printf("4 != %" PRIu32 ": ", ctx->shifttable[1]); WmDestroyCtx(&mpm_ctx); return result; @@ -1750,9 +1749,9 @@ int WmTestPrepare04 (void) { WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; WmAddPattern(&mpm_ctx, (uint8_t *)"a", 1, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); - if (ctx->Scan == WmScan1) + if (ctx->Search == WmSearch1) result = 1; WmDestroyCtx(&mpm_ctx); @@ -1766,10 +1765,10 @@ int WmTestPrepare05 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - if (ctx->scan_shiftlen == 4) + if (ctx->shiftlen == 4) result = 1; WmDestroyCtx(&mpm_ctx); @@ -1783,13 +1782,13 @@ int WmTestPrepare06 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - if (ctx->scan_shifttable[1] == 4) + if (ctx->shifttable[1] == 4) result = 1; else - printf("4 != %" PRIu32 ": ", ctx->scan_shifttable[1]); + printf("4 != %" PRIu32 ": ", ctx->shifttable[1]); WmDestroyCtx(&mpm_ctx); return result; @@ -1805,11 +1804,11 @@ int WmTestSearch01 (void) { WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); //mpm_ctx.PrintCtx(&mpm_ctx); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); if (cnt == 1) result = 1; @@ -1832,12 +1831,12 @@ int WmTestSearch01Hash12 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - ctx->scan_hash_size = HASH12_SIZE; - WmScanPreparePatterns(&mpm_ctx); + ctx->hash_size = HASH12_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); //mpm_ctx.PrintCtx(&mpm_ctx); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); if (cnt == 1) result = 1; @@ -1860,12 +1859,12 @@ int WmTestSearch01Hash14 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - ctx->scan_hash_size = HASH14_SIZE; - WmScanPreparePatterns(&mpm_ctx); + ctx->hash_size = HASH14_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); //mpm_ctx.PrintCtx(&mpm_ctx); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); if (cnt == 1) result = 1; @@ -1888,12 +1887,12 @@ int WmTestSearch01Hash15 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - ctx->scan_hash_size = HASH15_SIZE; - WmScanPreparePatterns(&mpm_ctx); + ctx->hash_size = HASH15_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); //mpm_ctx.PrintCtx(&mpm_ctx); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); if (cnt == 1) result = 1; @@ -1916,12 +1915,12 @@ int WmTestSearch01Hash16 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - ctx->scan_hash_size = HASH16_SIZE; - WmScanPreparePatterns(&mpm_ctx); + ctx->hash_size = HASH16_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); //mpm_ctx.PrintCtx(&mpm_ctx); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcd", 4); if (cnt == 1) result = 1; @@ -1942,10 +1941,10 @@ int WmTestSearch02 (void) { WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abce", 4); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abce", 4); if (cnt == 0) result = 1; @@ -1964,10 +1963,10 @@ int WmTestSearch03 (void) { WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); if (cnt == 1) result = 1; else @@ -1987,10 +1986,10 @@ int WmTestSearch04 (void) { WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; WmAddPattern(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); if (cnt == 1) result = 1; @@ -2009,10 +2008,10 @@ int WmTestSearch05 (void) { WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; WmAddPattern(&mpm_ctx, (uint8_t *)"efgh", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); if (cnt == 1) result = 1; @@ -2031,10 +2030,10 @@ int WmTestSearch06 (void) { WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; WmAddPattern(&mpm_ctx, (uint8_t *)"eFgH", 4, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdEfGh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdEfGh", 8); if (cnt == 1) result = 1; @@ -2054,10 +2053,10 @@ int WmTestSearch07 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 1, 0, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"eFgH", 4, 0, 0, 1, 1, 1, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdEfGh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdEfGh", 8); if (cnt == 2) result = 1; @@ -2077,10 +2076,10 @@ int WmTestSearch08 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"abcde", 5, 0, 0, 1, 1, 0, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 1, 1, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); if (cnt == 2) result = 1; @@ -2099,10 +2098,10 @@ int WmTestSearch09 (void) { WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; WmAddPattern(&mpm_ctx, (uint8_t *)"ab", 2, 0, 0, 1, 1, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"ab", 2); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"ab", 2); if (cnt == 1) result = 1; @@ -2121,11 +2120,11 @@ int WmTestSearch10 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"bc", 2, 0, 0, 1, 1, 0, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"gh", 2, 0, 0, 1, 1, 1, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 2); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); if (cnt == 2) result = 1; @@ -2145,11 +2144,11 @@ int WmTestSearch11 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"a", 1, 0, 0, 1, 1, 0, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"d", 1, 0, 0, 1, 1, 1, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"h", 1, 0, 0, 1, 1, 2, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); if (cnt == 3) result = 1; @@ -2170,10 +2169,10 @@ int WmTestSearch12 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 1, 1, 0, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"d", 1, 0, 0, 1, 1, 1, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"Z", 1, 0, 0, 1, 1, 2, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); if (cnt == 2) result = 1; @@ -2196,10 +2195,10 @@ int WmTestSearch13 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"a", 1, 0, 0, 1, 1, 0, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"de",2, 0, 0, 1, 1, 1, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"h", 1, 0, 0, 1, 1, 2, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); if (cnt == 3) result = 1; @@ -2222,10 +2221,10 @@ int WmTestSearch14 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 1, 1, 0, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"de",2, 0, 0, 1, 1, 1, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"Z", 1, 0, 0, 1, 1, 2, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); if (cnt == 2) result = 1; @@ -2248,10 +2247,10 @@ int WmTestSearch15 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 1, 1, 0, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"de",2, 0, 0, 1, 1, 1, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"Z", 1, 0, 0, 1, 1, 2, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); uint32_t len = mpm_thread_ctx.match[1].len; @@ -2275,10 +2274,10 @@ int WmTestSearch16 (void) { WmAddPattern(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 1, 1, 0, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"de",2, 0, 0, 1, 1, 1, 0, 0); WmAddPattern(&mpm_ctx, (uint8_t *)"Z", 1, 0, 0, 1, 1, 2, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 3); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"abcdefgh", 8); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2299,11 +2298,11 @@ int WmTestSearch17 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2324,12 +2323,12 @@ int WmTestSearch18Hash12 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH12_SIZE; - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH12_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2349,12 +2348,12 @@ int WmTestSearch18Hash14 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH14_SIZE; - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH14_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2374,12 +2373,12 @@ int WmTestSearch18Hash15 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH15_SIZE; - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH15_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2399,12 +2398,12 @@ int WmTestSearch18 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH16_SIZE; - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH16_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2425,12 +2424,12 @@ int WmTestSearch18Hash16 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH16_SIZE; - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH16_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2451,11 +2450,11 @@ int WmTestSearch19 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2476,12 +2475,12 @@ int WmTestSearch19Hash12 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH12_SIZE; - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH12_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2502,12 +2501,12 @@ int WmTestSearch19Hash14 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH14_SIZE; - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH14_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2528,12 +2527,12 @@ int WmTestSearch19Hash15 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH15_SIZE; - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH15_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2554,12 +2553,12 @@ int WmTestSearch19Hash16 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH16_SIZE; - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCI(&mpm_ctx, (uint8_t *)"/VideoAccessCodecInstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH16_SIZE; + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstaLL.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2580,11 +2579,11 @@ int WmTestSearch20 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2605,12 +2604,12 @@ int WmTestSearch20Hash12 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH12_SIZE; /* force hash12 */ - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH12_SIZE; /* force hash12 */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2630,12 +2629,12 @@ int WmTestSearch20Hash14 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH14_SIZE; /* force hash14 */ - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH14_SIZE; /* force hash14 */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2656,12 +2655,12 @@ int WmTestSearch20Hash15 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH15_SIZE; /* force hash15 */ - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH15_SIZE; /* force hash15 */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2682,12 +2681,12 @@ int WmTestSearch20Hash16 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH16_SIZE; /* force hash16 */ - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH16_SIZE; /* force hash16 */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/VideoAccessCodecInstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2708,11 +2707,11 @@ int WmTestSearch21 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2733,12 +2732,12 @@ static int WmTestSearch21Hash12 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH12_SIZE; /* force hash16 */ - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH12_SIZE; /* force hash16 */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); //WmPrintInfo(&mpm_ctx); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2759,12 +2758,12 @@ static int WmTestSearch21Hash14 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH14_SIZE; /* force hash16 */ - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH14_SIZE; /* force hash16 */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); //WmPrintInfo(&mpm_ctx); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2785,12 +2784,12 @@ static int WmTestSearch21Hash15 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH15_SIZE; /* force hash16 */ - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH15_SIZE; /* force hash16 */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); //WmPrintInfo(&mpm_ctx); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2811,12 +2810,12 @@ static int WmTestSearch21Hash16 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); - ctx->scan_hash_size = HASH16_SIZE; /* force hash16 */ - WmScanPreparePatterns(&mpm_ctx); + WmAddPatternCS(&mpm_ctx, (uint8_t *)"/videoaccesscodecinstall.exe", 28, 0, 0, 0, 0, 0); + ctx->hash_size = HASH16_SIZE; /* force hash16 */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); //WmPrintInfo(&mpm_ctx); - ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); + ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"/videoaccesscodecinstall.exe", 28); uint32_t len = mpm_thread_ctx.match[0].len; @@ -2837,19 +2836,19 @@ static int WmTestSearch22Hash9 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ /* total matches: 135 */ - ctx->scan_hash_size = HASH9_SIZE; /* force hash size */ - WmScanPreparePatterns(&mpm_ctx); + ctx->hash_size = HASH9_SIZE; /* force hash size */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 6 /* 6 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); if (cnt == 135) @@ -2870,19 +2869,19 @@ static int WmTestSearch22Hash12 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ /* total matches: 135 */ - ctx->scan_hash_size = HASH12_SIZE; /* force hash size */ - WmScanPreparePatterns(&mpm_ctx); + ctx->hash_size = HASH12_SIZE; /* force hash size */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 6 /* 6 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); if (cnt == 135) @@ -2903,19 +2902,19 @@ static int WmTestSearch22Hash14 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ /* total matches: 135 */ - ctx->scan_hash_size = HASH14_SIZE; /* force hash size */ - WmScanPreparePatterns(&mpm_ctx); + ctx->hash_size = HASH14_SIZE; /* force hash size */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 6 /* 6 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); if (cnt == 135) @@ -2936,19 +2935,19 @@ static int WmTestSearch22Hash15 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ /* total matches: 135 */ - ctx->scan_hash_size = HASH15_SIZE; /* force hash size */ - WmScanPreparePatterns(&mpm_ctx); + ctx->hash_size = HASH15_SIZE; /* force hash size */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 6 /* 6 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); if (cnt == 135) @@ -2969,19 +2968,19 @@ static int WmTestSearch22Hash16 (void) { MpmInitCtx(&mpm_ctx, MPM_WUMANBER, -1); WmCtx *ctx = (WmCtx *)mpm_ctx.ctx; - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ - WmAddScanPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"A", 1, 0, 0, 0, 0, 0); /* should match 30 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 1, 0, 0); /* should match 29 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAA", 3, 0, 0, 2, 0, 0); /* should match 28 times */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAA", 5, 0, 0, 3, 0, 0); /* 26 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAA", 10, 0, 0, 4, 0, 0); /* 21 */ + WmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30, 0, 0, 5, 0, 0); /* 1 */ /* total matches: 135 */ - ctx->scan_hash_size = HASH16_SIZE; /* force hash size */ - WmScanPreparePatterns(&mpm_ctx); + ctx->hash_size = HASH16_SIZE; /* force hash size */ + WmPreparePatterns(&mpm_ctx); WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 6 /* 6 patterns */); - uint32_t cnt = ctx->Scan(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); + uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30); if (cnt == 135) diff --git a/src/util-mpm-wumanber.h b/src/util-mpm-wumanber.h index e2b53fb152..e21c6a5c49 100644 --- a/src/util-mpm-wumanber.h +++ b/src/util-mpm-wumanber.h @@ -31,39 +31,39 @@ typedef struct WmCtx_ { /* hash used during ctx initialization */ WmPattern **init_hash; - uint16_t scan_shiftlen; + uint16_t shiftlen; - uint32_t scan_hash_size; - WmHashItem **scan_hash; - BloomFilter **scan_bloom; - uint8_t *scan_pminlen; /* array containing the minimal length + uint32_t hash_size; + WmHashItem **hash; + BloomFilter **bloom; + uint8_t *pminlen; /* array containing the minimal length of the patters in a hash bucket. Used for the BloomFilter. */ - WmHashItem scan_hash1[256]; + WmHashItem hash1[256]; /* we store our own scan ptr here for WmSearch1 */ - uint32_t (*Scan)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, uint8_t *, uint16_t); + uint32_t (*Search)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, uint8_t *, uint16_t); /* we store our own multi byte scan ptr here for WmSearch1 */ - uint32_t (*MBScan)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, uint8_t *, uint16_t); + uint32_t (*MBSearch)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, uint8_t *, uint16_t); /* pattern arrays */ WmPattern **parray; /* only used for multibyte pattern search */ - uint16_t *scan_shifttable; + uint16_t *shifttable; } WmCtx; typedef struct WmThreadCtx_ { #ifdef WUMANBER_COUNTERS - uint32_t scan_stat_pminlen_calls; - uint32_t scan_stat_pminlen_total; - uint32_t scan_stat_bloom_calls; - uint32_t scan_stat_bloom_hits; - uint32_t scan_stat_shift_null; - uint32_t scan_stat_loop_match; - uint32_t scan_stat_loop_no_match; - uint32_t scan_stat_num_shift; - uint32_t scan_stat_total_shift; + uint32_t stat_pminlen_calls; + uint32_t stat_pminlen_total; + uint32_t stat_bloom_calls; + uint32_t stat_bloom_hits; + uint32_t stat_shift_null; + uint32_t stat_loop_match; + uint32_t stat_loop_no_match; + uint32_t stat_num_shift; + uint32_t stat_total_shift; #endif /* WUMANBER_COUNTERS */ } WmThreadCtx; diff --git a/src/util-mpm.h b/src/util-mpm.h index 941f208e98..85faf5a1f8 100644 --- a/src/util-mpm.h +++ b/src/util-mpm.h @@ -89,8 +89,8 @@ typedef struct MpmCtx_ { uint32_t pattern_cnt; /* unique patterns */ uint32_t total_pattern_cnt; /* total patterns added */ - uint16_t scan_minlen; - uint16_t scan_maxlen; + uint16_t minlen; + uint16_t maxlen; } MpmCtx; typedef struct MpmTableElmt_ { @@ -100,13 +100,10 @@ typedef struct MpmTableElmt_ { void (*InitThreadCtx)(struct MpmCtx_ *, struct MpmThreadCtx_ *, uint32_t); void (*DestroyCtx)(struct MpmCtx_ *); void (*DestroyThreadCtx)(struct MpmCtx_ *, struct MpmThreadCtx_ *); - int (*AddScanPattern)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, uint8_t); - int (*AddScanPatternNocase)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, uint8_t); -// int (*AddPattern)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t); -// int (*AddPatternNocase)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t); + int (*AddPattern)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, uint8_t); + int (*AddPatternNocase)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, uint32_t, uint8_t); int (*Prepare)(struct MpmCtx_ *); - uint32_t (*Scan)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, uint8_t *, uint16_t); -// uint32_t (*Search)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, uint8_t *, uint16_t); + uint32_t (*Search)(struct MpmCtx_ *, struct MpmThreadCtx_ *, PatternMatcherQueue *, uint8_t *, uint16_t); void (*Cleanup)(struct MpmThreadCtx_ *); void (*PrintCtx)(struct MpmCtx_ *); void (*PrintThreadCtx)(struct MpmThreadCtx_ *);