]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm factory: include alproto
authorVictor Julien <vjulien@oisf.net>
Sat, 18 Mar 2023 18:56:07 +0000 (19:56 +0100)
committerVictor Julien <vjulien@oisf.net>
Thu, 23 Mar 2023 10:33:48 +0000 (11:33 +0100)
In preparation of spliting out mpm's for keywords shared by
multiple protocols, like file.data.

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

index e29ddbe725fa5ec30197bd4c1b08737c613ed916..c83a3fb6dcbb74aa7e92e55be4ae5b5078722fdd 100644 (file)
@@ -167,7 +167,8 @@ void DetectAppLayerMpmRegisterByParentId(DetectEngineCtx *de_ctx,
             am->app_v2.tx_min_progress = t->app_v2.tx_min_progress;
             am->priority = t->priority;
             am->sgh_mpm_context = t->sgh_mpm_context;
-            am->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(de_ctx, am->name, am->sm_list);
+            am->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(
+                    de_ctx, am->name, am->sm_list, am->app_v2.alproto);
             am->next = t->next;
             if (transforms) {
                 memcpy(&am->transforms, transforms, sizeof(*transforms));
@@ -246,7 +247,8 @@ void DetectMpmInitializeAppMpms(DetectEngineCtx *de_ctx)
             n->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
         } else {
             SCLogDebug("using shared mpm ctx' for %s", n->name);
-            n->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(de_ctx, n->name, n->sm_list);
+            n->sgh_mpm_context =
+                    MpmFactoryRegisterMpmCtxProfile(de_ctx, n->name, n->sm_list, n->app_v2.alproto);
         }
 
         list = list->next;
@@ -415,7 +417,8 @@ void DetectEngineFrameMpmRegister(DetectEngineCtx *de_ctx, const char *name, int
     if (shared == 0) {
         am->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
     } else {
-        am->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(de_ctx, am->name, am->sm_list);
+        am->sgh_mpm_context =
+                MpmFactoryRegisterMpmCtxProfile(de_ctx, am->name, am->sm_list, alproto);
     }
 
     if (de_ctx->frame_mpms_list == NULL) {
@@ -471,7 +474,8 @@ void DetectMpmInitializeFrameMpms(DetectEngineCtx *de_ctx)
             n->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
         } else {
             SCLogDebug("using shared mpm ctx' for %s", n->name);
-            n->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(de_ctx, n->name, n->sm_list);
+            n->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(
+                    de_ctx, n->name, n->sm_list, n->frame_v1.alproto);
         }
 
         list = list->next;
@@ -639,7 +643,8 @@ void DetectMpmInitializePktMpms(DetectEngineCtx *de_ctx)
             n->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
         } else {
             SCLogDebug("using shared mpm ctx' for %s", n->name);
-            n->sgh_mpm_context = MpmFactoryRegisterMpmCtxProfile(de_ctx, n->name, n->sm_list);
+            n->sgh_mpm_context =
+                    MpmFactoryRegisterMpmCtxProfile(de_ctx, n->name, n->sm_list, ALPROTO_UNKNOWN);
         }
 
         list = list->next;
@@ -693,7 +698,7 @@ static int32_t SetupBuiltinMpm(DetectEngineCtx *de_ctx, const char *name)
         ctx = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
         SCLogDebug("using unique mpm ctx' for %s", name);
     } else {
-        ctx = MpmFactoryRegisterMpmCtxProfile(de_ctx, name, DETECT_SM_LIST_PMATCH);
+        ctx = MpmFactoryRegisterMpmCtxProfile(de_ctx, name, DETECT_SM_LIST_PMATCH, ALPROTO_UNKNOWN);
         SCLogDebug("using shared mpm ctx' for %s", name);
     }
     return ctx;
index 555286b8e964c31fcec481945f45570015a93876..1e05097ae584a35fc284a0804e593d3a80805fcd 100644 (file)
@@ -53,11 +53,12 @@ uint8_t mpm_default_matcher;
  *
  * \param name A new profile to be registered to store this MpmCtx.
  * \param sm_list sm_list for this name (might be variable with xforms)
+ * \param alproto app proto or ALPROTO_UNKNOWN if not for app-layer
  *
  * \retval id Return the id created for the new MpmCtx profile.
  */
 int32_t MpmFactoryRegisterMpmCtxProfile(
-        DetectEngineCtx *de_ctx, const char *name, const int sm_list)
+        DetectEngineCtx *de_ctx, const char *name, const int sm_list, const AppProto alproto)
 {
     /* the very first entry */
     if (de_ctx->mpm_ctx_factory_container == NULL) {
@@ -71,7 +72,8 @@ int32_t MpmFactoryRegisterMpmCtxProfile(
     MpmCtxFactoryItem *item = de_ctx->mpm_ctx_factory_container->items;
     MpmCtxFactoryItem *pitem = NULL;
     while (item) {
-        if (item->sm_list == sm_list && item->name != NULL && strcmp(item->name, name) == 0) {
+        if (item->sm_list == sm_list && item->alproto == alproto && item->name != NULL &&
+                strcmp(item->name, name) == 0) {
             return item->id;
         }
         pitem = item;
@@ -85,6 +87,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(
     nitem->name = name;
     nitem->sm_list = sm_list;
     nitem->id = de_ctx->mpm_ctx_factory_container->max_id++;
+    nitem->alproto = alproto;
 
     /* toserver */
     nitem->mpm_ctx_ts = SCCalloc(1, sizeof(MpmCtx));
index 1c6b17f3e1bcf04152d278d341621c2253838bfd..bf3772f9517243f22ff3cfdd0870de1a077b88fd 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef __UTIL_MPM_H__
 #define __UTIL_MPM_H__
 
+#include "app-layer-protos.h"
 #include "util-prefilter.h"
 
 #define MPM_INIT_HASH_SIZE 65536
@@ -118,6 +119,7 @@ typedef struct MpmCtxFactoryItem {
     MpmCtx *mpm_ctx_tc;
     int32_t id;
     int32_t sm_list;
+    AppProto alproto; /**< ALPROTO_UNKNOWN is not an app item */
     struct MpmCtxFactoryItem *next;
 } MpmCtxFactoryItem;
 
@@ -174,7 +176,8 @@ extern uint8_t mpm_default_matcher;
 
 struct DetectEngineCtx_;
 
-int32_t MpmFactoryRegisterMpmCtxProfile(struct DetectEngineCtx_ *, const char *, const int);
+int32_t MpmFactoryRegisterMpmCtxProfile(
+        struct DetectEngineCtx_ *, const char *, const int, const AppProto);
 void MpmFactoryReClaimMpmCtx(const struct DetectEngineCtx_ *, MpmCtx *);
 MpmCtx *MpmFactoryGetMpmCtxForProfile(const struct DetectEngineCtx_ *, int32_t, int);
 void MpmFactoryDeRegisterAllMpmCtxProfiles(struct DetectEngineCtx_ *);