From 84fdf350be27cd4aec6b36204864a511bf397d23 Mon Sep 17 00:00:00 2001 From: "Michael Altizer (mialtize)" Date: Tue, 28 Aug 2018 16:24:49 -0400 Subject: [PATCH] Merge pull request #1343 in SNORT/snort3 from s_switcher_usage to master Squashed commit of the following: commit e1b965c371481d6d49f68166f4bb338ad7c80649 Author: Carter Waxman Date: Thu Aug 23 16:25:18 2018 -0400 DetectionEngine: don't use s_switcher to get file data commit 1b5ef8073bf6615b14e6e17c40818e4d63c35df7 Author: Carter Waxman Date: Thu Aug 23 15:13:19 2018 -0400 DetectionEngine: use packet to reference context --- src/detection/detection_engine.cc | 4 ++-- src/detection/detection_engine.h | 10 ++++------ src/detection/detection_options.cc | 3 ++- src/ips_options/ips_file_data.cc | 5 ++--- src/log/log_text.cc | 6 ++---- src/service_inspectors/http2_inspect/http2_inspect.cc | 3 ++- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/detection/detection_engine.cc b/src/detection/detection_engine.cc index 6e615735b..79481ec1c 100644 --- a/src/detection/detection_engine.cc +++ b/src/detection/detection_engine.cc @@ -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); } diff --git a/src/detection/detection_engine.h b/src/detection/detection_engine.h index 2a9d550e0..e6015ab41 100644 --- a/src/detection/detection_engine.h +++ b/src/detection/detection_engine.h @@ -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 diff --git a/src/detection/detection_options.cc b/src/detection/detection_options.cc index ccf2ae324..5f99e0a2a 100644 --- a/src/detection/detection_options.cc +++ b/src/detection/detection_options.cc @@ -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; diff --git a/src/ips_options/ips_file_data.cc b/src/ips_options/ips_file_data.cc index d7d1c17aa..d04b2f4b7 100644 --- a/src/ips_options/ips_file_data.cc +++ b/src/ips_options/ips_file_data.cc @@ -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; diff --git a/src/log/log_text.cc b/src/log/log_text.cc index 02461bb7a..2d3c4ef9b 100644 --- a/src/log/log_text.cc +++ b/src/log/log_text.cc @@ -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 ) { diff --git a/src/service_inspectors/http2_inspect/http2_inspect.cc b/src/service_inspectors/http2_inspect/http2_inspect.cc index e00745311..6a69005ac 100644 --- a/src/service_inspectors/http2_inspect/http2_inspect.cc +++ b/src/service_inspectors/http2_inspect/http2_inspect.cc @@ -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 -- 2.47.3