detect: introduce 'minimal' detect engine

The minimal detect engine has only the minimal memory use and setup
time. It's to be used for 'delayed' detect where the first detection
engine is essentially empty.

The threads setup are also minimal.
pull/1389/head
Victor Julien 11 years ago
parent f4617d5357
commit e7882da178

@ -817,7 +817,8 @@ void PatternMatchThreadPrint(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher)
void PatternMatchThreadDestroy(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher) void PatternMatchThreadDestroy(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher)
{ {
SCLogDebug("mpm_thread_ctx %p, mpm_matcher %"PRIu16"", mpm_thread_ctx, mpm_matcher); SCLogDebug("mpm_thread_ctx %p, mpm_matcher %"PRIu16"", mpm_thread_ctx, mpm_matcher);
mpm_table[mpm_matcher].DestroyThreadCtx(NULL, mpm_thread_ctx); if (mpm_table[mpm_matcher].DestroyThreadCtx != NULL)
mpm_table[mpm_matcher].DestroyThreadCtx(NULL, mpm_thread_ctx);
} }
void PatternMatchThreadPrepare(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher, uint32_t max_id) void PatternMatchThreadPrepare(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher, uint32_t max_id)
{ {

@ -966,7 +966,7 @@ void DetectEngineSpawnLiveRuleSwapMgmtThread(void)
SCReturn; SCReturn;
} }
DetectEngineCtx *DetectEngineCtxInit(void) static DetectEngineCtx *DetectEngineCtxInitReal(int minimal)
{ {
DetectEngineCtx *de_ctx; DetectEngineCtx *de_ctx;
@ -981,6 +981,12 @@ DetectEngineCtx *DetectEngineCtxInit(void)
memset(de_ctx,0,sizeof(DetectEngineCtx)); memset(de_ctx,0,sizeof(DetectEngineCtx));
if (minimal) {
de_ctx->minimal = 1;
de_ctx->id = detect_engine_ctx_id++;
return de_ctx;
}
if (ConfGetBool("engine.init-failure-fatal", (int *)&(de_ctx->failure_fatal)) != 1) { if (ConfGetBool("engine.init-failure-fatal", (int *)&(de_ctx->failure_fatal)) != 1) {
SCLogDebug("ConfGetBool could not load the value."); SCLogDebug("ConfGetBool could not load the value.");
} }
@ -1037,8 +1043,6 @@ DetectEngineCtx *DetectEngineCtxInit(void)
goto error; goto error;
} }
de_ctx->id = detect_engine_ctx_id++;
/* init iprep... ignore errors for now */ /* init iprep... ignore errors for now */
(void)SRepInit(de_ctx); (void)SRepInit(de_ctx);
@ -1053,9 +1057,21 @@ DetectEngineCtx *DetectEngineCtxInit(void)
goto error; goto error;
} }
de_ctx->id = detect_engine_ctx_id++;
return de_ctx; return de_ctx;
error: error:
return NULL; return NULL;
}
DetectEngineCtx *DetectEngineCtxInitMinimal(void)
{
return DetectEngineCtxInitReal(1);
}
DetectEngineCtx *DetectEngineCtxInit(void)
{
return DetectEngineCtxInitReal(0);
} }
static void DetectEngineCtxFreeThreadKeywordData(DetectEngineCtx *de_ctx) static void DetectEngineCtxFreeThreadKeywordData(DetectEngineCtx *de_ctx)
@ -1572,9 +1588,11 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
#endif #endif
} }
if (ThreadCtxDoInit(det_ctx->de_ctx, det_ctx) != TM_ECODE_OK) { if (det_ctx->de_ctx->minimal == 0) {
DetectEngineThreadCtxDeinit(tv, det_ctx); if (ThreadCtxDoInit(det_ctx->de_ctx, det_ctx) != TM_ECODE_OK) {
return TM_ECODE_FAILED; DetectEngineThreadCtxDeinit(tv, det_ctx);
return TM_ECODE_FAILED;
}
} }
/** alert counter setup */ /** alert counter setup */

@ -57,6 +57,7 @@ extern DetectEngineAppInspectionEngine *app_inspection_engine[FLOW_PROTO_DEFAULT
void DetectEngineRegisterAppInspectionEngines(void); void DetectEngineRegisterAppInspectionEngines(void);
void DetectEngineSpawnLiveRuleSwapMgmtThread(void); void DetectEngineSpawnLiveRuleSwapMgmtThread(void);
DetectEngineCtx *DetectEngineCtxInit(void); DetectEngineCtx *DetectEngineCtxInit(void);
DetectEngineCtx *DetectEngineCtxInitMinimal(void);
void DetectEngineCtxFree(DetectEngineCtx *); void DetectEngineCtxFree(DetectEngineCtx *);
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **); TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **);

@ -732,6 +732,9 @@ typedef struct DetectEngineCtx_ {
struct SCProfileKeywordDetectCtx_ *profile_keyword_ctx_per_list[DETECT_SM_LIST_MAX]; struct SCProfileKeywordDetectCtx_ *profile_keyword_ctx_per_list[DETECT_SM_LIST_MAX];
#endif #endif
/** minimal: essentially a stub */
int minimal;
/** how many de_ctx' are referencing this */ /** how many de_ctx' are referencing this */
uint32_t ref_cnt; uint32_t ref_cnt;
/** list in master: either active or freelist */ /** list in master: either active or freelist */

@ -2303,7 +2303,12 @@ int main(int argc, char **argv)
DetectEngineCtx *de_ctx = NULL; DetectEngineCtx *de_ctx = NULL;
if (!suri.disabled_detect) { if (!suri.disabled_detect) {
de_ctx = DetectEngineCtxInit(); SetupDelayedDetect(&suri);
if (!suri.delayed_detect) {
de_ctx = DetectEngineCtxInit();
} else {
de_ctx = DetectEngineCtxInitMinimal();
}
if (de_ctx == NULL) { if (de_ctx == NULL) {
SCLogError(SC_ERR_INITIALIZATION, "initializing detection engine " SCLogError(SC_ERR_INITIALIZATION, "initializing detection engine "
"context failed."); "context failed.");
@ -2315,7 +2320,6 @@ int main(int argc, char **argv)
CudaVarsSetDeCtx(de_ctx); CudaVarsSetDeCtx(de_ctx);
#endif /* __SC_CUDA_SUPPORT__ */ #endif /* __SC_CUDA_SUPPORT__ */
SetupDelayedDetect(&suri);
if (!suri.delayed_detect) { if (!suri.delayed_detect) {
if (LoadSignatures(de_ctx, &suri) != TM_ECODE_OK) if (LoadSignatures(de_ctx, &suri) != TM_ECODE_OK)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

Loading…
Cancel
Save