76 static void SCACRegisterTests(
void);
80 #define SC_AC_FAIL (-1)
82 #define STATE_QUEUE_CONTAINER_SIZE 65536
84 #define AC_CASE_MASK 0x80000000
85 #define AC_PID_MASK 0x7FFFFFFF
86 #define AC_CASE_BIT 31
88 static int construct_both_16_and_32_state_tables = 0;
105 static void SCACGetConfig(
void)
123 static inline size_t SCACCheckSafeSizetMult(
size_t a,
size_t b)
126 if (b > 0 && a > SIZE_MAX / b) {
127 SCLogError(
"%" PRIuMAX
" * %" PRIuMAX
" > %" PRIuMAX
128 " would overflow size_t calculating buffer size",
129 (uintmax_t)a, (uintmax_t)b, (uintmax_t)SIZE_MAX);
143 static inline int SCACReallocState(
SCACCtx *
ctx, uint32_t
cnt)
149 size = SCACCheckSafeSizetMult((
size_t)
cnt, (
size_t)
ctx->single_state_size);
154 ctx->goto_table = NULL;
157 ctx->goto_table = ptmp;
160 size_t oldsize = SCACCheckSafeSizetMult((
size_t)
ctx->state_count,
163 SCLogDebug(
"oldsize %"PRIuMAX
" size %"PRIuMAX
" cnt %d ctx->state_count %u",
164 (uintmax_t) oldsize, (uintmax_t) size,
cnt,
ctx->state_count);
171 ctx->output_table = NULL;
174 ctx->output_table = ptmp;
176 memset(((uint8_t *)
ctx->output_table + oldsize), 0, (size - oldsize));
201 SCLogDebug(
"oldsize %d newsize %d ctx->allocated_state_count %u "
202 "ctx->state_count %u: shrink by %d bytes", oldsize,
203 newsize,
ctx->allocated_state_count,
ctx->state_count,
209 ctx->output_table = NULL;
212 ctx->output_table = ptmp;
215 static inline int SCACInitNewState(
MpmCtx *mpm_ctx)
220 if (
ctx->allocated_state_count <
ctx->state_count + 1) {
221 if (
ctx->allocated_state_count == 0)
222 ctx->allocated_state_count = 256;
224 ctx->allocated_state_count *= 2;
226 SCACReallocState(
ctx,
ctx->allocated_state_count);
230 if (
ctx->allocated_state_count > 260) {
237 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
241 return ctx->state_count++;
252 static void SCACSetOutputState(int32_t state, uint32_t pid,
MpmCtx *mpm_ctx)
259 for (i = 0; i < output_state->no_of_entries; i++) {
260 if (output_state->pids[i] == pid)
264 output_state->no_of_entries++;
266 output_state->no_of_entries *
sizeof(uint32_t));
268 SCFree(output_state->pids);
269 output_state->pids = NULL;
272 output_state->pids = ptmp;
274 output_state->pids[output_state->no_of_entries - 1] = pid;
287 static inline void SCACEnter(uint8_t *pattern, uint16_t pattern_len, uint32_t pid,
292 int32_t newstate = 0;
298 for (i = 0; i < pattern_len; i++) {
300 state =
ctx->goto_table[state][pattern[i]];
308 for (p = i; p < pattern_len; p++) {
309 newstate = SCACInitNewState(mpm_ctx);
310 ctx->goto_table[state][pattern[p]] = newstate;
316 SCACSetOutputState(state, pid, mpm_ctx);
325 static inline void SCACCreateGotoTable(
MpmCtx *mpm_ctx)
332 SCACEnter(
ctx->parray[i]->ci,
ctx->parray[i]->len,
333 ctx->parray[i]->id, mpm_ctx);
337 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
339 ctx->goto_table[0][ascii_code] = 0;
344 static inline void SCACDetermineLevel1Gap(
MpmCtx *mpm_ctx)
350 memset(map, 0,
sizeof(map));
353 map[
ctx->parray[u]->ci[0]] = 1;
355 for (u = 0; u < 256; u++) {
358 int32_t newstate = SCACInitNewState(mpm_ctx);
359 ctx->goto_table[0][u] = newstate;
363 static inline int SCACStateQueueIsEmpty(
StateQueue *q)
371 static inline void SCACEnqueue(
StateQueue *q, int32_t state)
376 for (i = q->
bot; i < q->top; i++) {
377 if (q->
store[i] == state)
387 FatalError(
"Just ran out of space in the queue. Please file a bug report on this");
391 static inline int32_t SCACDequeue(
StateQueue *q)
397 FatalError(
"StateQueue behaving weirdly. Please file a bug report on this");
412 static inline void SCACClubOutputStates(int32_t dst_state, int32_t src_state,
423 for (i = 0; i < output_src_state->no_of_entries; i++) {
424 for (j = 0; j < output_dst_state->no_of_entries; j++) {
425 if (output_src_state->pids[i] == output_dst_state->pids[j]) {
429 if (j == output_dst_state->no_of_entries) {
430 output_dst_state->no_of_entries++;
433 (output_dst_state->no_of_entries *
sizeof(uint32_t)));
435 SCFree(output_dst_state->pids);
436 output_dst_state->pids = NULL;
439 output_dst_state->pids = ptmp;
441 output_dst_state->pids[output_dst_state->no_of_entries - 1] =
442 output_src_state->pids[i];
453 static inline void SCACCreateFailureTable(
MpmCtx *mpm_ctx)
468 if (
ctx->failure_table == NULL) {
475 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
476 int32_t temp_state =
ctx->goto_table[0][ascii_code];
477 if (temp_state != 0) {
478 SCACEnqueue(q, temp_state);
479 ctx->failure_table[temp_state] = 0;
483 while (!SCACStateQueueIsEmpty(q)) {
485 r_state = SCACDequeue(q);
486 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
487 int32_t temp_state =
ctx->goto_table[r_state][ascii_code];
490 SCACEnqueue(q, temp_state);
491 state =
ctx->failure_table[r_state];
494 state =
ctx->failure_table[state];
495 ctx->failure_table[temp_state] =
ctx->goto_table[state][ascii_code];
496 SCACClubOutputStates(temp_state,
ctx->failure_table[temp_state],
509 static inline void SCACCreateDeltaTable(
MpmCtx *mpm_ctx)
515 if ((
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
516 ctx->state_table_u16 =
SCCalloc(
ctx->state_count,
sizeof(*
ctx->state_table_u16));
517 if (
ctx->state_table_u16 == NULL) {
528 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
531 ctx->state_table_u16[0][ascii_code] = temp_state;
533 SCACEnqueue(q, temp_state);
536 while (!SCACStateQueueIsEmpty(q)) {
537 r_state = SCACDequeue(q);
539 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
540 int32_t temp_state =
ctx->goto_table[r_state][ascii_code];
542 SCACEnqueue(q, temp_state);
544 ctx->state_table_u16[r_state][ascii_code] = (uint16_t)temp_state;
546 ctx->state_table_u16[r_state][ascii_code] =
547 ctx->state_table_u16[
ctx->failure_table[r_state]][ascii_code];
554 if (!(
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
558 ctx->state_table_u32 =
SCCalloc(
ctx->state_count,
sizeof(*
ctx->state_table_u32));
559 if (
ctx->state_table_u32 == NULL) {
570 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
572 ctx->state_table_u32[0][ascii_code] = temp_state;
574 SCACEnqueue(q, temp_state);
577 while (!SCACStateQueueIsEmpty(q)) {
578 r_state = SCACDequeue(q);
580 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
581 int32_t temp_state =
ctx->goto_table[r_state][ascii_code];
583 SCACEnqueue(q, temp_state);
584 ctx->state_table_u32[r_state][ascii_code] = temp_state;
586 ctx->state_table_u32[r_state][ascii_code] =
587 ctx->state_table_u32[
ctx->failure_table[r_state]][ascii_code];
595 static inline void SCACClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
600 uint32_t temp_state = 0;
602 if ((
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
603 for (state = 0; state <
ctx->state_count; state++) {
604 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
605 temp_state =
ctx->state_table_u16[state & 0x7FFF][ascii_code];
606 if (
ctx->output_table[temp_state & 0x7FFF].no_of_entries != 0)
607 ctx->state_table_u16[state & 0x7FFF][ascii_code] |= (1 << 15);
612 if (!(
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
613 for (state = 0; state <
ctx->state_count; state++) {
614 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
615 temp_state =
ctx->state_table_u32[state & 0x00FFFFFF][ascii_code];
616 if (
ctx->output_table[temp_state & 0x00FFFFFF].no_of_entries != 0)
617 ctx->state_table_u32[state & 0x00FFFFFF][ascii_code] |= (1 << 24);
623 static inline void SCACInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
629 for (state = 0; state <
ctx->state_count; state++) {
630 if (
ctx->output_table[state].no_of_entries == 0)
633 for (k = 0; k <
ctx->output_table[state].no_of_entries; k++) {
634 if (
ctx->pid_pat_list[
ctx->output_table[state].pids[k]].cs != NULL) {
643 static void SCACPrintDeltaTable(
MpmCtx *mpm_ctx)
648 printf(
"##############Delta Table##############\n");
649 for (i = 0; i <
ctx->state_count; i++) {
651 for (j = 0; j < 256; j++) {
652 if (SCACGetDelta(i, j, mpm_ctx) != 0) {
653 printf(
" %c -> %d\n", j, SCACGetDelta(i, j, mpm_ctx));
665 static void SCACPrepareStateTable(
MpmCtx *mpm_ctx)
670 SCACInitNewState(mpm_ctx);
672 SCACDetermineLevel1Gap(mpm_ctx);
675 SCACCreateGotoTable(mpm_ctx);
677 SCACCreateFailureTable(mpm_ctx);
679 SCACCreateDeltaTable(mpm_ctx);
681 SCACClubOutputStatePresenceWithDeltaTable(mpm_ctx);
684 SCACInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
687 SCACShrinkState(
ctx);
690 SCACPrintDeltaTable(mpm_ctx);
695 ctx->goto_table = NULL;
697 ctx->failure_table = NULL;
710 SCLogDebug(
"no patterns supplied to this mpm_ctx");
716 if (
ctx->parray == NULL)
722 uint32_t i = 0, p = 0;
725 while(node != NULL) {
728 ctx->parray[p++] = node;
738 ctx->single_state_size =
sizeof(int32_t) * 256;
742 if (
ctx->pid_pat_list == NULL) {
749 if (
ctx->pid_pat_list[
ctx->parray[i]->id].cs == NULL) {
752 memcpy(
ctx->pid_pat_list[
ctx->parray[i]->id].cs,
753 ctx->parray[i]->original_pat,
ctx->parray[i]->len);
754 ctx->pid_pat_list[
ctx->parray[i]->id].patlen =
ctx->parray[i]->len;
756 ctx->pid_pat_list[
ctx->parray[i]->id].offset =
ctx->parray[i]->offset;
757 ctx->pid_pat_list[
ctx->parray[i]->id].depth =
ctx->parray[i]->depth;
758 ctx->pid_pat_list[
ctx->parray[i]->id].endswith =
763 ctx->pid_pat_list[
ctx->parray[i]->id].sids_size =
ctx->parray[i]->sids_size;
764 ctx->pid_pat_list[
ctx->parray[i]->id].sids =
ctx->parray[i]->sids;
766 ctx->parray[i]->sids_size = 0;
767 ctx->parray[i]->sids = NULL;
771 SCACPrepareStateTable(mpm_ctx);
775 if (
ctx->parray[i] != NULL) {
784 ctx->pattern_id_bitarray_size = (mpm_ctx->
max_pat_id / 8) + 1;
785 SCLogDebug(
"ctx->pattern_id_bitarray_size %u",
ctx->pattern_id_bitarray_size);
800 if (mpm_ctx->
ctx != NULL)
804 if (mpm_ctx->
ctx == NULL) {
842 if (
ctx->parray != NULL) {
845 if (
ctx->parray[i] != NULL) {
856 if (
ctx->state_table_u16 != NULL) {
858 ctx->state_table_u16 = NULL;
864 if (
ctx->state_table_u32 != NULL) {
866 ctx->state_table_u32 = NULL;
873 if (
ctx->output_table != NULL) {
874 uint32_t state_count;
875 for (state_count = 0; state_count <
ctx->state_count; state_count++) {
876 if (
ctx->output_table[state_count].pids != NULL) {
877 SCFree(
ctx->output_table[state_count].pids);
883 if (
ctx->pid_pat_list != NULL) {
885 for (i = 0; i < (mpm_ctx->
max_pat_id + 1); i++) {
886 if (
ctx->pid_pat_list[i].cs != NULL)
888 if (
ctx->pid_pat_list[i].sids != NULL)
923 uint8_t bitarray[
ctx->pattern_id_bitarray_size];
924 memset(bitarray, 0,
ctx->pattern_id_bitarray_size);
926 if (
ctx->state_count < 32767) {
929 for (uint32_t i = 0; i < buflen; i++) {
930 state = state_table_u16[state & 0x7FFF][
u8_tolower(buf[i])];
931 if (state & 0x8000) {
932 const uint32_t no_of_entries =
ctx->output_table[state & 0x7FFF].no_of_entries;
933 const uint32_t *pids =
ctx->output_table[state & 0x7FFF].pids;
934 for (uint32_t k = 0; k < no_of_entries; k++) {
949 if (!(bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8)))) {
950 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
963 if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
964 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
975 for (uint32_t i = 0; i < buflen; i++) {
976 state = state_table_u32[state & 0x00FFFFFF][
u8_tolower(buf[i])];
977 if (state & 0xFF000000) {
978 const uint32_t no_of_entries =
ctx->output_table[state & 0x00FFFFFF].no_of_entries;
979 const uint32_t *pids =
ctx->output_table[state & 0x00FFFFFF].pids;
980 for (uint32_t k = 0; k < no_of_entries; k++) {
982 const uint32_t lower_pid = pids[k] & 0x0000FFFF;
996 if (!(bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8)))) {
997 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1010 if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
1011 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1041 uint16_t
offset, uint16_t depth, uint32_t pid,
1066 uint16_t
offset, uint16_t depth, uint32_t pid,
1076 printf(
"MPM AC Information:\n");
1077 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1078 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1079 printf(
" Sizeof:\n");
1080 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1081 printf(
" SCACCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACCtx));
1082 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1083 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1084 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1085 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1086 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1087 printf(
"Total states in the state table: %" PRIu32
"\n",
ctx->state_count);
1118 static int SCACTest01(
void)
1125 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1135 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1138 (uint8_t *)buf, strlen(buf));
1143 printf(
"1 != %" PRIu32
" ",
cnt);
1150 static int SCACTest02(
void)
1157 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1167 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1169 (uint8_t *)buf, strlen(buf));
1174 printf(
"0 != %" PRIu32
" ",
cnt);
1181 static int SCACTest03(
void)
1188 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1202 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1204 (uint8_t *)buf, strlen(buf));
1209 printf(
"3 != %" PRIu32
" ",
cnt);
1216 static int SCACTest04(
void)
1223 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1234 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1236 (uint8_t *)buf, strlen(buf));
1241 printf(
"1 != %" PRIu32
" ",
cnt);
1248 static int SCACTest05(
void)
1255 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1266 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1268 (uint8_t *)buf, strlen(buf));
1273 printf(
"3 != %" PRIu32
" ",
cnt);
1280 static int SCACTest06(
void)
1287 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1296 const char *buf =
"abcd";
1298 (uint8_t *)buf, strlen(buf));
1303 printf(
"1 != %" PRIu32
" ",
cnt);
1310 static int SCACTest07(
void)
1316 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1329 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1331 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1338 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1340 (uint8_t *)buf, strlen(buf));
1348 static int SCACTest08(
void)
1355 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1371 printf(
"0 != %" PRIu32
" ",
cnt);
1378 static int SCACTest09(
void)
1385 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1396 (uint8_t *)
"ab", 2);
1401 printf(
"1 != %" PRIu32
" ",
cnt);
1408 static int SCACTest10(
void)
1415 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1425 const char *buf =
"01234567890123456789012345678901234567890123456789"
1426 "01234567890123456789012345678901234567890123456789"
1428 "01234567890123456789012345678901234567890123456789"
1429 "01234567890123456789012345678901234567890123456789";
1431 (uint8_t *)buf, strlen(buf));
1436 printf(
"1 != %" PRIu32
" ",
cnt);
1443 static int SCACTest11(
void)
1450 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1454 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1456 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1458 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1460 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1469 const char *buf =
"he";
1470 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1473 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1476 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1479 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1488 static int SCACTest12(
void)
1495 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1507 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1509 (uint8_t *)buf, strlen(buf));
1514 printf(
"2 != %" PRIu32
" ",
cnt);
1521 static int SCACTest13(
void)
1528 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1533 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1534 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1539 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1541 (uint8_t *)buf, strlen(buf));
1546 printf(
"1 != %" PRIu32
" ",
cnt);
1553 static int SCACTest14(
void)
1560 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1565 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1566 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1571 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1573 (uint8_t *)buf, strlen(buf));
1578 printf(
"1 != %" PRIu32
" ",
cnt);
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);
1603 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1605 (uint8_t *)buf, strlen(buf));
1610 printf(
"1 != %" PRIu32
" ",
cnt);
1617 static int SCACTest16(
void)
1624 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1629 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1630 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1635 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1637 (uint8_t *)buf, strlen(buf));
1642 printf(
"1 != %" PRIu32
" ",
cnt);
1649 static int SCACTest17(
void)
1656 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1661 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1662 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1667 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1669 (uint8_t *)buf, strlen(buf));
1674 printf(
"1 != %" PRIu32
" ",
cnt);
1681 static int SCACTest18(
void)
1688 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1693 const char pat[] =
"abcde"
1699 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1704 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
1706 (uint8_t *)buf, strlen(buf));
1711 printf(
"1 != %" PRIu32
" ",
cnt);
1718 static int SCACTest19(
void)
1725 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1730 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1731 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1736 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1738 (uint8_t *)buf, strlen(buf));
1743 printf(
"1 != %" PRIu32
" ",
cnt);
1750 static int SCACTest20(
void)
1757 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1762 const char pat[] =
"AAAAA"
1769 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1774 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
1776 (uint8_t *)buf, strlen(buf));
1781 printf(
"1 != %" PRIu32
" ",
cnt);
1788 static int SCACTest21(
void)
1795 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1806 (uint8_t *)
"AA", 2);
1811 printf(
"1 != %" PRIu32
" ",
cnt);
1818 static int SCACTest22(
void)
1825 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1837 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1839 (uint8_t *)buf, strlen(buf));
1844 printf(
"2 != %" PRIu32
" ",
cnt);
1851 static int SCACTest23(
void)
1858 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1869 (uint8_t *)
"aa", 2);
1874 printf(
"1 != %" PRIu32
" ",
cnt);
1881 static int SCACTest24(
void)
1888 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1899 (uint8_t *)
"aa", 2);
1904 printf(
"1 != %" PRIu32
" ",
cnt);
1911 static int SCACTest25(
void)
1918 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1929 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1931 (uint8_t *)buf, strlen(buf));
1936 printf(
"3 != %" PRIu32
" ",
cnt);
1943 static int SCACTest26(
void)
1950 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1960 const char *buf =
"works";
1962 (uint8_t *)buf, strlen(buf));
1967 printf(
"3 != %" PRIu32
" ",
cnt);
1974 static int SCACTest27(
void)
1981 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1991 const char *buf =
"tone";
1993 (uint8_t *)buf, strlen(buf));
1998 printf(
"0 != %" PRIu32
" ",
cnt);
2005 static int SCACTest28(
void)
2011 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2021 const char *buf =
"tONE";
2023 (uint8_t *)buf, strlen(buf));
2031 static int SCACTest29(
void)
2033 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2034 uint16_t buflen =
sizeof(buf) - 1;
2038 memset(&th_v, 0,
sizeof(th_v));
2047 "alert tcp any any -> any any "
2048 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2051 "alert tcp any any -> any any "
2052 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2072 static int SCACTest30(
void)
2078 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2088 const char *buf1 =
"abcdefghijklmnopqrstuvwxyz";
2089 uint32_t
cnt =
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf1, strlen(buf1));
2091 const char *buf2 =
"xyzxyzxyzxyzxyzxyzxyza";
2092 cnt =
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf2, strlen(buf2));
2100 void SCACRegisterTests(
void)