]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1341 in SNORT/snort3 from offload_reload_fix to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Tue, 28 Aug 2018 21:31:01 +0000 (17:31 -0400)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Tue, 28 Aug 2018 21:31:01 +0000 (17:31 -0400)
Squashed commit of the following:

commit b2628f9106194a07c325951cf2cf3e02a117f90b
Author: Bhagya Tholpady <bbantwal@cisco.com>
Date:   Mon Aug 27 20:11:23 2018 -0400

    detection: allocate ips context data using hard coded max_ips_id == 32

src/detection/ips_context.cc
src/detection/ips_context.h

index c7b04ad294e9fb0d0350685d08652849b8188e62..ac07d74e98e01dfe78831d8af5ddc33483d4456c 100644 (file)
@@ -45,18 +45,23 @@ using namespace snort;
 // tests (and only tests) can reset the id
 static unsigned ips_id = 0;
 
-unsigned IpsContextData::get_ips_id()
-{ return ++ips_id; }
+// Only 5 inspectors currently use the ips context data.
+// FIXIT-L This limit should to be updated if any more inspectors/modules use it.
+constexpr unsigned max_ips_id = 32;
 
-unsigned IpsContextData::get_max_id()
-{ return ips_id; }
+unsigned IpsContextData::get_ips_id()
+{ 
+    ++ips_id;
+    assert( ips_id < max_ips_id );
+    return ips_id; 
+}
 
 //--------------------------------------------------------------------------
 // context methods
 //--------------------------------------------------------------------------
 
 IpsContext::IpsContext(unsigned size) :
-    data(size ? size : IpsContextData::get_max_id() + 1, nullptr)
+    data(size ? size : max_ips_id, nullptr)
 {
     packet = new Packet(false);
     encode_packet = nullptr;
@@ -142,13 +147,12 @@ int TestData::count = 0;
 TEST_CASE("IpsContextData id", "[IpsContextData]")
 {
     ips_id = 0;
-    CHECK(IpsContextData::get_max_id() == 0);
 
     auto id1 = IpsContextData::get_ips_id();
     auto id2 = IpsContextData::get_ips_id();
     CHECK(id1 != id2);
 
-    CHECK(IpsContextData::get_max_id() == id2);
+    CHECK(max_ips_id > id2 );
 }
 
 TEST_CASE("IpsContext basic", "[IpsContext]")
index f9fb6eef47dae8b29eee8057613e6544262e8291..86031c0995d406cfdddf69dd73fc0f38384c9760 100644 (file)
@@ -58,7 +58,6 @@ public:
     virtual ~IpsContextData() = default;
 
     static unsigned get_ips_id();
-    static unsigned get_max_id();
     virtual void clear() {}
 
 protected: