]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm: allow app buffer shared/unique
authorVictor Julien <victor@inliniac.net>
Wed, 28 Oct 2015 16:02:40 +0000 (17:02 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 5 Apr 2016 07:37:42 +0000 (09:37 +0200)
Allow setting of shared or unique setting per app buffer type:
e.g. detect.mpm.http_uri.shared=true

src/detect-engine-mpm.c
src/detect.c

index dd454ce5a4618382b159cce23ba48c90e7887ba6..179085603f70478a36205ead28a373a909f5d84b 100644 (file)
@@ -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);
                 }
index 734117cf07617a90d20a933f25addc142fe5ef8c..a322bfc75561a1f10ee683b1659db722f7c9aaee 100644 (file)
@@ -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();