From bdd74d413b55632ce17a7f16bb8c5a532d891610 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 19 Jul 2019 16:05:30 +0200 Subject: [PATCH] detect/mpm: put transform into 'profile name' So that profiling gives more info about cost of the mpm engines when they use transforms. --- src/detect-engine-mpm.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/detect-engine-mpm.c b/src/detect-engine-mpm.c index 63f24e9ea3..ed9abae24d 100644 --- a/src/detect-engine-mpm.c +++ b/src/detect-engine-mpm.c @@ -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++;