diff --git a/rust/src/core.rs b/rust/src/core.rs index 2280e28958..ed06bbd871 100644 --- a/rust/src/core.rs +++ b/rust/src/core.rs @@ -18,7 +18,7 @@ //! This module exposes items from the core "C" code to Rust. use std; -use std::os::raw::{c_int, c_void}; +use std::os::raw::c_void; use suricata_sys::sys::{AppProto, AppProtoEnum, SCLogLevel}; use crate::filecontainer::*; @@ -72,8 +72,8 @@ macro_rules!BIT_U64 { /// cbindgen:ignore extern "C" { pub fn MpmAddPatternCI( - ctx: *const c_void, pat: *const libc::c_char, pat_len: c_int, _offset: c_int, - _depth: c_int, id: c_int, rule_id: c_int, _flags: c_int, + ctx: *const c_void, pat: *const libc::c_char, pat_len: u16, _offset: u16, + _depth: u16, id: u32, rule_id: u32, _flags: u8, ) -> c_void; } diff --git a/rust/src/ftp/ftp.rs b/rust/src/ftp/ftp.rs index 154badf8c2..1aa31251b5 100644 --- a/rust/src/ftp/ftp.rs +++ b/rust/src/ftp/ftp.rs @@ -18,7 +18,7 @@ use std; use std::ptr; use std::ffi::{CStr, CString}; -use std::os::raw::{c_char, c_int, c_void}; +use std::os::raw::{c_char, c_void}; use crate::conf::{conf_get, get_memval}; use crate::core::*; @@ -141,11 +141,11 @@ pub unsafe extern "C" fn SCFTPSetMpmState(ctx: *const c_void) { MpmAddPatternCI( ctx, name_ptr, - len as c_int, + len as u16, 0, 0, - index as c_int, - index as c_int, + index as u32, + index as u32, 0, ); } diff --git a/src/util-mpm-ac-ks.c b/src/util-mpm-ac-ks.c index 665147744c..5e73dfd533 100644 --- a/src/util-mpm-ac-ks.c +++ b/src/util-mpm-ac-ks.c @@ -86,8 +86,8 @@ void SCACTileInitCtx(MpmCtx *); void SCACTileDestroyCtx(MpmCtx *); -int SCACTileAddPatternCI(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, - uint32_t, SigIntId, uint8_t); +int SCACTileAddPatternCI( + MpmCtx *, const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCACTileAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCACTilePreparePatterns(MpmConfig *mpm_conf, MpmCtx *mpm_ctx); @@ -1336,9 +1336,8 @@ uint32_t SCACTileSearchLarge(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thr * \retval 0 On success. * \retval -1 On failure. */ -int SCACTileAddPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, - uint16_t offset, uint16_t depth, uint32_t pid, - SigIntId sid, uint8_t flags) +int SCACTileAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset, + uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags) { flags |= MPM_PATTERN_FLAG_NOCASE; return MpmAddPattern(mpm_ctx, pat, patlen, offset, depth, diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 9f4607f50e..4a151cec0f 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -64,8 +64,8 @@ void SCACInitCtx(MpmCtx *); void SCACDestroyCtx(MpmCtx *); -int SCACAddPatternCI(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, - uint32_t, SigIntId, uint8_t); +int SCACAddPatternCI( + MpmCtx *, const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCACAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCACPreparePatterns(MpmConfig *, MpmCtx *mpm_ctx); @@ -1038,9 +1038,8 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, * \retval 0 On success. * \retval -1 On failure. */ -int SCACAddPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, - uint16_t offset, uint16_t depth, uint32_t pid, - SigIntId sid, uint8_t flags) +int SCACAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset, + uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags) { flags |= MPM_PATTERN_FLAG_NOCASE; return MpmAddPattern(mpm_ctx, pat, patlen, offset, depth, pid, sid, flags); diff --git a/src/util-mpm-hs.c b/src/util-mpm-hs.c index a738a691c3..c37c1731b3 100644 --- a/src/util-mpm-hs.c +++ b/src/util-mpm-hs.c @@ -55,8 +55,8 @@ void SCHSInitCtx(MpmCtx *); void SCHSInitThreadCtx(MpmCtx *, MpmThreadCtx *); void SCHSDestroyCtx(MpmCtx *); void SCHSDestroyThreadCtx(MpmCtx *, MpmThreadCtx *); -int SCHSAddPatternCI(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, - uint32_t, SigIntId, uint8_t); +int SCHSAddPatternCI( + MpmCtx *, const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCHSAddPatternCS(MpmCtx *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); int SCHSPreparePatterns(MpmConfig *mpm_conf, MpmCtx *mpm_ctx); @@ -128,7 +128,7 @@ static void SCHSSetAllocators(void) * * \retval hash A 32 bit unsigned hash. */ -static inline uint32_t SCHSInitHashRaw(uint8_t *pat, uint16_t patlen) +static inline uint32_t SCHSInitHashRaw(const uint8_t *pat, uint16_t patlen) { uint32_t hash = patlen * pat[0]; if (patlen > 1) @@ -149,10 +149,8 @@ static inline uint32_t SCHSInitHashRaw(uint8_t *pat, uint16_t patlen) * * \retval hash A 32 bit unsigned hash. */ -static inline SCHSPattern *SCHSInitHashLookup(SCHSCtx *ctx, uint8_t *pat, - uint16_t patlen, uint16_t offset, - uint16_t depth, char flags, - uint32_t pid) +static inline SCHSPattern *SCHSInitHashLookup(SCHSCtx *ctx, const uint8_t *pat, uint16_t patlen, + uint16_t offset, uint16_t depth, char flags, uint32_t pid) { uint32_t hash = SCHSInitHashRaw(pat, patlen); @@ -272,9 +270,8 @@ static inline int SCHSInitHashAdd(SCHSCtx *ctx, SCHSPattern *p) * \retval 0 On success. * \retval -1 On failure. */ -static int SCHSAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, - uint16_t offset, uint16_t depth, uint32_t pid, - SigIntId sid, uint8_t flags) +static int SCHSAddPattern(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset, + uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags) { SCHSCtx *ctx = (SCHSCtx *)mpm_ctx->ctx; @@ -1087,9 +1084,8 @@ uint32_t SCHSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, * \retval 0 On success. * \retval -1 On failure. */ -int SCHSAddPatternCI(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, - uint16_t offset, uint16_t depth, uint32_t pid, - SigIntId sid, uint8_t flags) +int SCHSAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset, + uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags) { flags |= MPM_PATTERN_FLAG_NOCASE; return SCHSAddPattern(mpm_ctx, pat, patlen, offset, depth, pid, sid, flags); diff --git a/src/util-mpm.c b/src/util-mpm.c index 9c7c18cfda..c2ff50f2d7 100644 --- a/src/util-mpm.c +++ b/src/util-mpm.c @@ -255,9 +255,8 @@ int MpmAddPatternCS(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen, pid, sid, flags); } -int MpmAddPatternCI(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen, - uint16_t offset, uint16_t depth, - uint32_t pid, SigIntId sid, uint8_t flags) +int MpmAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset, + uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags) { return mpm_table[mpm_ctx->mpm_type].AddPatternNocase(mpm_ctx, pat, patlen, offset, depth, @@ -275,7 +274,7 @@ int MpmAddPatternCI(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen, * * \retval hash A 32 bit unsigned hash. */ -static inline uint32_t MpmInitHashRaw(uint8_t *pat, uint16_t patlen) +static inline uint32_t MpmInitHashRaw(const uint8_t *pat, uint16_t patlen) { uint32_t hash = patlen * pat[0]; if (patlen > 1) @@ -296,10 +295,8 @@ static inline uint32_t MpmInitHashRaw(uint8_t *pat, uint16_t patlen) * * \retval hash A 32 bit unsigned hash. */ -static inline MpmPattern *MpmInitHashLookup(MpmCtx *ctx, - uint8_t *pat, uint16_t patlen, - uint16_t offset, uint16_t depth, - uint8_t flags, uint32_t pid) +static inline MpmPattern *MpmInitHashLookup(MpmCtx *ctx, const uint8_t *pat, uint16_t patlen, + uint16_t offset, uint16_t depth, uint8_t flags, uint32_t pid) { uint32_t hash = MpmInitHashRaw(pat, patlen); @@ -435,9 +432,8 @@ static inline int MpmInitHashAdd(MpmCtx *ctx, MpmPattern *p) * \retval 0 On success. * \retval -1 On failure. */ -int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, - uint16_t offset, uint16_t depth, uint32_t pid, - SigIntId sid, uint8_t flags) +int MpmAddPattern(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset, + uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags) { SCLogDebug("Adding pattern for ctx %p, patlen %"PRIu16" and pid %" PRIu32, mpm_ctx, patlen, pid); diff --git a/src/util-mpm.h b/src/util-mpm.h index 6c18828e8b..14252f1584 100644 --- a/src/util-mpm.h +++ b/src/util-mpm.h @@ -170,7 +170,8 @@ typedef struct MpmTableElmt_ { * \param flags pattern flags */ int (*AddPattern)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); - int (*AddPatternNocase)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t); + int (*AddPatternNocase)(struct MpmCtx_ *, const uint8_t *, uint16_t, uint16_t, uint16_t, + uint32_t, SigIntId, uint8_t); int (*Prepare)(MpmConfig *, struct MpmCtx_ *); int (*CacheRuleset)(MpmConfig *); /** \retval cnt number of patterns that matches: once per pattern max. */ @@ -205,14 +206,12 @@ void MpmDestroyThreadCtx(MpmThreadCtx *mpm_thread_ctx, const uint16_t matcher); int MpmAddPatternCS(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags); -int MpmAddPatternCI(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen, - uint16_t offset, uint16_t depth, - uint32_t pid, SigIntId sid, uint8_t flags); +int MpmAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset, + uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags); void MpmFreePattern(MpmCtx *mpm_ctx, MpmPattern *p); -int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, - uint16_t offset, uint16_t depth, uint32_t pid, - SigIntId sid, uint8_t flags); +int MpmAddPattern(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset, + uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags); #endif /* SURICATA_UTIL_MPM_H */