rust: define AppLayerEventType only in rust

And detect.h does no longer depend on app-layer-events.h
pull/9001/head
Philippe Antoine 3 years ago committed by Victor Julien
parent 668501c225
commit f2a18e91c4

@ -589,7 +589,7 @@ pub unsafe fn get_event_info<T: AppLayerEvent>(
Ok(Some(event)) => event.as_i32(), Ok(Some(event)) => event.as_i32(),
_ => -1, _ => -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; *event_id = event as std::os::raw::c_int;
return 0; return 0;
} }
@ -604,7 +604,7 @@ pub unsafe fn get_event_info_by_id<T: AppLayerEvent>(
) -> i8 { ) -> i8 {
if let Some(e) = T::from_id(event_id) { if let Some(e) = T::from_id(event_id) {
*event_name = e.to_cstring().as_ptr() as *const std::os::raw::c_char; *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 0;
} }
return -1; return -1;

@ -25,10 +25,13 @@ use crate::debug_validate_fail;
pub enum DetectEngineState {} pub enum DetectEngineState {}
pub enum AppLayerDecoderEvents {} pub enum AppLayerDecoderEvents {}
// From app-layer-events.h #[repr(C)]
pub type AppLayerEventType = std::os::raw::c_int; #[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub const APP_LAYER_EVENT_TYPE_TRANSACTION : i32 = 1; #[allow(non_camel_case_types)]
pub const APP_LAYER_EVENT_TYPE_PACKET : i32 = 2; pub enum AppLayerEventType {
APP_LAYER_EVENT_TYPE_TRANSACTION = 1,
APP_LAYER_EVENT_TYPE_PACKET = 2,
}
pub const STREAM_START: u8 = 0x01; pub const STREAM_START: u8 = 0x01;
pub const STREAM_EOF: u8 = 0x02; pub const STREAM_EOF: u8 = 0x02;

@ -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;
}

@ -27,6 +27,7 @@
/* contains fwd declaration of AppLayerDecoderEvents_ */ /* contains fwd declaration of AppLayerDecoderEvents_ */
#include "decode.h" #include "decode.h"
#include "rust.h"
/** /**
* \brief Data structure to store app layer decoder events. * \brief Data structure to store app layer decoder events.
@ -52,12 +53,6 @@ enum {
APPLAYER_UNEXPECTED_PROTOCOL, 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 AppLayerGetPktEventInfo(const char *event_name, int *event_id);
int AppLayerGetEventInfoById(int event_id, const char **event_name, int AppLayerGetEventInfoById(int event_id, const char **event_name,
@ -82,6 +77,7 @@ static inline int AppLayerDecoderEventsIsEventSet(AppLayerDecoderEvents *devents
void AppLayerDecoderEventsResetEvents(AppLayerDecoderEvents *events); void AppLayerDecoderEventsResetEvents(AppLayerDecoderEvents *events);
void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events); void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events);
int DetectEngineGetEventInfo(const char *event_name, int *event_id, AppLayerEventType *event_type);
#endif /* __APP_LAYER_EVENTS_H__ */ #endif /* __APP_LAYER_EVENTS_H__ */

@ -27,6 +27,7 @@
#include "suricata-common.h" #include "suricata-common.h"
#include "app-layer-htp-file.h" #include "app-layer-htp-file.h"
#include "app-layer-htp-range.h" #include "app-layer-htp-range.h"
#include "app-layer-events.h"
#include "util-validate.h" #include "util-validate.h"
extern StreamingBufferConfig htp_sbcfg; extern StreamingBufferConfig htp_sbcfg;

@ -121,30 +121,6 @@ const struct SignatureProperties signature_properties[SIG_TYPE_MAX] = {
}; };
// clang-format on // 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 /** \brief register inspect engine at start up time
* *
* \note errors are fatal */ * \note errors are fatal */
@ -4829,22 +4805,6 @@ AppLayerDecoderEvents *DetectEngineGetEvents(DetectEngineThreadCtx *det_ctx)
return det_ctx->decoder_events; 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*********************************/ /*************************************Unittest*********************************/
#ifdef UNITTESTS #ifdef UNITTESTS

@ -26,7 +26,6 @@
#include "suricata-common.h" #include "suricata-common.h"
#include "flow.h" #include "flow.h"
#include "app-layer-events.h"
#include "detect-engine-proto.h" #include "detect-engine-proto.h"
#include "detect-reference.h" #include "detect-reference.h"
@ -1274,9 +1273,6 @@ typedef struct SigTableElmt_ {
/* event code */ /* event code */
enum { enum {
#ifdef UNITTESTS
DET_CTX_EVENT_TEST,
#endif
FILE_DECODER_EVENT_NO_MEM, FILE_DECODER_EVENT_NO_MEM,
FILE_DECODER_EVENT_INVALID_SWF_LENGTH, FILE_DECODER_EVENT_INVALID_SWF_LENGTH,
FILE_DECODER_EVENT_INVALID_SWF_VERSION, FILE_DECODER_EVENT_INVALID_SWF_VERSION,
@ -1571,8 +1567,6 @@ void DetectMetadataHashFree(DetectEngineCtx *de_ctx);
/* events */ /* events */
void DetectEngineSetEvent(DetectEngineThreadCtx *det_ctx, uint8_t e); void DetectEngineSetEvent(DetectEngineThreadCtx *det_ctx, uint8_t e);
AppLayerDecoderEvents *DetectEngineGetEvents(DetectEngineThreadCtx *det_ctx); AppLayerDecoderEvents *DetectEngineGetEvents(DetectEngineThreadCtx *det_ctx);
int DetectEngineGetEventInfo(const char *event_name, int *event_id,
AppLayerEventType *event_type);
void DumpPatterns(DetectEngineCtx *de_ctx); void DumpPatterns(DetectEngineCtx *de_ctx);

@ -18,7 +18,6 @@
#ifndef __RUST_H__ #ifndef __RUST_H__
#define __RUST_H__ #define __RUST_H__
#include "app-layer-events.h"
#include "util-file.h" #include "util-file.h"
// hack for include orders cf SCSha256 // hack for include orders cf SCSha256

Loading…
Cancel
Save