]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
general: Use bool instead of int for condition fns
authorJeff Lucovsky <jlucovsky@oisf.net>
Thu, 27 Jul 2023 13:17:14 +0000 (09:17 -0400)
committerVictor Julien <victor@inliniac.net>
Fri, 17 Nov 2023 21:24:13 +0000 (22:24 +0100)
This commit changes the conditional logging functions to use bool rather
than int values.

18 files changed:
src/alert-debuglog.c
src/alert-fastlog.c
src/alert-syslog.c
src/app-layer-ssh.c
src/app-layer-ssh.h
src/log-pcap.c
src/log-tlsstore.c
src/output-eve-stream.c
src/output-json-alert.c
src/output-json-anomaly.c
src/output-json-drop.c
src/output-json-frame.c
src/output-json-metadata.c
src/output-lua.c
src/output-packet.c
src/output-packet.h
src/output-tx.c
src/output-tx.h

index dfcd2938d3ab360e8c2ecbbcb356a6dcbce77ae9..e0a0802051e1114b6fcf7b55b6ac5d8b6d5a2d1f 100644 (file)
@@ -468,9 +468,9 @@ error:
     return result;
 }
 
-static int AlertDebugLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
+static bool AlertDebugLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
 {
-    return (p->alerts.cnt ? TRUE : FALSE);
+    return (p->alerts.cnt > 0);
 }
 
 static int AlertDebugLogLogger(ThreadVars *tv, void *thread_data, const Packet *p)
index bfb7f8ffe8c4856f2e47858be3b434fec1ff57c2..8cd4a3c58aa82d6611b0366c236d895cb28e342b 100644 (file)
@@ -71,7 +71,7 @@ TmEcode AlertFastLogThreadDeinit(ThreadVars *, void *);
 void AlertFastLogRegisterTests(void);
 static void AlertFastLogDeInitCtx(OutputCtx *);
 
-int AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p);
+static bool AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p);
 int AlertFastLogger(ThreadVars *tv, void *data, const Packet *p);
 
 void AlertFastLogRegister(void)
@@ -87,9 +87,9 @@ typedef struct AlertFastLogThread_ {
     LogFileCtx* file_ctx;
 } AlertFastLogThread;
 
-int AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
+static bool AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
 {
-    return (p->alerts.cnt ? TRUE : FALSE);
+    return (p->alerts.cnt > 0);
 }
 
 static inline void AlertFastLogOutputAlert(AlertFastLogThread *aft, char *buffer,
index fa585811bb5d0d24dc9c9559c8ae8cf9c78e68bc..df0be1a94a63b32452a87fbab2f38962cb58b7ee 100644 (file)
@@ -367,9 +367,9 @@ static TmEcode AlertSyslogDecoderEvent(ThreadVars *tv, const Packet *p, void *da
     return TM_ECODE_OK;
 }
 
-static int AlertSyslogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
+static bool AlertSyslogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
 {
-    return (p->alerts.cnt > 0 ? TRUE : FALSE);
+    return (p->alerts.cnt > 0);
 }
 
 static int AlertSyslogLogger(ThreadVars *tv, void *thread_data, const Packet *p)
index 0cf404c8736e8db583152a16e29fb52e728a42fc..71bc786ad6b494ee13e93c40c26fc50a24bdb631 100644 (file)
@@ -71,7 +71,7 @@ static int SSHRegisterPatternsForProtocolDetection(void)
     return 0;
 }
 
-int SSHTxLogCondition(ThreadVars * tv, const Packet * p, void *state, void *tx, uint64_t tx_id)
+bool SSHTxLogCondition(ThreadVars *tv, const Packet *p, void *state, void *tx, uint64_t tx_id)
 {
     return rs_ssh_tx_get_log_condition(tx);
 }
index 8dbb3be817ef0a6ecebddcd86a633428e9f4597e..996cc260c7356c8ba5b7d374892238381880cc8c 100644 (file)
@@ -28,7 +28,7 @@
 void RegisterSSHParsers(void);
 void SSHParserRegisterTests(void);
 
-int SSHTxLogCondition(ThreadVars *, const Packet *, void *state, void *tx, uint64_t tx_id);
+bool SSHTxLogCondition(ThreadVars *, const Packet *, void *state, void *tx, uint64_t tx_id);
 
 #endif /* __APP_LAYER_SSH_H__ */
 
index 1e1b6da1fb55dbf543625a81f91a44dfa7de87ba..7f16ddc7924b4cc1c4787b5ca4ef1ad5b1fa0163 100644 (file)
@@ -206,7 +206,7 @@ static TmEcode PcapLogDataDeinit(ThreadVars *, void *);
 static void PcapLogFileDeInitCtx(OutputCtx *);
 static OutputInitResult PcapLogInitCtx(ConfNode *);
 static void PcapLogProfilingDump(PcapLogData *);
-static int PcapLogCondition(ThreadVars *, void *, const Packet *);
+static bool PcapLogCondition(ThreadVars *, void *, const Packet *);
 
 void PcapLogRegister(void)
 {
@@ -226,7 +226,7 @@ void PcapLogRegister(void)
     (prof).total += (UtilCpuGetTicks() - pcaplog_profile_ticks); \
     (prof).cnt++
 
-static int PcapLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
+static bool PcapLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
 {
     PcapLogThreadData *ptd = (PcapLogThreadData *)thread_data;
 
@@ -235,29 +235,21 @@ static int PcapLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
         case LOGMODE_COND_ALL:
             break;
         case LOGMODE_COND_ALERTS:
-            if (p->alerts.cnt || (p->flow && FlowHasAlerts(p->flow))) {
-                return TRUE;
-            } else {
-                return FALSE;
-            }
+            return (p->alerts.cnt || (p->flow && FlowHasAlerts(p->flow)));
             break;
         case LOGMODE_COND_TAG:
-            if (p->flags & (PKT_HAS_TAG | PKT_FIRST_TAG)) {
-                return TRUE;
-            } else {
-                return FALSE;
-            }
+            return (p->flags & (PKT_HAS_TAG | PKT_FIRST_TAG));
             break;
     }
 
     if (p->flags & PKT_PSEUDO_STREAM_END) {
-        return FALSE;
+        return false;
     }
 
     if (IS_TUNNEL_PKT(p) && !IS_TUNNEL_ROOT_PKT(p)) {
-        return FALSE;
+        return false;
     }
-    return TRUE;
+    return true;
 }
 
 /**
index 4e1d54a5fe3a75d978c36f8888e4cadacc52d8f5..969044553673097190f71222126c7529bb54f141 100644 (file)
@@ -226,15 +226,15 @@ end_fp:
  *  \brief Condition function for TLS logger
  *  \retval bool true or false -- log now?
  */
-static int LogTlsStoreCondition(ThreadVars *tv, const Packet *p, void *state,
-                                void *tx, uint64_t tx_id)
+static bool LogTlsStoreCondition(
+        ThreadVars *tv, const Packet *p, void *state, void *tx, uint64_t tx_id)
 {
     if (p->flow == NULL) {
-        return FALSE;
+        return false;
     }
 
     if (!(PKT_IS_TCP(p))) {
-        return FALSE;
+        return false;
     }
 
     SSLState *ssl_state = (SSLState *)state;
@@ -250,9 +250,9 @@ static int LogTlsStoreCondition(ThreadVars *tv, const Packet *p, void *state,
             ssl_state->server_connp.cert0_subject == NULL)
         goto dontlog;
 
-    return TRUE;
+    return true;
 dontlog:
-    return FALSE;
+    return false;
 }
 
 static int LogTlsStoreLogger(ThreadVars *tv, void *thread_data, const Packet *p,
index 446fb3e60e18771b49d133db7028da2d55909388..919505dce70d3b62576da0179af336e059551f63 100644 (file)
@@ -282,7 +282,7 @@ static void LogStream(const TcpStream *stream, JsonBuilder *js)
  * \param data  Pointer to the EveStreamLogThread struct
  * \param p     Pointer the packet which is being logged
  *
- * \retval 0 on succes
+ * \retval 0 on success
  */
 static int EveStreamLogger(ThreadVars *tv, void *thread_data, const Packet *p)
 {
@@ -422,9 +422,9 @@ static int EveStreamLogger(ThreadVars *tv, void *thread_data, const Packet *p)
  * \param tv    Pointer the current thread variables
  * \param p     Pointer the packet which is tested
  *
- * \retval bool TRUE or FALSE
+ * \retval bool true or false
  */
-static int EveStreamLogCondition(ThreadVars *tv, void *data, const Packet *p)
+static bool EveStreamLogCondition(ThreadVars *tv, void *data, const Packet *p)
 {
     EveStreamLogThread *td = data;
     EveStreamOutputCtx *ctx = td->stream_ctx;
index a7df1065509ee755b5181634ba3ea1675d198197..c3886231c001841d91e1c76f55a3712d6bd1de57 100644 (file)
@@ -947,12 +947,9 @@ static int JsonAlertLogger(ThreadVars *tv, void *thread_data, const Packet *p)
     return 0;
 }
 
-static int JsonAlertLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
+static bool JsonAlertLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
 {
-    if (p->alerts.cnt || (p->flags & PKT_HAS_TAG)) {
-        return TRUE;
-    }
-    return FALSE;
+    return (p->alerts.cnt || (p->flags & PKT_HAS_TAG));
 }
 
 static TmEcode JsonAlertLogThreadInit(ThreadVars *t, const void *initdata, void **data)
index 606ead0e62249f9d125e57710212ad429e7dcfae..ffe931a73ed67372788686e96b278603aebb40cf 100644 (file)
@@ -279,7 +279,7 @@ static int JsonAnomalyLogger(ThreadVars *tv, void *thread_data, const Packet *p)
     return AnomalyJson(tv, aft, p);
 }
 
-static int JsonAnomalyLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
+static bool JsonAnomalyLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
 {
     return p->events.cnt > 0 ||
            (p->app_layer_events && p->app_layer_events->cnt > 0) ||
index 56484c36d43b24e52b5830f8ba9ab4effad14fbe..edce3793d100e04643ec87e874d5d0968c997ead 100644 (file)
@@ -340,49 +340,48 @@ static int JsonDropLogger(ThreadVars *tv, void *thread_data, const Packet *p)
     return 0;
 }
 
-
 /**
  * \brief Check if we need to drop-log this packet
  *
  * \param tv    Pointer the current thread variables
  * \param p     Pointer the packet which is tested
  *
- * \retval bool TRUE or FALSE
+ * \retval bool true or false
  */
-static int JsonDropLogCondition(ThreadVars *tv, void *data, const Packet *p)
+static bool JsonDropLogCondition(ThreadVars *tv, void *data, const Packet *p)
 {
     if (!EngineModeIsIPS()) {
         SCLogDebug("engine is not running in inline mode, so returning");
-        return FALSE;
+        return false;
     }
     if (PKT_IS_PSEUDOPKT(p)) {
         SCLogDebug("drop log doesn't log pseudo packets");
-        return FALSE;
+        return false;
     }
 
     if (!(PacketCheckAction(p, ACTION_DROP))) {
-        return FALSE;
+        return false;
     }
 
     if (g_droplog_flows_start && p->flow != NULL) {
-        int ret = FALSE;
+        bool ret = false;
 
         /* for a flow that will be dropped fully, log just once per direction */
         if (p->flow->flags & FLOW_ACTION_DROP) {
             if (PKT_IS_TOSERVER(p) && !(p->flow->flags & FLOW_TOSERVER_DROP_LOGGED))
-                ret = TRUE;
+                ret = true;
             else if (PKT_IS_TOCLIENT(p) && !(p->flow->flags & FLOW_TOCLIENT_DROP_LOGGED))
-                ret = TRUE;
+                ret = true;
         }
 
         /* if drop is caused by signature, log anyway */
         if (p->alerts.drop.action != 0)
-            ret = TRUE;
+            ret = true;
 
         return ret;
     }
 
-    return TRUE;
+    return true;
 }
 
 void JsonDropLogRegister (void)
index d23ba92ac380183bb7199c89ae3ba2e79d6d0ff2..b7aaabc1dea968c69080fea991c73054951d09c4 100644 (file)
@@ -376,15 +376,15 @@ static int JsonFrameLogger(ThreadVars *tv, void *thread_data, const Packet *p)
     return FrameJson(tv, aft, p);
 }
 
-static int JsonFrameLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
+static bool JsonFrameLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
 {
     if (p->flow == NULL || p->flow->alproto == ALPROTO_UNKNOWN)
-        return FALSE;
+        return false;
 
     if ((p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP) && p->flow->alparser != NULL) {
         FramesContainer *frames_container = AppLayerFramesGetContainer(p->flow);
         if (frames_container == NULL)
-            return FALSE;
+            return false;
 
         Frames *frames;
         if (PKT_IS_TOSERVER(p)) {
@@ -394,7 +394,7 @@ static int JsonFrameLogCondition(ThreadVars *tv, void *thread_data, const Packet
         }
         return (frames->cnt != 0);
     }
-    return FALSE;
+    return false;
 }
 
 static TmEcode JsonFrameLogThreadInit(ThreadVars *t, const void *initdata, void **data)
index 231ff1d5d3e218ac75493c2c69b3ce780f2b6d62..772b2ccb06f22c1545c40f4a319f0a172f205a6b 100644 (file)
@@ -87,12 +87,9 @@ static int JsonMetadataLogger(ThreadVars *tv, void *thread_data, const Packet *p
     return MetadataJson(tv, aft, p);
 }
 
-static int JsonMetadataLogCondition(ThreadVars *tv, void *data, const Packet *p)
+static bool JsonMetadataLogCondition(ThreadVars *tv, void *data, const Packet *p)
 {
-    if (p->pktvar) {
-        return TRUE;
-    }
-    return FALSE;
+    return p->pktvar != NULL;
 }
 
 void JsonMetadataLogRegister (void)
index cc93a2de4a54d78ebe7f1b8c9ca7cfb7b07b41fa..28ba3e9f91b71232f99339efa59fc143d4ec7230 100644 (file)
@@ -162,7 +162,7 @@ static int LuaStreamingLogger(ThreadVars *tv, void *thread_data, const Flow *f,
  *
  *  A single call to this function will run one script for a single
  *  packet. If it is called, it means that the registered condition
- *  function has returned TRUE.
+ *  function has returned true.
  *
  *  The script is called once for each alert stored in the packet.
  *
@@ -215,11 +215,9 @@ not_supported:
     SCReturnInt(0);
 }
 
-static int LuaPacketConditionAlerts(ThreadVars *tv, void *data, const Packet *p)
+static bool LuaPacketConditionAlerts(ThreadVars *tv, void *data, const Packet *p)
 {
-    if (p->alerts.cnt > 0)
-        return TRUE;
-    return FALSE;
+    return (p->alerts.cnt > 0);
 }
 
 /** \internal
@@ -227,7 +225,7 @@ static int LuaPacketConditionAlerts(ThreadVars *tv, void *data, const Packet *p)
  *
  *  A single call to this function will run one script for a single
  *  packet. If it is called, it means that the registered condition
- *  function has returned TRUE.
+ *  function has returned true.
  *
  *  The script is called once for each packet.
  *
@@ -265,9 +263,9 @@ not_supported:
     SCReturnInt(0);
 }
 
-static int LuaPacketCondition(ThreadVars *tv, void *data, const Packet *p)
+static bool LuaPacketCondition(ThreadVars *tv, void *data, const Packet *p)
 {
-    return TRUE;
+    return true;
 }
 
 /** \internal
index 232be2697e5a3a32b177bcddbe8800aa9fb02361..d42d1033cade2084515317b88f3ae46cfe09ca3f 100644 (file)
@@ -105,7 +105,7 @@ static TmEcode OutputPacketLog(ThreadVars *tv, Packet *p, void *thread_data)
     while (logger && store) {
         DEBUG_VALIDATE_BUG_ON(logger->LogFunc == NULL || logger->ConditionFunc == NULL);
 
-        if ((logger->ConditionFunc(tv, store->thread_data, (const Packet *)p)) == TRUE) {
+        if (logger->ConditionFunc(tv, store->thread_data, (const Packet *)p)) {
             PACKET_PROFILING_LOGGER_START(p, logger->logger_id);
             logger->LogFunc(tv, store->thread_data, (const Packet *)p);
             PACKET_PROFILING_LOGGER_END(p, logger->logger_id);
index adba556891225d3d305bd685bec61ab578df1017..1e468669f13784115be106233f20fcb1c02bd4ff 100644 (file)
@@ -32,7 +32,7 @@ typedef int (*PacketLogger)(ThreadVars *, void *thread_data, const Packet *);
 /** packet logger condition function pointer type,
  *  must return true for packets that should be logged
  */
-typedef int (*PacketLogCondition)(ThreadVars *, void *thread_data, const Packet *);
+typedef bool (*PacketLogCondition)(ThreadVars *, void *thread_data, const Packet *);
 
 int OutputRegisterPacketLogger(LoggerId logger_id, const char *name,
     PacketLogger LogFunc, PacketLogCondition ConditionFunc, OutputCtx *,
index 18a34e78a7342cb404b3945569faccdeff51bd1a..8eb6a842a656ad24f4137fa40185d0c3a115916d 100644 (file)
@@ -299,8 +299,7 @@ static void OutputTxLogCallLoggers(ThreadVars *tv, OutputTxLoggerThreadData *op_
                 SCLogDebug("EOF, so log now");
             } else {
                 if (logger->LogCondition) {
-                    int r = logger->LogCondition(tv, p, alstate, tx, tx_id);
-                    if (r == FALSE) {
+                    if (!logger->LogCondition(tv, p, alstate, tx, tx_id)) {
                         SCLogDebug("conditions not met, not logging");
                         goto next_logger;
                     }
index 8d58156bef8d0745245cd02422b7e80fb0cd3ca5..88c12ff25f684df74901437b24063196db5ba6a5 100644 (file)
@@ -35,7 +35,8 @@ typedef int (*TxLogger)(ThreadVars *, void *thread_data, const Packet *, Flow *f
 /** tx logger condition function pointer type,
  *  must return true for tx that should be logged
  */
-typedef int (*TxLoggerCondition)(ThreadVars *, const Packet *, void *state, void *tx, uint64_t tx_id);
+typedef bool (*TxLoggerCondition)(
+        ThreadVars *, const Packet *, void *state, void *tx, uint64_t tx_id);
 
 int OutputRegisterTxLogger(LoggerId id, const char *name, AppProto alproto,
         TxLogger LogFunc,