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.
pull/1295/head
Ken Steele 11 years ago committed by Victor Julien
parent 5008d0a58b
commit b96645ded2

@ -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);
}

@ -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__ */

Loading…
Cancel
Save