]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3333: http_inspect: install header files, create SO_PUBLIC base class...
authorGeorge Koikara (gkoikara) <gkoikara@cisco.com>
Fri, 29 Apr 2022 14:36:20 +0000 (14:36 +0000)
committerGeorge Koikara (gkoikara) <gkoikara@cisco.com>
Fri, 29 Apr 2022 14:36:20 +0000 (14:36 +0000)
Merge in SNORT/snort3 from ~SHIKV/snort3:h3_initial to master

Squashed commit of the following:

commit f027a9fa26ff3ee219eb3ed4717a90056c01a0f7
Author: shibin k v <shikv@cisco.com>
Date:   Wed Mar 30 11:19:21 2022 +0000

    http_inspect: install header files, create a virtual base class for http_inspect and http_stream_splitter

25 files changed:
src/service_inspectors/http2_inspect/http2_data_cutter.cc
src/service_inspectors/http2_inspect/http2_headers_frame.cc
src/service_inspectors/http2_inspect/http2_headers_frame_header.cc
src/service_inspectors/http2_inspect/http2_headers_frame_trailer.cc
src/service_inspectors/http2_inspect/http2_headers_frame_with_startline.cc
src/service_inspectors/http2_inspect/http2_push_promise_frame.cc
src/service_inspectors/http2_inspect/http2_stream.cc
src/service_inspectors/http2_inspect/http2_stream_splitter.cc
src/service_inspectors/http_inspect/CMakeLists.txt
src/service_inspectors/http_inspect/http_common.h
src/service_inspectors/http_inspect/http_cutter.cc
src/service_inspectors/http_inspect/http_cutter.h
src/service_inspectors/http_inspect/http_enum.h
src/service_inspectors/http_inspect/http_flow_data.cc
src/service_inspectors/http_inspect/http_flow_data.h
src/service_inspectors/http_inspect/http_inspect.cc
src/service_inspectors/http_inspect/http_inspect.h
src/service_inspectors/http_inspect/http_inspect_base.h [new file with mode: 0644]
src/service_inspectors/http_inspect/http_msg_body_h2.cc
src/service_inspectors/http_inspect/http_stream_splitter.h
src/service_inspectors/http_inspect/http_stream_splitter_base.h [new file with mode: 0644]
src/service_inspectors/http_inspect/http_stream_splitter_finish.cc
src/service_inspectors/http_inspect/http_stream_splitter_reassemble.cc
src/service_inspectors/http_inspect/http_stream_splitter_scan.cc
src/service_inspectors/http_inspect/ips_http_param.cc

index f0d22edb2c4205000a08c2e80d3fdf818dca783e..89ff65ba27106d14dd1714154b62e0c4697e55e7 100644 (file)
@@ -74,7 +74,7 @@ StreamSplitter::Status Http2DataCutter::skip_over_frame(Http2Stream* const strea
 bool Http2DataCutter::check_http_state(Http2Stream* const stream)
 {
     HttpFlowData* const http_flow = stream->get_hi_flow_data();
-    if ((http_flow->get_type_expected(source_id) != HttpEnums::SEC_BODY_H2))
+    if ((http_flow->get_type_expected(source_id) != SEC_BODY_H2))
     {
         stream->set_state(source_id, STREAM_ERROR);
         if (data_len > 0)
@@ -138,7 +138,7 @@ StreamSplitter::Status Http2DataCutter::scan(const uint8_t* data, uint32_t lengt
         if ((data_bytes_read == data_len) && (frame_flags & FLAG_END_STREAM))
         {
             HttpFlowData* const hi_flow = stream->get_hi_flow_data();
-            hi_flow->set_h2_body_state(source_id, HttpEnums::H2_BODY_LAST_SEG);
+            hi_flow->set_h2_body_state(source_id, H2_BODY_LAST_SEG);
         }
         scan_result = session_data->hi_ss[source_id]->scan(&dummy_pkt, data + cur_data_offset,
             cur_data, unused, &http_flush_offset);
index 09b22d8621d2d64f469b569265044788c8864ced..8c1f995762b14071334b88f9f4bfc2c9645456f5 100644 (file)
@@ -24,7 +24,6 @@
 #include "http2_headers_frame.h"
 
 #include "protocols/packet.h"
-#include "service_inspectors/http_inspect/http_enum.h"
 #include "service_inspectors/http_inspect/http_flow_data.h"
 #include "service_inspectors/http_inspect/http_inspect.h"
 #include "service_inspectors/http_inspect/http_stream_splitter.h"
@@ -152,7 +151,7 @@ void Http2HeadersFrame::process_decoded_headers(HttpFlowData* http_flow, SourceI
         dummy_pkt.data = stream_buf.data;
         dummy_pkt.xtradata_mask = 0;
         session_data->hi->eval(&dummy_pkt);
-        if (http_flow->get_type_expected(hi_source_id) == HttpEnums::SEC_ABORT)
+        if (http_flow->get_type_expected(hi_source_id) == SEC_ABORT)
         {
             assert(session_data->is_processing_partial_header());
             stream->set_state(hi_source_id, STREAM_ERROR);
index 074ff8e9e8dec24806446970d3b2dd7b66bdb0f9..41b823084416cb51393cc536ff5be0e1cc94db05 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "http2_headers_frame_header.h"
 
-#include "service_inspectors/http_inspect/http_enum.h"
 #include "service_inspectors/http_inspect/http_flow_data.h"
 
 #include "http2_enum.h"
@@ -73,7 +72,7 @@ void Http2HeadersFrameHeader::analyze_http1()
 
     // if END_STREAM flag set on headers, tell http_inspect not to expect a message body
     if (get_flags() & FLAG_END_STREAM)
-        stream->get_hi_flow_data()->finish_h2_body(source_id, HttpEnums::H2_BODY_NO_BODY, false);
+        stream->get_hi_flow_data()->finish_h2_body(source_id, H2_BODY_NO_BODY, false);
 
     process_decoded_headers(http_flow, source_id);
 }
index a71df628ce7c5b31f741f4d88d23691b5d81dad1..7925e9861f8388f2cf983f740dce0cc6927af704 100644 (file)
@@ -24,7 +24,6 @@
 #include "http2_headers_frame_trailer.h"
 
 #include "protocols/packet.h"
-#include "service_inspectors/http_inspect/http_enum.h"
 #include "service_inspectors/http_inspect/http_flow_data.h"
 #include "service_inspectors/http_inspect/http_inspect.h"
 #include "service_inspectors/http_inspect/http_stream_splitter.h"
@@ -72,11 +71,11 @@ void Http2HeadersFrameTrailer::analyze_http1()
     assert(http_flow);
 
     const bool valid_headers = http1_header.length() > 0;
-    if (http_flow->get_type_expected(source_id) != HttpEnums::SEC_TRAILER)
+    if (http_flow->get_type_expected(source_id) != SEC_TRAILER)
     {
         // http_inspect is not yet expecting trailers. Flush empty buffer through scan, reassemble,
         // and eval to prepare http_inspect for trailers.
-        assert(http_flow->get_type_expected(source_id) == HttpEnums::SEC_BODY_H2);
+        assert(http_flow->get_type_expected(source_id) == SEC_BODY_H2);
         stream->finish_msg_body(source_id, valid_headers, true); // calls http_inspect scan()
 
         unsigned copied;
@@ -93,8 +92,8 @@ void Http2HeadersFrameTrailer::analyze_http1()
             dummy_pkt.dsize = stream_buf.length;
             dummy_pkt.data = stream_buf.data;
             session_data->hi->eval(&dummy_pkt);
-            assert (!valid_headers || http_flow->get_type_expected(source_id) == HttpEnums::SEC_TRAILER);
-            if (http_flow->get_type_expected(source_id) == HttpEnums::SEC_ABORT)
+            assert (!valid_headers || http_flow->get_type_expected(source_id) == SEC_TRAILER);
+            if (http_flow->get_type_expected(source_id) == SEC_ABORT)
             {
                 stream->set_state(source_id, STREAM_ERROR);
                 return;
index 024a225be322487c581480577dc98bdcbb5cf76f..5574dbf8d2caafbdbc3851bf69485de9bc3d616d 100644 (file)
@@ -24,7 +24,6 @@
 #include "http2_headers_frame_with_startline.h"
 
 #include "protocols/packet.h"
-#include "service_inspectors/http_inspect/http_enum.h"
 #include "service_inspectors/http_inspect/http_flow_data.h"
 #include "service_inspectors/http_inspect/http_inspect.h"
 #include "service_inspectors/http_inspect/http_stream_splitter.h"
@@ -90,7 +89,7 @@ bool Http2HeadersFrameWithStartline::process_start_line(HttpFlowData*& http_flow
         dummy_pkt.dsize = stream_buf.length;
         dummy_pkt.data = stream_buf.data;
         session_data->hi->eval(&dummy_pkt);
-        if (http_flow->get_type_expected(hi_source_id) != HttpEnums::SEC_HEADER)
+        if (http_flow->get_type_expected(hi_source_id) != SEC_HEADER)
         {
             stream->set_state(hi_source_id, STREAM_ERROR);
             return false;
index b72a892d8e73dca3e69b563b35bf7e2f51276f81..2083985cf0d027db3da30eceecd1ae7848acc5b0 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "http2_push_promise_frame.h"
 
-#include "service_inspectors/http_inspect/http_enum.h"
 #include "service_inspectors/http_inspect/http_flow_data.h"
 
 #include "http2_flow_data.h"
@@ -117,7 +116,7 @@ void Http2PushPromiseFrame::analyze_http1()
 
     // Push promise cannot have a message body
     // FIXIT-E handle bad request lines and cases where a message body is implied
-    stream->get_hi_flow_data()->finish_h2_body(SRC_CLIENT, HttpEnums::H2_BODY_NO_BODY, false);
+    stream->get_hi_flow_data()->finish_h2_body(SRC_CLIENT, H2_BODY_NO_BODY, false);
 
     process_decoded_headers(http_flow, SRC_CLIENT);
 }
index 99abd7d2a99cfcd9cad9119ceff16979ecc091a2..cdbdbcf6fc619701717d32abe9b96cdfd6c1ec04 100644 (file)
@@ -24,7 +24,6 @@
 #include "http2_enum.h"
 #include "http2_stream.h"
 
-#include "service_inspectors/http_inspect/http_enum.h"
 #include "service_inspectors/http_inspect/http_flow_data.h"
 #include "service_inspectors/http_inspect/http_stream_splitter.h"
 
@@ -34,7 +33,6 @@
 
 using namespace HttpCommon;
 using namespace Http2Enums;
-using namespace HttpEnums;
 
 Http2Stream::Http2Stream(uint32_t stream_id_, Http2FlowData* session_data_) :
     stream_id(stream_id_),
index c921c3a420a86054e89a4d7370e8b9095e4a682e..27f28dd67a1fa097d89ef8ea728fa7b84e2198ba 100644 (file)
@@ -264,7 +264,7 @@ bool Http2StreamSplitter::finish(Flow* flow)
             (stream->get_state(source_id) >= STREAM_COMPLETE)         ||
             (stream->get_hi_flow_data() == nullptr)                   ||
             (stream->get_hi_flow_data()->get_type_expected(source_id)
-                != HttpEnums::SEC_BODY_H2)                            ||
+                != SEC_BODY_H2)                                       ||
             (session_data->processing_partial_header &&
                 (stream->get_stream_id() == session_data->current_stream[source_id])))
         {
index c9069f2ce7a1a7a5cdec4a660861c2c6069ad2ed..3ef0ac16851c886f33b77699048f40af19cc7112 100644 (file)
@@ -1,9 +1,16 @@
 
+set(HTTP_INCLUDES
+    http_field.h
+    http_common.h
+    http_inspect_base.h
+    http_stream_splitter_base.h
+)
 set (FILE_LIST
+    ${HTTP_INCLUDES}
     ips_http.cc
     ips_http.h
-    http_buffer_info.h
     http_buffer_info.cc
+    http_buffer_info.h
     http_inspect.cc
     http_inspect.h
     http_msg_section.cc
@@ -60,9 +67,7 @@ set (FILE_LIST
     http_transaction.h
     http_test_manager.cc
     http_test_manager.h
-    http_enum.h
     http_field.cc
-    http_field.h
     http_stream_splitter_finish.cc
     http_stream_splitter_reassemble.cc
     http_stream_splitter_scan.cc
@@ -91,6 +96,8 @@ set (FILE_LIST
     #add_dynamic_module(http_inspect inspectors ${FILE_LIST})
 
 #endif(STATIC_INSPECTORS)
-
+install(FILES ${HTTP_INCLUDES}
+    DESTINATION "${INCLUDE_INSTALL_PATH}/service_inspectors/http_inspect"
+)
 add_subdirectory ( test )
 
index e67603c6afd35b90b70920cb72eee5381d2521d6..679a9ff79818808519bc9407e2d83591080cfe6d 100644 (file)
@@ -32,6 +32,14 @@ enum StatusCode { STAT_NO_SOURCE=-16, STAT_NOT_CONFIGURED=-15, STAT_NOT_COMPUTE=
 // Message originator--client or server
 enum SourceId { SRC__NOT_COMPUTE=-14, SRC_CLIENT=0, SRC_SERVER=1 };
 
+// Type of message section
+enum SectionType { SEC_DISCARD = -19, SEC_ABORT = -18, SEC__NOT_COMPUTE=-14, SEC__NOT_PRESENT=-11,
+    SEC_REQUEST = 2, SEC_STATUS, SEC_HEADER, SEC_BODY_CL, SEC_BODY_CHUNK, SEC_TRAILER,
+    SEC_BODY_OLD, SEC_BODY_H2 };
+
+enum H2BodyState { H2_BODY_NOT_COMPLETE, H2_BODY_LAST_SEG, H2_BODY_COMPLETE,
+    H2_BODY_COMPLETE_EXPECT_TRAILERS, H2_BODY_NO_BODY };
+
 } // end namespace HttpCommon
 
 #endif
index 22057be215bf72705ce5e545867e1695ab814905..929f07bc81b0bb44b8ddaef120f2677d4ca14a9c 100644 (file)
 #include "http_module.h"
 
 using namespace HttpEnums;
+using namespace HttpCommon;
 
 ScanResult HttpStartCutter::cut(const uint8_t* buffer, uint32_t length,
-    HttpInfractions* infractions, HttpEventGen* events, uint32_t, bool, HttpEnums::H2BodyState)
+    HttpInfractions* infractions, HttpEventGen* events, uint32_t, bool, H2BodyState)
 {
     for (uint32_t k = 0; k < length; k++)
     {
@@ -183,7 +184,7 @@ HttpStartCutter::ValidationResult HttpStatusCutter::validate(uint8_t octet,
 }
 
 ScanResult HttpHeaderCutter::cut(const uint8_t* buffer, uint32_t length,
-    HttpInfractions* infractions, HttpEventGen* events, uint32_t, bool, HttpEnums::H2BodyState)
+    HttpInfractions* infractions, HttpEventGen* events, uint32_t, bool, H2BodyState)
 {
     // Header separators: leading \r\n, leading \n, leading \r\r\n, nonleading \r\n\r\n, nonleading
     // \n\r\n, nonleading \r\r\n, nonleading \r\n\n, and nonleading \n\n. The separator itself
@@ -323,7 +324,7 @@ HttpBodyCutter::~HttpBodyCutter()
 }
 
 ScanResult HttpBodyClCutter::cut(const uint8_t* buffer, uint32_t length, HttpInfractions*,
-    HttpEventGen*, uint32_t flow_target, bool stretch, HttpEnums::H2BodyState)
+    HttpEventGen*, uint32_t flow_target, bool stretch, H2BodyState)
 {
     assert(remaining > octets_seen);
 
@@ -400,7 +401,7 @@ ScanResult HttpBodyClCutter::cut(const uint8_t* buffer, uint32_t length, HttpInf
 }
 
 ScanResult HttpBodyOldCutter::cut(const uint8_t* buffer, uint32_t length, HttpInfractions*,
-    HttpEventGen*, uint32_t flow_target, bool stretch, HttpEnums::H2BodyState)
+    HttpEventGen*, uint32_t flow_target, bool stretch, H2BodyState)
 {
     if (flow_target == 0)
     {
@@ -446,7 +447,7 @@ void HttpBodyChunkCutter::transition_to_chunk_bad(bool& accelerate_this_packet)
 
 ScanResult HttpBodyChunkCutter::cut(const uint8_t* buffer, uint32_t length,
     HttpInfractions* infractions, HttpEventGen* events, uint32_t flow_target, bool stretch,
-    HttpEnums::H2BodyState)
+    H2BodyState)
 {
     // Are we skipping through the rest of this chunked body to the trailers and the next message?
     const bool discard_mode = (flow_target == 0);
@@ -764,7 +765,7 @@ ScanResult HttpBodyH2Cutter::cut(const uint8_t* buffer, uint32_t length,
         {
             *infractions += INF_H2_DATA_OVERRUNS_CL;
             events->create_event(EVENT_H2_DATA_OVERRUNS_CL);
-            expected_body_length = HttpCommon::STAT_NOT_COMPUTE;
+            expected_body_length = STAT_NOT_COMPUTE;
         }
         else if (state != H2_BODY_NOT_COMPLETE and
             ((total_octets_scanned + length) < expected_body_length))
index 024d2e09b9091fa3489d13f209701d48208bb548..1edc8b70fc8947f801f19747014863bbde1a7c0c 100644 (file)
@@ -23,6 +23,7 @@
 #include <cassert>
 #include <zlib.h>
 
+#include "http_common.h"
 #include "http_enum.h"
 #include "http_event.h"
 #include "http_module.h"
@@ -39,7 +40,7 @@ public:
     virtual ~HttpCutter() = default;
     virtual HttpEnums::ScanResult cut(const uint8_t* buffer, uint32_t length,
         HttpInfractions* infractions, HttpEventGen* events, uint32_t flow_target, bool stretch,
-        HttpEnums::H2BodyState state) = 0;
+        HttpCommon::H2BodyState state) = 0;
     uint32_t get_num_flush() const { return num_flush; }
     uint32_t get_octets_seen() const { return octets_seen; }
     uint32_t get_num_excess() const { return num_crlf; }
@@ -59,7 +60,7 @@ class HttpStartCutter : public HttpCutter
 {
 public:
     HttpEnums::ScanResult cut(const uint8_t* buffer, uint32_t length,
-        HttpInfractions* infractions, HttpEventGen* events, uint32_t, bool, HttpEnums::H2BodyState)
+        HttpInfractions* infractions, HttpEventGen* events, uint32_t, bool, HttpCommon::H2BodyState)
         override;
 
 protected:
@@ -90,7 +91,7 @@ class HttpHeaderCutter : public HttpCutter
 {
 public:
     HttpEnums::ScanResult cut(const uint8_t* buffer, uint32_t length,
-        HttpInfractions* infractions, HttpEventGen* events, uint32_t, bool, HttpEnums::H2BodyState)
+        HttpInfractions* infractions, HttpEventGen* events, uint32_t, bool, HttpCommon::H2BodyState)
         override;
     uint32_t get_num_head_lines() const override { return num_head_lines; }
 
@@ -137,7 +138,7 @@ public:
         remaining(expected_length)
         { assert(remaining > 0); }
     HttpEnums::ScanResult cut(const uint8_t*, uint32_t length, HttpInfractions*, HttpEventGen*,
-        uint32_t flow_target, bool stretch, HttpEnums::H2BodyState) override;
+        uint32_t flow_target, bool stretch, HttpCommon::H2BodyState) override;
 
 private:
     int64_t remaining;
@@ -151,7 +152,7 @@ public:
         HttpBodyCutter(accelerated_blocking, finder, compression)
         {}
     HttpEnums::ScanResult cut(const uint8_t*, uint32_t, HttpInfractions*, HttpEventGen*,
-        uint32_t flow_target, bool stretch, HttpEnums::H2BodyState) override;
+        uint32_t flow_target, bool stretch, HttpCommon::H2BodyState) override;
 };
 
 class HttpBodyChunkCutter : public HttpBodyCutter
@@ -164,7 +165,7 @@ public:
         {}
     HttpEnums::ScanResult cut(const uint8_t* buffer, uint32_t length,
         HttpInfractions* infractions, HttpEventGen* events, uint32_t flow_target, bool stretch,
-        HttpEnums::H2BodyState) override;
+        HttpCommon::H2BodyState) override;
     bool get_is_broken_chunk() const override { return curr_state == HttpEnums::CHUNK_BAD; }
     uint32_t get_num_good_chunks() const override { return num_good_chunks; }
     void soft_reset() override { num_good_chunks = 0; HttpBodyCutter::soft_reset(); }
@@ -193,7 +194,7 @@ public:
             expected_body_length(expected_length)
         {}
     HttpEnums::ScanResult cut(const uint8_t* buffer, uint32_t length, HttpInfractions*,
-        HttpEventGen*, uint32_t flow_target, bool stretch, HttpEnums::H2BodyState state) override;
+        HttpEventGen*, uint32_t flow_target, bool stretch, HttpCommon::H2BodyState state) override;
 private:
     int64_t expected_body_length;
     uint32_t total_octets_scanned = 0;
index 6c6df742382235389a1d819b1a57fbc915f8866e..bbbcc320cf09d218b28984785f41069a1f39d3d6 100755 (executable)
@@ -48,11 +48,6 @@ static const uint8_t MAX_CUSTOM_HEADERS = MAX_XFF_HEADERS;
 // This can grow into a bitmap for the get_buf() form parameter
 static const uint64_t FORM_REQUEST = 0x1;
 
-// Type of message section
-enum SectionType { SEC_DISCARD = -19, SEC_ABORT = -18, SEC__NOT_COMPUTE=-14, SEC__NOT_PRESENT=-11,
-    SEC_REQUEST = 2, SEC_STATUS, SEC_HEADER, SEC_BODY_CL, SEC_BODY_CHUNK, SEC_TRAILER,
-    SEC_BODY_OLD, SEC_BODY_H2 };
-
 // HTTP rule options.
 // Lower numbered portion is message buffers available to clients.
 // That part must remain synchronized with HttpApi::classic_buffer_names[]
@@ -449,9 +444,6 @@ extern const bool is_sp_tab_quote_dquote[256];
 extern const bool is_print_char[256]; // printable includes SP, tab, CR, LF
 extern const bool is_sp_comma[256];
 
-enum H2BodyState { H2_BODY_NOT_COMPLETE, H2_BODY_LAST_SEG, H2_BODY_COMPLETE,
-    H2_BODY_COMPLETE_EXPECT_TRAILERS, H2_BODY_NO_BODY };
-
 } // end namespace HttpEnums
 
 #endif
index 117d1b1381f85c91a02f7a03ffcc86f656deec13..b5542fc8d8bee9b43eb2b0c367948e476629ba0f 100644 (file)
@@ -343,7 +343,7 @@ HttpInfractions* HttpFlowData::get_infractions(SourceId source_id)
     return transaction[source_id]->get_infractions(source_id);
 }
 
-void HttpFlowData::finish_h2_body(HttpCommon::SourceId source_id, HttpEnums::H2BodyState state,
+void HttpFlowData::finish_h2_body(HttpCommon::SourceId source_id, HttpCommon::H2BodyState state,
     bool clear_partial_buffer)
 {
     assert((h2_body_state[source_id] == H2_BODY_NOT_COMPLETE) ||
index 050acfb8bd4b49f460e3e8b02397078dd357b709..10438f2eb7d5f41e65e846c259a7102a61d49730 100644 (file)
@@ -75,13 +75,13 @@ public:
     friend class HttpUnitTestSetup;
 #endif
 
-    HttpEnums::SectionType get_type_expected(HttpCommon::SourceId source_id) const
+    HttpCommon::SectionType get_type_expected(HttpCommon::SourceId source_id) const
     { return type_expected[source_id]; }
 
-    void finish_h2_body(HttpCommon::SourceId source_id, HttpEnums::H2BodyState state,
+    void finish_h2_body(HttpCommon::SourceId source_id, HttpCommon::H2BodyState state,
         bool clear_partial_buffer);
 
-    void set_h2_body_state(HttpCommon::SourceId source_id, HttpEnums::H2BodyState state)
+    void set_h2_body_state(HttpCommon::SourceId source_id, HttpCommon::H2BodyState state)
     { h2_body_state[source_id] = state; }
 
     uint32_t get_h2_stream_id() const;
@@ -118,8 +118,8 @@ private:
     bool is_broken_chunk[2] = { false, false };
 
     // *** StreamSplitter => Inspector (facts about the most recent message section)
-    HttpEnums::SectionType section_type[2] = { HttpEnums::SEC__NOT_COMPUTE,
-                                                HttpEnums::SEC__NOT_COMPUTE };
+    HttpCommon::SectionType section_type[2] = { HttpCommon::SEC__NOT_COMPUTE,
+                                                HttpCommon::SEC__NOT_COMPUTE };
     int32_t octets_reassembled[2] = { HttpCommon::STAT_NOT_PRESENT, HttpCommon::STAT_NOT_PRESENT };
     int32_t num_head_lines[2] = { HttpCommon::STAT_NOT_PRESENT, HttpCommon::STAT_NOT_PRESENT };
     bool tcp_close[2] = { false, false };
@@ -137,7 +137,7 @@ private:
     HttpInfractions* get_infractions(HttpCommon::SourceId source_id);
 
     // *** Inspector => StreamSplitter (facts about the message section that is coming next)
-    HttpEnums::SectionType type_expected[2] = { HttpEnums::SEC_REQUEST, HttpEnums::SEC_STATUS };
+    HttpCommon::SectionType type_expected[2] = { HttpCommon::SEC_REQUEST, HttpCommon::SEC_STATUS };
     bool last_request_was_connect = false;
     z_stream* compress_stream[2] = { nullptr, nullptr };
     uint64_t zero_nine_expected = 0;
@@ -223,8 +223,8 @@ private:
     // *** HTTP/2 handling
     bool for_http2 = false;
     uint32_t h2_stream_id = 0;
-    HttpEnums::H2BodyState h2_body_state[2] = { HttpEnums::H2_BODY_NOT_COMPLETE,
-        HttpEnums::H2_BODY_NOT_COMPLETE };
+    HttpCommon::H2BodyState h2_body_state[2] = { HttpCommon::H2_BODY_NOT_COMPLETE,
+        HttpCommon::H2_BODY_NOT_COMPLETE };
 
 #ifdef REG_TEST
     static uint64_t instance_count;
index e2ca27238fe225516d59352bab04985bc552114e..57edbea660fc791d66816b0a919924e72ca3147d 100755 (executable)
@@ -325,6 +325,25 @@ VersionId HttpInspect::http_get_version_id(Packet* p,
     return current_section->get_version_id(buffer_info);
 }
 
+HttpCommon::SectionType HttpInspect::get_type_expected(snort::Flow* flow, HttpCommon::SourceId source_id) const
+{
+    HttpFlowData* session_data = http_get_flow_data(flow);
+    return session_data->get_type_expected(source_id);
+}
+
+void HttpInspect::finish_h2_body(snort::Flow* flow, HttpCommon::SourceId source_id, HttpCommon::H2BodyState state,
+    bool clear_partial_buffer) const
+{
+    HttpFlowData* session_data = http_get_flow_data(flow);
+    session_data->finish_h2_body(source_id, state, clear_partial_buffer);
+}
+
+void HttpInspect::set_h2_body_state(snort::Flow* flow, HttpCommon::SourceId source_id, HttpCommon::H2BodyState state) const
+{
+    HttpFlowData* session_data = http_get_flow_data(flow);
+    session_data->set_h2_body_state(source_id, state);
+}
+
 bool HttpInspect::get_fp_buf(InspectionBuffer::Type ibt, Packet* p, InspectionBuffer& b)
 {
     if (get_latest_is(p) == IS_NONE)
index c6954b36878ee831a417bc959ce0c2cb501684dd..0865fe96d6ba3e9be8b6e5cd215c1033ccb583c3 100644 (file)
 #include "http_common.h"
 #include "http_enum.h"
 #include "http_field.h"
+#include "http_inspect_base.h"
 #include "http_module.h"
-#include "http_msg_section.h"
 #include "http_stream_splitter.h"
 
 class HttpApi;
 class HttpParam;
 
-class HttpInspect : public snort::Inspector
+class HttpInspect : public HttpInspectBase
 {
 public:
     HttpInspect(const HttpParaList* params_);
@@ -54,6 +54,10 @@ public:
     int32_t http_get_num_headers(snort::Packet* p, const HttpBufferInfo& buffer_info) const;
     HttpEnums::VersionId http_get_version_id(snort::Packet* p,
         const HttpBufferInfo& buffer_info) const;
+    HttpCommon::SectionType get_type_expected(snort::Flow* flow, HttpCommon::SourceId source_id) const override;
+    void finish_h2_body(snort::Flow* flow, HttpCommon::SourceId source_id, HttpCommon::H2BodyState state,
+        bool clear_partial_buffer) const override;
+    void set_h2_body_state(snort::Flow* flow, HttpCommon::SourceId source_id, HttpCommon::H2BodyState state) const override;
     bool get_fp_buf(snort::InspectionBuffer::Type ibt, snort::Packet* p,
         snort::InspectionBuffer& b) override;
     bool configure(snort::SnortConfig*) override;
diff --git a/src/service_inspectors/http_inspect/http_inspect_base.h b/src/service_inspectors/http_inspect/http_inspect_base.h
new file mode 100644 (file)
index 0000000..1c853f6
--- /dev/null
@@ -0,0 +1,41 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2022-2022 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation.  You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//--------------------------------------------------------------------------
+// http_inspect_base.h author Shibin K V <shikv@cisco.com>
+
+#ifndef HTTP_INSPECT_BASE_H
+#define HTTP_INSPECT_BASE_H
+
+#include "flow/flow.h"
+#include "framework/inspector.h"
+#include "main/snort_types.h"
+
+#include "http_common.h"
+
+class SO_PUBLIC HttpInspectBase : public snort::Inspector
+{
+public:
+    virtual ~HttpInspectBase() override = default;
+    
+    virtual HttpCommon::SectionType get_type_expected(snort::Flow* flow, HttpCommon::SourceId source_id) const = 0;
+    virtual void finish_h2_body(snort::Flow* flow, HttpCommon::SourceId source_id, HttpCommon::H2BodyState state,
+        bool clear_partial_buffer) const = 0;
+    virtual void set_h2_body_state(snort::Flow* flow, HttpCommon::SourceId source_id, HttpCommon::H2BodyState state) const = 0;
+};
+
+#endif
+
index 906b85553d29a973e4f35092c6e877f5b62c5eca..0a601958be133c6e463eb55f27bd46eff2635bf6 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "http_msg_body_h2.h"
 
-using namespace HttpEnums;
+using namespace HttpCommon;
 
 void HttpMsgBodyH2::update_flow()
 {
index b9ea3ad7d225425fa2559fd40b93276caf08c2e0..e64bde15291e04c26c721a3a96c0e3e455156f2b 100644 (file)
 
 #include <zlib.h>
 
-#include "stream/stream_splitter.h"
-
 #include "http_common.h"
 #include "http_enum.h"
 #include "http_flow_data.h"
+#include "http_stream_splitter_base.h"
 #include "http_test_manager.h"
 
 class HttpInspect;
 
-class HttpStreamSplitter : public snort::StreamSplitter
+class HttpStreamSplitter : public HttpStreamSplitterBase
 {
 public:
     HttpStreamSplitter(bool is_client_to_server, HttpInspect* my_inspector_) :
-        snort::StreamSplitter(is_client_to_server),
+        HttpStreamSplitterBase(is_client_to_server),
         my_inspector(my_inspector_),
         source_id(is_client_to_server ? HttpCommon::SRC_CLIENT : HttpCommon::SRC_SERVER) {}
     Status scan(snort::Packet* pkt, const uint8_t* data, uint32_t length, uint32_t not_used,
@@ -43,7 +42,7 @@ public:
     const snort::StreamBuffer reassemble(snort::Flow* flow, unsigned total, unsigned, const
         uint8_t* data, unsigned len, uint32_t flags, unsigned& copied) override;
     bool finish(snort::Flow* flow) override;
-    void prep_partial_flush(snort::Flow* flow, uint32_t num_flush);
+    void prep_partial_flush(snort::Flow* flow, uint32_t num_flush) override;
     bool is_paf() override { return true; }
     static StreamSplitter::Status status_value(StreamSplitter::Status ret_val, bool http2 = false);
 
@@ -52,11 +51,11 @@ public:
     void go_away() override {}
 
 private:
-    void prepare_flush(HttpFlowData* session_data, uint32_t* flush_offset, HttpEnums::SectionType
+    void prepare_flush(HttpFlowData* session_data, uint32_t* flush_offset, HttpCommon::SectionType
         section_type, uint32_t num_flushed, uint32_t num_excess, int32_t num_head_lines,
         bool is_broken_chunk, uint32_t num_good_chunks, uint32_t octets_seen)
         const;
-    HttpCutter* get_cutter(HttpEnums::SectionType type, HttpFlowData* session) const;
+    HttpCutter* get_cutter(HttpCommon::SectionType type, HttpFlowData* session) const;
     void chunk_spray(HttpFlowData* session_data, uint8_t* buffer, const uint8_t* data,
         unsigned length) const;
     void decompress_copy(uint8_t* buffer, uint32_t& offset, const uint8_t* data,
diff --git a/src/service_inspectors/http_inspect/http_stream_splitter_base.h b/src/service_inspectors/http_inspect/http_stream_splitter_base.h
new file mode 100644 (file)
index 0000000..65b98fb
--- /dev/null
@@ -0,0 +1,38 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2022-2022 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation.  You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//--------------------------------------------------------------------------
+// http_stream_splitter_base.h author Shibin K V <shikv@cisco.com>
+
+#ifndef HTTP_STREAM_SPLITTER_BASE_H
+#define HTTP_STREAM_SPLITTER_BASE_H
+
+#include "main/snort_types.h"
+#include "stream/stream_splitter.h"
+
+class SO_PUBLIC HttpStreamSplitterBase : public snort::StreamSplitter
+{
+public:
+    virtual ~HttpStreamSplitterBase() override = default;
+
+    virtual void prep_partial_flush(snort::Flow* flow, uint32_t num_flush) = 0;
+    
+protected:
+    HttpStreamSplitterBase(bool c2s) : StreamSplitter(c2s) { }
+};
+
+#endif
+
index 641f8ece35f69e0c547efec69764ce24cd9c8ca1..ec2140574b0a7cad5da27587db19047e09aa2204 100644 (file)
@@ -21,6 +21,8 @@
 #include "config.h"
 #endif
 
+#include "http_stream_splitter.h"
+
 #include "file_api/file_flows.h"
 #include "pub_sub/http_request_body_event.h"
 
@@ -32,7 +34,6 @@
 #include "http_module.h"
 #include "http_msg_header.h"
 #include "http_msg_request.h"
-#include "http_stream_splitter.h"
 #include "http_test_input.h"
 
 using namespace HttpCommon;
index e06d67097503fbfb3490b1b871cda5f768e0d909..605003371d843623986284c98f7cc2bbd9d2bbde 100644 (file)
 #include "config.h"
 #endif
 
+#include "http_stream_splitter.h"
+
 #include "protocols/packet.h"
 
 #include "http_inspect.h"
 #include "http_module.h"
-#include "http_stream_splitter.h"
 #include "http_test_input.h"
 
+using namespace HttpCommon;
 using namespace HttpEnums;
 using namespace snort;
 
index 21ace0227d60c5499b038e17cfd3dea8de0b102d..3155adb2590427d6d11cc05ddcb4ad7f90810c61 100644 (file)
@@ -21,6 +21,8 @@
 #include "config.h"
 #endif
 
+#include "http_stream_splitter.h"
+
 #include "packet_io/active.h"
 
 #include "http_common.h"
@@ -28,7 +30,7 @@
 #include "http_enum.h"
 #include "http_inspect.h"
 #include "http_module.h"
-#include "http_stream_splitter.h"
+#include "http_msg_section.h"
 #include "http_test_input.h"
 
 using namespace snort;
index a864f8df2a8b4f556bf9dac5e4987e51e4a1a19c..3db8f2ff0327be51bd0e6b2ebcf5991ee393fdf7 100644 (file)
@@ -33,6 +33,7 @@
 #include "http_common.h"
 #include "http_enum.h"
 #include "http_inspect.h"
+#include "http_msg_section.h"
 #include "http_param.h"
 
 using namespace snort;