Go to the documentation of this file.
42 #define PARSE_REGEX "^\\s*(?:(<|>))?\\s*([0-9]+)"
55 static bool PrefilterFragOffsetIsPrefilterable(
const Signature *s);
77 static inline int FragOffsetMatch(
const uint16_t poffset,
const uint8_t mode,
78 const uint16_t doffset)
82 if (poffset < doffset)
86 if (poffset > doffset)
90 if (poffset == doffset)
116 if (PacketIsIPv4(p)) {
117 const IPV4Hdr *ip4h = PacketGetIPv4(p);
119 }
else if (PacketIsIPv6(p)) {
130 return FragOffsetMatch(frag, fragoff->
mode, fragoff->
frag_off);
145 char *substr[3] = {NULL, NULL, NULL};
151 pcre2_match_data *match = NULL;
154 if (ret < 1 || ret > 4) {
159 for (i = 1; i < ret; i++) {
162 SCLogError(
"pcre2_substring_get_bynumber failed");
165 substr[i-1] = (
char *)str_ptr;
179 while(*mode !=
'\0') {
199 for (i = 0; i < 3; i++) {
200 if (substr[i] != NULL)
201 pcre2_substring_free((PCRE2_UCHAR8 *)substr[i]);
204 pcre2_match_data_free(match);
209 pcre2_match_data_free(match);
211 for (i = 0; i < 3; i++) {
212 if (substr[i] != NULL)
213 pcre2_substring_free((PCRE2_UCHAR8 *)substr[i]);
234 fragoff = DetectFragOffsetParse(
de_ctx, fragoffsetstr);
235 if (fragoff == NULL)
goto error;
270 if (PacketIsIPv4(p)) {
271 const IPV4Hdr *ip4h = PacketGetIPv4(p);
273 }
else if (PacketIsIPv6(p)) {
285 if (FragOffsetMatch(frag,
ctx->v1.u8[0],
ctx->v1.u16[1]))
287 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
303 if (v.
u8[0] == fb->
mode &&
314 PrefilterPacketFragOffsetSet, PrefilterPacketFragOffsetCompare,
315 PrefilterPacketFragOffsetMatch);
318 static bool PrefilterFragOffsetIsPrefilterable(
const Signature *s)
338 static int DetectFragOffsetParseTest01 (
void)
354 static int DetectFragOffsetParseTest02 (
void)
370 static int DetectFragOffsetParseTest03 (
void)
384 static int DetectFragOffsetMatchTest01 (
void)
395 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
403 p->
src.addr_data32[0] = 0x01020304;
404 p->
dst.addr_data32[0] = 0x04030201;
406 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
407 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
441 UtRegisterTest(
"DetectFragOffsetParseTest01", DetectFragOffsetParseTest01);
442 UtRegisterTest(
"DetectFragOffsetParseTest02", DetectFragOffsetParseTest02);
443 UtRegisterTest(
"DetectFragOffsetParseTest03", DetectFragOffsetParseTest03);
444 UtRegisterTest(
"DetectFragOffsetMatchTest01", DetectFragOffsetMatchTest01);
#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]
void DetectFragOffsetRegisterTests(void)
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
#define IPV6_EXTHDR_GET_FH_OFFSET(p)
#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 IPV6_EXTHDR_ISSET_FH(p)
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
void UTHSetIPV4Hdr(Packet *p, IPV4Hdr *ip4h)
void DetectFragOffsetRegister(void)
Registration function for fragoffset.
main detection engine ctx
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
void FlowInitConfig(bool quiet)
initialize the configuration
void DetectFragOffsetFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectFragOffsetData
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
#define PASS
Pass the test.
#define IPV4_GET_RAW_FRAGOFFSET(ip4h)
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Per thread variable structure.
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
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 *)
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
void FlowShutdown(void)
shutdown the flow engine
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
#define SCLogError(...)
Macro used to log ERROR messages.
Structure to hold thread specific data for all decode modules.
bool(* SupportsPrefilter)(const Signature *s)
a single match condition for a signature
DetectEngineCtx * DetectEngineCtxInit(void)
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(* RegisterTests)(void)
#define SIG_FLAG_REQUIRE_PACKET