suricata
detect-xbits.c
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  * Implements the xbits keyword
24  */
25 
26 #include "suricata-common.h"
27 #include "decode.h"
28 #include "detect.h"
29 #include "threads.h"
30 #include "flow.h"
31 #include "flow-util.h"
32 #include "detect-xbits.h"
33 #include "detect-hostbits.h"
34 #include "util-spm.h"
35 #include "util-byte.h"
36 
37 #include "detect-engine-sigorder.h"
38 
39 #include "app-layer-parser.h"
40 
41 #include "detect-parse.h"
42 #include "detect-engine.h"
43 #include "detect-engine-mpm.h"
44 #include "detect-engine-state.h"
45 #include "detect-engine-build.h"
46 
47 #include "flow-bit.h"
48 #include "host-bit.h"
49 #include "ippair-bit.h"
50 #include "util-var-name.h"
51 #include "util-unittest.h"
52 #include "util-debug.h"
53 
54 /*
55  xbits:set,bitname,track ip_pair,expire 60
56  */
57 
58 #define PARSE_REGEX "^([a-z]+)" "(?:,\\s*([^,]+))?" "(?:,\\s*(?:track\\s+([^,]+)))" "(?:,\\s*(?:expire\\s+([^,]+)))?"
59 static DetectParseRegex parse_regex;
60 
61 static int DetectXbitMatch (DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *);
62 static int DetectXbitSetup (DetectEngineCtx *, Signature *, const char *);
63 #ifdef UNITTESTS
64 static void XBitsRegisterTests(void);
65 #endif
66 static void DetectXbitFree (DetectEngineCtx *, void *);
67 
69 {
70  sigmatch_table[DETECT_XBITS].name = "xbits";
71  sigmatch_table[DETECT_XBITS].desc = "operate on bits";
72  sigmatch_table[DETECT_XBITS].url = "/rules/xbits.html";
73  sigmatch_table[DETECT_XBITS].Match = DetectXbitMatch;
74  sigmatch_table[DETECT_XBITS].Setup = DetectXbitSetup;
75  sigmatch_table[DETECT_XBITS].Free = DetectXbitFree;
76 #ifdef UNITTESTS
77  sigmatch_table[DETECT_XBITS].RegisterTests = XBitsRegisterTests;
78 #endif
79  /* this is compatible to ip-only signatures */
81 
82  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
83 }
84 
85 static int DetectIPPairbitMatchToggle (Packet *p, const DetectXbitsData *fd)
86 {
87  IPPair *pair = IPPairGetIPPairFromHash(&p->src, &p->dst);
88  if (pair == NULL)
89  return 0;
90 
91  IPPairBitToggle(pair,fd->idx,p->ts.tv_sec + fd->expire);
92  IPPairRelease(pair);
93  return 1;
94 }
95 
96 /* return true even if bit not found */
97 static int DetectIPPairbitMatchUnset (Packet *p, const DetectXbitsData *fd)
98 {
99  IPPair *pair = IPPairLookupIPPairFromHash(&p->src, &p->dst);
100  if (pair == NULL)
101  return 1;
102 
103  IPPairBitUnset(pair,fd->idx);
104  IPPairRelease(pair);
105  return 1;
106 }
107 
108 static int DetectIPPairbitMatchSet (Packet *p, const DetectXbitsData *fd)
109 {
110  IPPair *pair = IPPairGetIPPairFromHash(&p->src, &p->dst);
111  if (pair == NULL)
112  return 0;
113 
114  IPPairBitSet(pair, fd->idx, p->ts.tv_sec + fd->expire);
115  IPPairRelease(pair);
116  return 1;
117 }
118 
119 static int DetectIPPairbitMatchIsset (Packet *p, const DetectXbitsData *fd)
120 {
121  int r = 0;
122  IPPair *pair = IPPairLookupIPPairFromHash(&p->src, &p->dst);
123  if (pair == NULL)
124  return 0;
125 
126  r = IPPairBitIsset(pair,fd->idx,p->ts.tv_sec);
127  IPPairRelease(pair);
128  return r;
129 }
130 
131 static int DetectIPPairbitMatchIsnotset (Packet *p, const DetectXbitsData *fd)
132 {
133  int r = 0;
134  IPPair *pair = IPPairLookupIPPairFromHash(&p->src, &p->dst);
135  if (pair == NULL)
136  return 1;
137 
138  r = IPPairBitIsnotset(pair,fd->idx,p->ts.tv_sec);
139  IPPairRelease(pair);
140  return r;
141 }
142 
143 static int DetectXbitMatchIPPair(Packet *p, const DetectXbitsData *xd)
144 {
145  switch (xd->cmd) {
147  return DetectIPPairbitMatchIsset(p,xd);
149  return DetectIPPairbitMatchIsnotset(p,xd);
151  return DetectIPPairbitMatchSet(p,xd);
153  return DetectIPPairbitMatchUnset(p,xd);
155  return DetectIPPairbitMatchToggle(p,xd);
156  }
157  return 0;
158 }
159 
160 /*
161  * returns 0: no match
162  * 1: match
163  * -1: error
164  */
165 
166 static int DetectXbitMatch (DetectEngineThreadCtx *det_ctx, Packet *p, const Signature *s, const SigMatchCtx *ctx)
167 {
168  const DetectXbitsData *fd = (const DetectXbitsData *)ctx;
169  if (fd == NULL)
170  return 0;
171 
172  switch (fd->type) {
173  case VAR_TYPE_HOST_BIT:
174  return DetectXbitMatchHost(p, (const DetectXbitsData *)fd);
175  break;
176  case VAR_TYPE_IPPAIR_BIT:
177  return DetectXbitMatchIPPair(p, (const DetectXbitsData *)fd);
178  break;
179  default:
180  break;
181  }
182  return 0;
183 }
184 
185 /** \internal
186  * \brief parse xbits rule options
187  * \retval 0 ok
188  * \retval -1 bad
189  * \param[out] cdout return DetectXbitsData structure or NULL if noalert
190  */
191 static int DetectXbitParse(DetectEngineCtx *de_ctx,
192  const char *rawstr, DetectXbitsData **cdout)
193 {
194  DetectXbitsData *cd = NULL;
195  uint8_t fb_cmd = 0;
196  uint8_t hb_dir = 0;
197  int ret = 0, res = 0;
198  size_t pcre2len;
199  char fb_cmd_str[16] = "", fb_name[256] = "";
200  char hb_dir_str[16] = "";
201  enum VarTypes var_type = VAR_TYPE_NOT_SET;
202  uint32_t expire = DETECT_XBITS_EXPIRE_DEFAULT;
203 
204  ret = DetectParsePcreExec(&parse_regex, rawstr, 0, 0);
205  if (ret != 2 && ret != 3 && ret != 4 && ret != 5) {
206  SCLogError(SC_ERR_PCRE_MATCH, "\"%s\" is not a valid setting for xbits.", rawstr);
207  return -1;
208  }
209  SCLogDebug("ret %d, %s", ret, rawstr);
210  pcre2len = sizeof(fb_cmd_str);
211  res = pcre2_substring_copy_bynumber(
212  parse_regex.match, 1, (PCRE2_UCHAR8 *)fb_cmd_str, &pcre2len);
213  if (res < 0) {
214  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
215  return -1;
216  }
217 
218  if (ret >= 3) {
219  pcre2len = sizeof(fb_name);
220  res = pcre2_substring_copy_bynumber(
221  parse_regex.match, 2, (PCRE2_UCHAR8 *)fb_name, &pcre2len);
222  if (res < 0) {
223  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
224  return -1;
225  }
226  if (ret >= 4) {
227  pcre2len = sizeof(hb_dir_str);
228  res = pcre2_substring_copy_bynumber(
229  parse_regex.match, 3, (PCRE2_UCHAR8 *)hb_dir_str, &pcre2len);
230  if (res < 0) {
231  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
232  return -1;
233  }
234  SCLogDebug("hb_dir_str %s", hb_dir_str);
235  if (strlen(hb_dir_str) > 0) {
236  if (strcmp(hb_dir_str, "ip_src") == 0) {
237  hb_dir = DETECT_XBITS_TRACK_IPSRC;
238  var_type = VAR_TYPE_HOST_BIT;
239  } else if (strcmp(hb_dir_str, "ip_dst") == 0) {
240  hb_dir = DETECT_XBITS_TRACK_IPDST;
241  var_type = VAR_TYPE_HOST_BIT;
242  } else if (strcmp(hb_dir_str, "ip_pair") == 0) {
243  hb_dir = DETECT_XBITS_TRACK_IPPAIR;
244  var_type = VAR_TYPE_IPPAIR_BIT;
245  } else {
246  // TODO
247  return -1;
248  }
249  }
250 
251  if (ret >= 5) {
252  char expire_str[16] = "";
253  pcre2len = sizeof(expire_str);
254  res = pcre2_substring_copy_bynumber(
255  parse_regex.match, 4, (PCRE2_UCHAR8 *)expire_str, &pcre2len);
256  if (res < 0) {
257  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
258  return -1;
259  }
260  SCLogDebug("expire_str %s", expire_str);
261  if (StringParseUint32(&expire, 10, 0, (const char *)expire_str) < 0) {
262  SCLogError(SC_ERR_INVALID_VALUE, "Invalid value for "
263  "expire: \"%s\"", expire_str);
264  return -1;
265  }
266  if (expire == 0) {
267  SCLogError(SC_ERR_INVALID_VALUE, "expire must be bigger than 0");
268  return -1;
269  }
270  SCLogDebug("expire %d", expire);
271  }
272  }
273  }
274 
275  if (strcmp(fb_cmd_str,"noalert") == 0) {
276  fb_cmd = DETECT_XBITS_CMD_NOALERT;
277  } else if (strcmp(fb_cmd_str,"isset") == 0) {
278  fb_cmd = DETECT_XBITS_CMD_ISSET;
279  } else if (strcmp(fb_cmd_str,"isnotset") == 0) {
280  fb_cmd = DETECT_XBITS_CMD_ISNOTSET;
281  } else if (strcmp(fb_cmd_str,"set") == 0) {
282  fb_cmd = DETECT_XBITS_CMD_SET;
283  } else if (strcmp(fb_cmd_str,"unset") == 0) {
284  fb_cmd = DETECT_XBITS_CMD_UNSET;
285  } else if (strcmp(fb_cmd_str,"toggle") == 0) {
286  fb_cmd = DETECT_XBITS_CMD_TOGGLE;
287  } else {
288  SCLogError(SC_ERR_UNKNOWN_VALUE, "xbits action \"%s\" is not supported.", fb_cmd_str);
289  return -1;
290  }
291 
292  switch (fb_cmd) {
294  if (strlen(fb_name) != 0)
295  return -1;
296  /* return ok, cd is NULL. Flag sig. */
297  *cdout = NULL;
298  return 0;
299  }
305  if (strlen(fb_name) == 0)
306  return -1;
307  break;
308  }
309 
310  cd = SCMalloc(sizeof(DetectXbitsData));
311  if (unlikely(cd == NULL))
312  return -1;
313 
314  cd->idx = VarNameStoreSetupAdd(fb_name, var_type);
315  cd->cmd = fb_cmd;
316  cd->tracker = hb_dir;
317  cd->type = var_type;
318  cd->expire = expire;
319 
320  SCLogDebug("idx %" PRIu32 ", cmd %s, name %s",
321  cd->idx, fb_cmd_str, strlen(fb_name) ? fb_name : "(none)");
322 
323  *cdout = cd;
324  return 0;
325 }
326 
327 int DetectXbitSetup (DetectEngineCtx *de_ctx, Signature *s, const char *rawstr)
328 {
329  SigMatch *sm = NULL;
330  DetectXbitsData *cd = NULL;
331 
332  int result = DetectXbitParse(de_ctx, rawstr, &cd);
333  if (result < 0) {
334  return -1;
335  /* noalert doesn't use a cd/sm struct. It flags the sig. We're done. */
336  } else if (result == 0 && cd == NULL) {
337  s->flags |= SIG_FLAG_NOALERT;
338  return 0;
339  }
340 
341  /* Okay so far so good, lets get this into a SigMatch
342  * and put it in the Signature. */
343  sm = SigMatchAlloc();
344  if (sm == NULL)
345  goto error;
346 
347  sm->type = DETECT_XBITS;
348  sm->ctx = (void *)cd;
349 
350  switch (cd->cmd) {
351  /* case DETECT_XBITS_CMD_NOALERT can't happen here */
352 
355  /* checks, so packet list */
357  break;
358 
362  /* modifiers, only run when entire sig has matched */
364  break;
365  }
366 
367  return 0;
368 
369 error:
370  if (cd != NULL)
371  SCFree(cd);
372  return -1;
373 }
374 
375 static void DetectXbitFree (DetectEngineCtx *de_ctx, void *ptr)
376 {
377  DetectXbitsData *fd = (DetectXbitsData *)ptr;
378 
379  if (fd == NULL)
380  return;
381 
382  SCFree(fd);
383 }
384 
385 #ifdef UNITTESTS
386 
387 static void XBitsTestSetup(void)
388 {
389  StorageInit();
390  HostBitInitCtx();
392  StorageFinalize();
393  HostInitConfig(true);
394  IPPairInitConfig(true);
395 }
396 
397 static void XBitsTestShutdown(void)
398 {
399  HostCleanup();
400  IPPairCleanup();
401  StorageCleanup();
402 }
403 
404 
405 static int XBitsTestParse01(void)
406 {
407  DetectEngineCtx *de_ctx = NULL;
410  de_ctx->flags |= DE_QUIET;
411  DetectXbitsData *cd = NULL;
412 
413 #define BAD_INPUT(str) \
414  FAIL_IF_NOT(DetectXbitParse(de_ctx, (str), &cd) == -1);
415 
416  BAD_INPUT("alert");
417  BAD_INPUT("n0alert");
418  BAD_INPUT("nOalert");
419  BAD_INPUT("set,abc,track nonsense, expire 3600");
420  BAD_INPUT("set,abc,track ip_source, expire 3600");
421  BAD_INPUT("set,abc,track ip_src, expire -1");
422  BAD_INPUT("set,abc,track ip_src, expire 0");
423 
424 #undef BAD_INPUT
425 
426 #define GOOD_INPUT(str, command, trk, typ, exp) \
427  FAIL_IF_NOT(DetectXbitParse(de_ctx, (str), &cd) == 0); \
428  FAIL_IF_NULL(cd); \
429  FAIL_IF_NOT(cd->cmd == (command)); \
430  FAIL_IF_NOT(cd->tracker == (trk)); \
431  FAIL_IF_NOT(cd->type == (typ)); \
432  FAIL_IF_NOT(cd->expire == (exp)); \
433  DetectXbitFree(NULL, cd); \
434  cd = NULL;
435 
436  GOOD_INPUT("set,abc,track ip_pair",
440  GOOD_INPUT("set,abc,track ip_pair, expire 3600",
443  3600);
444  GOOD_INPUT("set,abc,track ip_src, expire 1234",
447  1234);
448 
449 #undef GOOD_INPUT
450 
452  PASS;
453 }
454 
455 /**
456  * \test
457  */
458 
459 static int XBitsTestSig01(void)
460 {
461  uint8_t *buf = (uint8_t *)
462  "GET /one/ HTTP/1.1\r\n"
463  "Host: one.example.org\r\n"
464  "\r\n";
465  uint16_t buflen = strlen((char *)buf);
466  Packet *p = PacketGetFromAlloc();
467  FAIL_IF_NULL(p);
468  Signature *s = NULL;
469  ThreadVars th_v;
470  DetectEngineThreadCtx *det_ctx = NULL;
471  DetectEngineCtx *de_ctx = NULL;
472 
473  memset(&th_v, 0, sizeof(th_v));
474  p->src.family = AF_INET;
475  p->dst.family = AF_INET;
476  p->payload = buf;
477  p->payload_len = buflen;
478  p->proto = IPPROTO_TCP;
479 
480  XBitsTestSetup();
481 
484  de_ctx->flags |= DE_QUIET;
485 
487  "alert ip any any -> any any (xbits:set,abc,track ip_pair; content:\"GET \"; sid:1;)");
488  FAIL_IF_NULL(s);
489 
491  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
492  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
493  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
495  XBitsTestShutdown();
496  SCFree(p);
497  StatsThreadCleanup(&th_v);
499  PASS;
500 }
501 
502 /**
503  * \test various options
504  *
505  * \retval 1 on succces
506  * \retval 0 on failure
507  */
508 
509 static int XBitsTestSig02(void)
510 {
511  Signature *s = NULL;
512  DetectEngineCtx *de_ctx = NULL;
515  de_ctx->flags |= DE_QUIET;
516 
518  "alert ip any any -> any any (xbits:isset,abc,track ip_src; content:\"GET \"; sid:1;)");
519  FAIL_IF_NULL(s);
520 
522  "alert ip any any -> any any (xbits:isnotset,abc,track ip_dst; content:\"GET \"; sid:2;)");
523  FAIL_IF_NULL(s);
524 
526  "alert ip any any -> any any (xbits:set,abc,track ip_pair; content:\"GET \"; sid:3;)");
527  FAIL_IF_NULL(s);
528 
530  "alert ip any any -> any any (xbits:unset,abc,track ip_src; content:\"GET \"; sid:4;)");
531  FAIL_IF_NULL(s);
532 
534  "alert ip any any -> any any (xbits:toggle,abc,track ip_dst; content:\"GET \"; sid:5;)");
535  FAIL_IF_NULL(s);
536 
538  "alert ip any any -> any any (xbits:!set,abc,track ip_dst; content:\"GET \"; sid:6;)");
539  FAIL_IF_NOT_NULL(s);
540 
542  PASS;
543 }
544 
545 /**
546  * \brief this function registers unit tests for XBits
547  */
548 static void XBitsRegisterTests(void)
549 {
550  UtRegisterTest("XBitsTestParse01", XBitsTestParse01);
551  UtRegisterTest("XBitsTestSig01", XBitsTestSig01);
552  UtRegisterTest("XBitsTestSig02", XBitsTestSig02);
553 }
554 #endif /* UNITTESTS */
IPPairBitUnset
void IPPairBitUnset(IPPair *h, uint32_t idx)
Definition: ippair-bit.c:139
util-byte.h
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:47
SigTableElmt_::url
const char * url
Definition: detect.h:1238
Packet_::proto
uint8_t proto
Definition: decode.h:447
detect-engine.h
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
DetectXbitsRegister
void DetectXbitsRegister(void)
Definition: detect-xbits.c:68
IPPairInitConfig
void IPPairInitConfig(bool quiet)
initialize the configuration
Definition: ippair.c:169
SigTableElmt_::desc
const char * desc
Definition: detect.h:1237
DetectXbitsData_::expire
uint32_t expire
Definition: detect-xbits.h:46
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2488
SC_ERR_INVALID_VALUE
@ SC_ERR_INVALID_VALUE
Definition: util-error.h:160
StorageInit
void StorageInit(void)
Definition: util-storage.c:68
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1225
flow-util.h
DetectParseRegex
Definition: detect-parse.h:44
IPPairRelease
void IPPairRelease(IPPair *h)
Definition: ippair.c:521
SigTableElmt_::name
const char * name
Definition: detect.h:1235
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:296
Packet_::payload
uint8_t * payload
Definition: decode.h:567
ippair-bit.h
threads.h
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1229
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:784
DetectXbitsData_::cmd
uint8_t cmd
Definition: detect-xbits.h:44
IPPairBitSet
void IPPairBitSet(IPPair *h, uint32_t idx, uint32_t expire)
Definition: ippair-bit.c:131
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2445
StorageCleanup
void StorageCleanup(void)
Definition: util-storage.c:76
flow-bit.h
util-var-name.h
DETECT_XBITS_TRACK_IPDST
#define DETECT_XBITS_TRACK_IPDST
Definition: detect-xbits.h:36
DE_QUIET
#define DE_QUIET
Definition: detect.h:287
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1788
SC_ERR_PCRE_GET_SUBSTRING
@ SC_ERR_PCRE_GET_SUBSTRING
Definition: util-error.h:34
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1220
HostBitInitCtx
void HostBitInitCtx(void)
Definition: host-bit.c:49
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:568
DetectXbitsData_
Definition: detect-xbits.h:42
util-unittest.h
VAR_TYPE_NOT_SET
@ VAR_TYPE_NOT_SET
Definition: util-var.h:28
GOOD_INPUT
#define GOOD_INPUT(str, command, trk, typ, exp)
DETECT_SM_LIST_POSTMATCH
@ DETECT_SM_LIST_POSTMATCH
Definition: detect.h:87
DetectXbitMatchHost
int DetectXbitMatchHost(Packet *p, const DetectXbitsData *xd)
Definition: detect-hostbits.c:246
detect-xbits.h
DETECT_XBITS_CMD_ISNOTSET
#define DETECT_XBITS_CMD_ISNOTSET
Definition: detect-xbits.h:30
DETECT_XBITS_EXPIRE_DEFAULT
#define DETECT_XBITS_EXPIRE_DEFAULT
Definition: detect-xbits.h:40
decode.h
FAIL_IF_NOT_NULL
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Definition: util-unittest.h:96
util-debug.h
SC_ERR_PCRE_MATCH
@ SC_ERR_PCRE_MATCH
Definition: util-error.h:32
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
IPPairBitToggle
void IPPairBitToggle(IPPair *h, uint32_t idx, uint32_t expire)
Definition: ippair-bit.c:147
IPPairCleanup
void IPPairCleanup(void)
Cleanup the ippair engine.
Definition: ippair.c:341
DetectEngineThreadCtx_
Definition: detect.h:1024
SC_ERR_UNKNOWN_VALUE
@ SC_ERR_UNKNOWN_VALUE
Definition: util-error.h:159
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2611
HostCleanup
void HostCleanup(void)
Cleanup the host engine.
Definition: host.c:343
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
BAD_INPUT
#define BAD_INPUT(str)
DETECT_XBITS_TRACK_IPPAIR
#define DETECT_XBITS_TRACK_IPPAIR
Definition: detect-xbits.h:37
StringParseUint32
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:313
IPPairGetIPPairFromHash
IPPair * IPPairGetIPPairFromHash(Address *a, Address *b)
Definition: ippair.c:545
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:78
app-layer-parser.h
DETECT_XBITS
@ DETECT_XBITS
Definition: detect-engine-register.h:249
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:316
IPPairBitIsnotset
int IPPairBitIsnotset(IPPair *h, uint32_t idx, uint32_t ts)
Definition: ippair-bit.c:171
DetectXbitsData_::type
enum VarTypes type
Definition: detect-xbits.h:48
Signature_::flags
uint32_t flags
Definition: detect.h:540
Packet_
Definition: decode.h:425
detect-engine-build.h
StorageFinalize
int StorageFinalize(void)
Definition: util-storage.c:140
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1203
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:238
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1954
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:308
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *de_ctx, const char *sigstr)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:2434
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3154
Packet_::ts
struct timeval ts
Definition: decode.h:468
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3368
SigMatch_::type
uint16_t type
Definition: detect.h:314
IPPair_
Definition: ippair.h:58
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:76
util-spm.h
DetectXbitsData_::idx
uint32_t idx
Definition: detect-xbits.h:43
VarNameStoreSetupAdd
uint32_t VarNameStoreSetupAdd(const char *name, const enum VarTypes type)
add to staging or return existing id if already in there
Definition: util-var-name.c:323
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:255
SIG_FLAG_NOALERT
#define SIG_FLAG_NOALERT
Definition: detect.h:205
detect-hostbits.h
VAR_TYPE_HOST_BIT
@ VAR_TYPE_HOST_BIT
Definition: util-var.h:39
IPPairBitInitCtx
void IPPairBitInitCtx(void)
Definition: ippair-bit.c:49
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:173
detect-engine-sigorder.h
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
DetectXbitsData_::tracker
uint8_t tracker
Definition: detect-xbits.h:45
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DETECT_XBITS_TRACK_IPSRC
#define DETECT_XBITS_TRACK_IPSRC
Definition: detect-xbits.h:35
detect-parse.h
Signature_
Signature container.
Definition: detect.h:539
SigMatch_
a single match condition for a signature
Definition: detect.h:313
DETECT_XBITS_CMD_NOALERT
#define DETECT_XBITS_CMD_NOALERT
Definition: detect-xbits.h:32
DETECT_XBITS_CMD_ISSET
#define DETECT_XBITS_CMD_ISSET
Definition: detect-xbits.h:31
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2406
VarTypes
VarTypes
Definition: util-var.h:27
Address_::family
char family
Definition: decode.h:112
Packet_::dst
Address dst
Definition: decode.h:430
IPPairLookupIPPairFromHash
IPPair * IPPairLookupIPPairFromHash(Address *a, Address *b)
look up a ippair in the hash
Definition: ippair.c:644
HostInitConfig
void HostInitConfig(bool quiet)
initialize the configuration
Definition: host.c:175
IPPairBitIsset
int IPPairBitIsset(IPPair *h, uint32_t idx, uint32_t ts)
Definition: ippair-bit.c:157
DETECT_XBITS_CMD_SET
#define DETECT_XBITS_CMD_SET
Definition: detect-xbits.h:27
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:785
DETECT_XBITS_CMD_TOGGLE
#define DETECT_XBITS_CMD_TOGGLE
Definition: detect-xbits.h:28
flow.h
DETECT_XBITS_CMD_UNSET
#define DETECT_XBITS_CMD_UNSET
Definition: detect-xbits.h:29
VAR_TYPE_IPPAIR_BIT
@ VAR_TYPE_IPPAIR_BIT
Definition: util-var.h:43
StatsReleaseResources
void StatsReleaseResources()
Releases the resources alloted by the Stats API.
Definition: counters.c:1268
StatsThreadCleanup
void StatsThreadCleanup(ThreadVars *tv)
Definition: counters.c:1309
SIGMATCH_IPONLY_COMPAT
#define SIGMATCH_IPONLY_COMPAT
Definition: detect.h:1423
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:352
Packet_::src
Address src
Definition: decode.h:429
PARSE_REGEX
#define PARSE_REGEX
Definition: detect-xbits.c:58
host-bit.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1227