From: Jason Ish Date: Mon, 31 Mar 2025 15:50:33 +0000 (-0600) Subject: snmp: rust naming and visibility cleanups X-Git-Tag: suricata-8.0.0-beta1~164 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27fd2fe74be47dda3013bbf906384ca01a52ba97;p=thirdparty%2Fsuricata.git snmp: rust naming and visibility cleanups Ticket: #7498 --- diff --git a/rust/src/snmp/log.rs b/rust/src/snmp/log.rs index 5707f30ccb..8320b46a50 100644 --- a/rust/src/snmp/log.rs +++ b/rust/src/snmp/log.rs @@ -77,7 +77,7 @@ fn snmp_log_response(jsb: &mut JsonBuilder, tx: &mut SNMPTransaction) -> Result< } #[no_mangle] -pub extern "C" fn rs_snmp_log_json_response(tx: &mut SNMPTransaction, jsb: &mut JsonBuilder) -> bool +pub extern "C" fn SCSnmpLogJsonResponse(tx: &mut SNMPTransaction, jsb: &mut JsonBuilder) -> bool { snmp_log_response(jsb, tx).is_ok() } diff --git a/rust/src/snmp/snmp.rs b/rust/src/snmp/snmp.rs index aa4b0b3f60..caf1c6620c 100644 --- a/rust/src/snmp/snmp.rs +++ b/rust/src/snmp/snmp.rs @@ -252,8 +252,7 @@ impl<'a> SNMPTransaction<'a> { } /// Returns *mut SNMPState -#[no_mangle] -pub extern "C" fn rs_snmp_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void { +extern "C" fn snmp_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void { let state = SNMPState::new(); let boxed = Box::new(state); return Box::into_raw(boxed) as *mut _; @@ -261,14 +260,12 @@ pub extern "C" fn rs_snmp_state_new(_orig_state: *mut std::os::raw::c_void, _ori /// Params: /// - state: *mut SNMPState as void pointer -#[no_mangle] -pub extern "C" fn rs_snmp_state_free(state: *mut std::os::raw::c_void) { +extern "C" fn snmp_state_free(state: *mut std::os::raw::c_void) { let mut snmp_state = unsafe{ Box::from_raw(state as *mut SNMPState) }; snmp_state.free(); } -#[no_mangle] -pub unsafe extern "C" fn rs_snmp_parse_request(_flow: *const Flow, +unsafe extern "C" fn snmp_parse_request(_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void, stream_slice: StreamSlice, @@ -278,8 +275,7 @@ pub unsafe extern "C" fn rs_snmp_parse_request(_flow: *const Flow, state.parse(stream_slice.as_slice(), Direction::ToServer).into() } -#[no_mangle] -pub unsafe extern "C" fn rs_snmp_parse_response(_flow: *const Flow, +unsafe extern "C" fn snmp_parse_response(_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void, stream_slice: StreamSlice, @@ -289,8 +285,7 @@ pub unsafe extern "C" fn rs_snmp_parse_response(_flow: *const Flow, state.parse(stream_slice.as_slice(), Direction::ToClient).into() } -#[no_mangle] -pub unsafe extern "C" fn rs_snmp_state_get_tx(state: *mut std::os::raw::c_void, +unsafe extern "C" fn snmp_state_get_tx(state: *mut std::os::raw::c_void, tx_id: u64) -> *mut std::os::raw::c_void { @@ -301,24 +296,21 @@ pub unsafe extern "C" fn rs_snmp_state_get_tx(state: *mut std::os::raw::c_void, } } -#[no_mangle] -pub unsafe extern "C" fn rs_snmp_state_get_tx_count(state: *mut std::os::raw::c_void) +unsafe extern "C" fn snmp_state_get_tx_count(state: *mut std::os::raw::c_void) -> u64 { let state = cast_pointer!(state,SNMPState); state.tx_id } -#[no_mangle] -pub unsafe extern "C" fn rs_snmp_state_tx_free(state: *mut std::os::raw::c_void, +unsafe extern "C" fn snmp_state_tx_free(state: *mut std::os::raw::c_void, tx_id: u64) { let state = cast_pointer!(state,SNMPState); state.free_tx(tx_id); } -#[no_mangle] -pub extern "C" fn rs_snmp_tx_get_alstate_progress(_tx: *mut std::os::raw::c_void, +extern "C" fn snmp_tx_get_alstate_progress(_tx: *mut std::os::raw::c_void, _direction: u8) -> std::os::raw::c_int { @@ -354,8 +346,7 @@ fn parse_pdu_envelope_version(i:&[u8]) -> IResult<&[u8],u32> { } } -#[no_mangle] -pub unsafe extern "C" fn rs_snmp_probing_parser(_flow: *const Flow, +unsafe extern "C" fn snmp_probing_parser(_flow: *const Flow, _direction: u8, input:*const u8, input_len: u32, @@ -379,26 +370,26 @@ export_state_data_get!(snmp_get_state_data, SNMPState); const PARSER_NAME : &[u8] = b"snmp\0"; #[no_mangle] -pub unsafe extern "C" fn rs_register_snmp_parser() { +pub unsafe extern "C" fn SCRegisterSnmpParser() { let default_port = CString::new("161").unwrap(); let mut parser = RustParser { name : PARSER_NAME.as_ptr() as *const std::os::raw::c_char, default_port : default_port.as_ptr(), ipproto : core::IPPROTO_UDP, - probe_ts : Some(rs_snmp_probing_parser), - probe_tc : Some(rs_snmp_probing_parser), + probe_ts : Some(snmp_probing_parser), + probe_tc : Some(snmp_probing_parser), min_depth : 0, max_depth : 16, - state_new : rs_snmp_state_new, - state_free : rs_snmp_state_free, - tx_free : rs_snmp_state_tx_free, - parse_ts : rs_snmp_parse_request, - parse_tc : rs_snmp_parse_response, - get_tx_count : rs_snmp_state_get_tx_count, - get_tx : rs_snmp_state_get_tx, + state_new : snmp_state_new, + state_free : snmp_state_free, + tx_free : snmp_state_tx_free, + parse_ts : snmp_parse_request, + parse_tc : snmp_parse_response, + get_tx_count : snmp_state_get_tx_count, + get_tx : snmp_state_get_tx, tx_comp_st_ts : 1, tx_comp_st_tc : 1, - tx_get_progress : rs_snmp_tx_get_alstate_progress, + tx_get_progress : snmp_tx_get_alstate_progress, get_eventinfo : Some(SNMPEvent::get_event_info), get_eventinfo_byid : Some(SNMPEvent::get_event_info_by_id), localstorage_new : None, diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 1461df83d6..917c5d0f70 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -1745,7 +1745,7 @@ void AppLayerParserRegisterProtocolParsers(void) RegisterIKEParsers(); rs_register_krb5_parser(); SCRegisterDhcpParser(); - rs_register_snmp_parser(); + SCRegisterSnmpParser(); rs_sip_register_parser(); rs_quic_register_parser(); rs_websocket_register_parser(); diff --git a/src/output.c b/src/output.c index 527ddda59a..8fbb9265f5 100644 --- a/src/output.c +++ b/src/output.c @@ -904,7 +904,7 @@ void OutputRegisterRootLoggers(void) RegisterSimpleJsonApplayerLogger(ALPROTO_QUIC, rs_quic_to_json, NULL); // ALPROTO_DHCP TODO missing RegisterSimpleJsonApplayerLogger( - ALPROTO_SNMP, (EveJsonSimpleTxLogFunc)rs_snmp_log_json_response, NULL); + ALPROTO_SNMP, (EveJsonSimpleTxLogFunc)SCSnmpLogJsonResponse, NULL); RegisterSimpleJsonApplayerLogger(ALPROTO_SIP, (EveJsonSimpleTxLogFunc)rs_sip_log_json, NULL); RegisterSimpleJsonApplayerLogger(ALPROTO_RFB, rs_rfb_logger_log, NULL); RegisterSimpleJsonApplayerLogger(ALPROTO_MQTT, JsonMQTTAddMetadata, NULL);