Go to the documentation of this file.
41 #define PARSE_REGEX "^\\s*(\"\\s*)?([0-9]+)(\\s*\")?\\s*$"
49 static void DetectIcmpSeqRegisterTests(
void);
53 static bool PrefilterIcmpSeqIsPrefilterable(
const Signature *s);
75 static inline bool GetIcmpSeq(
Packet *p, uint16_t *
seq)
79 if (PacketIsICMPv4(p)) {
89 SCLogDebug(
"ICMPV4_GET_SEQ(p) %"PRIu16
" (network byte order), "
99 }
else if (PacketIsICMPv6(p)) {
103 SCLogDebug(
"ICMPV6_GET_SEQ(p) %"PRIu16
" (network byte order), "
139 if (!GetIcmpSeq(p, &seqn))
143 if (seqn == iseq->
seq)
161 char *substr[3] = {NULL, NULL, NULL};
167 pcre2_match_data *match = NULL;
169 if (ret < 1 || ret > 4) {
174 for (i = 1; i < ret; i++) {
177 SCLogError(
"pcre2_substring_get_bynumber failed");
180 substr[i-1] = (
char *)str_ptr;
189 if (substr[0] != NULL && strlen(substr[0]) != 0) {
190 if (substr[2] == NULL) {
195 if (substr[2] != NULL) {
210 for (i = 0; i < 3; i++) {
211 if (substr[i] != NULL)
212 pcre2_substring_free((PCRE2_UCHAR8 *)substr[i]);
215 pcre2_match_data_free(match);
220 pcre2_match_data_free(match);
222 for (i = 0; i < 3; i++) {
223 if (substr[i] != NULL)
224 pcre2_substring_free((PCRE2_UCHAR8 *)substr[i]);
245 iseq = DetectIcmpSeqParse(
de_ctx, icmpseqstr);
246 if (iseq == NULL)
goto error;
284 if (!GetIcmpSeq(p, &seqn))
287 if (seqn ==
ctx->v1.u16[0])
290 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
313 PrefilterPacketIcmpSeqSet, PrefilterPacketIcmpSeqCompare, PrefilterPacketIcmpSeqMatch);
316 static bool PrefilterIcmpSeqIsPrefilterable(
const Signature *s)
336 static int DetectIcmpSeqParseTest01 (
void)
339 iseq = DetectIcmpSeqParse(NULL,
"300");
350 static int DetectIcmpSeqParseTest02 (
void)
353 iseq = DetectIcmpSeqParse(NULL,
" 300 ");
363 static int DetectIcmpSeqParseTest03 (
void)
370 static void DetectIcmpSeqRegisterTests (
void)
372 UtRegisterTest(
"DetectIcmpSeqParseTest01", DetectIcmpSeqParseTest01);
373 UtRegisterTest(
"DetectIcmpSeqParseTest02", DetectIcmpSeqParseTest02);
374 UtRegisterTest(
"DetectIcmpSeqParseTest03", DetectIcmpSeqParseTest03);
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
#define SIG_MASK_REQUIRE_REAL_PKT
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
#define ICMP_INFO_REQUEST
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Container for matching data for a signature group.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define ICMPV6_GET_SEQ(p)
main detection engine ctx
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
struct Packet_::@29::@36 icmp_s
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define ICMP6_ECHO_REQUEST
#define ICMPV4_GET_SEQ(p)
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
#define ICMP_ADDRESSREPLY
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
#define PASS
Pass the test.
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
void DetectIcmpSeqRegister(void)
Registration function for icmp_seq.
int SC_Pcre2SubstringGet(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen)
SignatureInitData * init_data
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))
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
#define SCLogError(...)
Macro used to log ERROR messages.
bool(* SupportsPrefilter)(const Signature *s)
a single match condition for a signature
#define ICMP_TIMESTAMPREPLY
#define ICMPV6_GET_TYPE(icmp6h)
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
#define DEBUG_VALIDATE_BUG_ON(exp)
void DetectIcmpSeqFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectIcmpSeqData
void(* RegisterTests)(void)
#define SIG_FLAG_REQUIRE_PACKET