]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricata: separate keyword and app layer listing code
authorEric Leblond <eric@regit.org>
Tue, 9 Apr 2013 09:05:39 +0000 (11:05 +0200)
committerEric Leblond <eric@regit.org>
Mon, 29 Jul 2013 07:56:36 +0000 (09:56 +0200)
The list-keyword and app-layer listing code was spread over all the
init code. This patch introduces a separate file to store non standard
running mode like these ones.

src/Makefile.am
src/suricata.c
src/util-running-modes.c [new file with mode: 0644]
src/util-running-modes.h [new file with mode: 0644]

index fbd0558992d6b3b9479574d3219ffc28b48078ff..c80146a6d55f85947ad34cd4660cb16a0a38a04f 100644 (file)
@@ -318,6 +318,7 @@ util-ringbuffer.c util-ringbuffer.h \
 util-rohash.c util-rohash.h \
 util-rule-vars.c util-rule-vars.h \
 util-runmodes.c util-runmodes.h \
+util-running-modes.c util-running-modes.h \
 util-signal.c util-signal.h \
 util-spm-bm.c util-spm-bm.h \
 util-spm-bs2bm.c util-spm-bs2bm.h \
index 030c7b31b1fc0b5c29693af73a55df8255db65c0..953d114b08a012a913331afa90834b02906f6222 100644 (file)
@@ -58,6 +58,7 @@
 #include "util-ioctl.h"
 #include "util-device.h"
 #include "util-misc.h"
+#include "util-running-modes.h"
 
 #include "detect-parse.h"
 #include "detect-engine.h"
@@ -1317,20 +1318,25 @@ int main(int argc, char **argv)
         }
     }
 
-    if (!list_keywords && !list_app_layer_protocols) {
+    if (list_keywords) {
+        return SuriListKeywords(keyword_info);
+    }
+
+    if (list_app_layer_protocols) {
+        return SuriListAppLayerProtocols();
+    }
+
 #ifdef REVISION
-        SCLogInfo("This is %s version %s (rev %s)", PROG_NAME, PROG_VER, xstr(REVISION));
+    SCLogInfo("This is %s version %s (rev %s)", PROG_NAME, PROG_VER, xstr(REVISION));
 #elif defined RELEASE
-        SCLogInfo("This is %s version %s RELEASE", PROG_NAME, PROG_VER);
+    SCLogInfo("This is %s version %s RELEASE", PROG_NAME, PROG_VER);
 #else
-        SCLogInfo("This is %s version %s", PROG_NAME, PROG_VER);
+    SCLogInfo("This is %s version %s", PROG_NAME, PROG_VER);
 #endif
-    }
 
     SetBpfString(optind, argv);
 
-    if (!list_keywords && !list_app_layer_protocols)
-        UtilCpuPrintSummary();
+    UtilCpuPrintSummary();
 
 #ifdef __SC_CUDA_SUPPORT__
     /* Init the CUDA environment */
@@ -1351,9 +1357,7 @@ int main(int argc, char **argv)
     TimeInit();
     SupportFastPatternForSigMatchTypes();
 
-    if (run_mode != RUNMODE_UNITTEST &&
-            !list_keywords &&
-            !list_app_layer_protocols) {
+    if (run_mode != RUNMODE_UNITTEST) {
         if (conf_filename == NULL)
             conf_filename = DEFAULT_CONF_FILE;
     }
@@ -1405,10 +1409,6 @@ int main(int argc, char **argv)
 #endif
 
     AppLayerDetectProtoThreadInit();
-    if (list_app_layer_protocols) {
-        AppLayerListSupportedProtocols();
-        exit(EXIT_SUCCESS);
-    }
     AppLayerParsersInitPostProcess();
 
     if (dump_config) {
@@ -1429,17 +1429,15 @@ int main(int argc, char **argv)
 #endif /* OS_WIN32 */
     }
 
-    if (!list_keywords && !list_app_layer_protocols) {
 #ifdef OS_WIN32
-        if (_stat(log_dir, &buf) != 0) {
+    if (_stat(log_dir, &buf) != 0) {
 #else
-        if (stat(log_dir, &buf) != 0) {
+    if (stat(log_dir, &buf) != 0) {
 #endif /* OS_WIN32 */
-            SCLogError(SC_ERR_LOGDIR_CONFIG, "The logging directory \"%s\" "
-                        "supplied by %s (default-log-dir) doesn't exist. "
-                        "Shutting down the engine", log_dir, conf_filename);
-            exit(EXIT_FAILURE);
-        }
+        SCLogError(SC_ERR_LOGDIR_CONFIG, "The logging directory \"%s\" "
+                "supplied by %s (default-log-dir) doesn't exist. "
+                "Shutting down the engine", log_dir, conf_filename);
+        exit(EXIT_FAILURE);
     }
 
     /* Pull the max pending packets from the config, if not found fall
@@ -1493,13 +1491,12 @@ int main(int argc, char **argv)
 
     /* Load the Host-OS lookup. */
     SCHInfoLoadFromConfig();
-    if (!list_keywords && !list_app_layer_protocols &&
-        (run_mode != RUNMODE_UNIX_SOCKET)) {
+    if (run_mode != RUNMODE_UNIX_SOCKET) {
         DefragInit();
     }
 
     if (run_mode == RUNMODE_UNKNOWN) {
-        if (!engine_analysis && !list_keywords && !conf_test) {
+        if (!engine_analysis && !conf_test) {
             usage(argv[0]);
             exit(EXIT_FAILURE);
         }
@@ -1529,10 +1526,6 @@ int main(int argc, char **argv)
 
     /* hardcoded initialization code */
     SigTableSetup(); /* load the rule keywords */
-    if (list_keywords) {
-        SigTableList(keyword_info);
-        exit(EXIT_FAILURE);
-    }
     TmqhSetup();
 
     StorageInit();
diff --git a/src/util-running-modes.c b/src/util-running-modes.c
new file mode 100644 (file)
index 0000000..439d27f
--- /dev/null
@@ -0,0 +1,39 @@
+/* Copyright (C) 2013 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/** \file
+ *
+ *  \author Eric Leblond <eric@regit.org>
+ */
+
+#include "suricata-common.h"
+#include "app-layer-detect-proto.h"
+
+int SuriListKeywords(const char *keyword_info)
+{
+    SigTableSetup(); /* load the rule keywords */
+    SigTableList(keyword_info);
+    exit(EXIT_SUCCESS);
+}
+
+int SuriListAppLayerProtocols()
+{
+    MpmTableSetup();
+    AppLayerDetectProtoThreadInit();
+    AppLayerListSupportedProtocols();
+    exit(EXIT_SUCCESS);
+}
diff --git a/src/util-running-modes.h b/src/util-running-modes.h
new file mode 100644 (file)
index 0000000..e4a421c
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (C) 2013 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/** \file
+ *
+ *  \author Eric Leblond <eric@regit.org>
+ */
+
+#ifndef __UTIL_RUNNING_MODES_H__
+#define __UTIL_RUNNING_MODES_H__
+
+
+int SuriListKeywords(const char *keyword_info);
+int SuriListAppLayerProtocols();
+
+
+#endif /* __UTIL_RUNNING_MODES_H__ */