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;
711 SCLogDebug(
"no patterns supplied to this mpm_ctx");
717 if (
ctx->parray == NULL)
723 uint32_t i = 0, p = 0;
726 while(node != NULL) {
729 ctx->parray[p++] = node;
739 ctx->single_state_size =
sizeof(int32_t) * 256;
743 if (
ctx->pid_pat_list == NULL) {
750 if (
ctx->pid_pat_list[
ctx->parray[i]->id].cs == NULL) {
753 memcpy(
ctx->pid_pat_list[
ctx->parray[i]->id].cs,
754 ctx->parray[i]->original_pat,
ctx->parray[i]->len);
755 ctx->pid_pat_list[
ctx->parray[i]->id].patlen =
ctx->parray[i]->len;
757 ctx->pid_pat_list[
ctx->parray[i]->id].offset =
ctx->parray[i]->offset;
758 ctx->pid_pat_list[
ctx->parray[i]->id].depth =
ctx->parray[i]->depth;
759 ctx->pid_pat_list[
ctx->parray[i]->id].endswith =
764 ctx->pid_pat_list[
ctx->parray[i]->id].sids_size =
ctx->parray[i]->sids_size;
765 ctx->pid_pat_list[
ctx->parray[i]->id].sids =
ctx->parray[i]->sids;
767 ctx->parray[i]->sids_size = 0;
768 ctx->parray[i]->sids = NULL;
772 SCACPrepareStateTable(mpm_ctx);
776 if (
ctx->parray[i] != NULL) {
785 ctx->pattern_id_bitarray_size = (mpm_ctx->
max_pat_id / 8) + 1;
786 SCLogDebug(
"ctx->pattern_id_bitarray_size %u",
ctx->pattern_id_bitarray_size);
801 if (mpm_ctx->
ctx != NULL)
805 if (mpm_ctx->
ctx == NULL) {
843 if (
ctx->parray != NULL) {
846 if (
ctx->parray[i] != NULL) {
857 if (
ctx->state_table_u16 != NULL) {
859 ctx->state_table_u16 = NULL;
865 if (
ctx->state_table_u32 != NULL) {
867 ctx->state_table_u32 = NULL;
874 if (
ctx->output_table != NULL) {
875 uint32_t state_count;
876 for (state_count = 0; state_count <
ctx->state_count; state_count++) {
877 if (
ctx->output_table[state_count].pids != NULL) {
878 SCFree(
ctx->output_table[state_count].pids);
884 if (
ctx->pid_pat_list != NULL) {
886 for (i = 0; i < (mpm_ctx->
max_pat_id + 1); i++) {
887 if (
ctx->pid_pat_list[i].cs != NULL)
889 if (
ctx->pid_pat_list[i].sids != NULL)
924 uint8_t bitarray[
ctx->pattern_id_bitarray_size];
925 memset(bitarray, 0,
ctx->pattern_id_bitarray_size);
927 if (
ctx->state_count < 32767) {
930 for (uint32_t i = 0; i < buflen; i++) {
931 state = state_table_u16[state & 0x7FFF][
u8_tolower(buf[i])];
932 if (state & 0x8000) {
933 const uint32_t no_of_entries =
ctx->output_table[state & 0x7FFF].no_of_entries;
934 const uint32_t *pids =
ctx->output_table[state & 0x7FFF].pids;
935 for (uint32_t k = 0; k < no_of_entries; k++) {
950 if (!(bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8)))) {
951 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
964 if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
965 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
976 for (uint32_t i = 0; i < buflen; i++) {
977 state = state_table_u32[state & 0x00FFFFFF][
u8_tolower(buf[i])];
978 if (state & 0xFF000000) {
979 const uint32_t no_of_entries =
ctx->output_table[state & 0x00FFFFFF].no_of_entries;
980 const uint32_t *pids =
ctx->output_table[state & 0x00FFFFFF].pids;
981 for (uint32_t k = 0; k < no_of_entries; k++) {
983 const uint32_t lower_pid = pids[k] & 0x0000FFFF;
997 if (!(bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8)))) {
998 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1011 if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
1012 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1042 uint16_t
offset, uint16_t depth, uint32_t pid,
1067 uint16_t
offset, uint16_t depth, uint32_t pid,
1077 printf(
"MPM AC Information:\n");
1078 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1079 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1080 printf(
" Sizeof:\n");
1081 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1082 printf(
" SCACCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACCtx));
1083 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1084 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1085 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1086 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1087 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1088 printf(
"Total states in the state table: %" PRIu32
"\n",
ctx->state_count);
1123 static int SCACTest01(
void)
1130 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1140 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1143 (uint8_t *)buf, strlen(buf));
1148 printf(
"1 != %" PRIu32
" ",
cnt);
1155 static int SCACTest02(
void)
1162 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1172 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1174 (uint8_t *)buf, strlen(buf));
1179 printf(
"0 != %" PRIu32
" ",
cnt);
1186 static int SCACTest03(
void)
1193 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1207 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1209 (uint8_t *)buf, strlen(buf));
1214 printf(
"3 != %" PRIu32
" ",
cnt);
1221 static int SCACTest04(
void)
1228 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1239 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1241 (uint8_t *)buf, strlen(buf));
1246 printf(
"1 != %" PRIu32
" ",
cnt);
1253 static int SCACTest05(
void)
1260 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1271 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1273 (uint8_t *)buf, strlen(buf));
1278 printf(
"3 != %" PRIu32
" ",
cnt);
1285 static int SCACTest06(
void)
1292 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1301 const char *buf =
"abcd";
1303 (uint8_t *)buf, strlen(buf));
1308 printf(
"1 != %" PRIu32
" ",
cnt);
1315 static int SCACTest07(
void)
1321 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1334 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1336 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1343 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1345 (uint8_t *)buf, strlen(buf));
1353 static int SCACTest08(
void)
1360 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1376 printf(
"0 != %" PRIu32
" ",
cnt);
1383 static int SCACTest09(
void)
1390 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1401 (uint8_t *)
"ab", 2);
1406 printf(
"1 != %" PRIu32
" ",
cnt);
1413 static int SCACTest10(
void)
1420 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1430 const char *buf =
"01234567890123456789012345678901234567890123456789"
1431 "01234567890123456789012345678901234567890123456789"
1433 "01234567890123456789012345678901234567890123456789"
1434 "01234567890123456789012345678901234567890123456789";
1436 (uint8_t *)buf, strlen(buf));
1441 printf(
"1 != %" PRIu32
" ",
cnt);
1448 static int SCACTest11(
void)
1455 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1459 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1461 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1463 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1465 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1474 const char *buf =
"he";
1475 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1478 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1481 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1484 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1493 static int SCACTest12(
void)
1500 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1512 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1514 (uint8_t *)buf, strlen(buf));
1519 printf(
"2 != %" PRIu32
" ",
cnt);
1526 static int SCACTest13(
void)
1533 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1538 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1539 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1544 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1546 (uint8_t *)buf, strlen(buf));
1551 printf(
"1 != %" PRIu32
" ",
cnt);
1558 static int SCACTest14(
void)
1565 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1570 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1571 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1576 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1578 (uint8_t *)buf, strlen(buf));
1583 printf(
"1 != %" PRIu32
" ",
cnt);
1590 static int SCACTest15(
void)
1597 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1602 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1603 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1608 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1610 (uint8_t *)buf, strlen(buf));
1615 printf(
"1 != %" PRIu32
" ",
cnt);
1622 static int SCACTest16(
void)
1629 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1634 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1635 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1640 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1642 (uint8_t *)buf, strlen(buf));
1647 printf(
"1 != %" PRIu32
" ",
cnt);
1654 static int SCACTest17(
void)
1661 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1666 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1667 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1672 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1674 (uint8_t *)buf, strlen(buf));
1679 printf(
"1 != %" PRIu32
" ",
cnt);
1686 static int SCACTest18(
void)
1693 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1698 const char pat[] =
"abcde"
1704 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1709 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
1711 (uint8_t *)buf, strlen(buf));
1716 printf(
"1 != %" PRIu32
" ",
cnt);
1723 static int SCACTest19(
void)
1730 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1735 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1736 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1741 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1743 (uint8_t *)buf, strlen(buf));
1748 printf(
"1 != %" PRIu32
" ",
cnt);
1755 static int SCACTest20(
void)
1762 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1767 const char pat[] =
"AAAAA"
1774 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1779 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
1781 (uint8_t *)buf, strlen(buf));
1786 printf(
"1 != %" PRIu32
" ",
cnt);
1793 static int SCACTest21(
void)
1800 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1811 (uint8_t *)
"AA", 2);
1816 printf(
"1 != %" PRIu32
" ",
cnt);
1823 static int SCACTest22(
void)
1830 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1842 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1844 (uint8_t *)buf, strlen(buf));
1849 printf(
"2 != %" PRIu32
" ",
cnt);
1856 static int SCACTest23(
void)
1863 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1874 (uint8_t *)
"aa", 2);
1879 printf(
"1 != %" PRIu32
" ",
cnt);
1886 static int SCACTest24(
void)
1893 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1904 (uint8_t *)
"aa", 2);
1909 printf(
"1 != %" PRIu32
" ",
cnt);
1916 static int SCACTest25(
void)
1923 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1934 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1936 (uint8_t *)buf, strlen(buf));
1941 printf(
"3 != %" PRIu32
" ",
cnt);
1948 static int SCACTest26(
void)
1955 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1965 const char *buf =
"works";
1967 (uint8_t *)buf, strlen(buf));
1972 printf(
"3 != %" PRIu32
" ",
cnt);
1979 static int SCACTest27(
void)
1986 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1996 const char *buf =
"tone";
1998 (uint8_t *)buf, strlen(buf));
2003 printf(
"0 != %" PRIu32
" ",
cnt);
2010 static int SCACTest28(
void)
2016 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2026 const char *buf =
"tONE";
2028 (uint8_t *)buf, strlen(buf));
2036 static int SCACTest29(
void)
2038 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2039 uint16_t buflen =
sizeof(buf) - 1;
2043 memset(&th_v, 0,
sizeof(th_v));
2052 "alert tcp any any -> any any "
2053 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2056 "alert tcp any any -> any any "
2057 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2077 static int SCACTest30(
void)
2083 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2093 const char *buf1 =
"abcdefghijklmnopqrstuvwxyz";
2094 uint32_t
cnt =
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf1, strlen(buf1));
2096 const char *buf2 =
"xyzxyzxyzxyzxyzxyzxyza";
2097 cnt =
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf2, strlen(buf2));
2105 void SCACRegisterTests(
void)