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