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)
497 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
502 SCACBSEnqueue(&q, temp_state);
505 while (!SCACBSStateQueueIsEmpty(&q)) {
506 r_state = SCACBSDequeue(&q);
508 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
509 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
511 SCACBSEnqueue(&q, temp_state);
539 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
543 SCACBSEnqueue(&q, temp_state);
546 while (!SCACBSStateQueueIsEmpty(&q)) {
547 r_state = SCACBSDequeue(&q);
549 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
550 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
552 SCACBSEnqueue(&q, temp_state);
565 static inline void SCACBSClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
570 uint32_t temp_state = 0;
573 for (state = 0; state < ctx->
state_count; state++) {
574 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
581 for (state = 0; state < ctx->
state_count; state++) {
582 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
593 static inline void SCACBSInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
599 for (state = 0; state < ctx->
state_count; state++) {
615 static void SCACBSPrintDeltaTable(
MpmCtx *mpm_ctx)
620 printf(
"##############Delta Table##############\n");
623 for (j = 0; j < 256; j++) {
624 if (SCACBSGetDelta(i, j, mpm_ctx) != 0) {
625 printf(
" %c -> %d\n", j, SCACBSGetDelta(i, j, mpm_ctx));
634 static inline int SCACBSZeroTransitionPresent(
SCACBSCtx *ctx, uint32_t state)
641 for (ascii = 0; ascii < 256; ascii++) {
650 for (ascii = 0; ascii < 256; ascii++) {
652 (state & 0x00FFFFFF)) {
668 static inline void SCACBSCreateModDeltaTable(
MpmCtx *mpm_ctx)
676 for (state = 1; state < ctx->
state_count; state++) {
679 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
681 if (SCACBSZeroTransitionPresent(ctx, temp_state))
685 size +=
sizeof(uint16_t) * k * 2;
713 uint16_t *no_of_entries = NULL;
714 uint16_t *ascii_codes = NULL;
715 uint16_t ascii_code = 0;
717 for (state = 0; state < ctx->
state_count; state++) {
720 no_of_entries = curr_loc++;
721 ascii_codes = curr_loc;
724 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
726 if (state != 0 && SCACBSZeroTransitionPresent(ctx, temp_state))
729 ascii_codes[k] = ascii_code;
736 no_of_entries[0] = k;
748 for (state = 1; state < ctx->
state_count; state++) {
751 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
753 if (SCACBSZeroTransitionPresent(ctx, temp_state))
757 size +=
sizeof(uint32_t) * k * 2;
785 uint32_t *no_of_entries = NULL;
786 uint32_t *ascii_codes = NULL;
787 uint32_t ascii_code = 0;
789 for (state = 0; state < ctx->
state_count; state++) {
792 no_of_entries = curr_loc++;
793 ascii_codes = curr_loc;
796 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
798 if (state != 0 && SCACBSZeroTransitionPresent(ctx, temp_state))
801 ascii_codes[k] = ascii_code;
808 no_of_entries[0] = k;
826 static inline void SCACBSPrepareStateTable(
MpmCtx *mpm_ctx)
831 SCACBSInitNewState(mpm_ctx);
834 SCACBSCreateGotoTable(mpm_ctx);
836 SCACBSCreateFailureTable(mpm_ctx);
838 SCACBSCreateDeltaTable(mpm_ctx);
840 SCACBSClubOutputStatePresenceWithDeltaTable(mpm_ctx);
842 SCACBSCreateModDeltaTable(mpm_ctx);
845 SCACBSInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
858 SCACBSPrintDeltaTable(mpm_ctx);
884 SCLogDebug(
"no patterns supplied to this mpm_ctx");
898 uint32_t i = 0, p = 0;
901 while(node != NULL) {
940 SCACBSPrepareStateTable(mpm_ctx);
944 if (ctx->
parray[i] != NULL) {
973 if (mpm_thread_ctx->
ctx == NULL) {
990 if (mpm_ctx->
ctx != NULL)
994 if (mpm_ctx->
ctx == NULL) {
1026 if (mpm_thread_ctx->
ctx != NULL) {
1028 mpm_thread_ctx->
ctx = NULL;
1054 if (ctx->
parray != NULL) {
1057 if (ctx->
parray[i] != NULL) {
1085 uint32_t state_count;
1086 for (state_count = 0; state_count < ctx->
state_count; state_count++) {
1096 for (i = 0; i < (mpm_ctx->
max_pat_id + 1); i++) {
1152 uint16_t no_of_entries;
1153 uint16_t *ascii_codes;
1155 uint16_t *zero_state = state_table_mod_pointers[0] + 1;
1157 for (i = 0; i < buflen; i++) {
1161 no_of_entries = *(state_table_mod_pointers[state & 0x7FFF]);
1162 if (no_of_entries == 1) {
1163 ascii_codes = state_table_mod_pointers[state & 0x7FFF] + 1;
1165 if (buf_local == ascii_codes[0]) {
1166 state = *(ascii_codes + no_of_entries);
1168 state = zero_state[buf_local];
1171 if (no_of_entries == 0) {
1176 ascii_codes = state_table_mod_pointers[state & 0x7FFF] + 1;
1178 int high = no_of_entries;
1180 while (low <= high) {
1181 mid = (low + high) / 2;
1182 if (ascii_codes[mid] == buf_local) {
1183 state = ((ascii_codes + no_of_entries))[mid];
1185 }
else if (ascii_codes[mid] < buf_local) {
1191 state = zero_state[buf_local];
1196 if (state & 0x8000) {
1200 for (k = 0; k < nentries; k++) {
1201 if (pids[k] & 0xFFFF0000) {
1202 uint32_t lower_pid = pids[k] & 0x0000FFFF;
1203 if (
SCMemcmp(pid_pat_list[lower_pid].cs,
1204 buf + i - pid_pat_list[lower_pid].patlen + 1,
1205 pid_pat_list[lower_pid].patlen) != 0) {
1209 if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
1212 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1213 PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids,
1214 pid_pat_list[lower_pid].sids_size);
1218 if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
1221 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1222 PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids,
1223 pid_pat_list[pids[k]].sids_size);
1235 uint32_t no_of_entries;
1236 uint32_t *ascii_codes;
1238 uint32_t *zero_state = state_table_mod_pointers[0] + 1;
1240 for (i = 0; i < buflen; i++) {
1244 no_of_entries = *(state_table_mod_pointers[state & 0x00FFFFFF]);
1245 if (no_of_entries == 1) {
1246 ascii_codes = state_table_mod_pointers[state & 0x00FFFFFF] + 1;
1248 if (buf_local == ascii_codes[0]) {
1249 state = *(ascii_codes + no_of_entries);
1251 state = zero_state[buf_local];
1254 if (no_of_entries == 0) {
1259 ascii_codes = state_table_mod_pointers[state & 0x00FFFFFF] + 1;
1261 int high = no_of_entries;
1263 while (low <= high) {
1264 mid = (low + high) / 2;
1265 if (ascii_codes[mid] == buf_local) {
1266 state = ((ascii_codes + no_of_entries))[mid];
1268 }
else if (ascii_codes[mid] < buf_local) {
1274 state = zero_state[buf_local];
1279 if (state & 0xFF000000) {
1283 for (k = 0; k < nentries; k++) {
1284 if (pids[k] & 0xFFFF0000) {
1285 uint32_t lower_pid = pids[k] & 0x0000FFFF;
1286 if (
SCMemcmp(pid_pat_list[lower_pid].cs,
1287 buf + i - pid_pat_list[lower_pid].patlen + 1,
1288 pid_pat_list[lower_pid].patlen) != 0) {
1292 if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
1295 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1296 PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids,
1297 pid_pat_list[lower_pid].sids_size);
1301 if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
1304 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1305 PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids,
1306 pid_pat_list[pids[k]].sids_size);
1338 uint16_t
offset, uint16_t depth, uint32_t pid,
1363 uint16_t
offset, uint16_t depth, uint32_t pid,
1372 #ifdef SC_AC_BS_COUNTERS
1374 printf(
"AC Thread Search stats (ctx %p)\n", ctx);
1375 printf(
"Total calls: %" PRIu32
"\n", ctx->
total_calls);
1386 printf(
"MPM AC Information:\n");
1387 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1388 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1389 printf(
" Sizeof:\n");
1390 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1391 printf(
" SCACBSCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACBSCtx));
1392 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1393 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1394 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1395 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1396 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1397 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");