]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: get flow reference during lookup
authorVictor Julien <victor@inliniac.net>
Tue, 17 Mar 2015 11:48:14 +0000 (12:48 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 20 May 2016 06:56:18 +0000 (08:56 +0200)
Update Flow lookup functions to get a flow reference during lookup.

This reference is set under the FlowBucket lock.

This paves the way to not getting a flow lock during lookups.

src/flow-hash.c
src/flow-hash.h
src/flow.c
src/flow.h
src/stream-tcp.c

index f6d746630c2a45960ba292a958851d22e1648b1e..20f1d36c611db5b48070091f03f1c57e25b58b66 100644 (file)
@@ -418,7 +418,7 @@ static Flow *FlowGetNew(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p)
     return f;
 }
 
-Flow *FlowGetFlowFromHashByPacket(const Packet *p)
+Flow *FlowGetFlowFromHashByPacket(const Packet *p, Flow **dest)
 {
     Flow *f = NULL;
 
@@ -448,6 +448,7 @@ Flow *FlowGetFlowFromHashByPacket(const Packet *p)
         f->fb = fb;
         /* update the last seen timestamp of this flow */
         COPY_TIMESTAMP(&p->ts,&f->lastts);
+        FlowReference(dest, f);
 
     }
     FBLOCK_UNLOCK(fb);
@@ -463,7 +464,7 @@ Flow *FlowGetFlowFromHashByPacket(const Packet *p)
  *
  *  \retval f flow or NULL if not found
  */
-Flow *FlowLookupFlowFromHash(const Packet *p)
+Flow *FlowLookupFlowFromHash(const Packet *p, Flow **dest)
 {
     Flow *f = NULL;
 
@@ -516,6 +517,7 @@ Flow *FlowLookupFlowFromHash(const Packet *p)
                 FLOWLOCK_WRLOCK(f);
                 /* update the last seen timestamp of this flow */
                 COPY_TIMESTAMP(&p->ts,&f->lastts);
+                FlowReference(dest, f);
 
                 FBLOCK_UNLOCK(fb);
                 return f;
@@ -527,6 +529,7 @@ Flow *FlowLookupFlowFromHash(const Packet *p)
     FLOWLOCK_WRLOCK(f);
     /* update the last seen timestamp of this flow */
     COPY_TIMESTAMP(&p->ts,&f->lastts);
+    FlowReference(dest, f);
 
     FBLOCK_UNLOCK(fb);
     return f;
@@ -549,7 +552,7 @@ Flow *FlowLookupFlowFromHash(const Packet *p)
  *
  *  \retval f *LOCKED* flow or NULL
  */
-Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p)
+Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p, Flow **dest)
 {
     Flow *f = NULL;
 
@@ -580,6 +583,7 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p
 
         /* update the last seen timestamp of this flow */
         COPY_TIMESTAMP(&p->ts,&f->lastts);
+        FlowReference(dest, f);
 
         FBLOCK_UNLOCK(fb);
         return f;
@@ -615,6 +619,7 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p
 
                 /* update the last seen timestamp of this flow */
                 COPY_TIMESTAMP(&p->ts,&f->lastts);
+                FlowReference(dest, f);
 
                 FBLOCK_UNLOCK(fb);
                 return f;
@@ -642,6 +647,7 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p
                 FLOWLOCK_WRLOCK(f);
                 /* update the last seen timestamp of this flow */
                 COPY_TIMESTAMP(&p->ts,&f->lastts);
+                FlowReference(dest, f);
 
                 FBLOCK_UNLOCK(fb);
                 return f;
@@ -653,6 +659,7 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p
     FLOWLOCK_WRLOCK(f);
     /* update the last seen timestamp of this flow */
     COPY_TIMESTAMP(&p->ts,&f->lastts);
+    FlowReference(dest, f);
 
     FBLOCK_UNLOCK(fb);
     return f;
index 16d408521b543bb029a3977b6f0780dfeca7be6e..e570b055513cef6b46df5e97a17b137f2c17576a 100644 (file)
@@ -68,7 +68,7 @@ typedef struct FlowBucket_ {
 
 /* prototypes */
 
-Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *);
+Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *, Flow **);
 
 void FlowDisableTcpReuseHandling(void);
 
index a2e1a64cd42a826c69c99b15dad19bd4c48de103..9c3973e65495f7d4ff12ac9943856f1a32c55d86 100644 (file)
@@ -270,9 +270,6 @@ void FlowHandlePacketUpdate(Flow *f, Packet *p)
 {
     SCLogDebug("packet %"PRIu64" -- flow %p", p->pcap_cnt, f);
 
-    /* Point the Packet at the Flow */
-    FlowReference(&p->flow, f);
-
     /* update flags and counters */
     if (FlowGetPacketDirection(f, p) == TOSERVER) {
         f->todstpktcnt++;
@@ -329,7 +326,7 @@ void FlowHandlePacket(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
     /* Get this packet's flow from the hash. FlowHandlePacket() will setup
      * a new flow if nescesary. If we get NULL, we're out of flow memory.
      * The returned flow is locked. */
-    Flow *f = FlowGetFlowFromHash(tv, dtv, p);
+    Flow *f = FlowGetFlowFromHash(tv, dtv, p, &p->flow);
     if (f == NULL)
         return;
 
index 5953b55fcfaec4747c040a974b8964f183cf87fa..2085f32242ed66927ff3f9d2d707c9b722709e30 100644 (file)
@@ -580,8 +580,8 @@ uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags);
 void FlowHandlePacketUpdateRemove(Flow *f, Packet *p);
 void FlowHandlePacketUpdate(Flow *f, Packet *p);
 
-Flow *FlowGetFlowFromHashByPacket(const Packet *p);
-Flow *FlowLookupFlowFromHash(const Packet *p);
+Flow *FlowGetFlowFromHashByPacket(const Packet *p, Flow **dest);
+Flow *FlowLookupFlowFromHash(const Packet *p, Flow **dest);
 
 #endif /* __FLOW_H__ */
 
index b83d45c33644b00c7e329a7298d4778931b188fd..22cb446c8f4562b792b08085906e7431ebbf355c 100644 (file)
@@ -4920,7 +4920,7 @@ static void TcpSessionReuseHandle(Packet *p) {
      * a different thread. */
 
     /* Get a flow. It will be either a locked flow or NULL */
-    Flow *new_f = FlowGetFlowFromHashByPacket(p);
+    Flow *new_f = FlowGetFlowFromHashByPacket(p, &p->flow);
     if (new_f == NULL) {
         FlowDeReference(&old_f); // < can't disappear while usecnt >0
         return;
@@ -4992,7 +4992,7 @@ static void TcpSessionReuseHandleApplyToPacket(Packet *p)
     FlowDeReference(&p->flow); // < can't disappear while usecnt >0
 
     /* find the new flow that does belong to this packet */
-    Flow *new_f = FlowLookupFlowFromHash(p);
+    Flow *new_f = FlowLookupFlowFromHash(p, &p->flow);
     if (new_f == NULL) {
         // TODO reset packet flag wrt flow: direction, HAS_FLOW etc
         p->flags &= ~PKT_HAS_FLOW;