From 1a73276acb2f01340b172f53da53e7a1693ef6a4 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Sat, 17 Oct 2026 15:22:52 -0600 Subject: [PATCH] detect: expose the sigmatch list ids to Rust Move enum DetectSigmatchListEnum to detect-engine-register.h, which is already included by detect.h and the bindgen header, and allowlist it in the Rust bindings. Packet keywords implemented in Rust or in plugins need DETECT_SM_LIST_MATCH to add their SigMatch and to look up earlier ones, and had to hardcode its value. Related to ticket: 7499 --- rust/Makefile.am | 1 + rust/sys/src/sys.rs | 17 +++++++++++++++++ src/detect-engine-register.h | 29 +++++++++++++++++++++++++++++ src/detect.h | 29 ----------------------------- 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/rust/Makefile.am b/rust/Makefile.am index aa069e916e..db68c0dbf0 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -157,6 +157,7 @@ if HAVE_BINDGEN --allowlist-function 'SC.*' \ --allowlist-var 'SC.*' \ --allowlist-var 'SIGMATCH.*' \ + --allowlist-type 'DetectSigmatchListEnum' \ --opaque-type 'SCConfNode' \ --allowlist-type 'ThreadVars.?' \ --opaque-type 'ThreadVars.?' \ diff --git a/rust/sys/src/sys.rs b/rust/sys/src/sys.rs index 72aa482fbe..6659bf931f 100644 --- a/rust/sys/src/sys.rs +++ b/rust/sys/src/sys.rs @@ -635,6 +635,23 @@ extern "C" { tv: *mut ThreadVars, p: *const Packet, f: *mut Flow, jb: *mut SCJsonBuilder, ); } +impl DetectSigmatchListEnum { + pub const DETECT_SM_LIST_DYNAMIC_START: DetectSigmatchListEnum = + DetectSigmatchListEnum::DETECT_SM_LIST_MAX; +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum DetectSigmatchListEnum { + DETECT_SM_LIST_MATCH = 0, + DETECT_SM_LIST_PMATCH = 1, + DETECT_SM_LIST_BASE64_DATA = 2, + DETECT_SM_LIST_POSTMATCH = 3, + #[doc = "< post-detection tagging"] + DETECT_SM_LIST_TMATCH = 4, + DETECT_SM_LIST_SUPPRESS = 5, + DETECT_SM_LIST_THRESHOLD = 6, + DETECT_SM_LIST_MAX = 7, +} extern "C" { pub fn SCSigTablePreRegister( KeywordsRegister: ::std::option::Option, diff --git a/src/detect-engine-register.h b/src/detect-engine-register.h index 8a247f3600..837cb22de4 100644 --- a/src/detect-engine-register.h +++ b/src/detect-engine-register.h @@ -298,6 +298,35 @@ enum DetectKeywordId { DETECT_TBLSIZE_STATIC, }; +/* holds the values for different possible lists in struct Signature. + * These codes are access points to particular lists in the array + * Signature->init_data->smlists[DETECT_SM_LIST_MAX]. */ +enum DetectSigmatchListEnum { + /* list for non-payload per packet matches, e.g. ttl, flow keyword */ + DETECT_SM_LIST_MATCH = 0, + /* list for payload and stream match */ + DETECT_SM_LIST_PMATCH, + + /* base64_data keyword uses some hardcoded logic so consider + * built-in + * TODO convert to inspect engine */ + DETECT_SM_LIST_BASE64_DATA, + + /* list for post match actions: flowbit set, flowint increment, etc */ + DETECT_SM_LIST_POSTMATCH, + + DETECT_SM_LIST_TMATCH, /**< post-detection tagging */ + + /* lists for alert thresholding and suppression */ + DETECT_SM_LIST_SUPPRESS, + DETECT_SM_LIST_THRESHOLD, + + DETECT_SM_LIST_MAX, + + /* start of dynamically registered lists */ + DETECT_SM_LIST_DYNAMIC_START = DETECT_SM_LIST_MAX, +}; + extern int DETECT_TBLSIZE; extern int DETECT_TBLSIZE_IDX; // step for reallocating sigmatch_table diff --git a/src/detect.h b/src/detect.h index 605b54693a..0d3671e2ea 100644 --- a/src/detect.h +++ b/src/detect.h @@ -110,35 +110,6 @@ extern const struct SignatureProperties signature_properties[SIG_TYPE_MAX]; -- Protocol */ -/* holds the values for different possible lists in struct Signature. - * These codes are access points to particular lists in the array - * Signature->init_data->smlists[DETECT_SM_LIST_MAX]. */ -enum DetectSigmatchListEnum { - /* list for non-payload per packet matches, e.g. ttl, flow keyword */ - DETECT_SM_LIST_MATCH = 0, - /* list for payload and stream match */ - DETECT_SM_LIST_PMATCH, - - /* base64_data keyword uses some hardcoded logic so consider - * built-in - * TODO convert to inspect engine */ - DETECT_SM_LIST_BASE64_DATA, - - /* list for post match actions: flowbit set, flowint increment, etc */ - DETECT_SM_LIST_POSTMATCH, - - DETECT_SM_LIST_TMATCH, /**< post-detection tagging */ - - /* lists for alert thresholding and suppression */ - DETECT_SM_LIST_SUPPRESS, - DETECT_SM_LIST_THRESHOLD, - - DETECT_SM_LIST_MAX, - - /* start of dynamically registered lists */ - DETECT_SM_LIST_DYNAMIC_START = DETECT_SM_LIST_MAX, -}; - /* used for Signature->list, which indicates which list * we're adding keywords to in cases of sticky buffers like * file_data */