rust: use bindgened Flow definition

Ticket: 7667
pull/13328/head
Philippe Antoine 8 months ago committed by Victor Julien
parent 6bc86230a5
commit f2e7309bbb

@ -36,11 +36,10 @@ use suricata::applayer::{
};
use suricata::conf::conf_get;
use suricata::core::{ALPROTO_UNKNOWN, IPPROTO_TCP};
use suricata::flow::Flow;
use suricata::{
build_slice, cast_pointer, export_state_data_get, export_tx_data_get, SCLogError, SCLogNotice,
};
use suricata_sys::sys::AppProto;
use suricata_sys::sys::{AppProto, Flow};
static mut TEMPLATE_MAX_TX: usize = 256;

@ -28,28 +28,25 @@ extern "C" {
pub const FLOW_DIR_REVERSED: u32 = BIT_U32!(26);
/// Opaque flow type (defined in C)
pub enum Flow {}
pub use suricata_sys::sys::Flow;
/// Rust implementation of Flow.
impl Flow {
/// Return the time of the last flow update as a `Duration`
/// since the epoch.
pub fn get_last_time(&mut self) -> std::time::Duration {
unsafe {
let mut secs: u64 = 0;
let mut usecs: u64 = 0;
FlowGetLastTimeAsParts(self, &mut secs, &mut usecs);
std::time::Duration::new(secs, usecs as u32 * 1000)
}
/// Return the time of the last flow update as a `Duration`
/// since the epoch.
pub fn flow_get_last_time(flow: &Flow) -> std::time::Duration {
unsafe {
let mut secs: u64 = 0;
let mut usecs: u64 = 0;
FlowGetLastTimeAsParts(flow, &mut secs, &mut usecs);
std::time::Duration::new(secs, usecs as u32 * 1000)
}
}
/// Return the flow flags.
pub fn get_flags(&self) -> u32 {
unsafe { FlowGetFlags(self) }
}
/// Return the flow flags.
pub fn flow_get_flags(flow: &Flow) -> u32 {
unsafe { FlowGetFlags(flow) }
}
/// Return flow ports
pub fn get_ports(&self) -> (u16, u16) {
unsafe { (FlowGetSourcePort(self), FlowGetDestinationPort(self)) }
}
/// Return flow ports
pub fn flow_get_ports(flow: &Flow) -> (u16, u16) {
unsafe { (FlowGetSourcePort(flow), FlowGetDestinationPort(flow)) }
}

@ -33,7 +33,7 @@ use crate::direction::Direction;
use crate::direction::DIR_BOTH;
use crate::filecontainer::*;
use crate::filetracker::*;
use crate::flow::Flow;
use crate::flow::{Flow, flow_get_last_time};
use crate::frames::*;
use crate::nfs::nfs2_records::*;
@ -1946,7 +1946,7 @@ unsafe extern "C" fn nfs_parse_request(
}
SCLogDebug!("parsing {} bytes of request data", stream_slice.len());
state.update_ts(flow.get_last_time().as_secs());
state.update_ts(flow_get_last_time(flow).as_secs());
state.parse_tcp_data_ts(flow, &stream_slice)
}
@ -1966,7 +1966,7 @@ unsafe extern "C" fn nfs_parse_response(
}
SCLogDebug!("parsing {} bytes of response data", stream_slice.len());
state.update_ts(flow.get_last_time().as_secs());
state.update_ts(flow_get_last_time(flow).as_secs());
state.parse_tcp_data_tc(flow, &stream_slice)
}

@ -41,7 +41,7 @@ use crate::core::*;
use crate::applayer;
use crate::applayer::*;
use crate::direction::Direction;
use crate::flow::{Flow, FLOW_DIR_REVERSED};
use crate::flow::{Flow, FLOW_DIR_REVERSED, flow_get_flags, flow_get_last_time, flow_get_ports};
use crate::frames::*;
use crate::conf::*;
use crate::applayer::{AppLayerResult, AppLayerTxData, AppLayerEvent};
@ -2025,7 +2025,7 @@ unsafe extern "C" fn smb_parse_request_tcp(flow: *const Flow,
state.ts_gap = true;
}
state.update_ts(flow.get_last_time().as_secs());
state.update_ts(flow_get_last_time(flow).as_secs());
state.parse_tcp_data_ts(flow, &stream_slice)
}
@ -2058,7 +2058,7 @@ unsafe extern "C" fn smb_parse_response_tcp(flow: *const Flow,
state.tc_gap = true;
}
state.update_ts(flow.get_last_time().as_secs());
state.update_ts(flow_get_last_time(flow).as_secs());
state.parse_tcp_data_tc(flow, &stream_slice)
}
@ -2273,8 +2273,8 @@ unsafe extern "C" fn smb3_probe_tcp(f: *const Flow, dir: u8, input: *const u8, l
if retval != ALPROTO_SMB {
return retval;
}
let (sp, dp) = f.get_ports();
let flags = f.get_flags();
let (sp, dp) = flow_get_ports(f);
let flags = flow_get_flags(f);
let fsp = if (flags & FLOW_DIR_REVERSED) != 0 { dp } else { sp };
let fdp = if (flags & FLOW_DIR_REVERSED) != 0 { sp } else { dp };
if fsp == 445 && fdp != 445 {

Loading…
Cancel
Save