31 static 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;
39 static char PrefilterPacketHeaderCompareFunc(
void *data1, uint16_t len1,
40 void *data2, uint16_t len2)
50 static void PrefilterPacketHeaderFreeFunc(
void *ptr)
55 static void PrefilterPacketHeaderFree(
void *pectx)
62 static void PrefilterPacketU8HashCtxFree(
void *vctx)
66 for (i = 0; i < 256; i++) {
76 static 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;
172 case DetectUintModeLte: {
191 case DetectUintModeGte: {
206 }
while (++x < v.
u8[2]);
210 case DetectUintModeNe: {
211 for (uint8_t i = 0; i < UINT8_MAX; i++) {
217 if (UINT8_MAX != v.
u8[1]) {
246 for (
int i = 0; i < 256; i++) {
252 ctx->array[i]->cnt = counts[i];
259 PrefilterPacketU8HashCtxFree(
ctx);
271 memset(&v, 0,
sizeof(v));
274 ApplyToU8Hash(
ctx, v, s);
284 PrefilterPacketU8HashCtxFree(
ctx);
300 SetupEngineForPacketHeader(
de_ctx, sgh, sm_type, mask,
ctx, Compare, Match);
312 uint32_t counts[256];
313 memset(&counts, 0,
sizeof(counts));
319 switch (
ctx->v1.u8[0]) {
321 counts[
ctx->v1.u8[1]] +=
ctx->cnt;
325 uint8_t v =
ctx->v1.u8[1];
328 counts[v] +=
ctx->cnt;
333 case DetectUintModeLte: {
334 uint8_t v =
ctx->v1.u8[1];
335 counts[v] +=
ctx->cnt;
338 counts[v] +=
ctx->cnt;
345 uint8_t v =
ctx->v1.u8[1];
346 while (v < UINT8_MAX) {
348 counts[v] +=
ctx->cnt;
353 case DetectUintModeGte: {
354 uint8_t v =
ctx->v1.u8[1];
355 counts[v] +=
ctx->cnt;
356 while (v < UINT8_MAX) {
358 counts[v] +=
ctx->cnt;
365 if (
ctx->v1.u8[1] <
ctx->v1.u8[2]) {
367 uint8_t v =
ctx->v1.u8[1] + 1;
368 while (v < ctx->v1.u8[2]) {
369 counts[v] +=
ctx->cnt;
375 case DetectUintModeNe: {
376 for (uint8_t i = 0; i < UINT8_MAX; i++) {
377 if (i !=
ctx->v1.u8[1]) {
378 counts[i] +=
ctx->cnt;
381 if (UINT8_MAX !=
ctx->v1.u8[1]) {
382 counts[UINT8_MAX] +=
ctx->cnt;
387 SCLogWarning(
"Prefilter not implemented for mode 0x%x",
ctx->v1.u8[0]);
391 SetupEngineForPacketHeaderPrefilterPacketU8HashCtx(
392 de_ctx, sgh, sm_type, mask, counts, Set, Compare, Match);
409 PrefilterPacketHeaderHashFunc,
410 PrefilterPacketHeaderCompareFunc,
411 PrefilterPacketHeaderFreeFunc);
412 if (hash_table == NULL)
423 memset(&
ctx, 0,
sizeof(
ctx));
426 GetExtraMatch(s, &
ctx.type, &
ctx.value);
450 SetupSingle(
de_ctx, hash_table, sgh, sm_type, mask, Compare, Match);
452 SetupU8Hash(
de_ctx, hash_table, sgh, sm_type, mask, Set, Compare, Match);
467 return PrefilterSetupPacketHeaderCommon(
de_ctx, sgh, sm_type, mask, Set, Compare, Match,
true);
475 return PrefilterSetupPacketHeaderCommon(
de_ctx, sgh, sm_type, mask, Set, Compare, Match,
false);