85 #if __BYTE_ORDER == __LITTLE_ENDIAN
99 static void SCACTileRegisterTests(
void);
104 const uint8_t *buf, uint32_t buflen);
107 const uint8_t *buf, uint32_t buflen);
110 const uint8_t *buf, uint32_t buflen);
113 const uint8_t *buf, uint32_t buflen);
116 const uint8_t *buf, uint32_t buflen);
119 const uint8_t *buf, uint32_t buflen);
122 const uint8_t *buf, uint32_t buflen);
126 const uint8_t *buf, uint32_t buflen);
129 const uint8_t *buf, uint32_t buflen);
132 const uint8_t *buf, uint32_t buflen);
135 const uint8_t *buf, uint32_t buflen);
138 const uint8_t *buf, uint32_t buflen);
141 const uint8_t *buf, uint32_t buflen);
144 static void SCACTileDestroyInitCtx(
MpmCtx *mpm_ctx);
148 #define SC_AC_TILE_FAIL (-1)
150 #define STATE_QUEUE_CONTAINER_SIZE 65536
167 static void SCACTileGetConfig(
void)
180 for (
int i = 0; i < p->
len; i++) {
181 ctx->alpha_hist[p->
ci[i]]++;
193 for (
int i = 0; i < 256; i++) {
195 if (i >=
'A' && i <=
'Z') {
196 ctx->alpha_hist[i -
'A' +
'a'] +=
ctx->alpha_hist[i];
197 ctx->alpha_hist[i] = 0;
199 if (
ctx->alpha_hist[i]) {
200 ctx->alphabet_size++;
202 ctx->translate_table[i] = (uint8_t)
ctx->alphabet_size;
204 ctx->translate_table[i] = 0;
207 for (
int i =
'A'; i <=
'Z'; i++)
208 ctx->translate_table[i] =
ctx->translate_table[i -
'A' +
'a'];
215 ctx->alphabet_size += 1;
216 if (
ctx->alphabet_size <= 8) {
217 ctx->alphabet_storage = 8;
218 }
else if (
ctx->alphabet_size <= 16) {
219 ctx->alphabet_storage = 16;
220 }
else if (
ctx->alphabet_size <= 32) {
221 ctx->alphabet_storage = 32;
222 }
else if (
ctx->alphabet_size <= 64) {
223 ctx->alphabet_storage = 64;
224 }
else if (
ctx->alphabet_size <= 128) {
225 ctx->alphabet_storage = 128;
227 ctx->alphabet_storage = 256;
230 static void SCACTileReallocOutputTable(
SCACTileCtx *
ctx,
int new_state_count)
238 ctx->output_table = NULL;
241 ctx->output_table = ptmp;
244 static void SCACTileReallocState(
SCACTileCtx *
ctx,
int new_state_count)
247 size_t size =
ctx->allocated_state_count *
sizeof(int32_t) * 256;
251 ctx->goto_table = NULL;
254 ctx->goto_table = ptmp;
256 SCACTileReallocOutputTable(
ctx, new_state_count);
267 static inline int SCACTileInitNewState(
MpmCtx *mpm_ctx)
274 if (
ctx->allocated_state_count <
ctx->state_count + 1) {
275 if (
ctx->allocated_state_count == 0)
276 ctx->allocated_state_count = 256;
278 ctx->allocated_state_count *= 2;
280 SCACTileReallocState(
ctx,
ctx->allocated_state_count);
284 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
288 memset(
ctx->output_table +
ctx->state_count, 0,
291 return ctx->state_count++;
312 for (i = 0; i < output_state->no_of_entries; i++) {
313 if (output_state->patterns[i] == pindex)
319 output_state->no_of_entries++;
323 SCFree(output_state->patterns);
324 output_state->patterns = NULL;
327 output_state->patterns = ptmp;
329 output_state->patterns[output_state->no_of_entries - 1] = pindex;
342 static void SCACTileEnter(uint8_t *pattern, uint16_t pattern_len,
349 int32_t newstate = 0;
356 for (i = 0; i < pattern_len; i++) {
357 tc =
ctx->translate_table[pattern[i]];
360 state =
ctx->goto_table[state][tc];
365 for (p = i; p < pattern_len; p++) {
366 newstate = SCACTileInitNewState(mpm_ctx);
367 tc =
ctx->translate_table[pattern[p]];
368 ctx->goto_table[state][tc] = newstate;
374 SCACTileSetOutputState(state, pindex, mpm_ctx);
383 static void SCACTileCreateGotoTable(
MpmCtx *mpm_ctx)
392 SCACTileEnter(
ctx->parray[i]->ci,
ctx->parray[i]->len,
397 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
399 ctx->goto_table[0][aa] = 0;
404 static inline int SCACTileStateQueueIsEmpty(
StateQueue *q)
412 static inline void SCACTileEnqueue(
StateQueue *q, int32_t state)
417 for (i = q->
bot; i < q->top; i++) {
418 if (q->
store[i] == state)
428 FatalError(
"Just ran out of space in the queue. "
429 "Fatal Error. Exiting. Please file a bug report on this");
433 static inline int32_t SCACTileDequeue(
StateQueue *q)
440 "Fatal Error. Exiting. Please file a bug report on this");
455 static void SCACTileClubOutputStates(int32_t dst_state,
469 for (i = 0; i < output_src_state->no_of_entries; i++) {
470 for (j = 0; j < output_dst_state->no_of_entries; j++) {
471 if (output_src_state->patterns[i] == output_dst_state->patterns[j]) {
475 if (j == output_dst_state->no_of_entries) {
476 output_dst_state->no_of_entries++;
478 ptmp =
SCRealloc(output_dst_state->patterns,
479 (output_dst_state->no_of_entries *
sizeof(uint32_t)));
481 SCFree(output_dst_state->patterns);
482 output_dst_state->patterns = NULL;
485 output_dst_state->patterns = ptmp;
487 output_dst_state->patterns[output_dst_state->no_of_entries - 1] =
488 output_src_state->patterns[i];
499 static void SCACTileCreateFailureTable(
MpmCtx *mpm_ctx)
514 if (
ctx->failure_table == NULL) {
521 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
522 int32_t temp_state =
ctx->goto_table[0][aa];
523 if (temp_state != 0) {
524 SCACTileEnqueue(&q, temp_state);
525 ctx->failure_table[temp_state] = 0;
529 while (!SCACTileStateQueueIsEmpty(&q)) {
531 r_state = SCACTileDequeue(&q);
532 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
533 int32_t temp_state =
ctx->goto_table[r_state][aa];
536 SCACTileEnqueue(&q, temp_state);
537 state =
ctx->failure_table[r_state];
540 state =
ctx->failure_table[state];
541 ctx->failure_table[temp_state] =
ctx->goto_table[state][aa];
542 SCACTileClubOutputStates(temp_state,
ctx->failure_table[temp_state],
551 static void SCACTileSetState1Byte(
SCACTileCtx *
ctx,
int state,
int aa,
552 int next_state,
int outputs)
554 uint8_t *state_table = (uint8_t*)
ctx->state_table;
556 uint8_t encoded_next_state = (uint8_t)next_state;
563 encoded_next_state |= (1 << 7);
565 state_table[state *
ctx->alphabet_storage + aa] = encoded_next_state;
571 static void SCACTileSetState2Bytes(
SCACTileCtx *
ctx,
int state,
int aa,
572 int next_state,
int outputs)
574 uint16_t *state_table = (uint16_t*)
ctx->state_table;
576 uint16_t encoded_next_state = (uint16_t)next_state;
583 encoded_next_state |= (1 << 15);
585 state_table[state *
ctx->alphabet_storage + aa] = encoded_next_state;
591 static void SCACTileSetState4Bytes(
SCACTileCtx *
ctx,
int state,
int aa,
592 int next_state,
int outputs)
594 uint32_t *state_table = (uint32_t*)
ctx->state_table;
595 uint32_t encoded_next_state = next_state;
602 encoded_next_state |= (1UL << 31);
604 state_table[state *
ctx->alphabet_storage + aa] = encoded_next_state;
613 static inline void SCACTileCreateDeltaTable(
MpmCtx *mpm_ctx)
621 if (
ctx->state_count < 32767) {
622 if (
ctx->state_count < 128) {
623 ctx->bytes_per_state = 1;
624 ctx->SetNextState = SCACTileSetState1Byte;
626 switch(
ctx->alphabet_storage) {
647 ctx->bytes_per_state = 2;
648 ctx->SetNextState = SCACTileSetState2Bytes;
650 switch(
ctx->alphabet_storage) {
673 ctx->bytes_per_state = 4;
674 ctx->SetNextState = SCACTileSetState4Bytes;
676 ctx->alphabet_storage = 256;
682 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
683 int temp_state =
ctx->goto_table[0][aa];
685 SCACTileEnqueue(&q, temp_state);
688 while (!SCACTileStateQueueIsEmpty(&q)) {
689 r_state = SCACTileDequeue(&q);
691 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
692 int temp_state =
ctx->goto_table[r_state][aa];
694 SCACTileEnqueue(&q, temp_state);
696 int f_state =
ctx->failure_table[r_state];
697 ctx->goto_table[r_state][aa] =
ctx->goto_table[f_state][aa];
703 static void SCACTileClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
712 int size =
ctx->state_count *
ctx->bytes_per_state *
ctx->alphabet_storage;
713 void *state_table =
SCCalloc(1, size);
714 if (
unlikely(state_table == NULL)) {
717 ctx->state_table = state_table;
722 SCLogDebug(
"Delta Table size %d, alphabet: %d, %d-byte states: %d",
723 size,
ctx->alphabet_size,
ctx->bytes_per_state,
ctx->state_count);
729 for (state = 0; state <
ctx->state_count; state++) {
730 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
731 int next_state =
ctx->goto_table[state][aa];
732 int next_state_outputs =
ctx->output_table[next_state].no_of_entries;
733 ctx->SetNextState(
ctx, state, aa, next_state, next_state_outputs);
738 static inline void SCACTileInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
746 for (state = 0; state <
ctx->state_count; state++) {
747 if (
ctx->output_table[state].no_of_entries == 0)
750 for (k = 0; k <
ctx->output_table[state].no_of_entries; k++) {
751 if (
ctx->pattern_list[
ctx->output_table[state].patterns[k]].cs != NULL) {
753 ctx->output_table[state].patterns[k] &= 0x0FFFFFFF;
754 ctx->output_table[state].patterns[k] |= (uint32_t)1 << 31;
761 static void SCACTilePrintDeltaTable(
MpmCtx *mpm_ctx)
768 printf(
"##############Delta Table##############\n");
769 for (i = 0; i <
ctx->state_count; i++) {
771 for (j = 0; j <
ctx->alphabet_size; j++) {
772 if (SCACTileGetDelta(i, j, mpm_ctx) != 0) {
773 printf(
" %c -> %d\n", j, SCACTileGetDelta(i, j, mpm_ctx));
785 static void SCACTilePrepareStateTable(
MpmCtx *mpm_ctx)
791 SCACTileInitTranslateTable(
ctx);
794 SCACTileInitNewState(mpm_ctx);
797 SCACTileCreateGotoTable(mpm_ctx);
799 SCACTileCreateFailureTable(mpm_ctx);
801 SCACTileCreateDeltaTable(mpm_ctx);
803 SCACTileClubOutputStatePresenceWithDeltaTable(mpm_ctx);
806 SCACTileInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
809 SCACTilePrintDeltaTable(mpm_ctx);
814 ctx->goto_table = NULL;
816 ctx->failure_table = NULL;
827 static void SCACTilePrepareSearch(
MpmCtx *mpm_ctx)
833 SCACTileReallocOutputTable(
ctx,
ctx->state_count);
840 ctx->state_table = NULL;
845 ctx->output_table = NULL;
849 ctx->pattern_list = NULL;
856 SCACTileDestroyInitCtx(mpm_ctx);
869 SCLogDebug(
"no patterns supplied to this mpm_ctx");
874 SCLogDebug(
"no patterns supplied to this mpm_ctx");
880 if (
ctx->parray == NULL)
884 uint32_t i = 0, p = 0;
887 while(node != NULL) {
890 ctx->parray[p++] = node;
891 SCACTileHistogramAlphabet(
ctx, node);
905 size_t string_space_needed = 0;
909 uint32_t space = ((
ctx->parray[i]->len + 7) / 8) * 8;
910 string_space_needed += space;
915 size_t mem_size = string_space_needed + pattern_list_size;
916 void *mem_block =
SCCalloc(1, mem_size);
917 if (mem_block == NULL) {
923 ctx->pattern_list = mem_block;
924 uint8_t *string_space = mem_block + pattern_list_size;
929 uint16_t
len =
ctx->parray[i]->len;
930 uint32_t space = ((
len + 7) / 8) * 8;
931 memcpy(string_space,
ctx->parray[i]->original_pat,
len);
932 ctx->pattern_list[i].cs = string_space;
933 ctx->pattern_list[i].patlen =
len;
934 string_space += space;
936 ctx->pattern_list[i].offset =
ctx->parray[i]->offset;
937 ctx->pattern_list[i].depth =
ctx->parray[i]->depth;
938 ctx->pattern_list[i].pid =
ctx->parray[i]->id;
941 ctx->pattern_list[i].sids_size =
ctx->parray[i]->sids_size;
942 ctx->pattern_list[i].sids =
ctx->parray[i]->sids;
943 ctx->parray[i]->sids = NULL;
944 ctx->parray[i]->sids_size = 0;
948 SCACTilePrepareStateTable(mpm_ctx);
951 SCACTilePrepareSearch(mpm_ctx);
966 if (mpm_ctx->
ctx != NULL)
971 if (mpm_ctx->
ctx == NULL) {
1000 static void SCACTileDestroyInitCtx(
MpmCtx *mpm_ctx)
1013 if (
ctx->parray != NULL) {
1016 if (
ctx->parray[i] != NULL) {
1025 if (
ctx->state_table != NULL) {
1030 ctx->bytes_per_state *
ctx->alphabet_storage);
1033 if (
ctx->output_table != NULL) {
1035 for (state = 0; state <
ctx->state_count; state++) {
1036 if (
ctx->output_table[state].patterns != NULL) {
1037 SCFree(
ctx->output_table[state].patterns);
1043 if (
ctx->pattern_list != NULL) {
1046 if (
ctx->pattern_list[i].cs != NULL)
1048 if (
ctx->pattern_list[i].sids != NULL)
1068 if (search_ctx == NULL)
1072 SCACTileDestroyInitCtx(mpm_ctx);
1088 for (state = 0; state < search_ctx->
state_count; state++) {
1097 mpm_ctx->
ctx = NULL;
1107 #define SCHECK(x) ((x) > 0)
1108 #define BUF_TYPE int32_t
1110 #define BYTE0(x) (((x) & 0x000000ff) >> 0)
1111 #define BYTE1(x) (((x) & 0x0000ff00) >> 8)
1112 #define BYTE2(x) (((x) & 0x00ff0000) >> 16)
1113 #define BYTE3(x) (((x) & 0xff000000) >> 24)
1114 #define EXTRA 4 // need 4 extra bytes to avoid OOB reads
1117 const uint8_t *buf, uint32_t buflen,
1118 uint16_t state,
int i,
int matches,
1119 uint8_t *mpm_bitarray)
1122 const uint8_t *buf_offset = buf + i + 1;
1123 uint32_t no_of_entries =
ctx->output_table[state].no_of_entries;
1127 for (k = 0; k < no_of_entries; k++) {
1129 if (mpm_bitarray[pindex / 8] & (1 << (pindex % 8))) {
1139 if (patterns[k] >> 31) {
1140 const uint16_t patlen = pat->
patlen;
1141 if (
SCMemcmp(pat->
cs, buf_offset - patlen, patlen) != 0) {
1147 mpm_bitarray[pindex / 8] |= (1 << (pindex % 8));
1152 PrefilterAddSids(pmq, pattern_list[pindex].sids,
1153 pattern_list[pindex].sids_size);
1181 return search_ctx->
Search(search_ctx, mpm_thread_ctx, pmq, buf, buflen);
1187 const uint8_t *buf, uint32_t buflen)
1192 uint8_t mpm_bitarray[
ctx->mpm_bitarray_size];
1193 memset(mpm_bitarray, 0,
ctx->mpm_bitarray_size);
1195 const uint8_t* restrict xlate =
ctx->translate_table;
1196 register int state = 0;
1197 int32_t (*state_table_u32)[256] =
ctx->state_table;
1198 for (i = 0; i < buflen; i++) {
1199 state = state_table_u32[state & 0x00FFFFFF][xlate[buf[i]]];
1202 matches = CheckMatch(
ctx, pmq, buf, buflen, (uint16_t)state, i, matches, mpm_bitarray);
1214 #define SINDEX_INTERNAL(y, x, log_mult, width) \
1215 ((1<<log_mult) * (x & ((1<<width) - 1)))
1218 #define STYPE int16_t
1219 #define SLOAD(x) *(STYPE * restrict)(x)
1221 #define FUNC_NAME SCACTileSearchSmall256
1223 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 15)
1229 #define FUNC_NAME SCACTileSearchSmall128
1231 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 15)
1237 #define FUNC_NAME SCACTileSearchSmall64
1239 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 15)
1245 #define FUNC_NAME SCACTileSearchSmall32
1247 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 15)
1253 #define FUNC_NAME SCACTileSearchSmall16
1255 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 15)
1261 #define FUNC_NAME SCACTileSearchSmall8
1263 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 15)
1271 #define STYPE int8_t
1275 #define FUNC_NAME SCACTileSearchTiny256
1277 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 7)
1283 #define FUNC_NAME SCACTileSearchTiny128
1285 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 7)
1291 #define FUNC_NAME SCACTileSearchTiny64
1293 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 7)
1299 #define FUNC_NAME SCACTileSearchTiny32
1301 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 7)
1307 #define FUNC_NAME SCACTileSearchTiny16
1309 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 7)
1315 #define FUNC_NAME SCACTileSearchTiny8
1317 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 7)
1339 uint16_t
offset, uint16_t depth, uint32_t pid,
1365 uint16_t
offset, uint16_t depth, uint32_t pid,
1377 printf(
"MPM AC Information:\n");
1378 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1379 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1380 printf(
" Sizeof:\n");
1381 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1382 printf(
" SCACTileCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACTileCtx));
1383 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1384 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1385 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1386 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1387 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1388 printf(
"Total states in the state table: %u\n",
ctx->state_count);
1420 static int SCACTileTest01(
void)
1427 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1437 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1440 (uint8_t *)buf, strlen(buf));
1445 printf(
"1 != %" PRIu32
" ",
cnt);
1452 static int SCACTileTest02(
void)
1459 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1469 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1471 (uint8_t *)buf, strlen(buf));
1476 printf(
"0 != %" PRIu32
" ",
cnt);
1483 static int SCACTileTest03(
void)
1490 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1504 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1506 (uint8_t *)buf, strlen(buf));
1511 printf(
"3 != %" PRIu32
" ",
cnt);
1518 static int SCACTileTest04(
void)
1525 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1536 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1538 (uint8_t *)buf, strlen(buf));
1543 printf(
"1 != %" PRIu32
" ",
cnt);
1550 static int SCACTileTest05(
void)
1557 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1568 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1570 (uint8_t *)buf, strlen(buf));
1575 printf(
"3 != %" PRIu32
" ",
cnt);
1582 static int SCACTileTest06(
void)
1589 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1598 const char *buf =
"abcd";
1600 (uint8_t *)buf, strlen(buf));
1605 printf(
"1 != %" PRIu32
" ",
cnt);
1612 static int SCACTileTest07(
void)
1618 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1631 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1633 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1640 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1642 (uint8_t *)buf, strlen(buf));
1650 static int SCACTileTest08(
void)
1657 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1673 printf(
"0 != %" PRIu32
" ",
cnt);
1680 static int SCACTileTest09(
void)
1687 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1698 (uint8_t *)
"ab", 2);
1703 printf(
"1 != %" PRIu32
" ",
cnt);
1710 static int SCACTileTest10(
void)
1717 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1727 const char *buf =
"01234567890123456789012345678901234567890123456789"
1728 "01234567890123456789012345678901234567890123456789"
1730 "01234567890123456789012345678901234567890123456789"
1731 "01234567890123456789012345678901234567890123456789";
1733 (uint8_t *)buf, strlen(buf));
1738 printf(
"1 != %" PRIu32
" ",
cnt);
1745 static int SCACTileTest11(
void)
1752 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1756 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1758 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1760 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1762 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1771 const char *buf =
"he";
1772 result &= (
SCACTileSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1775 result &= (
SCACTileSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1778 result &= (
SCACTileSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1781 result &= (
SCACTileSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1790 static int SCACTileTest12(
void)
1797 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1809 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1811 (uint8_t *)buf, strlen(buf));
1816 printf(
"2 != %" PRIu32
" ",
cnt);
1823 static int SCACTileTest13(
void)
1830 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1835 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1836 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1841 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1843 (uint8_t *)buf, strlen(buf));
1848 printf(
"1 != %" PRIu32
" ",
cnt);
1855 static int SCACTileTest14(
void)
1862 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1867 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1868 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1873 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1875 (uint8_t *)buf, strlen(buf));
1880 printf(
"1 != %" PRIu32
" ",
cnt);
1887 static int SCACTileTest15(
void)
1894 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1899 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1900 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1905 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1907 (uint8_t *)buf, strlen(buf));
1912 printf(
"1 != %" PRIu32
" ",
cnt);
1919 static int SCACTileTest16(
void)
1926 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1931 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1932 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1937 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1939 (uint8_t *)buf, strlen(buf));
1944 printf(
"1 != %" PRIu32
" ",
cnt);
1951 static int SCACTileTest17(
void)
1958 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1963 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1964 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1969 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1971 (uint8_t *)buf, strlen(buf));
1976 printf(
"1 != %" PRIu32
" ",
cnt);
1983 static int SCACTileTest18(
void)
1990 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1995 const char pat[] =
"abcde"
2001 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2006 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2008 (uint8_t *)buf, strlen(buf));
2013 printf(
"1 != %" PRIu32
" ",
cnt);
2020 static int SCACTileTest19(
void)
2027 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2032 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2033 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2038 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2040 (uint8_t *)buf, strlen(buf));
2045 printf(
"1 != %" PRIu32
" ",
cnt);
2052 static int SCACTileTest20(
void)
2059 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2064 const char pat[] =
"AAAAA"
2071 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2076 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2078 (uint8_t *)buf, strlen(buf));
2083 printf(
"1 != %" PRIu32
" ",
cnt);
2090 static int SCACTileTest21(
void)
2097 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2108 (uint8_t *)
"AA", 2);
2113 printf(
"1 != %" PRIu32
" ",
cnt);
2120 static int SCACTileTest22(
void)
2127 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2139 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
2141 (uint8_t *)buf, strlen(buf));
2146 printf(
"2 != %" PRIu32
" ",
cnt);
2153 static int SCACTileTest23(
void)
2160 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2171 (uint8_t *)
"aa", 2);
2176 printf(
"1 != %" PRIu32
" ",
cnt);
2183 static int SCACTileTest24(
void)
2190 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2201 (uint8_t *)
"aa", 2);
2206 printf(
"1 != %" PRIu32
" ",
cnt);
2213 static int SCACTileTest25(
void)
2220 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2231 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2233 (uint8_t *)buf, strlen(buf));
2238 printf(
"3 != %" PRIu32
" ",
cnt);
2245 static int SCACTileTest26(
void)
2252 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2262 const char *buf =
"works";
2264 (uint8_t *)buf, strlen(buf));
2269 printf(
"3 != %" PRIu32
" ",
cnt);
2276 static int SCACTileTest27(
void)
2283 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2293 const char *buf =
"tone";
2295 (uint8_t *)buf, strlen(buf));
2300 printf(
"0 != %" PRIu32
" ",
cnt);
2307 static int SCACTileTest28(
void)
2314 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2324 const char *buf =
"tONE";
2326 (uint8_t *)buf, strlen(buf));
2331 printf(
"0 != %" PRIu32
" ",
cnt);
2338 static int SCACTileTest29(
void)
2340 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2341 uint16_t buflen =
sizeof(buf) - 1;
2347 memset(&th_v, 0,
sizeof(th_v));
2357 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2361 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2370 printf(
"if (PacketAlertCheck(p, 1) != 1) failure\n");
2374 printf(
"if (PacketAlertCheck(p, 1) != 2) failure\n");
2392 void SCACTileRegisterTests(
void)