From: Victor Julien Date: Tue, 27 Jan 2015 10:30:08 +0000 (+0100) Subject: detect reload: allow master update during reload X-Git-Tag: suricata-2.1beta4~124 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=55e7370fc514258b83a26645633c8ee3c386617c;p=thirdparty%2Fsuricata.git detect reload: allow master update during reload Add DetectEngineReference, which takes a reference to a detect engine, and make DetectEngineThreadCtxInitForLiveRuleSwap use it. This way reload will not depend on master staying the same. This allows master to be updated in between w/o affecting the reload that is in progress. --- diff --git a/src/detect-engine.c b/src/detect-engine.c index 93aab65780..f9785c7c98 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -1308,7 +1308,7 @@ static TmEcode DetectEngineThreadCtxInitForLiveRuleSwap(ThreadVars *tv, void *in memset(det_ctx, 0, sizeof(DetectEngineThreadCtx)); det_ctx->tv = tv; - det_ctx->de_ctx = DetectEngineGetCurrent(); + det_ctx->de_ctx = DetectEngineReference(initdata); if (det_ctx->de_ctx == NULL) { return TM_ECODE_FAILED; } @@ -1527,6 +1527,14 @@ DetectEngineCtx *DetectEngineGetCurrent(void) return master->list; } +DetectEngineCtx *DetectEngineReference(DetectEngineCtx *de_ctx) +{ + if (de_ctx == NULL) + return NULL; + de_ctx->ref_cnt++; + return de_ctx; +} + void DetectEngineDeReference(DetectEngineCtx **de_ctx) { BUG_ON((*de_ctx)->ref_cnt == 0); diff --git a/src/detect-engine.h b/src/detect-engine.h index af58075134..b95f509ebb 100644 --- a/src/detect-engine.h +++ b/src/detect-engine.h @@ -72,6 +72,7 @@ int DetectEngineAddToMaster(DetectEngineCtx *de_ctx); DetectEngineCtx *DetectEngineGetCurrent(void); void DetectEnginePruneFreeList(void); int DetectEngineMoveToFreeList(DetectEngineCtx *de_ctx); +DetectEngineCtx *DetectEngineReference(DetectEngineCtx *); void DetectEngineDeReference(DetectEngineCtx **de_ctx); int DetectEngineReload(void); int DetectEngineEnabled(void);