Go to the documentation of this file.
54 #define PARSE_REGEX "^\\s*(host|session)\\s*(,\\s*(\\d+)\\s*,\\s*(packets|bytes|seconds)\\s*(,\\s*(src|dst))?\\s*)?$"
62 static void DetectTagRegisterTests(
void);
117 SCLogDebug(
"Tagging Host with sid %"PRIu32
":%"PRIu32
"", s->
id, s->
gid);
121 if (p->
flow != NULL) {
130 SCLogDebug(
"Adding to or updating flow; first_ts %u count %u",
134 SCLogDebug(
"No flow to append the session tag");
139 SCLogDebug(
"unknown type of a tag keyword (not session nor host)");
160 const char *str_ptr = NULL;
162 pcre2_match_data *match = NULL;
165 SCLogError(
"parse error, ret %" PRId32
", string %s", ret, tagstr);
169 int res = pcre2_substring_get_bynumber(match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
170 if (res < 0 || str_ptr == NULL) {
171 SCLogError(
"pcre2_substring_get_bynumber failed");
176 if (strcasecmp(
"session", str_ptr) == 0) {
178 }
else if (strcasecmp(
"host", str_ptr) == 0) {
181 SCLogError(
"Invalid argument type. Must be session or host (%s)", tagstr);
184 pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
193 res = pcre2_substring_get_bynumber(match, 3, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
194 if (res < 0 || str_ptr == NULL) {
195 SCLogError(
"pcre2_substring_get_bynumber failed");
202 SCLogError(
"Invalid argument for count. Must be a value in the range of 0 to %" PRIu32
208 pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
211 res = pcre2_substring_get_bynumber(match, 4, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
212 if (res < 0 || str_ptr == NULL) {
213 SCLogError(
"pcre2_substring_get_bynumber failed");
218 if (strcasecmp(
"packets", str_ptr) == 0) {
223 }
else if (strcasecmp(
"seconds", str_ptr) == 0) {
225 }
else if (strcasecmp(
"bytes", str_ptr) == 0) {
229 "Invalid argument metric. Must be one of \"seconds\", \"packets\" or \"bytes\" "
235 pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
240 res = pcre2_substring_get_bynumber(match, 6, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
241 if (res < 0 || str_ptr == NULL) {
242 SCLogError(
"pcre2_substring_get_bynumber failed");
247 if (strcasecmp(
"src", str_ptr) == 0) {
249 }
else if (strcasecmp(
"dst", str_ptr) == 0) {
253 "Invalid argument direction. Must be one of \"src\" or \"dst\" (only valid "
254 "for tag host type, not sessions) (%s)",
261 "Argument direction doesn't make sense for type \"session\" (%s [%" PRIu8
266 pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
278 pcre2_match_data_free(match);
283 pcre2_match_data_free(match);
286 pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
321 static void DetectTagDataEntryFree(
void *ptr)
341 while (entry != NULL) {
343 DetectTagDataEntryFree(entry);
367 static int DetectTagTestParse01(
void)
371 td = DetectTagParse(
"session, 123, packets");
385 static int DetectTagTestParse02(
void)
389 td = DetectTagParse(
"host, 200, bytes, src");
404 static int DetectTagTestParse03(
void)
408 td = DetectTagParse(
"host, 200, bytes, dst");
423 static int DetectTagTestParse04(
void)
427 td = DetectTagParse(
"session");
441 static int DetectTagTestParse05(
void)
445 td = DetectTagParse(
"host");
460 void DetectTagRegisterTests(
void)
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
main detection engine ctx
void DetectTagDataListFree(void *ptr)
this function will free all the entries of a list DetectTagDataEntry
#define TAG_ENTRY_FLAG_DIR_SRC
@ DETECT_TAG_METRIC_PACKET
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define TAG_ENTRY_FLAG_DIR_DST
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
#define SCLogWarning(...)
Macro used to log WARNING messages.
@ DETECT_TAG_METRIC_BYTES
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
SC_ATOMIC_EXTERN(unsigned int, num_tags)
Data structures and function prototypes for keeping state for the detection engine.
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
void DetectTagRegister(void)
Registration function for keyword tag.
#define DETECT_TAG_MAX_PKTS
@ DETECT_TAG_METRIC_SECONDS
void DetectEngineTagRegisterTests(void)
this function registers unit tests for DetectTag
#define SCLogError(...)
Macro used to log ERROR messages.
int TagFlowAdd(Packet *p, DetectTagDataEntry *tde)
This function is used to add a tag to a session (type session) or update it if it's already installed...
int TagHashAddTag(DetectTagDataEntry *tde, Packet *p)
Add a tag entry for a host. If it already exist, update it.
struct DetectTagDataEntry_ * next
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
@ DETECT_TAG_TYPE_SESSION
#define SIGMATCH_IPONLY_COMPAT
void DetectTagDataFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectTagData
void(* RegisterTests)(void)