From: Jason Ish Date: Thu, 27 Feb 2025 17:30:07 +0000 (-0600) Subject: bittorrent: no_mangle, pub and naming cleanups X-Git-Tag: suricata-8.0.0-beta1~342 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0116c3a6bd6ade59c3ecb6611d63b629349f3e1;p=thirdparty%2Fsuricata.git bittorrent: no_mangle, pub and naming cleanups - Remove rs_prefix - Remove no_mangle and pub when not needed Related to ticket: #7498 --- diff --git a/rust/src/bittorrent_dht/bittorrent_dht.rs b/rust/src/bittorrent_dht/bittorrent_dht.rs index 3f447635db..474405500f 100644 --- a/rust/src/bittorrent_dht/bittorrent_dht.rs +++ b/rust/src/bittorrent_dht/bittorrent_dht.rs @@ -142,11 +142,10 @@ impl BitTorrentDHTState { // C exports. -export_tx_data_get!(bittorrent_dht_get_tx_data, BitTorrentDHTTransaction); -export_state_data_get!(bittorrent_dht_get_state_data, BitTorrentDHTState); +export_tx_data_get!(get_tx_data, BitTorrentDHTTransaction); +export_state_data_get!(get_state_data, BitTorrentDHTState); -#[no_mangle] -pub extern "C" fn rs_bittorrent_dht_state_new( +extern "C" fn state_new( _orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto, ) -> *mut std::os::raw::c_void { let state = BitTorrentDHTState::new(); @@ -154,41 +153,36 @@ pub extern "C" fn rs_bittorrent_dht_state_new( return Box::into_raw(boxed) as *mut std::os::raw::c_void; } -#[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_state_free(state: *mut std::os::raw::c_void) { +unsafe extern "C" fn state_free(state: *mut std::os::raw::c_void) { std::mem::drop(Box::from_raw(state as *mut BitTorrentDHTState)); } -#[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_state_tx_free( +unsafe extern "C" fn state_tx_free( state: *mut std::os::raw::c_void, tx_id: u64, ) { let state = cast_pointer!(state, BitTorrentDHTState); state.free_tx(tx_id); } -#[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_parse_ts( +unsafe extern "C" fn parse_ts( _flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void, stream_slice: StreamSlice, _data: *const std::os::raw::c_void, ) -> AppLayerResult { - return rs_bittorrent_dht_parse( + return parse( _flow, state, _pstate, stream_slice, _data, Direction::ToServer); } -#[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_parse_tc( +unsafe extern "C" fn parse_tc( _flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void, stream_slice: StreamSlice, _data: *const std::os::raw::c_void, ) -> AppLayerResult { - return rs_bittorrent_dht_parse( + return parse( _flow, state, _pstate, stream_slice, _data, Direction::ToClient); } -#[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_parse( +unsafe extern "C" fn parse( _flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void, stream_slice: StreamSlice, _data: *const std::os::raw::c_void, direction: Direction, @@ -198,8 +192,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_parse( state.parse(buf, direction).into() } -#[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx( +unsafe extern "C" fn state_get_tx( state: *mut std::os::raw::c_void, tx_id: u64, ) -> *mut std::os::raw::c_void { let state = cast_pointer!(state, BitTorrentDHTState); @@ -213,16 +206,14 @@ pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx( } } -#[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx_count( +unsafe extern "C" fn state_get_tx_count( state: *mut std::os::raw::c_void, ) -> u64 { let state = cast_pointer!(state, BitTorrentDHTState); return state.tx_id; } -#[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_tx_get_alstate_progress( +unsafe extern "C" fn tx_get_alstate_progress( tx: *mut std::os::raw::c_void, _direction: u8, ) -> std::os::raw::c_int { let tx = cast_pointer!(tx, BitTorrentDHTTransaction); @@ -235,8 +226,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_tx_get_alstate_progress( return 0; } -#[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx_iterator( +unsafe extern "C" fn state_get_tx_iterator( _ipproto: u8, _alproto: AppProto, state: *mut std::os::raw::c_void, min_tx_id: u64, _max_tx_id: u64, istate: &mut u64, ) -> applayer::AppLayerGetTxIterTuple { @@ -257,7 +247,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx_iterator( const PARSER_NAME: &[u8] = b"bittorrent-dht\0"; #[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() { +pub unsafe extern "C" fn SCRegisterBittorrentDhtUdpParser() { let parser = RustParser { name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char, default_port: std::ptr::null(), @@ -266,24 +256,24 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() { probe_tc: None, min_depth: 0, max_depth: 16, - state_new: rs_bittorrent_dht_state_new, - state_free: rs_bittorrent_dht_state_free, - tx_free: rs_bittorrent_dht_state_tx_free, - parse_ts: rs_bittorrent_dht_parse_ts, - parse_tc: rs_bittorrent_dht_parse_tc, - get_tx_count: rs_bittorrent_dht_state_get_tx_count, - get_tx: rs_bittorrent_dht_state_get_tx, + state_new, + state_free, + tx_free: state_tx_free, + parse_ts, + parse_tc, + get_tx_count: state_get_tx_count, + get_tx: state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_bittorrent_dht_tx_get_alstate_progress, + tx_get_progress: tx_get_alstate_progress, get_eventinfo: Some(BitTorrentDHTEvent::get_event_info), get_eventinfo_byid: Some(BitTorrentDHTEvent::get_event_info_by_id), localstorage_new: None, localstorage_free: None, get_tx_files: None, - get_tx_iterator: Some(rs_bittorrent_dht_state_get_tx_iterator), - get_tx_data: bittorrent_dht_get_tx_data, - get_state_data: bittorrent_dht_get_state_data, + get_tx_iterator: Some(state_get_tx_iterator), + get_tx_data, + get_state_data, apply_tx_config: None, flags: 0, get_frame_id_by_name: None, diff --git a/rust/src/bittorrent_dht/logger.rs b/rust/src/bittorrent_dht/logger.rs index b4ec5af9f4..19f895ff7f 100644 --- a/rust/src/bittorrent_dht/logger.rs +++ b/rust/src/bittorrent_dht/logger.rs @@ -131,7 +131,7 @@ fn log_bittorrent_dht( } #[no_mangle] -pub unsafe extern "C" fn rs_bittorrent_dht_logger_log( +pub unsafe extern "C" fn SCBittorrentDhtLogger( tx: *mut std::os::raw::c_void, js: &mut JsonBuilder, ) -> bool { let tx = cast_pointer!(tx, BitTorrentDHTTransaction); diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 6a8f66c5a0..606a0cd83e 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -1738,7 +1738,7 @@ void AppLayerParserRegisterProtocolParsers(void) RegisterSMTPParsers(); SCRegisterDnsUdpParser(); SCRegisterDnsTcpParser(); - rs_bittorrent_dht_udp_register_parser(); + SCRegisterBittorrentDhtUdpParser(); RegisterModbusParsers(); SCEnipRegisterParsers(); RegisterDNP3Parsers(); diff --git a/src/output.c b/src/output.c index 845b264409..7a9c86a267 100644 --- a/src/output.c +++ b/src/output.c @@ -918,7 +918,7 @@ void OutputRegisterRootLoggers(void) RegisterSimpleJsonApplayerLogger(ALPROTO_HTTP2, rs_http2_log_json, "http"); // underscore instead of dash for bittorrent_dht RegisterSimpleJsonApplayerLogger( - ALPROTO_BITTORRENT_DHT, rs_bittorrent_dht_logger_log, "bittorrent_dht"); + ALPROTO_BITTORRENT_DHT, SCBittorrentDhtLogger, "bittorrent_dht"); OutputPacketLoggerRegister(); OutputFiledataLoggerRegister();