Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new MPM: ac-tile #9

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ util-misc.c util-misc.h \
util-mpm-ac-bs.c util-mpm-ac-bs.h \
util-mpm-ac.c util-mpm-ac.h \
util-mpm-ac-gfbs.c util-mpm-ac-gfbs.h \
util-mpm-ac-tile.c util-mpm-ac-tile.h \
util-mpm-b2gc.c util-mpm-b2gc.h \
util-mpm-b2g.c util-mpm-b2g.h \
util-mpm-b2gm.c util-mpm-b2gm.h \
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-smtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ SCEnumCharMap smtp_decoder_event_table[ ] = {
{ NULL, -1 },
};

#define SMTP_MPM MPM_AC
#define SMTP_MPM DEFAULT_MPM

static MpmCtx *smtp_mpm_ctx = NULL;
MpmThreadCtx *smtp_mpm_thread_ctx;
Expand Down
2 changes: 1 addition & 1 deletion src/detect-csum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ int DetectCsumICMPV6Test01(void)
printf("DetectEngineCtxInit failure\n");
goto end;
}
de_ctx->mpm_matcher = MPM_AC;
de_ctx->mpm_matcher = DEFAULT_MPM;
de_ctx->flags |= DE_QUIET;

s = de_ctx->sig_list = SigInit(de_ctx, "alert ip any any -> any any "
Expand Down
16 changes: 11 additions & 5 deletions src/detect-engine-mpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
#endif

/** \todo make it possible to use multiple pattern matcher algorithms next to
eachother. */
#define PM MPM_AC
each other. */

#define POPULATE_MPM_AVOID_PACKET_MPM_PATTERNS 0x01
#define POPULATE_MPM_AVOID_STREAM_MPM_PATTERNS 0x02
Expand Down Expand Up @@ -134,13 +133,13 @@ int SignatureHasStreamContent(Signature *s) {
/**
* \brief Function to return the multi pattern matcher algorithm to be
* used by the engine, based on the mpm-algo setting in yaml
* Use the default mpm non is found in yaml.
* Use the default mpm if none is specified in the yaml file.
*
* \retval mpm algo value
*/
uint16_t PatternMatchDefaultMatcher(void) {
char *mpm_algo;
uint16_t mpm_algo_val = PM;
uint16_t mpm_algo_val = DEFAULT_MPM;

/* Get the mpm algo defined in config file by the user */
if ((ConfGet("mpm-algo", &mpm_algo)) == 1) {
Expand All @@ -152,7 +151,8 @@ uint16_t PatternMatchDefaultMatcher(void) {
continue;

if (strcmp(mpm_table[u].name, mpm_algo) == 0) {
return u;
mpm_algo_val = u;
goto done;
}
}
}
Expand All @@ -162,6 +162,12 @@ uint16_t PatternMatchDefaultMatcher(void) {
exit(EXIT_FAILURE);
}

done:
#ifdef __tile__
if (mpm_algo_val == MPM_AC)
mpm_algo_val = MPM_AC_TILE;
#endif

return mpm_algo_val;
}

Expand Down
24 changes: 12 additions & 12 deletions src/detect-engine-payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ static int PayloadTestSig18(void)
"byte_extract:1,2,one,string,dec,relative; "
"content:\"|0C 0D 0E 0F|\"; distance:one; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) == 0) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) == 0) {
result = 0;
goto end;
}
Expand Down Expand Up @@ -654,7 +654,7 @@ static int PayloadTestSig19(void)
"byte_extract:1,2,one,string,hex,relative; "
"content:\"|0C 0D 0E 0F|\"; distance:one; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) == 0) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) == 0) {
result = 0;
goto end;
}
Expand Down Expand Up @@ -683,7 +683,7 @@ static int PayloadTestSig20(void)
"byte_extract:1,2,one,string,dec,relative; "
"content:\"|06 35 07 08|\"; offset:one; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) == 0) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) == 0) {
result = 0;
goto end;
}
Expand Down Expand Up @@ -712,7 +712,7 @@ static int PayloadTestSig21(void)
"byte_extract:1,2,one,string,dec,relative; "
"content:\"|03 04 05 06|\"; depth:one; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) == 0) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) == 0) {
result = 0;
goto end;
}
Expand Down Expand Up @@ -741,7 +741,7 @@ static int PayloadTestSig22(void)
"byte_extract:1,2,one,string,dec,relative; "
"content:\"|09 0A 0B 0C|\"; within:one; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) == 0) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) == 0) {
result = 0;
goto end;
}
Expand Down Expand Up @@ -771,7 +771,7 @@ static int PayloadTestSig23(void)
"byte_extract:1,3,two,string,dec,relative; "
"byte_test:1,=,one,two,string,dec,relative; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) == 0) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) == 0) {
result = 0;
goto end;
}
Expand Down Expand Up @@ -801,7 +801,7 @@ static int PayloadTestSig24(void)
"byte_jump:1,one,string,dec,relative; "
"content:\"|0D 0E 0F|\"; distance:0; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) == 0) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) == 0) {
result = 0;
goto end;
}
Expand Down Expand Up @@ -833,7 +833,7 @@ static int PayloadTestSig25(void)
"byte_extract:1,-4,one,string,dec,relative; "
"content:\"|0C 0D 0E 0F|\"; distance:one; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) == 0) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) == 0) {
result = 0;
goto end;
}
Expand Down Expand Up @@ -865,7 +865,7 @@ static int PayloadTestSig26(void)
"byte_extract:1,-3000,one,string,dec,relative; "
"content:\"|0C 0D 0E 0F|\"; distance:one; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) != 0) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) != 0) {
result = 0;
goto end;
}
Expand Down Expand Up @@ -893,7 +893,7 @@ static int PayloadTestSig27(void)
"depth:5; sid:1;)";

p->flags |= PKT_STREAM_ADD;
if (UTHPacketMatchSigMpm(p, sig, MPM_AC) != 1)
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) != 1)
goto end;

result = 1;
Expand All @@ -919,7 +919,7 @@ static int PayloadTestSig28(void)
"offset:4; depth:12; sid:1;)";

p->flags |= PKT_STREAM_ADD;
if (UTHPacketMatchSigMpm(p, sig, MPM_AC) != 1)
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) != 1)
goto end;

result = 1;
Expand All @@ -943,7 +943,7 @@ static int PayloadTestSig29(void)
char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
"pcre:/^.{4}/; content:\"nova\"; within:4; sid:1;)";

if (UTHPacketMatchSigMpm(p, sig, MPM_AC) == 1) {
if (UTHPacketMatchSigMpm(p, sig, DEFAULT_MPM) == 1) {
result = 0;
goto end;
}
Expand Down
3 changes: 3 additions & 0 deletions src/detect-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ static uint8_t DetectEngineCtxLoadConf(DetectEngineCtx *de_ctx) {
/* for now, since we still haven't implemented any intelligence into
* understanding the patterns and distributing mpm_ctx across sgh */
if (de_ctx->mpm_matcher == MPM_AC || de_ctx->mpm_matcher == MPM_AC_GFBS ||
#ifdef __tile__
de_ctx->mpm_matcher == MPM_AC_TILE ||
#endif
#ifdef __SC_CUDA_SUPPORT__
de_ctx->mpm_matcher == MPM_AC_BS || de_ctx->mpm_matcher == MPM_AC_CUDA) {
#else
Expand Down
2 changes: 1 addition & 1 deletion src/detect-http-header.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ static int DetectHttpHeaderTest09(void)
goto end;

de_ctx->flags |= DE_QUIET;
de_ctx->mpm_matcher = MPM_AC;
de_ctx->mpm_matcher = DEFAULT_MPM;

de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
"(msg:\"http header test\"; "
Expand Down
4 changes: 2 additions & 2 deletions src/detect-ipproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -8890,7 +8890,7 @@ static int DetectIPProtoTestSig2(void)
goto end;
}

de_ctx->mpm_matcher = MPM_AC;
de_ctx->mpm_matcher = DEFAULT_MPM;
de_ctx->flags |= DE_QUIET;

de_ctx->sig_list = SigInit(de_ctx,
Expand Down Expand Up @@ -8978,7 +8978,7 @@ static int DetectIPProtoTestSig3(void)
goto end;
}

de_ctx->mpm_matcher = MPM_AC;
de_ctx->mpm_matcher = DEFAULT_MPM;
de_ctx->flags |= DE_QUIET;

de_ctx->sig_list = SigInit(de_ctx,
Expand Down
91 changes: 91 additions & 0 deletions src/util-mpm-ac-tile-small.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* Copyright (C) 2013 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

/**
* \file
*
* \author Ken Steele <suricata@tilera.com>

* Included by util-mpm-ac-tile.c with different SLOAD, SINDEX and
* FUNC_NAME
*
*/


/* This function handles (ctx->state_count < 32767) */
uint32_t FUNC_NAME(SCACTileCtx *ctx, MpmThreadCtx *mpm_thread_ctx,
PatternMatcherQueue *pmq, uint8_t *buf, uint16_t buflen)
{
int i = 0;
int matches = 0;

uint8_t* restrict xlate = ctx->translate_table;
char *state_table = (char*)ctx->state_table_u16;
STYPE state = 0;
int c = xlate[buf[0]];
/* If buflen at least 4 bytes and buf 4-byte aligned. */
if (buflen >= 4 && ((uint64_t)buf & 0x3) == 0) {
BTYPE data = *(BTYPE* restrict)(&buf[0]);
uint64_t index = 0;
/* Process 4*floor(buflen/4) bytes. */
i = 0;
while (i < (buflen & ~0x3)) {
BTYPE data1 = *(BTYPE* restrict)(&buf[i + 4]);
index = SINDEX(index, state);
state = SLOAD(state_table + index + 2 * c);
c = xlate[BYTE1(data)];
if (unlikely(SCHECK(state))) {
matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches);
}
i++;
index = SINDEX(index, state);
state = SLOAD(state_table + index + 2*c);
c = xlate[BYTE2(data)];
if (unlikely(SCHECK(state))) {
matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches);
}
i++;
index = SINDEX(index, state);
state = SLOAD(state_table + index + 2*c);
c = xlate[BYTE3(data)];
if (unlikely(SCHECK(state))) {
matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches);
}
data = data1;
i++;
index = SINDEX(index, state);
state = SLOAD(state_table + index + 2*c);
c = xlate[BYTE0(data)];
if (unlikely(SCHECK(state))) {
matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches);
}
i++;
}
}
/* Process buflen % 4 bytes. */
for (; i < buflen; i++) {
uint64_t index = 0 ;
index = SINDEX(index, state);
state = SLOAD(state_table + index + 2*c);
c = xlate[buf[i+1]];
if (unlikely(SCHECK(state))) {
matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches);
}
} /* for (i = 0; i < buflen; i++) */

return matches;
}
Loading