]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm: refactor 'single' setup handling
authorVictor Julien <victor@inliniac.net>
Wed, 28 Oct 2015 08:17:45 +0000 (09:17 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 5 Apr 2016 07:37:42 +0000 (09:37 +0200)
src/detect-engine-mpm.c
src/detect.c

index c923b593611898eec2052573c619c07331ba6f05..dd454ce5a4618382b159cce23ba48c90e7887ba6 100644 (file)
@@ -116,7 +116,11 @@ void DetectMpmInitializeAppMpms(DetectEngineCtx *de_ctx)
     for (i = 0; i < APP_MPMS_MAX; i++) {
         AppLayerMpms *am = &app_mpms[i];
 
-        am->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(de_ctx, am->name);
+        if (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE) {
+            am->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(de_ctx, am->name);
+        } else {
+            am->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
+        }
 
         SCLogDebug("AppLayer MPM %s: %u", am->name, am->sgh_mpm_context);
     }
@@ -782,11 +786,7 @@ void MpmStoreSetup(const DetectEngineCtx *de_ctx, MpmStore *ms)
             dir = 0;
     }
 
-    if (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE) {
-        ms->mpm_ctx = MpmFactoryGetMpmCtxForProfile(de_ctx, ms->sgh_mpm_context, dir);
-    } else {
-        ms->mpm_ctx = MpmFactoryGetMpmCtxForProfile(de_ctx, MPM_CTX_FACTORY_UNIQUE_CONTEXT, dir);
-    }
+    ms->mpm_ctx = MpmFactoryGetMpmCtxForProfile(de_ctx, ms->sgh_mpm_context, dir);
     MpmInitCtx(ms->mpm_ctx, de_ctx->mpm_matcher);
 
     /* add the patterns */
index 40ba84bbb6af09898815cfbd476b130d9ba642c9..734117cf07617a90d20a933f25addc142fe5ef8c 100644 (file)
@@ -2730,14 +2730,21 @@ static int SignatureCreateMask(Signature *s)
 
 static void SigInitStandardMpmFactoryContexts(DetectEngineCtx *de_ctx)
 {
-    de_ctx->sgh_mpm_context_proto_tcp_packet =
-        MpmFactoryRegisterMpmCtxProfile(de_ctx, "packet_proto_tcp");
-    de_ctx->sgh_mpm_context_proto_udp_packet =
-        MpmFactoryRegisterMpmCtxProfile(de_ctx, "packet_proto_udp");
-    de_ctx->sgh_mpm_context_proto_other_packet =
-        MpmFactoryRegisterMpmCtxProfile(de_ctx, "packet_proto_other");
-    de_ctx->sgh_mpm_context_stream =
-        MpmFactoryRegisterMpmCtxProfile(de_ctx, "stream");
+    if (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE) {
+        de_ctx->sgh_mpm_context_proto_tcp_packet =
+            MpmFactoryRegisterMpmCtxProfile(de_ctx, "packet_proto_tcp");
+        de_ctx->sgh_mpm_context_proto_udp_packet =
+            MpmFactoryRegisterMpmCtxProfile(de_ctx, "packet_proto_udp");
+        de_ctx->sgh_mpm_context_proto_other_packet =
+            MpmFactoryRegisterMpmCtxProfile(de_ctx, "packet_proto_other");
+        de_ctx->sgh_mpm_context_stream =
+            MpmFactoryRegisterMpmCtxProfile(de_ctx, "stream");
+    } else {
+        de_ctx->sgh_mpm_context_proto_tcp_packet = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
+        de_ctx->sgh_mpm_context_proto_udp_packet = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
+        de_ctx->sgh_mpm_context_proto_other_packet = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
+        de_ctx->sgh_mpm_context_stream = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
+    }
 
     DetectMpmInitializeAppMpms(de_ctx);
 
@@ -4112,11 +4119,7 @@ int SigGroupBuild(DetectEngineCtx *de_ctx)
     if (DetectSetFastPatternAndItsId(de_ctx) < 0)
         return -1;
 
-    /* if we are using single sgh_mpm_context then let us init the standard mpm
-     * contexts using the mpm_ctx factory */
-    if (de_ctx->sgh_mpm_context == ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE) {
-        SigInitStandardMpmFactoryContexts(de_ctx);
-    }
+    SigInitStandardMpmFactoryContexts(de_ctx);
 
     if (SigAddressPrepareStage1(de_ctx) != 0) {
         SCLogError(SC_ERR_DETECT_PREPARE, "initializing the detection engine failed");