suricata
detect-parse.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2020 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/**
19 * \file
20 *
21 * \author Victor Julien <victor@inliniac.net>
22 */
23
24#ifndef SURICATA_DETECT_PARSE_H
25#define SURICATA_DETECT_PARSE_H
26
27#include "app-layer-protos.h"
29// types from detect.h with only forward declarations for bindgen
31typedef struct Signature_ Signature;
33typedef struct SigMatch_ SigMatch;
35
36/** Flags to indicate if the Signature parsing must be done
37* switching the source and dest (for ip addresses and ports)
38* or otherwise as normal */
39enum {
42};
43
44/** Flags to indicate if are referencing the source of the Signature
45* or the destination (for ip addresses and ports)*/
46enum {
49};
50
51/* prototypes */
53Signature *SigAlloc(void);
55Signature *SigInit(DetectEngineCtx *, const char *sigstr);
57void SigParseRegisterTests(void);
60
63int SigMatchListSMBelongsTo(const Signature *, const SigMatch *);
64
67
69 Signature *s, const char *arg, int sm_type, int sm_list,
70 AppProto alproto);
71
73 const enum DetectKeywordId id);
74bool SigMatchStrictEnabled(const enum DetectKeywordId id);
75
76const char *DetectListToHumanString(int list);
77const char *DetectListToString(int list);
78
80
84SigMatch *DetectGetLastSMByListPtr(const Signature *s, SigMatch *sm_list, ...);
85SigMatch *DetectGetLastSMByListId(const Signature *s, int list_id, ...);
86
89
90/* parse regex setup and free util funcs */
91
92#ifndef SURICATA_BINDGEN_H
93typedef struct DetectParseRegex {
94 pcre2_code *regex;
95 pcre2_match_context *context;
98
99DetectParseRegex *DetectSetupPCRE2(const char *parse_str, int opts);
100bool DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *parse_regex, int opts);
101void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *parse_regex);
103void DetectParseFreeRegexes(void);
105
106/* parse regex exec */
107int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str,
108 int start_offset, int options);
110 pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen);
111int SC_Pcre2SubstringGet(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr,
112 PCRE2_SIZE *bufflen);
113#endif
114
116
117#endif /* SURICATA_DETECT_PARSE_H */
uint16_t AppProto
#define WARN_UNUSED
Definition bindgen.h:32
int SignatureInitDataBufferCheckExpand(Signature *s)
check if buffers array still has space left, expand if not
SigMatch * DetectGetLastSMFromMpmLists(const DetectEngineCtx *de_ctx, const Signature *s)
get the last SigMatch from lists that support MPM.
void DetectRegisterAppLayerHookLists(void)
register app hooks as generic lists
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.
@ SIG_DIREC_DST
@ SIG_DIREC_SRC
bool SigMatchStrictEnabled(const enum DetectKeywordId id)
DetectParseRegex * DetectSetupPCRE2(const char *parse_str, int opts)
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.
void DetectParseFreeRegex(DetectParseRegex *r)
int SC_Pcre2SubstringGet(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen)
void DetectParseFreeRegexes(void)
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *, Signature *, uint16_t, SigMatchCtx *, int)
Append a SigMatch to the list type.
Signature * DetectFirewallRuleAppendNew(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
int WARN_UNUSED SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
SigMatchData * SigMatchList2DataArray(SigMatch *head)
convert SigMatch list to SigMatchData array
const char * DetectListToHumanString(int list)
const char * DetectListToString(int list)
void SigTableApplyStrictCommandLineOption(const char *str)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
int SigMatchListSMBelongsTo(const Signature *, const SigMatch *)
int WARN_UNUSED DetectSignatureSetMultiAppProto(Signature *s, const AppProto *alprotos)
this function is used to set multiple possible app-layer protos
int DetectParseDupSigHashInit(DetectEngineCtx *)
Initializes the hash table that is used to cull duplicate sigs.
void SigFree(DetectEngineCtx *de_ctx, Signature *s)
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *parse_regex)
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
void DetectParseDupSigHashFree(DetectEngineCtx *)
Frees the hash table that is used to cull duplicate sigs.
void SigMatchRemoveSMFromList(Signature *, SigMatch *, int)
void SigParseRegisterTests(void)
int SC_Pcre2SubstringCopy(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
@ SIG_DIREC_SWITCHED
@ SIG_DIREC_NORMAL
SigMatch * DetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
Signature * SigAlloc(void)
bool DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *parse_regex, int opts)
Signature * SigInit(DetectEngineCtx *, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
bool SigMatchSilentErrorEnabled(const DetectEngineCtx *de_ctx, const enum DetectKeywordId id)
void DetectParseRegexAddToFreeList(DetectParseRegex *parse_regex)
add regex and/or study to at exit free list
SigMatch * DetectGetLastSM(const Signature *)
Returns the sm with the largest index (added latest) from this sig.
Flow * head
Definition flow-hash.h:1
DetectEngineCtx * de_ctx
main detection engine ctx
Definition detect.h:932
struct DetectParseRegex * next
pcre2_match_context * context
pcre2_code * regex
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition detect.h:351
Data needed for Match()
Definition detect.h:365
a single match condition for a signature
Definition detect.h:356
Signature container.
Definition detect.h:668
#define str(s)