diff --git a/rust/src/http2/range.rs b/rust/src/http2/range.rs index 4afd038f62..22d3bb1b57 100644 --- a/rust/src/http2/range.rs +++ b/rust/src/http2/range.rs @@ -16,9 +16,8 @@ */ use super::detect; -use crate::core::{StreamingBufferConfig, SuricataFileContext}; +use crate::core::SuricataFileContext; use crate::direction::Direction; -use crate::filecontainer::FileContainer; use crate::flow::Flow; use crate::http2::http2::HTTP2Transaction; use crate::http2::http2::SURICATA_HTTP2_FILE_CONFIG; @@ -30,18 +29,9 @@ use nom7::combinator::{map_res, value}; use nom7::error::{make_error, ErrorKind}; use nom7::{Err, IResult}; use std::str::FromStr; -use suricata_sys::sys::{HttpRangeContainerBlock, SCHttpRangeContainerOpenFile, SCHttpRangeAppendData}; - -// Defined in app-layer-htp-file.h -#[allow(unused_doc_comments)] -/// cbindgen:ignore -extern "C" { - #[cfg(not(test))] - pub fn SCHTPFileCloseHandleRange( - sbcfg: &StreamingBufferConfig, fc: *mut FileContainer, flags: u16, - c: *mut HttpRangeContainerBlock, data: *const u8, data_len: u32, - ) -> bool; -} +use suricata_sys::sys::{ + HttpRangeContainerBlock, SCHttpRangeAppendData, SCHttpRangeContainerOpenFile, +}; #[cfg(test)] #[allow(non_snake_case)] @@ -49,6 +39,12 @@ pub(super) unsafe fn SCHttpRangeFreeBlock(_range: *mut HttpRangeContainerBlock) #[cfg(not(test))] pub(super) use suricata_sys::sys::SCHttpRangeFreeBlock; +#[cfg(test)] +use crate::core::StreamingBufferConfig; +#[cfg(test)] +use crate::filecontainer::FileContainer; +#[cfg(not(test))] +pub(super) use suricata_sys::sys::SCHTPFileCloseHandleRange; #[cfg(test)] #[allow(non_snake_case)] pub(super) unsafe fn SCHTPFileCloseHandleRange( diff --git a/rust/sys/src/sys.rs b/rust/sys/src/sys.rs index 84d611c508..b4e24106cc 100644 --- a/rust/sys/src/sys.rs +++ b/rust/sys/src/sys.rs @@ -1131,6 +1131,12 @@ extern "C" { len: u32, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn SCHTPFileCloseHandleRange( + sbcfg: *const StreamingBufferConfig, arg1: *mut FileContainer, arg2: u16, + arg3: *mut HttpRangeContainerBlock, arg4: *const u8, arg5: u32, + ) -> bool; +} pub type FrameId = i64; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/src/app-layer-htp-file.c b/src/app-layer-htp-file.c index 4f3a8310e7..620ce0d9a2 100644 --- a/src/app-layer-htp-file.c +++ b/src/app-layer-htp-file.c @@ -260,36 +260,6 @@ end: SCReturnInt(retval); } -/** \brief close range, add reassembled file if possible - * \retval true if reassembled file was added - * \retval false if no reassembled file was added - */ -bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *files, - const uint16_t flags, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t data_len) -{ - bool added = false; - if (SCHttpRangeAppendData(sbcfg, c, data, data_len) < 0) { - SCLogDebug("Failed to append data"); - } - if (c->container) { - // we only call HttpRangeClose if we may some new data - // ie we do not call it if we skipped all this range request - THashDataLock(c->container->hdata); - if (c->container->error) { - SCLogDebug("range in ERROR state"); - } - File *ranged = HttpRangeClose(sbcfg, c, flags); - if (ranged && files) { - /* HtpState owns the constructed file now */ - FileContainerAdd(files, ranged); - added = true; - } - DEBUG_VALIDATE_BUG_ON(ranged && !files); - THashDataUnlock(c->container->hdata); - } - return added; -} - /** * \brief Close the file in the flow * diff --git a/src/app-layer-htp-file.h b/src/app-layer-htp-file.h index 4cfe5531e0..e4124b6223 100644 --- a/src/app-layer-htp-file.h +++ b/src/app-layer-htp-file.h @@ -31,8 +31,6 @@ int HTPFileOpen( HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *, uint32_t, uint8_t); int HTPFileOpenWithRange(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *, uint32_t, const htp_tx_t *, const bstr *rawvalue, HtpTxUserData *htud); -bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *, const uint16_t, - HttpRangeContainerBlock *, const uint8_t *, uint32_t); int HTPFileStoreChunk(HtpTxUserData *, const uint8_t *, uint32_t, uint8_t); int HTPParseContentRange(const bstr *rawvalue, HTTPContentRange *range); diff --git a/src/app-layer-htp-range.c b/src/app-layer-htp-range.c index 722bac670d..25334e72a8 100644 --- a/src/app-layer-htp-range.c +++ b/src/app-layer-htp-range.c @@ -627,3 +627,33 @@ void SCHttpRangeFreeBlock(HttpRangeContainerBlock *b) SCFree(b); } } + +/** \brief close range, add reassembled file if possible + * \retval true if reassembled file was added + * \retval false if no reassembled file was added + */ +bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *files, + const uint16_t flags, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t data_len) +{ + bool added = false; + if (SCHttpRangeAppendData(sbcfg, c, data, data_len) < 0) { + SCLogDebug("Failed to append data"); + } + if (c->container) { + // we only call HttpRangeClose if we may some new data + // ie we do not call it if we skipped all this range request + THashDataLock(c->container->hdata); + if (c->container->error) { + SCLogDebug("range in ERROR state"); + } + File *ranged = HttpRangeClose(sbcfg, c, flags); + if (ranged && files) { + /* HtpState owns the constructed file now */ + FileContainerAdd(files, ranged); + added = true; + } + DEBUG_VALIDATE_BUG_ON(ranged && !files); + THashDataUnlock(c->container->hdata); + } + return added; +} diff --git a/src/app-layer-htp-range.h b/src/app-layer-htp-range.h index 3a1cc474b6..1242acf4ee 100644 --- a/src/app-layer-htp-range.h +++ b/src/app-layer-htp-range.h @@ -52,6 +52,9 @@ HttpRangeContainerBlock *SCHttpRangeContainerOpenFile(const unsigned char *key, int SCHttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t len); +bool SCHTPFileCloseHandleRange(const StreamingBufferConfig *sbcfg, FileContainer *, const uint16_t, + HttpRangeContainerBlock *, const uint8_t *, uint32_t); + #ifndef SURICATA_BINDGEN_H #include "util-streaming-buffer.h"