From: Jeff Lucovsky Date: Thu, 27 Jul 2023 13:17:14 +0000 (-0400) Subject: general: Use bool instead of int for condition fns X-Git-Tag: suricata-8.0.0-beta1~2068 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=310dcd1dc46f113711084e08edc7d8b392c8a047;p=thirdparty%2Fsuricata.git general: Use bool instead of int for condition fns This commit changes the conditional logging functions to use bool rather than int values. --- diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index dfcd2938d3..e0a0802051 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -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) diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c index bfb7f8ffe8..8cd4a3c58a 100644 --- a/src/alert-fastlog.c +++ b/src/alert-fastlog.c @@ -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, diff --git a/src/alert-syslog.c b/src/alert-syslog.c index fa585811bb..df0be1a94a 100644 --- a/src/alert-syslog.c +++ b/src/alert-syslog.c @@ -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) diff --git a/src/app-layer-ssh.c b/src/app-layer-ssh.c index 0cf404c873..71bc786ad6 100644 --- a/src/app-layer-ssh.c +++ b/src/app-layer-ssh.c @@ -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); } diff --git a/src/app-layer-ssh.h b/src/app-layer-ssh.h index 8dbb3be817..996cc260c7 100644 --- a/src/app-layer-ssh.h +++ b/src/app-layer-ssh.h @@ -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__ */ diff --git a/src/log-pcap.c b/src/log-pcap.c index 1e1b6da1fb..7f16ddc792 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -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; } /** diff --git a/src/log-tlsstore.c b/src/log-tlsstore.c index 4e1d54a5fe..9690445536 100644 --- a/src/log-tlsstore.c +++ b/src/log-tlsstore.c @@ -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, diff --git a/src/output-eve-stream.c b/src/output-eve-stream.c index 446fb3e60e..919505dce7 100644 --- a/src/output-eve-stream.c +++ b/src/output-eve-stream.c @@ -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; diff --git a/src/output-json-alert.c b/src/output-json-alert.c index a7df106550..c3886231c0 100644 --- a/src/output-json-alert.c +++ b/src/output-json-alert.c @@ -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) diff --git a/src/output-json-anomaly.c b/src/output-json-anomaly.c index 606ead0e62..ffe931a73e 100644 --- a/src/output-json-anomaly.c +++ b/src/output-json-anomaly.c @@ -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) || diff --git a/src/output-json-drop.c b/src/output-json-drop.c index 56484c36d4..edce3793d1 100644 --- a/src/output-json-drop.c +++ b/src/output-json-drop.c @@ -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) diff --git a/src/output-json-frame.c b/src/output-json-frame.c index d23ba92ac3..b7aaabc1de 100644 --- a/src/output-json-frame.c +++ b/src/output-json-frame.c @@ -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) diff --git a/src/output-json-metadata.c b/src/output-json-metadata.c index 231ff1d5d3..772b2ccb06 100644 --- a/src/output-json-metadata.c +++ b/src/output-json-metadata.c @@ -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) diff --git a/src/output-lua.c b/src/output-lua.c index cc93a2de4a..28ba3e9f91 100644 --- a/src/output-lua.c +++ b/src/output-lua.c @@ -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 diff --git a/src/output-packet.c b/src/output-packet.c index 232be2697e..d42d1033ca 100644 --- a/src/output-packet.c +++ b/src/output-packet.c @@ -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); diff --git a/src/output-packet.h b/src/output-packet.h index adba556891..1e468669f1 100644 --- a/src/output-packet.h +++ b/src/output-packet.h @@ -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 *, diff --git a/src/output-tx.c b/src/output-tx.c index 18a34e78a7..8eb6a842a6 100644 --- a/src/output-tx.c +++ b/src/output-tx.c @@ -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; } diff --git a/src/output-tx.h b/src/output-tx.h index 8d58156bef..88c12ff25f 100644 --- a/src/output-tx.h +++ b/src/output-tx.h @@ -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,