classification: update pcre globals use

Don't update globals each time we parse, but instead do it once at
startup.
pull/1484/head
Victor Julien 11 years ago
parent b2da57c827
commit 46d401e3bb

@ -2257,6 +2257,7 @@ int main(int argc, char **argv)
DetectEngineCtx *de_ctx = NULL; DetectEngineCtx *de_ctx = NULL;
if (!suri.disabled_detect) { if (!suri.disabled_detect) {
SCClassConfInit();
SetupDelayedDetect(&suri); SetupDelayedDetect(&suri);
if (!suri.delayed_detect) { if (!suri.delayed_detect) {
de_ctx = DetectEngineCtxInit(); de_ctx = DetectEngineCtxInit();
@ -2485,6 +2486,9 @@ int main(int argc, char **argv)
if (suri.run_mode != RUNMODE_UNIX_SOCKET) { if (suri.run_mode != RUNMODE_UNIX_SOCKET) {
DefragDestroy(); DefragDestroy();
} }
if (!suri.disabled_detect) {
SCClassConfDeinit();
}
MagicDeinit(); MagicDeinit();
TmqhCleanup(); TmqhCleanup();
TmModuleRunDeInit(); TmModuleRunDeInit();

@ -47,8 +47,6 @@
#define SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/classification.config" #define SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/classification.config"
#endif #endif
/* Holds a pointer to the default path for the classification.config file */
static const char *default_file_path = SC_CLASS_CONF_DEF_CONF_FILEPATH;
static pcre *regex = NULL; static pcre *regex = NULL;
static pcre_extra *regex_study = NULL; static pcre_extra *regex_study = NULL;
@ -58,6 +56,42 @@ char SCClassConfClasstypeHashCompareFunc(void *data1, uint16_t datalen1,
void SCClassConfClasstypeHashFree(void *ch); void SCClassConfClasstypeHashFree(void *ch);
static char *SCClassConfGetConfFilename(void); static char *SCClassConfGetConfFilename(void);
void SCClassConfInit(void)
{
const char *eb = NULL;
int eo;
int opts = 0;
regex = pcre_compile(DETECT_CLASSCONFIG_REGEX, opts, &eb, &eo, NULL);
if (regex == NULL) {
SCLogDebug("Compile of \"%s\" failed at offset %" PRId32 ": %s",
DETECT_CLASSCONFIG_REGEX, eo, eb);
return;
}
regex_study = pcre_study(regex, 0, &eb);
if (eb != NULL) {
pcre_free(regex);
regex = NULL;
SCLogDebug("pcre study failed: %s", eb);
return;
}
return;
}
void SCClassConfDeinit(void)
{
if (regex != NULL) {
pcre_free(regex);
regex = NULL;
}
if (regex_study != NULL) {
pcre_free(regex_study);
regex_study = NULL;
}
}
/** /**
* \brief Inits the context to be used by the Classification Config parsing API. * \brief Inits the context to be used by the Classification Config parsing API.
* *
@ -74,9 +108,6 @@ static char *SCClassConfGetConfFilename(void);
FILE *SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd) FILE *SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
{ {
char *filename = NULL; char *filename = NULL;
const char *eb = NULL;
int eo;
int opts = 0;
/* init the hash table to be used by the classification config Classtypes */ /* init the hash table to be used by the classification config Classtypes */
de_ctx->class_conf_ht = HashTableInit(128, SCClassConfClasstypeHashFunc, de_ctx->class_conf_ht = HashTableInit(128, SCClassConfClasstypeHashFunc,
@ -104,19 +135,6 @@ FILE *SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
} }
} }
regex = pcre_compile(DETECT_CLASSCONFIG_REGEX, opts, &eb, &eo, NULL);
if (regex == NULL) {
SCLogDebug("Compile of \"%s\" failed at offset %" PRId32 ": %s",
DETECT_CLASSCONFIG_REGEX, eo, eb);
goto error;
}
regex_study = pcre_study(regex, 0, &eb);
if (eb != NULL) {
SCLogDebug("pcre study failed: %s", eb);
goto error;
}
return fd; return fd;
error: error:
@ -129,15 +147,6 @@ FILE *SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
fd = NULL; fd = NULL;
} }
if (regex != NULL) {
pcre_free(regex);
regex = NULL;
}
if (regex_study != NULL) {
pcre_free(regex_study);
regex_study = NULL;
}
return NULL; return NULL;
} }
@ -156,7 +165,7 @@ static char *SCClassConfGetConfFilename(void)
char *log_filename = NULL; char *log_filename = NULL;
if (ConfGet("classification-file", &log_filename) != 1) { if (ConfGet("classification-file", &log_filename) != 1) {
log_filename = (char *)default_file_path; log_filename = (char *)SC_CLASS_CONF_DEF_CONF_FILEPATH;
} }
return log_filename; return log_filename;
@ -171,18 +180,6 @@ static void SCClassConfDeInitLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
fclose(fd); fclose(fd);
fd = NULL; fd = NULL;
} }
default_file_path = SC_CLASS_CONF_DEF_CONF_FILEPATH;
if (regex != NULL) {
pcre_free(regex);
regex = NULL;
}
if (regex_study != NULL) {
pcre_free(regex_study);
regex_study = NULL;
}
return;
} }
/** /**

@ -56,4 +56,7 @@ FILE *SCClassConfGenerateValidDummyClassConfigFD01(void);
FILE *SCClassConfGenerateInValidDummyClassConfigFD02(void); FILE *SCClassConfGenerateInValidDummyClassConfigFD02(void);
FILE *SCClassConfGenerateInValidDummyClassConfigFD03(void); FILE *SCClassConfGenerateInValidDummyClassConfigFD03(void);
void SCClassConfInit(void);
void SCClassConfDeinit(void);
#endif /* __UTIL_CLASSIFICATION_CONFIG_H__ */ #endif /* __UTIL_CLASSIFICATION_CONFIG_H__ */

Loading…
Cancel
Save