flow/timeout: cleanup fn names and comments

pull/11353/head
Shivani Bhardwaj 1 year ago committed by Victor Julien
parent 8818b9cbe0
commit eb95d2bf66

@ -280,9 +280,9 @@ static uint32_t ProcessAsideQueue(FlowManagerTimeoutThread *td, FlowTimeoutCount
if (f->proto == IPPROTO_TCP && if (f->proto == IPPROTO_TCP &&
!(f->flags & (FLOW_TIMEOUT_REASSEMBLY_DONE | FLOW_ACTION_DROP)) && !(f->flags & (FLOW_TIMEOUT_REASSEMBLY_DONE | FLOW_ACTION_DROP)) &&
!FlowIsBypassed(f) && FlowForceReassemblyNeedReassembly(f)) { !FlowIsBypassed(f) && FlowNeedsReassembly(f)) {
/* Send the flow to its thread */ /* Send the flow to its thread */
FlowForceReassemblyForFlow(f); FlowSendToLocalThread(f);
FLOWLOCK_UNLOCK(f); FLOWLOCK_UNLOCK(f);
/* flow ownership is already passed to the worker thread */ /* flow ownership is already passed to the worker thread */

@ -66,17 +66,18 @@
/** /**
* \internal * \internal
* \brief Pseudo packet setup for flow forced reassembly. * \brief Pseudo packet setup to finish a flow when needed.
* *
* \param p a dummy pseudo packet from packet pool. Not all pseudo
* packets need to force reassembly, in which case we just
* set dummy ack/seq values.
* \param direction Direction of the packet. 0 indicates toserver and 1 * \param direction Direction of the packet. 0 indicates toserver and 1
* indicates toclient. * indicates toclient.
* \param f Pointer to the flow. * \param f Pointer to the flow.
* \param ssn Pointer to the tcp session. * \param ssn Pointer to the tcp session.
* \param dummy Indicates to create a dummy pseudo packet. Not all pseudo * \retval pseudo packet with everything set up
* packets need to force reassembly, in which case we just
* set dummy ack/seq values.
*/ */
static inline Packet *FlowForceReassemblyPseudoPacketSetup( static inline Packet *FlowPseudoPacketSetup(
Packet *p, int direction, Flow *f, const TcpSession *ssn) Packet *p, int direction, Flow *f, const TcpSession *ssn)
{ {
const int orig_dir = direction; const int orig_dir = direction;
@ -263,7 +264,7 @@ error:
return NULL; return NULL;
} }
Packet *FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, const TcpSession *ssn) Packet *FlowPseudoPacketGet(int direction, Flow *f, const TcpSession *ssn)
{ {
PacketPoolWait(); PacketPoolWait();
Packet *p = PacketPoolGetPacket(); Packet *p = PacketPoolGetPacket();
@ -273,7 +274,7 @@ Packet *FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, const TcpSess
PACKET_PROFILING_START(p); PACKET_PROFILING_START(p);
return FlowForceReassemblyPseudoPacketSetup(p, direction, f, ssn); return FlowPseudoPacketSetup(p, direction, f, ssn);
} }
/** /**
@ -284,7 +285,7 @@ Packet *FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, const TcpSess
* \retval false no * \retval false no
* \retval true yes * \retval true yes
*/ */
bool FlowForceReassemblyNeedReassembly(Flow *f) bool FlowNeedsReassembly(Flow *f)
{ {
if (f == NULL || f->protoctx == NULL) { if (f == NULL || f->protoctx == NULL) {
@ -330,7 +331,7 @@ bool FlowForceReassemblyNeedReassembly(Flow *f)
/** /**
* \internal * \internal
* \brief Forces reassembly for flow if it needs it. * \brief Sends the flow to its respective thread's flow queue.
* *
* The function requires flow to be locked beforehand. * The function requires flow to be locked beforehand.
* *
@ -339,10 +340,8 @@ bool FlowForceReassemblyNeedReassembly(Flow *f)
* flag is set, choose the second thread_id (to client/source). * flag is set, choose the second thread_id (to client/source).
* *
* \param f Pointer to the flow. * \param f Pointer to the flow.
*
* \retval 0 This flow doesn't need any reassembly processing; 1 otherwise.
*/ */
void FlowForceReassemblyForFlow(Flow *f) void FlowSendToLocalThread(Flow *f)
{ {
// Choose the thread_id based on whether the flow has been // Choose the thread_id based on whether the flow has been
// reversed. // reversed.
@ -352,7 +351,8 @@ void FlowForceReassemblyForFlow(Flow *f)
/** /**
* \internal * \internal
* \brief Forces reassembly for flows that need it. * \brief Remove flows from the hash bucket as they have more work to be done in
* in the detection engine.
* *
* When this function is called we're running in virtually dead engine, * When this function is called we're running in virtually dead engine,
* so locking the flows is not strictly required. The reasons it is still * so locking the flows is not strictly required. The reasons it is still
@ -362,10 +362,8 @@ void FlowForceReassemblyForFlow(Flow *f)
* - allow us to aggressively check using debug validation assertions * - allow us to aggressively check using debug validation assertions
* - be robust in case of future changes * - be robust in case of future changes
* - locking overhead is negligible when no other thread fights us * - locking overhead is negligible when no other thread fights us
*
* \param q The queue to process flows from.
*/ */
static inline void FlowForceReassemblyForHash(void) static inline void FlowRemoveHash(void)
{ {
for (uint32_t idx = 0; idx < flow_config.hash_size; idx++) { for (uint32_t idx = 0; idx < flow_config.hash_size; idx++) {
FlowBucket *fb = &flow_hash[idx]; FlowBucket *fb = &flow_hash[idx];
@ -392,10 +390,10 @@ static inline void FlowForceReassemblyForHash(void)
/* in case of additional work, we pull the flow out of the /* in case of additional work, we pull the flow out of the
* hash and xfer ownership to the injected packet(s) */ * hash and xfer ownership to the injected packet(s) */
if (FlowForceReassemblyNeedReassembly(f)) { if (FlowNeedsReassembly(f)) {
RemoveFromHash(f, prev_f); RemoveFromHash(f, prev_f);
f->flow_end_flags |= FLOW_END_FLAG_SHUTDOWN; f->flow_end_flags |= FLOW_END_FLAG_SHUTDOWN;
FlowForceReassemblyForFlow(f); FlowSendToLocalThread(f);
FLOWLOCK_UNLOCK(f); FLOWLOCK_UNLOCK(f);
f = next_f; f = next_f;
continue; continue;
@ -412,10 +410,11 @@ static inline void FlowForceReassemblyForHash(void)
} }
/** /**
* \brief Force reassembly for all the flows that have unprocessed segments. * \brief Clean up all the flows that have unprocessed segments and have
* some work to do in the detection engine.
*/ */
void FlowForceReassembly(void) void FlowWorkToDoCleanup(void)
{ {
/* Carry out flow reassembly for unattended flows */ /* Carry out cleanup of unattended flows */
FlowForceReassemblyForHash(); FlowRemoveHash();
} }

@ -26,9 +26,9 @@
#include "stream-tcp-private.h" #include "stream-tcp-private.h"
void FlowForceReassemblyForFlow(Flow *f); void FlowSendToLocalThread(Flow *f);
bool FlowForceReassemblyNeedReassembly(Flow *f); bool FlowNeedsReassembly(Flow *f);
void FlowForceReassembly(void); void FlowWorkToDoCleanup(void);
Packet *FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, const TcpSession *ssn); Packet *FlowPseudoPacketGet(int direction, Flow *f, const TcpSession *ssn);
#endif /* SURICATA_FLOW_TIMEOUT_H */ #endif /* SURICATA_FLOW_TIMEOUT_H */

@ -120,7 +120,7 @@ static int FlowFinish(ThreadVars *tv, Flow *f, FlowWorkerThreadData *fw, void *d
/* insert a pseudo packet in the toserver direction */ /* insert a pseudo packet in the toserver direction */
if (client == STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION) { if (client == STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION) {
Packet *p = FlowForceReassemblyPseudoPacketGet(0, f, ssn); Packet *p = FlowPseudoPacketGet(0, f, ssn);
if (p != NULL) { if (p != NULL) {
PKT_SET_SRC(p, PKT_SRC_FFR); PKT_SET_SRC(p, PKT_SRC_FFR);
if (server == STREAM_HAS_UNPROCESSED_SEGMENTS_NONE) { if (server == STREAM_HAS_UNPROCESSED_SEGMENTS_NONE) {
@ -134,7 +134,7 @@ static int FlowFinish(ThreadVars *tv, Flow *f, FlowWorkerThreadData *fw, void *d
/* handle toclient */ /* handle toclient */
if (server == STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION) { if (server == STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION) {
Packet *p = FlowForceReassemblyPseudoPacketGet(1, f, ssn); Packet *p = FlowPseudoPacketGet(1, f, ssn);
if (p != NULL) { if (p != NULL) {
PKT_SET_SRC(p, PKT_SRC_FFR); PKT_SET_SRC(p, PKT_SRC_FFR);
p->flowflags |= FLOW_PKT_LAST_PSEUDO; p->flowflags |= FLOW_PKT_LAST_PSEUDO;
@ -166,7 +166,7 @@ static void CheckWorkQueue(ThreadVars *tv, FlowWorkerThreadData *fw, FlowTimeout
if (f->proto == IPPROTO_TCP) { if (f->proto == IPPROTO_TCP) {
if (!(f->flags & (FLOW_TIMEOUT_REASSEMBLY_DONE | FLOW_ACTION_DROP)) && if (!(f->flags & (FLOW_TIMEOUT_REASSEMBLY_DONE | FLOW_ACTION_DROP)) &&
!FlowIsBypassed(f) && FlowForceReassemblyNeedReassembly(f) && f->ffr != 0) { !FlowIsBypassed(f) && FlowNeedsReassembly(f) && f->ffr != 0) {
/* read detect thread in case we're doing a reload */ /* read detect thread in case we're doing a reload */
void *detect_thread = SC_ATOMIC_GET(fw->detect_thread); void *detect_thread = SC_ATOMIC_GET(fw->detect_thread);
int cnt = FlowFinish(tv, f, fw, detect_thread); int cnt = FlowFinish(tv, f, fw, detect_thread);

@ -2273,14 +2273,14 @@ void PostRunDeinit(const int runmode, struct timeval *start_time)
if (runmode == RUNMODE_UNIX_SOCKET) if (runmode == RUNMODE_UNIX_SOCKET)
return; return;
/* needed by FlowForceReassembly */ /* needed by FlowWorkToDoCleanup */
PacketPoolInit(); PacketPoolInit();
/* handle graceful shutdown of the flow engine, it's helper /* handle graceful shutdown of the flow engine, it's helper
* threads and the packet threads */ * threads and the packet threads */
FlowDisableFlowManagerThread(); FlowDisableFlowManagerThread();
TmThreadDisableReceiveThreads(); TmThreadDisableReceiveThreads();
FlowForceReassembly(); FlowWorkToDoCleanup();
TmThreadDisablePacketThreads(); TmThreadDisablePacketThreads();
SCPrintElapsedTime(start_time); SCPrintElapsedTime(start_time);
FlowDisableFlowRecyclerThread(); FlowDisableFlowRecyclerThread();

Loading…
Cancel
Save