]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
runmodes: typedef runmode enum and use as type
authorJason Ish <jason.ish@oisf.net>
Mon, 26 Aug 2024 20:18:22 +0000 (14:18 -0600)
committerVictor Julien <victor@inliniac.net>
Tue, 1 Apr 2025 08:17:05 +0000 (10:17 +0200)
Also remove function to set the library mode. This is easy enough to
do with SCRunmodeSet, and we don't want to add a specific setter for
each and every runmode.

Ticket: #7240

examples/lib/custom/main.c
src/runmodes.c
src/runmodes.h
src/suricata.c
src/suricata.h
src/util-privs.c

index 85926ce31408081305b56e510f7ebe863b1c1783..45b0bb5046707bde3a3f6f50499c7d0beacf4924 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include "suricata.h"
+#include "runmodes.h"
 #include "conf.h"
 #include "pcap.h"
 #include "runmode-lib.h"
@@ -94,9 +95,9 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    /* Set lib runmode. There is currently no way to set it via the
-     * Conf API. */
-    SuricataSetLibRunmode();
+    /* Set the runmode to library mode. Perhaps in the future this
+     * should be done in some library bootstrap function. */
+    SCRunmodeSet(RUNMODE_LIB);
 
     /* Validate/finalize the runmode. */
     if (SCFinalizeRunMode() != TM_ECODE_OK) {
index f5434f4cc8f807f26e13f0676c5c9cbbad4039d0..897aba6d374d9ed798d02f81c9892867048ec1cb 100644 (file)
@@ -81,7 +81,7 @@ const char *thread_name_heartbeat = "HB";
  */
 typedef struct RunMode_ {
     /* the runmode type */
-    enum RunModes runmode;
+    enum SCRunModes runmode;
     const char *name;
     const char *description;
     /* runmode function */
@@ -177,7 +177,7 @@ static const char *RunModeTranslateModeToName(int runmode)
  * \param runmode           The runmode type.
  * \param runmode_custom_id The runmode custom id.
  */
-static RunMode *RunModeGetCustomMode(enum RunModes runmode, const char *custom_mode)
+static RunMode *RunModeGetCustomMode(enum SCRunModes runmode, const char *custom_mode)
 {
     if (runmode < RUNMODE_USER_MAX) {
         for (int i = 0; i < runmodes[runmode].cnt; i++) {
@@ -473,7 +473,7 @@ int RunModeNeedsBypassManager(void)
  * \param description Description for this runmode.
  * \param RunModeFunc The function to be run for this runmode.
  */
-void RunModeRegisterNewRunMode(enum RunModes runmode, const char *name, const char *description,
+void RunModeRegisterNewRunMode(enum SCRunModes runmode, const char *name, const char *description,
         int (*RunModeFunc)(void), int (*RunModeIsIPSEnabled)(void))
 {
     if (RunModeGetCustomMode(runmode, name) != NULL) {
@@ -535,7 +535,7 @@ int RunModeOutputFiledataEnabled(void)
     return filedata_logger_count > 0;
 }
 
-bool IsRunModeSystem(enum RunModes run_mode_to_check)
+bool IsRunModeSystem(enum SCRunModes run_mode_to_check)
 {
     switch (run_mode_to_check) {
         case RUNMODE_PCAP_FILE:
@@ -548,7 +548,7 @@ bool IsRunModeSystem(enum RunModes run_mode_to_check)
     }
 }
 
-bool IsRunModeOffline(enum RunModes run_mode_to_check)
+bool IsRunModeOffline(enum SCRunModes run_mode_to_check)
 {
     switch(run_mode_to_check) {
         case RUNMODE_CONF_TEST:
index 4466d69b9e4bc21aa7755989c10aa542d910513f..748733e4f49dc4e7766956a25f2c143d08327fc0 100644 (file)
@@ -24,7 +24,7 @@
 #define SURICATA_RUNMODES_H
 
 /* Run mode */
-enum RunModes {
+typedef enum SCRunModes {
     RUNMODE_UNKNOWN = 0,
     RUNMODE_PCAP_DEV,
     RUNMODE_PCAP_FILE,
@@ -60,7 +60,7 @@ enum RunModes {
 #endif
     RUNMODE_DUMP_FEATURES,
     RUNMODE_MAX,
-};
+} SCRunMode;
 
 /* Run Mode Global Thread Names */
 extern const char *thread_name_autofp;
@@ -83,7 +83,7 @@ void RunModeListRunmodes(void);
 int RunModeEngineIsIPS(int capture_mode, const char *runmode, const char *capture_plugin_name);
 void RunModeDispatch(int, const char *, const char *capture_plugin_name, const char *capture_plugin_args);
 void RunModeRegisterRunModes(void);
-void RunModeRegisterNewRunMode(enum RunModes, const char *, const char *, int (*RunModeFunc)(void),
+void RunModeRegisterNewRunMode(SCRunMode, const char *, const char *, int (*RunModeFunc)(void),
         int (*RunModeIsIPSEnabled)(void));
 void RunModeInitializeThreadSettings(void);
 void RunModeInitializeOutputs(void);
@@ -92,8 +92,8 @@ void RunModeShutDown(void);
 /* bool indicating if filedata logger is enabled */
 int RunModeOutputFiledataEnabled(void);
 /** bool indicating if run mode is offline */
-bool IsRunModeOffline(enum RunModes run_mode_to_check);
-bool IsRunModeSystem(enum RunModes run_mode_to_check);
+bool IsRunModeOffline(SCRunMode run_mode_to_check);
+bool IsRunModeSystem(SCRunMode run_mode_to_check);
 
 void RunModeEnablesBypassManager(void);
 int RunModeNeedsBypassManager(void);
index 7c3b05f3f8656456bee51be34f3f92b21830e520..ebd411af2733712680b3affe95cdd57f73f2edf8 100644 (file)
@@ -262,12 +262,12 @@ int RunmodeIsUnittests(void)
 }
 #endif
 
-int SCRunmodeGet(void)
+SCRunMode SCRunmodeGet(void)
 {
     return suricata.run_mode;
 }
 
-void SCRunmodeSet(int run_mode)
+void SCRunmodeSet(SCRunMode run_mode)
 {
     suricata.run_mode = run_mode;
 }
@@ -3067,8 +3067,3 @@ void SuricataPostInit(void)
     }
     SCPledge();
 }
-
-void SuricataSetLibRunmode(void)
-{
-    suricata.run_mode = RUNMODE_LIB;
-}
index 311671cb794eeaa69eb18d23a27b20e8a5d3be88..ba83c16b167b70fb3f0b358ded80e297ecfc93d8 100644 (file)
@@ -121,8 +121,8 @@ enum {
 #include "runmodes.h"
 
 typedef struct SCInstance_ {
-    enum RunModes run_mode;
-    enum RunModes aux_run_mode;
+    enum SCRunModes run_mode;
+    enum SCRunModes aux_run_mode;
 
     char pcap_dev[128];
     char *sig_file;
@@ -191,14 +191,14 @@ int RunmodeIsUnittests(void);
 /**
  * \brief Get the current run mode.
  */
-int SCRunmodeGet(void);
+SCRunMode SCRunmodeGet(void);
 
 /**
  * \brief Set the current run mode.
  *
  * Mainly exposed outside of suricata.c as a unit-test helper.
  */
-void SCRunmodeSet(int run_mode);
+void SCRunmodeSet(SCRunMode run_mode);
 
 int SuriHasSigFile(void);
 
@@ -227,7 +227,4 @@ int WindowsInitService(int argc, char **argv);
 
 const char *GetProgramVersion(void);
 
-/* Library only methods. */
-void SuricataSetLibRunmode(void);
-
 #endif /* SURICATA_SURICATA_H */
index 835247090dc17b0746013bfbb3fa93c4d4145a5d..da82234ba42498c0ba056469b58f44ce0dd60666 100644 (file)
@@ -72,6 +72,8 @@ void SCDropMainThreadCaps(uint32_t userid, uint32_t groupid)
                     CAP_SYS_NICE,
                     -1);
             break;
+        default:
+            break;
     }
 
     if (capng_change_id(userid, groupid, CAPNG_DROP_SUPP_GRP |