mpm: allow app buffer shared/unique

Allow setting of shared or unique setting per app buffer type:
e.g. detect.mpm.http_uri.shared=true
pull/1980/head
Victor Julien 9 years ago
parent 79a96b2b90
commit 6ef27c9f92

@ -116,16 +116,33 @@ void DetectMpmInitializeAppMpms(DetectEngineCtx *de_ctx)
for (i = 0; i < APP_MPMS_MAX; i++) {
AppLayerMpms *am = &app_mpms[i];
if (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE) {
am->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(de_ctx, am->name);
} else {
/* default to whatever the global setting is */
int shared = (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE);
/* see if we use a unique or shared mpm ctx for this type */
int confshared = 0;
char confstring[256] = "detect.mpm.";
strlcat(confstring, am->name, sizeof(confstring));
strlcat(confstring, ".shared", sizeof(confstring));
if (ConfGetBool(confstring, &confshared) == 1)
shared = confshared;
if (shared == 0) {
SCLogInfo("using unique mpm ctx' for %s", am->name);
am->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
} else {
SCLogInfo("using shared mpm ctx' for %s", am->name);
am->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(de_ctx, am->name);
}
SCLogDebug("AppLayer MPM %s: %u", am->name, am->sgh_mpm_context);
}
}
/**
* \brief initialize mpm contexts for applayer buffers that are in
* "single or "shared" mode.
*/
void DetectMpmPrepareAppMpms(DetectEngineCtx *de_ctx)
{
int i;
@ -134,10 +151,13 @@ void DetectMpmPrepareAppMpms(DetectEngineCtx *de_ctx)
int dir = (am->direction == SIG_FLAG_TOSERVER) ? 1 : 0;
MpmCtx *mpm_ctx = MpmFactoryGetMpmCtxForProfile(de_ctx, am->sgh_mpm_context, dir);
if (mpm_ctx != NULL) {
if (mpm_table[de_ctx->mpm_matcher].Prepare != NULL) {
mpm_table[de_ctx->mpm_matcher].Prepare(mpm_ctx);
if (am->sgh_mpm_context != MPM_CTX_FACTORY_UNIQUE_CONTEXT)
{
MpmCtx *mpm_ctx = MpmFactoryGetMpmCtxForProfile(de_ctx, am->sgh_mpm_context, dir);
if (mpm_ctx != NULL) {
if (mpm_table[de_ctx->mpm_matcher].Prepare != NULL) {
mpm_table[de_ctx->mpm_matcher].Prepare(mpm_ctx);
}
}
}
}
@ -834,7 +854,7 @@ void MpmStoreSetup(const DetectEngineCtx *de_ctx, MpmStore *ms)
MpmFactoryReClaimMpmCtx(de_ctx, ms->mpm_ctx);
ms->mpm_ctx = NULL;
} else {
if (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_FULL) {
if (ms->sgh_mpm_context == MPM_CTX_FACTORY_UNIQUE_CONTEXT) {
if (mpm_table[ms->mpm_ctx->mpm_type].Prepare != NULL) {
mpm_table[ms->mpm_ctx->mpm_type].Prepare(ms->mpm_ctx);
}

@ -4197,8 +4197,6 @@ int SigGroupBuild(DetectEngineCtx *de_ctx)
}
//printf("stream- %d\n", mpm_ctx->pattern_cnt);
DetectMpmPrepareAppMpms(de_ctx);
#ifdef __SC_CUDA_SUPPORT__
if (PatternMatchDefaultMatcher() == MPM_AC_CUDA) {
int r = SCCudaCtxPopCurrent(NULL);
@ -4212,8 +4210,8 @@ int SigGroupBuild(DetectEngineCtx *de_ctx)
* \todo Support this. */
DetermineCudaStateTableSize(de_ctx);
#endif
}
DetectMpmPrepareAppMpms(de_ctx);
// DetectAddressPrintMemory();
// DetectSigGroupPrintMemory();

Loading…
Cancel
Save