@ -93,9 +93,8 @@ static void GetExtraMatch(const Signature *s, uint16_t *type, uint16_t *value)
/** \internal
*/
static int
SetupEngineForPacketHeader ( DetectEngineCtx * de_ctx , SigGroupHead * sgh ,
int sm_type , PrefilterPacketHeaderHashCtx * hctx ,
static int SetupEngineForPacketHeader ( DetectEngineCtx * de_ctx , SigGroupHead * sgh , int sm_type ,
SignatureMask mask , PrefilterPacketHeaderHashCtx * hctx ,
bool ( * Compare ) ( PrefilterPacketHeaderValue v , void * ) ,
void ( * Match ) ( DetectEngineThreadCtx * det_ctx , Packet * p , const void * pectx ) )
{
@ -143,8 +142,8 @@ SetupEngineForPacketHeader(DetectEngineCtx *de_ctx, SigGroupHead *sgh,
SCLogDebug ( " %s: ctx %p extra type %u extra value %u, sig cnt %u " ,
sigmatch_table [ sm_type ] . name , ctx , ctx - > type , ctx - > value ,
ctx - > sigs_cnt ) ;
PrefilterAppendEngine ( de_ctx , sgh , Match , ctx ,
PrefilterPacketHeaderFree, sigmatch_table [ sm_type ] . name ) ;
PrefilterAppendEngine (
de_ctx, sgh , Match , mask , ctx , PrefilterPacketHeaderFree, sigmatch_table [ sm_type ] . name ) ;
return 0 ;
}
@ -197,9 +196,8 @@ static void ApplyToU8Hash(PrefilterPacketU8HashCtx *ctx, PrefilterPacketHeaderVa
* \ todo improve error handling
* \ todo deduplicate sigs arrays
*/
static int
SetupEngineForPacketHeaderPrefilterPacketU8HashCtx ( DetectEngineCtx * de_ctx ,
SigGroupHead * sgh , int sm_type , uint32_t * counts ,
static int SetupEngineForPacketHeaderPrefilterPacketU8HashCtx ( DetectEngineCtx * de_ctx ,
SigGroupHead * sgh , int sm_type , SignatureMask mask , uint32_t * counts ,
void ( * Set ) ( PrefilterPacketHeaderValue * v , void * ) ,
bool ( * Compare ) ( PrefilterPacketHeaderValue v , void * ) ,
void ( * Match ) ( DetectEngineThreadCtx * det_ctx , Packet * p , const void * pectx ) )
@ -247,8 +245,7 @@ SetupEngineForPacketHeaderPrefilterPacketU8HashCtx(DetectEngineCtx *de_ctx,
}
if ( cnt ) {
PrefilterAppendEngine ( de_ctx , sgh , Match , ctx ,
PrefilterPacketU8HashCtxFree ,
PrefilterAppendEngine ( de_ctx , sgh , Match , mask , ctx , PrefilterPacketU8HashCtxFree ,
sigmatch_table [ sm_type ] . name ) ;
} else {
PrefilterPacketU8HashCtxFree ( ctx ) ;
@ -259,30 +256,25 @@ SetupEngineForPacketHeaderPrefilterPacketU8HashCtx(DetectEngineCtx *de_ctx,
/** \internal
* \ brief setup a engine for each unique value
*/
static void SetupSingle ( DetectEngineCtx * de_ctx , HashListTable * hash_table ,
SigGroupHead * sgh , int sm_type ,
bool ( * Compare ) ( PrefilterPacketHeaderValue v , void * ) ,
void ( * Match ) ( DetectEngineThreadCtx * det_ctx ,
Packet * p , const void * pectx ) )
static void SetupSingle ( DetectEngineCtx * de_ctx , HashListTable * hash_table , SigGroupHead * sgh ,
int sm_type , SignatureMask mask , bool ( * Compare ) ( PrefilterPacketHeaderValue v , void * ) ,
void ( * Match ) ( DetectEngineThreadCtx * det_ctx , Packet * p , const void * pectx ) )
{
HashListTableBucket * hb = HashListTableGetListHead ( hash_table ) ;
for ( ; hb ! = NULL ; hb = HashListTableGetListNext ( hb ) ) {
PrefilterPacketHeaderHashCtx * ctx = HashListTableGetListData ( hb ) ;
SetupEngineForPacketHeader ( de_ctx , sgh , sm_type ,
ctx , Compare , Match ) ;
SetupEngineForPacketHeader ( de_ctx , sgh , sm_type , mask , ctx , Compare , Match ) ;
}
}
/** \internal
* \ brief setup a single engine with a hash map for u8 values
*/
static void SetupU8Hash ( DetectEngineCtx * de_ctx , HashListTable * hash_table ,
SigGroupHead * sgh , int sm_type ,
void ( * Set ) ( PrefilterPacketHeaderValue * v , void * ) ,
static void SetupU8Hash ( DetectEngineCtx * de_ctx , HashListTable * hash_table , SigGroupHead * sgh ,
int sm_type , SignatureMask mask , void ( * Set ) ( PrefilterPacketHeaderValue * v , void * ) ,
bool ( * Compare ) ( PrefilterPacketHeaderValue v , void * ) ,
void ( * Match ) ( DetectEngineThreadCtx * det_ctx ,
Packet * p , const void * pectx ) )
void ( * Match ) ( DetectEngineThreadCtx * det_ctx , Packet * p , const void * pectx ) )
{
uint32_t counts [ 256 ] ;
memset ( & counts , 0 , sizeof ( counts ) ) ;
@ -330,17 +322,14 @@ static void SetupU8Hash(DetectEngineCtx *de_ctx, HashListTable *hash_table,
}
}
SetupEngineForPacketHeaderPrefilterPacketU8HashCtx ( de_ctx , sgh , sm_type ,
counts, Set , Compare , Match ) ;
SetupEngineForPacketHeaderPrefilterPacketU8HashCtx (
de_ctx, sgh , sm_type , mask , counts, Set , Compare , Match ) ;
}
static int PrefilterSetupPacketHeaderCommon ( DetectEngineCtx * de_ctx ,
SigGroupHead * sgh , int sm_type ,
void ( * Set ) ( PrefilterPacketHeaderValue * v , void * ) ,
static int PrefilterSetupPacketHeaderCommon ( DetectEngineCtx * de_ctx , SigGroupHead * sgh , int sm_type ,
SignatureMask mask , void ( * Set ) ( PrefilterPacketHeaderValue * v , void * ) ,
bool ( * Compare ) ( PrefilterPacketHeaderValue v , void * ) ,
void ( * Match ) ( DetectEngineThreadCtx * det_ctx ,
Packet * p , const void * pectx ) ,
bool u8hash )
void ( * Match ) ( DetectEngineThreadCtx * det_ctx , Packet * p , const void * pectx ) , bool u8hash )
{
Signature * s = NULL ;
uint32_t sig = 0 ;
@ -392,9 +381,9 @@ static int PrefilterSetupPacketHeaderCommon(DetectEngineCtx *de_ctx,
}
if ( ! u8hash ) {
SetupSingle ( de_ctx , hash_table , sgh , sm_type , Compare, Match ) ;
SetupSingle ( de_ctx , hash_table , sgh , sm_type , mask, Compare, Match ) ;
} else {
SetupU8Hash ( de_ctx , hash_table , sgh , sm_type , Set, Compare , Match ) ;
SetupU8Hash ( de_ctx , hash_table , sgh , sm_type , mask, Set, Compare , Match ) ;
}
HashListTableFree ( hash_table ) ;
@ -404,22 +393,18 @@ error:
return - 1 ;
}
int PrefilterSetupPacketHeaderU8Hash ( DetectEngineCtx * de_ctx ,
SigGroupHead * sgh , int sm_type ,
void ( * Set ) ( PrefilterPacketHeaderValue * v , void * ) ,
int PrefilterSetupPacketHeaderU8Hash ( DetectEngineCtx * de_ctx , SigGroupHead * sgh , int sm_type ,
SignatureMask mask , void ( * Set ) ( PrefilterPacketHeaderValue * v , void * ) ,
bool ( * Compare ) ( PrefilterPacketHeaderValue v , void * ) ,
void ( * Match ) ( DetectEngineThreadCtx * det_ctx ,
Packet * p , const void * pectx ) )
void ( * Match ) ( DetectEngineThreadCtx * det_ctx , Packet * p , const void * pectx ) )
{
return PrefilterSetupPacketHeaderCommon ( de_ctx , sgh , sm_type , Set, Compare , Match , true ) ;
return PrefilterSetupPacketHeaderCommon ( de_ctx , sgh , sm_type , mask, Set, Compare , Match , true ) ;
}
int PrefilterSetupPacketHeader ( DetectEngineCtx * de_ctx ,
SigGroupHead * sgh , int sm_type ,
void ( * Set ) ( PrefilterPacketHeaderValue * v , void * ) ,
int PrefilterSetupPacketHeader ( DetectEngineCtx * de_ctx , SigGroupHead * sgh , int sm_type ,
SignatureMask mask , void ( * Set ) ( PrefilterPacketHeaderValue * v , void * ) ,
bool ( * Compare ) ( PrefilterPacketHeaderValue v , void * ) ,
void ( * Match ) ( DetectEngineThreadCtx * det_ctx ,
Packet * p , const void * pectx ) )
void ( * Match ) ( DetectEngineThreadCtx * det_ctx , Packet * p , const void * pectx ) )
{
return PrefilterSetupPacketHeaderCommon ( de_ctx , sgh , sm_type , Set, Compare , Match , false ) ;
return PrefilterSetupPacketHeaderCommon ( de_ctx , sgh , sm_type , mask, Set, Compare , Match , false ) ;
}