]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
defrag: avoid to run cleaning repetitively
authorEric Leblond <eric@regit.org>
Thu, 6 Sep 2012 06:41:17 +0000 (08:41 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 6 Sep 2012 11:40:46 +0000 (13:40 +0200)
src/defrag.c

index d26dfd57a7daa7fd3d65f673f5433a3fe475b665..f78d5b19c5d879ca2daa164ad780d43fd3fdabce 100644 (file)
@@ -106,6 +106,7 @@ typedef struct DefragContext_ {
     SCMutex frag_pool_lock;
 
     time_t timeout; /**< Default timeout. */
+    time_t last_timeouted; /**< time of last cleaning */
 } DefragContext;
 
 /**
@@ -473,6 +474,8 @@ DefragContextNew(void)
         dc->timeout = timeout;
     }
 
+    dc->last_timeouted = 0;
+
     SCLogDebug("Defrag Initialized:");
     SCLogDebug("\tTimeout: %"PRIuMAX, (uintmax_t)dc->timeout);
     SCLogDebug("\tMaximum defrag trackers: %"PRIuMAX, tracker_pool_size);
@@ -1026,6 +1029,15 @@ DefragTimeoutTracker(ThreadVars *tv, DecodeThreadVars *dtv, DefragContext *dc,
 {
     HashListTableBucket *next = HashListTableGetListHead(dc->frag_table);
     DefragTracker *tracker;
+    struct timeval ts;
+
+    TimeGet(&ts);
+    /* If last cleaning was made in the current second, we leave */
+    if (dc->last_timeouted >= ts.tv_sec) {
+        return;
+    } else {
+        dc->last_timeouted = ts.tv_sec;
+    }
     while (next != NULL) {
         tracker = HashListTableGetListData(next);