Fix setting hash size in the config for b2g pattern matcher.

remotes/origin/master-1.1.x
Victor Julien 15 years ago
parent 697167319e
commit 4329261faa

@ -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);

@ -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)<<B2G_HASHSHIFT) | (b))
#define B2G_Q 2
#define B2G_SEARCHFUNC B2gSearchBNDMq
@ -51,25 +50,16 @@
//#define B2G_SEARCH2
//#define B2G_COUNTERS
#if 0
typedef struct B2gPattern_ {
uint8_t flags; /**< MPM_PATTERN_FLAG_* flags */
uint16_t len; /**< \todo we're limited to 32/64 byte lengths, uint8_t would be fine here */
uint8_t *cs; /* case sensitive */
uint8_t *ci; /* case INsensitive */
struct B2gPattern_ *next;
uint32_t id;
} B2gPattern;
#endif
typedef struct B2gPattern_ { //HashItem_ {
uint16_t len; /**< \todo we're limited to 32/64 byte lengths, uint8_t would be fine here */
uint8_t flags;
uint8_t pad0;
struct B2gPattern_ *next;
uint8_t *cs; /* case sensitive */
uint8_t *ci; /* case INsensitive */
uint8_t *cs; /* case sensitive */
uint32_t id;
} B2gPattern;//HashItem;
struct B2gPattern_ *next;
} B2gPattern;
typedef struct B2gCtx_ {
B2G_TYPE *B2G;

Loading…
Cancel
Save