]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1279 in SNORT/snort3 from snort2lua_nap_merge to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 20 Jun 2018 20:26:09 +0000 (16:26 -0400)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 20 Jun 2018 20:26:09 +0000 (16:26 -0400)
Squashed commit of the following:

commit 116a11685c1ba81921f808abf0a6af8fe5e4a48b
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Wed Jun 13 16:39:17 2018 -0400

    snort2lua: merge multiple nap rules with the same id

tools/snort2lua/preprocessor_states/pps_nap_selector.cc

index fe0a35f27ff2466d16ee6dd9697d3087eea6dfd9..72ccf3e2f9807defb2f2fbe0a1d60e9e95ec834d 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <iostream>
 #include <sstream>
+#include <unordered_map>
 #include <vector>
 
 #include "conversion_state.h"
@@ -48,7 +49,7 @@ public:
         }
 
         unsigned rule_id;
-        if ( data_stream >> rule_id ) // is this a or config
+        if ( data_stream >> rule_id ) // is this a comment or config
         {
             std::string action;
             std::string src_zone, src_net, src_netmask, src_port;
@@ -104,7 +105,8 @@ public:
                 return false;
             }
 
-            auto& bind = cv.make_pending_binder(policy_id);
+            auto seen = rule_map.find(rule_id);
+            auto& bind = seen == rule_map.end() ? cv.make_pending_binder(policy_id) : *seen->second;
 
             bind.set_priority(order++);
 
@@ -131,6 +133,8 @@ public:
 
             if ( protocol != "any" )
                 bind.set_when_proto(protocol);
+
+            rule_map[rule_id] = &bind;
         }
         else
         {
@@ -152,6 +156,7 @@ public:
 
 private:
     unsigned order = 0;
+    std::unordered_map<unsigned, Binder*> rule_map;
 };
 
 class NapSelectorState : public ConversionState