69 MpmCtx *,
const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t,
SigIntId, uint8_t);
77 static void SCACRegisterTests(
void);
81 #define SC_AC_FAIL (-1)
83 #define AC_CASE_MASK 0x80000000
84 #define AC_PID_MASK 0x7FFFFFFF
85 #define AC_CASE_BIT 31
87 static int construct_both_16_and_32_state_tables = 0;
95 static void SCACGetConfig(
void)
113 static inline size_t SCACCheckSafeSizetMult(
size_t a,
size_t b)
116 if (b > 0 && a > SIZE_MAX / b) {
117 SCLogError(
"%" PRIuMAX
" * %" PRIuMAX
" > %" PRIuMAX
118 " would overflow size_t calculating buffer size",
119 (uintmax_t)a, (uintmax_t)b, (uintmax_t)SIZE_MAX);
133 static inline int SCACReallocState(
SCACCtx *
ctx, uint32_t
cnt)
139 size = SCACCheckSafeSizetMult((
size_t)
cnt, (
size_t)
ctx->single_state_size);
144 ctx->goto_table = NULL;
147 ctx->goto_table = ptmp;
150 size_t oldsize = SCACCheckSafeSizetMult((
size_t)
ctx->state_count,
153 SCLogDebug(
"oldsize %"PRIuMAX
" size %"PRIuMAX
" cnt %d ctx->state_count %u",
154 (uintmax_t) oldsize, (uintmax_t) size,
cnt,
ctx->state_count);
161 ctx->output_table = NULL;
164 ctx->output_table = ptmp;
166 memset(((uint8_t *)
ctx->output_table + oldsize), 0, (size - oldsize));
191 SCLogDebug(
"oldsize %d newsize %d ctx->allocated_state_count %u "
192 "ctx->state_count %u: shrink by %d bytes", oldsize,
193 newsize,
ctx->allocated_state_count,
ctx->state_count,
199 ctx->output_table = NULL;
202 ctx->output_table = ptmp;
205 static inline int SCACInitNewState(
MpmCtx *mpm_ctx)
210 if (
ctx->allocated_state_count <
ctx->state_count + 1) {
211 if (
ctx->allocated_state_count == 0)
212 ctx->allocated_state_count = 256;
214 ctx->allocated_state_count *= 2;
216 SCACReallocState(
ctx,
ctx->allocated_state_count);
220 if (
ctx->allocated_state_count > 260) {
227 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
231 return ctx->state_count++;
242 static void SCACSetOutputState(int32_t state, uint32_t pid,
MpmCtx *mpm_ctx)
249 for (i = 0; i < output_state->no_of_entries; i++) {
250 if (output_state->pids[i] == pid)
254 output_state->no_of_entries++;
256 output_state->no_of_entries *
sizeof(uint32_t));
258 SCFree(output_state->pids);
259 output_state->pids = NULL;
262 output_state->pids = ptmp;
264 output_state->pids[output_state->no_of_entries - 1] = pid;
277 static inline void SCACEnter(uint8_t *pattern, uint16_t pattern_len, uint32_t pid,
282 int32_t newstate = 0;
288 for (i = 0; i < pattern_len; i++) {
290 state =
ctx->goto_table[state][pattern[i]];
298 for (
p = i;
p < pattern_len;
p++) {
299 newstate = SCACInitNewState(mpm_ctx);
300 ctx->goto_table[state][pattern[
p]] = newstate;
306 SCACSetOutputState(state, pid, mpm_ctx);
315 static inline void SCACCreateGotoTable(
MpmCtx *mpm_ctx)
322 SCACEnter(
ctx->parray[i]->ci,
ctx->parray[i]->len,
323 ctx->parray[i]->id, mpm_ctx);
327 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
329 ctx->goto_table[0][ascii_code] = 0;
334 static inline void SCACDetermineLevel1Gap(
MpmCtx *mpm_ctx)
340 memset(map, 0,
sizeof(map));
343 map[
ctx->parray[u]->ci[0]] = 1;
345 for (u = 0; u < 256; u++) {
348 int32_t newstate = SCACInitNewState(mpm_ctx);
349 ctx->goto_table[0][u] = newstate;
362 static inline void SCACClubOutputStates(int32_t dst_state, int32_t src_state,
373 for (i = 0; i < output_src_state->no_of_entries; i++) {
374 for (j = 0; j < output_dst_state->no_of_entries; j++) {
375 if (output_src_state->pids[i] == output_dst_state->pids[j]) {
379 if (j == output_dst_state->no_of_entries) {
380 output_dst_state->no_of_entries++;
383 (output_dst_state->no_of_entries *
sizeof(uint32_t)));
385 SCFree(output_dst_state->pids);
386 output_dst_state->pids = NULL;
389 output_dst_state->pids = ptmp;
391 output_dst_state->pids[output_dst_state->no_of_entries - 1] =
392 output_src_state->pids[i];
403 static inline void SCACCreateFailureTable(
MpmCtx *mpm_ctx)
415 if (
ctx->failure_table == NULL) {
422 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
423 int32_t temp_state =
ctx->goto_table[0][ascii_code];
424 if (temp_state != 0) {
425 SCACEnqueue(q, temp_state);
426 ctx->failure_table[temp_state] = 0;
430 while (!SCACStateQueueIsEmpty(q)) {
432 r_state = SCACDequeue(q);
433 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
434 int32_t temp_state =
ctx->goto_table[r_state][ascii_code];
437 SCACEnqueue(q, temp_state);
438 state =
ctx->failure_table[r_state];
441 state =
ctx->failure_table[state];
442 ctx->failure_table[temp_state] =
ctx->goto_table[state][ascii_code];
443 SCACClubOutputStates(temp_state,
ctx->failure_table[temp_state],
456 static inline void SCACCreateDeltaTable(
MpmCtx *mpm_ctx)
462 if ((
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
463 ctx->state_table_u16 =
SCCalloc(
ctx->state_count,
sizeof(*
ctx->state_table_u16));
464 if (
ctx->state_table_u16 == NULL) {
472 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
475 ctx->state_table_u16[0][ascii_code] = temp_state;
477 SCACEnqueue(q, temp_state);
480 while (!SCACStateQueueIsEmpty(q)) {
481 r_state = SCACDequeue(q);
483 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
484 int32_t temp_state =
ctx->goto_table[r_state][ascii_code];
486 SCACEnqueue(q, temp_state);
488 ctx->state_table_u16[r_state][ascii_code] = (uint16_t)temp_state;
490 ctx->state_table_u16[r_state][ascii_code] =
491 ctx->state_table_u16[
ctx->failure_table[r_state]][ascii_code];
498 if (!(
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
502 ctx->state_table_u32 =
SCCalloc(
ctx->state_count,
sizeof(*
ctx->state_table_u32));
503 if (
ctx->state_table_u32 == NULL) {
511 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
513 ctx->state_table_u32[0][ascii_code] = temp_state;
515 SCACEnqueue(q, temp_state);
518 while (!SCACStateQueueIsEmpty(q)) {
519 r_state = SCACDequeue(q);
521 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
522 int32_t temp_state =
ctx->goto_table[r_state][ascii_code];
524 SCACEnqueue(q, temp_state);
525 ctx->state_table_u32[r_state][ascii_code] = temp_state;
527 ctx->state_table_u32[r_state][ascii_code] =
528 ctx->state_table_u32[
ctx->failure_table[r_state]][ascii_code];
536 static inline void SCACClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
541 uint32_t temp_state = 0;
543 if ((
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
544 for (state = 0; state <
ctx->state_count; state++) {
545 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
546 temp_state =
ctx->state_table_u16[state & 0x7FFF][ascii_code];
547 if (
ctx->output_table[temp_state & 0x7FFF].no_of_entries != 0)
548 ctx->state_table_u16[state & 0x7FFF][ascii_code] |= (1 << 15);
553 if (!(
ctx->state_count < 32767) || construct_both_16_and_32_state_tables) {
554 for (state = 0; state <
ctx->state_count; state++) {
555 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
556 temp_state =
ctx->state_table_u32[state & 0x00FFFFFF][ascii_code];
557 if (
ctx->output_table[temp_state & 0x00FFFFFF].no_of_entries != 0)
558 ctx->state_table_u32[state & 0x00FFFFFF][ascii_code] |= (1 << 24);
564 static inline void SCACInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
570 for (state = 0; state <
ctx->state_count; state++) {
571 if (
ctx->output_table[state].no_of_entries == 0)
574 for (k = 0; k <
ctx->output_table[state].no_of_entries; k++) {
575 if (
ctx->pid_pat_list[
ctx->output_table[state].pids[k]].cs != NULL) {
584 static void SCACPrintDeltaTable(
MpmCtx *mpm_ctx)
589 printf(
"##############Delta Table##############\n");
590 for (i = 0; i <
ctx->state_count; i++) {
592 for (j = 0; j < 256; j++) {
593 if (SCACGetDelta(i, j, mpm_ctx) != 0) {
594 printf(
" %c -> %d\n", j, SCACGetDelta(i, j, mpm_ctx));
606 static void SCACPrepareStateTable(
MpmCtx *mpm_ctx)
611 SCACInitNewState(mpm_ctx);
613 SCACDetermineLevel1Gap(mpm_ctx);
616 SCACCreateGotoTable(mpm_ctx);
618 SCACCreateFailureTable(mpm_ctx);
620 SCACCreateDeltaTable(mpm_ctx);
622 SCACClubOutputStatePresenceWithDeltaTable(mpm_ctx);
625 SCACInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
628 SCACShrinkState(
ctx);
631 SCACPrintDeltaTable(mpm_ctx);
636 ctx->goto_table = NULL;
638 ctx->failure_table = NULL;
652 SCLogDebug(
"no patterns supplied to this mpm_ctx");
658 if (
ctx->parray == NULL)
664 uint32_t i = 0,
p = 0;
667 while(node != NULL) {
670 ctx->parray[
p++] = node;
680 ctx->single_state_size =
sizeof(int32_t) * 256;
684 if (
ctx->pid_pat_list == NULL) {
691 if (
ctx->pid_pat_list[
ctx->parray[i]->id].cs == NULL) {
694 memcpy(
ctx->pid_pat_list[
ctx->parray[i]->id].cs,
695 ctx->parray[i]->original_pat,
ctx->parray[i]->len);
696 ctx->pid_pat_list[
ctx->parray[i]->id].patlen =
ctx->parray[i]->len;
698 ctx->pid_pat_list[
ctx->parray[i]->id].offset =
ctx->parray[i]->offset;
699 ctx->pid_pat_list[
ctx->parray[i]->id].depth =
ctx->parray[i]->depth;
700 ctx->pid_pat_list[
ctx->parray[i]->id].endswith =
705 ctx->pid_pat_list[
ctx->parray[i]->id].sids_size =
ctx->parray[i]->sids_size;
706 ctx->pid_pat_list[
ctx->parray[i]->id].sids =
ctx->parray[i]->sids;
708 ctx->parray[i]->sids_size = 0;
709 ctx->parray[i]->sids = NULL;
713 SCACPrepareStateTable(mpm_ctx);
717 if (
ctx->parray[i] != NULL) {
726 ctx->pattern_id_bitarray_size = (mpm_ctx->
max_pat_id / 8) + 1;
727 SCLogDebug(
"ctx->pattern_id_bitarray_size %u",
ctx->pattern_id_bitarray_size);
742 if (mpm_ctx->
ctx != NULL)
746 if (mpm_ctx->
ctx == NULL) {
784 if (
ctx->parray != NULL) {
787 if (
ctx->parray[i] != NULL) {
798 if (
ctx->state_table_u16 != NULL) {
800 ctx->state_table_u16 = NULL;
806 if (
ctx->state_table_u32 != NULL) {
808 ctx->state_table_u32 = NULL;
815 if (
ctx->output_table != NULL) {
816 uint32_t state_count;
817 for (state_count = 0; state_count <
ctx->state_count; state_count++) {
818 if (
ctx->output_table[state_count].pids != NULL) {
819 SCFree(
ctx->output_table[state_count].pids);
825 if (
ctx->pid_pat_list != NULL) {
827 for (i = 0; i < (mpm_ctx->
max_pat_id + 1); i++) {
828 if (
ctx->pid_pat_list[i].cs != NULL)
830 if (
ctx->pid_pat_list[i].sids != NULL)
864 uint8_t *bitarray = (uint8_t *)mpm_thread_ctx->
ctx;
867 if (
ctx->state_count < 32767) {
870 for (uint32_t i = 0; i < buflen; i++) {
871 state = state_table_u16[state & 0x7FFF][
u8_tolower(buf[i])];
872 if (state & 0x8000) {
873 const uint32_t no_of_entries =
ctx->output_table[state & 0x7FFF].no_of_entries;
874 const uint32_t *pids =
ctx->output_table[state & 0x7FFF].pids;
875 for (uint32_t k = 0; k < no_of_entries; k++) {
890 if (!(bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8)))) {
891 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
904 if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
905 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
916 for (uint32_t i = 0; i < buflen; i++) {
917 state = state_table_u32[state & 0x00FFFFFF][
u8_tolower(buf[i])];
918 if (state & 0xFF000000) {
919 const uint32_t no_of_entries =
ctx->output_table[state & 0x00FFFFFF].no_of_entries;
920 const uint32_t *pids =
ctx->output_table[state & 0x00FFFFFF].pids;
921 for (uint32_t k = 0; k < no_of_entries; k++) {
923 const uint32_t lower_pid = pids[k] & 0x0000FFFF;
937 if (!(bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8)))) {
938 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
951 if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
952 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1006 uint16_t
offset, uint16_t depth, uint32_t pid,
1016 printf(
"MPM AC Information:\n");
1017 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1018 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1019 printf(
" Sizeof:\n");
1020 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1021 printf(
" SCACCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACCtx));
1022 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1023 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1024 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1025 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1026 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1027 printf(
"Total states in the state table: %" PRIu32
"\n",
ctx->state_count);
1039 uint32_t size = (mpm_ctx->
max_pat_id / 8) + 1;
1041 uint8_t *bitarray =
SCCalloc(size,
sizeof(uint8_t));
1042 if (bitarray == NULL) {
1045 mpm_thread_ctx->
ctx = bitarray;
1055 mpm_thread_ctx->
ctx = NULL;
1090 static int SCACTest01(
void)
1097 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1106 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1108 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1111 (uint8_t *)buf, strlen(buf));
1116 printf(
"1 != %" PRIu32
" ",
cnt);
1119 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1124 static int SCACTest02(
void)
1131 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1140 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1142 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1144 (uint8_t *)buf, strlen(buf));
1149 printf(
"0 != %" PRIu32
" ",
cnt);
1152 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1157 static int SCACTest03(
void)
1164 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1177 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1179 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1181 (uint8_t *)buf, strlen(buf));
1186 printf(
"3 != %" PRIu32
" ",
cnt);
1189 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1194 static int SCACTest04(
void)
1201 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1211 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1213 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1215 (uint8_t *)buf, strlen(buf));
1220 printf(
"1 != %" PRIu32
" ",
cnt);
1223 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1228 static int SCACTest05(
void)
1235 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1245 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1247 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1249 (uint8_t *)buf, strlen(buf));
1254 printf(
"3 != %" PRIu32
" ",
cnt);
1257 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1262 static int SCACTest06(
void)
1269 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1277 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1279 const char *buf =
"abcd";
1281 (uint8_t *)buf, strlen(buf));
1286 printf(
"1 != %" PRIu32
" ",
cnt);
1289 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1294 static int SCACTest07(
void)
1300 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1313 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1315 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1321 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1323 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1325 (uint8_t *)buf, strlen(buf));
1329 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1334 static int SCACTest08(
void)
1341 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1350 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1358 printf(
"0 != %" PRIu32
" ",
cnt);
1361 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1366 static int SCACTest09(
void)
1373 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1382 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1385 (uint8_t *)
"ab", 2);
1390 printf(
"1 != %" PRIu32
" ",
cnt);
1393 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1398 static int SCACTest10(
void)
1405 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1414 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1416 const char *buf =
"01234567890123456789012345678901234567890123456789"
1417 "01234567890123456789012345678901234567890123456789"
1419 "01234567890123456789012345678901234567890123456789"
1420 "01234567890123456789012345678901234567890123456789";
1422 (uint8_t *)buf, strlen(buf));
1427 printf(
"1 != %" PRIu32
" ",
cnt);
1430 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1435 static int SCACTest11(
void)
1442 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1446 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1448 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1450 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1452 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1459 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1463 const char *buf =
"he";
1464 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1467 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1470 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1473 result &= (
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1478 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1483 static int SCACTest12(
void)
1490 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1501 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1503 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1505 (uint8_t *)buf, strlen(buf));
1510 printf(
"2 != %" PRIu32
" ",
cnt);
1513 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1518 static int SCACTest13(
void)
1525 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1530 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1531 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1535 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1537 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1539 (uint8_t *)buf, strlen(buf));
1544 printf(
"1 != %" PRIu32
" ",
cnt);
1547 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1552 static int SCACTest14(
void)
1559 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1564 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1565 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1569 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1571 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1573 (uint8_t *)buf, strlen(buf));
1578 printf(
"1 != %" PRIu32
" ",
cnt);
1581 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1586 static int SCACTest15(
void)
1593 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1598 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1599 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1603 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1605 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1607 (uint8_t *)buf, strlen(buf));
1612 printf(
"1 != %" PRIu32
" ",
cnt);
1615 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1620 static int SCACTest16(
void)
1627 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1632 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1633 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1637 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1639 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1641 (uint8_t *)buf, strlen(buf));
1646 printf(
"1 != %" PRIu32
" ",
cnt);
1649 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
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);
1671 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1673 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1675 (uint8_t *)buf, strlen(buf));
1680 printf(
"1 != %" PRIu32
" ",
cnt);
1683 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1688 static int SCACTest18(
void)
1695 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1700 const char pat[] =
"abcde"
1706 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1710 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1712 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
1714 (uint8_t *)buf, strlen(buf));
1719 printf(
"1 != %" PRIu32
" ",
cnt);
1722 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1727 static int SCACTest19(
void)
1734 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1739 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1740 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1744 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1746 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1748 (uint8_t *)buf, strlen(buf));
1753 printf(
"1 != %" PRIu32
" ",
cnt);
1756 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1761 static int SCACTest20(
void)
1768 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1773 const char pat[] =
"AAAAA"
1780 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1784 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1786 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
1788 (uint8_t *)buf, strlen(buf));
1793 printf(
"1 != %" PRIu32
" ",
cnt);
1796 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1801 static int SCACTest21(
void)
1808 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1817 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1820 (uint8_t *)
"AA", 2);
1825 printf(
"1 != %" PRIu32
" ",
cnt);
1828 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1833 static int SCACTest22(
void)
1840 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1851 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1853 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1855 (uint8_t *)buf, strlen(buf));
1860 printf(
"2 != %" PRIu32
" ",
cnt);
1863 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1868 static int SCACTest23(
void)
1875 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1884 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1887 (uint8_t *)
"aa", 2);
1892 printf(
"1 != %" PRIu32
" ",
cnt);
1895 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1900 static int SCACTest24(
void)
1907 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1916 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1919 (uint8_t *)
"aa", 2);
1924 printf(
"1 != %" PRIu32
" ",
cnt);
1927 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1932 static int SCACTest25(
void)
1939 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1949 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1951 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1953 (uint8_t *)buf, strlen(buf));
1958 printf(
"3 != %" PRIu32
" ",
cnt);
1961 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1966 static int SCACTest26(
void)
1973 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1982 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1984 const char *buf =
"works";
1986 (uint8_t *)buf, strlen(buf));
1991 printf(
"3 != %" PRIu32
" ",
cnt);
1994 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1999 static int SCACTest27(
void)
2006 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2015 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2017 const char *buf =
"tone";
2019 (uint8_t *)buf, strlen(buf));
2024 printf(
"0 != %" PRIu32
" ",
cnt);
2027 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2032 static int SCACTest28(
void)
2038 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2047 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2049 const char *buf =
"tONE";
2051 (uint8_t *)buf, strlen(buf));
2055 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2060 static int SCACTest29(
void)
2062 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2063 uint16_t buflen =
sizeof(buf) - 1;
2077 "alert tcp any any -> any any "
2078 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2081 "alert tcp any any -> any any "
2082 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2102 static int SCACTest30(
void)
2108 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2117 SCACInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2119 const char *buf1 =
"abcdefghijklmnopqrstuvwxyz";
2120 uint32_t
cnt =
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf1, strlen(buf1));
2122 const char *buf2 =
"xyzxyzxyzxyzxyzxyzxyza";
2123 cnt =
SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf2, strlen(buf2));
2127 SCACDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2132 void SCACRegisterTests(
void)