From e4d890e1869fc3c7073eeef2ce8699ff2c8a5fa2 Mon Sep 17 00:00:00 2001 From: Anoop Saldanha Date: Wed, 30 Mar 2011 15:13:21 +0530 Subject: [PATCH] modify runmode api to accept conf runmode paramter as a char string, instead of an interger id --- src/runmode-erf-dag.c | 12 +- src/runmode-erf-dag.h | 2 +- src/runmode-erf-file.c | 12 +- src/runmode-erf-file.h | 2 +- src/runmode-ipfw.c | 12 +- src/runmode-ipfw.h | 2 +- src/runmode-nfq.c | 12 +- src/runmode-nfq.h | 2 +- src/runmode-pcap-file.c | 20 ++- src/runmode-pcap-file.h | 2 +- src/runmode-pcap.c | 12 +- src/runmode-pcap.h | 2 +- src/runmode-pfring.c | 34 +++-- src/runmode-pfring.h | 2 +- src/runmodes.c | 276 +++++++++++++++++++++------------------- src/runmodes.h | 8 +- src/suricata.c | 30 +---- suricata.yaml | 6 +- 18 files changed, 213 insertions(+), 235 deletions(-) diff --git a/src/runmode-erf-dag.c b/src/runmode-erf-dag.c index 4fb7c2b2ec..9ea5eeb60e 100644 --- a/src/runmode-erf-dag.c +++ b/src/runmode-erf-dag.c @@ -37,19 +37,19 @@ #include "util-cpu.h" #include "util-affinity.h" -static int default_mode; +static const char *default_mode; -int RunModeErfDagGetDefaultMode(void) +const char *RunModeErfDagGetDefaultMode(void) { return default_mode; } void RunModeErfDagRegister(void) { - default_mode = RunModeRegisterNewRunMode(RUNMODE_DAG, - "erf_dag_auto", - "multi threaded Erf dag mode", - RunModeErfDagAuto); + default_mode = "auto"; + RunModeRegisterNewRunMode(RUNMODE_DAG, "auto", + "Multi threaded Erf dag mode", + RunModeErfDagAuto); return; } diff --git a/src/runmode-erf-dag.h b/src/runmode-erf-dag.h index 53c58ebe89..254b498ef1 100644 --- a/src/runmode-erf-dag.h +++ b/src/runmode-erf-dag.h @@ -25,6 +25,6 @@ int RunModeErfDagAuto(DetectEngineCtx *); void RunModeErfDagRegister(void); -int RunModeErfDagGetDefaultMode(void); +const char *RunModeErfDagGetDefaultMode(void); #endif /* __RUNMODE_ERF_DAG_H__ */ diff --git a/src/runmode-erf-file.c b/src/runmode-erf-file.c index 28c6587784..00bb192800 100644 --- a/src/runmode-erf-file.c +++ b/src/runmode-erf-file.c @@ -37,19 +37,19 @@ #include "util-cpu.h" #include "util-affinity.h" -static int default_mode; +static const char *default_mode; -int RunModeErfFileGetDefaultMode(void) +const char *RunModeErfFileGetDefaultMode(void) { return default_mode; } void RunModeErfFileRegister(void) { - default_mode = RunModeRegisterNewRunMode(RUNMODE_ERF_FILE, - "erf_file_auto", - "multi threaded Erf File mode", - RunModeErfFileAuto); + default_mode = "auto"; + RunModeRegisterNewRunMode(RUNMODE_ERF_FILE, "auto", + "Multi threaded Erf File mode", + RunModeErfFileAuto); return; } diff --git a/src/runmode-erf-file.h b/src/runmode-erf-file.h index e9b1458b15..b2455395eb 100644 --- a/src/runmode-erf-file.h +++ b/src/runmode-erf-file.h @@ -25,6 +25,6 @@ int RunModeErfFileAuto(DetectEngineCtx *); void RunModeErfFileRegister(void); -int RunModeErfFileGetDefaultMode(void); +const char *RunModeErfFileGetDefaultMode(void); #endif /* __RUNMODE_ERF_FILE_H__ */ diff --git a/src/runmode-ipfw.c b/src/runmode-ipfw.c index 5c1e544215..61a850c855 100644 --- a/src/runmode-ipfw.c +++ b/src/runmode-ipfw.c @@ -37,19 +37,19 @@ #include "util-cpu.h" #include "util-affinity.h" -static int default_mode; +static const char *default_mode; -int RunModeIpsIPFWGetDefaultMode(void) +const char *RunModeIpsIPFWGetDefaultMode(void) { return default_mode; } void RunModeIpsIPFWRegister(void) { - default_mode = RunModeRegisterNewRunMode(RUNMODE_IPFW, - "pfring_ipfw_auto", - "multi threaded IPFW IPS mode", - RunModeIpsIPFWAuto); + default_mode = "auto"; + RunModeRegisterNewRunMode(RUNMODE_IPFW, "auto", + "Multi threaded IPFW IPS mode", + RunModeIpsIPFWAuto); return; } diff --git a/src/runmode-ipfw.h b/src/runmode-ipfw.h index 6e658f779a..af698d3157 100644 --- a/src/runmode-ipfw.h +++ b/src/runmode-ipfw.h @@ -25,6 +25,6 @@ int RunModeIpsIPFWAuto(DetectEngineCtx *); void RunModeIpsIPFWRegister(void); -int RunModeIpsIPFWGetDefaultMode(void); +const char *RunModeIpsIPFWGetDefaultMode(void); #endif /* __RUNMODE_IPFW_H__ */ diff --git a/src/runmode-nfq.c b/src/runmode-nfq.c index a08d3f7cb5..a5fef0255b 100644 --- a/src/runmode-nfq.c +++ b/src/runmode-nfq.c @@ -37,19 +37,19 @@ #include "util-cpu.h" #include "util-affinity.h" -static int default_mode; +static const char *default_mode; -int RunModeIpsNFQGetDefaultMode(void) +const char *RunModeIpsNFQGetDefaultMode(void) { return default_mode; } void RunModeIpsNFQRegister(void) { - default_mode = RunModeRegisterNewRunMode(RUNMODE_NFQ, - "nfq_auto", - "multi threaded NFQ IPS mode", - RunModeIpsNFQAuto); + default_mode = "auto"; + RunModeRegisterNewRunMode(RUNMODE_NFQ, "auto", + "Multi threaded NFQ IPS mode", + RunModeIpsNFQAuto); return; } diff --git a/src/runmode-nfq.h b/src/runmode-nfq.h index 5295f47636..bcb9ac1301 100644 --- a/src/runmode-nfq.h +++ b/src/runmode-nfq.h @@ -25,6 +25,6 @@ int RunModeIpsNFQAuto(DetectEngineCtx *); void RunModeIpsNFQRegister(void); -int RunModeIpsNFQGetDefaultMode(void); +const char *RunModeIpsNFQGetDefaultMode(void); #endif /* __RUNMODE_NFQ_H__ */ diff --git a/src/runmode-pcap-file.c b/src/runmode-pcap-file.c index d66cd48ca1..c7f1b0170f 100644 --- a/src/runmode-pcap-file.c +++ b/src/runmode-pcap-file.c @@ -37,26 +37,24 @@ #include "util-cpu.h" #include "util-affinity.h" -static int default_mode; +static const char *default_mode = NULL; -int RunModeFilePcapGetDefaultMode(void) +const char *RunModeFilePcapGetDefaultMode(void) { return default_mode; } void RunModeFilePcapRegister(void) { - RunModeRegisterNewRunMode(RUNMODE_PCAP_FILE, - "pcap_file_single", + RunModeRegisterNewRunMode(RUNMODE_PCAP_FILE, "single", "Single threaded pcap file mode", RunModeFilePcap2); - default_mode = RunModeRegisterNewRunMode(RUNMODE_PCAP_FILE, - "pcap_file_auto", - "multi threaded pcap file mode", - RunModeFilePcapAuto); - RunModeRegisterNewRunMode(RUNMODE_PCAP_FILE, - "pcap_file_autofp", - "multi threaded pcap file mode. Packets from " + RunModeRegisterNewRunMode(RUNMODE_PCAP_FILE, "auto", + "Multi threaded pcap file mode", + RunModeFilePcapAuto); + default_mode = "auto"; + RunModeRegisterNewRunMode(RUNMODE_PCAP_FILE, "autofp", + "Multi threaded pcap file mode. Packets from " "each flow are assigned to a single detect thread, " "unlike \"pcap_file_auto\" where packets from " "the same flow can be processed by any detect " diff --git a/src/runmode-pcap-file.h b/src/runmode-pcap-file.h index 6b62297943..f75e257ff4 100644 --- a/src/runmode-pcap-file.h +++ b/src/runmode-pcap-file.h @@ -27,6 +27,6 @@ int RunModeFilePcap2(DetectEngineCtx *); int RunModeFilePcapAuto(DetectEngineCtx *); int RunModeFilePcapAutoFp(DetectEngineCtx *de_ctx); void RunModeFilePcapRegister(void); -int RunModeFilePcapGetDefaultMode(void); +const char *RunModeFilePcapGetDefaultMode(void); #endif /* __RUNMODE_PCAP_FILE_H__ */ diff --git a/src/runmode-pcap.c b/src/runmode-pcap.c index ccfa4a5a8d..77355de8a4 100644 --- a/src/runmode-pcap.c +++ b/src/runmode-pcap.c @@ -37,19 +37,19 @@ #include "util-cpu.h" #include "util-affinity.h" -static int default_mode; +static const char *default_mode = NULL; -int RunModeIdsGetDefaultMode(void) +const char *RunModeIdsGetDefaultMode(void) { return default_mode; } void RunModeIdsPcapRegister(void) { - default_mode = RunModeRegisterNewRunMode(RUNMODE_PCAP_DEV, - "pcap_dev_auto", - "Multi threaded pcap live mode", - RunModeIdsPcapAuto); + RunModeRegisterNewRunMode(RUNMODE_PCAP_DEV, "auto", + "Multi threaded pcap live mode", + RunModeIdsPcapAuto); + default_mode = "auto"; return; } diff --git a/src/runmode-pcap.h b/src/runmode-pcap.h index 5440cf2105..9dfb0307c7 100644 --- a/src/runmode-pcap.h +++ b/src/runmode-pcap.h @@ -25,6 +25,6 @@ int RunModeIdsPcapAuto(DetectEngineCtx *); void RunModeIdsPcapRegister(void); -int RunModeIdsGetDefaultMode(void); +const char *RunModeIdsGetDefaultMode(void); #endif /* __RUNMODE_PCAP_H__ */ diff --git a/src/runmode-pfring.c b/src/runmode-pfring.c index 0efd62f188..4909d74480 100644 --- a/src/runmode-pfring.c +++ b/src/runmode-pfring.c @@ -38,10 +38,10 @@ #include "util-cpu.h" #include "util-affinity.h" -static int default_mode_auto; -static int default_mode_autofp; +static const char *default_mode_auto = NULL; +static const char *default_mode_autofp = NULL; -int RunModeIdsPfringGetDefaultMode(void) +const char *RunModeIdsPfringGetDefaultMode(void) { #ifdef HAVE_PFRING if (PfringConfGetThreads() == 1) { @@ -50,26 +50,24 @@ int RunModeIdsPfringGetDefaultMode(void) return default_mode_autofp; } #else - return -2; + return NULL; #endif } void RunModeIdsPfringRegister(void) { - default_mode_auto = - RunModeRegisterNewRunMode(RUNMODE_PFRING, - "pfring_auto", - "multi threaded pfring mode", - RunModeIdsPfringAuto); - default_mode_autofp = - RunModeRegisterNewRunMode(RUNMODE_PFRING, - "pfring_autofp", - "multi threaded pfring mode. Packets from " - "each flow are assigned to a single detect " - "thread, unlike \"pfring_auto\" where packets " - "from the same flow can be processed by any " - "detect thread", - RunModeIdsPfringAutoFp); + default_mode_auto = "auto"; + RunModeRegisterNewRunMode(RUNMODE_PFRING, "auto", + "Multi threaded pfring mode", + RunModeIdsPfringAuto); + default_mode_autofp = "autofp"; + RunModeRegisterNewRunMode(RUNMODE_PFRING, "autofp", + "Multi threaded pfring mode. Packets from " + "each flow are assigned to a single detect " + "thread, unlike \"pfring_auto\" where packets " + "from the same flow can be processed by any " + "detect thread", + RunModeIdsPfringAutoFp); return; } diff --git a/src/runmode-pfring.h b/src/runmode-pfring.h index a3e23b5743..8296039f01 100644 --- a/src/runmode-pfring.h +++ b/src/runmode-pfring.h @@ -28,6 +28,6 @@ int RunModeIdsPfringAuto(DetectEngineCtx *); int RunModeIdsPfringAutoFp(DetectEngineCtx *de_ctx); void RunModeIdsPfringRegister(void); -int RunModeIdsPfringGetDefaultMode(void); +const char *RunModeIdsPfringGetDefaultMode(void); #endif /* __RUNMODE_PFRING_H__ */ diff --git a/src/runmodes.c b/src/runmodes.c index aa4e857ee3..d65e5e03da 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -56,8 +56,6 @@ * \brief Holds description for a runmode. */ typedef struct RunMode_ { - /* unique custom id generated for this runmode */ - int custom_id; /* the runmode type */ int runmode; const char *name; @@ -66,6 +64,11 @@ typedef struct RunMode_ { int (*RunModeFunc)(DetectEngineCtx *); } RunMode; +typedef struct RunModes_ { + int no_of_runmodes; + RunMode *runmodes; +} RunModes; + /** * A list of output modules that will be active for the run mode. */ @@ -78,44 +81,7 @@ typedef struct RunModeOutput_ { TAILQ_HEAD(, RunModeOutput_) RunModeOutputs = TAILQ_HEAD_INITIALIZER(RunModeOutputs); -/* unique key used to generate runmode custom ids */ -static int runmode_id = 0; -RunMode *runmodes = NULL; - -/** - * \internal - * \brief Check if a runmode custom id is valid. - * - * \param runmode_custom_id The id to be validated. - * - * \retval 1 If true. - * \retval 0 Otherwise. - */ -int RunModeCustomIdValid(int runmode_custom_id) -{ - if (runmode_custom_id < 0 || runmode_custom_id >= runmode_id) { - return 0; - } - - return 1; -} - -/** - * \brief Register all runmodes in the engine. - */ -void RunModeRegisterRunModes(void) -{ - RunModeIdsPcapRegister(); - RunModeFilePcapRegister(); - RunModeIdsPfringRegister(); - RunModeIpsNFQRegister(); - RunModeIpsIPFWRegister(); - RunModeErfFileRegister(); - RunModeErfDagRegister(); - UtRunModeRegister(); - - return; -} +static RunModes runmodes[RUNMODE_MAX]; /** * \internal @@ -130,38 +96,70 @@ static const char *RunModeTranslateModeToName(int runmode) switch (runmode) { case RUNMODE_PCAP_DEV: return "PCAP_DEV"; - break; case RUNMODE_PCAP_FILE: return "PCAP_FILE"; - break; case RUNMODE_PFRING: #ifdef HAVE_PFRING return "PFRING"; #else return "PFRING(DISABLED)"; #endif - break; case RUNMODE_NFQ: return "NFQ"; - break; case RUNMODE_IPFW: return "IPFW"; - break; case RUNMODE_ERF_FILE: return "ERF_FILE"; - break; case RUNMODE_DAG: return "ERF_DAG"; - break; case RUNMODE_UNITTEST: return "UNITTEST"; - break; default: SCLogError(SC_ERR_UNKNOWN_RUN_MODE, "Unknown runtime mode. Aborting"); exit(EXIT_FAILURE); } } +/** + * \internal + * \brief Dispatcher function for runmodes. Calls the required runmode function + * based on runmode + runmode_custom_id. + * + * \param runmode The runmode type. + * \param runmode_customd_id The runmode custom id. + * \param de_ctx Detection Engine Context. + */ +static RunMode *RunModeGetCustomMode(int runmode, const char *custom_mode) +{ + int i; + + for (i = 0; i < runmodes[runmode].no_of_runmodes; i++) { + if (strcmp(runmodes[runmode].runmodes[i].name, custom_mode) == 0) + return &runmodes[runmode].runmodes[i]; + } + + return NULL; +} + +/** + * \brief Register all runmodes in the engine. + */ +void RunModeRegisterRunModes(void) +{ + memset(runmodes, 0, sizeof(runmodes)); + + RunModeIdsPcapRegister(); + RunModeFilePcapRegister(); + RunModeIdsPfringRegister(); + RunModeIpsNFQRegister(); + RunModeIpsIPFWRegister(); + RunModeErfFileRegister(); + RunModeErfDagRegister(); + UtRunModeRegister(); + + return; +} + /** * \brief Lists all registered runmodes. */ @@ -174,92 +172,91 @@ void RunModeListRunmodes(void) printf("------------------------------------------------------------------" "-----------------------\n"); - printf("| %-2s | %-17s | %-17s | %-10s \n", - "Id", " Mode", " Name-", "Descripition"); + printf("| %-17s | %-17s | %-10s \n", + " RunMode Type", " Custom Mode ", "Descripition"); printf("|-----------------------------------------------------------------" "-----------------------\n"); - int i; - for (i = 0; i < runmode_id; i++) { - printf("| %-2d | %-17s | %-17s | %-27s \n", - i, - RunModeTranslateModeToName(runmodes[i].runmode), - runmodes[i].name, - runmodes[i].description); + int i = RUNMODE_UNKNOWN + 1; + int j = 0; + for ( ; i < RUNMODE_MAX; i++) { + int mode_displayed = 0; + for (j = 0; j < runmodes[i].no_of_runmodes; j++) { + if (mode_displayed == 1) { + printf("| ----------------------------------------------" + "-----------------------\n"); + RunMode *runmode = &runmodes[i].runmodes[j]; + printf("| %-17s | %-17s | %-27s \n", + "", + runmode->name, + runmode->description); + } else { + RunMode *runmode = &runmodes[i].runmodes[j]; + printf("| %-17s | %-17s | %-27s \n", + RunModeTranslateModeToName(runmode->runmode), + runmode->name, + runmode->description); + } + if (mode_displayed == 0) + mode_displayed = 1; + } + printf("|-----------------------------------------------------------------" + "-----------------------\n"); } - printf("|-----------------------------------------------------------------" - "-----------------------\n"); return; } -/** - * \brief Dispatcher function for runmodes. Calls the required runmode function - * based on runmode + runmode_custom_id. - * - * \param runmode The runmode type. - * \param runmode_customd_id The runmode custom id. - * \param de_ctx Detection Engine Context. - */ -void RunModeDispatch(int runmode, int runmode_custom_id, DetectEngineCtx *de_ctx) +void RunModeDispatch(int runmode, const char *custom_mode, DetectEngineCtx *de_ctx) { - if (runmode_custom_id != -1 && - (runmode_custom_id < 0 || runmode_custom_id >= runmode_id)) { - SCLogError(SC_ERR_RUNMODE, "You have supplied wrong runmode type - " - "%d", runmode_custom_id); - exit(EXIT_FAILURE); - } - - if (runmode_custom_id != -1) { - if (runmode != runmodes[runmode_custom_id].runmode) { - SCLogError(SC_ERR_RUNMODE, "The runmode custom id's(%d) " - "runmode - \"%s\" doesn't match the runmode type - \"%s\" " - "being used. Please use runmode id whose RunMode " - "mode matches the mode you are running the " - "engine in.", - runmode_custom_id, - RunModeTranslateModeToName(runmodes[runmode_custom_id].runmode), - RunModeTranslateModeToName(runmode)); - exit(EXIT_FAILURE); + if (custom_mode == NULL) { + char *val = NULL; + if (ConfGet("runmode", &val) != 1) { + custom_mode = NULL; + } else { + custom_mode = val; } - runmodes[runmode_custom_id].RunModeFunc(de_ctx); - return; } - switch (runmode) { - case RUNMODE_PCAP_DEV: - runmode_custom_id = RunModeIdsGetDefaultMode(); - break; - case RUNMODE_PCAP_FILE: - runmode_custom_id = RunModeFilePcapGetDefaultMode(); - break; + if (custom_mode == NULL) { + switch (runmode) { + case RUNMODE_PCAP_DEV: + custom_mode = RunModeIdsGetDefaultMode(); + break; + case RUNMODE_PCAP_FILE: + custom_mode = RunModeFilePcapGetDefaultMode(); + break; #ifdef HAVE_PFRING - case RUNMODE_PFRING: - runmode_custom_id = RunModeIdsPfringGetDefaultMode(); - break; + case RUNMODE_PFRING: + custom_mode = RunModeIdsPfringGetDefaultMode(); + break; #endif - case RUNMODE_NFQ: - runmode_custom_id = RunModeIpsNFQGetDefaultMode(); - break; - case RUNMODE_IPFW: - runmode_custom_id = RunModeIpsIPFWGetDefaultMode(); - break; - case RUNMODE_ERF_FILE: - runmode_custom_id = RunModeErfFileGetDefaultMode(); - break; - case RUNMODE_DAG: - runmode_custom_id = RunModeErfDagGetDefaultMode(); - break; - default: - SCLogError(SC_ERR_UNKNOWN_RUN_MODE, "Unknown runtime mode. Aborting"); - exit(EXIT_FAILURE); - } - - if (runmode_custom_id < 0 && runmode_custom_id >= runmode_id) { - SCLogError(SC_ERR_RUNMODE, "Wrong default custom id - %d, returned by " - "runmode - %d", runmode_custom_id, runmode); + case RUNMODE_NFQ: + custom_mode = RunModeIpsNFQGetDefaultMode(); + break; + case RUNMODE_IPFW: + custom_mode = RunModeIpsIPFWGetDefaultMode(); + break; + case RUNMODE_ERF_FILE: + custom_mode = RunModeErfFileGetDefaultMode(); + break; + case RUNMODE_DAG: + custom_mode = RunModeErfDagGetDefaultMode(); + break; + default: + SCLogError(SC_ERR_UNKNOWN_RUN_MODE, "Unknown runtime mode. Aborting"); + exit(EXIT_FAILURE); + } + } /* if (custom_mode == NULL) */ + + RunMode *mode = RunModeGetCustomMode(runmode, custom_mode); + if (mode == NULL) { + SCLogError(SC_ERR_RUNMODE, "The custom type \"%s\" doesn't exist " + "for this runmode type \"%s\". Please use --list-runmodes to " + "see available custom types for this runmode", + custom_mode, RunModeTranslateModeToName(runmode)); + exit(EXIT_FAILURE); } - - runmodes[runmode_custom_id].RunModeFunc(de_ctx); + mode->RunModeFunc(de_ctx); return; } @@ -268,26 +265,37 @@ void RunModeDispatch(int runmode, int runmode_custom_id, DetectEngineCtx *de_ctx * \brief Registers a new runmode. * * \param runmode Runmode type. - * \param name Simple name. Need not be unique, although suggested. + * \param name Custom mode for this specific runmode type. Within each + * runmode type, each custom name is a primary key. * \param description Description for this runmode. * \param RunModeFunc The function to be run for this runmode. */ -int RunModeRegisterNewRunMode(uint8_t runmode, const char *name, - const char *description, - int (*RunModeFunc)(DetectEngineCtx *)) +void RunModeRegisterNewRunMode(int runmode, const char *name, + const char *description, + int (*RunModeFunc)(DetectEngineCtx *)) { - runmodes = SCRealloc(runmodes, (runmode_id + 1) * sizeof(RunMode)); - if (runmodes == NULL) { + if (RunModeGetCustomMode(runmode, name) != NULL) { + SCLogError(SC_ERR_RUNMODE, "A runmode by this custom name has already " + "been registered. Please use an unique name"); + return; + } + + runmodes[runmode].runmodes = + SCRealloc(runmodes[runmode].runmodes, + (runmodes[runmode].no_of_runmodes + 1) * sizeof(RunMode)); + if (runmodes[runmode].runmodes == NULL) { exit(EXIT_FAILURE); } - runmodes[runmode_id].custom_id = runmode_id; - runmodes[runmode_id].runmode = runmode; - runmodes[runmode_id].name = SCStrdup(name); - runmodes[runmode_id].description = SCStrdup(description); - runmodes[runmode_id].RunModeFunc = RunModeFunc; - runmode_id++; - - return runmode_id - 1; + + RunMode *mode = &runmodes[runmode].runmodes[runmodes[runmode].no_of_runmodes]; + runmodes[runmode].no_of_runmodes++; + + mode->runmode = runmode; + mode->name = SCStrdup(name); + mode->description = SCStrdup(description); + mode->RunModeFunc = RunModeFunc; + + return; } /** diff --git a/src/runmodes.h b/src/runmodes.h index b6aebdfcf3..1aa0722553 100644 --- a/src/runmodes.h +++ b/src/runmodes.h @@ -37,13 +37,11 @@ enum { RUNMODE_MAX, }; -int RunModeCustomIdValid(int); void RunModeListRunmodes(void); -void RunModeDispatch(int, int, DetectEngineCtx *); +void RunModeDispatch(int, const char *, DetectEngineCtx *); void RunModeRegisterRunModes(void); -int RunModeRegisterNewRunMode(uint8_t, const char *, - const char *, - int (*RunModeFunc)(DetectEngineCtx *)); +void RunModeRegisterNewRunMode(int, const char *, const char *, + int (*RunModeFunc)(DetectEngineCtx *)); void RunModeInitialize(void); void RunModeInitializeOutputs(void); void SetupOutputs(ThreadVars *); diff --git a/src/suricata.c b/src/suricata.c index 49476a17ea..10ecc1b1e6 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -497,7 +497,7 @@ int main(int argc, char **argv) int list_unittests = 0; int list_cuda_cards = 0; int list_runmodes = 0; - int runmode_custom_id = -1; + const char *runmode_custom_mode = NULL; int daemon = 0; char *user_name = NULL; char *group_name = NULL; @@ -659,13 +659,7 @@ int main(int argc, char **argv) RunModeListRunmodes(); exit(EXIT_SUCCESS); } else if (strcmp((long_opts[option_index]).name, "runmode") == 0) { - runmode_custom_id = atoi(optarg); - if (!RunModeCustomIdValid(runmode_custom_id)) { - fprintf(stderr, "ERROR: Invalid runmode id - \"%d\" supplied. " - "Please pass valid runmode id from " - "--list-runmodes.\n", runmode_custom_id); - exit(EXIT_FAILURE); - } + runmode_custom_mode = optarg; } else if(strcmp((long_opts[option_index]).name, "engine-analysis") == 0) { // do nothing for now } @@ -941,24 +935,6 @@ int main(int argc, char **argv) exit(EXIT_SUCCESS); } - /* If runmode isn't supplied in the command line, retrieve it from the conf - * file. If supplied in command line, the command line version overrides - * conf file */ - if (runmode_custom_id == -1) { - intmax_t val; - if (ConfGetInt("runmode", &val) != 1) { - runmode_custom_id = -1; - } else { - runmode_custom_id = val; - if (!RunModeCustomIdValid(runmode_custom_id)) { - fprintf(stderr, "ERROR: Invalid runmode id - \"%d\" supplied " - "in conf file. Please pass valid runmode id from " - "--list-runmodes.\n", runmode_custom_id); - exit(EXIT_FAILURE); - } - } - } - /* Check for the existance of the default logging directory which we pick * from suricata.yaml. If not found, shut the engine down */ if (ConfGet("default-log-dir", &log_dir) != 1) @@ -1335,7 +1311,7 @@ int main(int argc, char **argv) } } - RunModeDispatch(run_mode, runmode_custom_id, de_ctx); + RunModeDispatch(run_mode, runmode_custom_mode, de_ctx); #ifdef __SC_CUDA_SUPPORT__ if (PatternMatchDefaultMatcher() == MPM_B2G_CUDA) { diff --git a/suricata.yaml b/suricata.yaml index 57531b2947..a872d8a6f9 100644 --- a/suricata.yaml +++ b/suricata.yaml @@ -15,9 +15,9 @@ # pattern matcher scans many packets in parallel. #max-pending-packets: 50 -# Runmode custom id the engine should run in. Please check --list-runmodes -# to get the runmode ids that can be used here. -#runmode: 0 +# Runmode custom mode the engine should run in. Please check --list-runmodes +# to get the runmode custom modes that can be used here for a particular runmode. +#runmode: auto # Preallocated size for packet. Default is 1514 which is the classical # size for pcap on ethernet. You should adjust this value to the highest