suricata
|
#include "suricata-common.h"
#include "suricata.h"
#include "detect.h"
#include "detect-parse.h"
#include "detect-engine.h"
#include "detect-engine-build.h"
#include "conf.h"
#include "util-debug.h"
#include "util-unittest.h"
#include "util-unittest-helper.h"
#include "util-memcmp.h"
#include "util-mpm-ac.h"
#include "util-memcpy.h"
#include "util-validate.h"
#include "detect-engine-alert.h"
Go to the source code of this file.
Data Structures | |
struct | StateQueue_ |
Helper structure used by AC during state table creation. More... | |
Macros | |
#define | SC_AC_FAIL (-1) |
#define | STATE_QUEUE_CONTAINER_SIZE 65536 |
#define | AC_CASE_MASK 0x80000000 |
#define | AC_PID_MASK 0x7FFFFFFF |
#define | AC_CASE_BIT 31 |
Typedefs | |
typedef struct StateQueue_ | StateQueue |
Helper structure used by AC during state table creation. More... | |
Functions | |
void | SCACInitCtx (MpmCtx *mpm_ctx) |
Initialize the AC context. More... | |
void | SCACDestroyCtx (MpmCtx *mpm_ctx) |
Destroy the mpm context. More... | |
int | SCACAddPatternCI (MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags) |
Add a case insensitive pattern. Although we have different calls for adding case sensitive and insensitive patterns, we make a single call for either case. No special treatment for either case. More... | |
int | SCACAddPatternCS (MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags) |
Add a case sensitive pattern. Although we have different calls for adding case sensitive and insensitive patterns, we make a single call for either case. No special treatment for either case. More... | |
int | SCACPreparePatterns (MpmCtx *mpm_ctx) |
Process the patterns added to the mpm, and create the internal tables. More... | |
uint32_t | SCACSearch (const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PrefilterRuleStore *pmq, const uint8_t *buf, uint32_t buflen) |
The aho corasick search function. More... | |
void | SCACPrintInfo (MpmCtx *mpm_ctx) |
void | MpmACRegister (void) |
Register the aho-corasick mpm. More... | |
Definition in file util-mpm-ac.c.
#define AC_CASE_BIT 31 |
Definition at line 87 of file util-mpm-ac.c.
#define AC_CASE_MASK 0x80000000 |
Definition at line 85 of file util-mpm-ac.c.
#define AC_PID_MASK 0x7FFFFFFF |
Definition at line 86 of file util-mpm-ac.c.
#define SC_AC_FAIL (-1) |
Definition at line 81 of file util-mpm-ac.c.
#define STATE_QUEUE_CONTAINER_SIZE 65536 |
Definition at line 83 of file util-mpm-ac.c.
typedef struct StateQueue_ StateQueue |
Helper structure used by AC during state table creation.
void MpmACRegister | ( | void | ) |
Register the aho-corasick mpm.
Definition at line 1097 of file util-mpm-ac.c.
References MpmTableElmt_::AddPattern, MpmTableElmt_::AddPatternNocase, MpmTableElmt_::DestroyCtx, MpmTableElmt_::InitCtx, MPM_AC, mpm_table, MpmTableElmt_::name, MpmTableElmt_::Prepare, MpmTableElmt_::PrintCtx, MpmTableElmt_::RegisterUnittests, SCACAddPatternCI(), SCACAddPatternCS(), SCACDestroyCtx(), SCACInitCtx(), SCACPreparePatterns(), SCACPrintInfo(), SCACSearch(), and MpmTableElmt_::Search.
Referenced by MpmTableSetup().
int SCACAddPatternCI | ( | MpmCtx * | mpm_ctx, |
uint8_t * | pat, | ||
uint16_t | patlen, | ||
uint16_t | offset, | ||
uint16_t | depth, | ||
uint32_t | pid, | ||
SigIntId | sid, | ||
uint8_t | flags | ||
) |
Add a case insensitive pattern. Although we have different calls for adding case sensitive and insensitive patterns, we make a single call for either case. No special treatment for either case.
mpm_ctx | Pointer to the mpm context. |
pat | The pattern to add. |
patnen | The pattern length. |
offset | Ignored. |
depth | Ignored. |
pid | The pattern id. |
sid | Ignored. |
flags | Flags associated with this pattern. |
0 | On success. |
-1 | On failure. |
Definition at line 1040 of file util-mpm-ac.c.
References flags, MPM_PATTERN_FLAG_NOCASE, MpmAddPattern(), and offset.
Referenced by MpmACRegister().
int SCACAddPatternCS | ( | MpmCtx * | mpm_ctx, |
uint8_t * | pat, | ||
uint16_t | patlen, | ||
uint16_t | offset, | ||
uint16_t | depth, | ||
uint32_t | pid, | ||
SigIntId | sid, | ||
uint8_t | flags | ||
) |
Add a case sensitive pattern. Although we have different calls for adding case sensitive and insensitive patterns, we make a single call for either case. No special treatment for either case.
mpm_ctx | Pointer to the mpm context. |
pat | The pattern to add. |
patnen | The pattern length. |
offset | Ignored. |
depth | Ignored. |
pid | The pattern id. |
sid | Ignored. |
flags | Flags associated with this pattern. |
0 | On success. |
-1 | On failure. |
Definition at line 1065 of file util-mpm-ac.c.
References flags, MpmAddPattern(), and offset.
Referenced by MpmACRegister().
void SCACDestroyCtx | ( | MpmCtx * | mpm_ctx | ) |
Destroy the mpm context.
mpm_ctx | Pointer to the mpm context. |
Definition at line 829 of file util-mpm-ac.c.
References ctx, MpmCtx_::ctx, MpmCtx_::init_hash, MpmCtx_::max_pat_id, MpmCtx_::memory_cnt, MpmCtx_::memory_size, MPM_INIT_HASH_SIZE, MpmFreePattern(), MpmCtx_::pattern_cnt, SC_AC_STATE_TYPE_U16, SC_AC_STATE_TYPE_U32, and SCFree.
Referenced by MpmACRegister().
void SCACInitCtx | ( | MpmCtx * | mpm_ctx | ) |
Initialize the AC context.
mpm_ctx | Mpm context. |
Definition at line 798 of file util-mpm-ac.c.
References MpmCtx_::ctx, MpmCtx_::init_hash, MpmCtx_::memory_cnt, MpmCtx_::memory_size, MPM_INIT_HASH_SIZE, and SCCalloc.
Referenced by MpmACRegister().
int SCACPreparePatterns | ( | MpmCtx * | mpm_ctx | ) |
Process the patterns added to the mpm, and create the internal tables.
mpm_ctx | Pointer to the mpm context. |
Definition at line 705 of file util-mpm-ac.c.
References ctx, MpmCtx_::ctx, FatalError, MpmCtx_::init_hash, MpmCtx_::max_pat_id, MpmCtx_::memory_cnt, MpmCtx_::memory_size, MPM_INIT_HASH_SIZE, MPM_PATTERN_FLAG_ENDSWITH, MPM_PATTERN_FLAG_NOCASE, MpmPattern_::next, MpmCtx_::pattern_cnt, SCCalloc, SCFree, SCLogDebug, and SCMalloc.
Referenced by MpmACRegister().
void SCACPrintInfo | ( | MpmCtx * | mpm_ctx | ) |
Definition at line 1072 of file util-mpm-ac.c.
References ctx, MpmCtx_::ctx, MpmCtx_::maxlen, MpmCtx_::memory_cnt, MpmCtx_::memory_size, MpmCtx_::minlen, and MpmCtx_::pattern_cnt.
Referenced by MpmACRegister().
uint32_t SCACSearch | ( | const MpmCtx * | mpm_ctx, |
MpmThreadCtx * | mpm_thread_ctx, | ||
PrefilterRuleStore * | pmq, | ||
const uint8_t * | buf, | ||
uint32_t | buflen | ||
) |
The aho corasick search function.
mpm_ctx | Pointer to the mpm context. |
mpm_thread_ctx | Pointer to the mpm thread context. |
pmq | Pointer to the Pattern Matcher Queue to hold search matches. |
buf | Buffer to be searched. |
buflen | Buffer length. |
matches | Match count: counts unique matches per pattern. |
Definition at line 912 of file util-mpm-ac.c.
References AC_CASE_MASK, AC_PID_MASK, SCACPatternList_::cs, ctx, MpmCtx_::ctx, SCACPatternList_::depth, SCACPatternList_::endswith, offset, SCACPatternList_::offset, SCACPatternList_::patlen, SC_AC_STATE_TYPE_U16, SCMemcmp, and u8_tolower.
Referenced by MpmACRegister().