suricata
detect-parse.h File Reference

Go to the source code of this file.

Data Structures

struct  DetectParseRegex_
 

Macros

#define MAX_SUBSTRINGS   30
 

Typedefs

typedef struct DetectParseRegex_ DetectParseRegex
 

Enumerations

enum  { SIG_DIREC_NORMAL, SIG_DIREC_SWITCHED }
 
enum  { SIG_DIREC_SRC, SIG_DIREC_DST }
 

Functions

SignatureSigAlloc (void)
 
void SigFree (Signature *s)
 
SignatureSigInit (DetectEngineCtx *, const char *sigstr)
 Parses a signature and adds it to the Detection Engine Context. More...
 
SignatureSigInitReal (DetectEngineCtx *, const char *)
 
SigMatchDataSigMatchList2DataArray (SigMatch *head)
 convert SigMatch list to SigMatchData array More...
 
void SigParseRegisterTests (void)
 
SignatureDetectEngineAppendSig (DetectEngineCtx *, const char *)
 Parse and append a Signature into the Detection Engine Context signature list. More...
 
void SigMatchAppendSMToList (Signature *, SigMatch *, int)
 Append a SigMatch to the list type. More...
 
void SigMatchRemoveSMFromList (Signature *, SigMatch *, int)
 
int SigMatchListSMBelongsTo (const Signature *, const SigMatch *)
 
int DetectParseDupSigHashInit (DetectEngineCtx *)
 Initializes the hash table that is used to cull duplicate sigs. More...
 
void DetectParseDupSigHashFree (DetectEngineCtx *)
 Frees the hash table that is used to cull duplicate sigs. More...
 
int DetectEngineContentModifierBufferSetup (DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
 
bool SigMatchSilentErrorEnabled (const DetectEngineCtx *de_ctx, const enum DetectKeywordId id)
 
bool SigMatchStrictEnabled (const enum DetectKeywordId id)
 
const char * DetectListToHumanString (int list)
 
const char * DetectListToString (int list)
 
void SigTableApplyStrictCommandlineOption (const char *str)
 
SigMatchDetectGetLastSM (const Signature *)
 Returns the sm with the largest index (added latest) from this sig. More...
 
SigMatchDetectGetLastSMFromMpmLists (const DetectEngineCtx *de_ctx, const Signature *s)
 get the last SigMatch from lists that support MPM. More...
 
SigMatchDetectGetLastSMFromLists (const Signature *s,...)
 Returns the sm with the largest index (added latest) from the lists passed to us. More...
 
SigMatchDetectGetLastSMByListPtr (const Signature *s, SigMatch *sm_list,...)
 Returns the sm with the largest index (added last) from the list passed to us as a pointer. More...
 
SigMatchDetectGetLastSMByListId (const Signature *s, int list_id,...)
 Returns the sm with the largest index (added last) from the list passed to us as an id. More...
 
int DetectSignatureAddTransform (Signature *s, int transform)
 
int WARN_UNUSED DetectSignatureSetAppProto (Signature *s, AppProto alproto)
 
void DetectSetupParseRegexesOpts (const char *parse_str, DetectParseRegex *parse_regex, int opts)
 
void DetectSetupParseRegexes (const char *parse_str, DetectParseRegex *parse_regex)
 
void DetectParseRegexAddToFreeList (DetectParseRegex *parse_regex)
 add regex and/or study to at exit free list More...
 
void DetectParseFreeRegexes (void)
 
void DetectParseFreeRegex (DetectParseRegex *r)
 
int DetectParsePcreExec (DetectParseRegex *parse_regex, const char *str, int start_offset, int options, int *ovector, int ovector_size)
 
int DetectParsePcreExecLen (DetectParseRegex *parse_regex, const char *str, int str_len, int start_offset, int options, int *ovector, int ovector_size)
 

Detailed Description

Macro Definition Documentation

◆ MAX_SUBSTRINGS

#define MAX_SUBSTRINGS   30

Definition at line 106 of file detect-parse.h.

Typedef Documentation

◆ DetectParseRegex

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Flags to indicate if the Signature parsing must be done switching the source and dest (for ip addresses and ports) or otherwise as normal

Enumerator
SIG_DIREC_NORMAL 
SIG_DIREC_SWITCHED 

Definition at line 30 of file detect-parse.h.

◆ anonymous enum

anonymous enum

Flags to indicate if are referencing the source of the Signature or the destination (for ip addresses and ports)

Enumerator
SIG_DIREC_SRC 
SIG_DIREC_DST 

Definition at line 37 of file detect-parse.h.

Function Documentation

◆ DetectEngineAppendSig()

Signature* DetectEngineAppendSig ( DetectEngineCtx de_ctx,
const char *  sigstr 
)

Parse and append a Signature into the Detection Engine Context signature list.

If the signature is bidirectional it should append two signatures (with the addresses switched) into the list. Also handle duplicate signatures. In case of duplicate sigs, use the ones that have the latest revision. We use the sid and the msg to identifiy duplicate sigs. If 2 sigs have the same sid and gid, they are duplicates.

Parameters
de_ctxPointer to the Detection Engine Context.
sigstrPointer to a character string containing the signature to be parsed.
sig_filePointer to a character string containing the filename from which signature is read
linenoLine number from where signature is read
Return values
Pointerto the head Signature in the detection engine ctx sig_list on success; NULL on failure.

In DetectEngineAppendSig(), the signatures are prepended and we always return the first one so if the signature is bidirectional, the returned sig will point through "next" ptr to the cloned signatures with the switched addresses

Definition at line 2316 of file detect-parse.c.

References de_ctx, and SigInit().

Referenced by UTHAppendSigs(), and UTHParseSignature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DetectEngineContentModifierBufferSetup()

◆ DetectGetLastSM()

SigMatch* DetectGetLastSM ( const Signature s)

Returns the sm with the largest index (added latest) from this sig.

Return values
sm_lastPointer to last sm

Definition at line 572 of file detect-parse.c.

References SigMatch_::idx, Signature_::init_data, SignatureInitData_::smlists_array_size, and SignatureInitData_::smlists_tail.

◆ DetectGetLastSMByListId()

SigMatch* DetectGetLastSMByListId ( const Signature s,
int  list_id,
  ... 
)

Returns the sm with the largest index (added last) from the list passed to us as an id.

Parameters
list_idid of the list to be searched
va_argslist of keyword types terminated by -1
Return values
sm_lastto last sm.

Definition at line 540 of file detect-parse.c.

References Signature_::init_data, and SignatureInitData_::smlists_tail.

Referenced by DetectEngineContentModifierBufferSetup().

Here is the caller graph for this function:

◆ DetectGetLastSMByListPtr()

SigMatch* DetectGetLastSMByListPtr ( const Signature s,
SigMatch sm_list,
  ... 
)

Returns the sm with the largest index (added last) from the list passed to us as a pointer.

Parameters
sm_listpointer to the SigMatch we should look before
va_argslist of keyword types terminated by -1
Return values
sm_lastto last sm.

Definition at line 508 of file detect-parse.c.

Referenced by DetectEngineContentModifierBufferSetup(), and DetectGetLastSMFromMpmLists().

Here is the caller graph for this function:

◆ DetectGetLastSMFromLists()

SigMatch* DetectGetLastSMFromLists ( const Signature s,
  ... 
)

Returns the sm with the largest index (added latest) from the lists passed to us.

Return values
Pointerto Last sm.

Definition at line 468 of file detect-parse.c.

References DETECT_SM_LIST_NOTSET, Signature_::init_data, SignatureInitData_::list, SignatureInitData_::smlists, and SignatureInitData_::smlists_array_size.

◆ DetectGetLastSMFromMpmLists()

SigMatch* DetectGetLastSMFromMpmLists ( const DetectEngineCtx de_ctx,
const Signature s 
)

get the last SigMatch from lists that support MPM.

Note
only supports the lists that are registered through DetectBufferTypeSupportsMpm().

Definition at line 429 of file detect-parse.c.

References de_ctx, DETECT_CONTENT, DETECT_SM_LIST_NOTSET, DetectBufferTypeSupportsMpmGetById(), DetectGetLastSMByListPtr(), Signature_::init_data, SignatureInitData_::list, SignatureInitData_::smlists_array_size, and SignatureInitData_::smlists_tail.

Here is the call graph for this function:

◆ DetectListToHumanString()

const char* DetectListToHumanString ( int  list)

Definition at line 114 of file detect-parse.c.

Referenced by RulesDumpMatchArray().

Here is the caller graph for this function:

◆ DetectListToString()

const char* DetectListToString ( int  list)

Definition at line 131 of file detect-parse.c.

◆ DetectParseDupSigHashFree()

void DetectParseDupSigHashFree ( DetectEngineCtx de_ctx)

Frees the hash table that is used to cull duplicate sigs.

Parameters
de_ctxPointer to the detection engine context that holds this table.

Definition at line 2147 of file detect-parse.c.

References de_ctx, DetectEngineCtx_::dup_sig_hash_table, and HashListTableFree().

Referenced by DetectEngineCtxFree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DetectParseDupSigHashInit()

int DetectParseDupSigHashInit ( DetectEngineCtx de_ctx)

Initializes the hash table that is used to cull duplicate sigs.

Parameters
de_ctxPointer to the detection engine context.
Return values
0On success.
-1On failure.

Definition at line 2130 of file detect-parse.c.

References de_ctx, DetectEngineCtx_::dup_sig_hash_table, and HashListTableInit().

Here is the call graph for this function:

◆ DetectParseFreeRegex()

void DetectParseFreeRegex ( DetectParseRegex r)

◆ DetectParseFreeRegexes()

void DetectParseFreeRegexes ( void  )

Definition at line 2390 of file detect-parse.c.

◆ DetectParsePcreExec()

int DetectParsePcreExec ( DetectParseRegex parse_regex,
const char *  str,
int  start_offset,
int  options,
int *  ovector,
int  ovector_size 
)

Definition at line 2372 of file detect-parse.c.

Referenced by DetectU32Parse().

Here is the caller graph for this function:

◆ DetectParsePcreExecLen()

int DetectParsePcreExecLen ( DetectParseRegex parse_regex,
const char *  str,
int  str_len,
int  start_offset,
int  options,
int *  ovector,
int  ovector_size 
)

Definition at line 2363 of file detect-parse.c.

◆ DetectParseRegexAddToFreeList()

void DetectParseRegexAddToFreeList ( DetectParseRegex parse_regex)

add regex and/or study to at exit free list

Definition at line 2406 of file detect-parse.c.

References FatalError, DetectParseRegex_::next, DetectParseRegex_::regex, SC_ERR_MEM_ALLOC, SCCalloc, and DetectParseRegex_::study.

Referenced by DetectSetupParseRegexesOpts().

Here is the caller graph for this function:

◆ DetectSetupParseRegexes()

void DetectSetupParseRegexes ( const char *  parse_str,
DetectParseRegex parse_regex 
)

Definition at line 2440 of file detect-parse.c.

References DetectSetupParseRegexesOpts().

Here is the call graph for this function:

◆ DetectSetupParseRegexesOpts()

void DetectSetupParseRegexesOpts ( const char *  parse_str,
DetectParseRegex parse_regex,
int  opts 
)

Definition at line 2418 of file detect-parse.c.

References DetectParseRegexAddToFreeList(), FatalError, DetectParseRegex_::regex, SC_ERR_PCRE_COMPILE, SC_ERR_PCRE_STUDY, and DetectParseRegex_::study.

Referenced by DetectSetupParseRegexes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DetectSignatureAddTransform()

◆ DetectSignatureSetAppProto()

int WARN_UNUSED DetectSignatureSetAppProto ( Signature s,
AppProto  alproto 
)

◆ SigAlloc()

◆ SigFree()

◆ SigInit()

Signature* SigInit ( DetectEngineCtx de_ctx,
const char *  sigstr 
)

Parses a signature and adds it to the Detection Engine Context.

Parameters
de_ctxPointer to the Detection Engine Context.
sigstrPointer to a character string containing the signature to be parsed.
Return values
Pointerto the Signature instance on success; NULL on failure.

Definition at line 2023 of file detect-parse.c.

References de_ctx, SCEnter, DetectEngineCtx_::sigerror_silent, and DetectEngineCtx_::signum.

Referenced by DetectEngineAppendSig().

Here is the caller graph for this function:

◆ SigInitReal()

Signature* SigInitReal ( DetectEngineCtx ,
const char *   
)

◆ SigMatchAppendSMToList()

void SigMatchAppendSMToList ( Signature s,
SigMatch new,
int  list 
)

Append a SigMatch to the list type.

Parameters
sSignature.
newThe sig match to append.
listThe list to append to.

Definition at line 349 of file detect-parse.c.

Referenced by DetectContentSetup(), and DetectFlowvarPostMatchSetup().

Here is the caller graph for this function:

◆ SigMatchList2DataArray()

SigMatchData* SigMatchList2DataArray ( SigMatch head)

convert SigMatch list to SigMatchData array

Note
ownership of sm->ctx is transfered to smd->ctx

Definition at line 1596 of file detect-parse.c.

References len.

Referenced by DetectEngineAppInspectionEngine2Signature().

Here is the caller graph for this function:

◆ SigMatchListSMBelongsTo()

int SigMatchListSMBelongsTo ( const Signature ,
const SigMatch  
)

Definition at line 622 of file detect-parse.c.

References Signature_::init_data, and SignatureInitData_::smlists_array_size.

Referenced by DetectEngineAppInspectionEngine2Signature(), DetectSetFastPatternAndItsId(), and RulesDumpMatchArray().

Here is the caller graph for this function:

◆ SigMatchRemoveSMFromList()

void SigMatchRemoveSMFromList ( Signature ,
SigMatch ,
int   
)

Definition at line 387 of file detect-parse.c.

References Signature_::init_data, SigMatch_::next, SigMatch_::prev, SignatureInitData_::smlists, and SignatureInitData_::smlists_tail.

Referenced by DetectIPProtoRemoveAllSMs().

Here is the caller graph for this function:

◆ SigMatchSilentErrorEnabled()

bool SigMatchSilentErrorEnabled ( const DetectEngineCtx de_ctx,
const enum DetectKeywordId  id 
)

Definition at line 292 of file detect-parse.c.

References de_ctx, and DetectEngineCtx_::sm_types_silent_error.

◆ SigMatchStrictEnabled()

bool SigMatchStrictEnabled ( const enum DetectKeywordId  id)

Definition at line 298 of file detect-parse.c.

References DETECT_TBLSIZE, flags, SIGMATCH_STRICT_PARSING, and sigmatch_table.

◆ SigParseRegisterTests()

void SigParseRegisterTests ( void  )

Definition at line 4096 of file detect-parse.c.

References DetectParseRegisterTests(), and UtRegisterTest().

Referenced by SigRegisterTests().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SigTableApplyStrictCommandlineOption()

void SigTableApplyStrictCommandlineOption ( const char *  str)