mpm: track maxdepth

Track max depth setting per MpmCtx.

To make sure the data structure doesn't increase in size change global
bool to use a flags field.
pull/3739/head
Victor Julien 6 years ago
parent 55e5d50496
commit 636fb8d387

@ -863,7 +863,7 @@ static void MpmStoreFreeFunc(void *ptr)
{ {
MpmStore *ms = ptr; MpmStore *ms = ptr;
if (ms != NULL) { if (ms != NULL) {
if (ms->mpm_ctx != NULL && !ms->mpm_ctx->global) if (ms->mpm_ctx != NULL && !(ms->mpm_ctx->flags & MPMCTX_FLAGS_GLOBAL))
{ {
SCLogDebug("destroying mpm_ctx %p", ms->mpm_ctx); SCLogDebug("destroying mpm_ctx %p", ms->mpm_ctx);
mpm_table[ms->mpm_ctx->mpm_type].DestroyCtx(ms->mpm_ctx); mpm_table[ms->mpm_ctx->mpm_type].DestroyCtx(ms->mpm_ctx);

@ -79,7 +79,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *nam
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(item[0].mpm_ctx_ts, 0, sizeof(MpmCtx)); memset(item[0].mpm_ctx_ts, 0, sizeof(MpmCtx));
item[0].mpm_ctx_ts->global = 1; item[0].mpm_ctx_ts->flags |= MPMCTX_FLAGS_GLOBAL;
/* toclient */ /* toclient */
item[0].mpm_ctx_tc = SCMalloc(sizeof(MpmCtx)); item[0].mpm_ctx_tc = SCMalloc(sizeof(MpmCtx));
@ -88,7 +88,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *nam
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(item[0].mpm_ctx_tc, 0, sizeof(MpmCtx)); memset(item[0].mpm_ctx_tc, 0, sizeof(MpmCtx));
item[0].mpm_ctx_tc->global = 1; item[0].mpm_ctx_tc->flags |= MPMCTX_FLAGS_GLOBAL;
/* our id starts from 0 always. Helps us with the ctx retrieval from /* our id starts from 0 always. Helps us with the ctx retrieval from
* the array */ * the array */
@ -113,7 +113,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *nam
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(items[i].mpm_ctx_ts, 0, sizeof(MpmCtx)); memset(items[i].mpm_ctx_ts, 0, sizeof(MpmCtx));
items[i].mpm_ctx_ts->global = 1; items[i].mpm_ctx_ts->flags |= MPMCTX_FLAGS_GLOBAL;
} }
if (items[i].mpm_ctx_tc == NULL) { if (items[i].mpm_ctx_tc == NULL) {
items[i].mpm_ctx_tc = SCMalloc(sizeof(MpmCtx)); items[i].mpm_ctx_tc = SCMalloc(sizeof(MpmCtx));
@ -122,7 +122,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *nam
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(items[i].mpm_ctx_tc, 0, sizeof(MpmCtx)); memset(items[i].mpm_ctx_tc, 0, sizeof(MpmCtx));
items[i].mpm_ctx_tc->global = 1; items[i].mpm_ctx_tc->flags |= MPMCTX_FLAGS_GLOBAL;
} }
return items[i].id; return items[i].id;
} }
@ -151,7 +151,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *nam
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(new_item[0].mpm_ctx_ts, 0, sizeof(MpmCtx)); memset(new_item[0].mpm_ctx_ts, 0, sizeof(MpmCtx));
new_item[0].mpm_ctx_ts->global = 1; new_item[0].mpm_ctx_ts->flags |= MPMCTX_FLAGS_GLOBAL;
/* toclient */ /* toclient */
new_item[0].mpm_ctx_tc = SCMalloc(sizeof(MpmCtx)); new_item[0].mpm_ctx_tc = SCMalloc(sizeof(MpmCtx));
@ -160,7 +160,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *nam
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(new_item[0].mpm_ctx_tc, 0, sizeof(MpmCtx)); memset(new_item[0].mpm_ctx_tc, 0, sizeof(MpmCtx));
new_item[0].mpm_ctx_tc->global = 1; new_item[0].mpm_ctx_tc->flags |= MPMCTX_FLAGS_GLOBAL;
new_item[0].id = de_ctx->mpm_ctx_factory_container->no_of_items; new_item[0].id = de_ctx->mpm_ctx_factory_container->no_of_items;
de_ctx->mpm_ctx_factory_container->no_of_items++; de_ctx->mpm_ctx_factory_container->no_of_items++;
@ -556,6 +556,17 @@ int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
mpm_ctx->pattern_cnt++; mpm_ctx->pattern_cnt++;
if (!(mpm_ctx->flags & MPMCTX_FLAGS_NODEPTH)) {
if (depth) {
mpm_ctx->maxdepth = MAX(mpm_ctx->maxdepth, depth);
SCLogDebug("%p: depth %u max %u", mpm_ctx, depth, mpm_ctx->maxdepth);
} else {
mpm_ctx->flags |= MPMCTX_FLAGS_NODEPTH;
mpm_ctx->maxdepth = 0;
SCLogDebug("%p: alas, no depth for us", mpm_ctx);
}
}
if (mpm_ctx->maxlen < patlen) if (mpm_ctx->maxlen < patlen)
mpm_ctx->maxlen = patlen; mpm_ctx->maxlen = patlen;

@ -79,15 +79,19 @@ typedef struct MpmPattern_ {
struct MpmPattern_ *next; struct MpmPattern_ *next;
} MpmPattern; } MpmPattern;
/* Indicates if this a global mpm_ctx. Global mpm_ctx is the one that
* is instantiated when we use "single". Non-global is "full", i.e.
* one per sgh. */
#define MPMCTX_FLAGS_GLOBAL BIT_U8(0)
#define MPMCTX_FLAGS_NODEPTH BIT_U8(1)
typedef struct MpmCtx_ { typedef struct MpmCtx_ {
void *ctx; void *ctx;
uint16_t mpm_type; uint8_t mpm_type;
uint8_t flags;
/* Indicates if this a global mpm_ctx. Global mpm_ctx is the one that uint16_t maxdepth;
* is instantiated when we use "single". Non-global is "full", i.e.
* one per sgh. We are using a uint16_t here to avoiding using a pad.
* You can use a uint8_t here as well. */
uint16_t global;
/* unique patterns */ /* unique patterns */
uint32_t pattern_cnt; uint32_t pattern_cnt;

Loading…
Cancel
Save