From 7a7805cde6d4fc9fe49a8a097a7a0cc397eb54dd Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sun, 7 Jun 2020 14:26:56 +0200 Subject: [PATCH] nfs: support AppLayerTxData --- rust/src/nfs/nfs.rs | 55 +++++++---------------------------------- src/app-layer-nfs-tcp.c | 27 ++------------------ src/app-layer-nfs-udp.c | 28 ++------------------- 3 files changed, 13 insertions(+), 97 deletions(-) diff --git a/rust/src/nfs/nfs.rs b/rust/src/nfs/nfs.rs index 0ac14a7246..9f06c7c02e 100644 --- a/rust/src/nfs/nfs.rs +++ b/rust/src/nfs/nfs.rs @@ -27,7 +27,7 @@ use nom; use crate::log::*; use crate::applayer; -use crate::applayer::{LoggerFlags, AppLayerResult}; +use crate::applayer::{AppLayerResult, AppLayerTxData}; use crate::core::*; use crate::filetracker::*; use crate::filecontainer::*; @@ -179,12 +179,10 @@ pub struct NFSTransaction { /// attempt failed. pub type_data: Option, - detect_flags_ts: u64, - detect_flags_tc: u64, - - pub logged: LoggerFlags, pub de_state: Option<*mut DetectEngineState>, pub events: *mut AppLayerDecoderEvents, + + pub tx_data: AppLayerTxData, } impl NFSTransaction { @@ -209,11 +207,9 @@ impl NFSTransaction { file_tx_direction: 0, file_handle:Vec::new(), type_data: None, - detect_flags_ts: 0, - detect_flags_tc: 0, - logged: LoggerFlags::new(), de_state: None, events: std::ptr::null_mut(), + tx_data: AppLayerTxData::new(), } } @@ -1572,19 +1568,12 @@ pub extern "C" fn rs_nfs_tx_get_alstate_progress(tx: &mut NFSTransaction, } #[no_mangle] -pub extern "C" fn rs_nfs_tx_set_logged(_state: &mut NFSState, - tx: &mut NFSTransaction, - logged: u32) -{ - tx.logged.set(logged); -} - -#[no_mangle] -pub extern "C" fn rs_nfs_tx_get_logged(_state: &mut NFSState, - tx: &mut NFSTransaction) - -> u32 +pub extern "C" fn rs_nfs_get_tx_data( + tx: *mut std::os::raw::c_void) + -> *mut AppLayerTxData { - return tx.logged.get(); + let tx = cast_pointer!(tx, NFSTransaction); + return &mut tx.tx_data; } #[no_mangle] @@ -1612,32 +1601,6 @@ pub extern "C" fn rs_nfs_state_get_tx_detect_state( } } -#[no_mangle] -pub extern "C" fn rs_nfs_tx_set_detect_flags( - tx: &mut NFSTransaction, - direction: u8, - flags: u64) -{ - if (direction & STREAM_TOSERVER) != 0 { - tx.detect_flags_ts = flags as u64; - } else { - tx.detect_flags_tc = flags as u64; - } -} - -#[no_mangle] -pub extern "C" fn rs_nfs_tx_get_detect_flags( - tx: &mut NFSTransaction, - direction: u8) - -> u64 -{ - if (direction & STREAM_TOSERVER) != 0 { - return tx.detect_flags_ts as u64; - } else { - return tx.detect_flags_tc as u64; - } -} - #[no_mangle] pub extern "C" fn rs_nfs_state_get_events(tx: *mut std::os::raw::c_void) -> *mut AppLayerDecoderEvents diff --git a/src/app-layer-nfs-tcp.c b/src/app-layer-nfs-tcp.c index 23ecfea3df..0d753d5547 100644 --- a/src/app-layer-nfs-tcp.c +++ b/src/app-layer-nfs-tcp.c @@ -208,16 +208,6 @@ static AppLayerGetTxIterTuple RustNFSTCPGetTxIterator( return rs_nfs_state_get_tx_iterator(alstate, min_tx_id, (uint64_t *)istate); } -static void NFSTCPSetTxLogged(void *state, void *vtx, LoggerId logged) -{ - rs_nfs_tx_set_logged(state, vtx, logged); -} - -static LoggerId NFSTCPGetTxLogged(void *state, void *vtx) -{ - return rs_nfs_tx_get_logged(state, vtx); -} - /** * \brief Called by the application layer. * @@ -267,16 +257,6 @@ static FileContainer *NFSTCPGetFiles(void *state, uint8_t direction) return rs_nfs_getfiles(direction, state); } -static void NFSTCPSetDetectFlags(void *tx, uint8_t dir, uint64_t flags) -{ - rs_nfs_tx_set_detect_flags(tx, dir, flags); -} - -static uint64_t NFSTCPGetDetectFlags(void *tx, uint8_t dir) -{ - return rs_nfs_tx_get_detect_flags(tx, dir); -} - static StreamingBufferConfig sbcfg = STREAMING_BUFFER_CONFIG_INITIALIZER; static SuricataFileContext sfc = { &sbcfg }; @@ -353,9 +333,6 @@ void RegisterNFSTCPParsers(void) AppLayerParserRegisterTxFreeFunc(IPPROTO_TCP, ALPROTO_NFS, NFSTCPStateTxFree); - AppLayerParserRegisterLoggerFuncs(IPPROTO_TCP, ALPROTO_NFS, - NFSTCPGetTxLogged, NFSTCPSetTxLogged); - /* Register a function to return the current transaction count. */ AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_NFS, NFSTCPGetTxCnt); @@ -385,8 +362,8 @@ void RegisterNFSTCPParsers(void) AppLayerParserRegisterGetEventsFunc(IPPROTO_TCP, ALPROTO_NFS, NFSTCPGetEvents); - AppLayerParserRegisterDetectFlagsFuncs(IPPROTO_TCP, ALPROTO_NFS, - NFSTCPGetDetectFlags, NFSTCPSetDetectFlags); + AppLayerParserRegisterTxDataFunc(IPPROTO_TCP, ALPROTO_NFS, + rs_nfs_get_tx_data); /* This parser accepts gaps. */ AppLayerParserRegisterOptionFlags(IPPROTO_TCP, ALPROTO_NFS, diff --git a/src/app-layer-nfs-udp.c b/src/app-layer-nfs-udp.c index dab800711a..a7a8bc224d 100644 --- a/src/app-layer-nfs-udp.c +++ b/src/app-layer-nfs-udp.c @@ -178,16 +178,6 @@ static AppLayerGetTxIterTuple RustNFSGetTxIterator( return rs_nfs_state_get_tx_iterator(alstate, min_tx_id, (uint64_t *)istate); } -static void NFSSetTxLogged(void *state, void *vtx, LoggerId logged) -{ - rs_nfs_tx_set_logged(state, vtx, logged); -} - -static LoggerId NFSGetTxLogged(void *state, void *vtx) -{ - return rs_nfs_tx_get_logged(state, vtx); -} - /** * \brief Called by the application layer. * @@ -237,16 +227,6 @@ static FileContainer *NFSGetFiles(void *state, uint8_t direction) return rs_nfs_getfiles(direction, state); } -static void NFSSetDetectFlags(void *tx, uint8_t dir, uint64_t flags) -{ - rs_nfs_tx_set_detect_flags(tx, dir, flags); -} - -static uint64_t NFSGetDetectFlags(void *tx, uint8_t dir) -{ - return rs_nfs_tx_get_detect_flags(tx, dir); -} - static StreamingBufferConfig sbcfg = STREAMING_BUFFER_CONFIG_INITIALIZER; static SuricataFileContext sfc = { &sbcfg }; @@ -317,9 +297,6 @@ void RegisterNFSUDPParsers(void) AppLayerParserRegisterTxFreeFunc(IPPROTO_UDP, ALPROTO_NFS, NFSStateTxFree); - AppLayerParserRegisterLoggerFuncs(IPPROTO_UDP, ALPROTO_NFS, - NFSGetTxLogged, NFSSetTxLogged); - /* Register a function to return the current transaction count. */ AppLayerParserRegisterGetTxCnt(IPPROTO_UDP, ALPROTO_NFS, NFSGetTxCnt); @@ -349,9 +326,8 @@ void RegisterNFSUDPParsers(void) AppLayerParserRegisterGetEventsFunc(IPPROTO_UDP, ALPROTO_NFS, NFSGetEvents); - AppLayerParserRegisterDetectFlagsFuncs(IPPROTO_UDP, ALPROTO_NFS, - NFSGetDetectFlags, NFSSetDetectFlags); - + AppLayerParserRegisterTxDataFunc(IPPROTO_UDP, ALPROTO_NFS, + rs_nfs_get_tx_data); } else { SCLogNotice("NFS protocol parsing disabled."); -- 2.47.2