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