]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
detection engine support for context data
authorRuss Combs <rucombs@cisco.com>
Sat, 22 Oct 2016 14:20:40 +0000 (10:20 -0400)
committerRuss Combs <rucombs@cisco.com>
Wed, 18 Jan 2017 14:41:33 +0000 (09:41 -0500)
src/detection/detection_engine.cc
src/detection/detection_engine.h
src/detection/ips_context.cc
src/detection/ips_context.h
src/main/snort.cc

index 894aa3df47fff5ab8005c8ce710be34ebcbf7165..a28aad097fab8d434010b4727c64ae6b10186fa7 100644 (file)
@@ -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; }
 
index 16c72971547992e4b09e3505d5e9e086c9f8b208..2de6912c21a065a4a95fd36d739cfba8724f8cf3 100644 (file)
@@ -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*);
 
index dbca66b2bfc8ecd490b37607e1bedcd5db80f56f..6e228bd36f682a8325d833fef008669713b482fb 100644 (file)
@@ -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;
index b5468964be6f7036e219659bbba8e8324e741f5e..6c7e421abcd96f0d44c7b05107f55d439707cc3b 100644 (file)
@@ -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*);
index 4f0193d5c9bd1cbdf656fa73100d8dbea9aad594..fdc5b7d37dfdcc3a2150de77b60228caa9498e30 100644 (file)
@@ -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);