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 #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(SC_ERR_FATAL, "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) {
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 
180 {
181  SCFree(h->iprep);
182  h->iprep = NULL;
183  DEBUG_VALIDATE_BUG_ON(SC_ATOMIC_GET(h->use_cnt) != 1);
184  HostDecrUsecnt(h);
185 }
186 
187 /** \brief Set effective reputation version after
188  * reputation initialization is complete. */
189 static void SRepInitComplete(void)
190 {
191  (void) SC_ATOMIC_SET(srep_eversion, 1);
192  SCLogDebug("effective Reputation version %u", SRepGetEffectiveVersion());
193 }
194 
195 /** \brief Check if a Host is timed out wrt ip rep, meaning a new
196  * version is in place.
197  *
198  * We clean up the old version here.
199  *
200  * \param h host
201  *
202  * \retval 0 not timed out
203  * \retval 1 timed out
204  */
206 {
207  BUG_ON(h == NULL);
208 
209  if (h->iprep == NULL)
210  return 1;
211 
212  uint32_t eversion = SRepGetEffectiveVersion();
213  SReputation *r = h->iprep;
214  if (r->version < eversion) {
215  SCLogDebug("host %p has reputation version %u, "
216  "effective version is %u", h, r->version, eversion);
217  SRepFreeHostData(h);
218  return 1;
219  }
220 
221  return 0;
222 }
223 
224 static int SRepCatSplitLine(char *line, uint8_t *cat, char *shortname, size_t shortname_len)
225 {
226  size_t line_len = strlen(line);
227  char *ptrs[2] = {NULL,NULL};
228  int i = 0;
229  int idx = 0;
230  char *origline = line;
231 
232  while (i < (int)line_len) {
233  if (line[i] == ',' || line[i] == '\n' || line[i] == '\0' || i == (int)(line_len - 1)) {
234  line[i] = '\0';
235 
236  ptrs[idx] = line;
237  idx++;
238 
239  line += (i+1);
240  i = 0;
241 
242  if (line >= origline + line_len)
243  break;
244  if (strlen(line) == 0)
245  break;
246  if (idx == 2)
247  break;
248  } else {
249  i++;
250  }
251  }
252 
253  if (idx != 2) {
254  return -1;
255  }
256 
257  SCLogDebug("%s, %s", ptrs[0], ptrs[1]);
258 
259  int c;
260  if (StringParseI32RangeCheck(&c, 10, 0, (const char *)ptrs[0], 0, SREP_MAX_CATS - 1) < 0)
261  return -1;
262 
263  *cat = (uint8_t)c;
264  strlcpy(shortname, ptrs[1], shortname_len);
265  return 0;
266 
267 }
268 
269 /**
270  * \retval 0 valid
271  * \retval 1 header
272  * \retval -1 bad line
273  */
274 static int SRepSplitLine(SRepCIDRTree *cidr_ctx, char *line, Address *ip, uint8_t *cat, uint8_t *value)
275 {
276  size_t line_len = strlen(line);
277  char *ptrs[3] = {NULL,NULL,NULL};
278  int i = 0;
279  int idx = 0;
280  char *origline = line;
281 
282  while (i < (int)line_len) {
283  if (line[i] == ',' || line[i] == '\n' || line[i] == '\0' || i == (int)(line_len - 1)) {
284  line[i] = '\0';
285 
286  ptrs[idx] = line;
287  idx++;
288 
289  line += (i+1);
290  i = 0;
291 
292  if (line >= origline + line_len)
293  break;
294  if (strlen(line) == 0)
295  break;
296  if (idx == 3)
297  break;
298  } else {
299  i++;
300  }
301  }
302 
303  if (idx != 3) {
304  return -1;
305  }
306 
307  //SCLogInfo("%s, %s, %s", ptrs[0], ptrs[1], ptrs[2]);
308 
309  if (strcmp(ptrs[0], "ip") == 0)
310  return 1;
311 
312  uint8_t c, v;
313  if (StringParseU8RangeCheck(&c, 10, 0, (const char *)ptrs[1], 0, SREP_MAX_CATS - 1) < 0)
314  return -1;
315 
316  if (StringParseU8RangeCheck(&v, 10, 0, (const char *)ptrs[2], 0, SREP_MAX_VAL) < 0)
317  return -1;
318 
319  if (strchr(ptrs[0], '/') != NULL) {
320  SRepCIDRAddNetblock(cidr_ctx, ptrs[0], c, v);
321  return 1;
322  } else {
323  if (inet_pton(AF_INET, ptrs[0], &ip->address) == 1) {
324  ip->family = AF_INET;
325  } else if (inet_pton(AF_INET6, ptrs[0], &ip->address) == 1) {
326  ip->family = AF_INET6;
327  } else {
328  return -1;
329  }
330 
331  *cat = c;
332  *value = v;
333  }
334 
335  return 0;
336 }
337 
338 #define SREP_SHORTNAME_LEN 32
339 static char srep_cat_table[SREP_MAX_CATS][SREP_SHORTNAME_LEN];
340 
341 uint8_t SRepCatGetByShortname(char *shortname)
342 {
343  uint8_t cat;
344  for (cat = 0; cat < SREP_MAX_CATS; cat++) {
345  if (strcmp(srep_cat_table[cat], shortname) == 0)
346  return cat;
347  }
348 
349  return 0;
350 }
351 
352 static int SRepLoadCatFile(const char *filename)
353 {
354  int r = 0;
355  FILE *fp = fopen(filename, "r");
356 
357  if (fp == NULL) {
358  SCLogError(SC_ERR_OPENING_RULE_FILE, "opening ip rep file %s: %s", filename, strerror(errno));
359  return -1;
360  }
361 
362  r = SRepLoadCatFileFromFD(fp);
363 
364  fclose(fp);
365  fp = NULL;
366  return r;
367 }
368 
370 {
371  char line[8192] = "";
372  Address a;
373  memset(&a, 0x00, sizeof(a));
374  a.family = AF_INET;
375  memset(&srep_cat_table, 0x00, sizeof(srep_cat_table));
376 
377  BUG_ON(SRepGetVersion() > 0);
378 
379  while(fgets(line, (int)sizeof(line), fp) != NULL) {
380  size_t len = strlen(line);
381  if (len == 0)
382  continue;
383 
384  /* ignore comments and empty lines */
385  if (line[0] == '\n' || line [0] == '\r' || line[0] == ' ' || line[0] == '#' || line[0] == '\t')
386  continue;
387 
388  while (isspace((unsigned char)line[--len]));
389 
390  /* Check if we have a trailing newline, and remove it */
391  len = strlen(line);
392  if (len == 0)
393  continue;
394 
395  if (line[len - 1] == '\n' || line[len - 1] == '\r') {
396  line[len - 1] = '\0';
397  }
398 
399  uint8_t cat = 0;
400  char shortname[SREP_SHORTNAME_LEN];
401  if (SRepCatSplitLine(line, &cat, shortname, sizeof(shortname)) == 0) {
402  strlcpy(srep_cat_table[cat], shortname, SREP_SHORTNAME_LEN);
403  } else {
404  SCLogError(SC_ERR_NO_REPUTATION, "bad line \"%s\"", line);
405  }
406  }
407 
408  SCLogDebug("IP Rep categories:");
409  int i;
410  for (i = 0; i < SREP_MAX_CATS; i++) {
411  if (strlen(srep_cat_table[i]) == 0)
412  continue;
413  SCLogDebug("CAT %d, name %s", i, srep_cat_table[i]);
414  }
415  return 0;
416 }
417 
418 static int SRepLoadFile(SRepCIDRTree *cidr_ctx, char *filename)
419 {
420  int r = 0;
421  FILE *fp = fopen(filename, "r");
422 
423  if (fp == NULL) {
424  SCLogError(SC_ERR_OPENING_RULE_FILE, "opening ip rep file %s: %s", filename, strerror(errno));
425  return -1;
426  }
427 
428  r = SRepLoadFileFromFD(cidr_ctx, fp);
429 
430  fclose(fp);
431  fp = NULL;
432  return r;
433 
434 }
435 
436 int SRepLoadFileFromFD(SRepCIDRTree *cidr_ctx, FILE *fp)
437 {
438  char line[8192] = "";
439 
440  while(fgets(line, (int)sizeof(line), fp) != NULL) {
441  size_t len = strlen(line);
442  if (len == 0)
443  continue;
444 
445  /* ignore comments and empty lines */
446  if (line[0] == '\n' || line [0] == '\r' || line[0] == ' ' || line[0] == '#' || line[0] == '\t')
447  continue;
448 
449  while (isspace((unsigned char)line[--len]));
450 
451  /* Check if we have a trailing newline, and remove it */
452  len = strlen(line);
453  if (len == 0)
454  continue;
455 
456  if (line[len - 1] == '\n' || line[len - 1] == '\r') {
457  line[len - 1] = '\0';
458  }
459 
460  Address a;
461  memset(&a, 0x00, sizeof(a));
462  a.family = AF_INET;
463 
464  uint8_t cat = 0, value = 0;
465  int r = SRepSplitLine(cidr_ctx, line, &a, &cat, &value);
466  if (r < 0) {
467  SCLogError(SC_ERR_NO_REPUTATION, "bad line \"%s\"", line);
468  } else if (r == 0) {
469  if (a.family == AF_INET) {
470  char ipstr[16];
471  PrintInet(AF_INET, (const void *)&a.address, ipstr, sizeof(ipstr));
472  SCLogDebug("%s %u %u", ipstr, cat, value);
473  } else {
474  char ipstr[128];
475  PrintInet(AF_INET6, (const void *)&a.address, ipstr, sizeof(ipstr));
476  SCLogDebug("%s %u %u", ipstr, cat, value);
477  }
478 
479  Host *h = HostGetHostFromHash(&a);
480  if (h == NULL) {
481  SCLogError(SC_ERR_NO_REPUTATION, "failed to get a host, increase host.memcap");
482  break;
483  } else {
484  //SCLogInfo("host %p", h);
485 
486  if (h->iprep == NULL) {
487  h->iprep = SCMalloc(sizeof(SReputation));
488  if (h->iprep != NULL) {
489  memset(h->iprep, 0x00, sizeof(SReputation));
490 
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  memset(de_ctx->srepCIDR_ctx, 0, sizeof(SRepCIDRTree));
593  SRepCIDRTree *cidr_ctx = de_ctx->srepCIDR_ctx;
594 
595  for (i = 0; i < SREP_MAX_CATS; i++) {
596  cidr_ctx->srepIPV4_tree[i] = NULL;
597  cidr_ctx->srepIPV6_tree[i] = NULL;
598  }
599 
600  if (SRepGetVersion() == 0) {
601  SC_ATOMIC_INIT(srep_eversion);
602  init = 1;
603  }
604 
605  /* if both settings are missing, we assume the user doesn't want ip rep */
606  (void)ConfGet("reputation-categories-file", &filename);
607  files = ConfGetNode("reputation-files");
608  if (filename == NULL && files == NULL) {
609  SCLogConfig("IP reputation disabled");
610  return 0;
611  }
612 
613  if (files == NULL) {
614  SCLogError(SC_ERR_NO_REPUTATION, "\"reputation-files\" not set");
615  return -1;
616  }
617 
618  if (init) {
619  if (filename == NULL) {
620  SCLogError(SC_ERR_NO_REPUTATION, "\"reputation-categories-file\" not set");
621  return -1;
622  }
623 
624  /* init even if we have reputation files, so that when we
625  * have a live reload, we have inited the cats */
626  if (SRepLoadCatFile(filename) < 0) {
627  SCLogError(SC_ERR_NO_REPUTATION, "failed to load reputation "
628  "categories file %s", 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 == 1) {
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:338
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:315
SRepFreeHostData
void SRepFreeHostData(Host *h)
Definition: reputation.c:179
PKT_IS_IPV6
#define PKT_IS_IPV6(p)
Definition: decode.h:263
SRepCatGetByShortname
uint8_t SRepCatGetByShortname(char *shortname)
Definition: reputation.c:341
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:965
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:1026
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
ConfGetNode
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:175
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:794
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:253
HostDecrUsecnt
#define HostDecrUsecnt(h)
Definition: host.h:114
DetectEngineCtx_::srep_version
uint32_t srep_version
Definition: detect.h:804
Address_
Definition: decode.h:122
Address_::address
union Address_::@32 address
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:1537
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:1595
HostIncrUsecnt
#define HostIncrUsecnt(h)
Definition: host.h:112
GET_IPV6_DST_ADDR
#define GET_IPV6_DST_ADDR(p)
Definition: decode.h:231
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:330
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:226
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:807
StringParseI32RangeCheck
int StringParseI32RangeCheck(int32_t *res, int base, size_t len, const char *str, int32_t min, int32_t max)
Definition: util-byte.c:704
SRepLoadCatFileFromFD
int SRepLoadCatFileFromFD(FILE *fp)
Definition: reputation.c:369
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
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:281
Packet_
Definition: decode.h:442
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:436
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
StringParseU8RangeCheck
int StringParseU8RangeCheck(uint8_t *res, int base, size_t len, const char *str, uint8_t min, uint8_t max)
Definition: util-byte.c:457
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:205
Host_::iprep
void * iprep
Definition: host.h:69
GET_IPV4_SRC_ADDR_PTR
#define GET_IPV4_SRC_ADDR_PTR(p)
Definition: decode.h:225
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
FatalError
#define FatalError(x,...)
Definition: util-debug.h:532
SReputation_::version
uint32_t version
Definition: reputation.h:40
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.
GET_IPV6_SRC_ADDR
#define GET_IPV6_SRC_ADDR(p)
Definition: decode.h:230
SRepInit
int SRepInit(DetectEngineCtx *de_ctx)
init reputation
Definition: reputation.c:581
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:70
HostPrintStats
void HostPrintStats(void)
print some host stats
Definition: host.c:293
reputation.c
SREP_MAX_VAL
#define SREP_MAX_VAL
Definition: reputation.h:32
SRepResetVersion
void SRepResetVersion(void)
Definition: reputation.c:62
SRepCIDRTree_::srepIPV4_tree
SCRadixTree * srepIPV4_tree[SREP_MAX_CATS]
Definition: reputation.h:35
Address_::family
char family
Definition: decode.h:123
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:376
Host_
Definition: host.h:58
PKT_IS_IPV4
#define PKT_IS_IPV4(p)
Definition: decode.h:262
SCLogDebugEnabled
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
Definition: util-debug.c:647
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:147
DetectEngineCtx_::failure_fatal
int failure_fatal
Definition: detect.h:796
SRepCIDRTree_::srepIPV6_tree
SCRadixTree * srepIPV6_tree[SREP_MAX_CATS]
Definition: reputation.h:36