@ -18,6 +18,7 @@
use crate ::applayer ::StreamSlice ;
use crate ::core ::Flow ;
use crate ::core ::STREAM_TOSERVER ;
use crate ::core ::Direction ;
#[ repr(C) ]
struct CFrame {
@ -38,7 +39,7 @@ extern {
pub struct Frame {
pub id : i64 ,
direction : i32 ,
direction : Direction ,
}
impl std ::fmt ::Debug for Frame {
@ -52,8 +53,6 @@ impl Frame {
flow : * const Flow , stream_slice : & StreamSlice , frame_start : & [ u8 ] , frame_len : i64 ,
frame_type : u8 ,
) -> Option < Self > {
// Derive the direction from the stream slice, 0 for to server, 1 for to client.
let direction = if stream_slice . flags ( ) & STREAM_TOSERVER ! = 0 { 0 } else { 1 } ;
let offset = frame_start . as_ptr ( ) as usize - stream_slice . as_slice ( ) . as_ptr ( ) as usize ;
SCLogDebug ! ( "offset {} stream_slice.len() {} frame_start.len() {}" , offset , stream_slice . len ( ) , frame_start . len ( ) ) ;
// If running Rust unit tests this won't be compiled and None will be returned, as we don't
@ -65,13 +64,16 @@ impl Frame {
stream_slice ,
offset as u32 ,
frame_len ,
direction ,
if stream_slice . flags ( ) & STREAM_TOSERVER ! = 0 { 0 } else { 1 } ,
frame_type ,
)
} ;
let id = unsafe { AppLayerFrameGetId ( frame ) } ;
if id > 0 {
Some ( Self { id , direction } )
Some ( Self {
id ,
direction : Direction ::from ( stream_slice . flags ( ) ) ,
} )
} else {
None
}
@ -80,21 +82,31 @@ impl Frame {
}
}
/// Conversion function to get the direction in the correct form for the
/// C frame methods which takes direction as a u32 value of 0 or 1 rather
/// than the flag value used internally by Frame.
fn direction ( & self ) -> i32 {
match self . direction {
Direction ::ToServer = > 0 ,
Direction ::ToClient = > 1 ,
}
}
pub fn set_len ( & self , flow : * const Flow , len : i64 ) {
unsafe {
AppLayerFrameSetLengthById ( flow , self . direction , self . id , len ) ;
AppLayerFrameSetLengthById ( flow , self . direction () , self . id , len ) ;
} ;
}
pub fn set_tx ( & self , flow : * const Flow , tx_id : u64 ) {
unsafe {
AppLayerFrameSetTxIdById ( flow , self . direction , self . id , tx_id ) ;
AppLayerFrameSetTxIdById ( flow , self . direction () , self . id , tx_id ) ;
} ;
}
pub fn add_event ( & self , flow : * const Flow , event : u8 ) {
unsafe {
AppLayerFrameAddEventById ( flow , self . direction , self . id , event ) ;
AppLayerFrameAddEventById ( flow , self . direction () , self . id , event ) ;
} ;
}
}