86 #if __BYTE_ORDER == __LITTLE_ENDIAN
91 MpmCtx *,
const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t,
SigIntId, uint8_t);
100 static void SCACTileRegisterTests(
void);
105 const uint8_t *buf, uint32_t buflen);
108 const uint8_t *buf, uint32_t buflen);
111 const uint8_t *buf, uint32_t buflen);
114 const uint8_t *buf, uint32_t buflen);
117 const uint8_t *buf, uint32_t buflen);
120 const uint8_t *buf, uint32_t buflen);
123 const uint8_t *buf, uint32_t buflen);
127 const uint8_t *buf, uint32_t buflen);
130 const uint8_t *buf, uint32_t buflen);
133 const uint8_t *buf, uint32_t buflen);
136 const uint8_t *buf, uint32_t buflen);
139 const uint8_t *buf, uint32_t buflen);
142 const uint8_t *buf, uint32_t buflen);
145 static void SCACTileDestroyInitCtx(
MpmCtx *mpm_ctx);
149 #define SC_AC_TILE_FAIL (-1)
157 static void SCACTileGetConfig(
void)
170 for (
int i = 0; i <
p->len; i++) {
171 ctx->alpha_hist[
p->ci[i]]++;
183 for (
int i = 0; i < 256; i++) {
185 if (i >=
'A' && i <=
'Z') {
186 ctx->alpha_hist[i -
'A' +
'a'] +=
ctx->alpha_hist[i];
187 ctx->alpha_hist[i] = 0;
189 if (
ctx->alpha_hist[i]) {
190 ctx->alphabet_size++;
192 ctx->translate_table[i] = (uint8_t)
ctx->alphabet_size;
194 ctx->translate_table[i] = 0;
197 for (
int i =
'A'; i <=
'Z'; i++)
198 ctx->translate_table[i] =
ctx->translate_table[i -
'A' +
'a'];
205 ctx->alphabet_size += 1;
206 if (
ctx->alphabet_size <= 8) {
207 ctx->alphabet_storage = 8;
208 }
else if (
ctx->alphabet_size <= 16) {
209 ctx->alphabet_storage = 16;
210 }
else if (
ctx->alphabet_size <= 32) {
211 ctx->alphabet_storage = 32;
212 }
else if (
ctx->alphabet_size <= 64) {
213 ctx->alphabet_storage = 64;
214 }
else if (
ctx->alphabet_size <= 128) {
215 ctx->alphabet_storage = 128;
217 ctx->alphabet_storage = 256;
220 static void SCACTileReallocOutputTable(
SCACTileCtx *
ctx,
int new_state_count)
228 ctx->output_table = NULL;
231 ctx->output_table = ptmp;
234 static void SCACTileReallocState(
SCACTileCtx *
ctx,
int new_state_count)
237 size_t size =
ctx->allocated_state_count *
sizeof(int32_t) * 256;
241 ctx->goto_table = NULL;
244 ctx->goto_table = ptmp;
246 SCACTileReallocOutputTable(
ctx, new_state_count);
257 static inline int SCACTileInitNewState(
MpmCtx *mpm_ctx)
264 if (
ctx->allocated_state_count <
ctx->state_count + 1) {
265 if (
ctx->allocated_state_count == 0)
266 ctx->allocated_state_count = 256;
268 ctx->allocated_state_count *= 2;
270 SCACTileReallocState(
ctx,
ctx->allocated_state_count);
274 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
278 memset(
ctx->output_table +
ctx->state_count, 0,
281 return ctx->state_count++;
302 for (i = 0; i < output_state->no_of_entries; i++) {
303 if (output_state->patterns[i] == pindex)
309 output_state->no_of_entries++;
313 SCFree(output_state->patterns);
314 output_state->patterns = NULL;
317 output_state->patterns = ptmp;
319 output_state->patterns[output_state->no_of_entries - 1] = pindex;
332 static void SCACTileEnter(uint8_t *pattern, uint16_t pattern_len,
339 int32_t newstate = 0;
346 for (i = 0; i < pattern_len; i++) {
347 tc =
ctx->translate_table[pattern[i]];
350 state =
ctx->goto_table[state][tc];
355 for (
p = i;
p < pattern_len;
p++) {
356 newstate = SCACTileInitNewState(mpm_ctx);
357 tc =
ctx->translate_table[pattern[
p]];
358 ctx->goto_table[state][tc] = newstate;
364 SCACTileSetOutputState(state, pindex, mpm_ctx);
373 static void SCACTileCreateGotoTable(
MpmCtx *mpm_ctx)
382 SCACTileEnter(
ctx->parray[i]->ci,
ctx->parray[i]->len,
387 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
389 ctx->goto_table[0][aa] = 0;
403 static void SCACTileClubOutputStates(int32_t dst_state,
417 for (i = 0; i < output_src_state->no_of_entries; i++) {
418 for (j = 0; j < output_dst_state->no_of_entries; j++) {
419 if (output_src_state->patterns[i] == output_dst_state->patterns[j]) {
423 if (j == output_dst_state->no_of_entries) {
424 output_dst_state->no_of_entries++;
426 ptmp =
SCRealloc(output_dst_state->patterns,
427 (output_dst_state->no_of_entries *
sizeof(uint32_t)));
429 SCFree(output_dst_state->patterns);
430 output_dst_state->patterns = NULL;
433 output_dst_state->patterns = ptmp;
435 output_dst_state->patterns[output_dst_state->no_of_entries - 1] =
436 output_src_state->patterns[i];
447 static void SCACTileCreateFailureTable(
MpmCtx *mpm_ctx)
461 if (
ctx->failure_table == NULL) {
468 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
469 int32_t temp_state =
ctx->goto_table[0][aa];
470 if (temp_state != 0) {
471 SCACEnqueue(q, temp_state);
472 ctx->failure_table[temp_state] = 0;
476 while (!SCACStateQueueIsEmpty(q)) {
478 r_state = SCACDequeue(q);
479 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
480 int32_t temp_state =
ctx->goto_table[r_state][aa];
483 SCACEnqueue(q, temp_state);
484 state =
ctx->failure_table[r_state];
487 state =
ctx->failure_table[state];
488 ctx->failure_table[temp_state] =
ctx->goto_table[state][aa];
489 SCACTileClubOutputStates(temp_state,
ctx->failure_table[temp_state],
499 static void SCACTileSetState1Byte(
SCACTileCtx *
ctx,
int state,
int aa,
500 int next_state,
int outputs)
502 uint8_t *state_table = (uint8_t*)
ctx->state_table;
504 uint8_t encoded_next_state = (uint8_t)next_state;
511 encoded_next_state |= (1 << 7);
513 state_table[state *
ctx->alphabet_storage + aa] = encoded_next_state;
519 static void SCACTileSetState2Bytes(
SCACTileCtx *
ctx,
int state,
int aa,
520 int next_state,
int outputs)
522 uint16_t *state_table = (uint16_t*)
ctx->state_table;
524 uint16_t encoded_next_state = (uint16_t)next_state;
531 encoded_next_state |= (1 << 15);
533 state_table[state *
ctx->alphabet_storage + aa] = encoded_next_state;
539 static void SCACTileSetState4Bytes(
SCACTileCtx *
ctx,
int state,
int aa,
540 int next_state,
int outputs)
542 uint32_t *state_table = (uint32_t*)
ctx->state_table;
543 uint32_t encoded_next_state = next_state;
550 encoded_next_state |= (1UL << 31);
552 state_table[state *
ctx->alphabet_storage + aa] = encoded_next_state;
561 static inline void SCACTileCreateDeltaTable(
MpmCtx *mpm_ctx)
569 if (
ctx->state_count < 32767) {
570 if (
ctx->state_count < 128) {
571 ctx->bytes_per_state = 1;
572 ctx->SetNextState = SCACTileSetState1Byte;
574 switch(
ctx->alphabet_storage) {
595 ctx->bytes_per_state = 2;
596 ctx->SetNextState = SCACTileSetState2Bytes;
598 switch(
ctx->alphabet_storage) {
621 ctx->bytes_per_state = 4;
622 ctx->SetNextState = SCACTileSetState4Bytes;
624 ctx->alphabet_storage = 256;
629 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
630 int temp_state =
ctx->goto_table[0][aa];
632 SCACEnqueue(q, temp_state);
635 while (!SCACStateQueueIsEmpty(q)) {
636 r_state = SCACDequeue(q);
638 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
639 int temp_state =
ctx->goto_table[r_state][aa];
641 SCACEnqueue(q, temp_state);
643 int f_state =
ctx->failure_table[r_state];
644 ctx->goto_table[r_state][aa] =
ctx->goto_table[f_state][aa];
651 static void SCACTileClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
660 int size =
ctx->state_count *
ctx->bytes_per_state *
ctx->alphabet_storage;
661 void *state_table =
SCCalloc(1, size);
662 if (
unlikely(state_table == NULL)) {
665 ctx->state_table = state_table;
670 SCLogDebug(
"Delta Table size %d, alphabet: %d, %d-byte states: %d",
671 size,
ctx->alphabet_size,
ctx->bytes_per_state,
ctx->state_count);
677 for (state = 0; state <
ctx->state_count; state++) {
678 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
679 int next_state =
ctx->goto_table[state][aa];
680 int next_state_outputs =
ctx->output_table[next_state].no_of_entries;
681 ctx->SetNextState(
ctx, state, aa, next_state, next_state_outputs);
686 static inline void SCACTileInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
694 for (state = 0; state <
ctx->state_count; state++) {
695 if (
ctx->output_table[state].no_of_entries == 0)
698 for (k = 0; k <
ctx->output_table[state].no_of_entries; k++) {
699 if (
ctx->pattern_list[
ctx->output_table[state].patterns[k]].cs != NULL) {
701 ctx->output_table[state].patterns[k] &= 0x0FFFFFFF;
702 ctx->output_table[state].patterns[k] |= (uint32_t)1 << 31;
709 static void SCACTilePrintDeltaTable(
MpmCtx *mpm_ctx)
716 printf(
"##############Delta Table##############\n");
717 for (i = 0; i <
ctx->state_count; i++) {
719 for (j = 0; j <
ctx->alphabet_size; j++) {
720 if (SCACTileGetDelta(i, j, mpm_ctx) != 0) {
721 printf(
" %c -> %d\n", j, SCACTileGetDelta(i, j, mpm_ctx));
733 static void SCACTilePrepareStateTable(
MpmCtx *mpm_ctx)
739 SCACTileInitTranslateTable(
ctx);
742 SCACTileInitNewState(mpm_ctx);
745 SCACTileCreateGotoTable(mpm_ctx);
747 SCACTileCreateFailureTable(mpm_ctx);
749 SCACTileCreateDeltaTable(mpm_ctx);
751 SCACTileClubOutputStatePresenceWithDeltaTable(mpm_ctx);
754 SCACTileInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
757 SCACTilePrintDeltaTable(mpm_ctx);
762 ctx->goto_table = NULL;
764 ctx->failure_table = NULL;
775 static void SCACTilePrepareSearch(
MpmCtx *mpm_ctx)
781 SCACTileReallocOutputTable(
ctx,
ctx->state_count);
788 ctx->state_table = NULL;
793 ctx->output_table = NULL;
797 ctx->pattern_list = NULL;
804 SCACTileDestroyInitCtx(mpm_ctx);
818 SCLogDebug(
"no patterns supplied to this mpm_ctx");
823 SCLogDebug(
"no patterns supplied to this mpm_ctx");
829 if (
ctx->parray == NULL)
833 uint32_t i = 0,
p = 0;
836 while(node != NULL) {
839 ctx->parray[
p++] = node;
840 SCACTileHistogramAlphabet(
ctx, node);
854 size_t string_space_needed = 0;
858 uint32_t space = ((
ctx->parray[i]->len + 7) / 8) * 8;
859 string_space_needed += space;
864 size_t mem_size = string_space_needed + pattern_list_size;
865 void *mem_block =
SCCalloc(1, mem_size);
866 if (mem_block == NULL) {
872 ctx->pattern_list = mem_block;
873 uint8_t *string_space = mem_block + pattern_list_size;
878 uint16_t
len =
ctx->parray[i]->len;
879 uint32_t space = ((
len + 7) / 8) * 8;
880 memcpy(string_space,
ctx->parray[i]->original_pat,
len);
881 ctx->pattern_list[i].cs = string_space;
882 ctx->pattern_list[i].patlen =
len;
883 string_space += space;
885 ctx->pattern_list[i].offset =
ctx->parray[i]->offset;
886 ctx->pattern_list[i].depth =
ctx->parray[i]->depth;
887 ctx->pattern_list[i].pid =
ctx->parray[i]->id;
890 ctx->pattern_list[i].sids_size =
ctx->parray[i]->sids_size;
891 ctx->pattern_list[i].sids =
ctx->parray[i]->sids;
892 ctx->parray[i]->sids = NULL;
893 ctx->parray[i]->sids_size = 0;
897 SCACTilePrepareStateTable(mpm_ctx);
900 SCACTilePrepareSearch(mpm_ctx);
915 if (mpm_ctx->
ctx != NULL)
920 if (mpm_ctx->
ctx == NULL) {
949 static void SCACTileDestroyInitCtx(
MpmCtx *mpm_ctx)
962 if (
ctx->parray != NULL) {
965 if (
ctx->parray[i] != NULL) {
974 if (
ctx->state_table != NULL) {
979 ctx->bytes_per_state *
ctx->alphabet_storage);
982 if (
ctx->output_table != NULL) {
984 for (state = 0; state <
ctx->state_count; state++) {
985 if (
ctx->output_table[state].patterns != NULL) {
986 SCFree(
ctx->output_table[state].patterns);
992 if (
ctx->pattern_list != NULL) {
995 if (
ctx->pattern_list[i].cs != NULL)
997 if (
ctx->pattern_list[i].sids != NULL)
1017 if (search_ctx == NULL)
1021 SCACTileDestroyInitCtx(mpm_ctx);
1037 for (state = 0; state < search_ctx->
state_count; state++) {
1046 mpm_ctx->
ctx = NULL;
1056 #define SCHECK(x) ((x) > 0)
1057 #define BUF_TYPE int32_t
1059 #define BYTE0(x) (((x) & 0x000000ff) >> 0)
1060 #define BYTE1(x) (((x) & 0x0000ff00) >> 8)
1061 #define BYTE2(x) (((x) & 0x00ff0000) >> 16)
1062 #define BYTE3(x) (((x) & 0xff000000) >> 24)
1063 #define EXTRA 4 // need 4 extra bytes to avoid OOB reads
1066 const uint8_t *buf, uint32_t buflen,
1067 uint16_t state,
int i,
int matches,
1068 uint8_t *mpm_bitarray)
1071 const uint8_t *buf_offset = buf + i + 1;
1072 uint32_t no_of_entries =
ctx->output_table[state].no_of_entries;
1076 for (k = 0; k < no_of_entries; k++) {
1078 if (mpm_bitarray[pindex / 8] & (1 << (pindex % 8))) {
1088 if (patterns[k] >> 31) {
1089 const uint16_t patlen = pat->
patlen;
1090 if (
SCMemcmp(pat->
cs, buf_offset - patlen, patlen) != 0) {
1096 mpm_bitarray[pindex / 8] |= (1 << (pindex % 8));
1101 PrefilterAddSids(pmq, pattern_list[pindex].sids,
1102 pattern_list[pindex].sids_size);
1130 return search_ctx->
Search(search_ctx, mpm_thread_ctx, pmq, buf, buflen);
1136 const uint8_t *buf, uint32_t buflen)
1141 uint8_t *mpm_bitarray = (uint8_t *)mpm_thread_ctx->
ctx;
1142 memset(mpm_bitarray, 0, mpm_thread_ctx->
memory_size);
1144 const uint8_t* restrict xlate =
ctx->translate_table;
1145 register int state = 0;
1146 int32_t (*state_table_u32)[256] =
ctx->state_table;
1147 for (i = 0; i < buflen; i++) {
1148 state = state_table_u32[state & 0x00FFFFFF][xlate[buf[i]]];
1151 matches = CheckMatch(
ctx, pmq, buf, buflen, (uint16_t)state, i, matches, mpm_bitarray);
1163 #define SINDEX_INTERNAL(y, x, log_mult, width) \
1164 ((1<<log_mult) * (x & ((1<<width) - 1)))
1167 #define STYPE int16_t
1168 #define SLOAD(x) *(STYPE * restrict)(x)
1170 #define FUNC_NAME SCACTileSearchSmall256
1172 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 15)
1178 #define FUNC_NAME SCACTileSearchSmall128
1180 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 15)
1186 #define FUNC_NAME SCACTileSearchSmall64
1188 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 15)
1194 #define FUNC_NAME SCACTileSearchSmall32
1196 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 15)
1202 #define FUNC_NAME SCACTileSearchSmall16
1204 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 15)
1210 #define FUNC_NAME SCACTileSearchSmall8
1212 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 15)
1220 #define STYPE int8_t
1224 #define FUNC_NAME SCACTileSearchTiny256
1226 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 7)
1232 #define FUNC_NAME SCACTileSearchTiny128
1234 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 7)
1240 #define FUNC_NAME SCACTileSearchTiny64
1242 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 7)
1248 #define FUNC_NAME SCACTileSearchTiny32
1250 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 7)
1256 #define FUNC_NAME SCACTileSearchTiny16
1258 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 7)
1264 #define FUNC_NAME SCACTileSearchTiny8
1266 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 7)
1313 uint16_t
offset, uint16_t depth, uint32_t pid,
1325 printf(
"MPM AC Information:\n");
1326 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1327 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1328 printf(
" Sizeof:\n");
1329 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1330 printf(
" SCACTileCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACTileCtx));
1331 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1332 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1333 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1334 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1335 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1336 printf(
"Total states in the state table: %u\n",
ctx->state_count);
1350 uint8_t *bitarray =
SCCalloc(size,
sizeof(uint8_t));
1351 if (bitarray == NULL) {
1354 mpm_thread_ctx->
ctx = bitarray;
1364 mpm_thread_ctx->
ctx = NULL;
1401 static int SCACTileTest01(
void)
1408 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1417 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1419 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1422 (uint8_t *)buf, strlen(buf));
1427 printf(
"1 != %" PRIu32
" ",
cnt);
1430 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1435 static int SCACTileTest02(
void)
1442 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1451 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1453 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1455 (uint8_t *)buf, strlen(buf));
1460 printf(
"0 != %" PRIu32
" ",
cnt);
1463 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1468 static int SCACTileTest03(
void)
1475 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1488 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1490 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1492 (uint8_t *)buf, strlen(buf));
1497 printf(
"3 != %" PRIu32
" ",
cnt);
1500 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1505 static int SCACTileTest04(
void)
1512 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1522 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1524 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1526 (uint8_t *)buf, strlen(buf));
1531 printf(
"1 != %" PRIu32
" ",
cnt);
1534 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1539 static int SCACTileTest05(
void)
1546 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1556 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1558 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1560 (uint8_t *)buf, strlen(buf));
1565 printf(
"3 != %" PRIu32
" ",
cnt);
1568 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1573 static int SCACTileTest06(
void)
1580 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1588 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1590 const char *buf =
"abcd";
1592 (uint8_t *)buf, strlen(buf));
1597 printf(
"1 != %" PRIu32
" ",
cnt);
1600 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1605 static int SCACTileTest07(
void)
1611 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1624 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1626 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1632 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1634 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1636 (uint8_t *)buf, strlen(buf));
1640 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1645 static int SCACTileTest08(
void)
1652 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1661 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1669 printf(
"0 != %" PRIu32
" ",
cnt);
1672 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1677 static int SCACTileTest09(
void)
1684 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1693 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1696 (uint8_t *)
"ab", 2);
1701 printf(
"1 != %" PRIu32
" ",
cnt);
1704 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1709 static int SCACTileTest10(
void)
1716 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1725 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1727 const char *buf =
"01234567890123456789012345678901234567890123456789"
1728 "01234567890123456789012345678901234567890123456789"
1730 "01234567890123456789012345678901234567890123456789"
1731 "01234567890123456789012345678901234567890123456789";
1733 (uint8_t *)buf, strlen(buf));
1738 printf(
"1 != %" PRIu32
" ",
cnt);
1741 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1746 static int SCACTileTest11(
void)
1753 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1757 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1759 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1761 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1763 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1769 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1773 const char *buf =
"he";
1788 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1793 static int SCACTileTest12(
void)
1800 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1811 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1813 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1815 (uint8_t *)buf, strlen(buf));
1820 printf(
"2 != %" PRIu32
" ",
cnt);
1823 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
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);
1845 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1847 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1849 (uint8_t *)buf, strlen(buf));
1854 printf(
"1 != %" PRIu32
" ",
cnt);
1857 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1862 static int SCACTileTest14(
void)
1869 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1874 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1875 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1879 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1881 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1883 (uint8_t *)buf, strlen(buf));
1888 printf(
"1 != %" PRIu32
" ",
cnt);
1891 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1896 static int SCACTileTest15(
void)
1903 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1908 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1909 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1913 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1915 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1917 (uint8_t *)buf, strlen(buf));
1922 printf(
"1 != %" PRIu32
" ",
cnt);
1925 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1930 static int SCACTileTest16(
void)
1937 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1942 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1943 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1947 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1949 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1951 (uint8_t *)buf, strlen(buf));
1956 printf(
"1 != %" PRIu32
" ",
cnt);
1959 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1964 static int SCACTileTest17(
void)
1971 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1976 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1977 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1981 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1983 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
1985 (uint8_t *)buf, strlen(buf));
1990 printf(
"1 != %" PRIu32
" ",
cnt);
1993 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1998 static int SCACTileTest18(
void)
2005 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2010 const char pat[] =
"abcde"
2016 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2020 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2022 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2024 (uint8_t *)buf, strlen(buf));
2029 printf(
"1 != %" PRIu32
" ",
cnt);
2032 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2037 static int SCACTileTest19(
void)
2044 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2049 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2050 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2054 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2056 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2058 (uint8_t *)buf, strlen(buf));
2063 printf(
"1 != %" PRIu32
" ",
cnt);
2066 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2071 static int SCACTileTest20(
void)
2078 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2083 const char pat[] =
"AAAAA"
2090 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2094 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2096 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2098 (uint8_t *)buf, strlen(buf));
2103 printf(
"1 != %" PRIu32
" ",
cnt);
2106 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2111 static int SCACTileTest21(
void)
2118 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2127 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2130 (uint8_t *)
"AA", 2);
2135 printf(
"1 != %" PRIu32
" ",
cnt);
2138 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2143 static int SCACTileTest22(
void)
2150 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2161 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2163 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
2165 (uint8_t *)buf, strlen(buf));
2170 printf(
"2 != %" PRIu32
" ",
cnt);
2173 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2178 static int SCACTileTest23(
void)
2185 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2194 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2197 (uint8_t *)
"aa", 2);
2202 printf(
"1 != %" PRIu32
" ",
cnt);
2205 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2210 static int SCACTileTest24(
void)
2217 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2226 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2229 (uint8_t *)
"aa", 2);
2234 printf(
"1 != %" PRIu32
" ",
cnt);
2237 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2242 static int SCACTileTest25(
void)
2249 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2259 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2261 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2263 (uint8_t *)buf, strlen(buf));
2268 printf(
"3 != %" PRIu32
" ",
cnt);
2271 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2276 static int SCACTileTest26(
void)
2283 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2292 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2294 const char *buf =
"works";
2296 (uint8_t *)buf, strlen(buf));
2301 printf(
"3 != %" PRIu32
" ",
cnt);
2304 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2309 static int SCACTileTest27(
void)
2316 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2325 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2327 const char *buf =
"tone";
2329 (uint8_t *)buf, strlen(buf));
2334 printf(
"0 != %" PRIu32
" ",
cnt);
2337 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2342 static int SCACTileTest28(
void)
2349 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2358 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2360 const char *buf =
"tONE";
2362 (uint8_t *)buf, strlen(buf));
2367 printf(
"0 != %" PRIu32
" ",
cnt);
2370 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2375 static int SCACTileTest29(
void)
2377 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2378 uint16_t buflen =
sizeof(buf) - 1;
2395 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2399 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2408 printf(
"if (PacketAlertCheck(p, 1) != 1) failure\n");
2412 printf(
"if (PacketAlertCheck(p, 1) != 2) failure\n");
2427 void SCACTileRegisterTests(
void)