From: Philippe Antoine Date: Thu, 16 Jan 2025 07:58:44 +0000 (+0100) Subject: snmp: make log function use the generic prototype X-Git-Tag: suricata-8.0.0-beta1~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=640a4c8b1162ca730a215429c2e3b05afa8c83f9;p=thirdparty%2Fsuricata.git snmp: make log function use the generic prototype and cast and also remove unneeded mut and rustfmt --- diff --git a/rust/src/snmp/log.rs b/rust/src/snmp/log.rs index 8320b46a50..d9a561b156 100644 --- a/rust/src/snmp/log.rs +++ b/rust/src/snmp/log.rs @@ -19,10 +19,10 @@ use crate::jsonbuilder::{JsonBuilder, JsonError}; use crate::snmp::snmp::SNMPTransaction; -use crate::snmp::snmp_parser::{NetworkAddress,PduType}; +use crate::snmp::snmp_parser::{NetworkAddress, PduType}; use std::borrow::Cow; -fn str_of_pdu_type(t:&PduType) -> Cow { +fn str_of_pdu_type(t: &PduType) -> Cow { match t { &PduType::GetRequest => Cow::Borrowed("get_request"), &PduType::GetNextRequest => Cow::Borrowed("get_next_request"), @@ -37,8 +37,7 @@ fn str_of_pdu_type(t:&PduType) -> Cow { } } -fn snmp_log_response(jsb: &mut JsonBuilder, tx: &mut SNMPTransaction) -> Result<(), JsonError> -{ +fn snmp_log_response(jsb: &mut JsonBuilder, tx: &SNMPTransaction) -> Result<(), JsonError> { jsb.open_object("snmp")?; jsb.set_uint("version", tx.version as u64)?; if tx.encrypted { @@ -53,7 +52,9 @@ fn snmp_log_response(jsb: &mut JsonBuilder, tx: &mut SNMPTransaction) -> Result< jsb.set_string("trap_type", &format!("{:?}", trap_type))?; jsb.set_string("trap_oid", &oid.to_string())?; match address { - NetworkAddress::IPv4(ip) => {jsb.set_string("trap_address", &ip.to_string())?;}, + NetworkAddress::IPv4(ip) => { + jsb.set_string("trap_address", &ip.to_string())?; + } } } if !info.vars.is_empty() { @@ -77,7 +78,10 @@ fn snmp_log_response(jsb: &mut JsonBuilder, tx: &mut SNMPTransaction) -> Result< } #[no_mangle] -pub extern "C" fn SCSnmpLogJsonResponse(tx: &mut SNMPTransaction, jsb: &mut JsonBuilder) -> bool -{ +pub unsafe extern "C" fn SCSnmpLogJsonResponse( + tx: *const std::os::raw::c_void, jsb: *mut std::os::raw::c_void, +) -> bool { + let tx = cast_pointer!(tx, SNMPTransaction); + let jsb = cast_pointer!(jsb, JsonBuilder); snmp_log_response(jsb, tx).is_ok() }