]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/mpm: put transform into 'profile name'
authorVictor Julien <victor@inliniac.net>
Fri, 19 Jul 2019 14:05:30 +0000 (16:05 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 19 Jul 2019 20:05:34 +0000 (22:05 +0200)
So that profiling gives more info about cost of the mpm
engines when they use transforms.

src/detect-engine-mpm.c

index 63f24e9ea3413a3af8174e6edd68e3873547ec8b..ed9abae24d4920cdcf5171338a3ec7863595ad88 100644 (file)
@@ -57,6 +57,7 @@
 
 #include "stream.h"
 
+#include "util-misc.h"
 #include "util-enum.h"
 #include "util-debug.h"
 #include "util-print.h"
@@ -152,7 +153,6 @@ void DetectAppLayerMpmRegisterByParentId(DetectEngineCtx *de_ctx,
             DetectBufferMpmRegistery *am = SCCalloc(1, sizeof(*am));
             BUG_ON(am == NULL);
             am->name = t->name;
-            snprintf(am->pname, sizeof(am->pname), "%s#%d", am->name, id);
             am->direction = t->direction;
             am->sm_list = id; // use new id
             am->type = DETECT_BUFFER_MPM_TYPE_APP;
@@ -165,6 +165,32 @@ void DetectAppLayerMpmRegisterByParentId(DetectEngineCtx *de_ctx,
             am->next = t->next;
             if (transforms) {
                 memcpy(&am->transforms, transforms, sizeof(*transforms));
+
+                /* create comma separated string of the names of the
+                 * transforms and then shorten it if necessary. Finally
+                 * use it to construct the 'profile' name for the engine */
+                char xforms[1024] = "";
+                for (int i = 0; i < transforms->cnt; i++) {
+                    char ttstr[64];
+                    (void)snprintf(ttstr,sizeof(ttstr), "%s,",
+                            sigmatch_table[transforms->transforms[i]].name);
+                    strlcat(xforms, ttstr, sizeof(xforms));
+                }
+                xforms[strlen(xforms)-1] = '\0';
+
+                size_t space = sizeof(am->pname) - strlen(am->name) - 3;
+                char toprint[space + 1];
+                memset(toprint, 0x00, space + 1);
+                if (space < strlen(xforms)) {
+                    ShortenString(xforms, toprint, space, '~');
+                } else {
+                    strlcpy(toprint, xforms,sizeof(toprint));
+                }
+                (void)snprintf(am->pname, sizeof(am->pname), "%s#%d (%s)",
+                        am->name, id, toprint);
+            } else {
+                (void)snprintf(am->pname, sizeof(am->pname), "%s#%d",
+                        am->name, id);
             }
             am->id = de_ctx->app_mpms_list_cnt++;