From bcf5431ca0ea4a2deb09b806d8c2be6bb09232fb Mon Sep 17 00:00:00 2001 From: "Michael Altizer (mialtize)" Date: Tue, 28 Aug 2018 17:31:01 -0400 Subject: [PATCH] Merge pull request #1341 in SNORT/snort3 from offload_reload_fix to master Squashed commit of the following: commit b2628f9106194a07c325951cf2cf3e02a117f90b Author: Bhagya Tholpady 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 | 18 +++++++++++------- src/detection/ips_context.h | 1 - 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/detection/ips_context.cc b/src/detection/ips_context.cc index c7b04ad29..ac07d74e9 100644 --- a/src/detection/ips_context.cc +++ b/src/detection/ips_context.cc @@ -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]") diff --git a/src/detection/ips_context.h b/src/detection/ips_context.h index f9fb6eef4..86031c099 100644 --- a/src/detection/ips_context.h +++ b/src/detection/ips_context.h @@ -58,7 +58,6 @@ public: virtual ~IpsContextData() = default; static unsigned get_ips_id(); - static unsigned get_max_id(); virtual void clear() {} protected: -- 2.47.3