]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
tftp: support AppLayerTxData
authorVictor Julien <victor@inliniac.net>
Sun, 7 Jun 2020 18:38:44 +0000 (20:38 +0200)
committerVictor Julien <victor@inliniac.net>
Sat, 11 Jul 2020 06:37:40 +0000 (08:37 +0200)
rust/src/tftp/tftp.rs
src/app-layer-tftp.c

index ecc5f7adb694c43dc6b5dca75d96a132a7198db1..53c7fd67c02425baa161aff133da4ad46b91a267 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2017-2019 Open Information Security Foundation
+/* Copyright (C) 2017-2020 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -23,15 +23,15 @@ use std::str;
 use std;
 use std::mem::transmute;
 
-use crate::applayer::LoggerFlags;
+use crate::applayer::AppLayerTxData;
 
 #[derive(Debug)]
 pub struct TFTPTransaction {
     pub opcode : u8,
     pub filename : String,
     pub mode : String,
-    pub logged : LoggerFlags,
     id: u64,
+    tx_data: AppLayerTxData,
 }
 
 pub struct TFTPState {
@@ -60,8 +60,8 @@ impl TFTPTransaction {
             opcode : opcode,
             filename : filename,
             mode : mode.to_lowercase(),
-            logged : LoggerFlags::new(),
             id : 0,
+            tx_data: AppLayerTxData::new(),
         }
     }
     pub fn is_mode_ok(&self) -> bool {
@@ -99,20 +99,6 @@ pub extern "C" fn rs_tftp_get_tx(state: &mut TFTPState,
     }
 }
 
-#[no_mangle]
-pub extern "C" fn rs_tftp_get_tx_logged(_state: &mut TFTPState,
-                                        tx: &mut TFTPTransaction)
-                                        -> u32 {
-    return tx.logged.get();
-}
-
-#[no_mangle]
-pub extern "C" fn rs_tftp_set_tx_logged(_state: &mut TFTPState,
-                                        tx: &mut TFTPTransaction,
-                                        logged: u32) {
-    tx.logged.set(logged);
-}
-
 #[no_mangle]
 pub extern "C" fn rs_tftp_get_tx_cnt(state: &mut TFTPState) -> u64 {
     return state.tx_id as u64;
@@ -153,3 +139,12 @@ pub extern "C" fn rs_tftp_request(state: &mut TFTPState,
         _ => 0
     }
 }
+
+#[no_mangle]
+pub extern "C" fn rs_tftp_get_tx_data(
+    tx: *mut std::os::raw::c_void)
+    -> *mut AppLayerTxData
+{
+    let tx = cast_pointer!(tx, TFTPTransaction);
+    return &mut tx.tx_data;
+}
index c22163a5a643756a3e22eeef0cc6c20d6b6fec60..821f91bc7ca94b07804f7825f25bca7ccc6edea3 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2017 Open Information Security Foundation
+/* Copyright (C) 2017-2020 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -141,16 +141,6 @@ static void *TFTPGetTx(void *state, uint64_t tx_id)
     return rs_tftp_get_tx(state, tx_id);
 }
 
-static void TFTPSetTxLogged(void *state, void *vtx, uint32_t logger)
-{
-    rs_tftp_set_tx_logged(state, vtx, logger);
-}
-
-static LoggerId TFTPGetTxLogged(void *state, void *vtx)
-{
-    return rs_tftp_get_tx_logged(state, vtx);
-}
-
 /**
  * \brief Called by the application layer.
  *
@@ -249,9 +239,6 @@ void RegisterTFTPParsers(void)
         AppLayerParserRegisterTxFreeFunc(IPPROTO_UDP, ALPROTO_TFTP,
                                          TFTPStateTxFree);
 
-        AppLayerParserRegisterLoggerFuncs(IPPROTO_UDP, ALPROTO_TFTP,
-                                          TFTPGetTxLogged, TFTPSetTxLogged);
-
         /* Register a function to return the current transaction count. */
         AppLayerParserRegisterGetTxCnt(IPPROTO_UDP, ALPROTO_TFTP,
                                        TFTPGetTxCnt);
@@ -274,6 +261,9 @@ void RegisterTFTPParsers(void)
                                            TFTPStateGetEventInfo);
         AppLayerParserRegisterGetEventsFunc(IPPROTO_UDP, ALPROTO_TFTP,
                                             TFTPGetEvents);
+
+        AppLayerParserRegisterTxDataFunc(IPPROTO_UDP, ALPROTO_TFTP,
+                                         rs_tftp_get_tx_data);
     }
     else {
         SCLogDebug("TFTP protocol parsing disabled.");