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 const uint8_t *buf, uint32_t buflen,
1086 uint16_t state,
int i,
int matches,
1087 uint8_t *mpm_bitarray)
1090 const uint8_t *buf_offset = buf + i + 1;
1091 uint32_t no_of_entries =
ctx->output_table[state].no_of_entries;
1095 for (k = 0; k < no_of_entries; k++) {
1097 if (mpm_bitarray[pindex / 8] & (1 << (pindex % 8))) {
1107 if (patterns[k] >> 31) {
1108 const uint16_t patlen = pat->
patlen;
1109 if (
SCMemcmp(pat->
cs, buf_offset - patlen, patlen) != 0) {
1115 mpm_bitarray[pindex / 8] |= (1 << (pindex % 8));
1120 PrefilterAddSids(pmq, pattern_list[pindex].sids,
1121 pattern_list[pindex].sids_size);
1149 return search_ctx->
Search(search_ctx, mpm_thread_ctx, pmq, buf, buflen);
1155 const uint8_t *buf, uint32_t buflen)
1160 uint8_t *mpm_bitarray = (uint8_t *)mpm_thread_ctx->
ctx;
1161 memset(mpm_bitarray, 0, mpm_thread_ctx->
memory_size);
1163 const uint8_t* restrict xlate =
ctx->translate_table;
1164 register int state = 0;
1165 int32_t (*state_table_u32)[256] =
ctx->state_table;
1166 for (i = 0; i < buflen; i++) {
1167 state = state_table_u32[state & 0x00FFFFFF][xlate[buf[i]]];
1170 matches = CheckMatch(
ctx, pmq, buf, buflen, (uint16_t)state, i, matches, mpm_bitarray);
1182 #define SINDEX_INTERNAL(y, x, log_mult, width) \
1183 ((1<<log_mult) * (x & ((1<<width) - 1)))
1186 #define STYPE int16_t
1187 #define SLOAD(x) *(STYPE * restrict)(x)
1189 #define FUNC_NAME SCACTileSearchSmall256
1191 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 15)
1197 #define FUNC_NAME SCACTileSearchSmall128
1199 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 15)
1205 #define FUNC_NAME SCACTileSearchSmall64
1207 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 15)
1213 #define FUNC_NAME SCACTileSearchSmall32
1215 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 15)
1221 #define FUNC_NAME SCACTileSearchSmall16
1223 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 15)
1229 #define FUNC_NAME SCACTileSearchSmall8
1231 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 15)
1239 #define STYPE int8_t
1243 #define FUNC_NAME SCACTileSearchTiny256
1245 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 8, 7)
1251 #define FUNC_NAME SCACTileSearchTiny128
1253 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 7, 7)
1259 #define FUNC_NAME SCACTileSearchTiny64
1261 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 6, 7)
1267 #define FUNC_NAME SCACTileSearchTiny32
1269 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 5, 7)
1275 #define FUNC_NAME SCACTileSearchTiny16
1277 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 4, 7)
1283 #define FUNC_NAME SCACTileSearchTiny8
1285 #define SINDEX(y,x) SINDEX_INTERNAL(y, x, 3, 7)
1332 uint16_t
offset, uint16_t depth, uint32_t pid,
1344 printf(
"MPM AC Information:\n");
1345 printf(
"Memory allocs: %" PRIu32
"\n", mpm_ctx->
memory_cnt);
1346 printf(
"Memory alloced: %" PRIu32
"\n", mpm_ctx->
memory_size);
1347 printf(
" Sizeof:\n");
1348 printf(
" MpmCtx %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmCtx));
1349 printf(
" SCACTileCtx: %" PRIuMAX
"\n", (uintmax_t)
sizeof(
SCACTileCtx));
1350 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1351 printf(
" MpmPattern %" PRIuMAX
"\n", (uintmax_t)
sizeof(
MpmPattern));
1352 printf(
"Unique Patterns: %" PRIu32
"\n", mpm_ctx->
pattern_cnt);
1353 printf(
"Smallest: %" PRIu32
"\n", mpm_ctx->
minlen);
1354 printf(
"Largest: %" PRIu32
"\n", mpm_ctx->
maxlen);
1355 printf(
"Total states in the state table: %u\n",
ctx->state_count);
1369 uint8_t *bitarray =
SCCalloc(size,
sizeof(uint8_t));
1370 if (bitarray == NULL) {
1373 mpm_thread_ctx->
ctx = bitarray;
1383 mpm_thread_ctx->
ctx = NULL;
1420 static int SCACTileTest01(
void)
1427 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1436 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1438 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1441 (uint8_t *)buf, strlen(buf));
1446 printf(
"1 != %" PRIu32
" ",
cnt);
1449 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1454 static int SCACTileTest02(
void)
1461 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1470 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1472 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1474 (uint8_t *)buf, strlen(buf));
1479 printf(
"0 != %" PRIu32
" ",
cnt);
1482 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1487 static int SCACTileTest03(
void)
1494 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1507 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1509 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1511 (uint8_t *)buf, strlen(buf));
1516 printf(
"3 != %" PRIu32
" ",
cnt);
1519 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1524 static int SCACTileTest04(
void)
1531 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1541 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1543 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1545 (uint8_t *)buf, strlen(buf));
1550 printf(
"1 != %" PRIu32
" ",
cnt);
1553 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1558 static int SCACTileTest05(
void)
1565 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1575 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1577 const char *buf =
"abcdefghjiklmnopqrstuvwxyz";
1579 (uint8_t *)buf, strlen(buf));
1584 printf(
"3 != %" PRIu32
" ",
cnt);
1587 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1592 static int SCACTileTest06(
void)
1599 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1607 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1609 const char *buf =
"abcd";
1611 (uint8_t *)buf, strlen(buf));
1616 printf(
"1 != %" PRIu32
" ",
cnt);
1619 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1624 static int SCACTileTest07(
void)
1630 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1643 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAA", 10, 0, 0, 4, 0, 0);
1645 MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
1651 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1653 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1655 (uint8_t *)buf, strlen(buf));
1659 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1664 static int SCACTileTest08(
void)
1671 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1680 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1688 printf(
"0 != %" PRIu32
" ",
cnt);
1691 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1696 static int SCACTileTest09(
void)
1703 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1712 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1715 (uint8_t *)
"ab", 2);
1720 printf(
"1 != %" PRIu32
" ",
cnt);
1723 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1728 static int SCACTileTest10(
void)
1735 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1744 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1746 const char *buf =
"01234567890123456789012345678901234567890123456789"
1747 "01234567890123456789012345678901234567890123456789"
1749 "01234567890123456789012345678901234567890123456789"
1750 "01234567890123456789012345678901234567890123456789";
1752 (uint8_t *)buf, strlen(buf));
1757 printf(
"1 != %" PRIu32
" ",
cnt);
1760 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1765 static int SCACTileTest11(
void)
1772 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
1776 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"he", 2, 0, 0, 1, 0, 0) == -1)
1778 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"she", 3, 0, 0, 2, 0, 0) == -1)
1780 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"his", 3, 0, 0, 3, 0, 0) == -1)
1782 if (
MpmAddPatternCS(&mpm_ctx, (uint8_t *)
"hers", 4, 0, 0, 4, 0, 0) == -1)
1788 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1792 const char *buf =
"he";
1807 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1812 static int SCACTileTest12(
void)
1819 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1830 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1832 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
1834 (uint8_t *)buf, strlen(buf));
1839 printf(
"2 != %" PRIu32
" ",
cnt);
1842 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1847 static int SCACTileTest13(
void)
1854 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1859 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCD";
1860 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1864 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1866 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCD";
1868 (uint8_t *)buf, strlen(buf));
1873 printf(
"1 != %" PRIu32
" ",
cnt);
1876 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1881 static int SCACTileTest14(
void)
1888 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1893 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDE";
1894 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1898 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1900 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDE";
1902 (uint8_t *)buf, strlen(buf));
1907 printf(
"1 != %" PRIu32
" ",
cnt);
1910 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1915 static int SCACTileTest15(
void)
1922 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1927 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1928 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1932 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1934 const char *buf =
"abcdefghijklmnopqrstuvwxyzABCDEF";
1936 (uint8_t *)buf, strlen(buf));
1941 printf(
"1 != %" PRIu32
" ",
cnt);
1944 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1949 static int SCACTileTest16(
void)
1956 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1961 const char pat[] =
"abcdefghijklmnopqrstuvwxyzABC";
1962 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
1966 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1968 const char *buf =
"abcdefghijklmnopqrstuvwxyzABC";
1970 (uint8_t *)buf, strlen(buf));
1975 printf(
"1 != %" PRIu32
" ",
cnt);
1978 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
1983 static int SCACTileTest17(
void)
1990 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
1995 const char pat[] =
"abcdefghijklmnopqrstuvwxyzAB";
1996 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2000 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2002 const char *buf =
"abcdefghijklmnopqrstuvwxyzAB";
2004 (uint8_t *)buf, strlen(buf));
2009 printf(
"1 != %" PRIu32
" ",
cnt);
2012 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2017 static int SCACTileTest18(
void)
2024 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2029 const char pat[] =
"abcde"
2035 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2039 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2041 const char *buf =
"abcde""fghij""klmno""pqrst""uvwxy""z";
2043 (uint8_t *)buf, strlen(buf));
2048 printf(
"1 != %" PRIu32
" ",
cnt);
2051 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2056 static int SCACTileTest19(
void)
2063 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2068 const char pat[] =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2069 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2073 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2075 const char *buf =
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
2077 (uint8_t *)buf, strlen(buf));
2082 printf(
"1 != %" PRIu32
" ",
cnt);
2085 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2090 static int SCACTileTest20(
void)
2097 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2102 const char pat[] =
"AAAAA"
2109 MpmAddPatternCS(&mpm_ctx, (uint8_t *)pat,
sizeof(pat) - 1, 0, 0, 0, 0, 0);
2113 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2115 const char *buf =
"AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AAAAA""AA";
2117 (uint8_t *)buf, strlen(buf));
2122 printf(
"1 != %" PRIu32
" ",
cnt);
2125 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2130 static int SCACTileTest21(
void)
2137 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2146 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2149 (uint8_t *)
"AA", 2);
2154 printf(
"1 != %" PRIu32
" ",
cnt);
2157 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2162 static int SCACTileTest22(
void)
2169 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2180 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2182 const char *buf =
"abcdefghijklmnopqrstuvwxyz";
2184 (uint8_t *)buf, strlen(buf));
2189 printf(
"2 != %" PRIu32
" ",
cnt);
2192 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2197 static int SCACTileTest23(
void)
2204 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2213 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2216 (uint8_t *)
"aa", 2);
2221 printf(
"1 != %" PRIu32
" ",
cnt);
2224 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2229 static int SCACTileTest24(
void)
2236 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2245 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2248 (uint8_t *)
"aa", 2);
2253 printf(
"1 != %" PRIu32
" ",
cnt);
2256 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2261 static int SCACTileTest25(
void)
2268 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2278 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2280 const char *buf =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2282 (uint8_t *)buf, strlen(buf));
2287 printf(
"3 != %" PRIu32
" ",
cnt);
2290 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2295 static int SCACTileTest26(
void)
2302 memset(&mpm_ctx, 0x00,
sizeof(
MpmCtx));
2311 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2313 const char *buf =
"works";
2315 (uint8_t *)buf, strlen(buf));
2320 printf(
"3 != %" PRIu32
" ",
cnt);
2323 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2328 static int SCACTileTest27(
void)
2335 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2344 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2346 const char *buf =
"tone";
2348 (uint8_t *)buf, strlen(buf));
2353 printf(
"0 != %" PRIu32
" ",
cnt);
2356 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2361 static int SCACTileTest28(
void)
2368 memset(&mpm_ctx, 0,
sizeof(
MpmCtx));
2377 SCACTileInitThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2379 const char *buf =
"tONE";
2381 (uint8_t *)buf, strlen(buf));
2386 printf(
"0 != %" PRIu32
" ",
cnt);
2389 SCACTileDestroyThreadCtx(&mpm_ctx, &mpm_thread_ctx);
2394 static int SCACTileTest29(
void)
2396 uint8_t buf[] =
"onetwothreefourfivesixseveneightnine";
2397 uint16_t buflen =
sizeof(buf) - 1;
2414 "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
2418 "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
2427 printf(
"if (PacketAlertCheck(p, 1) != 1) failure\n");
2431 printf(
"if (PacketAlertCheck(p, 1) != 2) failure\n");
2446 void SCACTileRegisterTests(
void)