From: Anoop Saldanha Date: Thu, 5 Jul 2012 12:08:58 +0000 (+0530) Subject: check if all packets are processed before disabling detect threads + kill all threads... X-Git-Tag: suricata-1.3~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34f0897163c466b1c31d0e454103c0266af6f8c4;p=thirdparty%2Fsuricata.git check if all packets are processed before disabling detect threads + kill all threads <= detect after FFR + other minor fixes --- diff --git a/src/flow-timeout.c b/src/flow-timeout.c index c481146f96..9b86b51f6c 100644 --- a/src/flow-timeout.c +++ b/src/flow-timeout.c @@ -605,10 +605,6 @@ void FlowForceReassembly(void) /* Do remember. We need to have packet acquire disabled by now */ /** ----- Part 1 ----- **/ - /* First we need to kill the flow manager thread */ - FlowKillFlowManagerThread(); - - /** ----- Part 2 ----- **/ /* Check if all threads are idle. We need this so that we have all * packets freeds. As a consequence, no flows are in use */ @@ -636,7 +632,7 @@ void FlowForceReassembly(void) SCMutexUnlock(&tv_root_lock); - /** ----- Part 3 ----- **/ + /** ----- Part 2 ----- **/ /* Carry out flow reassembly for unattended flows */ FlowForceReassemblyForHash(); diff --git a/src/stream-tcp.c b/src/stream-tcp.c index e65d45a7bf..2e6f219455 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -125,6 +125,7 @@ void TmModuleStreamTcpRegister (void) tmm_modules[TMM_STREAMTCP].ThreadDeinit = StreamTcpThreadDeinit; tmm_modules[TMM_STREAMTCP].RegisterTests = StreamTcpRegisterTests; tmm_modules[TMM_STREAMTCP].cap_flags = 0; + tmm_modules[TMM_STREAMTCP].flags = TM_FLAG_STREAM_TM; } void StreamTcpIncrMemuse(uint64_t size) { diff --git a/src/suricata.c b/src/suricata.c index 8ffb5b4e4a..f3207c896b 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -1888,6 +1888,9 @@ int main(int argc, char **argv) SCCudaPBKillBatchingPackets(); #endif + /* First we need to kill the flow manager thread */ + FlowKillFlowManagerThread(); + /* Disable packet acquire thread first */ TmThreadDisableReceiveThreads(); @@ -1902,7 +1905,7 @@ int main(int argc, char **argv) if (rule_reload == 1) { /* Disable detect threads first. This is required by live rule swap */ - TmThreadDisableDetectThreads(); + TmThreadDisableUptoDetectThreads(); /* wait if live rule swap is in progress */ if (UtilSignalIsHandler(SIGUSR2, SignalHandlerSigusr2Idle)) { diff --git a/src/tm-modules.h b/src/tm-modules.h index 3e35f70862..6789888fa3 100644 --- a/src/tm-modules.h +++ b/src/tm-modules.h @@ -30,7 +30,8 @@ /* thread flags */ #define TM_FLAG_RECEIVE_TM 0x01 #define TM_FLAG_DECODE_TM 0x02 -#define TM_FLAG_DETECT_TM 0x04 +#define TM_FLAG_STREAM_TM 0x04 +#define TM_FLAG_DETECT_TM 0x08 typedef struct TmModule_ { char *name; diff --git a/src/tm-threads.c b/src/tm-threads.c index 23b9bb9561..196d7dac0d 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -1549,9 +1549,9 @@ void TmThreadDisableReceiveThreads(void) } /** - * \brief Disable all detect threads. + * \brief Disable all threads <= detect. */ -void TmThreadDisableDetectThreads(void) +void TmThreadDisableUptoDetectThreads(void) { /* value in seconds */ #define THREAD_KILL_MAX_WAIT_TIME 60 @@ -1572,14 +1572,34 @@ void TmThreadDisableDetectThreads(void) * receive TM amongst the slots in a tv, it indicates we are done * with all receive threads */ while (tv) { + int disable = 0; /* obtain the slots for this TV */ TmSlot *slots = tv->tm_slots; while (slots != NULL) { TmModule *tm = TmModuleGetById(slots->tm_id); - if (!(tm->flags & TM_FLAG_DETECT_TM)) { - slots = slots->slot_next; - continue; + if (tm->flags & (TM_FLAG_RECEIVE_TM | TM_FLAG_DECODE_TM | + TM_FLAG_STREAM_TM | TM_FLAG_DETECT_TM)) { + disable = 1; + break; + } + + slots = slots->slot_next; + continue; + } + + if (disable) { + if (tv->inq != NULL) { + /* we wait till we dry out all the inq packets, before we + * kill this thread. Do note that you should have disabled + * packet acquire by now using TmThreadDisableReceiveThreads()*/ + if (!(strlen(tv->inq->name) == strlen("packetpool") && + strcasecmp(tv->inq->name, "packetpool") == 0)) { + PacketQueue *q = &trans_q[tv->inq->id]; + while (q->len != 0) { + usleep(1000); + } + } } /* we found our receive TV. Send it a KILL signal. This is all @@ -1607,8 +1627,6 @@ void TmThreadDisableDetectThreads(void) exit(EXIT_FAILURE); } } - - break; } tv = tv->next; diff --git a/src/tm-threads.h b/src/tm-threads.h index 9715b1972e..7f16384be8 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -113,7 +113,7 @@ TmEcode TmThreadsSlotVarRun (ThreadVars *tv, Packet *p, TmSlot *slot); ThreadVars *TmThreadsGetTVContainingSlot(TmSlot *); void TmThreadDisableReceiveThreads(void); -void TmThreadDisableDetectThreads(void); +void TmThreadDisableUptoDetectThreads(void); TmSlot *TmThreadGetFirstTmSlotForPartialPattern(const char *); /**