]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
spm: reduce spm_matcher size to uint8_t
authorVictor Julien <vjulien@oisf.net>
Wed, 12 Jul 2023 06:00:47 +0000 (08:00 +0200)
committerVictor Julien <vjulien@oisf.net>
Thu, 13 Jul 2023 04:49:26 +0000 (06:49 +0200)
No more space is needed.

src/app-layer-detect-proto.c
src/detect-content.c
src/detect.h
src/util-spm.c
src/util-spm.h

index 39e36bd31742066b30ef84f97e3c55d5bb60b4d9..4ae69350df540d9797cd63895c87f682f967b8de 100644 (file)
@@ -1728,7 +1728,7 @@ int AppLayerProtoDetectSetup(void)
 
     memset(&alpd_ctx, 0, sizeof(alpd_ctx));
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     uint8_t mpm_matcher = PatternMatchDefaultMatcher();
 
     alpd_ctx.spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
index 6a73daa5212537ea184acfa3b678175ecca7ab72..6026cf2956cab06474efa221e77137a176162171 100644 (file)
@@ -913,7 +913,7 @@ static int DetectContentParseTest01 (void)
     const char *teststring = "abc\\:def";
     const char *teststringparsed = "abc:def";
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -944,7 +944,7 @@ static int DetectContentParseTest02 (void)
     const char *teststring = "abc\\;def";
     const char *teststringparsed = "abc;def";
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -975,7 +975,7 @@ static int DetectContentParseTest03 (void)
     const char *teststring = "abc\\\"def";
     const char *teststringparsed = "abc\"def";
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -1006,7 +1006,7 @@ static int DetectContentParseTest04 (void)
     const char *teststring = "abc\\\\def";
     const char *teststringparsed = "abc\\def";
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -1037,7 +1037,7 @@ static int DetectContentParseTest05 (void)
     DetectContentData *cd = NULL;
     const char *teststring = "abc\\def";
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -1063,7 +1063,7 @@ static int DetectContentParseTest06 (void)
     const char *teststring = "a|42|c|44|e|46|";
     const char *teststringparsed = "abcdef";
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -1094,7 +1094,7 @@ static int DetectContentParseTest07 (void)
     DetectContentData *cd = NULL;
     const char *teststring = "";
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -1117,7 +1117,7 @@ static int DetectContentParseTest08 (void)
     DetectContentData *cd = NULL;
     const char *teststring = "";
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -1407,7 +1407,7 @@ static int DetectContentParseTest09(void)
     DetectContentData *cd = NULL;
     const char *teststring = "boo";
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -2072,7 +2072,7 @@ static int DetectContentParseTest41(void)
     }
     teststring[idx++] = '\0';
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -2105,7 +2105,7 @@ static int DetectContentParseTest42(void)
     }
     teststring[idx++] = '\0';
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -2139,7 +2139,7 @@ static int DetectContentParseTest43(void)
     }
     teststring[idx++] = '\0';
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
@@ -2176,7 +2176,7 @@ static int DetectContentParseTest44(void)
     }
     teststring[idx++] = '\0';
 
-    uint16_t spm_matcher = SinglePatternMatchDefaultMatcher();
+    uint8_t spm_matcher = SinglePatternMatchDefaultMatcher();
     SpmGlobalThreadCtx *spm_global_thread_ctx = SpmInitGlobalThreadCtx(spm_matcher);
     FAIL_IF(spm_global_thread_ctx == NULL);
 
index 971072b0b34dbff96436bfea74bf3c7a0eeed07a..e462933c2c236e32b322a36b9c74489d7dff1195 100644 (file)
@@ -872,7 +872,7 @@ typedef struct DetectEngineCtx_ {
 
     uint8_t flags;        /**< only DE_QUIET */
     uint8_t mpm_matcher;  /**< mpm matcher this ctx uses */
-    uint16_t spm_matcher; /**< spm matcher this ctx uses */
+    uint8_t spm_matcher;  /**< spm matcher this ctx uses */
 
     /* maximum recursion depth for content inspection */
     int inspection_recursion_limit;
index 5352e64ad1ac486728e7ff5b82ee146db9f8ff89..15b33398a62af4ad1326dddf089eead811349101 100644 (file)
@@ -65,7 +65,7 @@ SpmTableElmt spm_table[SPM_TABLE_SIZE];
  * \brief Returns the single pattern matcher algorithm to be used, based on the
  * spm-algo setting in yaml.
  */
-uint16_t SinglePatternMatchDefaultMatcher(void)
+uint8_t SinglePatternMatchDefaultMatcher(void)
 {
     const char *spm_algo;
     if ((ConfGet("spm-algo", &spm_algo)) == 1) {
@@ -73,7 +73,7 @@ uint16_t SinglePatternMatchDefaultMatcher(void)
             if (strcmp("auto", spm_algo) == 0) {
                 goto default_matcher;
             }
-            for (uint16_t i = 0; i < SPM_TABLE_SIZE; i++) {
+            for (uint8_t i = 0; i < SPM_TABLE_SIZE; i++) {
                 if (spm_table[i].name == NULL) {
                     continue;
                 }
@@ -135,7 +135,7 @@ void SpmTableSetup(void)
 #endif
 }
 
-SpmGlobalThreadCtx *SpmInitGlobalThreadCtx(uint16_t matcher)
+SpmGlobalThreadCtx *SpmInitGlobalThreadCtx(uint8_t matcher)
 {
     BUG_ON(spm_table[matcher].InitGlobalThreadCtx == NULL);
     return spm_table[matcher].InitGlobalThreadCtx();
@@ -146,7 +146,7 @@ void SpmDestroyGlobalThreadCtx(SpmGlobalThreadCtx *global_thread_ctx)
     if (global_thread_ctx == NULL) {
         return;
     }
-    uint16_t matcher = global_thread_ctx->matcher;
+    uint8_t matcher = global_thread_ctx->matcher;
     spm_table[matcher].DestroyGlobalThreadCtx(global_thread_ctx);
 }
 
@@ -155,7 +155,7 @@ SpmThreadCtx *SpmMakeThreadCtx(const SpmGlobalThreadCtx *global_thread_ctx)
     if (global_thread_ctx == NULL) {
         return NULL;
     }
-    uint16_t matcher = global_thread_ctx->matcher;
+    uint8_t matcher = global_thread_ctx->matcher;
     BUG_ON(spm_table[matcher].MakeThreadCtx == NULL);
     return spm_table[matcher].MakeThreadCtx(global_thread_ctx);
 }
@@ -165,7 +165,7 @@ void SpmDestroyThreadCtx(SpmThreadCtx *thread_ctx)
     if (thread_ctx == NULL) {
         return;
     }
-    uint16_t matcher = thread_ctx->matcher;
+    uint8_t matcher = thread_ctx->matcher;
     BUG_ON(spm_table[matcher].DestroyThreadCtx == NULL);
     spm_table[matcher].DestroyThreadCtx(thread_ctx);
 }
@@ -174,7 +174,7 @@ SpmCtx *SpmInitCtx(const uint8_t *needle, uint16_t needle_len, int nocase,
                    SpmGlobalThreadCtx *global_thread_ctx)
 {
     BUG_ON(global_thread_ctx == NULL);
-    uint16_t matcher = global_thread_ctx->matcher;
+    uint8_t matcher = global_thread_ctx->matcher;
     BUG_ON(spm_table[matcher].InitCtx == NULL);
     return spm_table[matcher].InitCtx(needle, needle_len, nocase,
                                       global_thread_ctx);
@@ -185,7 +185,7 @@ void SpmDestroyCtx(SpmCtx *ctx)
     if (ctx == NULL) {
         return;
     }
-    uint16_t matcher = ctx->matcher;
+    uint8_t matcher = ctx->matcher;
     BUG_ON(spm_table[matcher].DestroyCtx == NULL);
     spm_table[matcher].DestroyCtx(ctx);
 }
@@ -193,7 +193,7 @@ void SpmDestroyCtx(SpmCtx *ctx)
 uint8_t *SpmScan(const SpmCtx *ctx, SpmThreadCtx *thread_ctx,
                  const uint8_t *haystack, uint32_t haystack_len)
 {
-    uint16_t matcher = ctx->matcher;
+    uint8_t matcher = ctx->matcher;
     return spm_table[matcher].Scan(ctx, thread_ctx, haystack, haystack_len);
 }
 
@@ -2478,7 +2478,7 @@ typedef struct SpmTestData_ {
 } SpmTestData;
 
 /* Helper function to conduct a search with a particular SPM matcher. */
-static int SpmTestSearch(const SpmTestData *d, uint16_t matcher)
+static int SpmTestSearch(const SpmTestData *d, uint8_t matcher)
 {
     int ret = 1;
     SpmGlobalThreadCtx *global_thread_ctx = NULL;
@@ -2572,7 +2572,7 @@ static int SpmSearchTest01(void) {
 
     int ret = 1;
 
-    uint16_t matcher;
+    uint8_t matcher;
     for (matcher = 0; matcher < SPM_TABLE_SIZE; matcher++) {
         const SpmTableElmt *m = &spm_table[matcher];
         if (m->name == NULL) {
@@ -2614,7 +2614,7 @@ static int SpmSearchTest02(void) {
 
     int ret = 1;
 
-    uint16_t matcher;
+    uint8_t matcher;
     for (matcher = 0; matcher < SPM_TABLE_SIZE; matcher++) {
         const SpmTableElmt *m = &spm_table[matcher];
         if (m->name == NULL) {
index ae3fe7f025d22a39aa5ea0634d317fbe20950fc4..9893dcd4222ed12d0ec146cadc3146a625b3aae7 100644 (file)
@@ -33,26 +33,26 @@ enum {
     SPM_TABLE_SIZE
 };
 
-uint16_t SinglePatternMatchDefaultMatcher(void);
+uint8_t SinglePatternMatchDefaultMatcher(void);
 
 /** Structure holding an immutable "built" SPM matcher (such as the Boyer-Moore
  * tables, Hyperscan database etc) that is passed to the Scan call. */
 typedef struct SpmCtx_ {
-    uint16_t matcher;
+    uint8_t matcher;
     void *ctx;
 } SpmCtx;
 
 /** Structure holding a global prototype for per-thread scratch space, passed
  * to each InitCtx call. */
 typedef struct SpmGlobalThreadCtx_ {
-    uint16_t matcher;
+    uint8_t matcher;
     void *ctx;
 } SpmGlobalThreadCtx;
 
 /** Structure holding some mutable per-thread space for use by a matcher at
  * scan time. Constructed from SpmGlobalThreadCtx by the MakeThreadCtx call. */
 typedef struct SpmThreadCtx_ {
-    uint16_t matcher;
+    uint8_t matcher;
     void *ctx;
 } SpmThreadCtx;
 
@@ -73,7 +73,7 @@ extern SpmTableElmt spm_table[SPM_TABLE_SIZE];
 
 void SpmTableSetup(void);
 
-SpmGlobalThreadCtx *SpmInitGlobalThreadCtx(uint16_t matcher);
+SpmGlobalThreadCtx *SpmInitGlobalThreadCtx(uint8_t matcher);
 
 void SpmDestroyGlobalThreadCtx(SpmGlobalThreadCtx *g_thread_ctx);