From: Russ Combs Date: Sat, 22 Oct 2016 14:20:40 +0000 (-0400) Subject: detection engine support for context data X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c17a65e5e10a97a016824c98999a95cef148a002;p=thirdparty%2Fsnort3.git detection engine support for context data --- diff --git a/src/detection/detection_engine.cc b/src/detection/detection_engine.cc index 894aa3df4..a28aad097 100644 --- a/src/detection/detection_engine.cc +++ b/src/detection/detection_engine.cc @@ -100,6 +100,12 @@ uint8_t* DetectionEngine::get_buffer(unsigned& max) return Snort::get_switcher()->get_context()->buf; } +void DetectionEngine::set_data(unsigned id, IpsContextData* p) +{ Snort::get_switcher()->get_context()->set_context_data(id, p); } + +IpsContextData* DetectionEngine::get_data(unsigned id) +{ return Snort::get_switcher()->get_context()->get_context_data(id); } + DetectionEngine::ActiveRules DetectionEngine::get_detects() { return active_rules; } diff --git a/src/detection/detection_engine.h b/src/detection/detection_engine.h index 16c729715..2de6912c2 100644 --- a/src/detection/detection_engine.h +++ b/src/detection/detection_engine.h @@ -28,6 +28,7 @@ #include "actions/actions.h" #include "main/snort_types.h" +class IpsContextData; struct Packet; class SO_PUBLIC DetectionEngine @@ -45,6 +46,9 @@ public: static uint8_t* get_buffer(unsigned& max); + static void set_data(unsigned id, IpsContextData*); + static IpsContextData* get_data(unsigned id); + static bool detect(Packet*); static void inspect(Packet*); diff --git a/src/detection/ips_context.cc b/src/detection/ips_context.cc index dbca66b2b..6e228bd36 100644 --- a/src/detection/ips_context.cc +++ b/src/detection/ips_context.cc @@ -51,7 +51,8 @@ unsigned IpsContextData::get_max_id() // context methods //-------------------------------------------------------------------------- -IpsContext::IpsContext(unsigned size) : data(size, nullptr) +IpsContext::IpsContext(unsigned size) : + data(size ? size : IpsContextData::get_max_id() + 1, nullptr) { packet = new Packet(false); pkth = new DAQ_PktHdr_t; diff --git a/src/detection/ips_context.h b/src/detection/ips_context.h index b5468964b..6c7e421ab 100644 --- a/src/detection/ips_context.h +++ b/src/detection/ips_context.h @@ -50,7 +50,7 @@ protected: class SO_PUBLIC IpsContext { public: - IpsContext(unsigned size); + IpsContext(unsigned size = 0); // defaults to max id ~IpsContext(); void set_context_data(unsigned id, IpsContextData*); diff --git a/src/main/snort.cc b/src/main/snort.cc index 4f0193d5c..fdc5b7d37 100644 --- a/src/main/snort.cc +++ b/src/main/snort.cc @@ -660,12 +660,11 @@ void Snort::thread_init_unprivileged() { // using dummy values until further integration const unsigned max_contexts = 20; - const unsigned max_data = 1; s_switcher = new ContextSwitcher(max_contexts); for ( unsigned i = 0; i < max_contexts; ++i ) - s_switcher->push(new IpsContext(max_data)); + s_switcher->push(new IpsContext); CodecManager::thread_init(snort_conf);