diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 0c1d3a4ba8..33fa83a92d 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -589,7 +589,7 @@ pub unsafe fn get_event_info( 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( ) -> 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; diff --git a/rust/src/core.rs b/rust/src/core.rs index f3057c0ed8..5b0a67afc0 100644 --- a/rust/src/core.rs +++ b/rust/src/core.rs @@ -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; diff --git a/src/app-layer-events.c b/src/app-layer-events.c index 2ff47ecb69..e3d3811350 100644 --- a/src/app-layer-events.c +++ b/src/app-layer-events.c @@ -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; +} diff --git a/src/app-layer-events.h b/src/app-layer-events.h index 7e0a4a087a..83cb0d9ba4 100644 --- a/src/app-layer-events.h +++ b/src/app-layer-events.h @@ -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__ */ diff --git a/src/app-layer-htp-file.c b/src/app-layer-htp-file.c index 9aba4147ee..095b5903ca 100644 --- a/src/app-layer-htp-file.c +++ b/src/app-layer-htp-file.c @@ -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; diff --git a/src/detect-engine.c b/src/detect-engine.c index 522f1d50c1..83756018ca 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -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 diff --git a/src/detect.h b/src/detect.h index 49a920b03e..971072b0b3 100644 --- a/src/detect.h +++ b/src/detect.h @@ -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); diff --git a/src/rust.h b/src/rust.h index 39f94c4321..2916417ee7 100644 --- a/src/rust.h +++ b/src/rust.h @@ -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