{
BUG_ON(PatternMatchPrepareGroup(de_ctx, sgh) != 0);
- /* set up engines if needed - independent of 'detect.prefilter.default'
- * setting as the prefilter keyword may have enabled individual sigs */
+ /* set up engines if needed - when prefilter is set to auto we run
+ * all engines, otherwise only those that have been forced by the
+ * prefilter keyword. */
+ const enum DetectEnginePrefilterSetting setting = de_ctx->prefilter_setting;
for (int i = 0; i < DETECT_TBLSIZE; i++)
{
- if (sigmatch_table[i].SetupPrefilter != NULL) {
+ if (sigmatch_table[i].SetupPrefilter != NULL &&
+ (setting == DETECT_PREFILTER_AUTO ||
+ (de_ctx->sm_types_prefilter && de_ctx->sm_types_prefilter[i])))
+ {
sigmatch_table[i].SetupPrefilter(sgh);
}
}
cd->flags |= DETECT_CONTENT_FAST_PATTERN;
} else {
s->flags |= SIG_FLAG_PREFILTER;
+
+ /* make sure setup function runs for this type. */
+ if (de_ctx->sm_types_prefilter == NULL)
+ de_ctx->sm_types_prefilter = SCCalloc(sizeof(bool), DETECT_TBLSIZE);
+ if (de_ctx->sm_types_prefilter == NULL)
+ FatalError(SC_ERR_MEM_ALLOC, "failed to allocate sm_types_prefilter memory");
+ de_ctx->sm_types_prefilter[sm->type] = true;
}
SCReturnInt(0);
* \todo we only need this at init, so perhaps this
* can move to a DetectEngineCtx 'init' struct */
DetectMpmAppLayerKeyword *app_mpms;
+
+ /** per keyword flag indicating if a prefilter has been
+ * set for it. If true, the setup function will have to
+ * run. Will be alloc'd to DETECT_TBLSIZE if used. */
+ bool *sm_types_prefilter;
+
} DetectEngineCtx;
/* Engine groups profiles (low, medium, high, custom) */