]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: define AppLayerEventType only in rust
authorPhilippe Antoine <contact@catenacyber.fr>
Thu, 27 Apr 2023 13:04:38 +0000 (15:04 +0200)
committerVictor Julien <vjulien@oisf.net>
Fri, 9 Jun 2023 08:44:11 +0000 (10:44 +0200)
And detect.h does no longer depend on app-layer-events.h

rust/src/applayer.rs
rust/src/core.rs
src/app-layer-events.c
src/app-layer-events.h
src/app-layer-htp-file.c
src/detect-engine.c
src/detect.h
src/rust.h

index 0c1d3a4ba8edc03fbae02c32acf8c40f288be5d2..33fa83a92d006c53fbbc6c2ca4e8fcc3a9197640 100644 (file)
@@ -589,7 +589,7 @@ pub unsafe fn get_event_info<T: AppLayerEvent>(
         Ok(Some(event)) => event.as_i32(),
         _ => -1,
     };
-    *event_type = core::APP_LAYER_EVENT_TYPE_TRANSACTION;
+    *event_type = core::AppLayerEventType::APP_LAYER_EVENT_TYPE_TRANSACTION;
     *event_id = event as std::os::raw::c_int;
     return 0;
 }
@@ -604,7 +604,7 @@ pub unsafe fn get_event_info_by_id<T: AppLayerEvent>(
 ) -> i8 {
     if let Some(e) = T::from_id(event_id) {
         *event_name = e.to_cstring().as_ptr() as *const std::os::raw::c_char;
-        *event_type = core::APP_LAYER_EVENT_TYPE_TRANSACTION;
+        *event_type = core::AppLayerEventType::APP_LAYER_EVENT_TYPE_TRANSACTION;
         return 0;
     }
     return -1;
index f3057c0ed896915bedf71dd79dde3ff7ef97d225..5b0a67afc0fb1bf99b07f890672e8e87e0195815 100644 (file)
@@ -25,10 +25,13 @@ use crate::debug_validate_fail;
 pub enum DetectEngineState {}
 pub enum AppLayerDecoderEvents {}
 
-// From app-layer-events.h
-pub type AppLayerEventType = std::os::raw::c_int;
-pub const APP_LAYER_EVENT_TYPE_TRANSACTION : i32 = 1;
-pub const APP_LAYER_EVENT_TYPE_PACKET      : i32 = 2;
+#[repr(C)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy)]
+#[allow(non_camel_case_types)]
+pub enum AppLayerEventType {
+    APP_LAYER_EVENT_TYPE_TRANSACTION = 1,
+    APP_LAYER_EVENT_TYPE_PACKET = 2,
+}
 
 pub const STREAM_START:    u8 = 0x01;
 pub const STREAM_EOF:      u8 = 0x02;
index 2ff47ecb69d0405455e2a734b238a2b901f8a83d..e3d38113508562ad457d66430cc116ba712f7ae9 100644 (file)
@@ -141,3 +141,38 @@ void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
     }
 }
 
+SCEnumCharMap det_ctx_event_table[] = {
+    { "NO_MEMORY", FILE_DECODER_EVENT_NO_MEM },
+    { "INVALID_SWF_LENGTH", FILE_DECODER_EVENT_INVALID_SWF_LENGTH },
+    { "INVALID_SWF_VERSION", FILE_DECODER_EVENT_INVALID_SWF_VERSION },
+    { "Z_DATA_ERROR", FILE_DECODER_EVENT_Z_DATA_ERROR },
+    { "Z_STREAM_ERROR", FILE_DECODER_EVENT_Z_STREAM_ERROR },
+    { "Z_BUF_ERROR", FILE_DECODER_EVENT_Z_BUF_ERROR },
+    { "Z_UNKNOWN_ERROR", FILE_DECODER_EVENT_Z_UNKNOWN_ERROR },
+    { "LZMA_IO_ERROR", FILE_DECODER_EVENT_LZMA_IO_ERROR },
+    { "LZMA_HEADER_TOO_SHORT_ERROR", FILE_DECODER_EVENT_LZMA_HEADER_TOO_SHORT_ERROR },
+    { "LZMA_DECODER_ERROR", FILE_DECODER_EVENT_LZMA_DECODER_ERROR },
+    { "LZMA_MEMLIMIT_ERROR", FILE_DECODER_EVENT_LZMA_MEMLIMIT_ERROR },
+    { "LZMA_XZ_ERROR", FILE_DECODER_EVENT_LZMA_XZ_ERROR },
+    { "LZMA_UNKNOWN_ERROR", FILE_DECODER_EVENT_LZMA_UNKNOWN_ERROR },
+    {
+            "TOO_MANY_BUFFERS",
+            DETECT_EVENT_TOO_MANY_BUFFERS,
+    },
+    { NULL, -1 },
+};
+
+int DetectEngineGetEventInfo(const char *event_name, int *event_id, AppLayerEventType *event_type)
+{
+    *event_id = SCMapEnumNameToValue(event_name, det_ctx_event_table);
+    if (*event_id == -1) {
+        SCLogError("event \"%s\" not present in "
+                   "det_ctx's enum map table.",
+                event_name);
+        /* this should be treated as fatal */
+        return -1;
+    }
+    *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
+
+    return 0;
+}
index 7e0a4a087ada300545add2cef933e218a6de269f..83cb0d9ba47180648f589bb019c42d7232857b31 100644 (file)
@@ -27,6 +27,7 @@
 
 /* contains fwd declaration of AppLayerDecoderEvents_ */
 #include "decode.h"
+#include "rust.h"
 
 /**
  * \brief Data structure to store app layer decoder events.
@@ -52,12 +53,6 @@ enum {
     APPLAYER_UNEXPECTED_PROTOCOL,
 };
 
-/* the event types for app events */
-typedef enum AppLayerEventType_ {
-    APP_LAYER_EVENT_TYPE_TRANSACTION = 1,
-    APP_LAYER_EVENT_TYPE_PACKET,
-} AppLayerEventType;
-
 int AppLayerGetPktEventInfo(const char *event_name, int *event_id);
 
 int AppLayerGetEventInfoById(int event_id, const char **event_name,
@@ -82,6 +77,7 @@ static inline int AppLayerDecoderEventsIsEventSet(AppLayerDecoderEvents *devents
 
 void AppLayerDecoderEventsResetEvents(AppLayerDecoderEvents *events);
 void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events);
+int DetectEngineGetEventInfo(const char *event_name, int *event_id, AppLayerEventType *event_type);
 
 #endif /* __APP_LAYER_EVENTS_H__ */
 
index 9aba4147ee9ddf99d2ee0e40f4049685a0941522..095b5903ca5bd77aa5c8c54a1c7dddfc5cd78a39 100644 (file)
@@ -27,6 +27,7 @@
 #include "suricata-common.h"
 #include "app-layer-htp-file.h"
 #include "app-layer-htp-range.h"
+#include "app-layer-events.h"
 #include "util-validate.h"
 
 extern StreamingBufferConfig htp_sbcfg;
index 522f1d50c16ea9fae594fe1b8dd179dbdb92332e..83756018ca32b258c54eaea12fb0af8f4b7f4e80 100644 (file)
@@ -121,30 +121,6 @@ const struct SignatureProperties signature_properties[SIG_TYPE_MAX] = {
 };
 // clang-format on
 
-SCEnumCharMap det_ctx_event_table[] = {
-#ifdef UNITTESTS
-    { "TEST", DET_CTX_EVENT_TEST },
-#endif
-    { "NO_MEMORY", FILE_DECODER_EVENT_NO_MEM },
-    { "INVALID_SWF_LENGTH", FILE_DECODER_EVENT_INVALID_SWF_LENGTH },
-    { "INVALID_SWF_VERSION", FILE_DECODER_EVENT_INVALID_SWF_VERSION },
-    { "Z_DATA_ERROR", FILE_DECODER_EVENT_Z_DATA_ERROR },
-    { "Z_STREAM_ERROR", FILE_DECODER_EVENT_Z_STREAM_ERROR },
-    { "Z_BUF_ERROR", FILE_DECODER_EVENT_Z_BUF_ERROR },
-    { "Z_UNKNOWN_ERROR", FILE_DECODER_EVENT_Z_UNKNOWN_ERROR },
-    { "LZMA_IO_ERROR", FILE_DECODER_EVENT_LZMA_IO_ERROR },
-    { "LZMA_HEADER_TOO_SHORT_ERROR", FILE_DECODER_EVENT_LZMA_HEADER_TOO_SHORT_ERROR },
-    { "LZMA_DECODER_ERROR", FILE_DECODER_EVENT_LZMA_DECODER_ERROR },
-    { "LZMA_MEMLIMIT_ERROR", FILE_DECODER_EVENT_LZMA_MEMLIMIT_ERROR },
-    { "LZMA_XZ_ERROR", FILE_DECODER_EVENT_LZMA_XZ_ERROR },
-    { "LZMA_UNKNOWN_ERROR", FILE_DECODER_EVENT_LZMA_UNKNOWN_ERROR },
-    {
-            "TOO_MANY_BUFFERS",
-            DETECT_EVENT_TOO_MANY_BUFFERS,
-    },
-    { NULL, -1 },
-};
-
 /** \brief register inspect engine at start up time
  *
  *  \note errors are fatal */
@@ -4829,22 +4805,6 @@ AppLayerDecoderEvents *DetectEngineGetEvents(DetectEngineThreadCtx *det_ctx)
     return det_ctx->decoder_events;
 }
 
-int DetectEngineGetEventInfo(const char *event_name, int *event_id,
-                             AppLayerEventType *event_type)
-{
-    *event_id = SCMapEnumNameToValue(event_name, det_ctx_event_table);
-    if (*event_id == -1) {
-        SCLogError("event \"%s\" not present in "
-                   "det_ctx's enum map table.",
-                event_name);
-        /* this should be treated as fatal */
-        return -1;
-    }
-    *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
-
-    return 0;
-}
-
 /*************************************Unittest*********************************/
 
 #ifdef UNITTESTS
index 49a920b03eb4ba844d710c955e622d25a8b41300..971072b0b34dbff96436bfea74bf3c7a0eeed07a 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "suricata-common.h"
 #include "flow.h"
-#include "app-layer-events.h"
 
 #include "detect-engine-proto.h"
 #include "detect-reference.h"
@@ -1274,9 +1273,6 @@ typedef struct SigTableElmt_ {
 
 /* event code */
 enum {
-#ifdef UNITTESTS
-    DET_CTX_EVENT_TEST,
-#endif
     FILE_DECODER_EVENT_NO_MEM,
     FILE_DECODER_EVENT_INVALID_SWF_LENGTH,
     FILE_DECODER_EVENT_INVALID_SWF_VERSION,
@@ -1571,8 +1567,6 @@ void DetectMetadataHashFree(DetectEngineCtx *de_ctx);
 /* events */
 void DetectEngineSetEvent(DetectEngineThreadCtx *det_ctx, uint8_t e);
 AppLayerDecoderEvents *DetectEngineGetEvents(DetectEngineThreadCtx *det_ctx);
-int DetectEngineGetEventInfo(const char *event_name, int *event_id,
-                             AppLayerEventType *event_type);
 
 void DumpPatterns(DetectEngineCtx *de_ctx);
 
index 39f94c4321fa449a25533469b8dc829e498378e3..2916417ee78e44d5d413cab77f9192daa484b56a 100644 (file)
@@ -18,7 +18,6 @@
 #ifndef __RUST_H__
 #define __RUST_H__
 
-#include "app-layer-events.h"
 #include "util-file.h"
 
 // hack for include orders cf SCSha256