mpm factory: include alproto

In preparation of spliting out mpm's for keywords shared by
multiple protocols, like file.data.
pull/8624/head
Victor Julien 3 years ago
parent 416a780f69
commit a806445abf

@ -167,7 +167,8 @@ void DetectAppLayerMpmRegisterByParentId(DetectEngineCtx *de_ctx,
am->app_v2.tx_min_progress = t->app_v2.tx_min_progress; am->app_v2.tx_min_progress = t->app_v2.tx_min_progress;
am->priority = t->priority; am->priority = t->priority;
am->sgh_mpm_context = t->sgh_mpm_context; 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; am->next = t->next;
if (transforms) { if (transforms) {
memcpy(&am->transforms, transforms, sizeof(*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; n->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
} else { } else {
SCLogDebug("using shared mpm ctx' for %s", n->name); 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; list = list->next;
@ -415,7 +417,8 @@ void DetectEngineFrameMpmRegister(DetectEngineCtx *de_ctx, const char *name, int
if (shared == 0) { if (shared == 0) {
am->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT; am->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
} else { } 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) { 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; n->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
} else { } else {
SCLogDebug("using shared mpm ctx' for %s", n->name); 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; list = list->next;
@ -639,7 +643,8 @@ void DetectMpmInitializePktMpms(DetectEngineCtx *de_ctx)
n->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT; n->sgh_mpm_context = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
} else { } else {
SCLogDebug("using shared mpm ctx' for %s", n->name); 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; list = list->next;
@ -693,7 +698,7 @@ static int32_t SetupBuiltinMpm(DetectEngineCtx *de_ctx, const char *name)
ctx = MPM_CTX_FACTORY_UNIQUE_CONTEXT; ctx = MPM_CTX_FACTORY_UNIQUE_CONTEXT;
SCLogDebug("using unique mpm ctx' for %s", name); SCLogDebug("using unique mpm ctx' for %s", name);
} else { } 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); SCLogDebug("using shared mpm ctx' for %s", name);
} }
return ctx; return ctx;

@ -53,11 +53,12 @@ uint8_t mpm_default_matcher;
* *
* \param name A new profile to be registered to store this MpmCtx. * \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 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. * \retval id Return the id created for the new MpmCtx profile.
*/ */
int32_t MpmFactoryRegisterMpmCtxProfile( 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 */ /* the very first entry */
if (de_ctx->mpm_ctx_factory_container == NULL) { 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 *item = de_ctx->mpm_ctx_factory_container->items;
MpmCtxFactoryItem *pitem = NULL; MpmCtxFactoryItem *pitem = NULL;
while (item) { 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; return item->id;
} }
pitem = item; pitem = item;
@ -85,6 +87,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(
nitem->name = name; nitem->name = name;
nitem->sm_list = sm_list; nitem->sm_list = sm_list;
nitem->id = de_ctx->mpm_ctx_factory_container->max_id++; nitem->id = de_ctx->mpm_ctx_factory_container->max_id++;
nitem->alproto = alproto;
/* toserver */ /* toserver */
nitem->mpm_ctx_ts = SCCalloc(1, sizeof(MpmCtx)); nitem->mpm_ctx_ts = SCCalloc(1, sizeof(MpmCtx));

@ -24,6 +24,7 @@
#ifndef __UTIL_MPM_H__ #ifndef __UTIL_MPM_H__
#define __UTIL_MPM_H__ #define __UTIL_MPM_H__
#include "app-layer-protos.h"
#include "util-prefilter.h" #include "util-prefilter.h"
#define MPM_INIT_HASH_SIZE 65536 #define MPM_INIT_HASH_SIZE 65536
@ -118,6 +119,7 @@ typedef struct MpmCtxFactoryItem {
MpmCtx *mpm_ctx_tc; MpmCtx *mpm_ctx_tc;
int32_t id; int32_t id;
int32_t sm_list; int32_t sm_list;
AppProto alproto; /**< ALPROTO_UNKNOWN is not an app item */
struct MpmCtxFactoryItem *next; struct MpmCtxFactoryItem *next;
} MpmCtxFactoryItem; } MpmCtxFactoryItem;
@ -174,7 +176,8 @@ extern uint8_t mpm_default_matcher;
struct DetectEngineCtx_; 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 *); void MpmFactoryReClaimMpmCtx(const struct DetectEngineCtx_ *, MpmCtx *);
MpmCtx *MpmFactoryGetMpmCtxForProfile(const struct DetectEngineCtx_ *, int32_t, int); MpmCtx *MpmFactoryGetMpmCtxForProfile(const struct DetectEngineCtx_ *, int32_t, int);
void MpmFactoryDeRegisterAllMpmCtxProfiles(struct DetectEngineCtx_ *); void MpmFactoryDeRegisterAllMpmCtxProfiles(struct DetectEngineCtx_ *);

Loading…
Cancel
Save