]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
sources: allow interface definitions to be reordered
authorJason Ish <ish@unx.ca>
Thu, 5 May 2016 15:41:45 +0000 (09:41 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 9 May 2016 18:31:02 +0000 (20:31 +0200)
For af-packet, pf-ring, netmap, and pcap use a generic
lookup function to find the configuration node for an
interface.

The new lookup function does not depend on the ordering
of the items inside the device configuration.

src/runmode-af-packet.c
src/runmode-netmap.c
src/runmode-pcap.c
src/runmode-pfring.c
src/util-conf.c
src/util-conf.h

index 85d4c770a0f6f701423d486194c669bfdbf1642e..73bd263e1e354a976d9086f7b86a66cafcf1f8f0 100644 (file)
@@ -163,9 +163,9 @@ void *ParseAFPConfig(const char *iface)
         return aconf;
     }
 
-    if_root = ConfNodeLookupKeyValue(af_packet_node, "interface", iface);
+    if_root = ConfFindDeviceConfig(af_packet_node, iface);
 
-    if_default = ConfNodeLookupKeyValue(af_packet_node, "interface", "default");
+    if_default = ConfFindDeviceConfig(af_packet_node, "default");
 
     if (if_root == NULL && if_default == NULL) {
         SCLogInfo("Unable to find af-packet config for "
@@ -433,7 +433,7 @@ int AFPRunModeIsIPS()
             return 0;
         }
         char *copymodestr = NULL;
-        if_root = ConfNodeLookupKeyValue(af_packet_node, "interface", live_dev);
+        if_root = ConfFindDeviceConfig(af_packet_node, live_dev);
 
         if (if_root == NULL) {
             if (if_default == NULL) {
index 13a0c2b3d900d4fa716031b274aa3c921256643d..6ddad0439197f7b5c669b9efdd62b5665fe2731a 100644 (file)
@@ -159,9 +159,9 @@ static void *ParseNetmapConfig(const char *iface_name)
         return aconf;
     }
 
-    if_root = ConfNodeLookupKeyValue(netmap_node, "interface", aconf->iface_name);
+    if_root = ConfFindDeviceConfig(netmap_node, "interface", aconf->iface_name);
 
-    if_default = ConfNodeLookupKeyValue(netmap_node, "interface", "default");
+    if_default = ConfFindDeviceConfig(netmap_node, "default");
 
     if (if_root == NULL && if_default == NULL) {
         SCLogInfo("Unable to find netmap config for "
index a08150109f4798e6842d08b234fcfe4e7008455e..c2d806fff93a4eafecf9f642b6b3e49508dd015c 100644 (file)
@@ -121,9 +121,9 @@ void *ParsePcapConfig(const char *iface)
         return aconf;
     }
 
-    if_root = ConfNodeLookupKeyValue(pcap_node, "interface", iface);
+    if_root = ConfFindDeviceConfig(pcap_node, "iface");
 
-    if_default = ConfNodeLookupKeyValue(pcap_node, "interface", "default");
+    if_default = ConfFindDeviceConfig(pcap_node, "default");
 
     if (if_root == NULL && if_default == NULL) {
         SCLogInfo("Unable to find pcap config for "
index f7aa410a5dace223b3a0e033d7ff58eb92114e95..5332252570f573472de96c4d6d1cccf66993a362 100644 (file)
@@ -230,9 +230,9 @@ void *ParsePfringConfig(const char *iface)
         return pfconf;
     }
 
-    if_root = ConfNodeLookupKeyValue(pf_ring_node, "interface", iface);
+    if_root = ConfFindDeviceConfig(pf_ring_node, iface);
 
-    if_default = ConfNodeLookupKeyValue(pf_ring_node, "interface", "default");
+    if_default = ConfFindDeviceConfig(pf_ring_node, "default");
 
     if (if_root == NULL && if_default == NULL) {
         SCLogInfo("Unable to find pfring config for "
index e0f25d1d6395f3ee7b9f06eac48f2e36cd58dd82..17f5edfe32aad88704ed96d89c3375cd1205319b 100644 (file)
@@ -25,6 +25,7 @@
 #include "suricata-common.h"
 #include "config.h"
 #include "conf.h"
+#include "util-conf.h"
 
 TmEcode ConfigSetLogDirectory(char *name)
 {
@@ -63,3 +64,30 @@ TmEcode ConfigCheckLogDirectory(char *log_dir)
     }
     SCReturnInt(TM_ECODE_OK);
 }
+
+/**
+ * \brief Find the configuration node for a specific device.
+
+ * Basically hunts through the list of maps for the first one with a
+ * key of "interface", and a value of the provided interface.
+ *
+ * \param node The node to start looking for the device
+ *     configuration. Typically this would be something like the af-packet
+ *     or pf-ring node.
+ *
+ * \param iface The name of the interface to find the config for.
+ */
+ConfNode *ConfFindDeviceConfig(ConfNode *node, const char *iface)
+{
+    ConfNode *if_node, *item;
+    TAILQ_FOREACH(if_node, &node->head, next) {
+        TAILQ_FOREACH(item, &if_node->head, next) {
+            if (strcmp(item->name, "interface") == 0 &&
+                strcmp(item->val, iface) == 0) {
+                return if_node;
+            }
+        }
+    }
+
+    return NULL;
+}
index 74d87e305a788d704042db0a1af556ec24560f84..4f6399af8e1b53e09b16fb77cb47903346dc21cc 100644 (file)
 #ifndef __UTIL_UTIL_CONF_H__
 #define __UTIL_UTIL_CONF_H__
 
+#include "conf.h"
+
 TmEcode ConfigSetLogDirectory(char *name);
 char *ConfigGetLogDirectory();
 TmEcode ConfigCheckLogDirectory(char *log_dir);
 
+ConfNode *ConfFindDeviceConfig(ConfNode *node, const char *iface);
+
 #endif /* __UTIL_UTIL_CONF_H__ */