]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
finishing stream_tcp conversion. Adding basic 'config' option support
authorJosh <jrosenba@cisco.com>
Thu, 19 Jun 2014 17:30:49 +0000 (13:30 -0400)
committerJosh <jrosenba@cisco.com>
Thu, 19 Jun 2014 17:30:49 +0000 (13:30 -0400)
tools/snort2lua/CMakeLists.txt
tools/snort2lua/config_states/CMakeLists.txt [new file with mode: 0644]
tools/snort2lua/config_states/config_api.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_api.h [new file with mode: 0644]
tools/snort2lua/config_states/config_options.cc [new file with mode: 0644]
tools/snort2lua/conversion_state.h
tools/snort2lua/keyword_states/CMakeLists.txt
tools/snort2lua/keyword_states/kws_config.cc
tools/snort2lua/keyword_states/kws_suppress.cc
tools/snort2lua/preprocessor_states/pps_stream_tcp.cc

index fe516ff23c28026ce8ef1b2e2e115ca51bbb18c8..f9d1d4969141b055dd897d311ee14d7075bd8319 100644 (file)
@@ -6,6 +6,7 @@ add_subdirectory(data)
 add_subdirectory(keyword_states)
 add_subdirectory(preprocessor_states)
 add_subdirectory(output_states)
+add_subdirectory(config_states)
 
 add_executable(snort2lua
     snort2lua.cc
diff --git a/tools/snort2lua/config_states/CMakeLists.txt b/tools/snort2lua/config_states/CMakeLists.txt
new file mode 100644 (file)
index 0000000..807603d
--- /dev/null
@@ -0,0 +1,7 @@
+
+
+add_library( config_states
+    config_options.cc
+    config_api.h
+    config_api.cc
+)
diff --git a/tools/snort2lua/config_states/config_api.cc b/tools/snort2lua/config_states/config_api.cc
new file mode 100644 (file)
index 0000000..c06eb65
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * 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
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_api.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include "config_states/config_api.h"
+
+
+extern const ConvertMap *autogenerate_decode_rules_map;
+extern const ConvertMap *paf_max_map;
+
+
+const std::vector<const ConvertMap*> config_api = 
+{
+    autogenerate_decode_rules_map,
+    paf_max_map,
+};
diff --git a/tools/snort2lua/config_states/config_api.h b/tools/snort2lua/config_states/config_api.h
new file mode 100644 (file)
index 0000000..6fd0c59
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * 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
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_api.h author Josh Rosenbaum <jorosenba@cisco.com>
+
+#ifndef CONFIG_API_H
+#define CONFIG_API_H
+
+#include <vector>
+#include "../conversion_state.h"
+
+extern const std::vector<const ConvertMap*> config_api;
+
+#endif
diff --git a/tools/snort2lua/config_states/config_options.cc b/tools/snort2lua/config_states/config_options.cc
new file mode 100644 (file)
index 0000000..63a9145
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * 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
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_options.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "converter.h"
+#include "snort2lua_util.h"
+
+
+
+static inline bool open_table_add_option(Converter* cv, 
+                                            std::string table_name, 
+                                            std::string opt_name, 
+                                            bool val)
+{
+    bool tmpval = cv->open_table(table_name);
+    tmpval = cv->add_option_to_table(opt_name, val) && tmpval;
+    cv->close_table();
+    return tmpval;
+}
+
+/*********************************************
+ ************  config paf_max ****************
+ *********************************************/
+
+namespace {
+
+class PafMax : public ConversionState
+{
+public:
+    PafMax(Converter* cv)  : ConversionState(cv) {};
+    virtual ~PafMax() {};
+    virtual bool convert(std::stringstream& data_stream);
+};
+
+} // namespace
+
+
+bool PafMax::convert(std::stringstream& data_stream)
+{
+    converter->open_table("stream_tcp");
+    bool retval = parse_int_option("paf_max", data_stream);
+    converter->close_table();
+    return retval;    
+}
+
+/*******  A P I ***********/
+
+static ConversionState* paf_max_ctor(Converter* cv)
+{
+    return new PafMax(cv);
+}
+
+static const ConvertMap config_paf_max = 
+{
+    "paf_max",
+    paf_max_ctor,
+};
+
+
+const ConvertMap* paf_max_map = &config_paf_max;
+
+
+/*********************************************
+ *******  Autogenerate Decoder Rules *********
+ *********************************************/
+
+static ConversionState* autogenerate_preprocessor_decoder_rules_ctor(Converter* cv)
+{
+    open_table_add_option(cv, "ips", "enable_builtin_rules", true);
+    return nullptr;
+}
+
+static const ConvertMap config_autogenerate_decode_rules = 
+{
+    "autogenerate_preprocessor_decoder_rules",
+    autogenerate_preprocessor_decoder_rules_ctor,
+};
+
+const ConvertMap* autogenerate_decode_rules_map = &config_autogenerate_decode_rules;
index ebff711f772e8ec1e62e33486383fed5760e6bd6..0d12de0fbab30caae41b8ddc8b4a3211d9dc314e 100644 (file)
@@ -161,7 +161,7 @@ protected:
         return converter->add_option_to_table("--" + list_name, tmp );
     }
 
-    inline bool pen_table_add_option(std::string table_name, std::string opt_name, std::string val)
+    inline bool open_table_add_option(std::string table_name, std::string opt_name, std::string val)
     {
         bool tmpval = converter->open_table(table_name);
         tmpval = converter->add_option_to_table(opt_name, val) && tmpval;
index 7b32236a4b4b3590e5e5f02851eb4ba4a48af9f9..1347f90382cbc15523664274c8009fdb28c1df16 100644 (file)
@@ -13,4 +13,5 @@ add_library( keyword_states
 target_link_libraries( keyword_states
     output_states
     preprocessor_states
+    config_states
 )
\ No newline at end of file
index 4d95e6f434c2f64246d21a781eca7775a21e4e54..a1e6fcbfde4228bb9974155b774c7e9e33d859bc 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// config.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// kws_config.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
 
 #include "conversion_state.h"
 #include "converter.h"
+#include "config_states/config_api.h"
 #include "snort2lua_util.h"
 
 
@@ -42,12 +43,15 @@ public:
 
 bool Config::convert(std::stringstream& data_stream)
 {
-#if 0
     std::string keyword;
 
-    if(data >> keyword)
+    if(data_stream >> keyword)
     {
-        const ConvertMap* map = util::find_map(output_api, keyword);
+
+        if(keyword.back() == ':')
+            keyword.pop_back();
+
+        const ConvertMap* map = util::find_map(config_api, keyword);
         if (map)
         {
             converter->set_state(map->ctor(converter));
@@ -55,9 +59,6 @@ bool Config::convert(std::stringstream& data_stream)
         }
     }
 
-    return false;    
-#endif
-
     return false;
 }
 
index eda365699f9caa637bca383147421171f3904e07..5608c00cd540128747f3d92daded0cd67b515977 100644 (file)
@@ -46,6 +46,8 @@ bool Suppress::convert(std::stringstream& data_stream)
     std::string keyword;
 
     converter->open_table("suppress");
+    converter->add_deprecated_comment("gen_id", "gid");
+    converter->add_deprecated_comment("sig_id", "sid");
     converter->open_table();
 
     while(data_stream >> keyword)
@@ -65,16 +67,13 @@ bool Suppress::convert(std::stringstream& data_stream)
             tmpval = parse_string_option("ip", data_stream);
 
         else if(!keyword.compare("gen_id"))
-        {
-            converter->add_deprecated_comment("gen_id", "gid");
             tmpval = parse_int_option("gid", data_stream);
-        }
 
         else if (!keyword.compare("sig_id"))
-        {
-            converter->add_deprecated_comment("sig_id", "sid");
             tmpval = parse_int_option("sid", data_stream);
-        }
+
+        else
+            tmpval = false;
 
         if (retval)
             retval = tmpval;
index c528617716ad694cb0b8914e43b6b4619cd199b6..974b741553c48bccf51339bd5aa8938b48ab2818 100644 (file)
@@ -185,6 +185,13 @@ bool StreamTcp::convert(std::stringstream& data_stream)
         else if(!keyword.compare("check_session_hijacking"))
             converter->add_deprecated_comment("check_session_hijacking");
 
+        else if(!keyword.compare("bind_to"))
+        {
+            converter->add_deprecated_comment("bind_to", "bindings");
+            if(!(data_stream >> keyword))
+                tmpval = false;
+        }
+
         else if(!keyword.compare("dont_reassemble_async"))
         {
             converter->add_deprecated_comment("dont_reassemble_async", "reassemble_async");
@@ -228,13 +235,6 @@ bool StreamTcp::convert(std::stringstream& data_stream)
 
     return retval;    
 }
-#if 0
-
-#    bind_to <ip_addr>       - IP address for this policy.  The default is set
-    
-    ports <client|server|both> [all|space separated port list] 
-]
-#endif
 
 /**************************
  *******  A P I ***********