]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
nfs: support AppLayerTxData
authorVictor Julien <victor@inliniac.net>
Sun, 7 Jun 2020 12:26:56 +0000 (14:26 +0200)
committerVictor Julien <victor@inliniac.net>
Sat, 11 Jul 2020 06:37:40 +0000 (08:37 +0200)
rust/src/nfs/nfs.rs
src/app-layer-nfs-tcp.c
src/app-layer-nfs-udp.c

index 0ac14a7246f3de82ae1bd889cadcbac913de5050..9f06c7c02e84f7611f055fb16421d4042546427f 100644 (file)
@@ -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<NFSTransactionTypeData>,
 
-    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
index 23ecfea3df02cd14b7faa491c70ae99f825b53f0..0d753d554727bd73929bd671a157eedf26a1f1c8 100644 (file)
@@ -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,
index dab800711a60c0386894b3ad8418260d455c5c5a..a7a8bc224d04e1ea177ff75aa2889f98d0e02f36 100644 (file)
@@ -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.");