mpm: remove pattern id logic

pull/1980/head
Victor Julien 10 years ago
parent 69d38a3222
commit fa885e1d85

@ -1663,7 +1663,7 @@ AppLayerProtoDetectThreadCtx *AppLayerProtoDetectGetCtxThread(void)
memset(alpd_tctx, 0, sizeof(*alpd_tctx));
/* Get the max pat id for all the mpm ctxs. */
if (PmqSetup(&alpd_tctx->pmq, max_pat_id) < 0)
if (PmqSetup(&alpd_tctx->pmq) < 0)
goto error;
for (i = 0; i < FLOW_PROTO_DEFAULT; i++) {

@ -1341,8 +1341,7 @@ static void *SMTPLocalStorageAlloc(void)
if (unlikely(pmq == NULL)) {
exit(EXIT_FAILURE);
}
PmqSetup(pmq,
sizeof(smtp_reply_map)/sizeof(SCEnumCharMap) - 2);
PmqSetup(pmq);
return pmq;
}

@ -1332,9 +1332,9 @@ static TmEcode ThreadCtxDoInit (DetectEngineCtx *de_ctx, DetectEngineThreadCtx *
PatternMatchThreadPrepare(&det_ctx->mtcs, de_ctx->mpm_matcher);
PatternMatchThreadPrepare(&det_ctx->mtcu, de_ctx->mpm_matcher);
PmqSetup(&det_ctx->pmq, de_ctx->max_fp_id);
PmqSetup(&det_ctx->pmq);
for (i = 0; i < DETECT_SMSG_PMQ_NUM; i++) {
PmqSetup(&det_ctx->smsg_pmq[i], de_ctx->max_fp_id);
PmqSetup(&det_ctx->smsg_pmq[i]);
}
/* sized to the max of our sgh settings. A max setting of 0 implies that all

@ -1503,8 +1503,6 @@ uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
;
} else {
bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
pmq->pattern_id_bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
MpmAddPid(pmq, lower_pid);
MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size);
}
matches++;
@ -1513,9 +1511,6 @@ uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
;
} else {
bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
pmq->pattern_id_bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
MpmAddPid(pmq, pids[k]);
MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size);
}
matches++;
@ -1590,9 +1585,6 @@ uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
;
} else {
bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
pmq->pattern_id_bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
MpmAddPid(pmq, lower_pid);
MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size);
}
matches++;
@ -1601,9 +1593,6 @@ uint32_t SCACBSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
;
} else {
bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
pmq->pattern_id_bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
MpmAddPid(pmq, pids[k]);
MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size);
}
matches++;
@ -1719,7 +1708,7 @@ static int SCACBSTest01(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -1753,7 +1742,7 @@ static int SCACBSTest02(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abce", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -1790,7 +1779,7 @@ static int SCACBSTest03(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"fghj", 4, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -1824,7 +1813,7 @@ static int SCACBSTest04(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"bcdegh", 6, 0, 0, 1, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"fghjxyz", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -1858,7 +1847,7 @@ static int SCACBSTest05(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"fghJikl", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -1890,7 +1879,7 @@ static int SCACBSTest06(void)
SCACBSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -1934,7 +1923,7 @@ static int SCACBSTest07(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
30, 0, 0, 5, 0, 0);
PmqSetup(&pmq, 6);
PmqSetup(&pmq);
/* total matches: 135 */
SCACBSPreparePatterns(&mpm_ctx);
@ -1968,7 +1957,7 @@ static int SCACBSTest08(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2000,7 +1989,7 @@ static int SCACBSTest09(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"ab", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2032,7 +2021,7 @@ static int SCACBSTest10(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefgh", 8, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2075,7 +2064,7 @@ static int SCACBSTest11(void)
goto end;
if (MpmAddPatternCS(&mpm_ctx, (uint8_t *)"hers", 4, 0, 0, 4, 0, 0) == -1)
goto end;
PmqSetup(&pmq, 5);
PmqSetup(&pmq);
if (SCACBSPreparePatterns(&mpm_ctx) == -1)
goto end;
@ -2118,7 +2107,7 @@ static int SCACBSTest12(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"wxyz", 4, 0, 0, 0, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"vwxyz", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2152,7 +2141,7 @@ static int SCACBSTest13(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCD";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2186,7 +2175,7 @@ static int SCACBSTest14(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCDE";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2220,7 +2209,7 @@ static int SCACBSTest15(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCDEF";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2254,7 +2243,7 @@ static int SCACBSTest16(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABC";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2288,7 +2277,7 @@ static int SCACBSTest17(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzAB";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2322,7 +2311,7 @@ static int SCACBSTest18(void)
/* 1 match */
char *pat = "abcde""fghij""klmno""pqrst""uvwxy""z";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2356,7 +2345,7 @@ static int SCACBSTest19(void)
/* 1 */
char *pat = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2389,7 +2378,7 @@ static int SCACBSTest20(void)
/* 1 */
char *pat = "AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2422,7 +2411,7 @@ static int SCACBSTest21(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2456,7 +2445,7 @@ static int SCACBSTest22(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcde", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2489,7 +2478,7 @@ static int SCACBSTest23(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2521,7 +2510,7 @@ static int SCACBSTest24(void)
/* 1 */
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2554,7 +2543,7 @@ static int SCACBSTest25(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"fghiJkl", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2587,7 +2576,7 @@ static int SCACBSTest26(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"Works", 5, 0, 0, 0, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"Works", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2620,7 +2609,7 @@ static int SCACBSTest27(void)
/* 0 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"ONE", 3, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2653,7 +2642,7 @@ static int SCACBSTest28(void)
/* 0 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"one", 3, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);
@ -2688,7 +2677,7 @@ static int SCACBSTest29(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"bcdef", 5, 0, 0, 1, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"cdefg", 5, 0, 0, 3, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"defgh", 5, 0, 0, 4, 0, 0);
PmqSetup(&pmq, 4);
PmqSetup(&pmq);
SCACBSPreparePatterns(&mpm_ctx);

@ -1499,7 +1499,6 @@ int CheckMatch(const SCACTileSearchCtx *ctx, PatternMatcherQueue *pmq,
const uint8_t *buf_offset = buf + i + 1; // Lift out of loop
uint32_t no_of_entries = ctx->output_table[state].no_of_entries;
MpmPatternIndex *patterns = ctx->output_table[state].patterns;
uint8_t *pmq_bitarray = pmq->pattern_id_bitarray;
uint32_t k;
for (k = 0; k < no_of_entries; k++) {
@ -1515,7 +1514,6 @@ int CheckMatch(const SCACTileSearchCtx *ctx, PatternMatcherQueue *pmq,
matches++;
continue;
}
uint32_t pid = pattern_list[pindex].pid;
/* Double check case-sensitve match now. */
if (patterns[k] >> 31) {
uint16_t patlen = pattern_list[pindex].patlen;
@ -1531,11 +1529,6 @@ int CheckMatch(const SCACTileSearchCtx *ctx, PatternMatcherQueue *pmq,
/* New match found */
mpm_bitarray[pindex / 8] |= (1 << (pindex % 8));
if ((pmq_bitarray[pid / 8] & (1 << (pid % 8))) == 0) {
pmq_bitarray[(pid) / 8] |= (1 << ((pid) % 8));
MpmAddPid(pmq, pid);
}
/* Always add the Signature IDs, since they could be different in the current MPM
* than in a previous MPM on the same PMQ when finding the same pattern.
*/
@ -1852,7 +1845,7 @@ static int SCACTileTest01(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -1886,7 +1879,7 @@ static int SCACTileTest02(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abce", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -1923,7 +1916,7 @@ static int SCACTileTest03(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"fghj", 4, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -1957,7 +1950,7 @@ static int SCACTileTest04(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"bcdegh", 6, 0, 0, 1, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"fghjxyz", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -1991,7 +1984,7 @@ static int SCACTileTest05(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"fghJikl", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2023,7 +2016,7 @@ static int SCACTileTest06(void)
SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2067,7 +2060,7 @@ static int SCACTileTest07(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
30, 0, 0, 5, 0, 0);
PmqSetup(&pmq, 6);
PmqSetup(&pmq);
/* total matches: 135 */
SCACTilePreparePatterns(&mpm_ctx);
@ -2101,7 +2094,7 @@ static int SCACTileTest08(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2133,7 +2126,7 @@ static int SCACTileTest09(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"ab", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2165,7 +2158,7 @@ static int SCACTileTest10(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefgh", 8, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2208,7 +2201,7 @@ static int SCACTileTest11(void)
goto end;
if (MpmAddPatternCS(&mpm_ctx, (uint8_t *)"hers", 4, 0, 0, 4, 0, 0) == -1)
goto end;
PmqSetup(&pmq, 5);
PmqSetup(&pmq);
if (SCACTilePreparePatterns(&mpm_ctx) == -1)
goto end;
@ -2251,7 +2244,7 @@ static int SCACTileTest12(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"wxyz", 4, 0, 0, 0, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"vwxyz", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2285,7 +2278,7 @@ static int SCACTileTest13(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCD";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2319,7 +2312,7 @@ static int SCACTileTest14(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCDE";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2353,7 +2346,7 @@ static int SCACTileTest15(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCDEF";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2387,7 +2380,7 @@ static int SCACTileTest16(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABC";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2421,7 +2414,7 @@ static int SCACTileTest17(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzAB";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2455,7 +2448,7 @@ static int SCACTileTest18(void)
/* 1 match */
char *pat = "abcde""fghij""klmno""pqrst""uvwxy""z";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2489,7 +2482,7 @@ static int SCACTileTest19(void)
/* 1 */
char *pat = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2523,7 +2516,7 @@ static int SCACTileTest20(void)
/* 1 */
char *pat = "AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2556,7 +2549,7 @@ static int SCACTileTest21(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2590,7 +2583,7 @@ static int SCACTileTest22(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcde", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2623,7 +2616,7 @@ static int SCACTileTest23(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2655,7 +2648,7 @@ static int SCACTileTest24(void)
/* 1 */
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2688,7 +2681,7 @@ static int SCACTileTest25(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"fghiJkl", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2721,7 +2714,7 @@ static int SCACTileTest26(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"Works", 5, 0, 0, 0, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"Works", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2754,7 +2747,7 @@ static int SCACTileTest27(void)
/* 0 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"ONE", 3, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);
@ -2787,7 +2780,7 @@ static int SCACTileTest28(void)
/* 0 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"one", 3, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACTilePreparePatterns(&mpm_ctx);

@ -1340,9 +1340,7 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
;
} else {
pmq->pattern_id_bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
MpmAddPid(pmq, lower_pid);
MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size);
}
matches++;
@ -1350,9 +1348,7 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
;
} else {
pmq->pattern_id_bitarray[(pids[k]) / 8] |= (1 << ((pids[k]) % 8));
bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
MpmAddPid(pmq, pids[k]);
MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size);
}
matches++;
@ -1384,9 +1380,7 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
;
} else {
pmq->pattern_id_bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
MpmAddPid(pmq, lower_pid);
MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size);
}
matches++;
@ -1394,9 +1388,7 @@ uint32_t SCACSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
;
} else {
pmq->pattern_id_bitarray[(pids[k]) / 8] |= (1 << ((pids[k]) % 8));
bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
MpmAddPid(pmq, pids[k]);
MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size);
}
matches++;
@ -1860,6 +1852,9 @@ uint32_t SCACCudaPacketResultsProcessing(Packet *p, const MpmCtx *mpm_ctx,
SCACOutputTable *output_table = ctx->output_table;
SCACPatternList *pid_pat_list = ctx->pid_pat_list;
uint8_t bitarray[ctx->pattern_id_bitarray_size];
memset(bitarray, 0, ctx->pattern_id_bitarray_size);
for (u = 0; u < cuda_matches; u += 2) {
uint32_t offset = results[u];
uint32_t state = results[u + 1];
@ -1882,17 +1877,19 @@ uint32_t SCACCudaPacketResultsProcessing(Packet *p, const MpmCtx *mpm_ctx,
/* inside loop */
continue;
}
if (pmq->pattern_id_bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
;
} else {
pmq->pattern_id_bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
MpmAddSids(pmq, pid_pat_list[lower_pid].sids, pid_pat_list[lower_pid].sids_size);
}
matches++;
} else {
if (pmq->pattern_id_bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
;
} else {
pmq->pattern_id_bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
MpmAddSids(pmq, pid_pat_list[pids[k]].sids, pid_pat_list[pids[k]].sids_size);
}
matches++;
}
@ -2106,7 +2103,7 @@ static int SCACTest01(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2140,7 +2137,7 @@ static int SCACTest02(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abce", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2177,7 +2174,7 @@ static int SCACTest03(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"fghj", 4, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2211,7 +2208,7 @@ static int SCACTest04(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"bcdegh", 6, 0, 0, 1, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"fghjxyz", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2245,7 +2242,7 @@ static int SCACTest05(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"fghJikl", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2277,7 +2274,7 @@ static int SCACTest06(void)
SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2321,7 +2318,7 @@ static int SCACTest07(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
30, 0, 0, 5, 0, 0);
PmqSetup(&pmq, 6);
PmqSetup(&pmq);
/* total matches: 135 */
SCACPreparePatterns(&mpm_ctx);
@ -2355,7 +2352,7 @@ static int SCACTest08(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2387,7 +2384,7 @@ static int SCACTest09(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"ab", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2419,7 +2416,7 @@ static int SCACTest10(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefgh", 8, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2462,7 +2459,7 @@ static int SCACTest11(void)
goto end;
if (MpmAddPatternCS(&mpm_ctx, (uint8_t *)"hers", 4, 0, 0, 4, 0, 0) == -1)
goto end;
PmqSetup(&pmq, 5);
PmqSetup(&pmq);
if (SCACPreparePatterns(&mpm_ctx) == -1)
goto end;
@ -2505,7 +2502,7 @@ static int SCACTest12(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"wxyz", 4, 0, 0, 0, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"vwxyz", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2539,7 +2536,7 @@ static int SCACTest13(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCD";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2573,7 +2570,7 @@ static int SCACTest14(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCDE";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2607,7 +2604,7 @@ static int SCACTest15(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCDEF";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2641,7 +2638,7 @@ static int SCACTest16(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABC";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2675,7 +2672,7 @@ static int SCACTest17(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzAB";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2709,7 +2706,7 @@ static int SCACTest18(void)
/* 1 match */
char *pat = "abcde""fghij""klmno""pqrst""uvwxy""z";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2743,7 +2740,7 @@ static int SCACTest19(void)
/* 1 */
char *pat = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2777,7 +2774,7 @@ static int SCACTest20(void)
/* 1 */
char *pat = "AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2810,7 +2807,7 @@ static int SCACTest21(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2844,7 +2841,7 @@ static int SCACTest22(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcde", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2877,7 +2874,7 @@ static int SCACTest23(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2909,7 +2906,7 @@ static int SCACTest24(void)
/* 1 */
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2942,7 +2939,7 @@ static int SCACTest25(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"fghiJkl", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -2975,7 +2972,7 @@ static int SCACTest26(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"Works", 5, 0, 0, 0, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"Works", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -3008,7 +3005,7 @@ static int SCACTest27(void)
/* 0 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"ONE", 3, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);
@ -3041,7 +3038,7 @@ static int SCACTest28(void)
/* 0 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"one", 3, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCACPreparePatterns(&mpm_ctx);

@ -920,8 +920,6 @@ static int SCHSMatchEvent(unsigned int id, unsigned long long from,
" (pat id=%" PRIu32 ")",
cctx->match_count, (uint32_t)id, (uintmax_t)to, pat->id);
pmq->pattern_id_bitarray[pat->id / 8] |= (1 << (pat->id % 8));
MpmAddPid(pmq, pat->id);
MpmAddSids(pmq, pat->sids, pat->sids_size);
cctx->match_count++;
@ -1119,7 +1117,7 @@ static int SCHSTest01(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1153,7 +1151,7 @@ static int SCHSTest02(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abce", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1190,7 +1188,7 @@ static int SCHSTest03(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"bcde", 4, 0, 0, 1, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"fghj", 4, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1224,7 +1222,7 @@ static int SCHSTest04(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"bcdegh", 6, 0, 0, 1, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"fghjxyz", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1258,7 +1256,7 @@ static int SCHSTest05(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"fghJikl", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1290,7 +1288,7 @@ static int SCHSTest06(void)
MpmInitCtx(&mpm_ctx, MPM_HS);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1334,7 +1332,7 @@ static int SCHSTest07(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30,
0, 0, 5, 0, 0);
PmqSetup(&pmq, 6);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1367,7 +1365,7 @@ static int SCHSTest08(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1399,7 +1397,7 @@ static int SCHSTest09(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"ab", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1431,7 +1429,7 @@ static int SCHSTest10(void)
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcdefgh", 8, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1474,7 +1472,7 @@ static int SCHSTest11(void)
goto end;
if (MpmAddPatternCS(&mpm_ctx, (uint8_t *)"hers", 4, 0, 0, 4, 0, 0) == -1)
goto end;
PmqSetup(&pmq, 5);
PmqSetup(&pmq);
if (SCHSPreparePatterns(&mpm_ctx) == -1)
goto end;
@ -1518,7 +1516,7 @@ static int SCHSTest12(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"wxyz", 4, 0, 0, 0, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"vwxyz", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1552,7 +1550,7 @@ static int SCHSTest13(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCD";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1586,7 +1584,7 @@ static int SCHSTest14(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCDE";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1620,7 +1618,7 @@ static int SCHSTest15(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABCDEF";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1654,7 +1652,7 @@ static int SCHSTest16(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzABC";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1688,7 +1686,7 @@ static int SCHSTest17(void)
/* 1 match */
char *pat = "abcdefghijklmnopqrstuvwxyzAB";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1727,7 +1725,7 @@ static int SCHSTest18(void)
"uvwxy"
"z";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1766,7 +1764,7 @@ static int SCHSTest19(void)
/* 1 */
char *pat = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1806,7 +1804,7 @@ static int SCHSTest20(void)
"AAAAA"
"AA";
MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1845,7 +1843,7 @@ static int SCHSTest21(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1879,7 +1877,7 @@ static int SCHSTest22(void)
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcd", 4, 0, 0, 0, 0, 0);
/* 1 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"abcde", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1912,7 +1910,7 @@ static int SCHSTest23(void)
/* 1 */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1944,7 +1942,7 @@ static int SCHSTest24(void)
/* 1 */
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"AA", 2, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -1977,7 +1975,7 @@ static int SCHSTest25(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"ABCD", 4, 0, 0, 0, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"bCdEfG", 6, 0, 0, 1, 0, 0);
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"fghiJkl", 7, 0, 0, 2, 0, 0);
PmqSetup(&pmq, 3);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -2010,7 +2008,7 @@ static int SCHSTest26(void)
MpmAddPatternCI(&mpm_ctx, (uint8_t *)"Works", 5, 0, 0, 0, 0, 0);
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"Works", 5, 0, 0, 1, 0, 0);
PmqSetup(&pmq, 2);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -2043,7 +2041,7 @@ static int SCHSTest27(void)
/* 0 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"ONE", 3, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
@ -2076,7 +2074,7 @@ static int SCHSTest28(void)
/* 0 match */
MpmAddPatternCS(&mpm_ctx, (uint8_t *)"one", 3, 0, 0, 0, 0, 0);
PmqSetup(&pmq, 1);
PmqSetup(&pmq);
SCHSPreparePatterns(&mpm_ctx);
SCHSInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);

@ -409,16 +409,13 @@ void MpmCudaEnvironmentSetup()
* \brief Setup a pmq
*
* \param pmq Pattern matcher queue to be initialized
* \param maxid Max sig id to be matched on
* \param patmaxid Max pattern id to be matched on
*
* \retval -1 error
* \retval 0 ok
*/
int PmqSetup(PatternMatcherQueue *pmq, uint32_t patmaxid)
int PmqSetup(PatternMatcherQueue *pmq)
{
SCEnter();
SCLogDebug("patmaxid %u", patmaxid);
if (pmq == NULL) {
SCReturnInt(-1);
@ -426,38 +423,16 @@ int PmqSetup(PatternMatcherQueue *pmq, uint32_t patmaxid)
memset(pmq, 0, sizeof(PatternMatcherQueue));
if (patmaxid > 0) {
pmq->pattern_id_array_size = 32; /* Intial size, TODO Make this configure option */
pmq->pattern_id_array_cnt = 0;
pmq->pattern_id_array = SCCalloc(pmq->pattern_id_array_size, sizeof(uint32_t));
if (pmq->pattern_id_array == NULL) {
SCReturnInt(-1);
}
/* lookup bitarray */
pmq->pattern_id_bitarray_size = (patmaxid / 8) + 1;
pmq->pattern_id_bitarray = SCMalloc(pmq->pattern_id_bitarray_size);
if (pmq->pattern_id_bitarray == NULL) {
SCReturnInt(-1);
}
memset(pmq->pattern_id_bitarray, 0, pmq->pattern_id_bitarray_size);
SCLogDebug("pmq->pattern_id_array %p, pmq->pattern_id_bitarray %p",
pmq->pattern_id_array, pmq->pattern_id_bitarray);
pmq->rule_id_array_size = 128; /* Initial size, TODO: Make configure option. */
pmq->rule_id_array_cnt = 0;
pmq->rule_id_array_size = 128; /* Initial size, TODO: Make configure option. */
pmq->rule_id_array_cnt = 0;
size_t bytes = pmq->rule_id_array_size * sizeof(SigIntId);
pmq->rule_id_array = (SigIntId*)SCMalloc(bytes);
if (pmq->rule_id_array == NULL) {
pmq->rule_id_array_size = 0;
SCReturnInt(-1);
}
// Don't need to zero memory since it is always written first.
size_t bytes = pmq->rule_id_array_size * sizeof(SigIntId);
pmq->rule_id_array = (SigIntId*)SCMalloc(bytes);
if (pmq->rule_id_array == NULL) {
pmq->rule_id_array_size = 0;
SCReturnInt(-1);
}
// Don't need to zero memory since it is always written first.
SCReturnInt(0);
}
@ -498,40 +473,6 @@ MpmAddSidsResize(PatternMatcherQueue *pmq, uint32_t new_size)
return new_size;
}
/** \brief Increase the size of the Pattern rule ID array.
*
* \param pmq storage for match results
* \param new_size number of Signature IDs needing to be stored.
*
* \return 0 on failure.
*/
int
MpmAddPidResize(PatternMatcherQueue *pmq, uint32_t new_size)
{
/* Need to make the array bigger. Double the size needed to
* also handle the case that sids_size might still be
* larger than the old size.
*/
new_size = new_size * 2;
uint32_t *new_array = (uint32_t*)SCRealloc(pmq->pattern_id_array,
new_size * sizeof(uint32_t));
if (unlikely(new_array == NULL)) {
// Failed to allocate 2x, so try 1x.
new_size = new_size / 2;
new_array = (uint32_t*)SCRealloc(pmq->pattern_id_array,
new_size * sizeof(uint32_t));
if (unlikely(new_array == NULL)) {
SCLogError(SC_ERR_MEM_ALLOC, "Failed to realloc PatternMatchQueue"
" pattern ID array. Some new Pattern ID matches were lost.");
return 0;
}
}
pmq->pattern_id_array = new_array;
pmq->pattern_id_array_size = new_size;
return new_size;
}
/**
* \brief Merge two pmq's bitarrays
*
@ -540,17 +481,9 @@ MpmAddPidResize(PatternMatcherQueue *pmq, uint32_t new_size)
*/
void PmqMerge(PatternMatcherQueue *src, PatternMatcherQueue *dst)
{
uint32_t u;
if (src->pattern_id_array_cnt == 0)
if (src->rule_id_array_cnt == 0)
return;
for (u = 0; u < src->pattern_id_bitarray_size && u < dst->pattern_id_bitarray_size; u++) {
dst->pattern_id_bitarray[u] |= src->pattern_id_bitarray[u];
}
/** \todo now set merged flag? */
if (src->rule_id_array && dst->rule_id_array) {
MpmAddSids(dst, src->rule_id_array, src->rule_id_array_cnt);
}
@ -566,10 +499,6 @@ void PmqReset(PatternMatcherQueue *pmq)
if (pmq == NULL)
return;
memset(pmq->pattern_id_bitarray, 0, pmq->pattern_id_bitarray_size);
pmq->pattern_id_array_cnt = 0;
pmq->rule_id_array_cnt = 0;
/* TODO: Realloc the rule id array smaller at some size? */
}
@ -581,24 +510,10 @@ void PmqCleanup(PatternMatcherQueue *pmq)
{
if (pmq == NULL)
return;
if (pmq->pattern_id_array != NULL) {
SCFree(pmq->pattern_id_array);
pmq->pattern_id_array = NULL;
}
if (pmq->pattern_id_bitarray != NULL) {
SCFree(pmq->pattern_id_bitarray);
pmq->pattern_id_bitarray = NULL;
}
if (pmq->rule_id_array != NULL) {
SCFree(pmq->rule_id_array);
pmq->rule_id_array = NULL;
}
pmq->pattern_id_array_cnt = 0;
pmq->pattern_id_array_size = 0;
}
/** \brief Cleanup and free a Pmq

@ -65,16 +65,8 @@ typedef struct MpmThreadCtx_ {
* thread has this and passes a pointer to it to the pattern matcher.
* The actual pattern matcher will fill the structure. */
typedef struct PatternMatcherQueue_ {
uint32_t *pattern_id_array; /** array with pattern id's that had a
pattern match. These will be inspected
futher by the detection engine. */
uint32_t pattern_id_array_cnt; /**< Number currently stored */
uint32_t pattern_id_array_size; /**< Allocated size in bytes */
uint8_t *pattern_id_bitarray; /** bitarray with pattern id matches */
uint32_t pattern_id_bitarray_size; /**< size in bytes */
/* used for storing rule id's */
/* Array of rule IDs found. */
SigIntId *rule_id_array;
/* Number of rule IDs in the array. */
@ -210,7 +202,7 @@ MpmCtx *MpmFactoryGetMpmCtxForProfile(const struct DetectEngineCtx_ *, int32_t,
void MpmFactoryDeRegisterAllMpmCtxProfiles(struct DetectEngineCtx_ *);
int32_t MpmFactoryIsMpmCtxAvailable(const struct DetectEngineCtx_ *, const MpmCtx *);
int PmqSetup(PatternMatcherQueue *, uint32_t);
int PmqSetup(PatternMatcherQueue *);
void PmqMerge(PatternMatcherQueue *src, PatternMatcherQueue *dst);
void PmqReset(PatternMatcherQueue *);
void PmqCleanup(PatternMatcherQueue *);
@ -265,20 +257,4 @@ MpmAddSids(PatternMatcherQueue *pmq, SigIntId *sids, uint32_t sids_size)
} while (ptr != end);
pmq->rule_id_array_cnt += sids_size;
}
/* Resize Pattern ID array. Only called from MpmAddPid(). */
int MpmAddPidResize(PatternMatcherQueue *pmq, uint32_t new_size);
static inline void
MpmAddPid(PatternMatcherQueue *pmq, uint32_t patid)
{
uint32_t new_size = pmq->pattern_id_array_cnt + 1;
if (new_size > pmq->pattern_id_array_size) {
if (MpmAddPidResize(pmq, new_size) == 0)
return;
}
pmq->pattern_id_array[pmq->pattern_id_array_cnt] = patid;
pmq->pattern_id_array_cnt = new_size;
SCLogDebug("pattern_id_array_cnt %u", pmq->pattern_id_array_cnt);
}
#endif /* __UTIL_MPM_H__ */

Loading…
Cancel
Save