]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2930 in SNORT/snort3 from ~MMATIRKO/snort3:snort_docker to master
authorMasud Hasan (mashasan) <mashasan@cisco.com>
Mon, 21 Jun 2021 19:18:23 +0000 (19:18 +0000)
committerMasud Hasan (mashasan) <mashasan@cisco.com>
Mon, 21 Jun 2021 19:18:23 +0000 (19:18 +0000)
Squashed commit of the following:

commit d3a7ea0a8a94c50ca91bd3bb45be34337a8e8721
Author: Michael Matirko <mmatirko@cisco.com>
Date:   Thu Jun 10 11:03:41 2021 -0400

    main: implement test_features run flag to enable debug-like output

commit bdb3926895abb3d78dbc27046430d48c0bdd10cc
Author: Michael Matirko <mmatirko@cisco.com>
Date:   Fri Jun 4 11:38:12 2021 -0400

    sfip: fix unit tests for non-regtest builds

commit 2afa7a822c85641dbb7acaf9585b86781968baa9
Author: Michael Matirko <mmatirko@cisco.com>
Date:   Thu Jun 3 15:58:32 2021 -0400

    snort2lua: remove footprint size config

src/main/snort_config.h
src/main/snort_module.cc
src/network_inspectors/appid/test/appid_debug_test.cc
src/sfip/sf_ip.cc
src/sfip/sf_ip.h
src/sfip/sf_ipvar.cc
src/sfip/test/sf_ip_test.cc
tools/snort2lua/preprocessor_states/pps_stream5_tcp.cc

index 683f7fcc7f57219e6c0c2f11bb075812b8bb5f99..bf73f6c2f7aff22a97dbbb28d1c614f028b255d0 100644 (file)
@@ -72,11 +72,13 @@ enum RunFlag
     RUN_FLAG__IP_FRAGS_ONLY       = 0x00200000,
     RUN_FLAG__DUMP_RULE_STATE     = 0x00400000,
 
+    RUN_FLAG__TEST_FEATURES       = 0x00800000,
+
 #ifdef SHELL
-    RUN_FLAG__SHELL               = 0x00800000,
+    RUN_FLAG__SHELL               = 0x01000000,
 #endif
 #ifdef PIGLET
-    RUN_FLAG__PIGLET              = 0x01000000,
+    RUN_FLAG__PIGLET              = 0x02000000,
 #endif
 };
 
@@ -611,6 +613,9 @@ public:
     bool assure_established() const
     { return run_flags & RUN_FLAG__ASSURE_EST; }
 
+    bool test_features() const
+    { return run_flags & RUN_FLAG__TEST_FEATURES; }
+
     // other stuff
     uint8_t min_ttl() const
     { return get_network_policy()->min_ttl; }
index a013ac4249cd9d2e189335ee3b76a1e2886e0a4f..a909fcd3d47dba00135712f2ffd455a175d922b4 100644 (file)
@@ -131,7 +131,7 @@ static const Command snort_cmds[] =
 #endif
 
 //-------------------------------------------------------------------------
-// why not
+// hex conversion helper funcs
 //-------------------------------------------------------------------------
 
 [[noreturn]] static void c2x(const char* s)
@@ -378,6 +378,9 @@ static const Parameter s_params[] =
     { "--enable-inline-test", Parameter::PT_IMPLIED, nullptr, nullptr,
       "enable Inline-Test Mode Operation" },
 
+    { "--enable-test-features", Parameter::PT_IMPLIED, nullptr, nullptr,
+      "enable features used in testing" },
+
     { "--gen-msg-map", Parameter::PT_IMPLIED, nullptr, nullptr,
       "dump configured rules in gen-msg.map format for use by other tools" },
 
@@ -920,6 +923,12 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("--enable-inline-test") )
         sc->run_flags |= RUN_FLAG__INLINE_TEST;
 
+    else if ( v.is("--enable-test-features") )
+    {
+        sc->run_flags |= RUN_FLAG__TEST_FEATURES;
+        SfIp::test_features = true;
+    }
+
     else if ( v.is("--gen-msg-map") )
     {
         sc->run_flags |= (RUN_FLAG__DUMP_MSG_MAP | RUN_FLAG__TEST);
index 0b58e5db0472161c2513ad0a55a3fa43a74a9b1b..c5024f00b6e749e36000b321cd3a18fa9ff23129 100644 (file)
@@ -179,6 +179,7 @@ TEST(appid_debug, reverse_direction_activate_test)
 TEST(appid_debug, ipv6_test)
 {
     // set_constraints()
+    SfIp::test_features = true;
     AppIdDebugSessionConstraints constraints = { };
     SetConstraints(IpProtocol::UDP, "2001:db8:85a3::8a2e:370:7334", 1234,
         "2001:db8:85a3::8a2e:370:7335", 443, constraints);
@@ -204,13 +205,9 @@ TEST(appid_debug, ipv6_test)
     CHECK_EQUAL(appidDebug->is_active(), true);
 
     // get_debug_session()
-#ifdef REG_TEST
     const char* str = "2001:0db8:85a3:0000:0000:8a2e:0370:7334 1234 -> "
             "2001:0db8:85a3:0000:0000:8a2e:0370:7335 443 17 AS=100 ID=3";
-#else
-    const char* str = "2001:db8:85a3::8a2e:370:7334 1234 -> "
-            "2001:db8:85a3::8a2e:370:7335 443 17 AS=100 ID=3";
-#endif
+
     CHECK_TRUE(strcmp(appidDebug->get_debug_session(), str) == 0);
 
     delete &session.get_api();
index 363738e64f9c96ecfb537c0bdd1501eaaaa72c25..29b78526e4c180e5523da8b64c15ffbce2e41bfd 100644 (file)
@@ -37,6 +37,8 @@
 
 using namespace snort;
 
+bool SfIp::test_features{ false };
+
 /* Masks off 'val' bits from the IP contained within 'ip' */
 inline int SfIp::cidr_mask(int val)
 {
@@ -405,46 +407,49 @@ const char* snort_inet_ntop(int family, const void* ip_raw, char* buf, int bufsi
         return buf;
     }
 
-#if !defined(REG_TEST) && !defined(CATCH_TEST_BUILD)
-    if (!inet_ntop(family, ip_raw, buf, bufsize))
-        snprintf(buf, bufsize, "ERROR");
-#else
-    /* 4 fields of at most 3 characters each */
-    if (family == AF_INET)
+    if ( !SfIp::test_features )
     {
-        int i;
-        const uint8_t* p = (const uint8_t*)ip_raw;
-
-        for (i=0; p < ((const uint8_t*)ip_raw) + 4; p++)
-        {
-            i += sprintf(&buf[i], "%d", *p);
-
-            /* If this is the last iteration, this could technically cause one
-             *  extra byte to be written past the end. */
-            if (i < bufsize && ((p + 1) < ((const uint8_t*)ip_raw+4)))
-                buf[i] = '.';
-
-            i++;
-        }
+        if (!inet_ntop(family, ip_raw, buf, bufsize))
+            snprintf(buf, bufsize, "ERROR");
     }
     else
     {
-        int i;
-        const uint16_t* p = (const uint16_t*)ip_raw;
+        /* 4 fields of at most 3 characters each */
+        if (family == AF_INET)
+        {
+            int i;
+            const uint8_t* p = (const uint8_t*)ip_raw;
+
+            for (i=0; p < ((const uint8_t*)ip_raw) + 4; p++)
+            {
+                i += sprintf(&buf[i], "%d", *p);
 
-        for (i=0; p < ((const uint16_t*)ip_raw) + 8; p++)
+                /* If this is the last iteration, this could technically cause one
+                 *  extra byte to be written past the end. */
+                if (i < bufsize && ((p + 1) < ((const uint8_t*)ip_raw+4)))
+                    buf[i] = '.';
+
+                i++;
+            }
+        }
+        else
         {
-            i += sprintf(&buf[i], "%04x", ntohs(*p));
+            int i;
+            const uint16_t* p = (const uint16_t*)ip_raw;
+
+            for (i=0; p < ((const uint16_t*)ip_raw) + 8; p++)
+            {
+                i += sprintf(&buf[i], "%04x", ntohs(*p));
 
-            /* If this is the last iteration, this could technically cause one
-             *  extra byte to be written past the end. */
-            if (i < bufsize && ((p + 1) < ((const uint16_t*)ip_raw) + 8))
-                buf[i] = ':';
+                /* If this is the last iteration, this could technically cause one
+                 *  extra byte to be written past the end. */
+                if (i < bufsize && ((p + 1) < ((const uint16_t*)ip_raw) + 8))
+                    buf[i] = ':';
 
-            i++;
+                i++;
+            }
         }
     }
-#endif
     return buf;
 }
 
index a40fbcabe0a9e679fa77242cf0f86547a9587a6a..0446932e0ecae347e2cdf29700f68b84b6111d5c 100644 (file)
@@ -101,6 +101,8 @@ struct SO_PUBLIC SfIp
 
     void obfuscate(const SfCidr* ob);
 
+    static bool test_features;
+
 private:
     int cidr_mask(int val);
     bool _is_equals(const SfIp& rhs) const;
index e9777dd1426a5870a8faa144411a631d51a05e1c..698dca2ba6d68e6a1f3cdfa11eb9d5824792c2d4 100644 (file)
@@ -1206,6 +1206,8 @@ TEST_CASE("SfIpVarListMerge", "[SfIpVar]")
     sfip_var_t* var1;
     sfip_var_t* var2;
 
+    SfIp::test_features = true;
+
     SECTION("basic list merge")
     {
         table = sfvt_alloc_table();
@@ -1232,6 +1234,7 @@ TEST_CASE("SfIpVarListMerge", "[SfIpVar]")
         CHECK(sfvt_add_str(table, "my_cidr [ 192.168.0.0/16, f0:e0:d0:c0::8/64, 10.10.1.8/19,"
             " f0:e0:d1:c1::1/32]", &var2) == SFIP_SUCCESS);
         print_var_list(var2->head);
+
         CHECK(!strcmp("10.10.0.0,192.168.0.0,00f0:00e0:0000:0000:0000:0000:0000:0000",
             sfipvar_test_buff));
 
@@ -1300,6 +1303,9 @@ TEST_CASE("SfIpVarListMerge", "[SfIpVar]")
 
     SECTION("merge contained IPs and negated-IPs")
     {
+
+        SfIp::test_features = true;
+
         table = sfvt_alloc_table();
 
         CHECK(sfvt_add_str(table, "foo 1.2.3.4, cafe:feed:beef::0/48", &var1) == SFIP_SUCCESS);
@@ -1312,6 +1318,7 @@ TEST_CASE("SfIpVarListMerge", "[SfIpVar]")
 
         /* Check merged IP lists */
         print_var_list(var1->head);
+
         CHECK(!strcmp("1.2.0.0,cafe:0000:0000:0000:0000:0000:0000:0000", sfipvar_test_buff));
         print_var_list(var1->neg_head);
         CHECK(!strcmp("!9.0.0.0,!dead:beef:0000:0000:0000:0000:0000:0000", sfipvar_test_buff));
index 738afdbb03253a898fb447bf9657c3a8767b7fd4..1ca03aa5813aa3543f6f3222ac622ab18e88b89a 100644 (file)
@@ -248,6 +248,8 @@ static FuncTest ftests[] =
 
 static int RunFunc(const char* func, const char* arg1, const char* arg2)
 {
+    SfIp::test_features = true;
+
     SfCidr cidr1, cidr2;
     const SfIp* ip1, * ip2;
     int result = SFIP_FAILURE;
index fe8aaed35590a2eb2e20a4c369ba5c806883a827..308eb1740ed46bca844a79a367e112964586f8a3 100644 (file)
@@ -374,11 +374,7 @@ bool StreamTcp::convert(std::istringstream& data_stream)
         }
         else if (keyword == "use_static_footprint_sizes")
         {
-            table_api.add_diff_option_comment("use_static_footprint_sizes",
-                "stream.footprint = 192");
-            table_api.close_table();
-            table_api.open_top_level_table("stream");
-            table_api.add_option("footprint", 192);
+            table_api.add_deleted_comment("use_static_footprint_sizes");
             table_api.close_table();
             table_api.open_table("stream_tcp");
         }