suricata
detect-hostbits.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 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 hostbits 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-hostbits.h"
33 #include "util-spm.h"
34 
35 #include "detect-engine-sigorder.h"
36 
37 #include "app-layer-parser.h"
38 
39 #include "detect-parse.h"
40 #include "detect-engine.h"
41 #include "detect-engine-mpm.h"
42 #include "detect-engine-state.h"
43 
44 #include "flow-bit.h"
45 #include "host-bit.h"
46 #include "util-var-name.h"
47 #include "util-unittest.h"
48 #include "util-debug.h"
49 
50 /*
51  hostbits:isset,bitname;
52  hostbits:set,bitname;
53 
54  hostbits:set,bitname,src;
55  hostbits:set,bitname,dst;
56 TODO:
57  hostbits:set,bitname,both;
58 
59  hostbits:set,bitname,src,3600;
60  hostbits:set,bitname,dst,60;
61  hostbits:set,bitname,both,120;
62  */
63 
64 #define PARSE_REGEX "^([a-z]+)" /* Action */ \
65  "(?:\\s*,\\s*([^\\s,]+))?(?:\\s*)?" /* Name. */ \
66  "(?:\\s*,\\s*([^,\\s]+))?(?:\\s*)?" /* Direction. */ \
67  "(.+)?" /* Any remainding data. */
68 static DetectParseRegex parse_regex;
69 
70 static int DetectHostbitMatch (DetectEngineThreadCtx *, Packet *,
71  const Signature *, const SigMatchCtx *);
72 static int DetectHostbitSetup (DetectEngineCtx *, Signature *, const char *);
73 void DetectHostbitFree (DetectEngineCtx *, void *);
74 #ifdef UNITTESTS
75 void HostBitsRegisterTests(void);
76 #endif
77 
79 {
80  sigmatch_table[DETECT_HOSTBITS].name = "hostbits";
81  sigmatch_table[DETECT_HOSTBITS].desc = "operate on host flag";
82 // sigmatch_table[DETECT_HOSTBITS].url = "/rules/flow-keywords.html#flowbits";
83  sigmatch_table[DETECT_HOSTBITS].Match = DetectHostbitMatch;
84  sigmatch_table[DETECT_HOSTBITS].Setup = DetectHostbitSetup;
86 #ifdef UNITTESTS
88 #endif
89  /* this is compatible to ip-only signatures */
91 
92  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
93 }
94 
95 static int DetectHostbitMatchToggle (Packet *p, const DetectXbitsData *fd)
96 {
97  switch (fd->tracker) {
99  if (p->host_src == NULL) {
100  p->host_src = HostGetHostFromHash(&p->src);
101  if (p->host_src == NULL)
102  return 0;
103  }
104  else
105  HostLock(p->host_src);
106 
107  HostBitToggle(p->host_src,fd->idx,p->ts.tv_sec + fd->expire);
108  HostUnlock(p->host_src);
109  break;
111  if (p->host_dst == NULL) {
112  p->host_dst = HostGetHostFromHash(&p->dst);
113  if (p->host_dst == NULL)
114  return 0;
115  }
116  else
117  HostLock(p->host_dst);
118 
119  HostBitToggle(p->host_dst,fd->idx,p->ts.tv_sec + fd->expire);
120  HostUnlock(p->host_dst);
121  break;
122  }
123  return 1;
124 }
125 
126 /* return true even if bit not found */
127 static int DetectHostbitMatchUnset (Packet *p, const DetectXbitsData *fd)
128 {
129  switch (fd->tracker) {
131  if (p->host_src == NULL) {
133  if (p->host_src == NULL)
134  return 1;
135  } else
136  HostLock(p->host_src);
137 
138  HostBitUnset(p->host_src,fd->idx);
139  HostUnlock(p->host_src);
140  break;
142  if (p->host_dst == NULL) {
144  if (p->host_dst == NULL)
145  return 1;
146  } else
147  HostLock(p->host_dst);
148 
149  HostBitUnset(p->host_dst,fd->idx);
150  HostUnlock(p->host_dst);
151  break;
152  }
153  return 1;
154 }
155 
156 static int DetectHostbitMatchSet (Packet *p, const DetectXbitsData *fd)
157 {
158  switch (fd->tracker) {
160  if (p->host_src == NULL) {
161  p->host_src = HostGetHostFromHash(&p->src);
162  if (p->host_src == NULL)
163  return 0;
164  } else
165  HostLock(p->host_src);
166 
167  HostBitSet(p->host_src,fd->idx,p->ts.tv_sec + fd->expire);
168  HostUnlock(p->host_src);
169  break;
171  if (p->host_dst == NULL) {
172  p->host_dst = HostGetHostFromHash(&p->dst);
173  if (p->host_dst == NULL)
174  return 0;
175  } else
176  HostLock(p->host_dst);
177 
178  HostBitSet(p->host_dst,fd->idx, p->ts.tv_sec + fd->expire);
179  HostUnlock(p->host_dst);
180  break;
181  }
182  return 1;
183 }
184 
185 static int DetectHostbitMatchIsset (Packet *p, const DetectXbitsData *fd)
186 {
187  int r = 0;
188  switch (fd->tracker) {
190  if (p->host_src == NULL) {
192  if (p->host_src == NULL)
193  return 0;
194  } else
195  HostLock(p->host_src);
196 
197  r = HostBitIsset(p->host_src,fd->idx, p->ts.tv_sec);
198  HostUnlock(p->host_src);
199  return r;
201  if (p->host_dst == NULL) {
203  if (p->host_dst == NULL)
204  return 0;
205  } else
206  HostLock(p->host_dst);
207 
208  r = HostBitIsset(p->host_dst,fd->idx, p->ts.tv_sec);
209  HostUnlock(p->host_dst);
210  return r;
211  }
212  return 0;
213 }
214 
215 static int DetectHostbitMatchIsnotset (Packet *p, const DetectXbitsData *fd)
216 {
217  int r = 0;
218  switch (fd->tracker) {
220  if (p->host_src == NULL) {
222  if (p->host_src == NULL)
223  return 1;
224  } else
225  HostLock(p->host_src);
226 
227  r = HostBitIsnotset(p->host_src,fd->idx, p->ts.tv_sec);
228  HostUnlock(p->host_src);
229  return r;
231  if (p->host_dst == NULL) {
233  if (p->host_dst == NULL)
234  return 1;
235  } else
236  HostLock(p->host_dst);
237 
238  r = HostBitIsnotset(p->host_dst,fd->idx, p->ts.tv_sec);
239  HostUnlock(p->host_dst);
240  return r;
241  }
242  return 0;
243 }
244 
246 {
247  switch (xd->cmd) {
249  return DetectHostbitMatchIsset(p,xd);
251  return DetectHostbitMatchIsnotset(p,xd);
253  return DetectHostbitMatchSet(p,xd);
255  return DetectHostbitMatchUnset(p,xd);
257  return DetectHostbitMatchToggle(p,xd);
258  default:
259  SCLogError(SC_ERR_UNKNOWN_VALUE, "unknown cmd %" PRIu32 "", xd->cmd);
260  return 0;
261  }
262 
263  return 0;
264 }
265 
266 /*
267  * returns 0: no match
268  * 1: match
269  * -1: error
270  */
271 
272 static int DetectHostbitMatch (DetectEngineThreadCtx *det_ctx, Packet *p,
273  const Signature *s, const SigMatchCtx *ctx)
274 {
275  const DetectXbitsData *xd = (const DetectXbitsData *)ctx;
276  if (xd == NULL)
277  return 0;
278 
279  return DetectXbitMatchHost(p, xd);
280 }
281 
282 static int DetectHostbitParse(const char *str, char *cmd, int cmd_len,
283  char *name, int name_len, char *dir, int dir_len)
284 {
285  int count, rc;
286  size_t pcre2len;
287 
288  count = DetectParsePcreExec(&parse_regex, str, 0, 0);
289  if (count != 2 && count != 3 && count != 4) {
291  "\"%s\" is not a valid setting for hostbits.", str);
292  return 0;
293  }
294 
295  pcre2len = cmd_len;
296  rc = pcre2_substring_copy_bynumber(parse_regex.match, 1, (PCRE2_UCHAR8 *)cmd, &pcre2len);
297  if (rc < 0) {
298  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
299  return 0;
300  }
301 
302  if (count >= 3) {
303  pcre2len = name_len;
304  rc = pcre2_substring_copy_bynumber(parse_regex.match, 2, (PCRE2_UCHAR8 *)name, &pcre2len);
305  if (rc < 0) {
306  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
307  return 0;
308  }
309  if (count >= 4) {
310  pcre2len = dir_len;
311  rc = pcre2_substring_copy_bynumber(
312  parse_regex.match, 3, (PCRE2_UCHAR8 *)dir, &pcre2len);
313  if (rc < 0) {
314  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
315  return 0;
316  }
317  }
318  }
319 
320  return 1;
321 }
322 
323 int DetectHostbitSetup (DetectEngineCtx *de_ctx, Signature *s, const char *rawstr)
324 {
325  DetectXbitsData *cd = NULL;
326  SigMatch *sm = NULL;
327  uint8_t fb_cmd = 0;
328  uint8_t hb_dir = 0;
329  char fb_cmd_str[16] = "", fb_name[256] = "";
330  char hb_dir_str[16] = "";
331 
332  if (!DetectHostbitParse(rawstr, fb_cmd_str, sizeof(fb_cmd_str),
333  fb_name, sizeof(fb_name), hb_dir_str, sizeof(hb_dir_str))) {
334  return -1;
335  }
336 
337  if (strlen(hb_dir_str) > 0) {
338  if (strcmp(hb_dir_str, "src") == 0)
339  hb_dir = DETECT_XBITS_TRACK_IPSRC;
340  else if (strcmp(hb_dir_str, "dst") == 0)
341  hb_dir = DETECT_XBITS_TRACK_IPDST;
342  else if (strcmp(hb_dir_str, "both") == 0) {
343  //hb_dir = DETECT_XBITS_TRACK_IPBOTH;
344  SCLogError(SC_ERR_UNIMPLEMENTED, "'both' not implemented");
345  goto error;
346  } else {
347  // TODO
348  goto error;
349  }
350  }
351 
352  if (strcmp(fb_cmd_str,"noalert") == 0) {
353  fb_cmd = DETECT_XBITS_CMD_NOALERT;
354  } else if (strcmp(fb_cmd_str,"isset") == 0) {
355  fb_cmd = DETECT_XBITS_CMD_ISSET;
356  } else if (strcmp(fb_cmd_str,"isnotset") == 0) {
357  fb_cmd = DETECT_XBITS_CMD_ISNOTSET;
358  } else if (strcmp(fb_cmd_str,"set") == 0) {
359  fb_cmd = DETECT_XBITS_CMD_SET;
360  } else if (strcmp(fb_cmd_str,"unset") == 0) {
361  fb_cmd = DETECT_XBITS_CMD_UNSET;
362  } else if (strcmp(fb_cmd_str,"toggle") == 0) {
363  fb_cmd = DETECT_XBITS_CMD_TOGGLE;
364  } else {
365  SCLogError(SC_ERR_UNKNOWN_VALUE, "ERROR: flowbits action \"%s\" is not supported.", fb_cmd_str);
366  goto error;
367  }
368 
369  switch (fb_cmd) {
371  if (strlen(fb_name) != 0)
372  goto error;
373  s->flags |= SIG_FLAG_NOALERT;
374  return 0;
380  default:
381  if (strlen(fb_name) == 0)
382  goto error;
383  break;
384  }
385 
386  cd = SCMalloc(sizeof(DetectXbitsData));
387  if (unlikely(cd == NULL))
388  goto error;
389 
391  cd->cmd = fb_cmd;
392  cd->tracker = hb_dir;
393  cd->type = VAR_TYPE_HOST_BIT;
394  cd->expire = 300;
395 
396  SCLogDebug("idx %" PRIu32 ", cmd %s, name %s",
397  cd->idx, fb_cmd_str, strlen(fb_name) ? fb_name : "(none)");
398 
399  /* Okay so far so good, lets get this into a SigMatch
400  * and put it in the Signature. */
401  sm = SigMatchAlloc();
402  if (sm == NULL)
403  goto error;
404 
405  sm->type = DETECT_HOSTBITS;
406  sm->ctx = (void *)cd;
407 
408  switch (fb_cmd) {
409  /* case DETECT_XBITS_CMD_NOALERT can't happen here */
410 
413  /* checks, so packet list */
415  break;
416 
420  /* modifiers, only run when entire sig has matched */
422  break;
423 
424  // suppress coverity warning as scan-build-7 warns w/o this.
425  // coverity[deadcode : FALSE]
426  default:
427  goto error;
428  }
429 
430  return 0;
431 
432 error:
433  if (cd != NULL)
434  SCFree(cd);
435  if (sm != NULL)
436  SCFree(sm);
437  return -1;
438 }
439 
441 {
442  DetectXbitsData *fd = (DetectXbitsData *)ptr;
443 
444  if (fd == NULL)
445  return;
446 
447  SCFree(fd);
448 }
449 
450 #ifdef UNITTESTS
451 
452 static void HostBitsTestSetup(void)
453 {
454  StorageInit();
455  HostBitInitCtx();
456  StorageFinalize();
457  HostInitConfig(true);
458 }
459 
460 static void HostBitsTestShutdown(void)
461 {
462  HostCleanup();
463  StorageCleanup();
464 }
465 
466 static int HostBitsTestParse01(void)
467 {
468  char cmd[16] = "", name[256] = "", dir[16] = "";
469 
470  /* No direction. */
471  FAIL_IF(!DetectHostbitParse("isset,name", cmd, sizeof(cmd), name,
472  sizeof(name), dir, sizeof(dir)));
473  FAIL_IF(strcmp(cmd, "isset") != 0);
474  FAIL_IF(strcmp(name, "name") != 0);
475  FAIL_IF(strlen(dir));
476 
477  /* No direction, leading space. */
478  *cmd = '\0';
479  *name = '\0';
480  *dir = '\0';
481  FAIL_IF(!DetectHostbitParse("isset, name", cmd, sizeof(cmd), name,
482  sizeof(name), dir, sizeof(dir)));
483  FAIL_IF(strcmp(cmd, "isset") != 0);
484  FAIL_IF(strcmp(name, "name") != 0);
485 
486  /* No direction, trailing space. */
487  *cmd = '\0';
488  *name = '\0';
489  *dir = '\0';
490  FAIL_IF(!DetectHostbitParse("isset,name ", cmd, sizeof(cmd), name,
491  sizeof(name), dir, sizeof(dir)));
492  FAIL_IF(strcmp(cmd, "isset") != 0);
493  FAIL_IF(strcmp(name, "name") != 0);
494 
495  /* No direction, leading and trailing space. */
496  *cmd = '\0';
497  *name = '\0';
498  *dir = '\0';
499  FAIL_IF(!DetectHostbitParse("isset, name ", cmd, sizeof(cmd), name,
500  sizeof(name), dir, sizeof(dir)));
501  FAIL_IF(strcmp(cmd, "isset") != 0);
502  FAIL_IF(strcmp(name, "name") != 0);
503 
504  /* With direction. */
505  *cmd = '\0';
506  *name = '\0';
507  *dir = '\0';
508  FAIL_IF(!DetectHostbitParse("isset,name,src", cmd, sizeof(cmd), name,
509  sizeof(name), dir, sizeof(dir)));
510  FAIL_IF(strcmp(cmd, "isset") != 0);
511  FAIL_IF(strcmp(name, "name") != 0);
512  FAIL_IF(strcmp(dir, "src") != 0);
513 
514  /* With direction - leading and trailing spaces on name. */
515  *cmd = '\0';
516  *name = '\0';
517  *dir = '\0';
518  FAIL_IF(!DetectHostbitParse("isset, name ,src", cmd, sizeof(cmd), name,
519  sizeof(name), dir, sizeof(dir)));
520  FAIL_IF(strcmp(cmd, "isset") != 0);
521  FAIL_IF(strcmp(name, "name") != 0);
522  FAIL_IF(strcmp(dir, "src") != 0);
523 
524  /* With direction - space around direction. */
525  *cmd = '\0';
526  *name = '\0';
527  *dir = '\0';
528  FAIL_IF(!DetectHostbitParse("isset, name , src ", cmd, sizeof(cmd), name,
529  sizeof(name), dir, sizeof(dir)));
530  FAIL_IF(strcmp(cmd, "isset") != 0);
531  FAIL_IF(strcmp(name, "name") != 0);
532  FAIL_IF(strcmp(dir, "src") != 0);
533 
534  /* Name with space, no direction - should fail. */
535  *cmd = '\0';
536  *name = '\0';
537  *dir = '\0';
538  FAIL_IF(DetectHostbitParse("isset, name withspace ", cmd, sizeof(cmd), name,
539  sizeof(name), dir, sizeof(dir)));
540 
541  PASS;
542 }
543 
544 /**
545  * \test HostBitsTestSig01 is a test for a valid noalert flowbits option
546  *
547  * \retval 1 on succces
548  * \retval 0 on failure
549  */
550 
551 static int HostBitsTestSig01(void)
552 {
553  uint8_t *buf = (uint8_t *)
554  "GET /one/ HTTP/1.1\r\n"
555  "Host: one.example.org\r\n"
556  "\r\n";
557  uint16_t buflen = strlen((char *)buf);
558  Packet *p = PacketGetFromAlloc();
559  FAIL_IF_NULL(p);
560  Signature *s = NULL;
561  ThreadVars th_v;
562  DetectEngineThreadCtx *det_ctx = NULL;
563  DetectEngineCtx *de_ctx = NULL;
564 
565  memset(&th_v, 0, sizeof(th_v));
566  p->src.family = AF_INET;
567  p->dst.family = AF_INET;
568  p->payload = buf;
569  p->payload_len = buflen;
570  p->proto = IPPROTO_TCP;
571 
572  HostBitsTestSetup();
573 
576 
577  de_ctx->flags |= DE_QUIET;
578 
579  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (hostbits:set,abc; content:\"GET \"; sid:1;)");
580  FAIL_IF_NULL(s);
581 
583  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
584 
585  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
586 
587  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
589  PacketFree(p);
590  HostBitsTestShutdown();
591  PASS;
592 }
593 
594 /**
595  * \test various options
596  *
597  * \retval 1 on succces
598  * \retval 0 on failure
599  */
600 
601 static int HostBitsTestSig02(void)
602 {
603  Signature *s = NULL;
604  ThreadVars th_v;
605  DetectEngineCtx *de_ctx = NULL;
606 
607  memset(&th_v, 0, sizeof(th_v));
608 
611 
612  de_ctx->flags |= DE_QUIET;
613 
615  "alert ip any any -> any any (hostbits:isset,abc,src; content:\"GET \"; sid:1;)");
616  FAIL_IF_NULL(s);
617 
619  "alert ip any any -> any any (hostbits:isnotset,abc,dst; content:\"GET \"; sid:2;)");
620  FAIL_IF_NULL(s);
621 
623  "alert ip any any -> any any (hostbits:!isset,abc,dst; content:\"GET \"; sid:3;)");
624  FAIL_IF_NOT_NULL(s);
625 
626 /* TODO reenable after both is supported
627  s = DetectEngineAppendSig(de_ctx,
628  "alert ip any any -> any any (hostbits:set,abc,both; content:\"GET \"; sid:3;)");
629  FAIL_IF_NULL(s);
630 */
632  "alert ip any any -> any any (hostbits:unset,abc,src; content:\"GET \"; sid:4;)");
633  FAIL_IF_NULL(s);
634 
636  "alert ip any any -> any any (hostbits:toggle,abc,dst; content:\"GET \"; sid:5;)");
637  FAIL_IF_NULL(s);
638 
640  PASS;
641 }
642 
643 /**
644  * \test HostBitsTestSig03 is a test check idx value
645  *
646  * \retval 1 on succces
647  * \retval 0 on failure
648  */
649 
650 static int HostBitsTestSig03(void)
651 {
652  uint8_t *buf = (uint8_t *)
653  "GET /one/ HTTP/1.1\r\n"
654  "Host: one.example.org\r\n"
655  "\r\n";
656  uint16_t buflen = strlen((char *)buf);
657  Packet *p = PacketGetFromAlloc();
658  if (unlikely(p == NULL))
659  return 0;
660  Signature *s = NULL;
661  ThreadVars th_v;
662  DetectEngineThreadCtx *det_ctx = NULL;
663  DetectEngineCtx *de_ctx = NULL;
664  int idx = 0;
665 
666  memset(&th_v, 0, sizeof(th_v));
667  p->src.family = AF_INET;
668  p->dst.family = AF_INET;
669  p->payload = buf;
670  p->payload_len = buflen;
671  p->proto = IPPROTO_TCP;
672 
673  HostBitsTestSetup();
674 
677 
678  de_ctx->flags |= DE_QUIET;
679 
680  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"isset option\"; hostbits:isset,fbt; content:\"GET \"; sid:1;)");
681  FAIL_IF_NULL(s);
682 
684  FAIL_IF(idx != 1);
685 
687  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
688 
689  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
690 
691  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
693  HostBitsTestShutdown();
694 
695  SCFree(p);
696  PASS;
697 }
698 
699 /**
700  * \brief this function registers unit tests for HostBits
701  */
703 {
704  UtRegisterTest("HostBitsTestParse01", HostBitsTestParse01);
705  UtRegisterTest("HostBitsTestSig01", HostBitsTestSig01);
706  UtRegisterTest("HostBitsTestSig02", HostBitsTestSig02);
707  UtRegisterTest("HostBitsTestSig03", HostBitsTestSig03);
708 }
709 #endif /* UNITTESTS */
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:45
HostUnlock
void HostUnlock(Host *h)
Definition: host.c:491
Packet_::proto
uint8_t proto
Definition: decode.h:449
detect-engine.h
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SigTableElmt_::desc
const char * desc
Definition: detect.h:1269
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:2474
HostBitToggle
void HostBitToggle(Host *h, uint32_t idx, uint32_t expire)
Definition: host-bit.c:147
StorageInit
void StorageInit(void)
Definition: util-storage.c:67
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1257
flow-util.h
DetectParseRegex
Definition: detect-parse.h:42
SigTableElmt_::name
const char * name
Definition: detect.h:1267
HostBitsRegisterTests
void HostBitsRegisterTests(void)
this function registers unit tests for HostBits
Definition: detect-hostbits.c:702
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
Packet_::host_src
struct Host_ * host_src
Definition: decode.h:584
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:567
PARSE_REGEX
#define PARSE_REGEX
Definition: detect-hostbits.c:64
threads.h
SigInit
Signature * SigInit(DetectEngineCtx *, const char *)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2115
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1261
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:811
DetectXbitsData_::cmd
uint8_t cmd
Definition: detect-xbits.h:44
HostGetHostFromHash
Host * HostGetHostFromHash(Address *a)
Definition: host.c:505
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2433
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:295
DetectHostbitsRegister
void DetectHostbitsRegister(void)
Definition: detect-hostbits.c:78
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1790
SC_ERR_PCRE_GET_SUBSTRING
@ SC_ERR_PCRE_GET_SUBSTRING
Definition: util-error.h:34
Packet_::host_dst
struct Host_ * host_dst
Definition: decode.h:585
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1252
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
HostBitIsset
int HostBitIsset(Host *h, uint32_t idx, uint32_t ts)
Definition: host-bit.c:157
util-unittest.h
DETECT_HOSTBITS
@ DETECT_HOSTBITS
Definition: detect-engine-register.h:89
DETECT_SM_LIST_POSTMATCH
@ DETECT_SM_LIST_POSTMATCH
Definition: detect.h:98
DetectXbitMatchHost
int DetectXbitMatchHost(Packet *p, const DetectXbitsData *xd)
Definition: detect-hostbits.c:245
DETECT_XBITS_CMD_ISNOTSET
#define DETECT_XBITS_CMD_ISNOTSET
Definition: detect-xbits.h:30
HostBitIsnotset
int HostBitIsnotset(Host *h, uint32_t idx, uint32_t ts)
Definition: host-bit.c:170
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
DetectEngineThreadCtx_
Definition: detect.h:1060
SC_ERR_UNKNOWN_VALUE
@ SC_ERR_UNKNOWN_VALUE
Definition: util-error.h:159
HostBitUnset
void HostBitUnset(Host *h, uint32_t idx)
Definition: host-bit.c:139
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2597
HostCleanup
void HostCleanup(void)
Cleanup the host engine.
Definition: host.c:346
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
PacketFree
void PacketFree(Packet *p)
Return a malloced packet.
Definition: decode.c:134
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:89
app-layer-parser.h
HostLock
void HostLock(Host *h)
Definition: host.c:486
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:324
DetectXbitsData_::type
enum VarTypes type
Definition: detect-xbits.h:48
HostBitSet
void HostBitSet(Host *h, uint32_t idx, uint32_t expire)
Definition: host-bit.c:131
Signature_::flags
uint32_t flags
Definition: detect.h:549
Packet_
Definition: decode.h:427
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:1235
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:1948
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:316
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:2420
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3142
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
Packet_::ts
struct timeval ts
Definition: decode.h:470
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3354
SigMatch_::type
uint16_t type
Definition: detect.h:322
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
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
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:817
SIG_FLAG_NOALERT
#define SIG_FLAG_NOALERT
Definition: detect.h:216
detect-hostbits.h
SC_ERR_UNIMPLEMENTED
@ SC_ERR_UNIMPLEMENTED
Definition: util-error.h:118
VAR_TYPE_HOST_BIT
@ VAR_TYPE_HOST_BIT
Definition: util-var.h:39
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
str
#define str(s)
Definition: suricata-common.h:272
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:548
SigMatch_
a single match condition for a signature
Definition: detect.h:321
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:2394
HostLookupHostFromHash
Host * HostLookupHostFromHash(Address *a)
look up a host in the hash
Definition: host.c:604
Address_::family
char family
Definition: decode.h:123
Packet_::dst
Address dst
Definition: decode.h:432
HostInitConfig
void HostInitConfig(bool quiet)
initialize the configuration
Definition: host.c:175
DETECT_XBITS_CMD_SET
#define DETECT_XBITS_CMD_SET
Definition: detect-xbits.h:27
DetectHostbitFree
void DetectHostbitFree(DetectEngineCtx *, void *)
Definition: detect-hostbits.c:440
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:812
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
SIGMATCH_IPONLY_COMPAT
#define SIGMATCH_IPONLY_COMPAT
Definition: detect.h:1455
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:431
host-bit.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1259