80 #define SC_AC_BS_FAIL (-1)
82 #define STATE_QUEUE_CONTAINER_SIZE 65536
120 static void SCACBSGetConfig(
void)
138 static inline int SCACBSInitNewState(
MpmCtx *mpm_ctx)
156 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
190 static void SCACBSSetOutputState(int32_t state, uint32_t pid,
MpmCtx *mpm_ctx)
197 for (i = 0; i < output_state->no_of_entries; i++) {
198 if (output_state->pids[i] == pid)
204 output_state->no_of_entries *
sizeof(uint32_t));
206 SCFree(output_state->pids);
207 output_state->pids = NULL;
210 output_state->pids = ptmp;
212 output_state->pids[output_state->no_of_entries - 1] = pid;
227 static inline void SCACBSEnter(uint8_t *pattern, uint16_t pattern_len, uint32_t pid,
232 int32_t newstate = 0;
238 for (i = 0; i < pattern_len; i++) {
248 for (p = i; p < pattern_len; p++) {
249 newstate = SCACBSInitNewState(mpm_ctx);
250 ctx->
goto_table[state][pattern[p]] = newstate;
256 SCACBSSetOutputState(state, pid, mpm_ctx);
267 static inline void SCACBSCreateGotoTable(
MpmCtx *mpm_ctx)
279 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
288 static inline int SCACBSStateQueueIsEmpty(
StateQueue *q)
296 static inline void SCACBSEnqueue(
StateQueue *q, int32_t state)
301 for (i = q->
bot; i < q->top; i++) {
302 if (q->
store[i] == state)
313 "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");
375 static inline void SCACBSClubOutputStates(int32_t dst_state, int32_t src_state,
386 for (i = 0; i < output_src_state->no_of_entries; i++) {
387 for (j = 0; j < output_dst_state->no_of_entries; j++) {
388 if (output_src_state->pids[i] == output_dst_state->pids[j]) {
392 if (j == output_dst_state->no_of_entries) {
396 (output_dst_state->no_of_entries *
sizeof(uint32_t)));
398 SCFree(output_dst_state->pids);
399 output_dst_state->pids = NULL;
403 output_dst_state->pids = ptmp;
406 output_dst_state->pids[output_dst_state->no_of_entries - 1] =
407 output_src_state->pids[i];
420 static inline void SCACBSCreateFailureTable(
MpmCtx *mpm_ctx)
441 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
442 int32_t temp_state = ctx->
goto_table[0][ascii_code];
443 if (temp_state != 0) {
444 SCACBSEnqueue(&q, temp_state);
449 while (!SCACBSStateQueueIsEmpty(&q)) {
451 r_state = SCACBSDequeue(&q);
452 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
453 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
456 SCACBSEnqueue(&q, temp_state);
462 SCACBSClubOutputStates(temp_state, ctx->
failure_table[temp_state],
476 static inline void SCACBSCreateDeltaTable(
MpmCtx *mpm_ctx)
498 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
503 SCACBSEnqueue(&q, temp_state);
506 while (!SCACBSStateQueueIsEmpty(&q)) {
507 r_state = SCACBSDequeue(&q);
509 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
510 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
512 SCACBSEnqueue(&q, temp_state);
540 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
544 SCACBSEnqueue(&q, temp_state);
547 while (!SCACBSStateQueueIsEmpty(&q)) {
548 r_state = SCACBSDequeue(&q);
550 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
551 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
553 SCACBSEnqueue(&q, temp_state);
566 static inline void SCACBSClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
571 uint32_t temp_state = 0;
574 for (state = 0; state < ctx->
state_count; state++) {
575 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
582 for (state = 0; state < ctx->
state_count; state++) {
583 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
594 static inline void SCACBSInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
600 for (state = 0; state < ctx->
state_count; state++) {
616 static void SCACBSPrintDeltaTable(
MpmCtx *mpm_ctx)
621 printf(
"##############Delta Table##############\n");
624 for (j = 0; j < 256; j++) {
625 if (SCACBSGetDelta(i, j, mpm_ctx) != 0) {
626 printf(
" %c -> %d\n", j, SCACBSGetDelta(i, j, mpm_ctx));
635 static inline int SCACBSZeroTransitionPresent(
SCACBSCtx *ctx, uint32_t state)
642 for (ascii = 0; ascii < 256; ascii++) {
651 for (ascii = 0; ascii < 256; ascii++) {
653 (state & 0x00FFFFFF)) {
669 static inline void SCACBSCreateModDeltaTable(
MpmCtx *mpm_ctx)
677 for (state = 1; state < ctx->
state_count; state++) {
680 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
682 if (SCACBSZeroTransitionPresent(ctx, temp_state))
686 size +=
sizeof(uint16_t) * k * 2;
714 uint16_t *no_of_entries = NULL;
715 uint16_t *ascii_codes = NULL;
716 uint16_t ascii_code = 0;
718 for (state = 0; state < ctx->
state_count; state++) {
721 no_of_entries = curr_loc++;
722 ascii_codes = curr_loc;
725 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
727 if (state != 0 && SCACBSZeroTransitionPresent(ctx, temp_state))
730 ascii_codes[k] = ascii_code;
737 no_of_entries[0] = k;
749 for (state = 1; state < ctx->
state_count; state++) {
752 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
754 if (SCACBSZeroTransitionPresent(ctx, temp_state))
758 size +=
sizeof(uint32_t) * k * 2;
786 uint32_t *no_of_entries = NULL;
787 uint32_t *ascii_codes = NULL;
788 uint32_t ascii_code = 0;
790 for (state = 0; state < ctx->
state_count; state++) {
793 no_of_entries = curr_loc++;
794 ascii_codes = curr_loc;
797 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
799 if (state != 0 && SCACBSZeroTransitionPresent(ctx, temp_state))
802 ascii_codes[k] = ascii_code;
809 no_of_entries[0] = k;
827 static inline void SCACBSPrepareStateTable(
MpmCtx *mpm_ctx)
832 SCACBSInitNewState(mpm_ctx);
835 SCACBSCreateGotoTable(mpm_ctx);
837 SCACBSCreateFailureTable(mpm_ctx);
839 SCACBSCreateDeltaTable(mpm_ctx);
841 SCACBSClubOutputStatePresenceWithDeltaTable(mpm_ctx);
843 SCACBSCreateModDeltaTable(mpm_ctx);
846 SCACBSInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
859 SCACBSPrintDeltaTable(mpm_ctx);
885 SCLogDebug(
"no patterns supplied to this mpm_ctx");
899 uint32_t i = 0, p = 0;
902 while(node != NULL) {
941 SCACBSPrepareStateTable(mpm_ctx);
945 if (ctx->
parray[i] != NULL) {
974 if (mpm_thread_ctx->
ctx == NULL) {
991 if (mpm_ctx->
ctx != NULL)
995 if (mpm_ctx->
ctx == NULL) {
1027 if (mpm_thread_ctx->
ctx != NULL) {
1029 mpm_thread_ctx->
ctx = NULL;
1055 if (ctx->
parray != NULL) {
1058 if (ctx->
parray[i] != NULL) {
1086 uint32_t state_count;
1087 for (state_count = 0; state_count < ctx->
state_count; state_count++) {
1097 for (i = 0; i < (mpm_ctx->
max_pat_id + 1); i++) {
1153 uint16_t no_of_entries;
1154 uint16_t *ascii_codes;
1156 uint16_t *zero_state = state_table_mod_pointers[0] + 1;
1158 for (i = 0; i < buflen; i++) {
1162 no_of_entries = *(state_table_mod_pointers[state & 0x7FFF]);
1163 if (no_of_entries == 1) {
1164 ascii_codes = state_table_mod_pointers[state & 0x7FFF] + 1;
1166 if (buf_local == ascii_codes[0]) {
1167 state = *(ascii_codes + no_of_entries);;
1169 state = zero_state[buf_local];
1172 if (no_of_entries == 0) {
1177 ascii_codes = state_table_mod_pointers[state & 0x7FFF] + 1;
1179 int high = no_of_entries;
1181 while (low <= high) {
1182 mid = (low + high) / 2;
1183 if (ascii_codes[mid] == buf_local) {
1184 state = ((ascii_codes + no_of_entries))[mid];
1186 }
else if (ascii_codes[mid] < buf_local) {
1192 state = zero_state[buf_local];
1197 if (state & 0x8000) {
1201 for (k = 0; k < nentries; k++) {
1202 if (pids[k] & 0xFFFF0000) {
1203 uint32_t lower_pid = pids[k] & 0x0000FFFF;
1204 if (
SCMemcmp(pid_pat_list[lower_pid].cs,
1205 buf + i - pid_pat_list[lower_pid].patlen + 1,
1206 pid_pat_list[lower_pid].patlen) != 0) {
1210 if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
1213 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1214 PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids,
1215 pid_pat_list[lower_pid].sids_size);
1219 if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
1222 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1223 PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids,
1224 pid_pat_list[pids[k]].sids_size);
1236 uint32_t no_of_entries;
1237 uint32_t *ascii_codes;
1239 uint32_t *zero_state = state_table_mod_pointers[0] + 1;
1241 for (i = 0; i < buflen; i++) {
1245 no_of_entries = *(state_table_mod_pointers[state & 0x00FFFFFF]);
1246 if (no_of_entries == 1) {
1247 ascii_codes = state_table_mod_pointers[state & 0x00FFFFFF] + 1;
1249 if (buf_local == ascii_codes[0]) {
1250 state = *(ascii_codes + no_of_entries);;
1252 state = zero_state[buf_local];;
1255 if (no_of_entries == 0) {
1260 ascii_codes = state_table_mod_pointers[state & 0x00FFFFFF] + 1;
1262 int high = no_of_entries;
1264 while (low <= high) {
1265 mid = (low + high) / 2;
1266 if (ascii_codes[mid] == buf_local) {
1267 state = ((ascii_codes + no_of_entries))[mid];
1269 }
else if (ascii_codes[mid] < buf_local) {
1275 state = zero_state[buf_local];
1280 if (state & 0xFF000000) {
1284 for (k = 0; k < nentries; k++) {
1285 if (pids[k] & 0xFFFF0000) {
1286 uint32_t lower_pid = pids[k] & 0x0000FFFF;
1287 if (
SCMemcmp(pid_pat_list[lower_pid].cs,
1288 buf + i - pid_pat_list[lower_pid].patlen + 1,
1289 pid_pat_list[lower_pid].patlen) != 0) {
1293 if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
1296 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1297 PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids,
1298 pid_pat_list[lower_pid].sids_size);
1302 if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
1305 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1306 PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids,
1307 pid_pat_list[pids[k]].sids_size);
1339 uint16_t
offset, uint16_t depth, uint32_t pid,
1364 uint16_t
offset, uint16_t depth, uint32_t pid,
1373 #ifdef SC_AC_BS_COUNTERS
1375 printf(
"AC Thread Search stats (ctx %p)\n", ctx);
1376 printf(
"Total calls: %" PRIu32
"\n", ctx->
total_calls);
1387 printf(
"MPM AC Information:\n");
1388 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1389 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1390 printf(
" Sizeof:\n");
1391 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1392 printf(
" SCACBSCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACBSCtx));
1393 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1394 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1395 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1396 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1397 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1398 printf(
"Total states in the state table: %" PRIu32
"\n", ctx->
state_count);
1408 static int SCACBSTest01(
void)
1415 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1426 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1428 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1429 (uint8_t *)buf, strlen(buf));
1434 printf(
"1 != %" PRIu32
" ",cnt);
1442 static int SCACBSTest02(
void)
1449 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1460 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1461 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1462 (uint8_t *)buf, strlen(buf));
1467 printf(
"0 != %" PRIu32
" ",cnt);
1475 static int SCACBSTest03(
void)
1482 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1497 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1498 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1499 (uint8_t *)buf, strlen(buf));
1504 printf(
"3 != %" PRIu32
" ",cnt);
1512 static int SCACBSTest04(
void)
1519 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1531 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1532 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1533 (uint8_t *)buf, strlen(buf));
1538 printf(
"1 != %" PRIu32
" ",cnt);
1546 static int SCACBSTest05(
void)
1553 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1565 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1566 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1567 (uint8_t *)buf, strlen(buf));
1572 printf(
"3 != %" PRIu32
" ",cnt);
1580 static int SCACBSTest06(
void)
1587 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1597 const char *buf =
"abcd";
1598 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1599 (uint8_t *)buf, strlen(buf));
1604 printf(
"1 != %" PRIu32
" ",cnt);
1612 static int SCACBSTest07(
void)
1619 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1633 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1635 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1642 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1643 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1644 (uint8_t *)buf, strlen(buf));
1649 printf(
"135 != %" PRIu32
" ",cnt);
1657 static int SCACBSTest08(
void)
1664 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1675 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1681 printf(
"0 != %" PRIu32
" ",cnt);
1689 static int SCACBSTest09(
void)
1696 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1707 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1708 (uint8_t *)
"ab", 2);
1713 printf(
"1 != %" PRIu32
" ",cnt);
1721 static int SCACBSTest10(
void)
1728 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1739 const char *buf =
"01234567890123456789012345678901234567890123456789"
1740 "01234567890123456789012345678901234567890123456789"
1742 "01234567890123456789012345678901234567890123456789"
1743 "01234567890123456789012345678901234567890123456789";
1744 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1745 (uint8_t *)buf, strlen(buf));
1750 printf(
"1 != %" PRIu32
" ",cnt);
1758 static int SCACBSTest11(
void)
1765 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1770 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1772 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1774 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1776 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1785 const char *buf =
"he";
1786 result &= (
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1789 result &= (
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1792 result &= (
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1795 result &= (
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1805 static int SCACBSTest12(
void)
1812 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1825 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1826 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1827 (uint8_t *)buf, strlen(buf));
1832 printf(
"2 != %" PRIu32
" ",cnt);
1840 static int SCACBSTest13(
void)
1847 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1853 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1854 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1859 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1860 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1861 (uint8_t *)buf, strlen(buf));
1866 printf(
"1 != %" PRIu32
" ",cnt);
1874 static int SCACBSTest14(
void)
1881 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1887 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1888 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1893 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1894 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1895 (uint8_t *)buf, strlen(buf));
1900 printf(
"1 != %" PRIu32
" ",cnt);
1908 static int SCACBSTest15(
void)
1915 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1921 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1922 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1927 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1928 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1929 (uint8_t *)buf, strlen(buf));
1934 printf(
"1 != %" PRIu32
" ",cnt);
1942 static int SCACBSTest16(
void)
1949 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1955 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1956 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1961 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1962 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1963 (uint8_t *)buf, strlen(buf));
1968 printf(
"1 != %" PRIu32
" ",cnt);
1976 static int SCACBSTest17(
void)
1983 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1989 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1990 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1995 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1996 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1997 (uint8_t *)buf, strlen(buf));
2002 printf(
"1 != %" PRIu32
" ",cnt);
2010 static int SCACBSTest18(
void)
2017 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2023 const char pat[] =
"abcde"
2029 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2034 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2035 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2036 (uint8_t *)buf, strlen(buf));
2041 printf(
"1 != %" PRIu32
" ",cnt);
2049 static int SCACBSTest19(
void)
2056 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2062 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2063 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2068 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2069 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2070 (uint8_t *)buf, strlen(buf));
2075 printf(
"1 != %" PRIu32
" ",cnt);
2082 static int SCACBSTest20(
void)
2089 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2095 const char pat[] =
"AAAAA"
2102 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2107 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2108 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2109 (uint8_t *)buf, strlen(buf));
2114 printf(
"1 != %" PRIu32
" ",cnt);
2122 static int SCACBSTest21(
void)
2129 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2140 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2141 (uint8_t *)
"AA", 2);
2146 printf(
"1 != %" PRIu32
" ",cnt);
2154 static int SCACBSTest22(
void)
2161 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2174 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
2175 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2176 (uint8_t *)buf, strlen(buf));
2181 printf(
"2 != %" PRIu32
" ",cnt);
2189 static int SCACBSTest23(
void)
2196 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2207 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2208 (uint8_t *)
"aa", 2);
2213 printf(
"1 != %" PRIu32
" ",cnt);
2221 static int SCACBSTest24(
void)
2228 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2239 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2240 (uint8_t *)
"aa", 2);
2245 printf(
"1 != %" PRIu32
" ",cnt);
2253 static int SCACBSTest25(
void)
2260 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2272 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2273 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2274 (uint8_t *)buf, strlen(buf));
2279 printf(
"3 != %" PRIu32
" ",cnt);
2287 static int SCACBSTest26(
void)
2294 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2305 const char *buf =
"works";
2306 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2307 (uint8_t *)buf, strlen(buf));
2312 printf(
"3 != %" PRIu32
" ",cnt);
2320 static int SCACBSTest27(
void)
2327 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2338 const char *buf =
"tone";
2339 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2340 (uint8_t *)buf, strlen(buf));
2345 printf(
"0 != %" PRIu32
" ",cnt);
2353 static int SCACBSTest28(
void)
2360 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2371 const char *buf =
"tONE";
2372 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2373 (uint8_t *)buf, strlen(buf));
2378 printf(
"0 != %" PRIu32
" ",cnt);
2386 static int SCACBSTest29(
void)
2393 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2406 const char *buf =
"abcdefgh";
2407 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2408 (uint8_t *)buf, strlen(buf));
2413 printf(
"3 != %" PRIu32
" ",cnt);
2421 static int SCACBSTest30(
void)
2423 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2424 uint16_t buflen =
sizeof(buf) - 1;
2430 memset(&th_v, 0,
sizeof(th_v));
2441 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2445 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2454 printf(
"if (PacketAlertCheck(p, 1) != 1) failure\n");
2458 printf(
"if (PacketAlertCheck(p, 1) != 2) failure\n");