flow engine: introduce FlowRequeueMoveToSpare

As part of a clean up of how FlowRequeue is used, introduce
FlowRequeueMoveToSpare for moving a flow from a locked queue to the
spare queue.
remotes/origin/master-1.2.x
Victor Julien 13 years ago
parent 7fa3df33f2
commit 0331da9773

@ -26,6 +26,7 @@
#include "suricata-common.h"
#include "threads.h"
#include "debug.h"
#include "flow-private.h"
#include "flow-queue.h"
#include "flow-util.h"
#include "util-error.h"
@ -212,3 +213,56 @@ void FlowRequeueMoveToBot(Flow *f, FlowQueue *q)
SCMutexUnlock(&q->mutex_q);
}
/**
* \brief Transfer a flow from a queue to the spare queue
*
* \param f the flow to be transfered
* \param q the source queue, where the flow will be removed. This queue is locked.
*
* \note spare queue needs locking
*/
void FlowRequeueMoveToSpare(Flow *f, FlowQueue *q)
{
#ifdef DEBUG
BUG_ON(q == NULL || f == NULL);
#endif /* DEBUG */
/* remove from old queue */
if (q->top == f)
q->top = f->lnext; /* remove from queue top */
if (q->bot == f)
q->bot = f->lprev; /* remove from queue bot */
if (f->lprev != NULL)
f->lprev->lnext = f->lnext; /* remove from flow prev */
if (f->lnext != NULL)
f->lnext->lprev = f->lprev; /* remove from flow next */
#ifdef DEBUG
BUG_ON(q->len == 0);
#endif
if (q->len > 0)
q->len--; /* adjust len */
f->lnext = NULL;
f->lprev = NULL;
/* now put it in spare */
SCMutexLock(&flow_spare_q.mutex_q);
/* add to new queue (append) */
f->lprev = flow_spare_q.bot;
if (f->lprev != NULL)
f->lprev->lnext = f;
f->lnext = NULL;
flow_spare_q.bot = f;
if (flow_spare_q.top == NULL)
flow_spare_q.top = f;
flow_spare_q.len++;
#ifdef DBG_PERF
if (flow_spare_q.len > flow_spare_q.dbg_maxlen)
flow_spare_q.dbg_maxlen = flow_spare_q.len;
#endif /* DBG_PERF */
SCMutexUnlock(&flow_spare_q.mutex_q);
}

@ -49,6 +49,7 @@ void FlowEnqueue (FlowQueue *, Flow *);
Flow *FlowDequeue (FlowQueue *);
void FlowRequeue(Flow *, FlowQueue *, FlowQueue *, uint8_t);
void FlowRequeueMoveToBot(Flow *, FlowQueue *);
void FlowRequeueMoveToSpare(Flow *, FlowQueue *);
#endif /* __FLOW_QUEUE_H__ */

@ -351,8 +351,10 @@ static int FlowPrune(FlowQueue *q, struct timeval *ts, int try_cnt)
cnt++;
FlowClearMemory (f, f->protomap);
Flow *next_flow = f->lnext;
/* move to spare list */
FlowRequeue(f, q, &flow_spare_q, 0);
FlowRequeueMoveToSpare(f, q);
SCMutexUnlock(&f->m);
f = next_flow;
@ -507,7 +509,7 @@ int FlowKill (FlowQueue *q)
FlowClearMemory (f, f->protomap);
/* move to spare list */
FlowRequeue(f, q, &flow_spare_q, 0);
FlowRequeueMoveToSpare(f, q);
SCMutexUnlock(&f->m);

Loading…
Cancel
Save