68 MpmCtx *,
const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t,
SigIntId, uint8_t);
76 static void SCACRegisterTests(
void);
80 #define SC_AC_FAIL (-1)
82 #define AC_CASE_MASK 0x80000000
83 #define AC_PID_MASK 0x7FFFFFFF
84 #define AC_CASE_BIT 31
86 static int construct_both_16_and_32_state_tables = 0;
94 static void SCACGetConfig(
void)
112 static inline size_t SCACCheckSafeSizetMult(
size_t a,
size_t b)
114 size_t size = MpmCheckSafeSizetMult(a, b);
115 if (size == 0 && a != 0 && b != 0) {
116 SCLogError(
"%" PRIuMAX
" * %" PRIuMAX
" > %" PRIuMAX
117 " would overflow size_t calculating buffer size",
118 (uintmax_t)a, (uintmax_t)b, (uintmax_t)SIZE_MAX);
132 static inline int SCACReallocState(
SCACCtx *
ctx, uint32_t
cnt)
138 size = SCACCheckSafeSizetMult((
size_t)
cnt, (
size_t)
ctx->single_state_size);
143 ctx->goto_table = NULL;
146 ctx->goto_table = ptmp;
149 size_t oldsize = SCACCheckSafeSizetMult((
size_t)
ctx->state_count,
152 SCLogDebug(
"oldsize %"PRIuMAX
" size %"PRIuMAX
" cnt %d ctx->state_count %u",
153 (uintmax_t) oldsize, (uintmax_t) size,
cnt,
ctx->state_count);
160 ctx->output_table = NULL;
163 ctx->output_table = ptmp;
165 memset(((uint8_t *)
ctx->output_table + oldsize), 0, (size - oldsize));
190 SCLogDebug(
"oldsize %d newsize %d ctx->allocated_state_count %u "
191 "ctx->state_count %u: shrink by %d bytes", oldsize,
192 newsize,
ctx->allocated_state_count,
ctx->state_count,
198 ctx->output_table = NULL;
201 ctx->output_table = ptmp;
204 static inline int SCACInitNewState(
MpmCtx *mpm_ctx)
209 if (
ctx->allocated_state_count <
ctx->state_count + 1) {
210 if (
ctx->allocated_state_count == 0)
211 ctx->allocated_state_count = 256;
213 ctx->allocated_state_count *= 2;
215 SCACReallocState(
ctx,
ctx->allocated_state_count);
219 if (
ctx->allocated_state_count > 260) {
226 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
230 return ctx->state_count++;
241 static void SCACSetOutputState(int32_t state, uint32_t pid,
MpmCtx *mpm_ctx)
248 for (i = 0; i < output_state->no_of_entries; i++) {
249 if (output_state->pids[i] == pid)
253 output_state->no_of_entries++;
255 output_state->no_of_entries *
sizeof(uint32_t));
257 SCFree(output_state->pids);
258 output_state->pids = NULL;
261 output_state->pids = ptmp;
263 output_state->pids[output_state->no_of_entries - 1] = pid;
276 static inline void SCACEnter(uint8_t *pattern, uint16_t pattern_len, uint32_t pid,
281 int32_t newstate = 0;
287 for (i = 0; i < pattern_len; i++) {
289 state =
ctx->goto_table[state][pattern[i]];
297 for (
p = i;
p < pattern_len;
p++) {
298 newstate = SCACInitNewState(mpm_ctx);
299 ctx->goto_table[state][pattern[
p]] = newstate;
305 SCACSetOutputState(state, pid, mpm_ctx);
314 static inline void SCACCreateGotoTable(
MpmCtx *mpm_ctx)
321 SCACEnter(
ctx->parray[i]->ci,
ctx->parray[i]->len,
322 ctx->parray[i]->id, mpm_ctx);
326 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
328 ctx->goto_table[0][ascii_code] = 0;
333 static inline void SCACDetermineLevel1Gap(
MpmCtx *mpm_ctx)
339 memset(map, 0,
sizeof(map));
342 map[
ctx->parray[u]->ci[0]] = 1;
344 for (u = 0; u < 256; u++) {
347 int32_t newstate = SCACInitNewState(mpm_ctx);
348 ctx->goto_table[0][u] = newstate;
361 static inline void SCACClubOutputStates(int32_t dst_state, int32_t src_state,
372 for (i = 0; i < output_src_state->no_of_entries; i++) {
373 for (j = 0; j < output_dst_state->no_of_entries; j++) {
374 if (output_src_state->pids[i] == output_dst_state->pids[j]) {
378 if (j == output_dst_state->no_of_entries) {
379 output_dst_state->no_of_entries++;
382 (output_dst_state->no_of_entries *
sizeof(uint32_t)));
384 SCFree(output_dst_state->pids);
385 output_dst_state->pids = NULL;
388 output_dst_state->pids = ptmp;
390 output_dst_state->pids[output_dst_state->no_of_entries - 1] =
391 output_src_state->pids[i];
402 static inline void SCACCreateFailureTable(
MpmCtx *mpm_ctx)
414 if (
ctx->failure_table == NULL) {
421 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
422 int32_t temp_state =
ctx->goto_table[0][ascii_code];
423 if (temp_state != 0) {
424 SCACEnqueue(q, temp_state);
425 ctx->failure_table[temp_state] = 0;
429 while (!SCACStateQueueIsEmpty(q)) {
431 r_state = SCACDequeue(q);
432 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
433 int32_t temp_state =
ctx->goto_table[r_state][ascii_code];
436 SCACEnqueue(q, temp_state);
437 state =
ctx->failure_table[r_state];
440 state =
ctx->failure_table[state];
441 ctx->failure_table[temp_state] =
ctx->goto_table[state][ascii_code];
442 SCACClubOutputStates(temp_state,
ctx->failure_table[temp_state],
455 static inline void SCACCreateDeltaTable(
MpmCtx *mpm_ctx)
461 if ((
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
462 ctx->state_table_u16 =
SCCalloc(
ctx->state_count,
sizeof(*
ctx->state_table_u16));
463 if (
ctx->state_table_u16 == NULL) {
471 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
474 ctx->state_table_u16[0][ascii_code] = temp_state;
476 SCACEnqueue(q, temp_state);
479 while (!SCACStateQueueIsEmpty(q)) {
480 r_state = SCACDequeue(q);
482 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
483 int32_t temp_state =
ctx->goto_table[r_state][ascii_code];
485 SCACEnqueue(q, temp_state);
487 ctx->state_table_u16[r_state][ascii_code] = (uint16_t)temp_state;
489 ctx->state_table_u16[r_state][ascii_code] =
490 ctx->state_table_u16[
ctx->failure_table[r_state]][ascii_code];
497 if (!(
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
501 ctx->state_table_u32 =
SCCalloc(
ctx->state_count,
sizeof(*
ctx->state_table_u32));
502 if (
ctx->state_table_u32 == NULL) {
510 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
512 ctx->state_table_u32[0][ascii_code] = temp_state;
514 SCACEnqueue(q, temp_state);
517 while (!SCACStateQueueIsEmpty(q)) {
518 r_state = SCACDequeue(q);
520 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
521 int32_t temp_state =
ctx->goto_table[r_state][ascii_code];
523 SCACEnqueue(q, temp_state);
524 ctx->state_table_u32[r_state][ascii_code] = temp_state;
526 ctx->state_table_u32[r_state][ascii_code] =
527 ctx->state_table_u32[
ctx->failure_table[r_state]][ascii_code];
535 static inline void SCACClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
540 uint32_t temp_state = 0;
542 if ((
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
543 for (state = 0; state <
ctx->state_count; state++) {
544 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
545 temp_state =
ctx->state_table_u16[state & 0x7FFF][ascii_code];
546 if (
ctx->output_table[temp_state & 0x7FFF].no_of_entries != 0)
547 ctx->state_table_u16[state & 0x7FFF][ascii_code] |= (1 << 15);
552 if (!(
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
553 for (state = 0; state <
ctx->state_count; state++) {
554 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
555 temp_state =
ctx->state_table_u32[state & 0x00FFFFFF][ascii_code];
556 if (
ctx->output_table[temp_state & 0x00FFFFFF].no_of_entries != 0)
557 ctx->state_table_u32[state & 0x00FFFFFF][ascii_code] |= (1 << 24);
563 static inline void SCACInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
569 for (state = 0; state <
ctx->state_count; state++) {
570 if (
ctx->output_table[state].no_of_entries == 0)
573 for (k = 0; k <
ctx->output_table[state].no_of_entries; k++) {
574 if (
ctx->pid_pat_list[
ctx->output_table[state].pids[k]].cs != NULL) {
583 static void SCACPrintDeltaTable(
MpmCtx *mpm_ctx)
588 printf(
"##############Delta Table##############\n");
589 for (i = 0; i <
ctx->state_count; i++) {
591 for (j = 0; j < 256; j++) {
592 if (SCACGetDelta(i, j, mpm_ctx) != 0) {
593 printf(
" %c -> %d\n", j, SCACGetDelta(i, j, mpm_ctx));
605 static void SCACPrepareStateTable(
MpmCtx *mpm_ctx)
610 SCACInitNewState(mpm_ctx);
612 SCACDetermineLevel1Gap(mpm_ctx);
615 SCACCreateGotoTable(mpm_ctx);
617 SCACCreateFailureTable(mpm_ctx);
619 SCACCreateDeltaTable(mpm_ctx);
621 SCACClubOutputStatePresenceWithDeltaTable(mpm_ctx);
624 SCACInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
627 SCACShrinkState(
ctx);
630 SCACPrintDeltaTable(mpm_ctx);
635 ctx->goto_table = NULL;
637 ctx->failure_table = NULL;
651 SCLogDebug(
"no patterns supplied to this mpm_ctx");
657 if (
ctx->parray == NULL)
663 uint32_t i = 0,
p = 0;
666 while(node != NULL) {
669 ctx->parray[
p++] = node;
679 ctx->single_state_size =
sizeof(int32_t) * 256;
683 if (
ctx->pid_pat_list == NULL) {
690 if (
ctx->pid_pat_list[
ctx->parray[i]->id].cs == NULL) {
693 memcpy(
ctx->pid_pat_list[
ctx->parray[i]->id].cs,
694 ctx->parray[i]->original_pat,
ctx->parray[i]->len);
695 ctx->pid_pat_list[
ctx->parray[i]->id].patlen =
ctx->parray[i]->len;
697 ctx->pid_pat_list[
ctx->parray[i]->id].offset =
ctx->parray[i]->offset;
698 ctx->pid_pat_list[
ctx->parray[i]->id].depth =
ctx->parray[i]->depth;
699 ctx->pid_pat_list[
ctx->parray[i]->id].endswith =
704 ctx->pid_pat_list[
ctx->parray[i]->id].sids_size =
ctx->parray[i]->sids_size;
705 ctx->pid_pat_list[
ctx->parray[i]->id].sids =
ctx->parray[i]->sids;
707 ctx->parray[i]->sids_size = 0;
708 ctx->parray[i]->sids = NULL;
712 SCACPrepareStateTable(mpm_ctx);
716 if (
ctx->parray[i] != NULL) {
725 ctx->pattern_id_bitarray_size = (mpm_ctx->
max_pat_id / 8) + 1;
726 SCLogDebug(
"ctx->pattern_id_bitarray_size %u",
ctx->pattern_id_bitarray_size);
741 if (mpm_ctx->
ctx != NULL)
745 if (mpm_ctx->
ctx == NULL) {
783 if (
ctx->parray != NULL) {
786 if (
ctx->parray[i] != NULL) {
797 if (
ctx->state_table_u16 != NULL) {
799 ctx->state_table_u16 = NULL;
805 if (
ctx->state_table_u32 != NULL) {
807 ctx->state_table_u32 = NULL;
814 if (
ctx->output_table != NULL) {
815 uint32_t state_count;
816 for (state_count = 0; state_count <
ctx->state_count; state_count++) {
817 if (
ctx->output_table[state_count].pids != NULL) {
818 SCFree(
ctx->output_table[state_count].pids);
824 if (
ctx->pid_pat_list != NULL) {
826 for (i = 0; i < (mpm_ctx->
max_pat_id + 1); i++) {
827 if (
ctx->pid_pat_list[i].cs != NULL)
829 if (
ctx->pid_pat_list[i].sids != NULL)
863 uint8_t *bitarray = (uint8_t *)mpm_thread_ctx->
ctx;
866 if (
ctx->state_count < 32767) {
869 for (uint32_t i = 0; i < buflen; i++) {
870 state = state_table_u16[state & 0x7FFF][
u8_tolower(buf[i])];
871 if (state & 0x8000) {
872 const uint32_t no_of_entries =
ctx->output_table[state & 0x7FFF].no_of_entries;
873 const uint32_t *pids =
ctx->output_table[state & 0x7FFF].pids;
874 for (uint32_t k = 0; k < no_of_entries; k++) {
889 if (!(bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8)))) {
890 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
903 if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
904 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
915 for (uint32_t i = 0; i < buflen; i++) {
916 state = state_table_u32[state & 0x00FFFFFF][
u8_tolower(buf[i])];
917 if (state & 0xFF000000) {
918 const uint32_t no_of_entries =
ctx->output_table[state & 0x00FFFFFF].no_of_entries;
919 const uint32_t *pids =
ctx->output_table[state & 0x00FFFFFF].pids;
920 for (uint32_t k = 0; k < no_of_entries; k++) {
936 if (!(bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8)))) {
937 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
950 if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
951 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1005 uint16_t
offset, uint16_t depth, uint32_t pid,
1015 printf(
"MPM AC Information:\n");
1016 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1017 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1018 printf(
" Sizeof:\n");
1019 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1020 printf(
" SCACCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACCtx));
1021 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1022 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1023 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1024 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1025 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1026 printf(
"Total states in the state table: %" PRIu32
"\n",
ctx->state_count);
1038 uint32_t size = (mpm_ctx->
max_pat_id / 8) + 1;
1040 uint8_t *bitarray =
SCCalloc(size,
sizeof(uint8_t));
1041 if (bitarray == NULL) {
1044 mpm_thread_ctx->
ctx = bitarray;
1054 mpm_thread_ctx->
ctx = NULL;
1089 static int SCACTest01(
void)
1096 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1105 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1107 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1110 (uint8_t *)buf, strlen(buf));
1115 printf(
"1 != %" PRIu32
" ",
cnt);
1118 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1123 static int SCACTest02(
void)
1130 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1139 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1141 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1143 (uint8_t *)buf, strlen(buf));
1148 printf(
"0 != %" PRIu32
" ",
cnt);
1151 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1156 static int SCACTest03(
void)
1163 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1176 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1178 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1180 (uint8_t *)buf, strlen(buf));
1185 printf(
"3 != %" PRIu32
" ",
cnt);
1188 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1193 static int SCACTest04(
void)
1200 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1210 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1212 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1214 (uint8_t *)buf, strlen(buf));
1219 printf(
"1 != %" PRIu32
" ",
cnt);
1222 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1227 static int SCACTest05(
void)
1234 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1244 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1246 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1248 (uint8_t *)buf, strlen(buf));
1253 printf(
"3 != %" PRIu32
" ",
cnt);
1256 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1261 static int SCACTest06(
void)
1268 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1276 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1278 const char *buf =
"abcd";
1280 (uint8_t *)buf, strlen(buf));
1285 printf(
"1 != %" PRIu32
" ",
cnt);
1288 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1293 static int SCACTest07(
void)
1299 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1312 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1314 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1320 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1322 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1324 (uint8_t *)buf, strlen(buf));
1328 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1333 static int SCACTest08(
void)
1340 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1349 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1357 printf(
"0 != %" PRIu32
" ",
cnt);
1360 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1365 static int SCACTest09(
void)
1372 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1381 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1384 (uint8_t *)
"ab", 2);
1389 printf(
"1 != %" PRIu32
" ",
cnt);
1392 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1397 static int SCACTest10(
void)
1404 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1413 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1415 const char *buf =
"01234567890123456789012345678901234567890123456789"
1416 "01234567890123456789012345678901234567890123456789"
1418 "01234567890123456789012345678901234567890123456789"
1419 "01234567890123456789012345678901234567890123456789";
1421 (uint8_t *)buf, strlen(buf));
1426 printf(
"1 != %" PRIu32
" ",
cnt);
1429 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1434 static int SCACTest11(
void)
1441 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1445 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1447 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1449 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1451 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1458 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1462 const char *buf =
"he";
1463 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1466 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1469 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1472 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1477 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1482 static int SCACTest12(
void)
1489 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1500 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1502 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1504 (uint8_t *)buf, strlen(buf));
1509 printf(
"2 != %" PRIu32
" ",
cnt);
1512 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1517 static int SCACTest13(
void)
1524 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1529 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1530 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1534 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1536 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1538 (uint8_t *)buf, strlen(buf));
1543 printf(
"1 != %" PRIu32
" ",
cnt);
1546 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1551 static int SCACTest14(
void)
1558 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1563 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1564 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1568 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1570 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1572 (uint8_t *)buf, strlen(buf));
1577 printf(
"1 != %" PRIu32
" ",
cnt);
1580 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1585 static int SCACTest15(
void)
1592 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1597 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1598 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1602 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1604 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1606 (uint8_t *)buf, strlen(buf));
1611 printf(
"1 != %" PRIu32
" ",
cnt);
1614 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1619 static int SCACTest16(
void)
1626 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1631 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1632 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1636 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1638 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1640 (uint8_t *)buf, strlen(buf));
1645 printf(
"1 != %" PRIu32
" ",
cnt);
1648 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1653 static int SCACTest17(
void)
1660 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1665 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1666 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1670 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1672 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1674 (uint8_t *)buf, strlen(buf));
1679 printf(
"1 != %" PRIu32
" ",
cnt);
1682 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1687 static int SCACTest18(
void)
1694 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1699 const char pat[] =
"abcde"
1705 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1709 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1711 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
1713 (uint8_t *)buf, strlen(buf));
1718 printf(
"1 != %" PRIu32
" ",
cnt);
1721 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1726 static int SCACTest19(
void)
1733 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1738 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1739 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1743 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1745 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1747 (uint8_t *)buf, strlen(buf));
1752 printf(
"1 != %" PRIu32
" ",
cnt);
1755 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1760 static int SCACTest20(
void)
1767 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1772 const char pat[] =
"AAAAA"
1779 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1783 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1785 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
1787 (uint8_t *)buf, strlen(buf));
1792 printf(
"1 != %" PRIu32
" ",
cnt);
1795 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1800 static int SCACTest21(
void)
1807 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1816 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1819 (uint8_t *)
"AA", 2);
1824 printf(
"1 != %" PRIu32
" ",
cnt);
1827 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1832 static int SCACTest22(
void)
1839 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1850 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1852 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1854 (uint8_t *)buf, strlen(buf));
1859 printf(
"2 != %" PRIu32
" ",
cnt);
1862 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1867 static int SCACTest23(
void)
1874 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1883 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1886 (uint8_t *)
"aa", 2);
1891 printf(
"1 != %" PRIu32
" ",
cnt);
1894 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1899 static int SCACTest24(
void)
1906 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1915 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1918 (uint8_t *)
"aa", 2);
1923 printf(
"1 != %" PRIu32
" ",
cnt);
1926 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1931 static int SCACTest25(
void)
1938 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1948 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1950 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1952 (uint8_t *)buf, strlen(buf));
1957 printf(
"3 != %" PRIu32
" ",
cnt);
1960 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1965 static int SCACTest26(
void)
1972 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1981 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1983 const char *buf =
"works";
1985 (uint8_t *)buf, strlen(buf));
1990 printf(
"3 != %" PRIu32
" ",
cnt);
1993 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1998 static int SCACTest27(
void)
2005 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2014 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2016 const char *buf =
"tone";
2018 (uint8_t *)buf, strlen(buf));
2023 printf(
"0 != %" PRIu32
" ",
cnt);
2026 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2031 static int SCACTest28(
void)
2037 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2046 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2048 const char *buf =
"tONE";
2050 (uint8_t *)buf, strlen(buf));
2054 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2059 static int SCACTest29(
void)
2061 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2062 uint16_t buflen =
sizeof(buf) - 1;
2076 "alert tcp any any -> any any "
2077 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2080 "alert tcp any any -> any any "
2081 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2101 static int SCACTest30(
void)
2107 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2116 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2118 const char *buf1 =
"abcdefghijklmnopqrstuvwxyz";
2119 uint32_t
cnt =
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf1, strlen(buf1));
2121 const char *buf2 =
"xyzxyzxyzxyzxyzxyzxyza";
2122 cnt =
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf2, strlen(buf2));
2126 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2131 void SCACRegisterTests(
void)