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