From 2b84cd948381c3e33d728160a4c19b3a912bff94 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 5 Aug 2014 17:28:17 +0200 Subject: [PATCH] defrag: use 'struct timeval' for timeout tracking Until now the time out handling in defrag was done using a single uint32_t that tracked seconds. This lead to corner cases, where defrag trackers could be timed out a little too early. --- src/defrag-timeout.c | 2 +- src/defrag.c | 3 ++- src/defrag.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/defrag-timeout.c b/src/defrag-timeout.c index f77cc59cf9..663ee3b595 100644 --- a/src/defrag-timeout.c +++ b/src/defrag-timeout.c @@ -53,7 +53,7 @@ static int DefragTrackerTimedOut(DefragTracker *dt, struct timeval *ts) } /* retain if remove is not set and not timed out */ - if (!dt->remove && dt->timeout > (uint32_t)ts->tv_sec) + if (!dt->remove && timercmp(&dt->timeout, ts, >)) return 0; return 1; diff --git a/src/defrag.c b/src/defrag.c index a75978e013..c0088234df 100644 --- a/src/defrag.c +++ b/src/defrag.c @@ -579,7 +579,8 @@ DefragInsertFrag(ThreadVars *tv, DecodeThreadVars *dtv, DefragTracker *tracker, } /* Update timeout. */ - tracker->timeout = p->ts.tv_sec + tracker->host_timeout; + tracker->timeout.tv_sec = p->ts.tv_sec + tracker->host_timeout; + tracker->timeout.tv_usec = p->ts.tv_usec; Frag *prev = NULL, *next; int overlap = 0; diff --git a/src/defrag.h b/src/defrag.h index dd4aac09bd..8bd0325a34 100644 --- a/src/defrag.h +++ b/src/defrag.h @@ -110,7 +110,7 @@ typedef struct DefragTracker_ { Address src_addr; /**< Source address for this tracker. */ Address dst_addr; /**< Destination address for this tracker. */ - uint32_t timeout; /**< When this tracker will timeout. */ + struct timeval timeout; /**< When this tracker will timeout. */ uint32_t host_timeout; /**< Host timeout, statically assigned from the yaml */ /** use cnt, reference counter */ -- 2.47.2