85 #if __BYTE_ORDER == __LITTLE_ENDIAN
90 MpmCtx *,
const uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t,
SigIntId, uint8_t);
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)
156 static void SCACTileGetConfig(
void)
169 for (
int i = 0; i <
p->len; i++) {
170 ctx->alpha_hist[
p->ci[i]]++;
182 for (
int i = 0; i < 256; i++) {
184 if (i >=
'A' && i <=
'Z') {
185 ctx->alpha_hist[i -
'A' +
'a'] +=
ctx->alpha_hist[i];
186 ctx->alpha_hist[i] = 0;
188 if (
ctx->alpha_hist[i]) {
189 ctx->alphabet_size++;
191 ctx->translate_table[i] = (uint8_t)
ctx->alphabet_size;
193 ctx->translate_table[i] = 0;
196 for (
int i =
'A'; i <=
'Z'; i++)
197 ctx->translate_table[i] =
ctx->translate_table[i -
'A' +
'a'];
204 ctx->alphabet_size += 1;
205 if (
ctx->alphabet_size <= 8) {
206 ctx->alphabet_storage = 8;
207 }
else if (
ctx->alphabet_size <= 16) {
208 ctx->alphabet_storage = 16;
209 }
else if (
ctx->alphabet_size <= 32) {
210 ctx->alphabet_storage = 32;
211 }
else if (
ctx->alphabet_size <= 64) {
212 ctx->alphabet_storage = 64;
213 }
else if (
ctx->alphabet_size <= 128) {
214 ctx->alphabet_storage = 128;
216 ctx->alphabet_storage = 256;
219 static void SCACTileReallocOutputTable(
SCACTileCtx *
ctx,
int new_state_count)
227 ctx->output_table = NULL;
230 ctx->output_table = ptmp;
233 static void SCACTileReallocState(
SCACTileCtx *
ctx,
int new_state_count)
236 size_t size =
ctx->allocated_state_count *
sizeof(int32_t) * 256;
240 ctx->goto_table = NULL;
243 ctx->goto_table = ptmp;
245 SCACTileReallocOutputTable(
ctx, new_state_count);
256 static inline int SCACTileInitNewState(
MpmCtx *mpm_ctx)
263 if (
ctx->allocated_state_count <
ctx->state_count + 1) {
264 if (
ctx->allocated_state_count == 0)
265 ctx->allocated_state_count = 256;
267 ctx->allocated_state_count *= 2;
269 SCACTileReallocState(
ctx,
ctx->allocated_state_count);
273 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
277 memset(
ctx->output_table +
ctx->state_count, 0,
280 return ctx->state_count++;
301 for (i = 0; i < output_state->no_of_entries; i++) {
302 if (output_state->patterns[i] == pindex)
308 output_state->no_of_entries++;
312 SCFree(output_state->patterns);
313 output_state->patterns = NULL;
316 output_state->patterns = ptmp;
318 output_state->patterns[output_state->no_of_entries - 1] = pindex;
331 static void SCACTileEnter(uint8_t *pattern, uint16_t pattern_len,
338 int32_t newstate = 0;
345 for (i = 0; i < pattern_len; i++) {
346 tc =
ctx->translate_table[pattern[i]];
349 state =
ctx->goto_table[state][tc];
354 for (
p = i;
p < pattern_len;
p++) {
355 newstate = SCACTileInitNewState(mpm_ctx);
356 tc =
ctx->translate_table[pattern[
p]];
357 ctx->goto_table[state][tc] = newstate;
363 SCACTileSetOutputState(state, pindex, mpm_ctx);
372 static void SCACTileCreateGotoTable(
MpmCtx *mpm_ctx)
381 SCACTileEnter(
ctx->parray[i]->ci,
ctx->parray[i]->len,
386 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
388 ctx->goto_table[0][aa] = 0;
402 static void SCACTileClubOutputStates(int32_t dst_state,
416 for (i = 0; i < output_src_state->no_of_entries; i++) {
417 for (j = 0; j < output_dst_state->no_of_entries; j++) {
418 if (output_src_state->patterns[i] == output_dst_state->patterns[j]) {
422 if (j == output_dst_state->no_of_entries) {
423 output_dst_state->no_of_entries++;
425 ptmp =
SCRealloc(output_dst_state->patterns,
426 (output_dst_state->no_of_entries *
sizeof(uint32_t)));
428 SCFree(output_dst_state->patterns);
429 output_dst_state->patterns = NULL;
432 output_dst_state->patterns = ptmp;
434 output_dst_state->patterns[output_dst_state->no_of_entries - 1] =
435 output_src_state->patterns[i];
446 static void SCACTileCreateFailureTable(
MpmCtx *mpm_ctx)
460 if (
ctx->failure_table == NULL) {
467 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
468 int32_t temp_state =
ctx->goto_table[0][aa];
469 if (temp_state != 0) {
470 SCACEnqueue(q, temp_state);
471 ctx->failure_table[temp_state] = 0;
475 while (!SCACStateQueueIsEmpty(q)) {
477 r_state = SCACDequeue(q);
478 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
479 int32_t temp_state =
ctx->goto_table[r_state][aa];
482 SCACEnqueue(q, temp_state);
483 state =
ctx->failure_table[r_state];
486 state =
ctx->failure_table[state];
487 ctx->failure_table[temp_state] =
ctx->goto_table[state][aa];
488 SCACTileClubOutputStates(temp_state,
ctx->failure_table[temp_state],
498 static void SCACTileSetState1Byte(
SCACTileCtx *
ctx,
int state,
int aa,
499 int next_state,
int outputs)
501 uint8_t *state_table = (uint8_t*)
ctx->state_table;
503 uint8_t encoded_next_state = (uint8_t)next_state;
510 encoded_next_state |= (1 << 7);
512 state_table[state *
ctx->alphabet_storage + aa] = encoded_next_state;
518 static void SCACTileSetState2Bytes(
SCACTileCtx *
ctx,
int state,
int aa,
519 int next_state,
int outputs)
521 uint16_t *state_table = (uint16_t*)
ctx->state_table;
523 uint16_t encoded_next_state = (uint16_t)next_state;
530 encoded_next_state |= (1 << 15);
532 state_table[state *
ctx->alphabet_storage + aa] = encoded_next_state;
538 static void SCACTileSetState4Bytes(
SCACTileCtx *
ctx,
int state,
int aa,
539 int next_state,
int outputs)
541 uint32_t *state_table = (uint32_t*)
ctx->state_table;
542 uint32_t encoded_next_state = next_state;
549 encoded_next_state |= (1UL << 31);
551 state_table[state *
ctx->alphabet_storage + aa] = encoded_next_state;
560 static inline void SCACTileCreateDeltaTable(
MpmCtx *mpm_ctx)
568 if (
ctx->state_count < 32767) {
569 if (
ctx->state_count < 128) {
570 ctx->bytes_per_state = 1;
571 ctx->SetNextState = SCACTileSetState1Byte;
573 switch(
ctx->alphabet_storage) {
594 ctx->bytes_per_state = 2;
595 ctx->SetNextState = SCACTileSetState2Bytes;
597 switch(
ctx->alphabet_storage) {
620 ctx->bytes_per_state = 4;
621 ctx->SetNextState = SCACTileSetState4Bytes;
623 ctx->alphabet_storage = 256;
628 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
629 int temp_state =
ctx->goto_table[0][aa];
631 SCACEnqueue(q, temp_state);
634 while (!SCACStateQueueIsEmpty(q)) {
635 r_state = SCACDequeue(q);
637 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
638 int temp_state =
ctx->goto_table[r_state][aa];
640 SCACEnqueue(q, temp_state);
642 int f_state =
ctx->failure_table[r_state];
643 ctx->goto_table[r_state][aa] =
ctx->goto_table[f_state][aa];
655 static inline size_t SCACTileStateTableSize(
656 uint32_t state_count, uint8_t bytes_per_state, uint16_t alphabet_storage)
658 size_t size = MpmCheckSafeSizetMult((
size_t)state_count, (
size_t)bytes_per_state);
662 return MpmCheckSafeSizetMult(size, (
size_t)alphabet_storage);
665 static void SCACTileClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
675 SCACTileStateTableSize(
ctx->state_count,
ctx->bytes_per_state,
ctx->alphabet_storage);
677 FatalError(
"ac-ks state table size overflow");
679 void *state_table =
SCCalloc(1, size);
680 if (
unlikely(state_table == NULL)) {
683 ctx->state_table = state_table;
688 SCLogDebug(
"Delta Table size %" PRIuMAX
", alphabet: %d, %d-byte states: %d", (uintmax_t)size,
689 ctx->alphabet_size,
ctx->bytes_per_state,
ctx->state_count);
695 for (state = 0; state <
ctx->state_count; state++) {
696 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
697 int next_state =
ctx->goto_table[state][aa];
698 int next_state_outputs =
ctx->output_table[next_state].no_of_entries;
699 ctx->SetNextState(
ctx, state, aa, next_state, next_state_outputs);
704 static inline void SCACTileInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
712 for (state = 0; state <
ctx->state_count; state++) {
713 if (
ctx->output_table[state].no_of_entries == 0)
716 for (k = 0; k <
ctx->output_table[state].no_of_entries; k++) {
717 if (
ctx->pattern_list[
ctx->output_table[state].patterns[k]].cs != NULL) {
719 ctx->output_table[state].patterns[k] &= 0x0FFFFFFF;
720 ctx->output_table[state].patterns[k] |= (uint32_t)1 << 31;
727 static void SCACTilePrintDeltaTable(
MpmCtx *mpm_ctx)
734 printf(
"##############Delta Table##############\n");
735 for (i = 0; i <
ctx->state_count; i++) {
737 for (j = 0; j <
ctx->alphabet_size; j++) {
738 if (SCACTileGetDelta(i, j, mpm_ctx) != 0) {
739 printf(
" %c -> %d\n", j, SCACTileGetDelta(i, j, mpm_ctx));
751 static void SCACTilePrepareStateTable(
MpmCtx *mpm_ctx)
757 SCACTileInitTranslateTable(
ctx);
760 SCACTileInitNewState(mpm_ctx);
763 SCACTileCreateGotoTable(mpm_ctx);
765 SCACTileCreateFailureTable(mpm_ctx);
767 SCACTileCreateDeltaTable(mpm_ctx);
769 SCACTileClubOutputStatePresenceWithDeltaTable(mpm_ctx);
772 SCACTileInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
775 SCACTilePrintDeltaTable(mpm_ctx);
780 ctx->goto_table = NULL;
782 ctx->failure_table = NULL;
793 static void SCACTilePrepareSearch(
MpmCtx *mpm_ctx)
799 SCACTileReallocOutputTable(
ctx,
ctx->state_count);
806 ctx->state_table = NULL;
811 ctx->output_table = NULL;
815 ctx->pattern_list = NULL;
822 SCACTileDestroyInitCtx(mpm_ctx);
836 SCLogDebug(
"no patterns supplied to this mpm_ctx");
841 SCLogDebug(
"no patterns supplied to this mpm_ctx");
847 if (
ctx->parray == NULL)
851 uint32_t i = 0,
p = 0;
854 while(node != NULL) {
857 ctx->parray[
p++] = node;
858 SCACTileHistogramAlphabet(
ctx, node);
872 size_t string_space_needed = 0;
876 uint32_t space = ((
ctx->parray[i]->len + 7) / 8) * 8;
877 string_space_needed += space;
882 size_t mem_size = string_space_needed + pattern_list_size;
883 void *mem_block =
SCCalloc(1, mem_size);
884 if (mem_block == NULL) {
890 ctx->pattern_list = mem_block;
891 uint8_t *string_space = mem_block + pattern_list_size;
896 uint16_t
len =
ctx->parray[i]->len;
897 uint32_t space = ((
len + 7) / 8) * 8;
898 memcpy(string_space,
ctx->parray[i]->original_pat,
len);
899 ctx->pattern_list[i].cs = string_space;
900 ctx->pattern_list[i].patlen =
len;
901 string_space += space;
903 ctx->pattern_list[i].offset =
ctx->parray[i]->offset;
904 ctx->pattern_list[i].depth =
ctx->parray[i]->depth;
905 ctx->pattern_list[i].pid =
ctx->parray[i]->id;
908 ctx->pattern_list[i].sids_size =
ctx->parray[i]->sids_size;
909 ctx->pattern_list[i].sids =
ctx->parray[i]->sids;
910 ctx->parray[i]->sids = NULL;
911 ctx->parray[i]->sids_size = 0;
915 SCACTilePrepareStateTable(mpm_ctx);
918 SCACTilePrepareSearch(mpm_ctx);
933 if (mpm_ctx->
ctx != NULL)
938 if (mpm_ctx->
ctx == NULL) {
967 static void SCACTileDestroyInitCtx(
MpmCtx *mpm_ctx)
980 if (
ctx->parray != NULL) {
983 if (
ctx->parray[i] != NULL) {
992 if (
ctx->state_table != NULL) {
997 ctx->state_count,
ctx->bytes_per_state,
ctx->alphabet_storage);
1000 if (
ctx->output_table != NULL) {
1002 for (state = 0; state <
ctx->state_count; state++) {
1003 if (
ctx->output_table[state].patterns != NULL) {
1004 SCFree(
ctx->output_table[state].patterns);
1010 if (
ctx->pattern_list != NULL) {
1013 if (
ctx->pattern_list[i].cs != NULL)
1015 if (
ctx->pattern_list[i].sids != NULL)
1035 if (search_ctx == NULL)
1039 SCACTileDestroyInitCtx(mpm_ctx);
1055 for (state = 0; state < search_ctx->
state_count; state++) {
1064 mpm_ctx->
ctx = NULL;
1074 #define SCHECK(x) ((x) > 0)
1075 #define BUF_TYPE int32_t
1077 #define BYTE0(x) (((x) & 0x000000ff) >> 0)
1078 #define BYTE1(x) (((x) & 0x0000ff00) >> 8)
1079 #define BYTE2(x) (((x) & 0x00ff0000) >> 16)
1080 #define BYTE3(x) (((x) & 0xff000000) >> 24)
1081 #define EXTRA 4 // need 4 extra bytes to avoid OOB reads
1084 uint32_t buflen, uint32_t state,
int i,
int matches, uint8_t *mpm_bitarray)
1087 const uint8_t *buf_offset = buf + i + 1;
1088 uint32_t no_of_entries =
ctx->output_table[state].no_of_entries;
1092 for (k = 0; k < no_of_entries; k++) {
1094 if (mpm_bitarray[pindex / 8] & (1 << (pindex % 8))) {
1104 if (patterns[k] >> 31) {
1105 const uint16_t patlen = pat->
patlen;
1106 if (
SCMemcmp(pat->
cs, buf_offset - patlen, patlen) != 0) {
1112 mpm_bitarray[pindex / 8] |= (1 << (pindex % 8));
1117 PrefilterAddSids(pmq, pattern_list[pindex].sids,
1118 pattern_list[pindex].sids_size);
1146 return search_ctx->
Search(search_ctx, mpm_thread_ctx, pmq, buf, buflen);
1152 const uint8_t *buf, uint32_t buflen)
1157 uint8_t *mpm_bitarray = (uint8_t *)mpm_thread_ctx->
ctx;
1158 memset(mpm_bitarray, 0, mpm_thread_ctx->
memory_size);
1160 const uint8_t* restrict xlate =
ctx->translate_table;
1161 register int state = 0;
1162 int32_t (*state_table_u32)[256] =
ctx->state_table;
1163 for (i = 0; i < buflen; i++) {
1164 state = state_table_u32[state & 0x00FFFFFF][xlate[buf[i]]];
1166 matches = CheckMatch(
ctx, pmq, buf, buflen, (uint32_t)(state & 0x00FFFFFF), i, matches,
1179 #define SINDEX_INTERNAL(y, x, log_mult, width) \
1180 ((1<<log_mult) * (x & ((1<<width) - 1)))
1183 #define STYPE int16_t
1184 #define SLOAD(x) *(STYPE * restrict)(x)
1186 #define FUNC_NAME SCACTileSearchSmall256
1188 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 15)
1194 #define FUNC_NAME SCACTileSearchSmall128
1196 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 15)
1202 #define FUNC_NAME SCACTileSearchSmall64
1204 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 15)
1210 #define FUNC_NAME SCACTileSearchSmall32
1212 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 15)
1218 #define FUNC_NAME SCACTileSearchSmall16
1220 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 15)
1226 #define FUNC_NAME SCACTileSearchSmall8
1228 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 15)
1236 #define STYPE int8_t
1240 #define FUNC_NAME SCACTileSearchTiny256
1242 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 7)
1248 #define FUNC_NAME SCACTileSearchTiny128
1250 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 7)
1256 #define FUNC_NAME SCACTileSearchTiny64
1258 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 7)
1264 #define FUNC_NAME SCACTileSearchTiny32
1266 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 7)
1272 #define FUNC_NAME SCACTileSearchTiny16
1274 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 7)
1280 #define FUNC_NAME SCACTileSearchTiny8
1282 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 7)
1329 uint16_t
offset, uint16_t depth, uint32_t pid,
1341 printf(
"MPM AC Information:\n");
1342 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1343 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1344 printf(
" Sizeof:\n");
1345 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1346 printf(
" SCACTileCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACTileCtx));
1347 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1348 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1349 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1350 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1351 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1352 printf(
"Total states in the state table: %u\n",
ctx->state_count);
1366 uint8_t *bitarray =
SCCalloc(size,
sizeof(uint8_t));
1367 if (bitarray == NULL) {
1370 mpm_thread_ctx->
ctx = bitarray;
1380 mpm_thread_ctx->
ctx = NULL;
1417 static int SCACTileTest01(
void)
1424 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1433 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1435 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1438 (uint8_t *)buf, strlen(buf));
1443 printf(
"1 != %" PRIu32
" ",
cnt);
1446 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1451 static int SCACTileTest02(
void)
1458 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1467 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1469 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1471 (uint8_t *)buf, strlen(buf));
1476 printf(
"0 != %" PRIu32
" ",
cnt);
1479 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1484 static int SCACTileTest03(
void)
1491 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1504 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1506 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1508 (uint8_t *)buf, strlen(buf));
1513 printf(
"3 != %" PRIu32
" ",
cnt);
1516 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1521 static int SCACTileTest04(
void)
1528 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1538 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1540 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1542 (uint8_t *)buf, strlen(buf));
1547 printf(
"1 != %" PRIu32
" ",
cnt);
1550 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1555 static int SCACTileTest05(
void)
1562 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1572 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1574 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1576 (uint8_t *)buf, strlen(buf));
1581 printf(
"3 != %" PRIu32
" ",
cnt);
1584 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1589 static int SCACTileTest06(
void)
1596 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1604 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1606 const char *buf =
"abcd";
1608 (uint8_t *)buf, strlen(buf));
1613 printf(
"1 != %" PRIu32
" ",
cnt);
1616 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1621 static int SCACTileTest07(
void)
1627 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1640 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1642 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1648 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1650 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1652 (uint8_t *)buf, strlen(buf));
1656 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1661 static int SCACTileTest08(
void)
1668 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1677 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1685 printf(
"0 != %" PRIu32
" ",
cnt);
1688 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1693 static int SCACTileTest09(
void)
1700 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1709 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1712 (uint8_t *)
"ab", 2);
1717 printf(
"1 != %" PRIu32
" ",
cnt);
1720 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1725 static int SCACTileTest10(
void)
1732 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1741 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1743 const char *buf =
"01234567890123456789012345678901234567890123456789"
1744 "01234567890123456789012345678901234567890123456789"
1746 "01234567890123456789012345678901234567890123456789"
1747 "01234567890123456789012345678901234567890123456789";
1749 (uint8_t *)buf, strlen(buf));
1754 printf(
"1 != %" PRIu32
" ",
cnt);
1757 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1762 static int SCACTileTest11(
void)
1769 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1773 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1775 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1777 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1779 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1785 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1789 const char *buf =
"he";
1804 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1809 static int SCACTileTest12(
void)
1816 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1827 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1829 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1831 (uint8_t *)buf, strlen(buf));
1836 printf(
"2 != %" PRIu32
" ",
cnt);
1839 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1844 static int SCACTileTest13(
void)
1851 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1856 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1857 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1861 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1863 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1865 (uint8_t *)buf, strlen(buf));
1870 printf(
"1 != %" PRIu32
" ",
cnt);
1873 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1878 static int SCACTileTest14(
void)
1885 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1890 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1891 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1895 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1897 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1899 (uint8_t *)buf, strlen(buf));
1904 printf(
"1 != %" PRIu32
" ",
cnt);
1907 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1912 static int SCACTileTest15(
void)
1919 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1924 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1925 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1929 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1931 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1933 (uint8_t *)buf, strlen(buf));
1938 printf(
"1 != %" PRIu32
" ",
cnt);
1941 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1946 static int SCACTileTest16(
void)
1953 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1958 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1959 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1963 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1965 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1967 (uint8_t *)buf, strlen(buf));
1972 printf(
"1 != %" PRIu32
" ",
cnt);
1975 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1980 static int SCACTileTest17(
void)
1987 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1992 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1993 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1997 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1999 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
2001 (uint8_t *)buf, strlen(buf));
2006 printf(
"1 != %" PRIu32
" ",
cnt);
2009 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2014 static int SCACTileTest18(
void)
2021 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2026 const char pat[] =
"abcde"
2032 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2036 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2038 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2040 (uint8_t *)buf, strlen(buf));
2045 printf(
"1 != %" PRIu32
" ",
cnt);
2048 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2053 static int SCACTileTest19(
void)
2060 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2065 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2066 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2070 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2072 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2074 (uint8_t *)buf, strlen(buf));
2079 printf(
"1 != %" PRIu32
" ",
cnt);
2082 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2087 static int SCACTileTest20(
void)
2094 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2099 const char pat[] =
"AAAAA"
2106 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2110 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2112 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2114 (uint8_t *)buf, strlen(buf));
2119 printf(
"1 != %" PRIu32
" ",
cnt);
2122 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2127 static int SCACTileTest21(
void)
2134 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2143 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2146 (uint8_t *)
"AA", 2);
2151 printf(
"1 != %" PRIu32
" ",
cnt);
2154 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2159 static int SCACTileTest22(
void)
2166 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2177 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2179 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
2181 (uint8_t *)buf, strlen(buf));
2186 printf(
"2 != %" PRIu32
" ",
cnt);
2189 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2194 static int SCACTileTest23(
void)
2201 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2210 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2213 (uint8_t *)
"aa", 2);
2218 printf(
"1 != %" PRIu32
" ",
cnt);
2221 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2226 static int SCACTileTest24(
void)
2233 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2242 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2245 (uint8_t *)
"aa", 2);
2250 printf(
"1 != %" PRIu32
" ",
cnt);
2253 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2258 static int SCACTileTest25(
void)
2265 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2275 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2277 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2279 (uint8_t *)buf, strlen(buf));
2284 printf(
"3 != %" PRIu32
" ",
cnt);
2287 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2292 static int SCACTileTest26(
void)
2299 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2308 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2310 const char *buf =
"works";
2312 (uint8_t *)buf, strlen(buf));
2317 printf(
"3 != %" PRIu32
" ",
cnt);
2320 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2325 static int SCACTileTest27(
void)
2332 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2341 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2343 const char *buf =
"tone";
2345 (uint8_t *)buf, strlen(buf));
2350 printf(
"0 != %" PRIu32
" ",
cnt);
2353 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2358 static int SCACTileTest28(
void)
2365 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2374 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2376 const char *buf =
"tONE";
2378 (uint8_t *)buf, strlen(buf));
2383 printf(
"0 != %" PRIu32
" ",
cnt);
2386 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2391 static int SCACTileTest29(
void)
2393 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2394 uint16_t buflen =
sizeof(buf) - 1;
2411 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2415 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2424 printf(
"if (PacketAlertCheck(p, 1) != 1) failure\n");
2428 printf(
"if (PacketAlertCheck(p, 1) != 2) failure\n");
2443 void SCACTileRegisterTests(
void)