From bfa0acf2787947b0ffece54e71048624325ad28c Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Fri, 2 May 2025 16:54:22 -0600 Subject: [PATCH] rust/ike: replace rs_ naming with SC --- rust/src/ike/detect.rs | 18 ++--- rust/src/ike/ike.rs | 70 ++++++-------------- rust/src/ike/logger.rs | 2 +- src/detect-ike-chosen-sa.c | 2 +- src/detect-ike-exch-type.c | 2 +- src/detect-ike-key-exchange-payload-length.c | 2 +- src/detect-ike-key-exchange-payload.c | 2 +- src/detect-ike-nonce-payload-length.c | 2 +- src/detect-ike-nonce-payload.c | 2 +- src/detect-ike-spi.c | 4 +- src/detect-ike-vendor.c | 2 +- src/output-json-ike.c | 4 +- 12 files changed, 40 insertions(+), 72 deletions(-) diff --git a/rust/src/ike/detect.rs b/rust/src/ike/detect.rs index 6e07c15454..92c708646d 100644 --- a/rust/src/ike/detect.rs +++ b/rust/src/ike/detect.rs @@ -25,7 +25,7 @@ use std::os::raw::c_void; use std::ptr; #[no_mangle] -pub extern "C" fn rs_ike_state_get_exch_type(tx: &IKETransaction, exch_type: *mut u8) -> u8 { +pub extern "C" fn SCIkeStateGetExchType(tx: &IKETransaction, exch_type: *mut u8) -> u8 { debug_validate_bug_on!(exch_type.is_null()); if tx.ike_version == 1 { @@ -46,7 +46,7 @@ pub extern "C" fn rs_ike_state_get_exch_type(tx: &IKETransaction, exch_type: *mu } #[no_mangle] -pub extern "C" fn rs_ike_state_get_spi_initiator( +pub extern "C" fn SCIkeStateGetSpiInitiator( tx: &IKETransaction, buffer: *mut *const u8, buffer_len: *mut u32, ) -> u8 { debug_validate_bug_on!(buffer.is_null() || buffer_len.is_null()); @@ -59,7 +59,7 @@ pub extern "C" fn rs_ike_state_get_spi_initiator( } #[no_mangle] -pub extern "C" fn rs_ike_state_get_spi_responder( +pub extern "C" fn SCIkeStateGetSpiResponder( tx: &IKETransaction, buffer: *mut *const u8, buffer_len: *mut u32, ) -> u8 { debug_validate_bug_on!(buffer.is_null() || buffer_len.is_null()); @@ -72,7 +72,7 @@ pub extern "C" fn rs_ike_state_get_spi_responder( } #[no_mangle] -pub extern "C" fn rs_ike_state_get_nonce( +pub extern "C" fn SCIkeStateGetNonce( tx: &IKETransaction, buffer: *mut *const u8, buffer_len: *mut u32, ) -> u8 { debug_validate_bug_on!(buffer.is_null() || buffer_len.is_null()); @@ -95,7 +95,7 @@ pub extern "C" fn rs_ike_state_get_nonce( } #[no_mangle] -pub extern "C" fn rs_ike_state_get_key_exchange( +pub extern "C" fn SCIkeStateGetKeyExchange( tx: &IKETransaction, buffer: *mut *const u8, buffer_len: *mut u32, ) -> u8 { debug_validate_bug_on!(buffer.is_null() || buffer_len.is_null()); @@ -118,7 +118,7 @@ pub extern "C" fn rs_ike_state_get_key_exchange( } #[no_mangle] -pub unsafe extern "C" fn rs_ike_tx_get_vendor( +pub unsafe extern "C" fn SCIkeTxGetVendor( _de: *mut DetectEngineThreadCtx, tx: *const c_void, _flags: u8, i: u32, buf: *mut *const u8, len: *mut u32, ) -> bool { @@ -136,7 +136,7 @@ pub unsafe extern "C" fn rs_ike_tx_get_vendor( } #[no_mangle] -pub extern "C" fn rs_ike_state_get_sa_attribute( +pub extern "C" fn SCIkeStateGetSaAttribute( tx: &IKETransaction, sa_type: *const std::os::raw::c_char, value: *mut u32, ) -> u8 { debug_validate_bug_on!(value.is_null()); @@ -207,7 +207,7 @@ pub extern "C" fn rs_ike_state_get_sa_attribute( } #[no_mangle] -pub unsafe extern "C" fn rs_ike_state_get_key_exchange_payload_length( +pub unsafe extern "C" fn SCIkeStateGetKeyExchangePayloadLength( tx: &IKETransaction, value: *mut u32, ) -> u8 { debug_validate_bug_on!(value.is_null()); @@ -222,7 +222,7 @@ pub unsafe extern "C" fn rs_ike_state_get_key_exchange_payload_length( } #[no_mangle] -pub unsafe extern "C" fn rs_ike_state_get_nonce_payload_length( +pub unsafe extern "C" fn SCIkeStateGetNoncePayloadLength( tx: &IKETransaction, value: *mut u32, ) -> u8 { debug_validate_bug_on!(value.is_null()); diff --git a/rust/src/ike/ike.rs b/rust/src/ike/ike.rs index 94a37afc9c..398fd6e83b 100644 --- a/rust/src/ike/ike.rs +++ b/rust/src/ike/ike.rs @@ -115,7 +115,6 @@ pub struct IKETransaction { /// errors seen during exchange pub errors: u32, - logged: LoggerFlags, pub tx_data: applayer::AppLayerTxData, } @@ -280,8 +279,7 @@ fn probe(input: &[u8], direction: Direction, rdir: *mut u8) -> bool { // C exports. /// C entry point for a probing parser. -#[no_mangle] -pub unsafe extern "C" fn rs_ike_probing_parser( +unsafe extern "C" fn ike_probing_parser( _flow: *const Flow, direction: u8, input: *const u8, input_len: u32, rdir: *mut u8, ) -> AppProto { if input_len < 28 { @@ -298,8 +296,7 @@ pub unsafe extern "C" fn rs_ike_probing_parser( return ALPROTO_FAILED; } -#[no_mangle] -pub extern "C" fn rs_ike_state_new( +extern "C" fn ike_state_new( _orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto, ) -> *mut std::os::raw::c_void { let state = IKEState::default(); @@ -307,20 +304,17 @@ pub extern "C" fn rs_ike_state_new( return Box::into_raw(boxed) as *mut _; } -#[no_mangle] -pub unsafe extern "C" fn rs_ike_state_free(state: *mut std::os::raw::c_void) { +unsafe extern "C" fn ike_state_free(state: *mut std::os::raw::c_void) { // Just unbox... std::mem::drop(Box::from_raw(state as *mut IKEState)); } -#[no_mangle] -pub unsafe extern "C" fn rs_ike_state_tx_free(state: *mut std::os::raw::c_void, tx_id: u64) { +unsafe extern "C" fn ike_state_tx_free(state: *mut std::os::raw::c_void, tx_id: u64) { let state = cast_pointer!(state, IKEState); state.free_tx(tx_id); } -#[no_mangle] -pub unsafe extern "C" fn rs_ike_parse_request( +unsafe extern "C" fn ike_parse_request( _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 { @@ -328,8 +322,7 @@ pub unsafe extern "C" fn rs_ike_parse_request( return state.handle_input(stream_slice.as_slice(), Direction::ToServer); } -#[no_mangle] -pub unsafe extern "C" fn rs_ike_parse_response( +unsafe extern "C" fn ike_parse_response( _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 { @@ -337,8 +330,7 @@ pub unsafe extern "C" fn rs_ike_parse_response( return state.handle_input(stream_slice.as_slice(), Direction::ToClient); } -#[no_mangle] -pub unsafe extern "C" fn rs_ike_state_get_tx( +unsafe extern "C" fn ike_state_get_tx( state: *mut std::os::raw::c_void, tx_id: u64, ) -> *mut std::os::raw::c_void { let state = cast_pointer!(state, IKEState); @@ -352,41 +344,17 @@ pub unsafe extern "C" fn rs_ike_state_get_tx( } } -#[no_mangle] -pub unsafe extern "C" fn rs_ike_state_get_tx_count(state: *mut std::os::raw::c_void) -> u64 { +unsafe extern "C" fn ike_state_get_tx_count(state: *mut std::os::raw::c_void) -> u64 { let state = cast_pointer!(state, IKEState); return state.tx_id; } -#[no_mangle] -pub extern "C" fn rs_ike_state_progress_completion_status(_direction: u8) -> std::os::raw::c_int { - // This parser uses 1 to signal transaction completion status. - return 1; -} - -#[no_mangle] -pub extern "C" fn rs_ike_tx_get_alstate_progress( +extern "C" fn ike_tx_get_alstate_progress( _tx: *mut std::os::raw::c_void, _direction: u8, ) -> std::os::raw::c_int { return 1; } -#[no_mangle] -pub unsafe extern "C" fn rs_ike_tx_get_logged( - _state: *mut std::os::raw::c_void, tx: *mut std::os::raw::c_void, -) -> u32 { - let tx = cast_pointer!(tx, IKETransaction); - return tx.logged.get(); -} - -#[no_mangle] -pub unsafe extern "C" fn rs_ike_tx_set_logged( - _state: *mut std::os::raw::c_void, tx: *mut std::os::raw::c_void, logged: u32, -) { - let tx = cast_pointer!(tx, IKETransaction); - tx.logged.set(logged); -} - static mut ALPROTO_IKE: AppProto = ALPROTO_UNKNOWN; // Parser name as a C style string. @@ -403,20 +371,20 @@ pub unsafe extern "C" fn rs_ike_register_parser() { 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_ike_probing_parser), - probe_tc: Some(rs_ike_probing_parser), + probe_ts: Some(ike_probing_parser), + probe_tc: Some(ike_probing_parser), min_depth: 0, max_depth: 16, - state_new: rs_ike_state_new, - state_free: rs_ike_state_free, - tx_free: rs_ike_state_tx_free, - parse_ts: rs_ike_parse_request, - parse_tc: rs_ike_parse_response, - get_tx_count: rs_ike_state_get_tx_count, - get_tx: rs_ike_state_get_tx, + state_new: ike_state_new, + state_free: ike_state_free, + tx_free: ike_state_tx_free, + parse_ts: ike_parse_request, + parse_tc: ike_parse_response, + get_tx_count: ike_state_get_tx_count, + get_tx: ike_state_get_tx, tx_comp_st_ts: 1, tx_comp_st_tc: 1, - tx_get_progress: rs_ike_tx_get_alstate_progress, + tx_get_progress: ike_tx_get_alstate_progress, get_eventinfo: Some(IkeEvent::get_event_info), get_eventinfo_byid: Some(IkeEvent::get_event_info_by_id), localstorage_new: None, diff --git a/rust/src/ike/logger.rs b/rust/src/ike/logger.rs index 7523457537..8238501427 100644 --- a/rust/src/ike/logger.rs +++ b/rust/src/ike/logger.rs @@ -226,7 +226,7 @@ fn log_ikev2(tx: &IKETransaction, jb: &mut JsonBuilder) -> Result<(), JsonError> } #[no_mangle] -pub unsafe extern "C" fn rs_ike_logger_log( +pub unsafe extern "C" fn SCIkeLoggerLog( state: &mut IKEState, tx: *mut std::os::raw::c_void, flags: u32, js: &mut JsonBuilder, ) -> bool { let tx = cast_pointer!(tx, IKETransaction); diff --git a/src/detect-ike-chosen-sa.c b/src/detect-ike-chosen-sa.c index 6505b1bf22..619c8f2f56 100644 --- a/src/detect-ike-chosen-sa.c +++ b/src/detect-ike-chosen-sa.c @@ -105,7 +105,7 @@ static int DetectIkeChosenSaMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8 const DetectIkeChosenSaData *dd = (const DetectIkeChosenSaData *)ctx; uint32_t value; - if (!rs_ike_state_get_sa_attribute(txv, dd->sa_type, &value)) + if (!SCIkeStateGetSaAttribute(txv, dd->sa_type, &value)) SCReturnInt(0); if (value == dd->sa_value) SCReturnInt(1); diff --git a/src/detect-ike-exch-type.c b/src/detect-ike-exch-type.c index c72ae12914..5bad0b2135 100644 --- a/src/detect-ike-exch-type.c +++ b/src/detect-ike-exch-type.c @@ -87,7 +87,7 @@ static int DetectIkeExchTypeMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8 SCEnter(); uint8_t exch_type; - if (!rs_ike_state_get_exch_type(txv, &exch_type)) + if (!SCIkeStateGetExchType(txv, &exch_type)) SCReturnInt(0); const DetectU8Data *du8 = (const DetectU8Data *)ctx; diff --git a/src/detect-ike-key-exchange-payload-length.c b/src/detect-ike-key-exchange-payload-length.c index 3740b77974..f06495787f 100644 --- a/src/detect-ike-key-exchange-payload-length.c +++ b/src/detect-ike-key-exchange-payload-length.c @@ -91,7 +91,7 @@ static int DetectIkeKeyExchangePayloadLengthMatch(DetectEngineThreadCtx *det_ctx SCEnter(); uint32_t length; - if (!rs_ike_state_get_key_exchange_payload_length(txv, &length)) + if (!SCIkeStateGetKeyExchangePayloadLength(txv, &length)) SCReturnInt(0); const DetectU32Data *du32 = (const DetectU32Data *)ctx; return DetectU32Match(length, du32); diff --git a/src/detect-ike-key-exchange-payload.c b/src/detect-ike-key-exchange-payload.c index a76532388a..7d436c29d3 100644 --- a/src/detect-ike-key-exchange-payload.c +++ b/src/detect-ike-key-exchange-payload.c @@ -78,7 +78,7 @@ static InspectionBuffer *GetKeyExchangeData(DetectEngineThreadCtx *det_ctx, const uint8_t *b = NULL; uint32_t b_len = 0; - if (rs_ike_state_get_key_exchange(txv, &b, &b_len) != 1) + if (SCIkeStateGetKeyExchange(txv, &b, &b_len) != 1) return NULL; if (b == NULL || b_len == 0) return NULL; diff --git a/src/detect-ike-nonce-payload-length.c b/src/detect-ike-nonce-payload-length.c index 4cab7513d5..5a201aff8c 100644 --- a/src/detect-ike-nonce-payload-length.c +++ b/src/detect-ike-nonce-payload-length.c @@ -87,7 +87,7 @@ static int DetectIkeNoncePayloadLengthMatch(DetectEngineThreadCtx *det_ctx, Flow SCEnter(); uint32_t length; - if (!rs_ike_state_get_nonce_payload_length(txv, &length)) + if (!SCIkeStateGetNoncePayloadLength(txv, &length)) SCReturnInt(0); const DetectU32Data *du32 = (const DetectU32Data *)ctx; return DetectU32Match(length, du32); diff --git a/src/detect-ike-nonce-payload.c b/src/detect-ike-nonce-payload.c index 692962c2c8..01a3ed8a4e 100644 --- a/src/detect-ike-nonce-payload.c +++ b/src/detect-ike-nonce-payload.c @@ -78,7 +78,7 @@ static InspectionBuffer *GetNonceData(DetectEngineThreadCtx *det_ctx, const uint8_t *b = NULL; uint32_t b_len = 0; - if (rs_ike_state_get_nonce(txv, &b, &b_len) != 1) + if (SCIkeStateGetNonce(txv, &b, &b_len) != 1) return NULL; if (b == NULL || b_len == 0) return NULL; diff --git a/src/detect-ike-spi.c b/src/detect-ike-spi.c index a8e5a54751..b21cb5e993 100644 --- a/src/detect-ike-spi.c +++ b/src/detect-ike-spi.c @@ -95,7 +95,7 @@ static InspectionBuffer *GetInitiatorData(DetectEngineThreadCtx *det_ctx, const uint8_t *b = NULL; uint32_t b_len = 0; - if (rs_ike_state_get_spi_initiator(txv, &b, &b_len) != 1) + if (SCIkeStateGetSpiInitiator(txv, &b, &b_len) != 1) return NULL; if (b == NULL || b_len == 0) return NULL; @@ -115,7 +115,7 @@ static InspectionBuffer *GetResponderData(DetectEngineThreadCtx *det_ctx, const uint8_t *b = NULL; uint32_t b_len = 0; - if (rs_ike_state_get_spi_responder(txv, &b, &b_len) != 1) + if (SCIkeStateGetSpiResponder(txv, &b, &b_len) != 1) return NULL; if (b == NULL || b_len == 0) return NULL; diff --git a/src/detect-ike-vendor.c b/src/detect-ike-vendor.c index fe264bb390..a4cad8ef54 100644 --- a/src/detect-ike-vendor.c +++ b/src/detect-ike-vendor.c @@ -53,7 +53,7 @@ void DetectIkeVendorRegister(void) sigmatch_table[DETECT_IKE_VENDOR].flags |= SIGMATCH_INFO_STICKY_BUFFER; DetectAppLayerMultiRegister( - "ike.vendor", ALPROTO_IKE, SIG_FLAG_TOSERVER, 1, rs_ike_tx_get_vendor, 1); + "ike.vendor", ALPROTO_IKE, SIG_FLAG_TOSERVER, 1, SCIkeTxGetVendor, 1); g_ike_vendor_buffer_id = DetectBufferTypeGetByName("ike.vendor"); diff --git a/src/output-json-ike.c b/src/output-json-ike.c index bda0ba90dd..241767a479 100644 --- a/src/output-json-ike.c +++ b/src/output-json-ike.c @@ -68,7 +68,7 @@ bool EveIKEAddMetadata(const Flow *f, uint64_t tx_id, SCJsonBuilder *js) if (state) { IKETransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_IKE, state, tx_id); if (tx) { - return rs_ike_logger_log(state, tx, LOG_IKE_EXTENDED, js); + return SCIkeLoggerLog(state, tx, LOG_IKE_EXTENDED, js); } } @@ -86,7 +86,7 @@ static int JsonIKELogger(ThreadVars *tv, void *thread_data, const Packet *p, Flo } LogIKEFileCtx *ike_ctx = thread->ikelog_ctx; - if (!rs_ike_logger_log(state, tx, ike_ctx->flags, jb)) { + if (!SCIkeLoggerLog(state, tx, ike_ctx->flags, jb)) { goto error; } -- 2.47.3