From 9b830c92dc09ad875b8703b3ca18bac40cb79e9b Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Fri, 2 May 2025 11:38:26 -0600 Subject: [PATCH] rust/tftp: replace rs_ naming with SC --- rust/src/tftp/log.rs | 2 +- rust/src/tftp/tftp.rs | 16 ++++++++-------- src/app-layer-tftp.c | 17 ++++++++--------- src/output.c | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/rust/src/tftp/log.rs b/rust/src/tftp/log.rs index da04521e7f..33c05de6c8 100644 --- a/rust/src/tftp/log.rs +++ b/rust/src/tftp/log.rs @@ -34,6 +34,6 @@ fn tftp_log_request(tx: &TFTPTransaction, jb: &mut JsonBuilder) -> Result<(), Js } #[no_mangle] -pub extern "C" fn rs_tftp_log_json_request(tx: &TFTPTransaction, jb: &mut JsonBuilder) -> bool { +pub extern "C" fn SCTftpLogJsonRequest(tx: &TFTPTransaction, jb: &mut JsonBuilder) -> bool { tftp_log_request(tx, jb).is_ok() } diff --git a/rust/src/tftp/tftp.rs b/rust/src/tftp/tftp.rs index 8797e4ea13..6d77d0c6a0 100644 --- a/rust/src/tftp/tftp.rs +++ b/rust/src/tftp/tftp.rs @@ -87,25 +87,25 @@ impl TFTPTransaction { } #[no_mangle] -pub extern "C" fn rs_tftp_state_alloc() -> *mut std::os::raw::c_void { +pub extern "C" fn SCTftpStateAlloc() -> *mut std::os::raw::c_void { let state = TFTPState { state_data: AppLayerStateData::new(), transactions : Vec::new(), tx_id: 0, }; let boxed = Box::new(state); return Box::into_raw(boxed) as *mut _; } #[no_mangle] -pub extern "C" fn rs_tftp_state_free(state: *mut std::os::raw::c_void) { +pub extern "C" fn SCTftpStateFree(state: *mut std::os::raw::c_void) { std::mem::drop(unsafe { Box::from_raw(state as *mut TFTPState) }); } #[no_mangle] -pub extern "C" fn rs_tftp_state_tx_free(state: &mut TFTPState, +pub extern "C" fn SCTftpStateTxFree(state: &mut TFTPState, tx_id: u64) { state.free_tx(tx_id); } #[no_mangle] -pub extern "C" fn rs_tftp_get_tx(state: &mut TFTPState, +pub extern "C" fn SCTftpGetTx(state: &mut TFTPState, tx_id: u64) -> *mut std::os::raw::c_void { match state.get_tx_by_id(tx_id) { Some(tx) => tx as *const _ as *mut _, @@ -114,7 +114,7 @@ pub extern "C" fn rs_tftp_get_tx(state: &mut TFTPState, } #[no_mangle] -pub extern "C" fn rs_tftp_get_tx_cnt(state: &mut TFTPState) -> u64 { +pub extern "C" fn SCTftpGetTxCnt(state: &mut TFTPState) -> u64 { return state.tx_id; } @@ -155,7 +155,7 @@ fn parse_tftp_request(input: &[u8]) -> Option { } #[no_mangle] -pub unsafe extern "C" fn rs_tftp_request(state: &mut TFTPState, +pub unsafe extern "C" fn SCTftpParseRequest(state: &mut TFTPState, input: *const u8, len: u32) -> i64 { let buf = std::slice::from_raw_parts(input, len as usize); @@ -173,7 +173,7 @@ pub unsafe extern "C" fn rs_tftp_request(state: &mut TFTPState, } #[no_mangle] -pub unsafe extern "C" fn rs_tftp_get_tx_data( +pub unsafe extern "C" fn SCTftpGetTxData( tx: *mut std::os::raw::c_void) -> *mut AppLayerTxData { @@ -182,7 +182,7 @@ pub unsafe extern "C" fn rs_tftp_get_tx_data( } #[no_mangle] -pub unsafe extern "C" fn rs_tftp_get_state_data( +pub unsafe extern "C" fn SCTftpGetStateData( state: *mut std::os::raw::c_void) -> *mut AppLayerStateData { diff --git a/src/app-layer-tftp.c b/src/app-layer-tftp.c index 4a9b41176a..7a95fe8aad 100644 --- a/src/app-layer-tftp.c +++ b/src/app-layer-tftp.c @@ -43,12 +43,12 @@ static void *TFTPStateAlloc(void *orig_state, AppProto proto_orig) { - return rs_tftp_state_alloc(); + return SCTftpStateAlloc(); } static void TFTPStateFree(void *state) { - rs_tftp_state_free(state); + SCTftpStateFree(state); } /** @@ -59,7 +59,7 @@ static void TFTPStateFree(void *state) */ static void TFTPStateTxFree(void *state, uint64_t tx_id) { - rs_tftp_state_tx_free(state, tx_id); + SCTftpStateTxFree(state, tx_id); } static int TFTPStateGetEventInfo( @@ -108,7 +108,7 @@ static AppLayerResult TFTPParseRequest(Flow *f, void *state, AppLayerParserState SCReturnStruct(APP_LAYER_OK); } - int64_t res = rs_tftp_request(state, input, input_len); + int64_t res = SCTftpParseRequest(state, input, input_len); if (res < 0) { SCReturnStruct(APP_LAYER_ERROR); } @@ -126,12 +126,12 @@ static AppLayerResult TFTPParseResponse(Flow *f, void *state, AppLayerParserStat static uint64_t TFTPGetTxCnt(void *state) { - return rs_tftp_get_tx_cnt(state); + return SCTftpGetTxCnt(state); } static void *TFTPGetTx(void *state, uint64_t tx_id) { - return rs_tftp_get_tx(state, tx_id); + return SCTftpGetTx(state, tx_id); } /** @@ -228,9 +228,8 @@ void RegisterTFTPParsers(void) AppLayerParserRegisterGetEventInfo(IPPROTO_UDP, ALPROTO_TFTP, TFTPStateGetEventInfo); - AppLayerParserRegisterTxDataFunc(IPPROTO_UDP, ALPROTO_TFTP, - rs_tftp_get_tx_data); - AppLayerParserRegisterStateDataFunc(IPPROTO_UDP, ALPROTO_TFTP, rs_tftp_get_state_data); + AppLayerParserRegisterTxDataFunc(IPPROTO_UDP, ALPROTO_TFTP, SCTftpGetTxData); + AppLayerParserRegisterStateDataFunc(IPPROTO_UDP, ALPROTO_TFTP, SCTftpGetStateData); } else { SCLogDebug("TFTP protocol parsing disabled."); diff --git a/src/output.c b/src/output.c index af591ee531..d9858b8fe5 100644 --- a/src/output.c +++ b/src/output.c @@ -910,7 +910,7 @@ void OutputRegisterRootLoggers(void) RegisterSimpleJsonApplayerLogger( ALPROTO_FTPDATA, (EveJsonSimpleTxLogFunc)EveFTPDataAddMetadata, "ftp_data"); RegisterSimpleJsonApplayerLogger( - ALPROTO_TFTP, (EveJsonSimpleTxLogFunc)rs_tftp_log_json_request, NULL); + ALPROTO_TFTP, (EveJsonSimpleTxLogFunc)SCTftpLogJsonRequest, NULL); // ALPROTO_IKE special: uses state RegisterSimpleJsonApplayerLogger( ALPROTO_KRB5, (EveJsonSimpleTxLogFunc)SCKrb5LogJsonResponse, NULL);