]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
bittorrent: no_mangle, pub and naming cleanups
authorJason Ish <jason.ish@oisf.net>
Thu, 27 Feb 2025 17:30:07 +0000 (11:30 -0600)
committerVictor Julien <victor@inliniac.net>
Fri, 28 Feb 2025 06:08:22 +0000 (07:08 +0100)
- Remove rs_prefix
- Remove no_mangle and pub when not needed

Related to ticket: #7498

rust/src/bittorrent_dht/bittorrent_dht.rs
rust/src/bittorrent_dht/logger.rs
src/app-layer-parser.c
src/output.c

index 3f447635dbbfb61820c489e8b8986bb7d08956b1..474405500fe5f49e542ee739347e4b06fe4b479b 100644 (file)
@@ -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,
index b4ec5af9f4a30ee7f32a976595ef68d657005427..19f895ff7f8736072f247588b322cd0c88d3fea1 100644 (file)
@@ -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);
index 6a8f66c5a0909dacef9bf11f0155e94d12809381..606a0cd83e29e273e3f7a71d4cc9a063f22b853d 100644 (file)
@@ -1738,7 +1738,7 @@ void AppLayerParserRegisterProtocolParsers(void)
     RegisterSMTPParsers();
     SCRegisterDnsUdpParser();
     SCRegisterDnsTcpParser();
-    rs_bittorrent_dht_udp_register_parser();
+    SCRegisterBittorrentDhtUdpParser();
     RegisterModbusParsers();
     SCEnipRegisterParsers();
     RegisterDNP3Parsers();
index 845b2644093f0bd4ef693bab03fd26054d9a12b8..7a9c86a267b7dbec8b4dd5eabccc089018e14315 100644 (file)
@@ -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();