31static uint32_t PrefilterPacketHeaderHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
34 uint64_t hash =
ctx->v1.u64[0] +
ctx->v1.u64[1] +
ctx->type +
ctx->value;
36 return (uint32_t)hash;
39static char PrefilterPacketHeaderCompareFunc(
void *data1, uint16_t len1,
40 void *data2, uint16_t len2)
50static void PrefilterPacketHeaderFreeFunc(
void *ptr)
55static void PrefilterPacketHeaderFree(
void *pectx)
62static void PrefilterPacketU8HashCtxFree(
void *vctx)
66 for (i = 0; i < 256; i++) {
76static void GetExtraMatch(
const Signature *s, uint16_t *
type, uint16_t *value)
103 uint32_t sig_offset = 0;
113 ctx->sigs_cnt = hctx->
cnt;
115 if (
ctx->sigs_array == NULL) {
129 GetExtraMatch(s, &
type, &value);
134 SCLogDebug(
"appending sid %u on %u", s->
id, sig_offset);
135 ctx->sigs_array[sig_offset] = s->
iid;
142 SCLogDebug(
"%s: ctx %p extra type %u extra value %u, sig cnt %u",
164 uint8_t x = v.
u8[1] - 1;
188 }
while (++x < v.
u8[2]);
215 for (
int i = 0; i < 256; i++) {
221 ctx->array[i]->cnt = counts[i];
228 PrefilterPacketU8HashCtxFree(
ctx);
240 memset(&v, 0,
sizeof(v));
243 ApplyToU8Hash(
ctx, v, s);
253 PrefilterPacketU8HashCtxFree(
ctx);
269 SetupEngineForPacketHeader(
de_ctx, sgh, sm_type, mask,
ctx, Compare, Match);
281 uint32_t counts[256];
282 memset(&counts, 0,
sizeof(counts));
288 switch (
ctx->v1.u8[0]) {
290 counts[
ctx->v1.u8[1]] +=
ctx->cnt;
294 uint8_t v =
ctx->v1.u8[1];
297 counts[v] +=
ctx->cnt;
304 uint8_t v =
ctx->v1.u8[1];
305 while (v < UINT8_MAX) {
307 counts[v] +=
ctx->cnt;
314 if (
ctx->v1.u8[1] <
ctx->v1.u8[2]) {
316 uint8_t v =
ctx->v1.u8[1] + 1;
317 while (v < ctx->v1.u8[2]) {
318 counts[v] +=
ctx->cnt;
327 SetupEngineForPacketHeaderPrefilterPacketU8HashCtx(
328 de_ctx, sgh, sm_type, mask, counts, Set, Compare, Match);
345 PrefilterPacketHeaderHashFunc,
346 PrefilterPacketHeaderCompareFunc,
347 PrefilterPacketHeaderFreeFunc);
348 if (hash_table == NULL)
359 memset(&
ctx, 0,
sizeof(
ctx));
362 GetExtraMatch(s, &
ctx.type, &
ctx.value);
386 SetupSingle(
de_ctx, hash_table, sgh, sm_type, mask, Compare, Match);
388 SetupU8Hash(
de_ctx, hash_table, sgh, sm_type, mask, Set, Compare, Match);
403 return PrefilterSetupPacketHeaderCommon(
de_ctx, sgh, sm_type, mask, Set, Compare, Match,
true);
411 return PrefilterSetupPacketHeaderCommon(
de_ctx, sgh, sm_type, mask, Set, Compare, Match,
false);
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))
struct PrefilterPacketHeaderHashCtx_ PrefilterPacketHeaderHashCtx
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))
#define PREFILTER_EXTRA_MATCH_DSTPORT
#define PREFILTER_EXTRA_MATCH_SRCPORT
#define PREFILTER_EXTRA_MATCH_ALPROTO
#define PREFILTER_U8HASH_MODE_RA
#define PREFILTER_U8HASH_MODE_GT
#define PREFILTER_U8HASH_MODE_EQ
#define PREFILTER_U8HASH_MODE_LT
int PrefilterAppendEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterPktFn PrefilterFunc, SignatureMask mask, enum SignatureHookPkt hook, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
SigTableElmt * sigmatch_table
@ SIGNATURE_HOOK_PKT_NOT_SET
#define SIG_FLAG_PREFILTER
main detection engine ctx
struct DetectPort_ * next
Container for matching data for a signature group.
SigGroupHeadInitData * init
SignatureInitData * init_data
void * HashListTableLookup(HashListTable *ht, void *data, uint16_t datalen)
int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen)
HashListTableBucket * HashListTableGetListHead(HashListTable *ht)
HashListTable * HashListTableInit(uint32_t size, uint32_t(*Hash)(struct HashListTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
void HashListTableFree(HashListTable *ht)
#define HashListTableGetListData(hb)
#define HashListTableGetListNext(hb)