update flow pruning - v1

remotes/origin/master-1.1.x
Anoop Saldanha 14 years ago committed by Victor Julien
parent 272c2433ec
commit f197b32a55

@ -365,6 +365,12 @@ static inline int FlowForceReassemblyForFlowV2(ThreadVars *tv, Flow *f)
SCSpinUnlock(&f->fb->s); SCSpinUnlock(&f->fb->s);
if (suricata_ctl_flags != 0) { if (suricata_ctl_flags != 0) {
if (client_ok == 1) {
FlowDecrUsecnt(f);
}
if (server_ok == 1) {
FlowDecrUsecnt(f);
}
return 1; return 1;
} }
@ -482,6 +488,9 @@ static inline int FlowForceReassemblyForFlowV2(ThreadVars *tv, Flow *f)
static int FlowPrune(ThreadVars *tv, FlowQueue *q, struct timeval *ts) static int FlowPrune(ThreadVars *tv, FlowQueue *q, struct timeval *ts)
{ {
SCEnter(); SCEnter();
int cnt = 0;
Flow *qnext_f = NULL;
int mr = SCMutexTrylock(&q->mutex_q); int mr = SCMutexTrylock(&q->mutex_q);
if (mr != 0) { if (mr != 0) {
SCLogDebug("trylock failed"); SCLogDebug("trylock failed");
@ -497,6 +506,12 @@ static int FlowPrune(ThreadVars *tv, FlowQueue *q, struct timeval *ts)
} }
Flow *f = q->top; Flow *f = q->top;
/* label */
FlowPrune_Prune_Next:
if (suricata_ctl_flags != 0) {
SCMutexUnlock(&q->mutex_q);
return cnt;
}
if (f == NULL) { if (f == NULL) {
SCMutexUnlock(&q->mutex_q); SCMutexUnlock(&q->mutex_q);
SCLogDebug("top is null"); SCLogDebug("top is null");
@ -504,17 +519,18 @@ static int FlowPrune(ThreadVars *tv, FlowQueue *q, struct timeval *ts)
#ifdef FLOW_PRUNE_DEBUG #ifdef FLOW_PRUNE_DEBUG
prune_queue_empty++; prune_queue_empty++;
#endif #endif
return 0; return cnt;
} }
qnext_f = f->lnext;
if (SCMutexTrylock(&f->m) != 0) { if (SCMutexTrylock(&f->m) != 0) {
SCLogDebug("cant lock 1"); SCLogDebug("cant lock 1");
SCMutexUnlock(&q->mutex_q);
#ifdef FLOW_PRUNE_DEBUG #ifdef FLOW_PRUNE_DEBUG
prune_flow_lock++; prune_flow_lock++;
#endif #endif
return 0; f = f->lnext;
goto FlowPrune_Prune_Next;
} }
/* unlock list */ /* unlock list */
@ -527,7 +543,7 @@ static int FlowPrune(ThreadVars *tv, FlowQueue *q, struct timeval *ts)
#ifdef FLOW_PRUNE_DEBUG #ifdef FLOW_PRUNE_DEBUG
prune_bucket_lock++; prune_bucket_lock++;
#endif #endif
return 0; return cnt;
} }
/*set the timeout value according to the flow operating mode, flow's state /*set the timeout value according to the flow operating mode, flow's state
@ -588,7 +604,7 @@ static int FlowPrune(ThreadVars *tv, FlowQueue *q, struct timeval *ts)
#ifdef FLOW_PRUNE_DEBUG #ifdef FLOW_PRUNE_DEBUG
prune_no_timeout++; prune_no_timeout++;
#endif #endif
return 0; return cnt;
} }
/** never prune a flow that is used by a packet or stream msg /** never prune a flow that is used by a packet or stream msg
@ -602,11 +618,11 @@ static int FlowPrune(ThreadVars *tv, FlowQueue *q, struct timeval *ts)
#ifdef FLOW_PRUNE_DEBUG #ifdef FLOW_PRUNE_DEBUG
prune_usecnt++; prune_usecnt++;
#endif #endif
return 0; return cnt;
} }
if (FlowForceReassemblyForFlowV2(tv, f) == 1) { if (FlowForceReassemblyForFlowV2(tv, f) == 1) {
return 0; return cnt;
} }
/* this should not be possible */ /* this should not be possible */
@ -626,13 +642,14 @@ static int FlowPrune(ThreadVars *tv, FlowQueue *q, struct timeval *ts)
SCSpinUnlock(&f->fb->s); SCSpinUnlock(&f->fb->s);
f->fb = NULL; f->fb = NULL;
cnt++;
FlowClearMemory (f, f->protomap); FlowClearMemory (f, f->protomap);
/* move to spare list */ /* move to spare list */
FlowRequeue(f, q, &flow_spare_q, 1); FlowRequeue(f, q, &flow_spare_q, 1);
SCMutexUnlock(&f->m); SCMutexUnlock(&f->m);
return 1; return cnt;
} }
/** \brief Time out flows. /** \brief Time out flows.

Loading…
Cancel
Save