spm: reduce spm_matcher size to uint8_t

No more space is needed.
pull/9224/head
Victor Julien 2 years ago
parent 7d0851b0c2
commit fd36459c96

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

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

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

@ -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) {

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

Loading…
Cancel
Save