From: Jason Ish Date: Wed, 10 Nov 2021 19:25:23 +0000 (-0600) Subject: ike: add tx iterator X-Git-Tag: suricata-7.0.0-beta1~1200 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6b2d7e16ab08be8e98df212e0e1b730f86c503a;p=thirdparty%2Fsuricata.git ike: add tx iterator For IKE the manual iterator functions were there, but never registered. So this commit does add a tx iterator to ike. --- diff --git a/rust/src/ike/ike.rs b/rust/src/ike/ike.rs index f445e81581..7453c401ca 100644 --- a/rust/src/ike/ike.rs +++ b/rust/src/ike/ike.rs @@ -110,6 +110,12 @@ pub struct IKETransaction { tx_data: applayer::AppLayerTxData, } +impl Transaction for IKETransaction { + fn id(&self) -> u64 { + self.tx_id + } +} + impl IKETransaction { pub fn new() -> IKETransaction { IKETransaction { @@ -157,6 +163,12 @@ pub struct IKEState { pub ikev2_container: Ikev2Container, } +impl State for IKEState { + fn get_transactions(&self) -> &[IKETransaction] { + &self.transactions + } +} + impl IKEState { // Free a transaction by ID. fn free_tx(&mut self, tx_id: u64) { @@ -234,26 +246,6 @@ impl IKEState { } } } - - fn tx_iterator( - &mut self, min_tx_id: u64, state: &mut u64, - ) -> Option<(&IKETransaction, u64, bool)> { - let mut index = *state as usize; - let len = self.transactions.len(); - - while index < len { - let tx = &self.transactions[index]; - if tx.tx_id < min_tx_id + 1 { - index += 1; - continue; - } - *state = index as u64; - - return Some((tx, tx.tx_id - 1, (len - index) > 1)); - } - - return None; - } } /// Probe to see if this input looks like a request or response. @@ -425,24 +417,6 @@ pub unsafe extern "C" fn rs_ike_state_get_events( static mut ALPROTO_IKE : AppProto = ALPROTO_UNKNOWN; -#[no_mangle] -pub unsafe extern "C" fn rs_ike_state_get_tx_iterator( - _ipproto: u8, _alproto: AppProto, state: *mut std::os::raw::c_void, min_tx_id: u64, - _max_tx_id: u64, istate: &mut u64, -) -> applayer::AppLayerGetTxIterTuple { - let state = cast_pointer!(state, IKEState); - match state.tx_iterator(min_tx_id, istate) { - Some((tx, out_tx_id, has_next)) => { - let c_tx = tx as *const _ as *mut _; - let ires = applayer::AppLayerGetTxIterTuple::with_values(c_tx, out_tx_id, has_next); - return ires; - } - None => { - return applayer::AppLayerGetTxIterTuple::not_found(); - } - } -} - // Parser name as a C style string. const PARSER_NAME: &'static [u8] = b"ike\0"; const PARSER_ALIAS: &'static [u8] = b"ikev2\0"; @@ -478,7 +452,7 @@ pub unsafe extern "C" fn rs_ike_register_parser() { localstorage_new : None, localstorage_free : None, get_files : None, - get_tx_iterator : None, + get_tx_iterator : Some(applayer::state_get_tx_iterator::), get_tx_data : rs_ike_get_tx_data, apply_tx_config : None, flags : APP_LAYER_PARSER_OPT_UNIDIR_TXS,