suricata
reputation.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2019 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 Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
22  * \author Victor Julien <victor@inliniac.net>
23  * Original Idea by Matt Jonkman
24  *
25  * IP Reputation Module, initial API for IPV4 and IPV6 feed
26  */
27 
28 #include "suricata-common.h"
29 #include "detect.h"
30 #include "reputation.h"
31 #include "threads.h"
32 #include "conf.h"
33 
34 #include "util-byte.h"
35 #include "util-debug.h"
36 #include "util-error.h"
37 #include "util-ip.h"
38 #include "util-path.h"
39 #include "util-print.h"
40 #include "util-unittest.h"
41 #include "util-validate.h"
42 
43 /** effective reputation version, atomic as the host
44  * time out code will use it to check if a host's
45  * reputation info is outdated. */
46 SC_ATOMIC_DECLARE(uint32_t, srep_eversion);
47 /** reputation version set to the host's reputation,
48  * this will be set to 1 before rep files are loaded,
49  * so hosts will always have a minimal value of 1 */
50 static uint32_t srep_version = 0;
51 
52 static uint32_t SRepIncrVersion(void)
53 {
54  return ++srep_version;
55 }
56 
57 static uint32_t SRepGetVersion(void)
58 {
59  return srep_version;
60 }
61 
62 void SRepResetVersion(void)
63 {
64  srep_version = 0;
65 }
66 
67 static uint32_t SRepGetEffectiveVersion(void)
68 {
69  return SC_ATOMIC_GET(srep_eversion);
70 }
71 
72 static void SRepCIDRFreeUserData(void *data)
73 {
74  if (data != NULL)
75  SCFree(data);
76 
77  return;
78 }
79 
80 static void SRepCIDRAddNetblock(SRepCIDRTree *cidr_ctx, char *ip, int cat, uint8_t value)
81 {
82  SReputation *user_data = NULL;
83  if ((user_data = SCCalloc(1, sizeof(SReputation))) == NULL) {
84  FatalError("Error allocating memory. Exiting");
85  }
86 
87  user_data->version = SRepGetVersion();
88  user_data->rep[cat] = value;
89 
90  if (strchr(ip, ':') != NULL) {
91  if (cidr_ctx->srepIPV6_tree[cat] == NULL) {
92  cidr_ctx->srepIPV6_tree[cat] = SCRadixCreateRadixTree(SRepCIDRFreeUserData, NULL);
93  if (cidr_ctx->srepIPV6_tree[cat] == NULL) {
94  SCLogDebug("Error initializing Reputation IPV6 with CIDR module for cat %d", cat);
95  exit(EXIT_FAILURE);
96  }
97  SCLogDebug("Reputation IPV6 with CIDR module for cat %d initialized", cat);
98  }
99 
100  SCLogDebug("adding ipv6 host %s", ip);
101  if (!SCRadixAddKeyIPV6String(ip, cidr_ctx->srepIPV6_tree[cat], (void *)user_data)) {
102  SCFree(user_data);
103  if (sc_errno != SC_EEXIST)
104  SCLogWarning("failed to add ipv6 host %s", ip);
105  }
106 
107  } else {
108  if (cidr_ctx->srepIPV4_tree[cat] == NULL) {
109  cidr_ctx->srepIPV4_tree[cat] = SCRadixCreateRadixTree(SRepCIDRFreeUserData, NULL);
110  if (cidr_ctx->srepIPV4_tree[cat] == NULL) {
111  SCLogDebug("Error initializing Reputation IPV4 with CIDR module for cat %d", cat);
112  exit(EXIT_FAILURE);
113  }
114  SCLogDebug("Reputation IPV4 with CIDR module for cat %d initialized", cat);
115  }
116 
117  SCLogDebug("adding ipv4 host %s", ip);
118  if (!SCRadixAddKeyIPV4String(ip, cidr_ctx->srepIPV4_tree[cat], (void *)user_data)) {
119  SCFree(user_data);
120  if (sc_errno != SC_EEXIST)
121  SCLogWarning("failed to add ipv4 host %s", ip);
122  }
123  }
124 }
125 
126 static uint8_t SRepCIDRGetIPv4IPRep(SRepCIDRTree *cidr_ctx, uint8_t *ipv4_addr, uint8_t cat)
127 {
128  void *user_data = NULL;
129  (void)SCRadixFindKeyIPV4BestMatch(ipv4_addr, cidr_ctx->srepIPV4_tree[cat], &user_data);
130  if (user_data == NULL)
131  return 0;
132 
133  SReputation *r = (SReputation *)user_data;
134  return r->rep[cat];
135 }
136 
137 static uint8_t SRepCIDRGetIPv6IPRep(SRepCIDRTree *cidr_ctx, uint8_t *ipv6_addr, uint8_t cat)
138 {
139  void *user_data = NULL;
140  (void)SCRadixFindKeyIPV6BestMatch(ipv6_addr, cidr_ctx->srepIPV6_tree[cat], &user_data);
141  if (user_data == NULL)
142  return 0;
143 
144  SReputation *r = (SReputation *)user_data;
145  return r->rep[cat];
146 }
147 
148 uint8_t SRepCIDRGetIPRepSrc(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
149 {
150  uint8_t rep = 0;
151 
152  if (PKT_IS_IPV4(p))
153  rep = SRepCIDRGetIPv4IPRep(cidr_ctx, (uint8_t *)GET_IPV4_SRC_ADDR_PTR(p), cat);
154  else if (PKT_IS_IPV6(p))
155  rep = SRepCIDRGetIPv6IPRep(cidr_ctx, (uint8_t *)GET_IPV6_SRC_ADDR(p), cat);
156 
157  return rep;
158 }
159 
160 uint8_t SRepCIDRGetIPRepDst(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
161 {
162  uint8_t rep = 0;
163 
164  if (PKT_IS_IPV4(p))
165  rep = SRepCIDRGetIPv4IPRep(cidr_ctx, (uint8_t *)GET_IPV4_DST_ADDR_PTR(p), cat);
166  else if (PKT_IS_IPV6(p))
167  rep = SRepCIDRGetIPv6IPRep(cidr_ctx, (uint8_t *)GET_IPV6_DST_ADDR(p), cat);
168 
169  return rep;
170 }
171 
172 /** \brief Increment effective reputation version after
173  * a rule/reputation reload is complete. */
175 {
176  (void) SC_ATOMIC_ADD(srep_eversion, 1);
177  SCLogDebug("effective Reputation version %u", SRepGetEffectiveVersion());
178 }
179 
181 {
182  SCFree(h->iprep);
183  h->iprep = NULL;
184  DEBUG_VALIDATE_BUG_ON(SC_ATOMIC_GET(h->use_cnt) != 1);
185  HostDecrUsecnt(h);
186 }
187 
188 /** \brief Set effective reputation version after
189  * reputation initialization is complete. */
190 static void SRepInitComplete(void)
191 {
192  (void) SC_ATOMIC_SET(srep_eversion, 1);
193  SCLogDebug("effective Reputation version %u", SRepGetEffectiveVersion());
194 }
195 
196 /** \brief Check if a Host is timed out wrt ip rep, meaning a new
197  * version is in place.
198  *
199  * We clean up the old version here.
200  *
201  * \param h host
202  *
203  * \retval 0 not timed out
204  * \retval 1 timed out
205  */
207 {
208  BUG_ON(h == NULL);
209 
210  if (h->iprep == NULL)
211  return 1;
212 
213  uint32_t eversion = SRepGetEffectiveVersion();
214  SReputation *r = h->iprep;
215  if (r->version < eversion) {
216  SCLogDebug("host %p has reputation version %u, "
217  "effective version is %u", h, r->version, eversion);
218  SRepFreeHostData(h);
219  return 1;
220  }
221 
222  return 0;
223 }
224 
225 static int SRepCatSplitLine(char *line, uint8_t *cat, char *shortname, size_t shortname_len)
226 {
227  size_t line_len = strlen(line);
228  char *ptrs[2] = {NULL,NULL};
229  int i = 0;
230  int idx = 0;
231  char *origline = line;
232 
233  while (i < (int)line_len) {
234  if (line[i] == ',' || line[i] == '\n' || line[i] == '\0' || i == (int)(line_len - 1)) {
235  line[i] = '\0';
236 
237  ptrs[idx] = line;
238  idx++;
239 
240  line += (i+1);
241  i = 0;
242 
243  if (line >= origline + line_len)
244  break;
245  if (strlen(line) == 0)
246  break;
247  if (idx == 2)
248  break;
249  } else {
250  i++;
251  }
252  }
253 
254  if (idx != 2) {
255  return -1;
256  }
257 
258  SCLogDebug("%s, %s", ptrs[0], ptrs[1]);
259 
260  int c;
261  if (StringParseI32RangeCheck(&c, 10, 0, (const char *)ptrs[0], 0, SREP_MAX_CATS - 1) < 0)
262  return -1;
263 
264  *cat = (uint8_t)c;
265  strlcpy(shortname, ptrs[1], shortname_len);
266  return 0;
267 
268 }
269 
270 /**
271  * \retval 0 valid
272  * \retval 1 header
273  * \retval -1 bad line
274  */
275 static int SRepSplitLine(SRepCIDRTree *cidr_ctx, char *line, Address *ip, uint8_t *cat, uint8_t *value)
276 {
277  size_t line_len = strlen(line);
278  char *ptrs[3] = {NULL,NULL,NULL};
279  int i = 0;
280  int idx = 0;
281  char *origline = line;
282 
283  while (i < (int)line_len) {
284  if (line[i] == ',' || line[i] == '\n' || line[i] == '\r' || line[i] == '\0' ||
285  i == (int)(line_len - 1)) {
286  line[i] = '\0';
287 
288  ptrs[idx] = line;
289  idx++;
290 
291  line += (i+1);
292  i = 0;
293 
294  if (line >= origline + line_len)
295  break;
296  if (strlen(line) == 0)
297  break;
298  if (idx == 3)
299  break;
300  } else {
301  i++;
302  }
303  }
304 
305  if (idx != 3) {
306  return -1;
307  }
308 
309  //SCLogInfo("%s, %s, %s", ptrs[0], ptrs[1], ptrs[2]);
310 
311  if (strcmp(ptrs[0], "ip") == 0)
312  return 1;
313 
314  uint8_t c, v;
315  if (StringParseU8RangeCheck(&c, 10, 0, (const char *)ptrs[1], 0, SREP_MAX_CATS - 1) < 0)
316  return -1;
317 
318  if (StringParseU8RangeCheck(&v, 10, 0, (const char *)ptrs[2], 0, SREP_MAX_VAL) < 0)
319  return -1;
320 
321  if (strchr(ptrs[0], '/') != NULL) {
322  SRepCIDRAddNetblock(cidr_ctx, ptrs[0], c, v);
323  return 1;
324  } else {
325  if (inet_pton(AF_INET, ptrs[0], &ip->address) == 1) {
326  ip->family = AF_INET;
327  } else if (inet_pton(AF_INET6, ptrs[0], &ip->address) == 1) {
328  ip->family = AF_INET6;
329  } else {
330  return -1;
331  }
332 
333  *cat = c;
334  *value = v;
335  }
336 
337  return 0;
338 }
339 
340 #define SREP_SHORTNAME_LEN 32
341 static char srep_cat_table[SREP_MAX_CATS][SREP_SHORTNAME_LEN];
342 
343 uint8_t SRepCatGetByShortname(char *shortname)
344 {
345  uint8_t cat;
346  for (cat = 0; cat < SREP_MAX_CATS; cat++) {
347  if (strcmp(srep_cat_table[cat], shortname) == 0)
348  return cat;
349  }
350 
351  return 0;
352 }
353 
354 static int SRepLoadCatFile(const char *filename)
355 {
356  int r = 0;
357  FILE *fp = fopen(filename, "r");
358 
359  if (fp == NULL) {
360  SCLogError("opening ip rep file %s: %s", filename, strerror(errno));
361  return -1;
362  }
363 
364  r = SRepLoadCatFileFromFD(fp);
365 
366  fclose(fp);
367  fp = NULL;
368  return r;
369 }
370 
372 {
373  char line[8192] = "";
374  Address a;
375  memset(&a, 0x00, sizeof(a));
376  a.family = AF_INET;
377  memset(&srep_cat_table, 0x00, sizeof(srep_cat_table));
378 
379  BUG_ON(SRepGetVersion() > 0);
380 
381  while(fgets(line, (int)sizeof(line), fp) != NULL) {
382  size_t len = strlen(line);
383  if (len == 0)
384  continue;
385 
386  /* ignore comments and empty lines */
387  if (line[0] == '\n' || line [0] == '\r' || line[0] == ' ' || line[0] == '#' || line[0] == '\t')
388  continue;
389 
390  while (isspace((unsigned char)line[--len]));
391 
392  /* Check if we have a trailing newline, and remove it */
393  len = strlen(line);
394  if (len == 0)
395  continue;
396 
397  if (line[len - 1] == '\n' || line[len - 1] == '\r') {
398  line[len - 1] = '\0';
399  }
400 
401  uint8_t cat = 0;
402  char shortname[SREP_SHORTNAME_LEN];
403  if (SRepCatSplitLine(line, &cat, shortname, sizeof(shortname)) == 0) {
404  strlcpy(srep_cat_table[cat], shortname, SREP_SHORTNAME_LEN);
405  } else {
406  SCLogError("bad line \"%s\"", line);
407  }
408  }
409 
410  SCLogDebug("IP Rep categories:");
411  int i;
412  for (i = 0; i < SREP_MAX_CATS; i++) {
413  if (strlen(srep_cat_table[i]) == 0)
414  continue;
415  SCLogDebug("CAT %d, name %s", i, srep_cat_table[i]);
416  }
417  return 0;
418 }
419 
420 static int SRepLoadFile(SRepCIDRTree *cidr_ctx, char *filename)
421 {
422  int r = 0;
423  FILE *fp = fopen(filename, "r");
424 
425  if (fp == NULL) {
426  SCLogError("opening ip rep file %s: %s", filename, strerror(errno));
427  return -1;
428  }
429 
430  r = SRepLoadFileFromFD(cidr_ctx, fp);
431 
432  fclose(fp);
433  fp = NULL;
434  return r;
435 
436 }
437 
438 int SRepLoadFileFromFD(SRepCIDRTree *cidr_ctx, FILE *fp)
439 {
440  char line[8192] = "";
441 
442  while(fgets(line, (int)sizeof(line), fp) != NULL) {
443  size_t len = strlen(line);
444  if (len == 0)
445  continue;
446 
447  /* ignore comments and empty lines */
448  if (line[0] == '\n' || line [0] == '\r' || line[0] == ' ' || line[0] == '#' || line[0] == '\t')
449  continue;
450 
451  while (isspace((unsigned char)line[--len]));
452 
453  /* Check if we have a trailing newline, and remove it */
454  len = strlen(line);
455  if (len == 0)
456  continue;
457 
458  if (line[len - 1] == '\n' || line[len - 1] == '\r') {
459  line[len - 1] = '\0';
460  }
461 
462  Address a;
463  memset(&a, 0x00, sizeof(a));
464  a.family = AF_INET;
465 
466  uint8_t cat = 0, value = 0;
467  int r = SRepSplitLine(cidr_ctx, line, &a, &cat, &value);
468  if (r < 0) {
469  SCLogError("bad line \"%s\"", line);
470  } else if (r == 0) {
471  if (a.family == AF_INET) {
472  char ipstr[16];
473  PrintInet(AF_INET, (const void *)&a.address, ipstr, sizeof(ipstr));
474  SCLogDebug("%s %u %u", ipstr, cat, value);
475  } else {
476  char ipstr[128];
477  PrintInet(AF_INET6, (const void *)&a.address, ipstr, sizeof(ipstr));
478  SCLogDebug("%s %u %u", ipstr, cat, value);
479  }
480 
481  Host *h = HostGetHostFromHash(&a);
482  if (h == NULL) {
483  SCLogError("failed to get a host, increase host.memcap");
484  break;
485  } else {
486  //SCLogInfo("host %p", h);
487 
488  if (h->iprep == NULL) {
489  h->iprep = SCCalloc(1, sizeof(SReputation));
490  if (h->iprep != NULL) {
491  HostIncrUsecnt(h);
492  }
493  }
494  if (h->iprep != NULL) {
495  SReputation *rep = h->iprep;
496 
497  /* if version is outdated, it's an older entry that we'll
498  * now replace. */
499  if (rep->version != SRepGetVersion()) {
500  memset(rep, 0x00, sizeof(SReputation));
501  }
502 
503  rep->version = SRepGetVersion();
504  rep->rep[cat] = value;
505 
506  SCLogDebug("host %p iprep %p setting cat %u to value %u",
507  h, h->iprep, cat, value);
508 #ifdef DEBUG
509  if (SCLogDebugEnabled()) {
510  int i;
511  for (i = 0; i < SREP_MAX_CATS; i++) {
512  if (rep->rep[i] == 0)
513  continue;
514 
515  SCLogDebug("--> host %p iprep %p cat %d to value %u",
516  h, h->iprep, i, rep->rep[i]);
517  }
518  }
519 #endif
520  }
521 
522  HostRelease(h);
523  }
524  }
525  }
526 
527  return 0;
528 }
529 
530 /**
531  * \brief Create the path if default-rule-path was specified
532  * \param sig_file The name of the file
533  * \retval str Pointer to the string path + sig_file
534  */
535 static char *SRepCompleteFilePath(char *file)
536 {
537  const char *defaultpath = NULL;
538  char *path = NULL;
539 
540  /* Path not specified */
541  if (PathIsRelative(file)) {
542  if (ConfGet("default-reputation-path", &defaultpath) == 1) {
543  SCLogDebug("Default path: %s", defaultpath);
544  size_t path_len = sizeof(char) * (strlen(defaultpath) +
545  strlen(file) + 2);
546  path = SCMalloc(path_len);
547  if (unlikely(path == NULL))
548  return NULL;
549  strlcpy(path, defaultpath, path_len);
550 #if defined OS_WIN32 || defined __CYGWIN__
551  if (path[strlen(path) - 1] != '\\')
552  strlcat(path, "\\\\", path_len);
553 #else
554  if (path[strlen(path) - 1] != '/')
555  strlcat(path, "/", path_len);
556 #endif
557  strlcat(path, file, path_len);
558  } else {
559  path = SCStrdup(file);
560  if (unlikely(path == NULL))
561  return NULL;
562  }
563  } else {
564  path = SCStrdup(file);
565  if (unlikely(path == NULL))
566  return NULL;
567  }
568  return path;
569 }
570 
571 /** \brief init reputation
572  *
573  * \param de_ctx detection engine ctx for tracking iprep version
574  *
575  * \retval 0 ok
576  * \retval -1 error
577  *
578  * If this function is called more than once, the category file
579  * is not reloaded.
580  */
582 {
583  ConfNode *files;
584  ConfNode *file = NULL;
585  const char *filename = NULL;
586  int init = 0;
587  int i = 0;
588 
590  if (de_ctx->srepCIDR_ctx == NULL)
591  exit(EXIT_FAILURE);
592  SRepCIDRTree *cidr_ctx = de_ctx->srepCIDR_ctx;
593 
594  for (i = 0; i < SREP_MAX_CATS; i++) {
595  cidr_ctx->srepIPV4_tree[i] = NULL;
596  cidr_ctx->srepIPV6_tree[i] = NULL;
597  }
598 
599  if (SRepGetVersion() == 0) {
600  SC_ATOMIC_INIT(srep_eversion);
601  init = 1;
602  }
603 
604  /* if both settings are missing, we assume the user doesn't want ip rep */
605  (void)ConfGet("reputation-categories-file", &filename);
606  files = ConfGetNode("reputation-files");
607  if (filename == NULL && files == NULL) {
608  SCLogConfig("IP reputation disabled");
609  return 0;
610  }
611 
612  if (files == NULL) {
613  SCLogError("\"reputation-files\" not set");
614  return -1;
615  }
616 
617  if (init) {
618  if (filename == NULL) {
619  SCLogError("\"reputation-categories-file\" not set");
620  return -1;
621  }
622 
623  /* init even if we have reputation files, so that when we
624  * have a live reload, we have inited the cats */
625  if (SRepLoadCatFile(filename) < 0) {
626  SCLogError("failed to load reputation "
627  "categories file %s",
628  filename);
629  return -1;
630  }
631  }
632 
633  de_ctx->srep_version = SRepIncrVersion();
634  SCLogDebug("Reputation version %u", de_ctx->srep_version);
635 
636  /* ok, let's load reputation files from the general config */
637  if (files != NULL) {
638  TAILQ_FOREACH(file, &files->head, next) {
639  char *sfile = SRepCompleteFilePath(file->val);
640  if (sfile) {
641  SCLogInfo("Loading reputation file: %s", sfile);
642 
643  int r = SRepLoadFile(cidr_ctx, sfile);
644  if (r < 0){
645  if (de_ctx->failure_fatal) {
646  exit(EXIT_FAILURE);
647  }
648  }
649  SCFree(sfile);
650  }
651  }
652  }
653 
654  /* Set effective rep version.
655  * On live reload we will handle this after de_ctx has been swapped */
656  if (init) {
657  SRepInitComplete();
658  }
659 
660  HostPrintStats();
661  return 0;
662 }
663 
665  if (de_ctx->srepCIDR_ctx != NULL) {
666  int i;
667  for (i = 0; i < SREP_MAX_CATS; i++) {
668  if (de_ctx->srepCIDR_ctx->srepIPV4_tree[i] != NULL) {
670  de_ctx->srepCIDR_ctx->srepIPV4_tree[i] = NULL;
671  }
672 
673  if (de_ctx->srepCIDR_ctx->srepIPV6_tree[i] != NULL) {
675  de_ctx->srepCIDR_ctx->srepIPV6_tree[i] = NULL;
676  }
677  }
678 
680  de_ctx->srepCIDR_ctx = NULL;
681  }
682 }
683 
684 #ifdef UNITTESTS
685 #include "tests/reputation.c"
686 #endif
SREP_SHORTNAME_LEN
#define SREP_SHORTNAME_LEN
Definition: reputation.c:340
util-byte.h
SReputation_
Definition: reputation.h:40
len
uint8_t len
Definition: app-layer-dnp3.h:2
SREP_MAX_CATS
#define SREP_MAX_CATS
Definition: reputation.h:32
SCRadixAddKeyIPV6String
bool SCRadixAddKeyIPV6String(const char *str, SCRadixTree *tree, void *user)
Adds a new IPV6/netblock to the Radix tree from a string.
Definition: util-radix-tree.c:1064
SReputation_::rep
uint8_t rep[SREP_MAX_CATS]
Definition: reputation.h:42
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:314
SRepFreeHostData
void SRepFreeHostData(Host *h)
Definition: reputation.c:180
PKT_IS_IPV6
#define PKT_IS_IPV6(p)
Definition: decode.h:246
SRepCatGetByShortname
uint8_t SRepCatGetByShortname(char *shortname)
Definition: reputation.c:343
ConfNode_::val
char * val
Definition: conf.h:34
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:386
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
ConfGetNode
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:181
threads.h
HostRelease
void HostRelease(Host *h)
Definition: host.c:472
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:332
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:836
HostGetHostFromHash
Host * HostGetHostFromHash(Address *a)
Definition: host.c:497
SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint32_t, srep_eversion)
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
HostDecrUsecnt
#define HostDecrUsecnt(h)
Definition: host.h:114
DetectEngineCtx_::srep_version
uint32_t srep_version
Definition: detect.h:848
Address_
Definition: decode.h:115
SCRadixFindKeyIPV4BestMatch
SCRadixNode * SCRadixFindKeyIPV4BestMatch(uint8_t *key_stream, SCRadixTree *tree, void **user_data_result)
Checks if an IPV4 address is present in the tree under a netblock.
Definition: util-radix-tree.c:1591
SCRadixFindKeyIPV6BestMatch
SCRadixNode * SCRadixFindKeyIPV6BestMatch(uint8_t *key_stream, SCRadixTree *tree, void **user_data_result)
Checks if an IPV6 address is present in the tree under a netblock.
Definition: util-radix-tree.c:1649
HostIncrUsecnt
#define HostIncrUsecnt(h)
Definition: host.h:112
GET_IPV6_DST_ADDR
#define GET_IPV6_DST_ADDR(p)
Definition: decode.h:215
SCRadixAddKeyIPV4String
bool SCRadixAddKeyIPV4String(const char *str, SCRadixTree *tree, void *user)
Adds a new IPV4/netblock to the Radix tree from a string.
Definition: util-radix-tree.c:989
util-unittest.h
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
ConfGet
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:335
util-debug.h
SRepCIDRTree_
Definition: reputation.h:35
util-error.h
GET_IPV4_DST_ADDR_PTR
#define GET_IPV4_DST_ADDR_PTR(p)
Definition: decode.h:210
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
strlcat
size_t strlcat(char *, const char *src, size_t siz)
Definition: util-strlcatu.c:45
SCRadixReleaseRadixTree
void SCRadixReleaseRadixTree(SCRadixTree *tree)
Frees a Radix tree and all its nodes.
Definition: util-radix-tree.c:454
DetectEngineCtx_::srepCIDR_ctx
SRepCIDRTree * srepCIDR_ctx
Definition: detect.h:851
StringParseI32RangeCheck
int StringParseI32RangeCheck(int32_t *res, int base, size_t len, const char *str, int32_t min, int32_t max)
Definition: util-byte.c:716
SRepLoadCatFileFromFD
int SRepLoadCatFileFromFD(FILE *fp)
Definition: reputation.c:371
DetectEngineCtx_::failure_fatal
bool failure_fatal
Definition: detect.h:837
util-print.h
detect.h
util-ip.h
PrintInet
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
Definition: util-print.c:262
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
SCRadixCreateRadixTree
SCRadixTree * SCRadixCreateRadixTree(void(*Free)(void *), void(*PrintData)(void *))
Creates a new Radix tree.
Definition: util-radix-tree.c:417
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:300
Address_::address
union Address_::@30 address
Packet_
Definition: decode.h:436
conf.h
reputation.h
SRepLoadFileFromFD
int SRepLoadFileFromFD(SRepCIDRTree *cidr_ctx, FILE *fp)
Definition: reputation.c:438
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:224
StringParseU8RangeCheck
int StringParseU8RangeCheck(uint8_t *res, int base, size_t len, const char *str, uint8_t min, uint8_t max)
Definition: util-byte.c:462
SRepCIDRGetIPRepDst
uint8_t SRepCIDRGetIPRepDst(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
Definition: reputation.c:160
SRepReloadComplete
void SRepReloadComplete(void)
Increment effective reputation version after a rule/reputation reload is complete.
Definition: reputation.c:174
SRepHostTimedOut
int SRepHostTimedOut(Host *h)
Check if a Host is timed out wrt ip rep, meaning a new version is in place.
Definition: reputation.c:206
Host_::iprep
void * iprep
Definition: host.h:69
GET_IPV4_SRC_ADDR_PTR
#define GET_IPV4_SRC_ADDR_PTR(p)
Definition: decode.h:209
suricata-common.h
util-path.h
version
uint8_t version
Definition: decode-gre.h:1
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
FatalError
#define FatalError(...)
Definition: util-debug.h:502
SReputation_::version
uint32_t version
Definition: reputation.h:41
util-validate.h
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
SC_EEXIST
@ SC_EEXIST
Definition: util-error.h:32
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
GET_IPV6_SRC_ADDR
#define GET_IPV6_SRC_ADDR(p)
Definition: decode.h:214
SRepInit
int SRepInit(DetectEngineCtx *de_ctx)
init reputation
Definition: reputation.c:581
SCFree
#define SCFree(p)
Definition: util-mem.h:61
ConfNode_
Definition: conf.h:32
PathIsRelative
int PathIsRelative(const char *path)
Check if a path is relative.
Definition: util-path.c:69
HostPrintStats
void HostPrintStats(void)
print some host stats
Definition: host.c:291
sc_errno
thread_local SCError sc_errno
Definition: util-error.c:31
reputation.c
SREP_MAX_VAL
#define SREP_MAX_VAL
Definition: reputation.h:33
SRepResetVersion
void SRepResetVersion(void)
Definition: reputation.c:62
SRepCIDRTree_::srepIPV4_tree
SCRadixTree * srepIPV4_tree[SREP_MAX_CATS]
Definition: reputation.h:36
Address_::family
char family
Definition: decode.h:116
SRepDestroy
void SRepDestroy(DetectEngineCtx *de_ctx)
Definition: reputation.c:664
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
Host_
Definition: host.h:58
PKT_IS_IPV4
#define PKT_IS_IPV4(p)
Definition: decode.h:245
SCLogDebugEnabled
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
Definition: util-debug.c:771
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:103
SRepCIDRGetIPRepSrc
uint8_t SRepCIDRGetIPRepSrc(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
Definition: reputation.c:148
SRepCIDRTree_::srepIPV6_tree
SCRadixTree * srepIPV6_tree[SREP_MAX_CATS]
Definition: reputation.h:37