suricata
util-mpm.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2021 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 Victor Julien <victor@inliniac.net>
22  *
23  * Pattern matcher utility Functions
24  */
25 
26 #include "suricata-common.h"
27 #include "util-mpm.h"
28 #include "util-debug.h"
29 
30 /* include pattern matchers */
31 #include "util-mpm-ac.h"
32 #include "util-mpm-ac-ks.h"
33 #include "util-mpm-hs.h"
34 #include "util-hashlist.h"
35 
36 #include "detect-engine.h"
37 #include "util-misc.h"
38 #include "conf.h"
39 #include "conf-yaml-loader.h"
40 #include "queue.h"
41 #include "util-unittest.h"
42 #include "util-memcpy.h"
43 #ifdef BUILD_HYPERSCAN
44 #include "hs.h"
45 #endif
46 
49 
50 /**
51  * \brief Register a new Mpm Context.
52  *
53  * \param name A new profile to be registered to store this MpmCtx.
54  * \param sm_list sm_list for this name (might be variable with xforms)
55  * \param alproto app proto or ALPROTO_UNKNOWN if not for app-layer
56  *
57  * \retval id Return the id created for the new MpmCtx profile.
58  */
60  DetectEngineCtx *de_ctx, const char *name, const int sm_list, const AppProto alproto)
61 {
62  /* the very first entry */
63  if (de_ctx->mpm_ctx_factory_container == NULL) {
65  if (de_ctx->mpm_ctx_factory_container == NULL) {
66  FatalError("Error allocating memory");
67  }
69  }
70 
72  MpmCtxFactoryItem *pitem = NULL;
73  while (item) {
74  if (item->sm_list == sm_list && item->alproto == alproto && item->name != NULL &&
75  strcmp(item->name, name) == 0) {
76  return item->id;
77  }
78  pitem = item;
79  item = item->next;
80  }
81 
82  MpmCtxFactoryItem *nitem = SCCalloc(1, sizeof(MpmCtxFactoryItem));
83  if (unlikely(nitem == NULL)) {
84  FatalError("Error allocating memory");
85  }
86  nitem->name = name;
87  nitem->sm_list = sm_list;
89  nitem->alproto = alproto;
90 
91  /* toserver */
92  nitem->mpm_ctx_ts = SCCalloc(1, sizeof(MpmCtx));
93  if (nitem->mpm_ctx_ts == NULL) {
94  FatalError("Error allocating memory");
95  }
97 
98  /* toclient */
99  nitem->mpm_ctx_tc = SCCalloc(1, sizeof(MpmCtx));
100  if (nitem->mpm_ctx_tc == NULL) {
101  FatalError("Error allocating memory");
102  }
104 
105  /* store the newly created item */
106  if (pitem == NULL)
108  else
109  pitem->next = nitem;
110 
111  return nitem->id;
112 }
113 
115 {
116  if (mpm_ctx == NULL)
117  return 0;
118 
119  if (de_ctx->mpm_ctx_factory_container == NULL) {
120  return 0;
121  }
122 
123  for (MpmCtxFactoryItem *i = de_ctx->mpm_ctx_factory_container->items; i != NULL; i = i->next) {
124  if (mpm_ctx == i->mpm_ctx_ts || mpm_ctx == i->mpm_ctx_tc) {
125  return 1;
126  }
127  }
128  return 0;
129 }
130 
131 MpmCtx *MpmFactoryGetMpmCtxForProfile(const DetectEngineCtx *de_ctx, int32_t id, int direction)
132 {
133  if (id == MPM_CTX_FACTORY_UNIQUE_CONTEXT) {
134  MpmCtx *mpm_ctx = SCCalloc(1, sizeof(MpmCtx));
135  if (unlikely(mpm_ctx == NULL)) {
136  FatalError("Error allocating memory");
137  }
138  return mpm_ctx;
139  } else if (id < -1) {
140  SCLogError("Invalid argument - %d\n", id);
141  return NULL;
142  } else if (id >= de_ctx->mpm_ctx_factory_container->max_id) {
143  /* this id does not exist */
144  return NULL;
145  } else {
147  i = i->next) {
148  if (id == i->id) {
149  return (direction == 0) ? i->mpm_ctx_ts : i->mpm_ctx_tc;
150  }
151  }
152  return NULL;
153  }
154 }
155 
157 {
158  if (mpm_ctx == NULL)
159  return;
160 
161  if (!MpmFactoryIsMpmCtxAvailable(de_ctx, mpm_ctx)) {
162  if (mpm_ctx->mpm_type != MPM_NOTSET)
163  mpm_table[mpm_ctx->mpm_type].DestroyCtx(mpm_ctx);
164  SCFree(mpm_ctx);
165  }
166 }
167 
169 {
170  if (de_ctx->mpm_ctx_factory_container == NULL)
171  return;
172 
174  while (item) {
175  if (item->mpm_ctx_ts != NULL) {
176  if (item->mpm_ctx_ts->mpm_type != MPM_NOTSET)
178  SCFree(item->mpm_ctx_ts);
179  }
180  if (item->mpm_ctx_tc != NULL) {
181  if (item->mpm_ctx_tc->mpm_type != MPM_NOTSET)
183  SCFree(item->mpm_ctx_tc);
184  }
185 
186  MpmCtxFactoryItem *next = item->next;
187  SCFree(item);
188  item = next;
189  }
190 
193 }
194 
195 void MpmInitThreadCtx(MpmThreadCtx *mpm_thread_ctx, uint16_t matcher)
196 {
197  if (mpm_table[matcher].InitThreadCtx != NULL) {
198  mpm_table[matcher].InitThreadCtx(NULL, mpm_thread_ctx);
199  }
200 }
201 
202 void MpmDestroyThreadCtx(MpmThreadCtx *mpm_thread_ctx, const uint16_t matcher)
203 {
204  if (mpm_table[matcher].DestroyThreadCtx != NULL) {
205  mpm_table[matcher].DestroyThreadCtx(NULL, mpm_thread_ctx);
206  }
207 }
208 
209 void MpmInitCtx(MpmCtx *mpm_ctx, uint8_t matcher)
210 {
211  mpm_ctx->mpm_type = matcher;
212  mpm_table[matcher].InitCtx(mpm_ctx);
213 }
214 
215 /* MPM matcher to use by default, i.e. when "mpm-algo" is set to "auto".
216  * If Hyperscan is available, use it. Otherwise, use AC. */
217 #ifdef BUILD_HYPERSCAN
218 # define DEFAULT_MPM MPM_HS
219 # define DEFAULT_MPM_AC MPM_AC
220 #else
221 # define DEFAULT_MPM MPM_AC
222 #endif
223 
224 void MpmTableSetup(void)
225 {
226  memset(mpm_table, 0, sizeof(mpm_table));
228 
229  MpmACRegister();
231 #ifdef BUILD_HYPERSCAN
232  #ifdef HAVE_HS_VALID_PLATFORM
233  /* Enable runtime check for SSSE3. Do not use Hyperscan MPM matcher if
234  * check is not successful. */
235  if (hs_valid_platform() != HS_SUCCESS) {
236  SCLogInfo("SSSE3 support not detected, disabling Hyperscan for "
237  "MPM");
238  /* Fall back to best Aho-Corasick variant. */
239  mpm_default_matcher = DEFAULT_MPM_AC;
240  } else {
241  MpmHSRegister();
242  }
243  #else
244  MpmHSRegister();
245  #endif /* HAVE_HS_VALID_PLATFORM */
246 #endif /* BUILD_HYPERSCAN */
247 }
248 
249 int MpmAddPatternCS(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen,
250  uint16_t offset, uint16_t depth,
251  uint32_t pid, SigIntId sid, uint8_t flags)
252 {
253  return mpm_table[mpm_ctx->mpm_type].AddPattern(mpm_ctx, pat, patlen,
254  offset, depth,
255  pid, sid, flags);
256 }
257 
258 int MpmAddPatternCI(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen,
259  uint16_t offset, uint16_t depth,
260  uint32_t pid, SigIntId sid, uint8_t flags)
261 {
262  return mpm_table[mpm_ctx->mpm_type].AddPatternNocase(mpm_ctx, pat, patlen,
263  offset, depth,
264  pid, sid, flags);
265 }
266 
267 
268 /**
269  * \internal
270  * \brief Creates a hash of the pattern. We use it for the hashing process
271  * during the initial pattern insertion time, to cull duplicate sigs.
272  *
273  * \param pat Pointer to the pattern.
274  * \param patlen Pattern length.
275  *
276  * \retval hash A 32 bit unsigned hash.
277  */
278 static inline uint32_t MpmInitHashRaw(uint8_t *pat, uint16_t patlen)
279 {
280  uint32_t hash = patlen * pat[0];
281  if (patlen > 1)
282  hash += pat[1];
283 
284  return (hash % MPM_INIT_HASH_SIZE);
285 }
286 
287 /**
288  * \internal
289  * \brief Looks up a pattern. We use it for the hashing process during the
290  * the initial pattern insertion time, to cull duplicate sigs.
291  *
292  * \param ctx Pointer to the AC ctx.
293  * \param pat Pointer to the pattern.
294  * \param patlen Pattern length.
295  * \param flags Flags. We don't need this.
296  *
297  * \retval hash A 32 bit unsigned hash.
298  */
299 static inline MpmPattern *MpmInitHashLookup(MpmCtx *ctx,
300  uint8_t *pat, uint16_t patlen,
301  uint16_t offset, uint16_t depth,
302  uint8_t flags, uint32_t pid)
303 {
304  uint32_t hash = MpmInitHashRaw(pat, patlen);
305 
306  if (ctx->init_hash == NULL) {
307  return NULL;
308  }
309 
310  MpmPattern *t = ctx->init_hash[hash];
311  for ( ; t != NULL; t = t->next) {
312  if (!(flags & MPM_PATTERN_CTX_OWNS_ID)) {
313  if (t->id == pid)
314  return t;
315  } else {
316  if (t->len == patlen && t->offset == offset && t->depth == depth &&
317  memcmp(pat, t->original_pat, patlen) == 0 &&
318  t->flags == flags)
319  {
320  return t;
321  }
322  }
323  }
324 
325  return NULL;
326 }
327 
328 /**
329  * \internal
330  * \brief Allocs a new pattern instance.
331  *
332  * \param mpm_ctx Pointer to the mpm context.
333  *
334  * \retval p Pointer to the newly created pattern.
335  */
336 static inline MpmPattern *MpmAllocPattern(MpmCtx *mpm_ctx)
337 {
338  MpmPattern *p = SCCalloc(1, sizeof(MpmPattern));
339  if (unlikely(p == NULL)) {
340  exit(EXIT_FAILURE);
341  }
342 
343  mpm_ctx->memory_cnt++;
344  mpm_ctx->memory_size += sizeof(MpmPattern);
345 
346  return p;
347 }
348 
349 /**
350  * \internal
351  * \brief Used to free MpmPattern instances.
352  *
353  * \param mpm_ctx Pointer to the mpm context.
354  * \param p Pointer to the MpmPattern instance to be freed.
355  */
356 void MpmFreePattern(MpmCtx *mpm_ctx, MpmPattern *p)
357 {
358  if (p == NULL)
359  return;
360 
361  if (p->cs != NULL && p->cs != p->ci) {
362  SCFree(p->cs);
363  mpm_ctx->memory_cnt--;
364  mpm_ctx->memory_size -= p->len;
365  }
366 
367  if (p->ci != NULL) {
368  SCFree(p->ci);
369  mpm_ctx->memory_cnt--;
370  mpm_ctx->memory_size -= p->len;
371  }
372 
373  if (p->original_pat != NULL) {
374  SCFree(p->original_pat);
375  mpm_ctx->memory_cnt--;
376  mpm_ctx->memory_size -= p->len;
377  }
378 
379  if (p->sids != NULL) {
380  SCFree(p->sids);
381  }
382 
383  SCFree(p);
384  mpm_ctx->memory_cnt--;
385  mpm_ctx->memory_size -= sizeof(MpmPattern);
386 }
387 
388 static inline uint32_t MpmInitHash(MpmPattern *p)
389 {
390  uint32_t hash = p->len * p->original_pat[0];
391  if (p->len > 1)
392  hash += p->original_pat[1];
393 
394  return (hash % MPM_INIT_HASH_SIZE);
395 }
396 
397 static inline int MpmInitHashAdd(MpmCtx *ctx, MpmPattern *p)
398 {
399  uint32_t hash = MpmInitHash(p);
400 
401  if (ctx->init_hash == NULL) {
402  return -1;
403  }
404 
405  if (ctx->init_hash[hash] == NULL) {
406  ctx->init_hash[hash] = p;
407  return 0;
408  }
409 
410  MpmPattern *tt = NULL;
411  MpmPattern *t = ctx->init_hash[hash];
412 
413  /* get the list tail */
414  do {
415  tt = t;
416  t = t->next;
417  } while (t != NULL);
418 
419  tt->next = p;
420 
421  return 0;
422 }
423 
424 /**
425  * \internal
426  * \brief Add a pattern to the mpm-ac context.
427  *
428  * \param mpm_ctx Mpm context.
429  * \param pat Pointer to the pattern.
430  * \param patlen Length of the pattern.
431  * \param pid Pattern id
432  * \param sid Signature id (internal id).
433  * \param flags Pattern's MPM_PATTERN_* flags.
434  *
435  * \retval 0 On success.
436  * \retval -1 On failure.
437  */
438 int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
439  uint16_t offset, uint16_t depth, uint32_t pid,
440  SigIntId sid, uint8_t flags)
441 {
442  SCLogDebug("Adding pattern for ctx %p, patlen %"PRIu16" and pid %" PRIu32,
443  mpm_ctx, patlen, pid);
444 
445  if (patlen == 0) {
446  SCLogWarning("pattern length 0");
447  return 0;
448  }
449 
451  pid = UINT_MAX;
452 
453  /* check if we have already inserted this pattern */
454  MpmPattern *p = MpmInitHashLookup(mpm_ctx, pat, patlen,
455  offset, depth, flags, pid);
456  if (p == NULL) {
457  SCLogDebug("Allocing new pattern");
458 
459  /* p will never be NULL */
460  p = MpmAllocPattern(mpm_ctx);
461 
462  p->len = patlen;
463  p->flags = flags;
464  p->offset = offset;
465  p->depth = depth;
467  p->id = mpm_ctx->max_pat_id++;
468  else
469  p->id = pid;
470 
471  p->original_pat = SCMalloc(patlen);
472  if (p->original_pat == NULL)
473  goto error;
474  mpm_ctx->memory_cnt++;
475  mpm_ctx->memory_size += patlen;
476  memcpy(p->original_pat, pat, patlen);
477 
478  p->ci = SCMalloc(patlen);
479  if (p->ci == NULL)
480  goto error;
481  mpm_ctx->memory_cnt++;
482  mpm_ctx->memory_size += patlen;
483  memcpy_tolower(p->ci, pat, patlen);
484 
485  /* setup the case sensitive part of the pattern */
486  if (p->flags & MPM_PATTERN_FLAG_NOCASE) {
487  /* nocase means no difference between cs and ci */
488  p->cs = p->ci;
489  } else {
490  if (memcmp(p->ci, pat, p->len) == 0) {
491  /* no diff between cs and ci: pat is lowercase */
492  p->cs = p->ci;
493  } else {
494  p->cs = SCMalloc(patlen);
495  if (p->cs == NULL)
496  goto error;
497  mpm_ctx->memory_cnt++;
498  mpm_ctx->memory_size += patlen;
499  memcpy(p->cs, pat, patlen);
500  }
501  }
502 
503  /* put in the pattern hash */
504  if (MpmInitHashAdd(mpm_ctx, p) != 0)
505  goto error;
506 
507  mpm_ctx->pattern_cnt++;
508 
509  if (!(mpm_ctx->flags & MPMCTX_FLAGS_NODEPTH)) {
510  if (depth) {
511  mpm_ctx->maxdepth = MAX(mpm_ctx->maxdepth, depth);
512  SCLogDebug("%p: depth %u max %u", mpm_ctx, depth, mpm_ctx->maxdepth);
513  } else {
514  mpm_ctx->flags |= MPMCTX_FLAGS_NODEPTH;
515  mpm_ctx->maxdepth = 0;
516  SCLogDebug("%p: alas, no depth for us", mpm_ctx);
517  }
518  }
519 
520  if (mpm_ctx->maxlen < patlen)
521  mpm_ctx->maxlen = patlen;
522 
523  if (mpm_ctx->minlen == 0) {
524  mpm_ctx->minlen = patlen;
525  } else {
526  if (mpm_ctx->minlen > patlen)
527  mpm_ctx->minlen = patlen;
528  }
529 
530  /* we need the max pat id */
531  if (p->id > mpm_ctx->max_pat_id)
532  mpm_ctx->max_pat_id = p->id;
533 
534  p->sids_size = 1;
535  p->sids = SCMalloc(p->sids_size * sizeof(SigIntId));
536  BUG_ON(p->sids == NULL);
537  p->sids[0] = sid;
538  } else {
539  /* we can be called multiple times for the same sid in the case
540  * of the 'single' modus. Here multiple rule groups share the
541  * same mpm ctx and might be adding the same pattern to the
542  * mpm_ctx */
543  int found = 0;
544  uint32_t x = 0;
545  for (x = 0; x < p->sids_size; x++) {
546  if (p->sids[x] == sid) {
547  found = 1;
548  break;
549  }
550  }
551 
552  if (!found) {
553  SigIntId *sids = SCRealloc(p->sids, (sizeof(SigIntId) * (p->sids_size + 1)));
554  BUG_ON(sids == NULL);
555  p->sids = sids;
556  p->sids[p->sids_size] = sid;
557  p->sids_size++;
558  }
559  }
560 
561  return 0;
562 
563 error:
564  MpmFreePattern(mpm_ctx, p);
565  return -1;
566 }
567 
568 
569 /************************************Unittests*********************************/
570 
571 #ifdef UNITTESTS
572 #endif /* UNITTESTS */
573 
575 {
576 #ifdef UNITTESTS
577  uint16_t i;
578 
579  for (i = 0; i < MPM_TABLE_SIZE; i++) {
580  if (i == MPM_NOTSET)
581  continue;
582 
583  g_ut_modules++;
584 
585  if (mpm_table[i].RegisterUnittests != NULL) {
586  g_ut_covered++;
588  } else {
589  if (coverage_unittests)
590  SCLogWarning("mpm module %s has no "
591  "unittest registration function.",
592  mpm_table[i].name);
593  }
594  }
595 
596 #endif
597 }
MpmInitThreadCtx
void MpmInitThreadCtx(MpmThreadCtx *mpm_thread_ctx, uint16_t matcher)
Definition: util-mpm.c:195
MpmCtx_::mpm_type
uint8_t mpm_type
Definition: util-mpm.h:90
detect-engine.h
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
MpmTableElmt_::InitThreadCtx
void(* InitThreadCtx)(struct MpmCtx_ *, struct MpmThreadCtx_ *)
Definition: util-mpm.h:148
util-hashlist.h
MpmFactoryDeRegisterAllMpmCtxProfiles
void MpmFactoryDeRegisterAllMpmCtxProfiles(DetectEngineCtx *de_ctx)
Definition: util-mpm.c:168
g_ut_modules
int g_ut_modules
Definition: suricata.c:889
MpmThreadCtx_
Definition: util-mpm.h:46
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
MpmFreePattern
void MpmFreePattern(MpmCtx *mpm_ctx, MpmPattern *p)
Definition: util-mpm.c:356
MpmFactoryReClaimMpmCtx
void MpmFactoryReClaimMpmCtx(const DetectEngineCtx *de_ctx, MpmCtx *mpm_ctx)
Definition: util-mpm.c:156
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
util-mpm-ac-ks.h
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:85
MpmRegisterTests
void MpmRegisterTests(void)
Definition: util-mpm.c:574
ctx
struct Thresholds ctx
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:846
util-memcpy.h
MpmCtx_::memory_size
uint32_t memory_size
Definition: util-mpm.h:103
g_ut_covered
int g_ut_covered
Definition: suricata.c:890
MPM_NOTSET
@ MPM_NOTSET
Definition: util-mpm.h:33
MpmTableElmt_::AddPatternNocase
int(* AddPatternNocase)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t)
Definition: util-mpm.h:164
MpmCtxFactoryItem::mpm_ctx_ts
MpmCtx * mpm_ctx_ts
Definition: util-mpm.h:117
MPM_TABLE_SIZE
@ MPM_TABLE_SIZE
Definition: util-mpm.h:40
MpmCtx_::maxlen
uint16_t maxlen
Definition: util-mpm.h:100
MpmTableElmt_::AddPattern
int(* AddPattern)(struct MpmCtx_ *, uint8_t *, uint16_t, uint16_t, uint16_t, uint32_t, SigIntId, uint8_t)
Definition: util-mpm.h:163
mpm_default_matcher
uint8_t mpm_default_matcher
Definition: util-mpm.c:48
DetectEngineCtx_::mpm_ctx_factory_container
MpmCtxFactoryContainer * mpm_ctx_factory_container
Definition: detect.h:913
MpmPattern_::original_pat
uint8_t * original_pat
Definition: util-mpm.h:67
MpmCtx_::maxdepth
uint16_t maxdepth
Definition: util-mpm.h:94
MAX
#define MAX(x, y)
Definition: suricata-common.h:395
MpmTableElmt_::InitCtx
void(* InitCtx)(struct MpmCtx_ *)
Definition: util-mpm.h:147
util-unittest.h
MpmPattern_::flags
uint8_t flags
Definition: util-mpm.h:58
MpmInitCtx
void MpmInitCtx(MpmCtx *mpm_ctx, uint8_t matcher)
Definition: util-mpm.c:209
DEFAULT_MPM
#define DEFAULT_MPM
Definition: util-mpm.c:221
MpmCtx_::max_pat_id
uint32_t max_pat_id
Definition: util-mpm.h:105
MpmPattern
struct MpmPattern_ MpmPattern
MpmCtxFactoryItem::name
const char * name
Definition: util-mpm.h:116
MpmDestroyThreadCtx
void MpmDestroyThreadCtx(MpmThreadCtx *mpm_thread_ctx, const uint16_t matcher)
Definition: util-mpm.c:202
MpmFactoryIsMpmCtxAvailable
int32_t MpmFactoryIsMpmCtxAvailable(const DetectEngineCtx *de_ctx, const MpmCtx *mpm_ctx)
Definition: util-mpm.c:114
util-debug.h
MpmPattern_::next
struct MpmPattern_ * next
Definition: util-mpm.h:79
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
MpmFactoryGetMpmCtxForProfile
MpmCtx * MpmFactoryGetMpmCtxForProfile(const DetectEngineCtx *de_ctx, int32_t id, int direction)
Definition: util-mpm.c:131
MPM_PATTERN_CTX_OWNS_ID
#define MPM_PATTERN_CTX_OWNS_ID
Definition: util-mpm.h:138
MpmPattern_::id
uint32_t id
Definition: util-mpm.h:73
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
MpmCtxFactoryContainer_::items
MpmCtxFactoryItem * items
Definition: util-mpm.h:126
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:99
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:300
MpmPattern_::sids_size
uint32_t sids_size
Definition: util-mpm.h:76
MPMCTX_FLAGS_GLOBAL
#define MPMCTX_FLAGS_GLOBAL
Definition: util-mpm.h:85
MpmFactoryRegisterMpmCtxProfile
int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *name, const int sm_list, const AppProto alproto)
Register a new Mpm Context.
Definition: util-mpm.c:59
conf-yaml-loader.h
conf.h
MPM_INIT_HASH_SIZE
#define MPM_INIT_HASH_SIZE
Definition: util-mpm.h:30
name
const char * name
Definition: tm-threads.c:2081
queue.h
util-mpm-ac.h
MpmPattern_
Definition: util-mpm.h:54
MpmCtxFactoryItem::sm_list
int32_t sm_list
Definition: util-mpm.h:120
MpmTableSetup
void MpmTableSetup(void)
Definition: util-mpm.c:224
MpmAddPatternCS
int MpmAddPatternCS(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
Definition: util-mpm.c:249
MPMCTX_FLAGS_NODEPTH
#define MPMCTX_FLAGS_NODEPTH
Definition: util-mpm.h:86
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:224
MpmACTileRegister
void MpmACTileRegister(void)
Register the aho-corasick mpm 'ks' originally developed by Ken Steele for Tilera Tile-Gx processor.
Definition: util-mpm-ac-ks.c:1398
MpmPattern_::ci
uint8_t * ci
Definition: util-mpm.h:71
ENGINE_SGH_MPM_FACTORY_CONTEXT_START_ID_RANGE
#define ENGINE_SGH_MPM_FACTORY_CONTEXT_START_ID_RANGE
Definition: detect.h:1072
MpmCtxFactoryItem::next
struct MpmCtxFactoryItem * next
Definition: util-mpm.h:122
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
MPM_PATTERN_FLAG_NOCASE
#define MPM_PATTERN_FLAG_NOCASE
Definition: util-mpm.h:131
util-mpm.h
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
MpmCtx_::pattern_cnt
uint32_t pattern_cnt
Definition: util-mpm.h:97
MpmPattern_::offset
uint16_t offset
Definition: util-mpm.h:61
FatalError
#define FatalError(...)
Definition: util-debug.h:502
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
MpmPattern_::sids
SigIntId * sids
Definition: util-mpm.h:77
MpmPattern_::depth
uint16_t depth
Definition: util-mpm.h:64
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
MpmTableElmt_::DestroyCtx
void(* DestroyCtx)(struct MpmCtx_ *)
Definition: util-mpm.h:149
MpmCtxFactoryItem
Definition: util-mpm.h:115
SCFree
#define SCFree(p)
Definition: util-mem.h:61
MPM_CTX_FACTORY_UNIQUE_CONTEXT
#define MPM_CTX_FACTORY_UNIQUE_CONTEXT
Definition: util-mpm.h:113
MpmACRegister
void MpmACRegister(void)
Register the aho-corasick mpm.
Definition: util-mpm-ac.c:1097
MpmCtxFactoryItem::alproto
AppProto alproto
Definition: util-mpm.h:121
MpmCtxFactoryItem::id
int32_t id
Definition: util-mpm.h:119
MpmCtx_::memory_cnt
uint32_t memory_cnt
Definition: util-mpm.h:102
MpmPattern_::len
uint16_t len
Definition: util-mpm.h:56
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:47
MpmCtxFactoryItem::mpm_ctx_tc
MpmCtx * mpm_ctx_tc
Definition: util-mpm.h:118
util-mpm-hs.h
MpmAddPattern
int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
Definition: util-mpm.c:438
MpmTableElmt_::DestroyThreadCtx
void(* DestroyThreadCtx)(struct MpmCtx_ *, struct MpmThreadCtx_ *)
Definition: util-mpm.h:150
MpmCtxFactoryContainer_::max_id
int32_t max_id
Definition: util-mpm.h:127
coverage_unittests
int coverage_unittests
Definition: suricata.c:888
MpmCtx_
Definition: util-mpm.h:88
util-misc.h
MpmPattern_::cs
uint8_t * cs
Definition: util-mpm.h:69
SigIntId
#define SigIntId
Definition: suricata-common.h:315
MpmCtx_::flags
uint8_t flags
Definition: util-mpm.h:92
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
MpmTableElmt_
Definition: util-mpm.h:145
MpmHSRegister
void MpmHSRegister(void)
MpmAddPatternCI
int MpmAddPatternCI(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
Definition: util-mpm.c:258
MpmTableElmt_::RegisterUnittests
void(* RegisterUnittests)(void)
Definition: util-mpm.h:171
MpmCtxFactoryContainer_
Definition: util-mpm.h:125