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);
870 SCLogDebug(
"no patterns supplied to this mpm_ctx");
875 SCLogDebug(
"no patterns supplied to this mpm_ctx");
881 if (
ctx->parray == NULL)
885 uint32_t i = 0, p = 0;
888 while(node != NULL) {
891 ctx->parray[p++] = node;
892 SCACTileHistogramAlphabet(
ctx, node);
906 size_t string_space_needed = 0;
910 uint32_t space = ((
ctx->parray[i]->len + 7) / 8) * 8;
911 string_space_needed += space;
916 size_t mem_size = string_space_needed + pattern_list_size;
917 void *mem_block =
SCCalloc(1, mem_size);
918 if (mem_block == NULL) {
924 ctx->pattern_list = mem_block;
925 uint8_t *string_space = mem_block + pattern_list_size;
930 uint16_t
len =
ctx->parray[i]->len;
931 uint32_t space = ((
len + 7) / 8) * 8;
932 memcpy(string_space,
ctx->parray[i]->original_pat,
len);
933 ctx->pattern_list[i].cs = string_space;
934 ctx->pattern_list[i].patlen =
len;
935 string_space += space;
937 ctx->pattern_list[i].offset =
ctx->parray[i]->offset;
938 ctx->pattern_list[i].depth =
ctx->parray[i]->depth;
939 ctx->pattern_list[i].pid =
ctx->parray[i]->id;
942 ctx->pattern_list[i].sids_size =
ctx->parray[i]->sids_size;
943 ctx->pattern_list[i].sids =
ctx->parray[i]->sids;
944 ctx->parray[i]->sids = NULL;
945 ctx->parray[i]->sids_size = 0;
949 SCACTilePrepareStateTable(mpm_ctx);
952 SCACTilePrepareSearch(mpm_ctx);
967 if (mpm_ctx->
ctx != NULL)
972 if (mpm_ctx->
ctx == NULL) {
1001 static void SCACTileDestroyInitCtx(
MpmCtx *mpm_ctx)
1014 if (
ctx->parray != NULL) {
1017 if (
ctx->parray[i] != NULL) {
1026 if (
ctx->state_table != NULL) {
1031 ctx->bytes_per_state *
ctx->alphabet_storage);
1034 if (
ctx->output_table != NULL) {
1036 for (state = 0; state <
ctx->state_count; state++) {
1037 if (
ctx->output_table[state].patterns != NULL) {
1038 SCFree(
ctx->output_table[state].patterns);
1044 if (
ctx->pattern_list != NULL) {
1047 if (
ctx->pattern_list[i].cs != NULL)
1049 if (
ctx->pattern_list[i].sids != NULL)
1069 if (search_ctx == NULL)
1073 SCACTileDestroyInitCtx(mpm_ctx);
1089 for (state = 0; state < search_ctx->
state_count; state++) {
1098 mpm_ctx->
ctx = NULL;
1108 #define SCHECK(x) ((x) > 0)
1109 #define BUF_TYPE int32_t
1111 #define BYTE0(x) (((x) & 0x000000ff) >> 0)
1112 #define BYTE1(x) (((x) & 0x0000ff00) >> 8)
1113 #define BYTE2(x) (((x) & 0x00ff0000) >> 16)
1114 #define BYTE3(x) (((x) & 0xff000000) >> 24)
1115 #define EXTRA 4 // need 4 extra bytes to avoid OOB reads
1118 const uint8_t *buf, uint32_t buflen,
1119 uint16_t state,
int i,
int matches,
1120 uint8_t *mpm_bitarray)
1123 const uint8_t *buf_offset = buf + i + 1;
1124 uint32_t no_of_entries =
ctx->output_table[state].no_of_entries;
1128 for (k = 0; k < no_of_entries; k++) {
1130 if (mpm_bitarray[pindex / 8] & (1 << (pindex % 8))) {
1140 if (patterns[k] >> 31) {
1141 const uint16_t patlen = pat->
patlen;
1142 if (
SCMemcmp(pat->
cs, buf_offset - patlen, patlen) != 0) {
1148 mpm_bitarray[pindex / 8] |= (1 << (pindex % 8));
1153 PrefilterAddSids(pmq, pattern_list[pindex].sids,
1154 pattern_list[pindex].sids_size);
1182 return search_ctx->
Search(search_ctx, mpm_thread_ctx, pmq, buf, buflen);
1188 const uint8_t *buf, uint32_t buflen)
1193 uint8_t mpm_bitarray[
ctx->mpm_bitarray_size];
1194 memset(mpm_bitarray, 0,
ctx->mpm_bitarray_size);
1196 const uint8_t* restrict xlate =
ctx->translate_table;
1197 register int state = 0;
1198 int32_t (*state_table_u32)[256] =
ctx->state_table;
1199 for (i = 0; i < buflen; i++) {
1200 state = state_table_u32[state & 0x00FFFFFF][xlate[buf[i]]];
1203 matches = CheckMatch(
ctx, pmq, buf, buflen, (uint16_t)state, i, matches, mpm_bitarray);
1215 #define SINDEX_INTERNAL(y, x, log_mult, width) \
1216 ((1<<log_mult) * (x & ((1<<width) - 1)))
1219 #define STYPE int16_t
1220 #define SLOAD(x) *(STYPE * restrict)(x)
1222 #define FUNC_NAME SCACTileSearchSmall256
1224 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 15)
1230 #define FUNC_NAME SCACTileSearchSmall128
1232 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 15)
1238 #define FUNC_NAME SCACTileSearchSmall64
1240 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 15)
1246 #define FUNC_NAME SCACTileSearchSmall32
1248 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 15)
1254 #define FUNC_NAME SCACTileSearchSmall16
1256 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 15)
1262 #define FUNC_NAME SCACTileSearchSmall8
1264 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 15)
1272 #define STYPE int8_t
1276 #define FUNC_NAME SCACTileSearchTiny256
1278 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 7)
1284 #define FUNC_NAME SCACTileSearchTiny128
1286 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 7)
1292 #define FUNC_NAME SCACTileSearchTiny64
1294 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 7)
1300 #define FUNC_NAME SCACTileSearchTiny32
1302 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 7)
1308 #define FUNC_NAME SCACTileSearchTiny16
1310 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 7)
1316 #define FUNC_NAME SCACTileSearchTiny8
1318 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 7)
1340 uint16_t
offset, uint16_t depth, uint32_t pid,
1366 uint16_t
offset, uint16_t depth, uint32_t pid,
1378 printf(
"MPM AC Information:\n");
1379 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1380 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1381 printf(
" Sizeof:\n");
1382 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1383 printf(
" SCACTileCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACTileCtx));
1384 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1385 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1386 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1387 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1388 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1389 printf(
"Total states in the state table: %u\n",
ctx->state_count);
1425 static int SCACTileTest01(
void)
1432 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1442 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1445 (uint8_t *)buf, strlen(buf));
1450 printf(
"1 != %" PRIu32
" ",
cnt);
1457 static int SCACTileTest02(
void)
1464 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1474 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1476 (uint8_t *)buf, strlen(buf));
1481 printf(
"0 != %" PRIu32
" ",
cnt);
1488 static int SCACTileTest03(
void)
1495 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1509 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1511 (uint8_t *)buf, strlen(buf));
1516 printf(
"3 != %" PRIu32
" ",
cnt);
1523 static int SCACTileTest04(
void)
1530 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1541 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1543 (uint8_t *)buf, strlen(buf));
1548 printf(
"1 != %" PRIu32
" ",
cnt);
1555 static int SCACTileTest05(
void)
1562 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1573 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1575 (uint8_t *)buf, strlen(buf));
1580 printf(
"3 != %" PRIu32
" ",
cnt);
1587 static int SCACTileTest06(
void)
1594 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1603 const char *buf =
"abcd";
1605 (uint8_t *)buf, strlen(buf));
1610 printf(
"1 != %" PRIu32
" ",
cnt);
1617 static int SCACTileTest07(
void)
1623 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1636 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1638 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1645 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1647 (uint8_t *)buf, strlen(buf));
1655 static int SCACTileTest08(
void)
1662 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1678 printf(
"0 != %" PRIu32
" ",
cnt);
1685 static int SCACTileTest09(
void)
1692 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1703 (uint8_t *)
"ab", 2);
1708 printf(
"1 != %" PRIu32
" ",
cnt);
1715 static int SCACTileTest10(
void)
1722 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1732 const char *buf =
"01234567890123456789012345678901234567890123456789"
1733 "01234567890123456789012345678901234567890123456789"
1735 "01234567890123456789012345678901234567890123456789"
1736 "01234567890123456789012345678901234567890123456789";
1738 (uint8_t *)buf, strlen(buf));
1743 printf(
"1 != %" PRIu32
" ",
cnt);
1750 static int SCACTileTest11(
void)
1757 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1761 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1763 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1765 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1767 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1776 const char *buf =
"he";
1777 result &= (
SCACTileSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1780 result &= (
SCACTileSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1783 result &= (
SCACTileSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1786 result &= (
SCACTileSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf,
1795 static int SCACTileTest12(
void)
1802 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1814 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1816 (uint8_t *)buf, strlen(buf));
1821 printf(
"2 != %" PRIu32
" ",
cnt);
1828 static int SCACTileTest13(
void)
1835 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1840 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1841 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1846 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1848 (uint8_t *)buf, strlen(buf));
1853 printf(
"1 != %" PRIu32
" ",
cnt);
1860 static int SCACTileTest14(
void)
1867 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1872 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1873 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1878 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1880 (uint8_t *)buf, strlen(buf));
1885 printf(
"1 != %" PRIu32
" ",
cnt);
1892 static int SCACTileTest15(
void)
1899 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1904 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1905 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1910 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1912 (uint8_t *)buf, strlen(buf));
1917 printf(
"1 != %" PRIu32
" ",
cnt);
1924 static int SCACTileTest16(
void)
1931 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1936 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1937 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1942 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1944 (uint8_t *)buf, strlen(buf));
1949 printf(
"1 != %" PRIu32
" ",
cnt);
1956 static int SCACTileTest17(
void)
1963 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1968 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1969 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1974 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1976 (uint8_t *)buf, strlen(buf));
1981 printf(
"1 != %" PRIu32
" ",
cnt);
1988 static int SCACTileTest18(
void)
1995 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2000 const char pat[] =
"abcde"
2006 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2011 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2013 (uint8_t *)buf, strlen(buf));
2018 printf(
"1 != %" PRIu32
" ",
cnt);
2025 static int SCACTileTest19(
void)
2032 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2037 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2038 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2043 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2045 (uint8_t *)buf, strlen(buf));
2050 printf(
"1 != %" PRIu32
" ",
cnt);
2057 static int SCACTileTest20(
void)
2064 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2069 const char pat[] =
"AAAAA"
2076 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2081 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2083 (uint8_t *)buf, strlen(buf));
2088 printf(
"1 != %" PRIu32
" ",
cnt);
2095 static int SCACTileTest21(
void)
2102 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2113 (uint8_t *)
"AA", 2);
2118 printf(
"1 != %" PRIu32
" ",
cnt);
2125 static int SCACTileTest22(
void)
2132 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2144 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
2146 (uint8_t *)buf, strlen(buf));
2151 printf(
"2 != %" PRIu32
" ",
cnt);
2158 static int SCACTileTest23(
void)
2165 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2176 (uint8_t *)
"aa", 2);
2181 printf(
"1 != %" PRIu32
" ",
cnt);
2188 static int SCACTileTest24(
void)
2195 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2206 (uint8_t *)
"aa", 2);
2211 printf(
"1 != %" PRIu32
" ",
cnt);
2218 static int SCACTileTest25(
void)
2225 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2236 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2238 (uint8_t *)buf, strlen(buf));
2243 printf(
"3 != %" PRIu32
" ",
cnt);
2250 static int SCACTileTest26(
void)
2257 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2267 const char *buf =
"works";
2269 (uint8_t *)buf, strlen(buf));
2274 printf(
"3 != %" PRIu32
" ",
cnt);
2281 static int SCACTileTest27(
void)
2288 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2298 const char *buf =
"tone";
2300 (uint8_t *)buf, strlen(buf));
2305 printf(
"0 != %" PRIu32
" ",
cnt);
2312 static int SCACTileTest28(
void)
2319 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2329 const char *buf =
"tONE";
2331 (uint8_t *)buf, strlen(buf));
2336 printf(
"0 != %" PRIu32
" ",
cnt);
2343 static int SCACTileTest29(
void)
2345 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2346 uint16_t buflen =
sizeof(buf) - 1;
2352 memset(&th_v, 0,
sizeof(th_v));
2362 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2366 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2375 printf(
"if (PacketAlertCheck(p, 1) != 1) failure\n");
2379 printf(
"if (PacketAlertCheck(p, 1) != 2) failure\n");
2397 void SCACTileRegisterTests(
void)