]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1454 in SNORT/snort3 from ~MIALTIZE/snort3:preng to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 5 Dec 2018 14:32:36 +0000 (09:32 -0500)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 5 Dec 2018 14:32:36 +0000 (09:32 -0500)
Squashed commit of the following:

commit 05e0b65ebfc22ce68aada07f94e98442de5e6867
Author: Michael Altizer <mialtize@cisco.com>
Date:   Tue Oct 9 18:36:25 2018 -0400

    snort: Default to a snaplen of 1518

commit d4e70b104c72b6768dc328fda396d251171707c9
Author: Michael Altizer <mialtize@cisco.com>
Date:   Sat Nov 3 15:03:46 2018 -0400

    module_manager: Fix configuring module parameter defaults when modules have list parameters

commit 9166086ae089c4296be087bb91d02dd761b8b9e0
Author: Michael Altizer <mialtize@cisco.com>
Date:   Mon Oct 29 10:36:47 2018 -0400

    snort2lua: Fix compiler warning for catching exceptions by value

commit 8ae596426cccfab0c898013e881dfc39f16eba84
Author: Michael Altizer <mialtize@cisco.com>
Date:   Wed Oct 3 14:41:34 2018 -0400

    thread: No more breaks for pigs (union busting)

commit 8cdf8b414bcc153797024c1406369e8389137098
Author: Michael Altizer <mialtize@cisco.com>
Date:   Fri Aug 31 13:31:11 2018 -0400

    appid: Don't build unit test components without ENABLE_UNIT_TESTS

src/main/snort.cc
src/main/snort_module.cc
src/main/thread.cc
src/main/thread.h
src/managers/module_manager.cc
src/network_inspectors/appid/test/CMakeLists.txt
src/packet_io/sfdaq.cc
tools/snort2lua/config_states/config_ignore_ports.cc

index 7841fc7e8f77f05d918006530098e26bdd0a9e44..88a7715c8f9409f81fd81572f8c925c057c91134 100644 (file)
@@ -1056,8 +1056,6 @@ DAQ_Verdict Snort::packet_callback(
         SFDAQ::break_loop(0);
         s_pause.was_paused = s_pause.pause = true;
     }  
-    else if ( break_time() )
-        SFDAQ::break_loop(0);
 
     s_switcher->stop();
 
index 9062a51303c7e83beed61d057ce57e283592ed16..8393460535c47afffd82bf6c569b62212f714d37 100644 (file)
@@ -244,8 +244,8 @@ static const Parameter s_params[] =
     { "-S", Parameter::PT_STRING, nullptr, nullptr,
       "<x=v> set config variable x equal to value v" },
 
-    { "-s", Parameter::PT_INT, "68:65535", "1514",
-      "<snap> (same as --snaplen); default is 1514" },
+    { "-s", Parameter::PT_INT, "68:65535", "1518",
+      "<snap> (same as --snaplen); default is 1518" },
 
     { "-T", Parameter::PT_IMPLIED, nullptr, nullptr,
       "test and report on the current Snort configuration" },
@@ -481,7 +481,7 @@ static const Parameter s_params[] =
     { "--skip", Parameter::PT_INT, "0:", nullptr,
       "<n> skip 1st n packets", },
 
-    { "--snaplen", Parameter::PT_INT, "68:65535", "1514",
+    { "--snaplen", Parameter::PT_INT, "68:65535", "1518",
       "<snap> set snaplen of packet (same as -s)", },
 
     { "--stdin-rules", Parameter::PT_IMPLIED, nullptr, nullptr,
index 4b736486263be030350fac649343f395a3abb256..e0f9017c9c73d1a584c563aed3bd61e6e73bc4b5 100644 (file)
@@ -50,25 +50,6 @@ void set_instance_id(unsigned id)
 void set_thread_type(SThreadType type)
 { thread_type = type; }
 
-//-------------------------------------------------------------------------
-// union rules - breaks are mandatory and must be taken in daq thread
-//-------------------------------------------------------------------------
-
-static unsigned g_breaks = 0;
-static THREAD_LOCAL unsigned t_breaks = 0;
-
-void take_break()
-{ g_breaks++; }
-
-bool break_time()
-{
-    if ( t_breaks == g_breaks )
-        return false;
-
-    t_breaks = g_breaks;
-    return true;
-}
-
 namespace snort
 {
 unsigned get_instance_id()
index eca181d975fabdbbaef9f41dc713cc961fbc326f..f0602343bc0c35e0fcd12236e6866c04bc4a5578 100644 (file)
@@ -64,7 +64,4 @@ SO_PUBLIC inline bool is_packet_thread()
 SO_PUBLIC const char* get_instance_file(std::string&, const char* name);
 }
 
-void take_break();
-bool break_time();
-
 #endif
index 331660062a62dccb37fa118e30a824ef1a731309..bb08afa74d9fa2331823bd4b5b42fabce173a41a 100644 (file)
@@ -535,36 +535,41 @@ static bool top_level(const char* s)
 
 static bool begin(Module* m, const Parameter* p, const char* s, int idx, int depth)
 {
-    if ( !p )
+    // Module::(verified_)begin() will be called for top-level tables, lists, and list items only
+    if ( top_level(s) )
     {
-        p = m->get_parameters();
-        assert(p);
-    }
-
-    // Module::begin() top-level, lists, and list items only
-    if ( top_level(s) or
-         (!idx and p->type == Parameter::PT_LIST) or
-         (idx and p->type != Parameter::PT_LIST) )
-    {
-        //printf("begin %s %d\n", s, idx);
         if ( !m->verified_begin(s, idx, s_config) )
             return false;
-    }
-    // don't set list defaults
-    if ( m->is_list() or p->type == Parameter::PT_LIST )
-    {
-        if ( !idx )
+        // don't set list defaults
+        if ( m->is_list() and !idx )
             return true;
+        if ( !p )
+        {
+            p = m->get_parameters();
+            assert(p);
+        }
     }
-
-    // set list item defaults only if explicitly configured
-    // (this is why it is done here and not in the loop below)
-    if ( p->type == Parameter::PT_LIST )
+    else
     {
-        const Parameter* t =
-            reinterpret_cast<const Parameter*>(p->range);
+        assert(p);
+        if ((!idx and p->type == Parameter::PT_LIST) or
+             (idx and p->type != Parameter::PT_LIST) )
+        {
+            if ( !m->verified_begin(s, idx, s_config) )
+                return false;
+        }
+        if ( p->type == Parameter::PT_LIST )
+        {
+            // don't set list defaults (list items have idx > 0)
+            if ( !idx )
+                return true;
 
-        return begin(m, t, s, idx, depth+1);
+            // set list item defaults only if explicitly configured
+            // (this is why it is done here and not in the loop below)
+            const Parameter* list_item_params = reinterpret_cast<const Parameter*>(p->range);
+
+            return begin(m, list_item_params, s, idx, depth+1);
+        }
     }
 
     // don't begin subtables again
@@ -582,10 +587,9 @@ static bool begin(Module* m, const Parameter* p, const char* s, int idx, int dep
         // traverse subtables only to set defaults
         case Parameter::PT_TABLE:
             {
-                const Parameter* t =
-                    reinterpret_cast<const Parameter*>(p->range);
+                const Parameter* table_item_params = reinterpret_cast<const Parameter*>(p->range);
 
-                if ( !begin(m, t, fqn.c_str(), idx, depth+1) )
+                if ( !begin(m, table_item_params, fqn.c_str(), idx, depth+1) )
                     return false;
             }
             break;
@@ -599,7 +603,6 @@ static bool begin(Module* m, const Parameter* p, const char* s, int idx, int dep
             if ( p->deflt )
             {
                 bool b = p->get_bool();
-                //printf("set default %s = %s\n", fqn.c_str(), p->deflt);
                 set_bool(fqn.c_str(), b);
             }
             break;
@@ -610,7 +613,6 @@ static bool begin(Module* m, const Parameter* p, const char* s, int idx, int dep
             if ( p->deflt )
             {
                 double d = p->get_number();
-                //printf("set default %s = %f\n", fqn.c_str(), d);
                 set_number(fqn.c_str(), d);
             }
             break;
@@ -618,10 +620,7 @@ static bool begin(Module* m, const Parameter* p, const char* s, int idx, int dep
         // everything else is a string of some sort
         default:
             if ( p->deflt )
-            {
-                //printf("set default %s = %s\n", fqn.c_str(), p->deflt);
                 set_string(fqn.c_str(), p->deflt);
-            }
             break;
         }
         ++p;
@@ -647,7 +646,6 @@ static bool end(Module* m, const Parameter* p, const char* s, int idx)
          (!idx and p->type == Parameter::PT_LIST) or
          (idx and p->type != Parameter::PT_LIST) )
     {
-        //printf("end %s %d\n", s, idx);
         return m->verified_end(s, idx, s_config);
     }
     return true;
@@ -666,8 +664,6 @@ SO_PUBLIC bool set_alias(const char* from, const char* to)
 
 SO_PUBLIC bool open_table(const char* s, int idx)
 {
-    //printf("open %s %d\n", s, idx);
-
     const char* orig = s;
     string fqn = s;
     set_type(fqn);
@@ -744,8 +740,6 @@ SO_PUBLIC bool open_table(const char* s, int idx)
 
 SO_PUBLIC void close_table(const char* s, int idx)
 {
-    //printf("close %s %d\n", s, idx);
-
     string fqn = s;
     set_type(fqn);
     s = fqn.c_str();
@@ -783,21 +777,18 @@ SO_PUBLIC void close_table(const char* s, int idx)
 
 SO_PUBLIC bool set_bool(const char* fqn, bool b)
 {
-    //printf("bool %s %d\n", fqn, b);
     Value v(b);
     return set_value(fqn, v);
 }
 
 SO_PUBLIC bool set_number(const char* fqn, double d)
 {
-    //printf("real %s %f\n", fqn, d);
     Value v(d);
     return set_value(fqn, v);
 }
 
 SO_PUBLIC bool set_string(const char* fqn, const char* s)
 {
-    //printf("string %s %s\n", fqn, s);
     Value v(s);
     return set_value(fqn, v);
 }
index 3fd626d798388dd25dba832b84e640495a30766a..a421447f6661115ce55cd5daee258071ef4927e0 100644 (file)
@@ -1,4 +1,11 @@
-add_library(appid_cpputest_deps OBJECT ../appid_peg_counts.cc ../../../sfip/sf_ip.cc ../../../utils/util_cstring.cc)
+
+if ( ENABLE_UNIT_TESTS )
+    add_library(appid_cpputest_deps OBJECT EXCLUDE_FROM_ALL
+        ../appid_peg_counts.cc
+        ../../../sfip/sf_ip.cc
+        ../../../utils/util_cstring.cc
+    )
+endif ( ENABLE_UNIT_TESTS )
 
 include_directories ( appid PRIVATE ${APPID_INCLUDE_DIR} )
 
@@ -39,18 +46,24 @@ add_cpputest( appid_http_session_test
 )
 
 if ( ENABLE_APPID_THIRD_PARTY )
-  add_library(tp_mock MODULE tp_mock.cc)
 
-  add_cpputest( tp_lib_handler_test
-    SOURCES tp_lib_handler_test.cc
-    ../tp_lib_handler.cc
-    LIBS dl
+    add_cpputest( tp_lib_handler_test
+        SOURCES
+            tp_lib_handler_test.cc
+            ../tp_lib_handler.cc
+        LIBS
+            dl
     )
 
-  add_cpputest( tp_appid_types_test
-    SOURCES tp_appid_types_test.cc
+    if ( ENABLE_UNIT_TESTS )
+        add_library(tp_mock MODULE EXCLUDE_FROM_ALL tp_mock.cc)
+        set_property(TARGET tp_mock PROPERTY ENABLE_EXPORTS 1)
+        add_dependencies(tp_lib_handler_test tp_mock)
+    endif ( ENABLE_UNIT_TESTS )
+
+    add_cpputest( tp_appid_types_test
+        SOURCES tp_appid_types_test.cc
     )
 
-  set_property(TARGET tp_mock PROPERTY ENABLE_EXPORTS 1)
 endif()
 
index 71b4b95b2c8e7fae5de71cfb4a14a8e5bbb1c496..a1851f9c11501683d311466d163a451cdbe38375 100644 (file)
@@ -51,7 +51,7 @@ using namespace std;
 #define DAQ_DEFAULT "pcap"
 #endif
 
-static const int DEFAULT_PKT_SNAPLEN = 1514;
+static const int DEFAULT_PKT_SNAPLEN = 1518;
 
 // common for all daq threads / instances
 static const DAQ_Module_t* daq_mod = nullptr;
index 9019ef71391556cdf43f7bbacf2ef0fc5b1a81f0..2ac07804fea817310920806d3f2b8bbbb0dfafbb 100644 (file)
@@ -111,13 +111,13 @@ bool IgnorePorts::convert(std::istringstream& data_stream)
                     bind.add_when_port(std::to_string(i));
             }
         }
-        catch (std::invalid_argument)
+        catch (std::invalid_argument&)
         {
             data_api.failed_conversion(data_stream, "can't convert " + port);
             retval = false;
             bind.print_binding(false); // don't print the binding if an error occurred
         }
-        catch (std::out_of_range)
+        catch (std::out_of_range&)
         {
             data_api.failed_conversion(data_stream, "Port" + port + " must be <= 65535");
             retval = false;