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 
46 #include "flow-bit.h"
47 #include "host-bit.h"
48 #include "ippair-bit.h"
49 #include "util-var-name.h"
50 #include "util-unittest.h"
51 #include "util-debug.h"
52 
53 /*
54  xbits:set,bitname,track ip_pair,expire 60
55  */
56 
57 #define PARSE_REGEX "^([a-z]+)" "(?:,\\s*([^,]+))?" "(?:,\\s*(?:track\\s+([^,]+)))" "(?:,\\s*(?:expire\\s+([^,]+)))?"
58 static DetectParseRegex parse_regex;
59 
60 static int DetectXbitMatch (DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *);
61 static int DetectXbitSetup (DetectEngineCtx *, Signature *, const char *);
62 void DetectXbitFree (DetectEngineCtx *, void *);
63 void XBitsRegisterTests(void);
64 
66 {
67  sigmatch_table[DETECT_XBITS].name = "xbits";
68  sigmatch_table[DETECT_XBITS].desc = "operate on bits";
69  sigmatch_table[DETECT_XBITS].url = "/rules/xbits.html";
70  sigmatch_table[DETECT_XBITS].Match = DetectXbitMatch;
71  sigmatch_table[DETECT_XBITS].Setup = DetectXbitSetup;
74  /* this is compatible to ip-only signatures */
76 
77  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
78 }
79 
80 static int DetectIPPairbitMatchToggle (Packet *p, const DetectXbitsData *fd)
81 {
82  IPPair *pair = IPPairGetIPPairFromHash(&p->src, &p->dst);
83  if (pair == NULL)
84  return 0;
85 
86  IPPairBitToggle(pair,fd->idx,p->ts.tv_sec + fd->expire);
87  IPPairRelease(pair);
88  return 1;
89 }
90 
91 /* return true even if bit not found */
92 static int DetectIPPairbitMatchUnset (Packet *p, const DetectXbitsData *fd)
93 {
94  IPPair *pair = IPPairLookupIPPairFromHash(&p->src, &p->dst);
95  if (pair == NULL)
96  return 1;
97 
98  IPPairBitUnset(pair,fd->idx);
99  IPPairRelease(pair);
100  return 1;
101 }
102 
103 static int DetectIPPairbitMatchSet (Packet *p, const DetectXbitsData *fd)
104 {
105  IPPair *pair = IPPairGetIPPairFromHash(&p->src, &p->dst);
106  if (pair == NULL)
107  return 0;
108 
109  IPPairBitSet(pair, fd->idx, p->ts.tv_sec + fd->expire);
110  IPPairRelease(pair);
111  return 1;
112 }
113 
114 static int DetectIPPairbitMatchIsset (Packet *p, const DetectXbitsData *fd)
115 {
116  int r = 0;
117  IPPair *pair = IPPairLookupIPPairFromHash(&p->src, &p->dst);
118  if (pair == NULL)
119  return 0;
120 
121  r = IPPairBitIsset(pair,fd->idx,p->ts.tv_sec);
122  IPPairRelease(pair);
123  return r;
124 }
125 
126 static int DetectIPPairbitMatchIsnotset (Packet *p, const DetectXbitsData *fd)
127 {
128  int r = 0;
129  IPPair *pair = IPPairLookupIPPairFromHash(&p->src, &p->dst);
130  if (pair == NULL)
131  return 1;
132 
133  r = IPPairBitIsnotset(pair,fd->idx,p->ts.tv_sec);
134  IPPairRelease(pair);
135  return r;
136 }
137 
138 static int DetectXbitMatchIPPair(Packet *p, const DetectXbitsData *xd)
139 {
140  switch (xd->cmd) {
142  return DetectIPPairbitMatchIsset(p,xd);
144  return DetectIPPairbitMatchIsnotset(p,xd);
146  return DetectIPPairbitMatchSet(p,xd);
148  return DetectIPPairbitMatchUnset(p,xd);
150  return DetectIPPairbitMatchToggle(p,xd);
151  default:
152  SCLogError(SC_ERR_UNKNOWN_VALUE, "unknown cmd %" PRIu32 "", xd->cmd);
153  return 0;
154  }
155  return 0;
156 }
157 
158 /*
159  * returns 0: no match
160  * 1: match
161  * -1: error
162  */
163 
164 static int DetectXbitMatch (DetectEngineThreadCtx *det_ctx, Packet *p, const Signature *s, const SigMatchCtx *ctx)
165 {
166  const DetectXbitsData *fd = (const DetectXbitsData *)ctx;
167  if (fd == NULL)
168  return 0;
169 
170  switch (fd->type) {
171  case VAR_TYPE_HOST_BIT:
172  return DetectXbitMatchHost(p, (const DetectXbitsData *)fd);
173  break;
174  case VAR_TYPE_IPPAIR_BIT:
175  return DetectXbitMatchIPPair(p, (const DetectXbitsData *)fd);
176  break;
177  default:
178  break;
179  }
180  return 0;
181 }
182 
183 /** \internal
184  * \brief parse xbits rule options
185  * \retval 0 ok
186  * \retval -1 bad
187  * \param[out] cdout return DetectXbitsData structure or NULL if noalert
188  */
189 static int DetectXbitParse(DetectEngineCtx *de_ctx,
190  const char *rawstr, DetectXbitsData **cdout)
191 {
192  DetectXbitsData *cd = NULL;
193  uint8_t fb_cmd = 0;
194  uint8_t hb_dir = 0;
195  int ret = 0, res = 0;
196  int ov[MAX_SUBSTRINGS];
197  char fb_cmd_str[16] = "", fb_name[256] = "";
198  char hb_dir_str[16] = "";
199  enum VarTypes var_type = VAR_TYPE_NOT_SET;
200  uint32_t expire = DETECT_XBITS_EXPIRE_DEFAULT;
201 
202  ret = DetectParsePcreExec(&parse_regex, rawstr, 0, 0, ov, MAX_SUBSTRINGS);
203  if (ret != 2 && ret != 3 && ret != 4 && ret != 5) {
204  SCLogError(SC_ERR_PCRE_MATCH, "\"%s\" is not a valid setting for xbits.", rawstr);
205  return -1;
206  }
207  SCLogDebug("ret %d, %s", ret, rawstr);
208  res = pcre_copy_substring((char *)rawstr, ov, MAX_SUBSTRINGS, 1, fb_cmd_str, sizeof(fb_cmd_str));
209  if (res < 0) {
210  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring failed");
211  return -1;
212  }
213 
214  if (ret >= 3) {
215  res = pcre_copy_substring((char *)rawstr, ov, MAX_SUBSTRINGS, 2, fb_name, sizeof(fb_name));
216  if (res < 0) {
217  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring failed");
218  return -1;
219  }
220  if (ret >= 4) {
221  res = pcre_copy_substring((char *)rawstr, ov, MAX_SUBSTRINGS, 3, hb_dir_str, sizeof(hb_dir_str));
222  if (res < 0) {
223  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring failed");
224  return -1;
225  }
226  SCLogDebug("hb_dir_str %s", hb_dir_str);
227  if (strlen(hb_dir_str) > 0) {
228  if (strcmp(hb_dir_str, "ip_src") == 0) {
229  hb_dir = DETECT_XBITS_TRACK_IPSRC;
230  var_type = VAR_TYPE_HOST_BIT;
231  } else if (strcmp(hb_dir_str, "ip_dst") == 0) {
232  hb_dir = DETECT_XBITS_TRACK_IPDST;
233  var_type = VAR_TYPE_HOST_BIT;
234  } else if (strcmp(hb_dir_str, "ip_pair") == 0) {
235  hb_dir = DETECT_XBITS_TRACK_IPPAIR;
236  var_type = VAR_TYPE_IPPAIR_BIT;
237  } else {
238  // TODO
239  return -1;
240  }
241  }
242 
243  if (ret >= 5) {
244  char expire_str[16] = "";
245  res = pcre_copy_substring((char *)rawstr, ov, MAX_SUBSTRINGS, 4, expire_str, sizeof(expire_str));
246  if (res < 0) {
247  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring failed");
248  return -1;
249  }
250  SCLogDebug("expire_str %s", expire_str);
251  if (StringParseUint32(&expire, 10, 0, (const char *)expire_str) < 0) {
252  SCLogError(SC_ERR_INVALID_VALUE, "Invalid value for "
253  "expire: \"%s\"", expire_str);
254  return -1;
255  }
256  if (expire == 0) {
257  SCLogError(SC_ERR_INVALID_VALUE, "expire must be bigger than 0");
258  return -1;
259  }
260  SCLogDebug("expire %d", expire);
261  }
262  }
263  }
264 
265  if (strcmp(fb_cmd_str,"noalert") == 0) {
266  fb_cmd = DETECT_XBITS_CMD_NOALERT;
267  } else if (strcmp(fb_cmd_str,"isset") == 0) {
268  fb_cmd = DETECT_XBITS_CMD_ISSET;
269  } else if (strcmp(fb_cmd_str,"isnotset") == 0) {
270  fb_cmd = DETECT_XBITS_CMD_ISNOTSET;
271  } else if (strcmp(fb_cmd_str,"set") == 0) {
272  fb_cmd = DETECT_XBITS_CMD_SET;
273  } else if (strcmp(fb_cmd_str,"unset") == 0) {
274  fb_cmd = DETECT_XBITS_CMD_UNSET;
275  } else if (strcmp(fb_cmd_str,"toggle") == 0) {
276  fb_cmd = DETECT_XBITS_CMD_TOGGLE;
277  } else {
278  SCLogError(SC_ERR_UNKNOWN_VALUE, "xbits action \"%s\" is not supported.", fb_cmd_str);
279  return -1;
280  }
281 
282  switch (fb_cmd) {
284  if (strlen(fb_name) != 0)
285  return -1;
286  /* return ok, cd is NULL. Flag sig. */
287  *cdout = NULL;
288  return 0;
289  }
295  default:
296  if (strlen(fb_name) == 0)
297  return -1;
298  break;
299  }
300 
301  cd = SCMalloc(sizeof(DetectXbitsData));
302  if (unlikely(cd == NULL))
303  return -1;
304 
305  cd->idx = VarNameStoreSetupAdd(fb_name, var_type);
306  cd->cmd = fb_cmd;
307  cd->tracker = hb_dir;
308  cd->type = var_type;
309  cd->expire = expire;
310 
311  SCLogDebug("idx %" PRIu32 ", cmd %s, name %s",
312  cd->idx, fb_cmd_str, strlen(fb_name) ? fb_name : "(none)");
313 
314  *cdout = cd;
315  return 0;
316 }
317 
318 int DetectXbitSetup (DetectEngineCtx *de_ctx, Signature *s, const char *rawstr)
319 {
320  SigMatch *sm = NULL;
321  DetectXbitsData *cd = NULL;
322 
323  int result = DetectXbitParse(de_ctx, rawstr, &cd);
324  if (result < 0) {
325  return -1;
326  /* noalert doesn't use a cd/sm struct. It flags the sig. We're done. */
327  } else if (result == 0 && cd == NULL) {
328  s->flags |= SIG_FLAG_NOALERT;
329  return 0;
330  }
331 
332  /* Okay so far so good, lets get this into a SigMatch
333  * and put it in the Signature. */
334  sm = SigMatchAlloc();
335  if (sm == NULL)
336  goto error;
337 
338  sm->type = DETECT_XBITS;
339  sm->ctx = (void *)cd;
340 
341  switch (cd->cmd) {
342  /* case DETECT_XBITS_CMD_NOALERT can't happen here */
343 
346  /* checks, so packet list */
348  break;
349 
353  /* modifiers, only run when entire sig has matched */
355  break;
356  }
357 
358  return 0;
359 
360 error:
361  if (cd != NULL)
362  SCFree(cd);
363  return -1;
364 }
365 
367 {
368  DetectXbitsData *fd = (DetectXbitsData *)ptr;
369 
370  if (fd == NULL)
371  return;
372 
373  SCFree(fd);
374 }
375 
376 #ifdef UNITTESTS
377 
378 static void XBitsTestSetup(void)
379 {
380  StorageInit();
381  HostBitInitCtx();
383  StorageFinalize();
386 }
387 
388 static void XBitsTestShutdown(void)
389 {
390  HostCleanup();
391  IPPairCleanup();
392  StorageCleanup();
393 }
394 
395 
396 static int XBitsTestParse01(void)
397 {
398  DetectEngineCtx *de_ctx = NULL;
401  de_ctx->flags |= DE_QUIET;
402  DetectXbitsData *cd = NULL;
403 
404 #define BAD_INPUT(str) \
405  FAIL_IF_NOT(DetectXbitParse(de_ctx, (str), &cd) == -1);
406 
407  BAD_INPUT("alert");
408  BAD_INPUT("n0alert");
409  BAD_INPUT("nOalert");
410  BAD_INPUT("set,abc,track nonsense, expire 3600");
411  BAD_INPUT("set,abc,track ip_source, expire 3600");
412  BAD_INPUT("set,abc,track ip_src, expire -1");
413  BAD_INPUT("set,abc,track ip_src, expire 0");
414 
415 #undef BAD_INPUT
416 
417 #define GOOD_INPUT(str, command, trk, typ, exp) \
418  FAIL_IF_NOT(DetectXbitParse(de_ctx, (str), &cd) == 0); \
419  FAIL_IF_NULL(cd); \
420  FAIL_IF_NOT(cd->cmd == (command)); \
421  FAIL_IF_NOT(cd->tracker == (trk)); \
422  FAIL_IF_NOT(cd->type == (typ)); \
423  FAIL_IF_NOT(cd->expire == (exp)); \
424  DetectXbitFree(NULL, cd); \
425  cd = NULL;
426 
427  GOOD_INPUT("set,abc,track ip_pair",
431  GOOD_INPUT("set,abc,track ip_pair, expire 3600",
434  3600);
435  GOOD_INPUT("set,abc,track ip_src, expire 1234",
438  1234);
439 
440 #undef GOOD_INPUT
441 
443  PASS;
444 }
445 
446 /**
447  * \test
448  */
449 
450 static int XBitsTestSig01(void)
451 {
452  uint8_t *buf = (uint8_t *)
453  "GET /one/ HTTP/1.1\r\n"
454  "Host: one.example.org\r\n"
455  "\r\n";
456  uint16_t buflen = strlen((char *)buf);
458  FAIL_IF_NULL(p);
459  Signature *s = NULL;
460  ThreadVars th_v;
461  DetectEngineThreadCtx *det_ctx = NULL;
462  DetectEngineCtx *de_ctx = NULL;
463 
464  memset(&th_v, 0, sizeof(th_v));
465  memset(p, 0, SIZE_OF_PACKET);
466  p->src.family = AF_INET;
467  p->dst.family = AF_INET;
468  p->payload = buf;
469  p->payload_len = buflen;
470  p->proto = IPPROTO_TCP;
471 
472  XBitsTestSetup();
473 
476  de_ctx->flags |= DE_QUIET;
477 
479  "alert ip any any -> any any (xbits:set,abc,track ip_pair; content:\"GET \"; sid:1;)");
480  FAIL_IF_NULL(s);
481 
483  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
484  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
485  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
487  XBitsTestShutdown();
488  SCFree(p);
489  StatsThreadCleanup(&th_v);
491  PASS;
492 }
493 
494 /**
495  * \test various options
496  *
497  * \retval 1 on succces
498  * \retval 0 on failure
499  */
500 
501 static int XBitsTestSig02(void)
502 {
503  Signature *s = NULL;
504  DetectEngineCtx *de_ctx = NULL;
507  de_ctx->flags |= DE_QUIET;
508 
510  "alert ip any any -> any any (xbits:isset,abc,track ip_src; content:\"GET \"; sid:1;)");
511  FAIL_IF_NULL(s);
512 
514  "alert ip any any -> any any (xbits:isnotset,abc,track ip_dst; content:\"GET \"; sid:2;)");
515  FAIL_IF_NULL(s);
516 
518  "alert ip any any -> any any (xbits:set,abc,track ip_pair; content:\"GET \"; sid:3;)");
519  FAIL_IF_NULL(s);
520 
522  "alert ip any any -> any any (xbits:unset,abc,track ip_src; content:\"GET \"; sid:4;)");
523  FAIL_IF_NULL(s);
524 
526  "alert ip any any -> any any (xbits:toggle,abc,track ip_dst; content:\"GET \"; sid:5;)");
527  FAIL_IF_NULL(s);
528 
530  "alert ip any any -> any any (xbits:!set,abc,track ip_dst; content:\"GET \"; sid:6;)");
531  FAIL_IF_NOT_NULL(s);
532 
534  PASS;
535 }
536 
537 #endif /* UNITTESTS */
538 
539 /**
540  * \brief this function registers unit tests for XBits
541  */
543 {
544 #ifdef UNITTESTS
545  UtRegisterTest("XBitsTestParse01", XBitsTestParse01);
546  UtRegisterTest("XBitsTestSig01", XBitsTestSig01);
547  UtRegisterTest("XBitsTestSig02", XBitsTestSig02);
548 #endif /* UNITTESTS */
549 }
IPPairBitUnset
void IPPairBitUnset(IPPair *h, uint32_t idx)
Definition: ippair-bit.c:140
util-byte.h
SigTableElmt_::url
const char * url
Definition: detect.h:1212
Packet_::proto
uint8_t proto
Definition: decode.h:433
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:65
SigTableElmt_::desc
const char * desc
Definition: detect.h:1211
DetectXbitsData_::expire
uint32_t expire
Definition: detect-xbits.h:46
SC_ERR_INVALID_VALUE
@ SC_ERR_INVALID_VALUE
Definition: util-error.h:160
StorageInit
void StorageInit(void)
Definition: util-storage.c:67
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1200
flow-util.h
IPPairRelease
void IPPairRelease(IPPair *h)
Definition: ippair.c:518
SigTableElmt_::name
const char * name
Definition: detect.h:1209
MAX_SUBSTRINGS
#define MAX_SUBSTRINGS
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:298
Packet_::payload
uint8_t * payload
Definition: decode.h:543
ippair-bit.h
threads.h
HostInitConfig
void HostInitConfig(char quiet)
initialize the configuration
Definition: host.c:173
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1203
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:766
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:132
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2089
StorageCleanup
void StorageCleanup(void)
Definition: util-storage.c:75
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:293
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:1195
HostBitInitCtx
void HostBitInitCtx(void)
Definition: host-bit.c:49
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:544
DetectXbitsData_
Definition: detect-xbits.h:42
util-unittest.h
DetectXbitFree
void DetectXbitFree(DetectEngineCtx *, void *)
Definition: detect-xbits.c:366
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:98
DetectXbitMatchHost
int DetectXbitMatchHost(Packet *p, const DetectXbitsData *xd)
Definition: detect-hostbits.c:241
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:148
IPPairCleanup
void IPPairCleanup(void)
Cleanup the ippair engine.
Definition: ippair.c:338
DetectEngineThreadCtx_
Definition: detect.h:1009
SC_ERR_UNKNOWN_VALUE
@ SC_ERR_UNKNOWN_VALUE
Definition: util-error.h:159
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2456
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:58
BAD_INPUT
#define BAD_INPUT(str)
DETECT_XBITS_TRACK_IPPAIR
#define DETECT_XBITS_TRACK_IPPAIR
Definition: detect-xbits.h:37
IPPairGetIPPairFromHash
IPPair * IPPairGetIPPairFromHash(Address *a, Address *b)
Definition: ippair.c:542
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:89
SIZE_OF_PACKET
#define SIZE_OF_PACKET
Definition: decode.h:621
IPPairInitConfig
void IPPairInitConfig(char quiet)
initialize the configuration
Definition: ippair.c:168
app-layer-parser.h
TRUE
#define TRUE
Definition: suricata-common.h:33
DETECT_XBITS
@ DETECT_XBITS
Definition: detect-engine-register.h:220
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:322
SigMatchSignatures
void SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1668
IPPairBitIsnotset
int IPPairBitIsnotset(IPPair *h, uint32_t idx, uint32_t ts)
Definition: ippair-bit.c:172
DetectXbitsData_::type
enum VarTypes type
Definition: detect-xbits.h:48
Signature_::flags
uint32_t flags
Definition: detect.h:528
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options, int *ovector, int ovector_size)
Definition: detect-parse.c:2388
Packet_
Definition: decode.h:411
StorageFinalize
int StorageFinalize(void)
Definition: util-storage.c:139
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:1178
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:235
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1876
SigMatch_::type
uint8_t type
Definition: detect.h:320
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:314
StringParseUint32
int StringParseUint32(uint32_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:313
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:2326
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:2793
Packet_::ts
struct timeval ts
Definition: decode.h:454
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3001
IPPair_
Definition: ippair.h:58
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
DetectParseRegex_
Definition: detect-parse.h:42
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:257
SIG_FLAG_NOALERT
#define SIG_FLAG_NOALERT
Definition: detect.h:216
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
detect-engine-sigorder.h
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
XBitsRegisterTests
void XBitsRegisterTests(void)
this function registers unit tests for XBits
Definition: detect-xbits.c:542
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:527
SigMatch_
a single match condition for a signature
Definition: detect.h:319
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:2044
VarTypes
VarTypes
Definition: util-var.h:27
Address_::family
char family
Definition: decode.h:114
Packet_::dst
Address dst
Definition: decode.h:416
IPPairLookupIPPairFromHash
IPPair * IPPairLookupIPPairFromHash(Address *a, Address *b)
look up a ippair in the hash
Definition: ippair.c:641
IPPairBitIsset
int IPPairBitIsset(IPPair *h, uint32_t idx, uint32_t ts)
Definition: ippair-bit.c:158
DETECT_XBITS_CMD_SET
#define DETECT_XBITS_CMD_SET
Definition: detect-xbits.h:27
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:767
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:1258
StatsThreadCleanup
void StatsThreadCleanup(ThreadVars *tv)
Definition: counters.c:1299
SIGMATCH_IPONLY_COMPAT
#define SIGMATCH_IPONLY_COMPAT
Definition: detect.h:1380
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:349
Packet_::src
Address src
Definition: decode.h:415
PARSE_REGEX
#define PARSE_REGEX
Definition: detect-xbits.c:57
host-bit.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1201