From: Victor Julien Date: Thu, 23 May 2024 19:11:23 +0000 (+0200) Subject: defrag: timeout check on look up; tag for removal X-Git-Tag: suricata-8.0.0-beta1~1219 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=becc91c3065e9854f3bd74374bfef8eb6726f3c8;p=thirdparty%2Fsuricata.git defrag: timeout check on look up; tag for removal --- diff --git a/src/defrag-hash.c b/src/defrag-hash.c index 11fef806ea..2340826dab 100644 --- a/src/defrag-hash.c +++ b/src/defrag-hash.c @@ -20,6 +20,7 @@ #include "defrag-hash.h" #include "defrag-stack.h" #include "defrag-config.h" +#include "defrag-timeout.h" #include "util-random.h" #include "util-byte.h" #include "util-misc.h" @@ -557,14 +558,17 @@ DefragTracker *DefragGetTrackerFromHash(ThreadVars *tv, DecodeThreadVars *dtv, P dt = hb->head; do { - if (!dt->remove && DefragTrackerCompare(dt, p)) { + if (DefragTrackerTimedOut(dt, p->ts)) { + dt->remove = 1; + } else if (!dt->remove && DefragTrackerCompare(dt, p)) { /* found our tracker, lock & return */ SCMutexLock(&dt->lock); (void)DefragTrackerIncrUsecnt(dt); DRLOCK_UNLOCK(hb); return dt; + } - } else if (dt->hnext == NULL) { + if (dt->hnext == NULL) { DefragTracker *prev = dt; dt = DefragTrackerGetNew(tv, dtv, p); if (dt == NULL) { diff --git a/src/defrag-timeout.c b/src/defrag-timeout.c index dff754ea26..ea9ca3c9b4 100644 --- a/src/defrag-timeout.c +++ b/src/defrag-timeout.c @@ -36,7 +36,7 @@ * \retval 0 not timed out just yet * \retval 1 fully timed out, lets kill it */ -static int DefragTrackerTimedOut(DefragTracker *dt, SCTime_t ts) +int DefragTrackerTimedOut(DefragTracker *dt, SCTime_t ts) { /** never prune a trackers that is used by a packet * we are currently processing in one of the threads */ diff --git a/src/defrag-timeout.h b/src/defrag-timeout.h index 6a24fc0f42..38ff0248cf 100644 --- a/src/defrag-timeout.h +++ b/src/defrag-timeout.h @@ -24,6 +24,9 @@ #ifndef SURICATA_DEFRAG_TIMEOUT_H #define SURICATA_DEFRAG_TIMEOUT_H +#include "defrag.h" + +int DefragTrackerTimedOut(DefragTracker *dt, SCTime_t ts); uint32_t DefragTimeoutHash(SCTime_t ts); #endif