suricata
util-mpm-ac-tile-small.c
Go to the documentation of this file.
1 /* Copyright (C) 2013-2014 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Ken Steele <suricata@tilera.com>
22 
23  * Included by util-mpm-ac-tile.c with different SLOAD, SINDEX and
24  * FUNC_NAME
25  *
26  */
27 
28 /* Only included into util-mpm-ac-tile.c, which defines FUNC_NAME
29  *
30  */
31 #ifdef FUNC_NAME
32 
33 /* This function handles (ctx->state_count < 32767) */
34 uint32_t FUNC_NAME(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx,
35  PrefilterRuleStore *pmq, const uint8_t *buf, uint32_t buflen)
36 {
37  uint32_t i = 0;
38  int matches = 0;
39 
40  uint8_t mpm_bitarray[ctx->mpm_bitarray_size];
41  memset(mpm_bitarray, 0, ctx->mpm_bitarray_size);
42 
43  const uint8_t* restrict xlate = ctx->translate_table;
44  STYPE *state_table = (STYPE*)ctx->state_table;
45  STYPE state = 0;
46  int c = xlate[buf[0]];
47  /* If buflen at least 4 bytes and buf 4-byte aligned. */
48  if (buflen >= (4 + EXTRA) && ((uintptr_t)buf & 0x3) == 0) {
49  BUF_TYPE data = *(BUF_TYPE* restrict)(&buf[0]);
50  uint64_t index = 0;
51  /* Process 4*floor(buflen/4) bytes. */
52  i = 0;
53  while ((i + EXTRA) < (buflen & ~0x3)) {
54  BUF_TYPE data1 = *(BUF_TYPE* restrict)(&buf[i + 4]);
55  index = SINDEX(index, state);
56  state = SLOAD(state_table + index + c);
57  c = xlate[BYTE1(data)];
58  if (unlikely(SCHECK(state))) {
59  matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
60  }
61  i++;
62  index = SINDEX(index, state);
63  state = SLOAD(state_table + index + c);
64  c = xlate[BYTE2(data)];
65  if (unlikely(SCHECK(state))) {
66  matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
67  }
68  i++;
69  index = SINDEX(index, state);
70  state = SLOAD(state_table + index + c);
71  c = xlate[BYTE3(data)];
72  if (unlikely(SCHECK(state))) {
73  matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
74  }
75  data = data1;
76  i++;
77  index = SINDEX(index, state);
78  state = SLOAD(state_table + index + c);
79  c = xlate[BYTE0(data)];
80  if (unlikely(SCHECK(state))) {
81  matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
82  }
83  i++;
84  }
85  }
86  /* Process buflen % 4 bytes. */
87  for (; i < buflen; i++) {
88  size_t index = 0 ;
89  index = SINDEX(index, state);
90  state = SLOAD(state_table + index + c);
91 #ifndef __tile__
92  if (likely(i+1 < buflen))
93 #endif
94  c = xlate[buf[i+1]];
95  if (unlikely(SCHECK(state))) {
96  matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
97  }
98  } /* for (i = 0; i < buflen; i++) */
99 
100  return matches;
101 }
102 
103 #endif /* FUNC_NAME */
#define SINDEX(y, x)
#define unlikely(expr)
Definition: util-optimize.h:35
#define BYTE3(x)
#define STYPE
#define SCHECK(x)
#define index
Definition: win32-misc.h:29
#define BYTE1(x)
#define FUNC_NAME
#define BUF_TYPE
structure for storing potential rule matches
#define BYTE0(x)
#define EXTRA
#define BYTE2(x)
#define likely(expr)
Definition: util-optimize.h:32
uint8_t translate_table[256]
#define SLOAD(x)