]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Update all flow referencing to use the new FlowReference and FlowDeReference
authorAnoop Saldanha <anoopsaldanha@gmail.com>
Thu, 27 Sep 2012 12:55:37 +0000 (18:25 +0530)
committerVictor Julien <victor@inliniac.net>
Tue, 2 Oct 2012 08:20:09 +0000 (10:20 +0200)
macros.

src/app-layer.c
src/detect.c
src/flow-hash.c
src/flow-timeout.c
src/flow-util.h
src/flow.c
src/stream-tcp-reassemble.c
src/stream-tcp.c

index 6d49bce5496a5c184833fb6959220d09b8adfb74..be22283df60938e7ba316245c5117dcca15c5453 100644 (file)
@@ -30,6 +30,7 @@
 #include "stream-tcp-reassemble.h"
 #include "stream-tcp-private.h"
 #include "flow.h"
+#include "flow-util.h"
 
 #include "util-debug.h"
 #include "util-print.h"
@@ -258,17 +259,13 @@ int AppLayerHandleTCPMsg(AlpProtoDetectThreadCtx *dp_ctx, StreamMsg *smsg)
             }
         }
 
-        /* flow is free again */
-        FlowDecrUsecnt(smsg->flow);
-        /* dereference the flow */
-        smsg->flow = NULL;
+        FlowDeReference(&smsg->flow);
     } else { /* no ssn ptr */
         /* if there is no ssn ptr we won't
          * be inspecting this msg in detect
          * so return it to the pool. */
 
-        /* flow is free again */
-        FlowDecrUsecnt(smsg->flow);
+        FlowDeReference(&smsg->flow);
 
         /* return the used message to the queue */
         StreamMsgReturnToPool(smsg);
index 20e8bbda52e3d8875b00fe7dec0e076ba3f4c38c..484c0671a7fc414b5a376b28e4162eb5d954b416 100644 (file)
@@ -1426,8 +1426,6 @@ int SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineTh
             SCLogDebug("STREAM_EOF set");
         }
 
-        FlowIncrUsecnt(p->flow);
-
         FLOWLOCK_WRLOCK(p->flow);
         {
             /* live ruleswap check for flow updates */
@@ -1985,8 +1983,6 @@ end:
         StreamMsgReturnListToPool(smsg);
 
         FLOWLOCK_UNLOCK(p->flow);
-
-        FlowDecrUsecnt(p->flow);
     }
     PACKET_PROFILING_DETECT_END(p, PROF_DETECT_CLEANUP);
 
index 6d9b7ac87209b83998decd5a82b25467c280670b..283cbc480c07d5fb15056b65717d624ad8e408e5 100644 (file)
@@ -442,8 +442,6 @@ static Flow *FlowGetNew(Packet *p) {
         /* flow is initialized (recylced) but *unlocked* */
     }
 
-    FlowIncrUsecnt(f);
-
     FLOWLOCK_WRLOCK(f);
     return f;
 }
@@ -488,6 +486,8 @@ Flow *FlowGetFlowFromHash (Packet *p)
         fb->head = f;
         fb->tail = f;
 
+        FlowReference(&p->flow, f);
+
         /* got one, now lock, initialize and return */
         FlowInit(f,p);
         f->fb = fb;
@@ -523,6 +523,8 @@ Flow *FlowGetFlowFromHash (Packet *p)
 
                 f->hprev = pf;
 
+                FlowReference(&p->flow, f);
+
                 /* initialize and return */
                 FlowInit(f,p);
                 f->fb = fb;
@@ -550,8 +552,9 @@ Flow *FlowGetFlowFromHash (Packet *p)
                 fb->head->hprev = f;
                 fb->head = f;
 
+                FlowReference(&p->flow, f);
+
                 /* found our flow, lock & return */
-                FlowIncrUsecnt(f);
                 FLOWLOCK_WRLOCK(f);
                 FBLOCK_UNLOCK(fb);
                 FlowHashCountUpdate;
@@ -561,7 +564,7 @@ Flow *FlowGetFlowFromHash (Packet *p)
     }
 
     /* lock & return */
-    FlowIncrUsecnt(f);
+    FlowReference(&p->flow, f);
     FLOWLOCK_WRLOCK(f);
     FBLOCK_UNLOCK(fb);
     FlowHashCountUpdate;
index fc6f41249cbe25bdbcc9f7ef52f5473184f4ea7a..c3b15cc119dae8bf86cc8f94484dc96848d176d0 100644 (file)
@@ -113,8 +113,7 @@ static inline Packet *FlowForceReassemblyPseudoPacketSetup(Packet *p,
 {
     p->datalink = DLT_RAW;
     p->proto = IPPROTO_TCP;
-    p->flow = f;
-    FlowIncrUsecnt(f);
+    FlowReference(&p->flow, f);
     p->flags |= PKT_STREAM_EST;
     p->flags |= PKT_STREAM_EOF;
     p->flags |= PKT_HAS_FLOW;
index a44a553a8d2783413816aa8412d81bf70b9d12b4..21768bd3278fc942fb720d96c8ab42138ed4cf20 100644 (file)
 #define FLOW_CHECK_MEMCAP(size) \
     ((((uint64_t)SC_ATOMIC_GET(flow_memuse) + (uint64_t)(size)) <= flow_config.memcap))
 
-#define FlowReference(dst_f_ptr, f) do {        \
-        FlowIncrUsecnt((f));                    \
-        *(dst_f_ptr) = f;                       \
+#define FlowReference(dst_f_ptr, f) do {            \
+        if ((f) != NULL) {                          \
+            FlowIncrUsecnt((f));                    \
+            *(dst_f_ptr) = f;                       \
+        }                                           \
     } while (0)
 
-#define FlowDeReference(src_f_ptr) do {           \
-        FlowDecrUsecnt(*(src_f_ptr));   \
-        *(src_f_ptr) = NULL;                      \
+#define FlowDeReference(src_f_ptr) do {               \
+        if (*(src_f_ptr) != NULL) {                   \
+            FlowDecrUsecnt(*(src_f_ptr));             \
+            *(src_f_ptr) = NULL;                      \
+        }                                             \
     } while (0)
 
 Flow *FlowAlloc(void);
index 0a8462ce572029c8fb6fa6b44799a0f935e8bdfa..ad9931c1b62992376ad3f5d9e46f2b05f8c51579 100644 (file)
@@ -310,7 +310,6 @@ void FlowHandlePacket (ThreadVars *tv, Packet *p)
     FLOWLOCK_UNLOCK(f);
 
     /* set the flow in the packet */
-    p->flow = f;
     p->flags |= PKT_HAS_FLOW;
     return;
 }
index 9347c14509af50c36ae4945b7ec25f7e431e9b61..78ae7b052e20057acde5f0f981fc6e992c3c3d5c 100644 (file)
@@ -1714,11 +1714,9 @@ static void StreamTcpSetupMsg(TcpSession *ssn, TcpStream *stream, Packet *p,
     }
 
     smsg->data.data_len = 0;
-    smsg->flow = p->flow;
+    FlowReference(&smsg->flow, p->flow);
     BUG_ON(smsg->flow == NULL);
 
-    FlowIncrUsecnt(smsg->flow);
-
     SCLogDebug("smsg %p", smsg);
     SCReturn;
 }
index 596928f01387c199af9c268264ad705fa446ffc8..55cfde7d158e36af064a867737ae61ca3b9f250b 100644 (file)
@@ -4494,9 +4494,7 @@ Packet *StreamTcpPseudoSetup(Packet *parent, uint8_t *pkt, uint32_t len)
     p->ts.tv_sec = parent->ts.tv_sec;
     p->ts.tv_usec = parent->ts.tv_usec;
 
-    p->flow = parent->flow;
-    FlowIncrUsecnt(p->flow);
-
+    FlowReference(&p->flow, parent->flow);
     /* set tunnel flags */
 
     /* tell new packet it's part of a tunnel */