|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|