]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
defrag: turn hash row into single linked list
authorVictor Julien <vjulien@oisf.net>
Wed, 22 May 2024 13:29:13 +0000 (15:29 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 4 Jun 2024 04:28:26 +0000 (06:28 +0200)
src/defrag-hash.c
src/defrag-hash.h
src/defrag-timeout.c
src/defrag.h

index b342abb23700a98deb06fc7d52735aaa9821b131..6f1b59ff7f70091dab3f98cf5b2f7c34ae39c373 100644 (file)
@@ -564,7 +564,6 @@ DefragTracker *DefragGetTrackerFromHash(ThreadVars *tv, DecodeThreadVars *dtv, P
 
         /* tracker is locked */
         hb->head = dt;
-        hb->tail = dt;
 
         /* got one, now lock, initialize and return */
         DefragTrackerInit(dt,p);
@@ -591,8 +590,7 @@ DefragTracker *DefragGetTrackerFromHash(ThreadVars *tv, DecodeThreadVars *dtv, P
                 DRLOCK_UNLOCK(hb);
                 return NULL;
             }
-            prev->hnext = hb->tail = dt;
-            dt->hprev = prev;
+            prev->hnext = dt;
 
             /* tracker is locked */
 
@@ -702,17 +700,9 @@ static DefragTracker *DefragTrackerGetUsedDefragTracker(void)
         }
 
         /* remove from the hash */
-        if (dt->hprev != NULL)
-            dt->hprev->hnext = dt->hnext;
-        if (dt->hnext != NULL)
-            dt->hnext->hprev = dt->hprev;
-        if (hb->head == dt)
-            hb->head = dt->hnext;
-        if (hb->tail == dt)
-            hb->tail = dt->hprev;
+        hb->head = dt->hnext;
 
         dt->hnext = NULL;
-        dt->hprev = NULL;
         DRLOCK_UNLOCK(hb);
 
         DefragTrackerClearMemory(dt);
index 5e7499f31c9c3194384337a78a036c85cd474af5..299967a492a79ddab5695e4f9b952711ccf13239 100644 (file)
@@ -60,7 +60,6 @@
 typedef struct DefragTrackerHashRow_ {
     DRLOCK_TYPE lock;
     DefragTracker *head;
-    DefragTracker *tail;
 } DefragTrackerHashRow;
 
 /** defrag tracker hash table */
index 44e57956e0c7f6965e9f6b1007e074190ea8b7d6..dff754ea267a0720f24cea7e99680b3a50378265 100644 (file)
@@ -67,8 +67,10 @@ static uint32_t DefragTrackerHashRowTimeout(
 {
     uint32_t cnt = 0;
 
+    DefragTracker *prev_dt = NULL;
     do {
         if (SCMutexTrylock(&dt->lock) != 0) {
+            prev_dt = dt;
             dt = dt->hnext;
             continue;
         }
@@ -77,34 +79,33 @@ static uint32_t DefragTrackerHashRowTimeout(
 
         /* check if the tracker is fully timed out and
          * ready to be discarded. */
-        if (DefragTrackerTimedOut(dt, ts) == 1) {
-            /* remove from the hash */
-            if (dt->hprev != NULL)
-                dt->hprev->hnext = dt->hnext;
-            if (dt->hnext != NULL)
-                dt->hnext->hprev = dt->hprev;
-            if (hb->head == dt)
-                hb->head = dt->hnext;
-            if (hb->tail == dt)
-                hb->tail = dt->hprev;
-
-            dt->hnext = NULL;
-            dt->hprev = NULL;
-
-            DefragTrackerClearMemory(dt);
-
-            /* no one is referring to this tracker, use_cnt 0, removed from hash
-             * so we can unlock it and move it back to the spare queue. */
+        if (DefragTrackerTimedOut(dt, ts) == 0) {
+            prev_dt = dt;
             SCMutexUnlock(&dt->lock);
+            dt = next_dt;
+            continue;
+        }
 
-            /* move to spare list */
-            DefragTrackerMoveToSpare(dt);
-
-            cnt++;
+        /* remove from the hash */
+        if (prev_dt != NULL) {
+            prev_dt->hnext = dt->hnext;
         } else {
-            SCMutexUnlock(&dt->lock);
+            hb->head = dt->hnext;
         }
 
+        dt->hnext = NULL;
+
+        DefragTrackerClearMemory(dt);
+
+        /* no one is referring to this tracker, use_cnt 0, removed from hash
+         * so we can unlock it and move it back to the spare queue. */
+        SCMutexUnlock(&dt->lock);
+
+        /* move to spare list */
+        DefragTrackerMoveToSpare(dt);
+
+        cnt++;
+
         dt = next_dt;
     } while (dt != NULL);
 
index b6f3338b94673746df127186044238d615fe755e..3fb65aeed80eea65f44f2722afd196b055d93105 100644 (file)
@@ -115,9 +115,8 @@ typedef struct DefragTracker_ {
 
     struct IP_FRAGMENTS fragment_tree;
 
-    /** hash pointers, protected by hash row mutex/spin */
+    /** hash pointer, protected by hash row mutex/spin */
     struct DefragTracker_ *hnext;
-    struct DefragTracker_ *hprev;
 
     /** list pointers, protected by tracker-queue mutex/spin */
     struct DefragTracker_ *lnext;