diff --git a/src/util-mpm-b2g.c b/src/util-mpm-b2g.c index 31d5185eaa..18d7b94887 100644 --- a/src/util-mpm-b2g.c +++ b/src/util-mpm-b2g.c @@ -54,8 +54,11 @@ static uint32_t b2g_hash_size = 0; static uint32_t b2g_bloom_size = 0; +static uint8_t b2g_hash_shift = 0; static void *b2g_func; +#define B2G_HASH16(a,b) (((a) << b2g_hash_shift) | (b)) + void B2gInitCtx (MpmCtx *, int); void B2gThreadInitCtx(MpmCtx *, MpmThreadCtx *, uint32_t); void B2gDestroyCtx(MpmCtx *); @@ -703,6 +706,7 @@ static void B2gGetConfig() /* init defaults */ b2g_hash_size = HASHSIZE_LOW; b2g_bloom_size = BLOOMSIZE_MEDIUM; + b2g_hash_shift = B2G_HASHSHIFT_LOW; b2g_func = B2G_SEARCHFUNC; ConfNode *pm = ConfGetNode("pattern-matcher"); @@ -710,7 +714,7 @@ static void B2gGetConfig() if (pm != NULL) { TAILQ_FOREACH(b2g_conf, &pm->head, next) { - if (strncmp(b2g_conf->val, "b2g", 3) == 0) { + if (strcmp(b2g_conf->val, "b2g") == 0) { algo = ConfNodeLookupChildValue (b2g_conf->head.tqh_first, "algo"); @@ -727,14 +731,35 @@ static void B2gGetConfig() } } - if (hash_val != NULL) + if (hash_val != NULL) { b2g_hash_size = MpmGetHashSize(hash_val); + switch (b2g_hash_size) { + case HASHSIZE_LOWEST: + b2g_hash_shift = B2G_HASHSHIFT_LOWEST; + break; + case HASHSIZE_LOW: + b2g_hash_shift = B2G_HASHSHIFT_LOW; + break; + case HASHSIZE_MEDIUM: + b2g_hash_shift = B2G_HASHSHIFT_MEDIUM; + break; + case HASHSIZE_HIGH: + b2g_hash_shift = B2G_HASHSHIFT_HIGH; + break; + case HASHSIZE_HIGHEST: + b2g_hash_shift = B2G_HASHSHIFT_HIGHEST; + break; + case HASHSIZE_MAX: + b2g_hash_shift = B2G_HASHSHIFT_MAX; + break; + } + } if (bloom_val != NULL) b2g_bloom_size = MpmGetBloomSize(bloom_val); SCLogDebug("hash size is %"PRIu32" and bloom size is %"PRIu32"", - b2g_hash_size, b2g_bloom_size); + b2g_hash_size, b2g_bloom_size); } } } @@ -1941,7 +1966,7 @@ static int B2gTestSearchXX (void) { char *word; char line[128]; int w = 0; - int w_max = 10000; + int w_max = 4000; while((word = fgets(line, sizeof(line), fp)) != NULL) { word[strlen(word) - 1] = '\0'; @@ -2634,6 +2659,8 @@ static int B2gTestSearchXX (void) { cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)text, len); } + printf("cnt %u ", cnt); + B2gThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); B2gDestroyCtx(&mpm_ctx); fclose(fp); diff --git a/src/util-mpm-b2g.h b/src/util-mpm-b2g.h index 5a290c5955..5255a844ac 100644 --- a/src/util-mpm-b2g.h +++ b/src/util-mpm-b2g.h @@ -27,12 +27,12 @@ #include "util-mpm.h" #include "util-bloomfilter.h" -//#define B2G_HASHSHIFT 8 -//#define B2G_HASHSHIFT 7 -//#define B2G_HASHSHIFT 6 -//#define B2G_HASHSHIFT 5 -#define B2G_HASHSHIFT 4 -//#define B2G_HASHSHIFT 3 +#define B2G_HASHSHIFT_MAX 8 +#define B2G_HASHSHIFT_HIGHEST 7 +#define B2G_HASHSHIFT_HIGH 6 +#define B2G_HASHSHIFT_MEDIUM 5 +#define B2G_HASHSHIFT_LOW 4 +#define B2G_HASHSHIFT_LOWEST 3 //#define B2G_TYPE uint64_t #define B2G_TYPE uint32_t @@ -43,7 +43,6 @@ //#define B2G_WORD_SIZE 16 //#define B2G_WORD_SIZE 8 -#define B2G_HASH16(a,b) (((a)<