]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: immediately evict tcp reused flows 6539/head
authorVictor Julien <victor@inliniac.net>
Tue, 26 Oct 2021 09:09:51 +0000 (11:09 +0200)
committerVictor Julien <victor@inliniac.net>
Sat, 30 Oct 2021 12:19:57 +0000 (14:19 +0200)
Since we already know we're going to no longer use it, might as well
evict it right away.

src/flow-hash.c

index 9e8ea3d3093fb5473593eb53eaba660e597ed0b0..f43e9a84408bd5d93d89374c7f2a3eed4eb085c5 100644 (file)
@@ -809,11 +809,17 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, FlowLookupStruct *fls,
             FromHashLockCMP(f);//FLOWLOCK_WRLOCK(f);
             /* found a matching flow that is not timed out */
             if (unlikely(TcpSessionPacketSsnReuse(p, f, f->protoctx) == 1)) {
-                f = TcpReuseReplace(tv, fls, fb, f, hash, p);
-                if (f == NULL) {
+                Flow *new_f = TcpReuseReplace(tv, fls, fb, f, hash, p);
+                if (f->use_cnt == 0) {
+                    if (prev_f == NULL) /* if we have no prev it means new_f is now our prev */
+                        prev_f = new_f;
+                    MoveToWorkQueue(tv, fls, fb, f, prev_f); /* evict old flow */
+                }
+                if (new_f == NULL) {
                     FBLOCK_UNLOCK(fb);
                     return NULL;
                 }
+                f = new_f;
             }
             FlowReference(dest, f);
             FBLOCK_UNLOCK(fb);