]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/ike: replace rs_ naming with SC
authorJason Ish <jason.ish@oisf.net>
Fri, 2 May 2025 22:54:22 +0000 (16:54 -0600)
committerVictor Julien <victor@inliniac.net>
Sat, 3 May 2025 06:19:41 +0000 (08:19 +0200)
12 files changed:
rust/src/ike/detect.rs
rust/src/ike/ike.rs
rust/src/ike/logger.rs
src/detect-ike-chosen-sa.c
src/detect-ike-exch-type.c
src/detect-ike-key-exchange-payload-length.c
src/detect-ike-key-exchange-payload.c
src/detect-ike-nonce-payload-length.c
src/detect-ike-nonce-payload.c
src/detect-ike-spi.c
src/detect-ike-vendor.c
src/output-json-ike.c

index 6e07c15454e37d62d6d3d19d527857efc3b7229c..92c708646d0f38e816bfd113e746bfb0ca59c817 100644 (file)
@@ -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());
index 94a37afc9c6f5561a7a6f57745122695cb1f0656..398fd6e83b379bd534ab8227bc3c4fd7a4a86a8a 100644 (file)
@@ -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,
index 75234575375a46726b7c90df0e6aac5bb490547e..823850142777cde6af8f74b7750ac71fed66f4b1 100644 (file)
@@ -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);
index 6505b1bf2231bfee8916a7962a0a1a0bc03c01bc..619c8f2f56d028f06176974372e12a964c3a302f 100644 (file)
@@ -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);
index c72ae12914995c1a110424b63573013f6b7ea7fc..5bad0b213539ff8692aed31d7424e6d725ac4e29 100644 (file)
@@ -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;
index 3740b7797447a50aa777d687d24d6734e1d5fe0a..f06495787f4c5d0b4af1ea8e7d8726bc09800bca 100644 (file)
@@ -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);
index a76532388a0b07d30c480754766d800da7fdecbb..7d436c29d3ce671b795f1e296f68cdd7724c0fb6 100644 (file)
@@ -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;
index 4cab7513d5547182cb3c402441daa1f6cf84bec8..5a201aff8cc3aa68e6f96d027962cfa9a989b670 100644 (file)
@@ -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);
index 692962c2c8ec0f0f1a3e6c2c7593d7ac0344efe0..01a3ed8a4ec81a3ad25880d0522c5127287f4ba6 100644 (file)
@@ -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;
index a8e5a5475189703d380c91b20134fbc2b236786d..b21cb5e99396db14e99668526b3ecdc44d062b8c 100644 (file)
@@ -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;
index fe264bb390934380e8a5afdaf9db197961839c81..a4cad8ef5454daebdae19dc0494977d164fa9776 100644 (file)
@@ -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");
 
index bda0ba90dd996b0cd5fcf3aadaee733cf63adad4..241767a479a6c1bc33730d70c55d80b53b42015e 100644 (file)
@@ -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;
     }