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-ip.h"
32 #include "util-radix-tree.h"
33 #include "util-unittest.h"
34 #include "threads.h"
35 #include "util-print.h"
36 #include "host.h"
37 #include "conf.h"
38 #include "detect.h"
39 #include "reputation.h"
40 
41 /** effective reputation version, atomic as the host
42  * time out code will use it to check if a host's
43  * reputation info is outdated. */
44 SC_ATOMIC_DECLARE(uint32_t, srep_eversion);
45 /** reputation version set to the host's reputation,
46  * this will be set to 1 before rep files are loaded,
47  * so hosts will always have a minial value of 1 */
48 static uint32_t srep_version = 0;
49 
50 static uint32_t SRepIncrVersion(void)
51 {
52  return ++srep_version;
53 }
54 
55 static uint32_t SRepGetVersion(void)
56 {
57  return srep_version;
58 }
59 
60 void SRepResetVersion(void)
61 {
62  srep_version = 0;
63 }
64 
65 static uint32_t SRepGetEffectiveVersion(void)
66 {
67  return SC_ATOMIC_GET(srep_eversion);
68 }
69 
70 static void SRepCIDRFreeUserData(void *data)
71 {
72  if (data != NULL)
73  SCFree(data);
74 
75  return;
76 }
77 
78 static void SRepCIDRAddNetblock(SRepCIDRTree *cidr_ctx, char *ip, int cat, int value)
79 {
80  SReputation *user_data = NULL;
81  if ((user_data = SCMalloc(sizeof(SReputation))) == NULL) {
82  SCLogError(SC_ERR_FATAL, "Error allocating memory. Exiting");
83  exit(EXIT_FAILURE);
84  }
85  memset(user_data, 0x00, sizeof(SReputation));
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) == NULL) {
103  "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) {
119  "failed to add ipv4 host %s", ip);
120  }
121  }
122 }
123 
124 static uint8_t SRepCIDRGetIPv4IPRep(SRepCIDRTree *cidr_ctx, uint8_t *ipv4_addr, uint8_t cat)
125 {
126  void *user_data = NULL;
127  (void)SCRadixFindKeyIPV4BestMatch(ipv4_addr, cidr_ctx->srepIPV4_tree[cat], &user_data);
128  if (user_data == NULL)
129  return 0;
130 
131  SReputation *r = (SReputation *)user_data;
132  return r->rep[cat];
133 }
134 
135 static uint8_t SRepCIDRGetIPv6IPRep(SRepCIDRTree *cidr_ctx, uint8_t *ipv6_addr, uint8_t cat)
136 {
137  void *user_data = NULL;
138  (void)SCRadixFindKeyIPV6BestMatch(ipv6_addr, cidr_ctx->srepIPV6_tree[cat], &user_data);
139  if (user_data == NULL)
140  return 0;
141 
142  SReputation *r = (SReputation *)user_data;
143  return r->rep[cat];
144 }
145 
146 uint8_t SRepCIDRGetIPRepSrc(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
147 {
148  uint8_t rep = 0;
149 
150  if (PKT_IS_IPV4(p))
151  rep = SRepCIDRGetIPv4IPRep(cidr_ctx, (uint8_t *)GET_IPV4_SRC_ADDR_PTR(p), cat);
152  else if (PKT_IS_IPV6(p))
153  rep = SRepCIDRGetIPv6IPRep(cidr_ctx, (uint8_t *)GET_IPV6_SRC_ADDR(p), cat);
154 
155  return rep;
156 }
157 
158 uint8_t SRepCIDRGetIPRepDst(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
159 {
160  uint8_t rep = 0;
161 
162  if (PKT_IS_IPV4(p))
163  rep = SRepCIDRGetIPv4IPRep(cidr_ctx, (uint8_t *)GET_IPV4_DST_ADDR_PTR(p), cat);
164  else if (PKT_IS_IPV6(p))
165  rep = SRepCIDRGetIPv6IPRep(cidr_ctx, (uint8_t *)GET_IPV6_DST_ADDR(p), cat);
166 
167  return rep;
168 }
169 
170 /** \brief Increment effective reputation version after
171  * a rule/reputatio reload is complete. */
173 {
174  (void) SC_ATOMIC_ADD(srep_eversion, 1);
175  SCLogDebug("effective Reputation version %u", SRepGetEffectiveVersion());
176 }
177 
178 /** \brief Set effective reputation version after
179  * reputation initialization is complete. */
180 static void SRepInitComplete(void)
181 {
182  (void) SC_ATOMIC_SET(srep_eversion, 1);
183  SCLogDebug("effective Reputation version %u", SRepGetEffectiveVersion());
184 }
185 
186 /** \brief Check if a Host is timed out wrt ip rep, meaning a new
187  * version is in place.
188  *
189  * We clean up the old version here.
190  *
191  * \param h host
192  *
193  * \retval 0 not timed out
194  * \retval 1 timed out
195  */
197 {
198  BUG_ON(h == NULL);
199 
200  if (h->iprep == NULL)
201  return 1;
202 
203  uint32_t eversion = SRepGetEffectiveVersion();
204  SReputation *r = h->iprep;
205  if (r->version < eversion) {
206  SCLogDebug("host %p has reputation version %u, "
207  "effective version is %u", h, r->version, eversion);
208 
209  SCFree(h->iprep);
210  h->iprep = NULL;
211 
212  HostDecrUsecnt(h);
213  return 1;
214  }
215 
216  return 0;
217 }
218 
219 static int SRepCatSplitLine(char *line, uint8_t *cat, char *shortname, size_t shortname_len)
220 {
221  size_t line_len = strlen(line);
222  char *ptrs[2] = {NULL,NULL};
223  int i = 0;
224  int idx = 0;
225  char *origline = line;
226 
227  while (i < (int)line_len) {
228  if (line[i] == ',' || line[i] == '\n' || line[i] == '\0' || i == (int)(line_len - 1)) {
229  line[i] = '\0';
230 
231  ptrs[idx] = line;
232  idx++;
233 
234  line += (i+1);
235  i = 0;
236 
237  if (line >= origline + line_len)
238  break;
239  if (strlen(line) == 0)
240  break;
241  if (idx == 2)
242  break;
243  } else {
244  i++;
245  }
246  }
247 
248  if (idx != 2) {
249  return -1;
250  }
251 
252  SCLogDebug("%s, %s", ptrs[0], ptrs[1]);
253 
254  int c = atoi(ptrs[0]);
255  if (c < 0 || c >= SREP_MAX_CATS) {
256  return -1;
257  }
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 = atoi(ptrs[1]);
309  if (c < 0 || c >= SREP_MAX_CATS) {
310  return -1;
311  }
312 
313  int v = atoi(ptrs[2]);
314  if (v < 0 || v > SREP_MAX_VAL) {
315  return -1;
316  }
317 
318  if (strchr(ptrs[0], '/') != NULL) {
319  SRepCIDRAddNetblock(cidr_ctx, ptrs[0], c, v);
320  return 1;
321  } else {
322  if (inet_pton(AF_INET, ptrs[0], &ip->address) == 1) {
323  ip->family = AF_INET;
324  } else if (inet_pton(AF_INET6, ptrs[0], &ip->address) == 1) {
325  ip->family = AF_INET6;
326  } else {
327  return -1;
328  }
329 
330  *cat = c;
331  *value = v;
332  }
333 
334  return 0;
335 }
336 
337 #define SREP_SHORTNAME_LEN 32
338 static char srep_cat_table[SREP_MAX_CATS][SREP_SHORTNAME_LEN];
339 
340 uint8_t SRepCatGetByShortname(char *shortname)
341 {
342  uint8_t cat;
343  for (cat = 0; cat < SREP_MAX_CATS; cat++) {
344  if (strcmp(srep_cat_table[cat], shortname) == 0)
345  return cat;
346  }
347 
348  return 0;
349 }
350 
351 static int SRepLoadCatFile(const char *filename)
352 {
353  int r = 0;
354  FILE *fp = fopen(filename, "r");
355 
356  if (fp == NULL) {
357  SCLogError(SC_ERR_OPENING_RULE_FILE, "opening ip rep file %s: %s", filename, strerror(errno));
358  return -1;
359  }
360 
361  r = SRepLoadCatFileFromFD(fp);
362 
363  fclose(fp);
364  fp = NULL;
365  return r;
366 }
367 
369 {
370  char line[8192] = "";
371  Address a;
372  memset(&a, 0x00, sizeof(a));
373  a.family = AF_INET;
374  memset(&srep_cat_table, 0x00, sizeof(srep_cat_table));
375 
376  BUG_ON(SRepGetVersion() > 0);
377 
378  while(fgets(line, (int)sizeof(line), fp) != NULL) {
379  size_t len = strlen(line);
380  if (len == 0)
381  continue;
382 
383  /* ignore comments and empty lines */
384  if (line[0] == '\n' || line [0] == '\r' || line[0] == ' ' || line[0] == '#' || line[0] == '\t')
385  continue;
386 
387  while (isspace((unsigned char)line[--len]));
388 
389  /* Check if we have a trailing newline, and remove it */
390  len = strlen(line);
391  if (len == 0)
392  continue;
393 
394  if (line[len - 1] == '\n' || line[len - 1] == '\r') {
395  line[len - 1] = '\0';
396  }
397 
398  uint8_t cat = 0;
399  char shortname[SREP_SHORTNAME_LEN];
400  if (SRepCatSplitLine(line, &cat, shortname, sizeof(shortname)) == 0) {
401  strlcpy(srep_cat_table[cat], shortname, SREP_SHORTNAME_LEN);
402  } else {
403  SCLogError(SC_ERR_NO_REPUTATION, "bad line \"%s\"", line);
404  }
405  }
406 
407  SCLogDebug("IP Rep categories:");
408  int i;
409  for (i = 0; i < SREP_MAX_CATS; i++) {
410  if (strlen(srep_cat_table[i]) == 0)
411  continue;
412  SCLogDebug("CAT %d, name %s", i, srep_cat_table[i]);
413  }
414  return 0;
415 }
416 
417 static int SRepLoadFile(SRepCIDRTree *cidr_ctx, char *filename)
418 {
419  int r = 0;
420  FILE *fp = fopen(filename, "r");
421 
422  if (fp == NULL) {
423  SCLogError(SC_ERR_OPENING_RULE_FILE, "opening ip rep file %s: %s", filename, strerror(errno));
424  return -1;
425  }
426 
427  r = SRepLoadFileFromFD(cidr_ctx, fp);
428 
429  fclose(fp);
430  fp = NULL;
431  return r;
432 
433 }
434 
435 int SRepLoadFileFromFD(SRepCIDRTree *cidr_ctx, FILE *fp)
436 {
437  char line[8192] = "";
438  Address a;
439  memset(&a, 0x00, sizeof(a));
440  a.family = AF_INET;
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  uint8_t cat = 0, value = 0;
463  int r = SRepSplitLine(cidr_ctx, line, &a, &cat, &value);
464  if (r < 0) {
465  SCLogError(SC_ERR_NO_REPUTATION, "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(SC_ERR_NO_REPUTATION, "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 
587  de_ctx->srepCIDR_ctx = (SRepCIDRTree *)SCMalloc(sizeof(SRepCIDRTree));
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(SC_ERR_NO_REPUTATION, "\"reputation-files\" not set");
613  return -1;
614  }
615 
616  if (init) {
617  if (filename == NULL) {
618  SCLogError(SC_ERR_NO_REPUTATION, "\"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(SC_ERR_NO_REPUTATION, "failed to load reputation "
626  "categories file %s", filename);
627  return -1;
628  }
629  }
630 
631  de_ctx->srep_version = SRepIncrVersion();
632  SCLogDebug("Reputation version %u", de_ctx->srep_version);
633 
634  /* ok, let's load reputation files from the general config */
635  if (files != NULL) {
636  TAILQ_FOREACH(file, &files->head, next) {
637  char *sfile = SRepCompleteFilePath(file->val);
638  if (sfile) {
639  SCLogInfo("Loading reputation file: %s", sfile);
640 
641  int r = SRepLoadFile(cidr_ctx, sfile);
642  if (r < 0){
643  if (de_ctx->failure_fatal == 1) {
644  exit(EXIT_FAILURE);
645  }
646  }
647  SCFree(sfile);
648  }
649  }
650  }
651 
652  /* Set effective rep version.
653  * On live reload we will handle this after de_ctx has been swapped */
654  if (init) {
655  SRepInitComplete();
656  }
657 
658  HostPrintStats();
659  return 0;
660 }
661 
663  if (de_ctx->srepCIDR_ctx != NULL) {
664  int i;
665  for (i = 0; i < SREP_MAX_CATS; i++) {
666  if (de_ctx->srepCIDR_ctx->srepIPV4_tree[i] != NULL) {
668  de_ctx->srepCIDR_ctx->srepIPV4_tree[i] = NULL;
669  }
670 
671  if (de_ctx->srepCIDR_ctx->srepIPV6_tree[i] != NULL) {
673  de_ctx->srepCIDR_ctx->srepIPV6_tree[i] = NULL;
674  }
675  }
676 
677  SCFree(de_ctx->srepCIDR_ctx);
678  de_ctx->srepCIDR_ctx = NULL;
679  }
680 }
681 
682 #ifdef UNITTESTS
683 #include "tests/reputation.c"
684 #endif
void HostPrintStats(void)
print some host stats
Definition: host.c:287
int SRepInit(DetectEngineCtx *de_ctx)
init reputation
Definition: reputation.c:579
#define GET_IPV4_SRC_ADDR_PTR(p)
Definition: decode.h:215
void HostRelease(Host *h)
Definition: host.c:475
int PathIsRelative(const char *path)
Check if a path is relative.
Definition: util-path.c:64
#define SCLogDebug(...)
Definition: util-debug.h:335
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct HtpBodyChunk_ * next
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
#define BUG_ON(x)
void SRepDestroy(DetectEngineCtx *de_ctx)
Definition: reputation.c:662
#define unlikely(expr)
Definition: util-optimize.h:35
#define GET_IPV4_DST_ADDR_PTR(p)
Definition: decode.h:216
uint8_t SRepCIDRGetIPRepSrc(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
Definition: reputation.c:146
size_t strlcat(char *, const char *src, size_t siz)
Definition: util-strlcatu.c:45
SCRadixTree * srepIPV4_tree[SREP_MAX_CATS]
Definition: reputation.h:35
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:107
#define PKT_IS_IPV6(p)
Definition: decode.h:253
#define SREP_MAX_CATS
Definition: reputation.h:31
uint32_t srep_version
Definition: detect.h:771
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.
SCRadixTree * SCRadixCreateRadixTree(void(*Free)(void *), void(*PrintData)(void *))
Creates a new Radix tree.
char * val
Definition: conf.h:34
#define PKT_IS_IPV4(p)
Definition: decode.h:252
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:331
int SRepHostTimedOut(Host *h)
Check if a Host is timed out wrt ip rep, meaning a new version is in place.
Definition: reputation.c:196
main detection engine ctx
Definition: detect.h:761
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
Definition: util-debug.c:624
#define SREP_SHORTNAME_LEN
Definition: reputation.c:337
SCRadixNode * SCRadixAddKeyIPV6String(const char *str, SCRadixTree *tree, void *user)
Adds a new IPV6/netblock to the Radix tree from a string.
SCRadixTree * srepIPV6_tree[SREP_MAX_CATS]
Definition: reputation.h:36
#define SC_ATOMIC_INIT(name)
Initialize the previously declared atomic variable and it&#39;s lock.
Definition: util-atomic.h:81
void SCRadixReleaseRadixTree(SCRadixTree *tree)
Frees a Radix tree and all its nodes.
uint8_t rep[SREP_MAX_CATS]
Definition: reputation.h:41
char family
Definition: decode.h:112
#define SREP_MAX_VAL
Definition: reputation.h:32
#define GET_IPV6_DST_ADDR(p)
Definition: decode.h:221
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:294
int SRepLoadFileFromFD(SRepCIDRTree *cidr_ctx, FILE *fp)
Definition: reputation.c:435
#define HostIncrUsecnt(h)
Definition: host.h:112
uint32_t version
Definition: reputation.h:40
SCRadixNode * SCRadixAddKeyIPV4String(const char *str, SCRadixTree *tree, void *user)
Adds a new IPV4/netblock to the Radix tree from a string.
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
Definition: util-print.c:267
Host * HostGetHostFromHash(Address *a)
Definition: host.c:500
#define HostDecrUsecnt(h)
Definition: host.h:114
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
Definition: util-debug.h:281
int SRepLoadCatFileFromFD(FILE *fp)
Definition: reputation.c:368
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: conf.h:32
#define SCMalloc(a)
Definition: util-mem.h:222
#define GET_IPV6_SRC_ADDR(p)
Definition: decode.h:220
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:207
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:254
void * iprep
Definition: host.h:69
uint8_t version
Definition: decode-gre.h:405
#define SCFree(a)
Definition: util-mem.h:322
Definition: host.h:58
void SRepReloadComplete(void)
Increment effective reputation version after a rule/reputatio reload is complete. ...
Definition: reputation.c:172
SRepCIDRTree * srepCIDR_ctx
Definition: detect.h:774
int failure_fatal
Definition: detect.h:763
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:192
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:176
#define SCStrdup(a)
Definition: util-mem.h:268
uint8_t SRepCIDRGetIPRepDst(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
Definition: reputation.c:158
uint8_t SRepCatGetByShortname(char *shortname)
Definition: reputation.c:340
SC_ATOMIC_DECLARE(uint32_t, srep_eversion)
uint8_t len
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
void SRepResetVersion(void)
Definition: reputation.c:60
union Address_::@42 address