From 3ad766f379f95760402c3343c1c7b8a4f4a13a81 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 23 Jan 2025 10:12:05 +0100 Subject: [PATCH 1/4] rust: generated bindings depend on cbindgen.toml make should rerun cbindgen if cbindgen.toml is modified --- rust/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/Makefile.am b/rust/Makefile.am index d53eb97090e1..a47a1c15342d 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -84,7 +84,7 @@ vendor: $(CARGO_ENV) $(CARGO) vendor if HAVE_CBINDGEN -gen/rust-bindings.h: $(RUST_SURICATA_LIB) +gen/rust-bindings.h: $(RUST_SURICATA_LIB) cbindgen.toml cd $(abs_top_srcdir)/rust && \ cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \ --quiet --verify --output $(abs_top_builddir)/rust/gen/rust-bindings.h || true From 7c476a3aeef8ce32d302d9cbb6381985ddd6ac87 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 23 Jan 2025 10:12:59 +0100 Subject: [PATCH 2/4] rust: AppLayerRegisterParser out of SuricataContext Just use a regular compile time rust export, instead of having a runtime definition through the SuricataContext structure --- rust/src/applayer.rs | 6 +----- rust/src/core.rs | 2 -- src/rust-context.c | 2 -- src/rust-context.h | 3 --- 4 files changed, 1 insertion(+), 12 deletions(-) diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 048afbe5a7f5..0817f3c0223b 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -23,7 +23,6 @@ use crate::direction::Direction; use crate::filecontainer::FileContainer; use crate::flow::Flow; use std::os::raw::{c_void,c_char,c_int}; -use crate::core::SC; use std::ffi::CStr; use crate::core::StreamingBufferConfig; @@ -480,12 +479,9 @@ pub type GetFrameNameById = unsafe extern "C" fn(u8) -> *const c_char; extern { pub fn AppLayerRegisterProtocolDetection(parser: *const RustParser, enable_default: c_int) -> AppProto; pub fn AppLayerRegisterParserAlias(parser_name: *const c_char, alias_name: *const c_char); + pub fn AppLayerRegisterParser(parser: *const RustParser, alproto: AppProto) -> c_int; } -#[allow(non_snake_case)] -pub unsafe fn AppLayerRegisterParser(parser: *const RustParser, alproto: AppProto) -> c_int { - (SC.unwrap().AppLayerRegisterParser)(parser, alproto) -} // Defined in app-layer-detect-proto.h /// cbindgen:ignore diff --git a/rust/src/core.rs b/rust/src/core.rs index 7e1094a39e90..a1b74ceaf51a 100644 --- a/rust/src/core.rs +++ b/rust/src/core.rs @@ -163,8 +163,6 @@ pub struct SuricataContext { pub FileAppendData: SCFileAppendDataById, pub FileAppendGAP: SCFileAppendGAPById, pub FileContainerRecycle: SCFileContainerRecycle, - - pub AppLayerRegisterParser: extern fn(parser: *const crate::applayer::RustParser, alproto: AppProto) -> std::os::raw::c_int, } #[allow(non_snake_case)] diff --git a/src/rust-context.c b/src/rust-context.c index e63e12ce002d..1b7131a65d0e 100644 --- a/src/rust-context.c +++ b/src/rust-context.c @@ -37,8 +37,6 @@ const SuricataContext suricata_context = { FileAppendDataById, FileAppendGAPById, FileContainerRecycle, - - AppLayerRegisterParser, }; const SuricataContext *SCGetContext(void) diff --git a/src/rust-context.h b/src/rust-context.h index df1179e368cc..15495c3bea86 100644 --- a/src/rust-context.h +++ b/src/rust-context.h @@ -56,9 +56,6 @@ typedef struct SuricataContext_ { int (*FileAppendGAPById)(FileContainer *, const StreamingBufferConfig *, uint32_t track_id, const uint8_t *data, uint32_t data_len); void (*FileContainerRecycle)(FileContainer *ffc, const StreamingBufferConfig *); - - int (*AppLayerRegisterParser)(const struct AppLayerParser *p, AppProto alproto); - } SuricataContext; extern const SuricataContext suricata_context; From e89a979633d13c95225d1c34bdcc952c03997a9a Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 23 Jan 2025 13:31:05 +0100 Subject: [PATCH 3/4] detect/base64: remove unused macro warning when compiling without unit tests detect-transform-base64.c:47:9: warning: macro is not used [-Wunused-macros] 47 | #define DETECT_TRANSFORM_FROM_BASE64_MODE_DEFAULT (uint8_t) Base64ModeRFC4648 --- src/detect-transform-base64.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/detect-transform-base64.c b/src/detect-transform-base64.c index e0fbdeeb44d6..ddea2933543c 100644 --- a/src/detect-transform-base64.c +++ b/src/detect-transform-base64.c @@ -40,12 +40,11 @@ static int DetectTransformFromBase64DecodeSetup(DetectEngineCtx *, Signature *, const char *); static void DetectTransformFromBase64DecodeFree(DetectEngineCtx *, void *); #ifdef UNITTESTS +#define DETECT_TRANSFORM_FROM_BASE64_MODE_DEFAULT (uint8_t) Base64ModeRFC4648 static void DetectTransformFromBase64DecodeRegisterTests(void); #endif static void TransformFromBase64Decode(InspectionBuffer *buffer, void *options); -#define DETECT_TRANSFORM_FROM_BASE64_MODE_DEFAULT (uint8_t) Base64ModeRFC4648 - void DetectTransformFromBase64DecodeRegister(void) { sigmatch_table[DETECT_TRANSFORM_FROM_BASE64].name = "from_base64"; From 4ddaff42964ab792baddd3fa5e5f66845a6818a8 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 23 Jan 2025 13:54:22 +0100 Subject: [PATCH 4/4] source/pcap-file: remove unused macro warning --- src/source-pcap-file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c index 9c9f405eb4e7..f87c41cda3a4 100644 --- a/src/source-pcap-file.c +++ b/src/source-pcap-file.c @@ -137,9 +137,11 @@ void TmModuleDecodePcapFileRegister (void) tmm_modules[TMM_DECODEPCAPFILE].flags = TM_FLAG_DECODE_TM; } +#if defined(HAVE_SETVBUF) && defined(OS_LINUX) #define PCAP_FILE_BUFFER_SIZE_DEFAULT 131072U // 128 KiB #define PCAP_FILE_BUFFER_SIZE_MIN 4096U // 4 KiB #define PCAP_FILE_BUFFER_SIZE_MAX 67108864U // 64MiB +#endif void PcapFileGlobalInit(void) {