]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/feature: Support --dump-features
authorJeff Lucovsky <jeff@lucovsky.org>
Sat, 21 Dec 2019 16:16:31 +0000 (11:16 -0500)
committerVictor Julien <victor@inliniac.net>
Tue, 18 Feb 2020 15:25:21 +0000 (16:25 +0100)
src/feature.c
src/feature.h
src/runmodes.h
src/suricata.c

index d759194f037f0cf8892827fab013bbd53b1cfb01..00806b62afae90bfd53d981f0aa9c0edf646642f 100644 (file)
@@ -123,24 +123,30 @@ void ProvidesFeature(const char *feature_name)
 
 bool RequiresFeature(const char *feature_name)
 {
-    FeatureEntryType t = { 0, feature_name };
+    FeatureEntryType f = { feature_name };
 
     SCMutexLock(&feature_table_mutex);
-    FeatureEntryType *feature = HashTableLookup(feature_hash_table, &t, sizeof(t));
+    FeatureEntryType *feature = HashListTableLookup(feature_hash_table, &f, sizeof(f));
     SCMutexUnlock(&feature_table_mutex);
-
     return feature != NULL;
 }
 
 void FeatureTrackingRelease(void)
 {
     if (feature_hash_table != NULL) {
-        HashTableFree(feature_hash_table);
+        HashListTableFree(feature_hash_table);
         feature_hash_table = NULL;
-        feature_table_id = 0;
     }
 }
 
+void FeatureDump(void)
+{
+    HashListTableBucket *hb = HashListTableGetListHead(feature_hash_table);
+    for (; hb != NULL; hb = HashListTableGetListNext(hb)) {
+        FeatureEntryType *f = HashListTableGetListData(hb);
+        printf("provided feature name: %s\n", f->feature);
+    }
+}
 void FeatureTrackingRegister(void)
 {
     FeatureInit();
index 3bb48a097e4dace4d47c360a0c6fb2cea4e91172..6549c5bbeab5fc7155468e4098ba17aca00a6e12 100644 (file)
@@ -30,6 +30,8 @@
 void ProvidesFeature(const char *);
 bool RequiresFeature(const char *);
 
+void FeatureDump(void);
+
 void FeatureTrackingRelease(void);
 void FeatureTrackingRegister(void);
 
index c1202b75c186b949d214e518038c6c9a4cf1a103..b4370790093377eaa9ea7a5f2173e8ef85d9ca59 100644 (file)
@@ -56,6 +56,7 @@ enum RunModes {
     RUNMODE_REMOVE_SERVICE,
     RUNMODE_CHANGE_SERVICE_PARAMS,
 #endif
+    RUNMODE_DUMP_FEATURES,
     RUNMODE_MAX,
 };
 
index e06620d7ed1007847fd0797113e83ba976c606e9..e0cd02cb9fe557764ba9d93327eee3b0a9c61d5b 100644 (file)
@@ -621,6 +621,7 @@ static void PrintUsage(const char *progname)
     printf("\t--init-errors-fatal                  : enable fatal failure on signature init error\n");
     printf("\t--disable-detection                  : disable detection engine\n");
     printf("\t--dump-config                        : show the running configuration\n");
+    printf("\t--dump-features                      : display provided features\n");
     printf("\t--build-info                         : display build information\n");
     printf("\t--pcap[=<dev>]                       : run in pcap mode, no value select interfaces from suricata.yaml\n");
     printf("\t--pcap-file-continuous               : when running in pcap mode with a directory, continue checking directory for pcaps until interrupted\n");
@@ -1421,6 +1422,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
     int opt;
 
     int dump_config = 0;
+    int dump_features = 0;
     int list_app_layer_protocols = 0;
     int list_unittests = 0;
     int list_runmodes = 0;
@@ -1441,6 +1443,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
 
     struct option long_opts[] = {
         {"dump-config", 0, &dump_config, 1},
+        {"dump-features", 0, &dump_features, 1},
         {"pfring", optional_argument, 0, 0},
         {"pfring-int", required_argument, 0, 0},
         {"pfring-cluster-id", required_argument, 0, 0},
@@ -2137,6 +2140,8 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
         suri->run_mode = RUNMODE_LIST_UNITTEST;
     if (dump_config)
         suri->run_mode = RUNMODE_DUMP_CONFIG;
+    if (dump_features)
+        suri->run_mode = RUNMODE_DUMP_FEATURES;
     if (conf_test)
         suri->run_mode = RUNMODE_CONF_TEST;
     if (engine_analysis)
@@ -3063,6 +3068,9 @@ int SuricataMain(int argc, char **argv)
     } else if (suricata.run_mode == RUNMODE_CONF_TEST){
         SCLogNotice("Configuration provided was successfully loaded. Exiting.");
         goto out;
+    } else if (suricata.run_mode == RUNMODE_DUMP_FEATURES) {
+        FeatureDump();
+        goto out;
     }
 
     SCSetStartTime(&suricata);