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];
656 static inline size_t SCACTileStateTableSize(
657 uint32_t state_count, uint8_t bytes_per_state, uint16_t alphabet_storage)
659 size_t size = MpmCheckSafeSizetMult((
size_t)state_count, (
size_t)bytes_per_state);
663 return MpmCheckSafeSizetMult(size, (
size_t)alphabet_storage);
666 static void SCACTileClubOutputStatePresenceWithDeltaTable(
MpmCtx *mpm_ctx)
676 SCACTileStateTableSize(
ctx->state_count,
ctx->bytes_per_state,
ctx->alphabet_storage);
678 FatalError(
"ac-ks state table size overflow");
680 void *state_table =
SCCalloc(1, size);
681 if (
unlikely(state_table == NULL)) {
684 ctx->state_table = state_table;
689 SCLogDebug(
"Delta Table size %" PRIuMAX
", alphabet: %d, %d-byte states: %d", (uintmax_t)size,
690 ctx->alphabet_size,
ctx->bytes_per_state,
ctx->state_count);
696 for (state = 0; state <
ctx->state_count; state++) {
697 for (aa = 0; aa <
ctx->alphabet_size; aa++) {
698 int next_state =
ctx->goto_table[state][aa];
699 int next_state_outputs =
ctx->output_table[next_state].no_of_entries;
700 ctx->SetNextState(
ctx, state, aa, next_state, next_state_outputs);
705 static inline void SCACTileInsertCaseSensitiveEntriesForPatterns(
MpmCtx *mpm_ctx)
713 for (state = 0; state <
ctx->state_count; state++) {
714 if (
ctx->output_table[state].no_of_entries == 0)
717 for (k = 0; k <
ctx->output_table[state].no_of_entries; k++) {
718 if (
ctx->pattern_list[
ctx->output_table[state].patterns[k]].cs != NULL) {
720 ctx->output_table[state].patterns[k] &= 0x0FFFFFFF;
721 ctx->output_table[state].patterns[k] |= (uint32_t)1 << 31;
728 static void SCACTilePrintDeltaTable(
MpmCtx *mpm_ctx)
735 printf(
"##############Delta Table##############\n");
736 for (i = 0; i <
ctx->state_count; i++) {
738 for (j = 0; j <
ctx->alphabet_size; j++) {
739 if (SCACTileGetDelta(i, j, mpm_ctx) != 0) {
740 printf(
" %c -> %d\n", j, SCACTileGetDelta(i, j, mpm_ctx));
752 static void SCACTilePrepareStateTable(
MpmCtx *mpm_ctx)
758 SCACTileInitTranslateTable(
ctx);
761 SCACTileInitNewState(mpm_ctx);
764 SCACTileCreateGotoTable(mpm_ctx);
766 SCACTileCreateFailureTable(mpm_ctx);
768 SCACTileCreateDeltaTable(mpm_ctx);
770 SCACTileClubOutputStatePresenceWithDeltaTable(mpm_ctx);
773 SCACTileInsertCaseSensitiveEntriesForPatterns(mpm_ctx);
776 SCACTilePrintDeltaTable(mpm_ctx);
781 ctx->goto_table = NULL;
783 ctx->failure_table = NULL;
794 static void SCACTilePrepareSearch(
MpmCtx *mpm_ctx)
800 SCACTileReallocOutputTable(
ctx,
ctx->state_count);
807 ctx->state_table = NULL;
812 ctx->output_table = NULL;
816 ctx->pattern_list = NULL;
823 SCACTileDestroyInitCtx(mpm_ctx);
837 SCLogDebug(
"no patterns supplied to this mpm_ctx");
842 SCLogDebug(
"no patterns supplied to this mpm_ctx");
848 if (
ctx->parray == NULL)
852 uint32_t i = 0,
p = 0;
855 while(node != NULL) {
858 ctx->parray[
p++] = node;
859 SCACTileHistogramAlphabet(
ctx, node);
873 size_t string_space_needed = 0;
877 uint32_t space = ((
ctx->parray[i]->len + 7) / 8) * 8;
878 string_space_needed += space;
883 size_t mem_size = string_space_needed + pattern_list_size;
884 void *mem_block =
SCCalloc(1, mem_size);
885 if (mem_block == NULL) {
891 ctx->pattern_list = mem_block;
892 uint8_t *string_space = mem_block + pattern_list_size;
897 uint16_t
len =
ctx->parray[i]->len;
898 uint32_t space = ((
len + 7) / 8) * 8;
899 memcpy(string_space,
ctx->parray[i]->original_pat,
len);
900 ctx->pattern_list[i].cs = string_space;
901 ctx->pattern_list[i].patlen =
len;
902 string_space += space;
904 ctx->pattern_list[i].offset =
ctx->parray[i]->offset;
905 ctx->pattern_list[i].depth =
ctx->parray[i]->depth;
906 ctx->pattern_list[i].pid =
ctx->parray[i]->id;
909 ctx->pattern_list[i].sids_size =
ctx->parray[i]->sids_size;
910 ctx->pattern_list[i].sids =
ctx->parray[i]->sids;
911 ctx->parray[i]->sids = NULL;
912 ctx->parray[i]->sids_size = 0;
916 SCACTilePrepareStateTable(mpm_ctx);
919 SCACTilePrepareSearch(mpm_ctx);
934 if (mpm_ctx->
ctx != NULL)
939 if (mpm_ctx->
ctx == NULL) {
968 static void SCACTileDestroyInitCtx(
MpmCtx *mpm_ctx)
981 if (
ctx->parray != NULL) {
984 if (
ctx->parray[i] != NULL) {
993 if (
ctx->state_table != NULL) {
998 ctx->state_count,
ctx->bytes_per_state,
ctx->alphabet_storage);
1001 if (
ctx->output_table != NULL) {
1003 for (state = 0; state <
ctx->state_count; state++) {
1004 if (
ctx->output_table[state].patterns != NULL) {
1005 SCFree(
ctx->output_table[state].patterns);
1011 if (
ctx->pattern_list != NULL) {
1014 if (
ctx->pattern_list[i].cs != NULL)
1016 if (
ctx->pattern_list[i].sids != NULL)
1036 if (search_ctx == NULL)
1040 SCACTileDestroyInitCtx(mpm_ctx);
1056 for (state = 0; state < search_ctx->
state_count; state++) {
1065 mpm_ctx->
ctx = NULL;
1075 #define SCHECK(x) ((x) > 0)
1076 #define BUF_TYPE int32_t
1078 #define BYTE0(x) (((x) & 0x000000ff) >> 0)
1079 #define BYTE1(x) (((x) & 0x0000ff00) >> 8)
1080 #define BYTE2(x) (((x) & 0x00ff0000) >> 16)
1081 #define BYTE3(x) (((x) & 0xff000000) >> 24)
1082 #define EXTRA 4 // need 4 extra bytes to avoid OOB reads
1085 uint32_t buflen, uint32_t state,
int i,
int matches, uint8_t *mpm_bitarray)
1088 const uint8_t *buf_offset = buf + i + 1;
1089 uint32_t no_of_entries =
ctx->output_table[state].no_of_entries;
1093 for (k = 0; k < no_of_entries; k++) {
1095 if (mpm_bitarray[pindex / 8] & (1 << (pindex % 8))) {
1105 if (patterns[k] >> 31) {
1106 const uint16_t patlen = pat->
patlen;
1107 if (
SCMemcmp(pat->
cs, buf_offset - patlen, patlen) != 0) {
1113 mpm_bitarray[pindex / 8] |= (1 << (pindex % 8));
1118 PrefilterAddSids(pmq, pattern_list[pindex].sids,
1119 pattern_list[pindex].sids_size);
1147 return search_ctx->
Search(search_ctx, mpm_thread_ctx, pmq, buf, buflen);
1153 const uint8_t *buf, uint32_t buflen)
1158 uint8_t *mpm_bitarray = (uint8_t *)mpm_thread_ctx->
ctx;
1159 memset(mpm_bitarray, 0, mpm_thread_ctx->
memory_size);
1161 const uint8_t* restrict xlate =
ctx->translate_table;
1162 register int state = 0;
1163 int32_t (*state_table_u32)[256] =
ctx->state_table;
1164 for (i = 0; i < buflen; i++) {
1165 state = state_table_u32[state & 0x00FFFFFF][xlate[buf[i]]];
1167 matches = CheckMatch(
ctx, pmq, buf, buflen, (uint32_t)(state & 0x00FFFFFF), i, matches,
1180 #define SINDEX_INTERNAL(y, x, log_mult, width) \
1181 ((1<<log_mult) * (x & ((1<<width) - 1)))
1184 #define STYPE int16_t
1185 #define SLOAD(x) *(STYPE * restrict)(x)
1187 #define FUNC_NAME SCACTileSearchSmall256
1189 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 15)
1195 #define FUNC_NAME SCACTileSearchSmall128
1197 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 15)
1203 #define FUNC_NAME SCACTileSearchSmall64
1205 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 15)
1211 #define FUNC_NAME SCACTileSearchSmall32
1213 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 15)
1219 #define FUNC_NAME SCACTileSearchSmall16
1221 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 15)
1227 #define FUNC_NAME SCACTileSearchSmall8
1229 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 15)
1237 #define STYPE int8_t
1241 #define FUNC_NAME SCACTileSearchTiny256
1243 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 7)
1249 #define FUNC_NAME SCACTileSearchTiny128
1251 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 7)
1257 #define FUNC_NAME SCACTileSearchTiny64
1259 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 7)
1265 #define FUNC_NAME SCACTileSearchTiny32
1267 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 7)
1273 #define FUNC_NAME SCACTileSearchTiny16
1275 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 7)
1281 #define FUNC_NAME SCACTileSearchTiny8
1283 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 7)
1330 uint16_t
offset, uint16_t depth, uint32_t pid,
1342 printf(
"MPM AC Information:\n");
1343 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1344 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1345 printf(
" Sizeof:\n");
1346 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1347 printf(
" SCACTileCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACTileCtx));
1348 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1349 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1350 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1351 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1352 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1353 printf(
"Total states in the state table: %u\n",
ctx->state_count);
1367 uint8_t *bitarray =
SCCalloc(size,
sizeof(uint8_t));
1368 if (bitarray == NULL) {
1371 mpm_thread_ctx->
ctx = bitarray;
1381 mpm_thread_ctx->
ctx = NULL;
1418 static int SCACTileTest01(
void)
1425 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1434 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1436 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1439 (uint8_t *)buf, strlen(buf));
1444 printf(
"1 != %" PRIu32
" ",
cnt);
1447 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1452 static int SCACTileTest02(
void)
1459 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1468 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1470 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1472 (uint8_t *)buf, strlen(buf));
1477 printf(
"0 != %" PRIu32
" ",
cnt);
1480 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1485 static int SCACTileTest03(
void)
1492 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1505 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1507 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1509 (uint8_t *)buf, strlen(buf));
1514 printf(
"3 != %" PRIu32
" ",
cnt);
1517 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1522 static int SCACTileTest04(
void)
1529 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1539 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1541 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1543 (uint8_t *)buf, strlen(buf));
1548 printf(
"1 != %" PRIu32
" ",
cnt);
1551 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1556 static int SCACTileTest05(
void)
1563 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1573 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1575 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1577 (uint8_t *)buf, strlen(buf));
1582 printf(
"3 != %" PRIu32
" ",
cnt);
1585 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1590 static int SCACTileTest06(
void)
1597 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1605 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1607 const char *buf =
"abcd";
1609 (uint8_t *)buf, strlen(buf));
1614 printf(
"1 != %" PRIu32
" ",
cnt);
1617 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1622 static int SCACTileTest07(
void)
1628 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1641 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1643 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1649 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1651 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1653 (uint8_t *)buf, strlen(buf));
1657 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1662 static int SCACTileTest08(
void)
1669 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1678 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1686 printf(
"0 != %" PRIu32
" ",
cnt);
1689 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1694 static int SCACTileTest09(
void)
1701 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1710 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1713 (uint8_t *)
"ab", 2);
1718 printf(
"1 != %" PRIu32
" ",
cnt);
1721 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1726 static int SCACTileTest10(
void)
1733 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1742 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1744 const char *buf =
"01234567890123456789012345678901234567890123456789"
1745 "01234567890123456789012345678901234567890123456789"
1747 "01234567890123456789012345678901234567890123456789"
1748 "01234567890123456789012345678901234567890123456789";
1750 (uint8_t *)buf, strlen(buf));
1755 printf(
"1 != %" PRIu32
" ",
cnt);
1758 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1763 static int SCACTileTest11(
void)
1770 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1774 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1776 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1778 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1780 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1786 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1790 const char *buf =
"he";
1805 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1810 static int SCACTileTest12(
void)
1817 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1828 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1830 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1832 (uint8_t *)buf, strlen(buf));
1837 printf(
"2 != %" PRIu32
" ",
cnt);
1840 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1845 static int SCACTileTest13(
void)
1852 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1857 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1858 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1862 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1864 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1866 (uint8_t *)buf, strlen(buf));
1871 printf(
"1 != %" PRIu32
" ",
cnt);
1874 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1879 static int SCACTileTest14(
void)
1886 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1891 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1892 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1896 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1898 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1900 (uint8_t *)buf, strlen(buf));
1905 printf(
"1 != %" PRIu32
" ",
cnt);
1908 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1913 static int SCACTileTest15(
void)
1920 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1925 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1926 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1930 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1932 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1934 (uint8_t *)buf, strlen(buf));
1939 printf(
"1 != %" PRIu32
" ",
cnt);
1942 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1947 static int SCACTileTest16(
void)
1954 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1959 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1960 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1964 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1966 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1968 (uint8_t *)buf, strlen(buf));
1973 printf(
"1 != %" PRIu32
" ",
cnt);
1976 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1981 static int SCACTileTest17(
void)
1988 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1993 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1994 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1998 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2000 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
2002 (uint8_t *)buf, strlen(buf));
2007 printf(
"1 != %" PRIu32
" ",
cnt);
2010 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2015 static int SCACTileTest18(
void)
2022 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2027 const char pat[] =
"abcde"
2033 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2037 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2039 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2041 (uint8_t *)buf, strlen(buf));
2046 printf(
"1 != %" PRIu32
" ",
cnt);
2049 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2054 static int SCACTileTest19(
void)
2061 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2066 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2067 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2071 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2073 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2075 (uint8_t *)buf, strlen(buf));
2080 printf(
"1 != %" PRIu32
" ",
cnt);
2083 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2088 static int SCACTileTest20(
void)
2095 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2100 const char pat[] =
"AAAAA"
2107 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2111 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2113 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2115 (uint8_t *)buf, strlen(buf));
2120 printf(
"1 != %" PRIu32
" ",
cnt);
2123 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2128 static int SCACTileTest21(
void)
2135 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2144 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2147 (uint8_t *)
"AA", 2);
2152 printf(
"1 != %" PRIu32
" ",
cnt);
2155 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2160 static int SCACTileTest22(
void)
2167 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2178 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2180 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
2182 (uint8_t *)buf, strlen(buf));
2187 printf(
"2 != %" PRIu32
" ",
cnt);
2190 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2195 static int SCACTileTest23(
void)
2202 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2211 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2214 (uint8_t *)
"aa", 2);
2219 printf(
"1 != %" PRIu32
" ",
cnt);
2222 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2227 static int SCACTileTest24(
void)
2234 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2243 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2246 (uint8_t *)
"aa", 2);
2251 printf(
"1 != %" PRIu32
" ",
cnt);
2254 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2259 static int SCACTileTest25(
void)
2266 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2276 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2278 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2280 (uint8_t *)buf, strlen(buf));
2285 printf(
"3 != %" PRIu32
" ",
cnt);
2288 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2293 static int SCACTileTest26(
void)
2300 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2309 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2311 const char *buf =
"works";
2313 (uint8_t *)buf, strlen(buf));
2318 printf(
"3 != %" PRIu32
" ",
cnt);
2321 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2326 static int SCACTileTest27(
void)
2333 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2342 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2344 const char *buf =
"tone";
2346 (uint8_t *)buf, strlen(buf));
2351 printf(
"0 != %" PRIu32
" ",
cnt);
2354 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2359 static int SCACTileTest28(
void)
2366 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2375 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2377 const char *buf =
"tONE";
2379 (uint8_t *)buf, strlen(buf));
2384 printf(
"0 != %" PRIu32
" ",
cnt);
2387 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2392 static int SCACTileTest29(
void)
2394 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2395 uint16_t buflen =
sizeof(buf) - 1;
2412 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2416 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2425 printf(
"if (PacketAlertCheck(p, 1) != 1) failure\n");
2429 printf(
"if (PacketAlertCheck(p, 1) != 2) failure\n");
2444 void SCACTileRegisterTests(
void)