From: Tom Peters (thopeter) Date: Tue, 27 Sep 2022 15:19:44 +0000 (+0000) Subject: Pull request #3601: http2_inspect: std::list - remove indirection from stream list X-Git-Tag: 3.1.43.0~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d64c4f881e3c7d3d281811f3d3ee81d58fcd679b;p=thirdparty%2Fsnort3.git Pull request #3601: http2_inspect: std::list - remove indirection from stream list Merge in SNORT/snort3 from ~ADMAMOLE/snort3:vtune_test2 to master Squashed commit of the following: commit 1539d242a59d76adcccd50fd95197df634dbbdd5 Author: Adrian Mamolea Date: Thu Sep 22 16:37:47 2022 -0400 http2_inspect: std::list - remove indirection from stream list --- diff --git a/src/service_inspectors/http2_inspect/http2_flow_data.cc b/src/service_inspectors/http2_inspect/http2_flow_data.cc index 73f08ea28..76bcdeba7 100644 --- a/src/service_inspectors/http2_inspect/http2_flow_data.cc +++ b/src/service_inspectors/http2_inspect/http2_flow_data.cc @@ -97,12 +97,9 @@ Http2FlowData::~Http2FlowData() hi_ss[k]->go_away(); delete[] frame_data[k]; } - - for (Http2Stream* stream : streams) - delete stream; } -HttpFlowData* Http2FlowData::get_hi_flow_data() const +HttpFlowData* Http2FlowData::get_hi_flow_data() { assert(stream_in_hi != Http2Enums::NO_STREAM_ID); Http2Stream* stream = get_hi_stream(); @@ -116,12 +113,12 @@ void Http2FlowData::set_hi_flow_data(HttpFlowData* flow) stream->set_hi_flow_data(flow); } -Http2Stream* Http2FlowData::find_stream(const uint32_t key) const +Http2Stream* Http2FlowData::find_stream(const uint32_t key) { - for (Http2Stream* stream : streams) + for (Http2Stream& stream : streams) { - if (stream->get_stream_id() == key) - return stream; + if (stream.get_stream_id() == key) + return &stream; } return nullptr; @@ -178,8 +175,8 @@ Http2Stream* Http2FlowData::get_processing_stream(const SourceId source_id, uint } // Allocate new stream - stream = new Http2Stream(key, this); - streams.emplace_front(stream); + streams.emplace_front(key, this); + stream = &streams.front(); // stream 0 does not count against stream limit if (key > 0) @@ -194,12 +191,12 @@ Http2Stream* Http2FlowData::get_processing_stream(const SourceId source_id, uint void Http2FlowData::delete_processing_stream() { - std::list::iterator it; + std::list::iterator it; + for (it = streams.begin(); it != streams.end(); ++it) { - if ((*it)->get_stream_id() == processing_stream_id) + if (it->get_stream_id() == processing_stream_id) { - delete *it; streams.erase(it); delete_stream = false; assert(concurrent_streams > 0); @@ -210,17 +207,17 @@ void Http2FlowData::delete_processing_stream() assert(false); } -Http2Stream* Http2FlowData::get_hi_stream() const +Http2Stream* Http2FlowData::get_hi_stream() { return find_stream(stream_in_hi); } -Http2Stream* Http2FlowData::find_current_stream(const SourceId source_id) const +Http2Stream* Http2FlowData::find_current_stream(const SourceId source_id) { return find_stream(current_stream[source_id]); } -Http2Stream* Http2FlowData::find_processing_stream() const +Http2Stream* Http2FlowData::find_processing_stream() { return find_stream(get_processing_stream_id()); } diff --git a/src/service_inspectors/http2_inspect/http2_flow_data.h b/src/service_inspectors/http2_inspect/http2_flow_data.h index d975155be..e8d39e012 100644 --- a/src/service_inspectors/http2_inspect/http2_flow_data.h +++ b/src/service_inspectors/http2_inspect/http2_flow_data.h @@ -58,7 +58,7 @@ public: static void init() { inspector_id = snort::FlowData::create_flow_data_id(); } // Used by http_inspect to store its stuff - HttpFlowData* get_hi_flow_data() const; + HttpFlowData* get_hi_flow_data(); void set_hi_flow_data(HttpFlowData* flow); HttpMsgSection* get_hi_msg_section() const { return hi_msg_section; } void set_hi_msg_section(HttpMsgSection* section) @@ -86,10 +86,10 @@ public: friend class Http2WindowUpdateFrame; friend void finish_msg_body(Http2FlowData* session_data, HttpCommon::SourceId source_id); - Http2Stream* find_current_stream(const HttpCommon::SourceId source_id) const; + Http2Stream* find_current_stream(const HttpCommon::SourceId source_id); uint32_t get_current_stream_id(const HttpCommon::SourceId source_id) const; Http2Stream* get_processing_stream(const HttpCommon::SourceId source_id, uint32_t concurrent_streams_limit); - Http2Stream* find_processing_stream() const; + Http2Stream* find_processing_stream(); uint32_t get_processing_stream_id() const; void set_processing_stream_id(const HttpCommon::SourceId source_id); bool is_processing_partial_header() const { return processing_partial_header; } @@ -150,7 +150,7 @@ protected: // Used in eval() Http2ConnectionSettings connection_settings[2]; Http2HpackDecoder hpack_decoder[2]; - std::list streams; + std::list streams; uint32_t concurrent_files = 0; uint32_t concurrent_streams = 0; uint32_t stream_memory_allocations_tracked = Http2Enums::STREAM_MEMORY_TRACKING_INCREMENT; @@ -201,8 +201,8 @@ protected: #endif private: - Http2Stream* get_hi_stream() const; - Http2Stream* find_stream(const uint32_t key) const; + Http2Stream* get_hi_stream(); + Http2Stream* find_stream(const uint32_t key); void delete_processing_stream(); }; diff --git a/src/service_inspectors/http2_inspect/http2_stream_splitter.cc b/src/service_inspectors/http2_inspect/http2_stream_splitter.cc index 2c9bd0f29..0092992f5 100644 --- a/src/service_inspectors/http2_inspect/http2_stream_splitter.cc +++ b/src/service_inspectors/http2_inspect/http2_stream_splitter.cc @@ -262,23 +262,23 @@ bool Http2StreamSplitter::finish(Flow* flow) } // Loop through all nonzero streams with open message bodies and call NHI finish() - for (const Http2Stream* stream : session_data->streams) + for (const Http2Stream& stream : session_data->streams) { - if ((stream->get_stream_id() == 0) || - (stream->get_state(source_id) >= STREAM_COMPLETE) || - (stream->get_hi_flow_data() == nullptr) || - (stream->get_hi_flow_data()->get_type_expected(source_id) + if ((stream.get_stream_id() == 0) || + (stream.get_state(source_id) >= STREAM_COMPLETE) || + (stream.get_hi_flow_data() == nullptr) || + (stream.get_hi_flow_data()->get_type_expected(source_id) != SEC_BODY_HX) || (session_data->processing_partial_header && - (stream->get_stream_id() == session_data->current_stream[source_id]))) + (stream.get_stream_id() == session_data->current_stream[source_id]))) { continue; } - session_data->stream_in_hi = stream->get_stream_id(); + session_data->stream_in_hi = stream.get_stream_id(); if (session_data->hi_ss[source_id]->finish(flow)) { - assert(stream->get_stream_id() == session_data->current_stream[source_id]); + assert(stream.get_stream_id() == session_data->current_stream[source_id]); need_reassemble = true; #ifdef REG_TEST if (HttpTestManager::use_test_input(HttpTestManager::IN_HTTP2))