81 #define SC_AC_BS_FAIL (-1)
83 #define STATE_QUEUE_CONTAINER_SIZE 65536
121 static void SCACBSGetConfig(
void)
139 static inline int SCACBSInitNewState(
MpmCtx *mpm_ctx)
157 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
191 static void SCACBSSetOutputState(int32_t state, uint32_t pid,
MpmCtx *mpm_ctx)
198 for (i = 0; i < output_state->no_of_entries; i++) {
199 if (output_state->pids[i] == pid)
205 output_state->no_of_entries *
sizeof(uint32_t));
207 SCFree(output_state->pids);
208 output_state->pids = NULL;
211 output_state->pids = ptmp;
213 output_state->pids[output_state->no_of_entries - 1] = pid;
228 static inline void SCACBSEnter(uint8_t *pattern, uint16_t pattern_len, uint32_t pid,
233 int32_t newstate = 0;
239 for (i = 0; i < pattern_len; i++) {
249 for (p = i; p < pattern_len; p++) {
250 newstate = SCACBSInitNewState(mpm_ctx);
251 ctx->
goto_table[state][pattern[p]] = newstate;
257 SCACBSSetOutputState(state, pid, mpm_ctx);
268 static inline void SCACBSCreateGotoTable(
MpmCtx *mpm_ctx)
280 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
289 static inline int SCACBSStateQueueIsEmpty(
StateQueue *q)
297 static inline void SCACBSEnqueue(
StateQueue *q, int32_t state)
302 for (i = q->
bot; i < q->top; i++) {
303 if (q->
store[i] == state)
313 FatalError(
"Just ran out of space in the queue. "
314 "Fatal Error. Exiting. Please file a bug report on this");
320 static inline int32_t SCACBSDequeue(
StateQueue *q)
327 "Fatal Error. Exiting. Please file a bug report on this");
374 static inline void SCACBSClubOutputStates(int32_t dst_state, int32_t src_state,
385 for (i = 0; i < output_src_state->no_of_entries; i++) {
386 for (j = 0; j < output_dst_state->no_of_entries; j++) {
387 if (output_src_state->pids[i] == output_dst_state->pids[j]) {
391 if (j == output_dst_state->no_of_entries) {
395 (output_dst_state->no_of_entries *
sizeof(uint32_t)));
397 SCFree(output_dst_state->pids);
398 output_dst_state->pids = NULL;
402 output_dst_state->pids = ptmp;
405 output_dst_state->pids[output_dst_state->no_of_entries - 1] =
406 output_src_state->pids[i];
419 static inline void SCACBSCreateFailureTable(
MpmCtx *mpm_ctx)
440 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
441 int32_t temp_state = ctx->
goto_table[0][ascii_code];
442 if (temp_state != 0) {
443 SCACBSEnqueue(&q, temp_state);
448 while (!SCACBSStateQueueIsEmpty(&q)) {
450 r_state = SCACBSDequeue(&q);
451 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
452 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
455 SCACBSEnqueue(&q, temp_state);
461 SCACBSClubOutputStates(temp_state, ctx->
failure_table[temp_state],
475 static inline void SCACBSCreateDeltaTable(
MpmCtx *mpm_ctx)
492 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
497 SCACBSEnqueue(&q, temp_state);
500 while (!SCACBSStateQueueIsEmpty(&q)) {
501 r_state = SCACBSDequeue(&q);
503 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
504 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
506 SCACBSEnqueue(&q, temp_state);
529 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
533 SCACBSEnqueue(&q, temp_state);
536 while (!SCACBSStateQueueIsEmpty(&q)) {
537 r_state = SCACBSDequeue(&q);
539 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
540 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
542 SCACBSEnqueue(&q, temp_state);
555 static inline void SCACBSClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
560 uint32_t temp_state = 0;
563 for (state = 0; state < ctx->
state_count; state++) {
564 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
571 for (state = 0; state < ctx->
state_count; state++) {
572 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
583 static inline void SCACBSInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
589 for (state = 0; state < ctx->
state_count; state++) {
605 static void SCACBSPrintDeltaTable(
MpmCtx *mpm_ctx)
610 printf(
"##############Delta Table##############\n");
613 for (j = 0; j < 256; j++) {
614 if (SCACBSGetDelta(i, j, mpm_ctx) != 0) {
615 printf(
" %c -> %d\n", j, SCACBSGetDelta(i, j, mpm_ctx));
624 static inline int SCACBSZeroTransitionPresent(
SCACBSCtx *ctx, uint32_t state)
631 for (ascii = 0; ascii < 256; ascii++) {
640 for (ascii = 0; ascii < 256; ascii++) {
642 (state & 0x00FFFFFF)) {
658 static inline void SCACBSCreateModDeltaTable(
MpmCtx *mpm_ctx)
666 for (state = 1; state < ctx->
state_count; state++) {
669 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
671 if (SCACBSZeroTransitionPresent(ctx, temp_state))
675 size +=
sizeof(uint16_t) * k * 2;
703 uint16_t *no_of_entries = NULL;
704 uint16_t *ascii_codes = NULL;
705 uint16_t ascii_code = 0;
707 for (state = 0; state < ctx->
state_count; state++) {
710 no_of_entries = curr_loc++;
711 ascii_codes = curr_loc;
714 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
716 if (state != 0 && SCACBSZeroTransitionPresent(ctx, temp_state))
719 ascii_codes[k] = ascii_code;
726 no_of_entries[0] = k;
738 for (state = 1; state < ctx->
state_count; state++) {
741 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
743 if (SCACBSZeroTransitionPresent(ctx, temp_state))
747 size +=
sizeof(uint32_t) * k * 2;
775 uint32_t *no_of_entries = NULL;
776 uint32_t *ascii_codes = NULL;
777 uint32_t ascii_code = 0;
779 for (state = 0; state < ctx->
state_count; state++) {
782 no_of_entries = curr_loc++;
783 ascii_codes = curr_loc;
786 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
788 if (state != 0 && SCACBSZeroTransitionPresent(ctx, temp_state))
791 ascii_codes[k] = ascii_code;
798 no_of_entries[0] = k;
816 static inline void SCACBSPrepareStateTable(
MpmCtx *mpm_ctx)
821 SCACBSInitNewState(mpm_ctx);
824 SCACBSCreateGotoTable(mpm_ctx);
826 SCACBSCreateFailureTable(mpm_ctx);
828 SCACBSCreateDeltaTable(mpm_ctx);
830 SCACBSClubOutputStatePresenceWithDeltaTable(mpm_ctx);
832 SCACBSCreateModDeltaTable(mpm_ctx);
835 SCACBSInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
848 SCACBSPrintDeltaTable(mpm_ctx);
874 SCLogDebug(
"no patterns supplied to this mpm_ctx");
888 uint32_t i = 0, p = 0;
891 while(node != NULL) {
930 SCACBSPrepareStateTable(mpm_ctx);
934 if (ctx->
parray[i] != NULL) {
963 if (mpm_thread_ctx->
ctx == NULL) {
980 if (mpm_ctx->
ctx != NULL)
984 if (mpm_ctx->
ctx == NULL) {
1016 if (mpm_thread_ctx->
ctx != NULL) {
1018 mpm_thread_ctx->
ctx = NULL;
1044 if (ctx->
parray != NULL) {
1047 if (ctx->
parray[i] != NULL) {
1075 uint32_t state_count;
1076 for (state_count = 0; state_count < ctx->
state_count; state_count++) {
1086 for (i = 0; i < (mpm_ctx->
max_pat_id + 1); i++) {
1142 uint16_t no_of_entries;
1143 uint16_t *ascii_codes;
1145 uint16_t *zero_state = state_table_mod_pointers[0] + 1;
1147 for (i = 0; i < buflen; i++) {
1151 no_of_entries = *(state_table_mod_pointers[state & 0x7FFF]);
1152 if (no_of_entries == 1) {
1153 ascii_codes = state_table_mod_pointers[state & 0x7FFF] + 1;
1155 if (buf_local == ascii_codes[0]) {
1156 state = *(ascii_codes + no_of_entries);
1158 state = zero_state[buf_local];
1161 if (no_of_entries == 0) {
1166 ascii_codes = state_table_mod_pointers[state & 0x7FFF] + 1;
1168 int high = no_of_entries;
1170 while (low <= high) {
1171 mid = (low + high) / 2;
1172 if (ascii_codes[mid] == buf_local) {
1173 state = ((ascii_codes + no_of_entries))[mid];
1175 }
else if (ascii_codes[mid] < buf_local) {
1181 state = zero_state[buf_local];
1186 if (state & 0x8000) {
1190 for (k = 0; k < nentries; k++) {
1191 if (pids[k] & 0xFFFF0000) {
1192 uint32_t lower_pid = pids[k] & 0x0000FFFF;
1193 if (
SCMemcmp(pid_pat_list[lower_pid].cs,
1194 buf + i - pid_pat_list[lower_pid].patlen + 1,
1195 pid_pat_list[lower_pid].patlen) != 0) {
1199 if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
1202 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1203 PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids,
1204 pid_pat_list[lower_pid].sids_size);
1208 if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
1211 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1212 PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids,
1213 pid_pat_list[pids[k]].sids_size);
1225 uint32_t no_of_entries;
1226 uint32_t *ascii_codes;
1228 uint32_t *zero_state = state_table_mod_pointers[0] + 1;
1230 for (i = 0; i < buflen; i++) {
1234 no_of_entries = *(state_table_mod_pointers[state & 0x00FFFFFF]);
1235 if (no_of_entries == 1) {
1236 ascii_codes = state_table_mod_pointers[state & 0x00FFFFFF] + 1;
1238 if (buf_local == ascii_codes[0]) {
1239 state = *(ascii_codes + no_of_entries);
1241 state = zero_state[buf_local];
1244 if (no_of_entries == 0) {
1249 ascii_codes = state_table_mod_pointers[state & 0x00FFFFFF] + 1;
1251 int high = no_of_entries;
1253 while (low <= high) {
1254 mid = (low + high) / 2;
1255 if (ascii_codes[mid] == buf_local) {
1256 state = ((ascii_codes + no_of_entries))[mid];
1258 }
else if (ascii_codes[mid] < buf_local) {
1264 state = zero_state[buf_local];
1269 if (state & 0xFF000000) {
1273 for (k = 0; k < nentries; k++) {
1274 if (pids[k] & 0xFFFF0000) {
1275 uint32_t lower_pid = pids[k] & 0x0000FFFF;
1276 if (
SCMemcmp(pid_pat_list[lower_pid].cs,
1277 buf + i - pid_pat_list[lower_pid].patlen + 1,
1278 pid_pat_list[lower_pid].patlen) != 0) {
1282 if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
1285 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1286 PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids,
1287 pid_pat_list[lower_pid].sids_size);
1291 if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
1294 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1295 PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids,
1296 pid_pat_list[pids[k]].sids_size);
1328 uint16_t
offset, uint16_t depth, uint32_t pid,
1353 uint16_t
offset, uint16_t depth, uint32_t pid,
1362 #ifdef SC_AC_BS_COUNTERS
1364 printf(
"AC Thread Search stats (ctx %p)\n", ctx);
1365 printf(
"Total calls: %" PRIu32
"\n", ctx->
total_calls);
1376 printf(
"MPM AC Information:\n");
1377 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1378 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1379 printf(
" Sizeof:\n");
1380 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1381 printf(
" SCACBSCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACBSCtx));
1382 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1383 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1384 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1385 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1386 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1387 printf(
"Total states in the state table: %" PRIu32
"\n", ctx->
state_count);
1398 static int SCACBSTest01(
void)
1405 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1416 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1418 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1419 (uint8_t *)buf, strlen(buf));
1424 printf(
"1 != %" PRIu32
" ",cnt);
1432 static int SCACBSTest02(
void)
1439 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1450 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1451 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1452 (uint8_t *)buf, strlen(buf));
1457 printf(
"0 != %" PRIu32
" ",cnt);
1465 static int SCACBSTest03(
void)
1472 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1487 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1488 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1489 (uint8_t *)buf, strlen(buf));
1494 printf(
"3 != %" PRIu32
" ",cnt);
1502 static int SCACBSTest04(
void)
1509 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1521 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1522 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1523 (uint8_t *)buf, strlen(buf));
1528 printf(
"1 != %" PRIu32
" ",cnt);
1536 static int SCACBSTest05(
void)
1543 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1555 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1556 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1557 (uint8_t *)buf, strlen(buf));
1562 printf(
"3 != %" PRIu32
" ",cnt);
1570 static int SCACBSTest06(
void)
1577 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1587 const char *buf =
"abcd";
1588 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1589 (uint8_t *)buf, strlen(buf));
1594 printf(
"1 != %" PRIu32
" ",cnt);
1602 static int SCACBSTest07(
void)
1609 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1623 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1625 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1632 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1633 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1634 (uint8_t *)buf, strlen(buf));
1639 printf(
"135 != %" PRIu32
" ",cnt);
1647 static int SCACBSTest08(
void)
1654 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1665 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1671 printf(
"0 != %" PRIu32
" ",cnt);
1679 static int SCACBSTest09(
void)
1686 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1697 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1698 (uint8_t *)
"ab", 2);
1703 printf(
"1 != %" PRIu32
" ",cnt);
1711 static int SCACBSTest10(
void)
1718 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1729 const char *buf =
"01234567890123456789012345678901234567890123456789"
1730 "01234567890123456789012345678901234567890123456789"
1732 "01234567890123456789012345678901234567890123456789"
1733 "01234567890123456789012345678901234567890123456789";
1734 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1735 (uint8_t *)buf, strlen(buf));
1740 printf(
"1 != %" PRIu32
" ",cnt);
1748 static int SCACBSTest11(
void)
1755 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1760 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1762 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1764 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1766 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1775 const char *buf =
"he";
1776 result &= (
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1779 result &= (
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1782 result &= (
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1785 result &= (
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1795 static int SCACBSTest12(
void)
1802 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1815 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1816 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1817 (uint8_t *)buf, strlen(buf));
1822 printf(
"2 != %" PRIu32
" ",cnt);
1830 static int SCACBSTest13(
void)
1837 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1843 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1844 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1849 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1850 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1851 (uint8_t *)buf, strlen(buf));
1856 printf(
"1 != %" PRIu32
" ",cnt);
1864 static int SCACBSTest14(
void)
1871 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1877 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1878 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1883 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1884 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1885 (uint8_t *)buf, strlen(buf));
1890 printf(
"1 != %" PRIu32
" ",cnt);
1898 static int SCACBSTest15(
void)
1905 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1911 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1912 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1917 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1918 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1919 (uint8_t *)buf, strlen(buf));
1924 printf(
"1 != %" PRIu32
" ",cnt);
1932 static int SCACBSTest16(
void)
1939 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1945 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1946 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1951 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1952 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1953 (uint8_t *)buf, strlen(buf));
1958 printf(
"1 != %" PRIu32
" ",cnt);
1966 static int SCACBSTest17(
void)
1973 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1979 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1980 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1985 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1986 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1987 (uint8_t *)buf, strlen(buf));
1992 printf(
"1 != %" PRIu32
" ",cnt);
2000 static int SCACBSTest18(
void)
2007 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2013 const char pat[] =
"abcde"
2019 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2024 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2025 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2026 (uint8_t *)buf, strlen(buf));
2031 printf(
"1 != %" PRIu32
" ",cnt);
2039 static int SCACBSTest19(
void)
2046 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2052 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2053 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2058 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2059 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2060 (uint8_t *)buf, strlen(buf));
2065 printf(
"1 != %" PRIu32
" ",cnt);
2072 static int SCACBSTest20(
void)
2079 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2085 const char pat[] =
"AAAAA"
2092 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2097 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2098 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2099 (uint8_t *)buf, strlen(buf));
2104 printf(
"1 != %" PRIu32
" ",cnt);
2112 static int SCACBSTest21(
void)
2119 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2130 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2131 (uint8_t *)
"AA", 2);
2136 printf(
"1 != %" PRIu32
" ",cnt);
2144 static int SCACBSTest22(
void)
2151 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2164 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
2165 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2166 (uint8_t *)buf, strlen(buf));
2171 printf(
"2 != %" PRIu32
" ",cnt);
2179 static int SCACBSTest23(
void)
2186 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2197 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2198 (uint8_t *)
"aa", 2);
2203 printf(
"1 != %" PRIu32
" ",cnt);
2211 static int SCACBSTest24(
void)
2218 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2229 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2230 (uint8_t *)
"aa", 2);
2235 printf(
"1 != %" PRIu32
" ",cnt);
2243 static int SCACBSTest25(
void)
2250 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2262 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2263 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2264 (uint8_t *)buf, strlen(buf));
2269 printf(
"3 != %" PRIu32
" ",cnt);
2277 static int SCACBSTest26(
void)
2284 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2295 const char *buf =
"works";
2296 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2297 (uint8_t *)buf, strlen(buf));
2302 printf(
"3 != %" PRIu32
" ",cnt);
2310 static int SCACBSTest27(
void)
2317 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2328 const char *buf =
"tone";
2329 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2330 (uint8_t *)buf, strlen(buf));
2335 printf(
"0 != %" PRIu32
" ",cnt);
2343 static int SCACBSTest28(
void)
2350 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2361 const char *buf =
"tONE";
2362 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2363 (uint8_t *)buf, strlen(buf));
2368 printf(
"0 != %" PRIu32
" ",cnt);
2376 static int SCACBSTest29(
void)
2383 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2396 const char *buf =
"abcdefgh";
2397 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2398 (uint8_t *)buf, strlen(buf));
2403 printf(
"3 != %" PRIu32
" ",cnt);
2411 static int SCACBSTest30(
void)
2413 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2414 uint16_t buflen =
sizeof(buf) - 1;
2420 memset(&th_v, 0,
sizeof(th_v));
2431 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2435 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2444 printf(
"if (PacketAlertCheck(p, 1) != 1) failure\n");
2448 printf(
"if (PacketAlertCheck(p, 1) != 2) failure\n");