]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3601: http2_inspect: std::list - remove indirection from stream list
authorTom Peters (thopeter) <thopeter@cisco.com>
Tue, 27 Sep 2022 15:19:44 +0000 (15:19 +0000)
committerTom Peters (thopeter) <thopeter@cisco.com>
Tue, 27 Sep 2022 15:19:44 +0000 (15:19 +0000)
Merge in SNORT/snort3 from ~ADMAMOLE/snort3:vtune_test2 to master

Squashed commit of the following:

commit 1539d242a59d76adcccd50fd95197df634dbbdd5
Author: Adrian Mamolea <admamole@cisco.com>
Date:   Thu Sep 22 16:37:47 2022 -0400

    http2_inspect: std::list - remove indirection from stream list

src/service_inspectors/http2_inspect/http2_flow_data.cc
src/service_inspectors/http2_inspect/http2_flow_data.h
src/service_inspectors/http2_inspect/http2_stream_splitter.cc

index 73f08ea2833c4874edef94adfb35a925f687cbab..76bcdeba70166354beb8239e677233cda3db547d 100644 (file)
@@ -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<Http2Stream*>::iterator it;
+    std::list<Http2Stream>::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());
 }
index d975155bededae519792f3ea858e30b597082075..e8d39e012a982db653e0e1e938a23adfd1f058aa 100644 (file)
@@ -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<Http2Stream*> streams;
+    std::list<Http2Stream> 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();
 };
 
index 2c9bd0f2918eb39731c995632b10d39c90a30439..0092992f53a035030359f9d2e4df6c2fab14501d 100644 (file)
@@ -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))