suricata
detect-engine-prefilter-common.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2016 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18#ifndef SURICATA_DETECT_ENGINE_PREFILTER_COMMON_H
19#define SURICATA_DETECT_ENGINE_PREFILTER_COMMON_H
20
21#include "rust.h"
22
23typedef union {
24 uint8_t u8[16];
25 uint16_t u16[8];
26 uint32_t u32[4];
27 uint64_t u64[2];
29
30#define PREFILTER_EXTRA_MATCH_UNUSED 0
31#define PREFILTER_EXTRA_MATCH_ALPROTO 1
32#define PREFILTER_EXTRA_MATCH_SRCPORT 2
33#define PREFILTER_EXTRA_MATCH_DSTPORT 3
34
37
38 uint16_t type;
39 uint16_t value;
40
41 /** rules to add when the flags are present */
42 uint32_t sigs_cnt;
45
46typedef struct SigsArray_ {
48 uint32_t cnt;
49 uint32_t offset; // used to track assign pos
51
55
56#define PREFILTER_U8HASH_MODE_EQ DetectUintModeEqual
57#define PREFILTER_U8HASH_MODE_LT DetectUintModeLt
58#define PREFILTER_U8HASH_MODE_GT DetectUintModeGt
59#define PREFILTER_U8HASH_MODE_RA DetectUintModeRange
60
62 SignatureMask mask, void (*Set)(PrefilterPacketHeaderValue *v, void *),
63 bool (*Compare)(PrefilterPacketHeaderValue v, void *),
64 void (*Match)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx));
65
67 SignatureMask mask, void (*Set)(PrefilterPacketHeaderValue *v, void *),
68 bool (*Compare)(PrefilterPacketHeaderValue v, void *),
69 void (*Match)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx));
70
71static inline bool
72PrefilterPacketHeaderExtraMatch(const PrefilterPacketHeaderCtx *ctx,
73 const Packet *p)
74{
75 switch (ctx->type)
76 {
78 break;
80 if (p->flow == NULL || !AppProtoEquals(ctx->value, p->flow->alproto))
81 return false;
82 break;
84 if (p->sp != ctx->value)
85 return false;
86 break;
88 if (p->dp != ctx->value)
89 return false;
90 break;
91 }
92 return true;
93}
94
95static inline bool PrefilterIsPrefilterableById(const Signature *s, enum DetectKeywordId kid)
96{
97 const SigMatch *sm;
98 for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
99 if (sm->type == kid) {
100 return true;
101 }
102 }
103 return false;
104}
105
106#endif /* SURICATA_DETECT_ENGINE_PREFILTER_COMMON_H */
#define SignatureMask
Definition decode.h:99
struct PrefilterPacketU8HashCtx_ PrefilterPacketU8HashCtx
#define PREFILTER_EXTRA_MATCH_DSTPORT
struct PrefilterPacketHeaderCtx_ PrefilterPacketHeaderCtx
#define PREFILTER_EXTRA_MATCH_SRCPORT
#define PREFILTER_EXTRA_MATCH_ALPROTO
#define PREFILTER_EXTRA_MATCH_UNUSED
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 SigsArray_ SigsArray
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))
@ DETECT_SM_LIST_MATCH
Definition detect.h:117
DetectEngineCtx * de_ctx
struct Thresholds ctx
main detection engine ctx
Definition detect.h:932
AppProto alproto
application level protocol
Definition flow.h:450
Port sp
Definition decode.h:508
struct Flow_ * flow
Definition decode.h:546
Port dp
Definition decode.h:516
Container for matching data for a signature group.
Definition detect.h:1629
a single match condition for a signature
Definition detect.h:356
uint16_t type
Definition detect.h:357
struct SigMatch_ * next
Definition detect.h:360
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition detect.h:642
Signature container.
Definition detect.h:668
SignatureInitData * init_data
Definition detect.h:747
#define SigIntId