flow: modify lastts update logic

In the lastts timeval struct field in the flow the timestamp of the
last packet to update is recorded. This allows for tracking the timeout
of the flow. So far, this value was updated under the flow lock and also
read under the flow lock.

This patch moves the updating of this field to the FlowGetFlowFromHash
function, where it updated at the point where both the Flow and the
Flow Hash Row lock are held. This guarantees that the field is only
updated when both locks are held.

This makes reading the field safe when either lock is held, which is the
purpose of this patch.

The flow manager, while holding the flow hash row lock, can now safely
read the lastts value. This allows it to do the flow timeout check
without actually locking the flow.
pull/1315/head
Victor Julien 11 years ago
parent a0732d3db2
commit 5587372ce1

@ -529,6 +529,9 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p
FlowInit(f, p);
f->fb = fb;
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
FBLOCK_UNLOCK(fb);
FlowHashCountUpdate;
return f;
@ -564,6 +567,9 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p
FlowInit(f, p);
f->fb = fb;
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
FBLOCK_UNLOCK(fb);
FlowHashCountUpdate;
return f;
@ -589,6 +595,9 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p
/* found our flow, lock & return */
FLOWLOCK_WRLOCK(f);
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
FBLOCK_UNLOCK(fb);
FlowHashCountUpdate;
return f;
@ -598,6 +607,9 @@ Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p
/* lock & return */
FLOWLOCK_WRLOCK(f);
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
FBLOCK_UNLOCK(fb);
FlowHashCountUpdate;
return f;

@ -246,9 +246,6 @@ void FlowHandlePacket(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
/* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
/* update flags and counters */
if (FlowGetPacketDirection(f, p) == TOSERVER) {
if (FlowUpdateSeenFlag(p)) {

@ -337,7 +337,9 @@ typedef struct Flow_
uint32_t flags;
/* time stamp of last update (last packet) */
/* time stamp of last update (last packet). Set/updated under the
* flow and flow hash row locks, safe to read under either the
* flow lock or flow hash row lock. */
struct timeval lastts;
#ifdef FLOWLOCK_RWLOCK

Loading…
Cancel
Save