From 7fa3df33f217c921cad1ef5b67d6ad1c53c5e547 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 7 Dec 2011 08:03:10 +0100 Subject: [PATCH] flow engine: introduce FlowRequeueMoveToBot As part of a clean up of how FlowRequeue is used, introduce FlowRequeueMoveToBot for moving a flow to the bottom of it's queue. --- src/flow-queue.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/flow-queue.h | 1 + src/flow.c | 10 +++++----- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/flow-queue.c b/src/flow-queue.c index 77357d1992..9a7a85bb10 100644 --- a/src/flow-queue.c +++ b/src/flow-queue.c @@ -172,3 +172,43 @@ void FlowRequeue(Flow *f, FlowQueue *srcq, FlowQueue *dstq, uint8_t need_srclock SCMutexUnlock(&dstq->mutex_q); } +/** + * \brief Move flow to bottom of queue + * + * \param f the flow to be transfered + * \param q the queue + */ +void FlowRequeueMoveToBot(Flow *f, FlowQueue *q) +{ +#ifdef DEBUG + BUG_ON(q == NULL || f == NULL); +#endif /* DEBUG */ + + SCMutexLock(&q->mutex_q); + + /* remove from the 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 */ + + /* readd to the queue (append) */ + f->lprev = q->bot; + + if (f->lprev != NULL) + f->lprev->lnext = f; + + f->lnext = NULL; + + q->bot = f; + + if (q->top == NULL) + q->top = f; + + SCMutexUnlock(&q->mutex_q); +} + diff --git a/src/flow-queue.h b/src/flow-queue.h index e4679daa28..76f0b3bac7 100644 --- a/src/flow-queue.h +++ b/src/flow-queue.h @@ -48,6 +48,7 @@ void FlowQueueDestroy (FlowQueue *); void FlowEnqueue (FlowQueue *, Flow *); Flow *FlowDequeue (FlowQueue *); void FlowRequeue(Flow *, FlowQueue *, FlowQueue *, uint8_t); +void FlowRequeueMoveToBot(Flow *, FlowQueue *); #endif /* __FLOW_QUEUE_H__ */ diff --git a/src/flow.c b/src/flow.c index 800eaf3523..83c87bebf4 100644 --- a/src/flow.c +++ b/src/flow.c @@ -112,7 +112,7 @@ void FlowUpdateQueue(Flow *f) f->flags |= FLOW_EST_LIST; /* transition */ f->flags &= ~FLOW_NEW_LIST; } else { - FlowRequeue(f, &flow_new_q[f->protomap], &flow_new_q[f->protomap], 1); + FlowRequeueMoveToBot(f, &flow_new_q[f->protomap]); } } else if (f->flags & FLOW_EST_LIST) { if (flow_proto[f->protomap].GetProtoState != NULL) { @@ -126,12 +126,12 @@ void FlowUpdateQueue(Flow *f) } else { /* Pull and put back -- this way the flows on * top of the list are least recently used. */ - FlowRequeue(f, &flow_est_q[f->protomap], &flow_est_q[f->protomap], 1); + FlowRequeueMoveToBot(f, &flow_est_q[f->protomap]); } } else { /* Pull and put back -- this way the flows on * top of the list are least recently used. */ - FlowRequeue(f, &flow_est_q[f->protomap], &flow_est_q[f->protomap], 1); + FlowRequeueMoveToBot(f, &flow_est_q[f->protomap]); } } else if (f->flags & FLOW_CLOSED_LIST){ /* for the case of ssn reuse in TCP sessions we need to be able to pull @@ -148,12 +148,12 @@ void FlowUpdateQueue(Flow *f) } else { /* Pull and put back -- this way the flows on * top of the list are least recently used. */ - FlowRequeue(f, &flow_close_q[f->protomap], &flow_close_q[f->protomap], 1); + FlowRequeueMoveToBot(f, &flow_close_q[f->protomap]); } } else { /* Pull and put back -- this way the flows on * top of the list are least recently used. */ - FlowRequeue(f, &flow_close_q[f->protomap], &flow_close_q[f->protomap], 1); + FlowRequeueMoveToBot(f, &flow_close_q[f->protomap]); } }