From: Ken Steele Date: Fri, 5 Sep 2014 21:14:34 +0000 (-0400) Subject: Create a wrapper around DetectFlowvarProcessList() to check for empty list X-Git-Tag: suricata-2.1beta3~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b96645ded204c66670f2d09d2d06adb457c5c554;p=thirdparty%2Fsuricata.git Create a wrapper around DetectFlowvarProcessList() to check for empty list Creates an inline wrapper to check for flowvarlist == NULL before calling DetectFlowvarProcessList() to remove the overhead of checking since the list is usually empty. --- diff --git a/src/detect-flowvar.c b/src/detect-flowvar.c index b9f9696079..d764e085fd 100644 --- a/src/detect-flowvar.c +++ b/src/detect-flowvar.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2014 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -324,34 +324,27 @@ static int DetectFlowvarPostMatch(ThreadVars *tv, DetectEngineThreadCtx *det_ctx /** \brief Handle flowvar candidate list in det_ctx: * - clean up the list - * - enforce storage for type ALWAYS (luajit) */ -void DetectFlowvarProcessList(DetectEngineThreadCtx *det_ctx, Flow *f) + * - enforce storage for type ALWAYS (luajit) + * Only called from DetectFlowvarProcessList() when flowvarlist is not NULL . + */ +void DetectFlowvarProcessListInternal(DetectFlowvarList *fs, Flow *f) { - DetectFlowvarList *fs, *next; - - SCLogDebug("det_ctx->flowvarlist %p", det_ctx->flowvarlist); + DetectFlowvarList *next; - if (det_ctx->flowvarlist != NULL) { - fs = det_ctx->flowvarlist; - while (fs != NULL) { - next = fs->next; + do { + next = fs->next; - if (fs->type == DETECT_FLOWVAR_TYPE_ALWAYS) { - BUG_ON(f == NULL); - SCLogDebug("adding to the flow %u:", fs->idx); - //PrintRawDataFp(stdout, fs->buffer, fs->len); - - FlowVarAddStr(f, fs->idx, fs->buffer, fs->len); - /* memory at fs->buffer is now the responsibility of - * the flowvar code. */ - } else { - SCFree(fs->buffer); - } - SCFree(fs); - fs = next; - } + if (fs->type == DETECT_FLOWVAR_TYPE_ALWAYS) { + BUG_ON(f == NULL); + SCLogDebug("adding to the flow %u:", fs->idx); + //PrintRawDataFp(stdout, fs->buffer, fs->len); - det_ctx->flowvarlist = NULL; - } + FlowVarAddStr(f, fs->idx, fs->buffer, fs->len); + /* memory at fs->buffer is now the responsibility of + * the flowvar code. */ + } else + SCFree(fs->buffer); + SCFree(fs); + fs = next; + } while (fs != NULL); } - diff --git a/src/detect-flowvar.h b/src/detect-flowvar.h index a2975f0521..7ee12f02cc 100644 --- a/src/detect-flowvar.h +++ b/src/detect-flowvar.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2014 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -37,7 +37,19 @@ void DetectFlowvarRegister (void); int DetectFlowvarPostMatchSetup(Signature *s, uint16_t idx); int DetectFlowvarStoreMatch(DetectEngineThreadCtx *, uint16_t, uint8_t *, uint16_t, int); -void DetectFlowvarProcessList(DetectEngineThreadCtx *det_ctx, Flow *); -#endif /* __DETECT_FLOWVAR_H__ */ +/* For use only by DetectFlowvarProcessList() */ +void DetectFlowvarProcessListInternal(DetectFlowvarList *fs, Flow *f); +static inline void DetectFlowvarProcessList(DetectEngineThreadCtx *det_ctx, Flow *f) +{ + DetectFlowvarList *fs = det_ctx->flowvarlist; + + SCLogDebug("det_ctx->flowvarlist %p", fs); + if (fs != NULL) { + det_ctx->flowvarlist = NULL; + DetectFlowvarProcessListInternal(fs, f); + } +} + +#endif /* __DETECT_FLOWVAR_H__ */