]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Create a wrapper around DetectFlowvarProcessList() to check for empty list
authorKen Steele <ken@tilera.com>
Fri, 5 Sep 2014 21:14:34 +0000 (17:14 -0400)
committerVictor Julien <victor@inliniac.net>
Thu, 15 Jan 2015 10:52:02 +0000 (11:52 +0100)
Creates an inline wrapper to check for flowvarlist == NULL before calling
DetectFlowvarProcessList() to remove the overhead of checking since the
list is usually empty.

src/detect-flowvar.c
src/detect-flowvar.h

index b9f9696079fc04584e2ad829040b2d2105a5e29b..d764e085fdbfbb06e3cf510af9b1cd060aaeb368 100644 (file)
@@ -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);
 }
-
index a2975f05210cf17bfdff57c7276f35b301f00ad0..7ee12f02ccd7c653dd9b898cfd75c9c5444f67c9 100644 (file)
@@ -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__ */