79 #define SC_AC_BS_FAIL (-1)
81 #define STATE_QUEUE_CONTAINER_SIZE 65536
119 static void SCACBSGetConfig(
void)
137 static inline int SCACBSInitNewState(
MpmCtx *mpm_ctx)
155 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
189 static void SCACBSSetOutputState(int32_t state, uint32_t pid,
MpmCtx *mpm_ctx)
196 for (i = 0; i < output_state->no_of_entries; i++) {
197 if (output_state->pids[i] == pid)
203 output_state->no_of_entries *
sizeof(uint32_t));
205 SCFree(output_state->pids);
206 output_state->pids = NULL;
209 output_state->pids = ptmp;
211 output_state->pids[output_state->no_of_entries - 1] = pid;
226 static inline void SCACBSEnter(uint8_t *pattern, uint16_t pattern_len, uint32_t pid,
231 int32_t newstate = 0;
237 for (i = 0; i < pattern_len; i++) {
247 for (p = i; p < pattern_len; p++) {
248 newstate = SCACBSInitNewState(mpm_ctx);
249 ctx->
goto_table[state][pattern[p]] = newstate;
255 SCACBSSetOutputState(state, pid, mpm_ctx);
266 static inline void SCACBSCreateGotoTable(
MpmCtx *mpm_ctx)
278 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
287 static inline int SCACBSStateQueueIsEmpty(
StateQueue *q)
295 static inline void SCACBSEnqueue(
StateQueue *q, int32_t state)
300 for (i = q->
bot; i < q->top; i++) {
301 if (q->
store[i] == state)
312 "Fatal Error. Exiting. Please file a bug report on this");
319 static inline int32_t SCACBSDequeue(
StateQueue *q)
326 "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++) {
501 SCACBSEnqueue(&q, temp_state);
504 while (!SCACBSStateQueueIsEmpty(&q)) {
505 r_state = SCACBSDequeue(&q);
507 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
508 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
510 SCACBSEnqueue(&q, temp_state);
537 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
541 SCACBSEnqueue(&q, temp_state);
544 while (!SCACBSStateQueueIsEmpty(&q)) {
545 r_state = SCACBSDequeue(&q);
547 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
548 int32_t temp_state = ctx->
goto_table[r_state][ascii_code];
550 SCACBSEnqueue(&q, temp_state);
563 static inline void SCACBSClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
568 uint32_t temp_state = 0;
571 for (state = 0; state < ctx->
state_count; state++) {
572 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
579 for (state = 0; state < ctx->
state_count; state++) {
580 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
591 static inline void SCACBSInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
597 for (state = 0; state < ctx->
state_count; state++) {
613 static void SCACBSPrintDeltaTable(
MpmCtx *mpm_ctx)
618 printf(
"##############Delta Table##############\n");
621 for (j = 0; j < 256; j++) {
622 if (SCACBSGetDelta(i, j, mpm_ctx) != 0) {
623 printf(
" %c -> %d\n", j, SCACBSGetDelta(i, j, mpm_ctx));
632 static inline int SCACBSZeroTransitionPresent(
SCACBSCtx *ctx, uint32_t state)
639 for (ascii = 0; ascii < 256; ascii++) {
648 for (ascii = 0; ascii < 256; ascii++) {
650 (state & 0x00FFFFFF)) {
666 static inline void SCACBSCreateModDeltaTable(
MpmCtx *mpm_ctx)
674 for (state = 1; state < ctx->
state_count; state++) {
677 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
679 if (SCACBSZeroTransitionPresent(ctx, temp_state))
683 size +=
sizeof(uint16_t) * k * 2;
711 uint16_t *no_of_entries = NULL;
712 uint16_t *ascii_codes = NULL;
713 uint16_t ascii_code = 0;
715 for (state = 0; state < ctx->
state_count; state++) {
718 no_of_entries = curr_loc++;
719 ascii_codes = curr_loc;
722 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
724 if (state != 0 && SCACBSZeroTransitionPresent(ctx, temp_state))
727 ascii_codes[k] = ascii_code;
734 no_of_entries[0] = k;
746 for (state = 1; state < ctx->
state_count; state++) {
749 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
751 if (SCACBSZeroTransitionPresent(ctx, temp_state))
755 size +=
sizeof(uint32_t) * k * 2;
783 uint32_t *no_of_entries = NULL;
784 uint32_t *ascii_codes = NULL;
785 uint32_t ascii_code = 0;
787 for (state = 0; state < ctx->
state_count; state++) {
790 no_of_entries = curr_loc++;
791 ascii_codes = curr_loc;
794 for (ascii_code = 0; ascii_code < 256; ascii_code++) {
796 if (state != 0 && SCACBSZeroTransitionPresent(ctx, temp_state))
799 ascii_codes[k] = ascii_code;
806 no_of_entries[0] = k;
824 static inline void SCACBSPrepareStateTable(
MpmCtx *mpm_ctx)
829 SCACBSInitNewState(mpm_ctx);
832 SCACBSCreateGotoTable(mpm_ctx);
834 SCACBSCreateFailureTable(mpm_ctx);
836 SCACBSCreateDeltaTable(mpm_ctx);
838 SCACBSClubOutputStatePresenceWithDeltaTable(mpm_ctx);
840 SCACBSCreateModDeltaTable(mpm_ctx);
843 SCACBSInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
856 SCACBSPrintDeltaTable(mpm_ctx);
882 SCLogDebug(
"no patterns supplied to this mpm_ctx");
896 uint32_t i = 0, p = 0;
899 while(node != NULL) {
938 SCACBSPrepareStateTable(mpm_ctx);
942 if (ctx->
parray[i] != NULL) {
971 if (mpm_thread_ctx->
ctx == NULL) {
988 if (mpm_ctx->
ctx != NULL)
992 if (mpm_ctx->
ctx == NULL) {
1024 if (mpm_thread_ctx->
ctx != NULL) {
1026 mpm_thread_ctx->
ctx = NULL;
1052 if (ctx->
parray != NULL) {
1055 if (ctx->
parray[i] != NULL) {
1083 uint32_t state_count;
1084 for (state_count = 0; state_count < ctx->
state_count; state_count++) {
1094 for (i = 0; i < (mpm_ctx->
max_pat_id + 1); i++) {
1150 uint16_t no_of_entries;
1151 uint16_t *ascii_codes;
1153 uint16_t *zero_state = state_table_mod_pointers[0] + 1;
1155 for (i = 0; i < buflen; i++) {
1159 no_of_entries = *(state_table_mod_pointers[state & 0x7FFF]);
1160 if (no_of_entries == 1) {
1161 ascii_codes = state_table_mod_pointers[state & 0x7FFF] + 1;
1163 if (buf_local == ascii_codes[0]) {
1164 state = *(ascii_codes + no_of_entries);;
1166 state = zero_state[buf_local];
1169 if (no_of_entries == 0) {
1174 ascii_codes = state_table_mod_pointers[state & 0x7FFF] + 1;
1176 int high = no_of_entries;
1178 while (low <= high) {
1179 mid = (low + high) / 2;
1180 if (ascii_codes[mid] == buf_local) {
1181 state = ((ascii_codes + no_of_entries))[mid];
1183 }
else if (ascii_codes[mid] < buf_local) {
1189 state = zero_state[buf_local];
1194 if (state & 0x8000) {
1198 for (k = 0; k < nentries; k++) {
1199 if (pids[k] & 0xFFFF0000) {
1200 uint32_t lower_pid = pids[k] & 0x0000FFFF;
1201 if (
SCMemcmp(pid_pat_list[lower_pid].cs,
1202 buf + i - pid_pat_list[lower_pid].patlen + 1,
1203 pid_pat_list[lower_pid].patlen) != 0) {
1207 if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
1210 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1211 PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids,
1212 pid_pat_list[lower_pid].sids_size);
1216 if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
1219 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1220 PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids,
1221 pid_pat_list[pids[k]].sids_size);
1233 uint32_t no_of_entries;
1234 uint32_t *ascii_codes;
1236 uint32_t *zero_state = state_table_mod_pointers[0] + 1;
1238 for (i = 0; i < buflen; i++) {
1242 no_of_entries = *(state_table_mod_pointers[state & 0x00FFFFFF]);
1243 if (no_of_entries == 1) {
1244 ascii_codes = state_table_mod_pointers[state & 0x00FFFFFF] + 1;
1246 if (buf_local == ascii_codes[0]) {
1247 state = *(ascii_codes + no_of_entries);;
1249 state = zero_state[buf_local];;
1252 if (no_of_entries == 0) {
1257 ascii_codes = state_table_mod_pointers[state & 0x00FFFFFF] + 1;
1259 int high = no_of_entries;
1261 while (low <= high) {
1262 mid = (low + high) / 2;
1263 if (ascii_codes[mid] == buf_local) {
1264 state = ((ascii_codes + no_of_entries))[mid];
1266 }
else if (ascii_codes[mid] < buf_local) {
1272 state = zero_state[buf_local];
1277 if (state & 0xFF000000) {
1281 for (k = 0; k < nentries; k++) {
1282 if (pids[k] & 0xFFFF0000) {
1283 uint32_t lower_pid = pids[k] & 0x0000FFFF;
1284 if (
SCMemcmp(pid_pat_list[lower_pid].cs,
1285 buf + i - pid_pat_list[lower_pid].patlen + 1,
1286 pid_pat_list[lower_pid].patlen) != 0) {
1290 if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) {
1293 bitarray[(lower_pid) / 8] |= (1 << ((lower_pid) % 8));
1294 PrefilterAddSids(pmq, pid_pat_list[lower_pid].sids,
1295 pid_pat_list[lower_pid].sids_size);
1299 if (bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
1302 bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
1303 PrefilterAddSids(pmq, pid_pat_list[pids[k]].sids,
1304 pid_pat_list[pids[k]].sids_size);
1336 uint16_t
offset, uint16_t depth, uint32_t pid,
1361 uint16_t
offset, uint16_t depth, uint32_t pid,
1370 #ifdef SC_AC_BS_COUNTERS
1372 printf(
"AC Thread Search stats (ctx %p)\n", ctx);
1373 printf(
"Total calls: %" PRIu32
"\n", ctx->
total_calls);
1384 printf(
"MPM AC Information:\n");
1385 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1386 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1387 printf(
" Sizeof:\n");
1388 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1389 printf(
" SCACBSCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACBSCtx));
1390 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1391 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1392 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1393 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1394 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1395 printf(
"Total states in the state table: %" PRIu32
"\n", ctx->
state_count);
1405 static int SCACBSTest01(
void)
1412 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1423 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1425 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1426 (uint8_t *)buf, strlen(buf));
1431 printf(
"1 != %" PRIu32
" ",cnt);
1439 static int SCACBSTest02(
void)
1446 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1457 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1458 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1459 (uint8_t *)buf, strlen(buf));
1464 printf(
"0 != %" PRIu32
" ",cnt);
1472 static int SCACBSTest03(
void)
1479 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1494 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1495 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1496 (uint8_t *)buf, strlen(buf));
1501 printf(
"3 != %" PRIu32
" ",cnt);
1509 static int SCACBSTest04(
void)
1516 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1528 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1529 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1530 (uint8_t *)buf, strlen(buf));
1535 printf(
"1 != %" PRIu32
" ",cnt);
1543 static int SCACBSTest05(
void)
1550 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1562 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1563 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1564 (uint8_t *)buf, strlen(buf));
1569 printf(
"3 != %" PRIu32
" ",cnt);
1577 static int SCACBSTest06(
void)
1584 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1594 const char *buf =
"abcd";
1595 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1596 (uint8_t *)buf, strlen(buf));
1601 printf(
"1 != %" PRIu32
" ",cnt);
1609 static int SCACBSTest07(
void)
1616 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1630 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1632 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1639 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1640 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1641 (uint8_t *)buf, strlen(buf));
1646 printf(
"135 != %" PRIu32
" ",cnt);
1654 static int SCACBSTest08(
void)
1661 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1672 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1678 printf(
"0 != %" PRIu32
" ",cnt);
1686 static int SCACBSTest09(
void)
1693 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1704 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1705 (uint8_t *)
"ab", 2);
1710 printf(
"1 != %" PRIu32
" ",cnt);
1718 static int SCACBSTest10(
void)
1725 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1736 const char *buf =
"01234567890123456789012345678901234567890123456789"
1737 "01234567890123456789012345678901234567890123456789"
1739 "01234567890123456789012345678901234567890123456789"
1740 "01234567890123456789012345678901234567890123456789";
1741 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1742 (uint8_t *)buf, strlen(buf));
1747 printf(
"1 != %" PRIu32
" ",cnt);
1755 static int SCACBSTest11(
void)
1762 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1767 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1769 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1771 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1773 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1782 const char *buf =
"he";
1783 result &= (
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
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,
1802 static int SCACBSTest12(
void)
1809 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1822 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1823 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1824 (uint8_t *)buf, strlen(buf));
1829 printf(
"2 != %" PRIu32
" ",cnt);
1837 static int SCACBSTest13(
void)
1844 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1850 const char *pat =
"abcdefghijklmnopqrstuvwxyzABCD";
1851 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
1856 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1857 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1858 (uint8_t *)buf, strlen(buf));
1863 printf(
"1 != %" PRIu32
" ",cnt);
1871 static int SCACBSTest14(
void)
1878 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1884 const char *pat =
"abcdefghijklmnopqrstuvwxyzABCDE";
1885 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
1890 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1891 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1892 (uint8_t *)buf, strlen(buf));
1897 printf(
"1 != %" PRIu32
" ",cnt);
1905 static int SCACBSTest15(
void)
1912 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1918 const char *pat =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1919 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
1924 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1925 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1926 (uint8_t *)buf, strlen(buf));
1931 printf(
"1 != %" PRIu32
" ",cnt);
1939 static int SCACBSTest16(
void)
1946 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1952 const char *pat =
"abcdefghijklmnopqrstuvwxyzABC";
1953 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
1958 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1959 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1960 (uint8_t *)buf, strlen(buf));
1965 printf(
"1 != %" PRIu32
" ",cnt);
1973 static int SCACBSTest17(
void)
1980 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1986 const char *pat =
"abcdefghijklmnopqrstuvwxyzAB";
1987 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
1992 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1993 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
1994 (uint8_t *)buf, strlen(buf));
1999 printf(
"1 != %" PRIu32
" ",cnt);
2007 static int SCACBSTest18(
void)
2014 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2020 const char *pat =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2021 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
2026 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2027 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2028 (uint8_t *)buf, strlen(buf));
2033 printf(
"1 != %" PRIu32
" ",cnt);
2041 static int SCACBSTest19(
void)
2048 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2054 const char *pat =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2055 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
2060 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2061 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2062 (uint8_t *)buf, strlen(buf));
2067 printf(
"1 != %" PRIu32
" ",cnt);
2074 static int SCACBSTest20(
void)
2081 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2087 const char *pat =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2088 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat, strlen(pat), 0, 0, 0, 0, 0);
2093 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2094 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2095 (uint8_t *)buf, strlen(buf));
2100 printf(
"1 != %" PRIu32
" ",cnt);
2108 static int SCACBSTest21(
void)
2115 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2126 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2127 (uint8_t *)
"AA", 2);
2132 printf(
"1 != %" PRIu32
" ",cnt);
2140 static int SCACBSTest22(
void)
2147 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2160 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
2161 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2162 (uint8_t *)buf, strlen(buf));
2167 printf(
"2 != %" PRIu32
" ",cnt);
2175 static int SCACBSTest23(
void)
2182 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2193 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2194 (uint8_t *)
"aa", 2);
2199 printf(
"1 != %" PRIu32
" ",cnt);
2207 static int SCACBSTest24(
void)
2214 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2225 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2226 (uint8_t *)
"aa", 2);
2231 printf(
"1 != %" PRIu32
" ",cnt);
2239 static int SCACBSTest25(
void)
2246 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2258 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2259 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2260 (uint8_t *)buf, strlen(buf));
2265 printf(
"3 != %" PRIu32
" ",cnt);
2273 static int SCACBSTest26(
void)
2280 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2291 const char *buf =
"works";
2292 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2293 (uint8_t *)buf, strlen(buf));
2298 printf(
"3 != %" PRIu32
" ",cnt);
2306 static int SCACBSTest27(
void)
2313 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2324 const char *buf =
"tone";
2325 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2326 (uint8_t *)buf, strlen(buf));
2331 printf(
"0 != %" PRIu32
" ",cnt);
2339 static int SCACBSTest28(
void)
2346 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2357 const char *buf =
"tONE";
2358 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2359 (uint8_t *)buf, strlen(buf));
2364 printf(
"0 != %" PRIu32
" ",cnt);
2372 static int SCACBSTest29(
void)
2379 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2392 const char *buf =
"abcdefgh";
2393 uint32_t cnt =
SCACBSSearch(&mpm_ctx, &mpm_thread_ctx, &pmq,
2394 (uint8_t *)buf, strlen(buf));
2399 printf(
"3 != %" PRIu32
" ",cnt);
2407 static int SCACBSTest30(
void)
2409 uint8_t *buf = (uint8_t *)
"onetwothreefourfivesixseveneightnine";
2410 uint16_t buflen = strlen((
char *)buf);
2416 memset(&th_v, 0,
sizeof(th_v));
2427 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2431 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2440 printf(
"if (PacketAlertCheck(p, 1) != 1) failure\n");
2444 printf(
"if (PacketAlertCheck(p, 1) != 2) failure\n");