-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/http range/v29 #6355
Closed
Closed
Feature/http range/v29 #6355
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1d48d57
detect: suppress scan-build warning
victorjulien e690fcb
util: adds util function SCBufferCmp
catenacyber 18375bc
util: export Djb2 hash string function
catenacyber 71af1f5
http/range: reassemble files from different flows with range
catenacyber 7e1ab56
http/range: fix memory leak on out of order ranges
victorjulien e0c6071
http/range: optimize struct layout
victorjulien 551a2f4
http/range: cleanup and simplification
victorjulien 5be9789
thash: add debug validation check for use_cnt
victorjulien 77ceb2e
http: avoid one lock for range append data
catenacyber 7bdf3af
http: range transfering ownership of file container
catenacyber 33d1ada
http: increase tracked files for ranges as well
catenacyber 27fcc74
http: more consistent return values for HTPFileOpenWithRange
catenacyber ef8fedc
try: close before free
catenacyber c0c1aa6
rust: rename to StreamingBufferConfig as in C
catenacyber ae71206
http2: better rust lifetimes
catenacyber 6147dc2
range: no final zero in key
catenacyber 928b29c
range: post process out of order blocks
catenacyber 2758109
http2: follow range requests
catenacyber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,14 @@ | |
*/ | ||
|
||
use super::decompression; | ||
use super::detect; | ||
use super::parser; | ||
use super::range; | ||
|
||
use crate::applayer::{self, *}; | ||
use crate::core::{ | ||
self, AppProto, Flow, SuricataFileContext, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, | ||
STREAM_TOCLIENT, STREAM_TOSERVER, | ||
self, AppProto, Flow, HttpRangeContainerBlock, SuricataFileContext, ALPROTO_FAILED, | ||
ALPROTO_UNKNOWN, IPPROTO_TCP, SC, STREAM_TOCLIENT, STREAM_TOSERVER, | ||
}; | ||
use crate::filecontainer::*; | ||
use crate::filetracker::*; | ||
|
@@ -129,11 +132,12 @@ pub struct HTTP2Transaction { | |
pub frames_ts: Vec<HTTP2Frame>, | ||
|
||
decoder: decompression::HTTP2Decoder, | ||
pub file_range: *mut HttpRangeContainerBlock, | ||
|
||
de_state: Option<*mut core::DetectEngineState>, | ||
events: *mut core::AppLayerDecoderEvents, | ||
tx_data: AppLayerTxData, | ||
ft_tc: FileTransferTracker, | ||
pub ft_tc: FileTransferTracker, | ||
ft_ts: FileTransferTracker, | ||
|
||
//temporary escaped header for detection | ||
|
@@ -151,6 +155,7 @@ impl HTTP2Transaction { | |
frames_tc: Vec::new(), | ||
frames_ts: Vec::new(), | ||
decoder: decompression::HTTP2Decoder::new(), | ||
file_range: std::ptr::null_mut(), | ||
de_state: None, | ||
events: std::ptr::null_mut(), | ||
tx_data: AppLayerTxData::new(), | ||
|
@@ -167,6 +172,27 @@ impl HTTP2Transaction { | |
if let Some(state) = self.de_state { | ||
core::sc_detect_engine_state_free(state); | ||
} | ||
if self.file_range != std::ptr::null_mut() { | ||
match unsafe { SC } { | ||
None => panic!("BUG no suricata_config"), | ||
Some(c) => { | ||
//TODO get a file container instead of NULL | ||
(c.HTPFileCloseHandleRange)( | ||
std::ptr::null_mut(), | ||
0, | ||
self.file_range, | ||
std::ptr::null_mut(), | ||
0, | ||
); | ||
(c.HttpRangeFreeBlock)(self.file_range); | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn set_event(&mut self, event: HTTP2Event) { | ||
let ev = event as u8; | ||
core::sc_app_layer_decoder_events_set_event_raw(&mut self.events, ev); | ||
} | ||
|
||
fn handle_headers(&mut self, blocks: &Vec<parser::HTTP2FrameHeaderBlock>, dir: u8) { | ||
|
@@ -179,7 +205,7 @@ impl HTTP2Transaction { | |
|
||
fn decompress<'a>( | ||
&'a mut self, input: &'a [u8], dir: u8, sfcm: &'static SuricataFileContext, over: bool, | ||
files: &mut FileContainer, flags: u16, | ||
files: &mut FileContainer, flags: u16, flow: *const Flow, | ||
) -> io::Result<()> { | ||
let mut output = Vec::with_capacity(decompression::HTTP2_DECOMPRESSION_CHUNK_SIZE); | ||
let decompressed = self.decoder.decompress(input, &mut output, dir)?; | ||
|
@@ -190,6 +216,31 @@ impl HTTP2Transaction { | |
// we are now sure that new_chunk will open a file | ||
// even if it may close it right afterwards | ||
self.tx_data.incr_files_opened(); | ||
if let Ok(value) = detect::http2_frames_get_header_value_vec( | ||
self, | ||
STREAM_TOCLIENT, | ||
"content-range", | ||
) { | ||
match range::http2_parse_content_range(&value) { | ||
Ok((_, v)) => { | ||
range::http2_range_open(self, &v, flow, sfcm, flags, decompressed); | ||
if over { | ||
range::http2_range_close(self, files, flags, &[]) | ||
} | ||
} | ||
_ => { | ||
self.set_event(HTTP2Event::InvalidRange); | ||
} | ||
} | ||
} | ||
} else { | ||
if self.file_range != std::ptr::null_mut() { | ||
if over { | ||
range::http2_range_close(self, files, flags, decompressed) | ||
} else { | ||
range::http2_range_append(self.file_range, decompressed) | ||
} | ||
} | ||
} | ||
self.ft_tc.new_chunk( | ||
sfcm, | ||
|
@@ -321,6 +372,7 @@ pub enum HTTP2Event { | |
StreamIdReuse, | ||
InvalidHTTP1Settings, | ||
FailedDecompression, | ||
InvalidRange, | ||
} | ||
|
||
pub struct HTTP2DynTable { | ||
|
@@ -350,6 +402,7 @@ pub struct HTTP2State { | |
transactions: Vec<HTTP2Transaction>, | ||
progress: HTTP2ConnectionState, | ||
pub files: Files, | ||
flow: *const Flow, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideally we're not adding this if we can just pass it around as a function argument There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right |
||
} | ||
|
||
impl HTTP2State { | ||
|
@@ -366,6 +419,7 @@ impl HTTP2State { | |
transactions: Vec::new(), | ||
progress: HTTP2ConnectionState::Http2StateInit, | ||
files: Files::default(), | ||
flow: std::ptr::null_mut(), | ||
} | ||
} | ||
|
||
|
@@ -825,6 +879,7 @@ impl HTTP2State { | |
over, | ||
files, | ||
flags, | ||
self.flow, | ||
) { | ||
Err(_e) => { | ||
self.set_event(HTTP2Event::FailedDecompression); | ||
|
@@ -1025,6 +1080,7 @@ pub unsafe extern "C" fn rs_http2_parse_ts( | |
|
||
state.files.flags_ts = FileFlowToFlags(flow, STREAM_TOSERVER); | ||
state.files.flags_ts = state.files.flags_ts | FILE_USE_DETECT; | ||
state.flow = flow; | ||
return state.parse_ts(buf); | ||
} | ||
|
||
|
@@ -1037,6 +1093,7 @@ pub unsafe extern "C" fn rs_http2_parse_tc( | |
let buf = build_slice!(input, input_len as usize); | ||
state.files.flags_tc = FileFlowToFlags(flow, STREAM_TOCLIENT); | ||
state.files.flags_tc = state.files.flags_tc | FILE_USE_DETECT; | ||
state.flow = flow; | ||
return state.parse_tc(buf); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ pub mod http2; | |
mod huffman; | ||
pub mod logger; | ||
mod parser; | ||
mod range; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: address or remove comment if its not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be much easier when we have file per tx
Right now, I should do something like
state.files.get(STREAM_TOCLIENT)
but I do not have an easy reference tostate
inHTTP2Transaction::free
So, what should we do ?