tftp: support AppLayerTxData

pull/5169/head
Victor Julien 5 years ago
parent 4ff51a0e07
commit e0debed0b4

@ -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;
}

@ -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.");

Loading…
Cancel
Save