flow: use bool wherever possible

pull/11353/head
Shivani Bhardwaj 2 years ago committed by Victor Julien
parent 8b831e6751
commit 87fa7f10ef

@ -175,10 +175,10 @@ again:
* \param f flow * \param f flow
* \param ts timestamp * \param ts timestamp
* *
* \retval 0 not timed out * \retval false not timed out
* \retval 1 timed out * \retval true timed out
*/ */
static int FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const bool emerg) static bool FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const bool emerg)
{ {
uint32_t flow_times_out_at = f->timeout_at; uint32_t flow_times_out_at = f->timeout_at;
if (emerg) { if (emerg) {
@ -190,10 +190,10 @@ static int FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const
/* do the timeout check */ /* do the timeout check */
if ((uint64_t)flow_times_out_at >= SCTIME_SECS(ts)) { if ((uint64_t)flow_times_out_at >= SCTIME_SECS(ts)) {
return 0; return false;
} }
return 1; return true;
} }
/** \internal /** \internal
@ -203,14 +203,14 @@ static int FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const
* \param ts timestamp * \param ts timestamp
* \param counters Flow timeout counters * \param counters Flow timeout counters
* *
* \retval 0 not timeout * \retval false not timeout
* \retval 1 timeout (or not capture bypassed) * \retval true timeout (or not capture bypassed)
*/ */
static inline int FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters *counters) static inline bool FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters *counters)
{ {
#ifdef CAPTURE_OFFLOAD #ifdef CAPTURE_OFFLOAD
if (f->flow_state != FLOW_STATE_CAPTURE_BYPASSED) { if (f->flow_state != FLOW_STATE_CAPTURE_BYPASSED) {
return 1; return true;
} }
FlowBypassInfo *fc = FlowGetStorageById(f, GetFlowBypassInfoID()); FlowBypassInfo *fc = FlowGetStorageById(f, GetFlowBypassInfoID());
@ -233,22 +233,20 @@ static inline int FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters
} }
counters->bypassed_pkts += pkts_tosrc + pkts_todst; counters->bypassed_pkts += pkts_tosrc + pkts_todst;
counters->bypassed_bytes += bytes_tosrc + bytes_todst; counters->bypassed_bytes += bytes_tosrc + bytes_todst;
return 0; return false;
} else { }
SCLogDebug("No new packet, dead flow %"PRId64"", FlowGetId(f)); SCLogDebug("No new packet, dead flow %" PRId64 "", FlowGetId(f));
if (f->livedev) { if (f->livedev) {
if (FLOW_IS_IPV4(f)) { if (FLOW_IS_IPV4(f)) {
LiveDevSubBypassStats(f->livedev, 1, AF_INET); LiveDevSubBypassStats(f->livedev, 1, AF_INET);
} else if (FLOW_IS_IPV6(f)) { } else if (FLOW_IS_IPV6(f)) {
LiveDevSubBypassStats(f->livedev, 1, AF_INET6); LiveDevSubBypassStats(f->livedev, 1, AF_INET6);
}
} }
counters->bypassed_count++;
return 1;
} }
counters->bypassed_count++;
} }
#endif /* CAPTURE_OFFLOAD */ #endif /* CAPTURE_OFFLOAD */
return 1; return true;
} }
typedef struct FlowManagerTimeoutThread { typedef struct FlowManagerTimeoutThread {
@ -269,7 +267,7 @@ 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) == 1) { !FlowIsBypassed(f) && FlowForceReassemblyNeedReassembly(f)) {
/* Send the flow to its thread */ /* Send the flow to its thread */
FlowForceReassemblyForFlow(f); FlowForceReassemblyForFlow(f);
FLOWLOCK_UNLOCK(f); FLOWLOCK_UNLOCK(f);
@ -319,8 +317,7 @@ static void FlowManagerHashRowTimeout(FlowManagerTimeoutThread *td, Flow *f, SCT
* be modified when we have both the flow and hash row lock */ * be modified when we have both the flow and hash row lock */
/* timeout logic goes here */ /* timeout logic goes here */
if (FlowManagerFlowTimeout(f, ts, next_ts, emergency) == 0) { if (FlowManagerFlowTimeout(f, ts, next_ts, emergency) == false) {
counters->flows_notimeout++; counters->flows_notimeout++;
prev_f = f; prev_f = f;

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2017 Open Information Security Foundation /* Copyright (C) 2007-2024 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -281,14 +281,14 @@ Packet *FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, const TcpSess
* *
* \param f *LOCKED* flow * \param f *LOCKED* flow
* *
* \retval 0 no * \retval false no
* \retval 1 yes * \retval true yes
*/ */
int FlowForceReassemblyNeedReassembly(Flow *f) bool FlowForceReassemblyNeedReassembly(Flow *f)
{ {
if (f == NULL || f->protoctx == NULL) { if (f == NULL || f->protoctx == NULL) {
SCReturnInt(0); return false;
} }
TcpSession *ssn = (TcpSession *)f->protoctx; TcpSession *ssn = (TcpSession *)f->protoctx;
@ -320,12 +320,12 @@ int FlowForceReassemblyNeedReassembly(Flow *f)
/* nothing to do */ /* nothing to do */
if (client == STREAM_HAS_UNPROCESSED_SEGMENTS_NONE && if (client == STREAM_HAS_UNPROCESSED_SEGMENTS_NONE &&
server == STREAM_HAS_UNPROCESSED_SEGMENTS_NONE) { server == STREAM_HAS_UNPROCESSED_SEGMENTS_NONE) {
SCReturnInt(0); return false;
} }
f->ffr_ts = client; f->ffr_ts = client;
f->ffr_tc = server; f->ffr_tc = server;
SCReturnInt(1); return true;
} }
/** /**
@ -392,7 +392,7 @@ 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) == 1) { if (FlowForceReassemblyNeedReassembly(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); FlowForceReassemblyForFlow(f);

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2012 Open Information Security Foundation /* Copyright (C) 2007-2024 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -27,7 +27,7 @@
#include "stream-tcp-private.h" #include "stream-tcp-private.h"
void FlowForceReassemblyForFlow(Flow *f); void FlowForceReassemblyForFlow(Flow *f);
int FlowForceReassemblyNeedReassembly(Flow *f); bool FlowForceReassemblyNeedReassembly(Flow *f);
void FlowForceReassembly(void); void FlowForceReassembly(void);
Packet *FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, const TcpSession *ssn); Packet *FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, const TcpSession *ssn);

@ -1,4 +1,4 @@
/* Copyright (C) 2016-2020 Open Information Security Foundation /* Copyright (C) 2016-2024 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -166,8 +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) == 1 && !FlowIsBypassed(f) && FlowForceReassemblyNeedReassembly(f) && f->ffr != 0) {
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);

Loading…
Cancel
Save