]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
classification: update pcre globals use
authorVictor Julien <victor@inliniac.net>
Wed, 13 May 2015 07:37:39 +0000 (09:37 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 13 May 2015 07:37:39 +0000 (09:37 +0200)
Don't update globals each time we parse, but instead do it once at
startup.

src/suricata.c
src/util-classification-config.c
src/util-classification-config.h

index d87f4d52ca4df11c1d8e652edb2fc6e725cbe6e7..9582b106fb209a8846c30349aa904928dfea089c 100644 (file)
@@ -2257,6 +2257,7 @@ int main(int argc, char **argv)
 
     DetectEngineCtx *de_ctx = NULL;
     if (!suri.disabled_detect) {
+        SCClassConfInit();
         SetupDelayedDetect(&suri);
         if (!suri.delayed_detect) {
             de_ctx = DetectEngineCtxInit();
@@ -2485,6 +2486,9 @@ int main(int argc, char **argv)
     if (suri.run_mode != RUNMODE_UNIX_SOCKET) {
         DefragDestroy();
     }
+    if (!suri.disabled_detect) {
+        SCClassConfDeinit();
+    }
     MagicDeinit();
     TmqhCleanup();
     TmModuleRunDeInit();
index af952e67593e113c7c97077b0e60014844ec5d41..3711dd32b1b3d2b107980373d8355886640aea20 100644 (file)
@@ -47,8 +47,6 @@
 #define SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/classification.config"
 #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_extra *regex_study = NULL;
 
@@ -58,6 +56,42 @@ char SCClassConfClasstypeHashCompareFunc(void *data1, uint16_t datalen1,
 void SCClassConfClasstypeHashFree(void *ch);
 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.
  *
@@ -74,9 +108,6 @@ static char *SCClassConfGetConfFilename(void);
 FILE *SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
 {
     char *filename = NULL;
-    const char *eb = NULL;
-    int eo;
-    int opts = 0;
 
     /* init the hash table to be used by the classification config Classtypes */
     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;
 
  error:
@@ -129,15 +147,6 @@ FILE *SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
         fd = NULL;
     }
 
-    if (regex != NULL) {
-        pcre_free(regex);
-        regex = NULL;
-    }
-    if (regex_study != NULL) {
-        pcre_free(regex_study);
-        regex_study = NULL;
-    }
-
     return NULL;
 }
 
@@ -156,7 +165,7 @@ static char *SCClassConfGetConfFilename(void)
     char *log_filename = NULL;
 
     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;
@@ -171,18 +180,6 @@ static void SCClassConfDeInitLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
         fclose(fd);
         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;
 }
 
 /**
index 7d9748ed5997e3498112e4ed63a749c5c47695b4..7e916c2cd2efa64a0be9551902b8a60cdf0462d6 100644 (file)
@@ -56,4 +56,7 @@ FILE *SCClassConfGenerateValidDummyClassConfigFD01(void);
 FILE *SCClassConfGenerateInValidDummyClassConfigFD02(void);
 FILE *SCClassConfGenerateInValidDummyClassConfigFD03(void);
 
+void SCClassConfInit(void);
+void SCClassConfDeinit(void);
+
 #endif /* __UTIL_CLASSIFICATION_CONFIG_H__ */