]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1343 in SNORT/snort3 from s_switcher_usage to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Tue, 28 Aug 2018 20:24:49 +0000 (16:24 -0400)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Tue, 28 Aug 2018 20:24:49 +0000 (16:24 -0400)
Squashed commit of the following:

commit e1b965c371481d6d49f68166f4bb338ad7c80649
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Thu Aug 23 16:25:18 2018 -0400

    DetectionEngine: don't use s_switcher to get file data

commit 1b5ef8073bf6615b14e6e17c40818e4d63c35df7
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Thu Aug 23 15:13:19 2018 -0400

    DetectionEngine: use packet to reference context

src/detection/detection_engine.cc
src/detection/detection_engine.h
src/detection/detection_options.cc
src/ips_options/ips_file_data.cc
src/log/log_text.cc
src/service_inspectors/http2_inspect/http2_inspect.cc

index 6e615735b3ed683fe38402f9faa9d8362d9b553d..79481ec1c2e4e024acd395d65475448d9a8258d5 100644 (file)
@@ -163,8 +163,8 @@ DataBuffer& DetectionEngine::get_alt_buffer(Packet* p)
 void DetectionEngine::set_file_data(const DataPointer& dp)
 { Snort::get_switcher()->get_context()->file_data = dp; }
 
-void DetectionEngine::get_file_data(DataPointer& dp)
-{ dp = Snort::get_switcher()->get_context()->file_data; }
+DataPointer& DetectionEngine::get_file_data(IpsContext* c)
+{ return c->file_data; }
 
 void DetectionEngine::set_data(unsigned id, IpsContextData* p)
 { Snort::get_switcher()->get_context()->set_context_data(id, p); }
index 2a9d550e0f1f6d9630f4ccc047ee38e41ef8ae59..e6015ab41ec61ec6ffb50b740a0bd09a44587e7b 100644 (file)
@@ -67,15 +67,15 @@ public:
     static void set_encode_packet(Packet*);
     static Packet* get_encode_packet();
 
-    static void set_file_data(const DataPointer&);
-    static void get_file_data(DataPointer&);
+    static void set_file_data(const DataPointer& dp);
+    static DataPointer& get_file_data(IpsContext*);
 
     static uint8_t* get_buffer(unsigned& max);
     static struct DataBuffer& get_alt_buffer(Packet*);
 
     static void set_data(unsigned id, IpsContextData*);
     static IpsContextData* get_data(unsigned id);
-    static IpsContextData* get_data(unsigned id, IpsContext* context);
+    static IpsContextData* get_data(unsigned id, IpsContext*);
 
     static void add_replacement(const std::string&, unsigned);
     static bool get_replacement(std::string&, unsigned&);
@@ -120,9 +120,7 @@ static inline void set_file_data(const uint8_t* p, unsigned n)
 }
 
 static inline void clear_file_data()
-{
-    set_file_data(nullptr, 0);
-}
+{ set_file_data(nullptr, 0); }
 
 } // namespace snort
 #endif
index ccf2ae3246f8a93e16dfa203d6c00b359b305258..5f99e0a2a598f785261a441fe9e3fdef9f637ef1 100644 (file)
@@ -360,11 +360,12 @@ int detection_option_node_evaluate(
     char flowbits_setoperation = 0;
     int loop_count = 0;
     uint32_t tmp_byte_extract_vars[NUM_IPS_OPTIONS_VARS];
-    uint64_t cur_eval_context_num = DetectionEngine::get_context()->context_num;
 
     if ( !eval_data || !eval_data->p || !eval_data->pomd )
         return 0;
 
+    uint64_t cur_eval_context_num = eval_data->p->context->context_num;
+
     node_eval_trace(node, cursor, eval_data->p);
 
     auto p = eval_data->p;
index d7d1c17aa300665e5cfc6f3553845739cc7addde..d04b2f4b732e7b5db4dc145cee7482f002f3cade 100644 (file)
@@ -49,12 +49,11 @@ public:
 // class methods
 //-------------------------------------------------------------------------
 
-IpsOption::EvalStatus FileDataOption::eval(Cursor& c, Packet*)
+IpsOption::EvalStatus FileDataOption::eval(Cursor& c, Packet* p)
 {
     Profile profile(fileDataPerfStats);
 
-    DataPointer dp;
-    DetectionEngine::get_file_data(dp);
+    DataPointer dp = DetectionEngine::get_file_data(p->context);
 
     if ( !dp.data || !dp.len )
         return NO_MATCH;
index 02461bb7aff726aa2da193a8a1fad1d8a4325ee1..2d3c4ef9b82a466d57d1d19bb45655655e01fcd9 100644 (file)
@@ -1356,8 +1356,7 @@ void LogPayload(TextLog* log, Packet* p)
         {
             LogCharData(log, p->data, p->dsize);
 
-            DataPointer file_data;
-            DetectionEngine::get_file_data(file_data);
+            DataPointer file_data = DetectionEngine::get_file_data(p->context);
 
             if ( file_data.len > 0 )
             {
@@ -1381,8 +1380,7 @@ void LogPayload(TextLog* log, Packet* p)
             {
                 LogNetData(log, p->data, p->dsize, p);
 
-                DataPointer file_data;
-                DetectionEngine::get_file_data(file_data);
+                DataPointer file_data = DetectionEngine::get_file_data(p->context);
 
                 if ( file_data.len > 0 )
                 {
index e00745311365c5e8e42fd02c4be0acda7710e609..6a69005ac42fd0981b19ada174a3df542f37f5b1 100644 (file)
@@ -80,7 +80,8 @@ void Http2Inspect::eval(Packet* p)
     Http2FlowData* const session_data =
         (Http2FlowData*)p->flow->get_flow_data(Http2FlowData::inspector_id);
 
-    set_file_data(session_data->frame_data[source_id], session_data->frame_data_size[source_id]);
+    set_file_data(session_data->frame_data[source_id],
+        session_data->frame_data_size[source_id]);
     session_data->frame_in_detection = true;
 
 #ifdef REG_TEST