mirror of
https://github.com/OISF/suricata.git
synced 2026-10-12 02:07:10 +00:00
defrag: turn hash row into single linked list
This commit is contained in:
committed by
Victor Julien
parent
26a73503aa
commit
8b57545540
+2
-12
@@ -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);
|
||||
|
||||
@@ -60,7 +60,6 @@
|
||||
typedef struct DefragTrackerHashRow_ {
|
||||
DRLOCK_TYPE lock;
|
||||
DefragTracker *head;
|
||||
DefragTracker *tail;
|
||||
} DefragTrackerHashRow;
|
||||
|
||||
/** defrag tracker hash table */
|
||||
|
||||
+26
-25
@@ -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. */
|
||||
SCMutexUnlock(&dt->lock);
|
||||
|
||||
/* move to spare list */
|
||||
DefragTrackerMoveToSpare(dt);
|
||||
|
||||
cnt++;
|
||||
} else {
|
||||
if (DefragTrackerTimedOut(dt, ts) == 0) {
|
||||
prev_dt = dt;
|
||||
SCMutexUnlock(&dt->lock);
|
||||
dt = next_dt;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* remove from the hash */
|
||||
if (prev_dt != NULL) {
|
||||
prev_dt->hnext = dt->hnext;
|
||||
} else {
|
||||
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);
|
||||
|
||||
|
||||
+1
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user