suricata
util-spm.h File Reference
#include "util-spm-bs.h"
#include "util-spm-bs2bm.h"
#include "util-spm-bm.h"
Include dependency graph for util-spm.h:

Go to the source code of this file.

Data Structures

struct  SpmCtx_
 
struct  SpmGlobalThreadCtx_
 
struct  SpmThreadCtx_
 
struct  SpmTableElmt_
 

Macros

#define SpmSearch(text, textlen, needle, needlelen)
 
#define SpmNocaseSearch(text, textlen, needle, needlelen)
 

Typedefs

typedef struct SpmCtx_ SpmCtx
 
typedef struct SpmGlobalThreadCtx_ SpmGlobalThreadCtx
 
typedef struct SpmThreadCtx_ SpmThreadCtx
 
typedef struct SpmTableElmt_ SpmTableElmt
 

Enumerations

enum  { SPM_BM, SPM_HS, SPM_TABLE_SIZE }
 

Functions

uint16_t SinglePatternMatchDefaultMatcher (void)
 Returns the single pattern matcher algorithm to be used, based on the spm-algo setting in yaml. More...
 
void SpmTableSetup (void)
 
SpmGlobalThreadCtxSpmInitGlobalThreadCtx (uint16_t matcher)
 
void SpmDestroyGlobalThreadCtx (SpmGlobalThreadCtx *g_thread_ctx)
 
SpmThreadCtxSpmMakeThreadCtx (const SpmGlobalThreadCtx *g_thread_ctx)
 
void SpmDestroyThreadCtx (SpmThreadCtx *thread_ctx)
 
SpmCtxSpmInitCtx (const uint8_t *needle, uint16_t needle_len, int nocase, SpmGlobalThreadCtx *g_thread_ctx)
 
void SpmDestroyCtx (SpmCtx *ctx)
 
uint8_t * SpmScan (const SpmCtx *ctx, SpmThreadCtx *thread_ctx, const uint8_t *haystack, uint32_t haystack_len)
 
uint8_t * Bs2bmSearch (const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen)
 Search a pattern in the text using the Bs2Bm algorithm (build a bad characters array) More...
 
uint8_t * Bs2bmNocaseSearch (const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen)
 Search a pattern in the text using the Bs2Bm nocase algorithm (build a bad characters array) More...
 
uint8_t * BoyerMooreSearch (const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen)
 Search a pattern in the text using Boyer Moore algorithm (build a bad character shifts array and good prefixes shift array) More...
 
uint8_t * BoyerMooreNocaseSearch (const uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen)
 Search a pattern in the text using Boyer Moore nocase algorithm (build a bad character shifts array and good prefixes shift array) More...
 
void UtilSpmSearchRegistertests (void)
 

Variables

SpmTableElmt spm_table [SPM_TABLE_SIZE]
 

Detailed Description

Macro Definition Documentation

#define SpmNocaseSearch (   text,
  textlen,
  needle,
  needlelen 
)
Value:
({\
uint8_t *mfound; \
if (needlelen < 4 && textlen < 512) \
mfound = BasicSearchNocase(text, textlen, needle, needlelen); \
else if (needlelen < 4) \
mfound = BasicSearchNocase(text, textlen, needle, needlelen); \
else \
mfound = BoyerMooreNocaseSearch(text, textlen, needle, needlelen); \
mfound; \
})
uint8_t * BasicSearchNocase(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len)
Basic search case less.
Definition: util-spm-bs.c:102
uint8_t * BoyerMooreNocaseSearch(const uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen)
Search a pattern in the text using Boyer Moore nocase algorithm (build a bad character shifts array a...
Definition: util-spm.c:262

Definition at line 112 of file util-spm.h.

#define SpmSearch (   text,
  textlen,
  needle,
  needlelen 
)
Value:
({\
uint8_t *mfound; \
if (needlelen < 4 && textlen < 512) \
mfound = BasicSearch(text, textlen, needle, needlelen); \
else if (needlelen < 4) \
mfound = BasicSearch(text, textlen, needle, needlelen); \
else \
mfound = BoyerMooreSearch(text, textlen, needle, needlelen); \
mfound; \
})
uint8_t * BasicSearch(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len)
Basic search improved. Limits are better handled, so it doesn&#39;t start searches that wont fit in the r...
Definition: util-spm-bs.c:48
uint8_t * BoyerMooreSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen)
Search a pattern in the text using Boyer Moore algorithm (build a bad character shifts array and good...
Definition: util-spm.c:242

Definition at line 101 of file util-spm.h.

Referenced by DetectFlowvarMatch(), and DetectPktvarRegister().

Typedef Documentation

typedef struct SpmCtx_ SpmCtx

Structure holding an immutable "built" SPM matcher (such as the Boyer-Moore tables, Hyperscan database etc) that is passed to the Scan call.

Structure holding a global prototype for per-thread scratch space, passed to each InitCtx call.

typedef struct SpmTableElmt_ SpmTableElmt
typedef struct SpmThreadCtx_ SpmThreadCtx

Structure holding some mutable per-thread space for use by a matcher at scan time. Constructed from SpmGlobalThreadCtx by the MakeThreadCtx call.

Enumeration Type Documentation

anonymous enum
Enumerator
SPM_BM 
SPM_HS 
SPM_TABLE_SIZE 

Definition at line 31 of file util-spm.h.

Function Documentation

uint8_t* BoyerMooreNocaseSearch ( const uint8_t *  text,
uint32_t  textlen,
uint8_t *  needle,
uint16_t  needlelen 
)

Search a pattern in the text using Boyer Moore nocase algorithm (build a bad character shifts array and good prefixes shift array)

Parameters
textText to search in
textlenlength of the text
needlepattern to search for
needlelenlength of the pattern

Definition at line 262 of file util-spm.c.

References BoyerMooreCtxDeInit(), BoyerMooreNocase(), and BoyerMooreNocaseCtxInit().

Here is the call graph for this function:

uint8_t* BoyerMooreSearch ( const uint8_t *  text,
uint32_t  textlen,
const uint8_t *  needle,
uint16_t  needlelen 
)

Search a pattern in the text using Boyer Moore algorithm (build a bad character shifts array and good prefixes shift array)

Parameters
textText to search in
textlenlength of the text
needlepattern to search for
needlelenlength of the pattern

Definition at line 242 of file util-spm.c.

References BoyerMoore(), BoyerMooreCtxDeInit(), and BoyerMooreCtxInit().

Here is the call graph for this function:

uint8_t* Bs2bmNocaseSearch ( const uint8_t *  text,
uint32_t  textlen,
const uint8_t *  needle,
uint16_t  needlelen 
)

Search a pattern in the text using the Bs2Bm nocase algorithm (build a bad characters array)

Parameters
textText to search in
textlenlength of the text
needlepattern to search for
needlelenlength of the pattern

Definition at line 224 of file util-spm.c.

References ALPHABET_SIZE, Bs2BmBadchars(), and Bs2BmNocase().

Here is the call graph for this function:

uint8_t* Bs2bmSearch ( const uint8_t *  text,
uint32_t  textlen,
const uint8_t *  needle,
uint16_t  needlelen 
)

Search a pattern in the text using the Bs2Bm algorithm (build a bad characters array)

Default algorithm to use: Boyer Moore

Wrappers for building context and searching (Bs2Bm and boyermoore) Use them if you cant store the context

Parameters
textText to search in
textlenlength of the text
needlepattern to search for
needlelenlength of the pattern

Definition at line 207 of file util-spm.c.

References ALPHABET_SIZE, Bs2Bm(), and Bs2BmBadchars().

Here is the call graph for this function:

uint16_t SinglePatternMatchDefaultMatcher ( void  )

Returns the single pattern matcher algorithm to be used, based on the spm-algo setting in yaml.

Definition at line 66 of file util-spm.c.

References ConfGet(), SC_ERR_INVALID_YAML_CONF_ENTRY, SCLogError, SCLogInfo, SPM_BM, SPM_HS, spm_table, and SPM_TABLE_SIZE.

Referenced by AppLayerProtoDetectSetup(), and DetectEngineInspectPktBufferGeneric().

Here is the call graph for this function:

Here is the caller graph for this function:

void SpmDestroyGlobalThreadCtx ( SpmGlobalThreadCtx g_thread_ctx)

Definition at line 137 of file util-spm.c.

References SpmTableElmt_::DestroyGlobalThreadCtx, SpmGlobalThreadCtx_::matcher, and spm_table.

Referenced by AppLayerProtoDetectDeSetup(), and DetectEngineCtxFree().

Here is the caller graph for this function:

void SpmDestroyThreadCtx ( SpmThreadCtx thread_ctx)

Definition at line 156 of file util-spm.c.

References BUG_ON, SpmTableElmt_::DestroyThreadCtx, SpmThreadCtx_::matcher, and spm_table.

Referenced by AppLayerProtoDetectDestroyCtxThread(), and DetectEngineThreadCtxInit().

Here is the caller graph for this function:

SpmCtx* SpmInitCtx ( const uint8_t *  needle,
uint16_t  needle_len,
int  nocase,
SpmGlobalThreadCtx g_thread_ctx 
)
SpmGlobalThreadCtx* SpmInitGlobalThreadCtx ( uint16_t  matcher)

Definition at line 131 of file util-spm.c.

References BUG_ON, SpmTableElmt_::InitGlobalThreadCtx, and spm_table.

Referenced by AppLayerProtoDetectSetup(), and DetectEngineInspectPktBufferGeneric().

Here is the caller graph for this function:

SpmThreadCtx* SpmMakeThreadCtx ( const SpmGlobalThreadCtx g_thread_ctx)

Definition at line 146 of file util-spm.c.

References BUG_ON, SpmTableElmt_::MakeThreadCtx, SpmGlobalThreadCtx_::matcher, and spm_table.

Referenced by AppLayerProtoDetectGetCtxThread(), and DetectEngineResetMaxSigId().

Here is the caller graph for this function:

uint8_t* SpmScan ( const SpmCtx ctx,
SpmThreadCtx thread_ctx,
const uint8_t *  haystack,
uint32_t  haystack_len 
)

Definition at line 186 of file util-spm.c.

References SpmCtx_::matcher, SpmTableElmt_::Scan, and spm_table.

Referenced by DetectEngineContentInspection().

Here is the caller graph for this function:

void SpmTableSetup ( void  )

Definition at line 115 of file util-spm.c.

References spm_table, SpmBMRegister(), and SpmHSRegister().

Referenced by GetProgramVersion(), ListAppLayerProtocols(), ListKeywords(), PostRunDeinit(), and RunUnittests().

Here is the call graph for this function:

Here is the caller graph for this function:

void UtilSpmSearchRegistertests ( void  )

Definition at line 2669 of file util-spm.c.

References UtRegisterTest().

Here is the call graph for this function:

Variable Documentation