Go to the documentation of this file.
47 #define PARSE_REGEX "^\\s*([0-9]{1,5}|\"[0-9]{1,5}\")\\s*$"
55 static void DetectIdRegisterTests(
void);
60 static bool PrefilterIdIsPrefilterable(
const Signature *s);
102 if (!PacketIsIPv4(p)) {
106 const IPV4Hdr *ip4h = PacketGetIPv4(p);
108 SCLogDebug(
"IPV4 Proto and matched with ip_id: %u.\n",
130 pcre2_match_data *match = NULL;
134 if (ret < 1 || ret > 3) {
135 SCLogError(
"invalid id option '%s'. The id option "
136 "value must be in the range %u - %u",
141 char copy_str[128] =
"";
143 pcre2len =
sizeof(copy_str);
144 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)copy_str, &pcre2len);
146 SCLogError(
"pcre2_substring_copy_bynumber failed");
152 if (tmp_str[0] ==
'"')
154 tmp_str[strlen(tmp_str) - 1] =
'\0';
160 SCLogError(
"invalid id option '%s'", tmp_str);
171 SCLogDebug(
"detect-id: will look for ip_id: %u\n", id_d->
id);
172 pcre2_match_data_free(match);
177 pcre2_match_data_free(match);
197 id_d = DetectIdParse(idstr);
232 if (!PacketIsIPv4(p)) {
236 if (!PrefilterPacketHeaderExtraMatch(
ctx, p))
239 const IPV4Hdr *ip4h = PacketGetIPv4(p);
242 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
257 if (v.
u16[0] == a->
id)
265 PrefilterPacketIdSet, PrefilterPacketIdCompare, PrefilterPacketIdMatch);
268 static bool PrefilterIdIsPrefilterable(
const Signature *s)
286 static int DetectIdTestParse01 (
void)
303 static int DetectIdTestParse02 (
void)
317 static int DetectIdTestParse03 (
void)
330 static int DetectIdTestParse04 (
void)
347 static int DetectIdTestMatch01(
void)
349 uint8_t *buf = (uint8_t *)
"Hi all!";
350 uint16_t buflen = strlen((
char *)buf);
370 sigs[0]=
"alert ip any any -> any any (msg:\"Testing id 1\"; id:1234; sid:1;)";
371 sigs[1]=
"alert ip any any -> any any (msg:\"Testing id 2\"; id:5678; sid:2;)";
372 sigs[2]=
"alert ip any any -> any any (msg:\"Testing id 3\"; id:5101; sid:3;)";
374 uint32_t sid[3] = {1, 2, 3};
376 uint32_t results[3][3] = {
394 void DetectIdRegisterTests(
void)
#define IPV4_GET_RAW_IPID(ip4h)
#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]
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.
main detection engine ctx
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
#define PARSE_REGEX
Regex for parsing "id" option, matching number or "number".
union PacketL3::Hdrs hdrs
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
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.
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
#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 DetectIdRegister(void)
Registration function for keyword: id.
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...
int UTHGenericTest(Packet **pkt, int numpkts, const char *sigs[], uint32_t sids[], uint32_t *results, int numsigs)
UTHGenericTest: function that perform a generic check taking care of as maximum common unittest eleme...
#define SCLogError(...)
Macro used to log ERROR messages.
bool(* SupportsPrefilter)(const Signature *s)
a single match condition for a signature
void DetectIdFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectIdData
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
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.