suricata
reputation.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2019 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
22  * \author Victor Julien <victor@inliniac.net>
23  * Original Idea by Matt Jonkman
24  *
25  * IP Reputation Module, initial API for IPV4 and IPV6 feed
26  */
27 
28 #include "suricata-common.h"
29 #include "detect.h"
30 #include "reputation.h"
31 #include "threads.h"
32 #include "conf.h"
33 
34 #include "util-byte.h"
35 #include "util-debug.h"
36 #include "util-error.h"
37 #include "util-ip.h"
38 #include "util-path.h"
39 #include "util-print.h"
40 #include "util-unittest.h"
41 #include "util-validate.h"
42 
43 /** effective reputation version, atomic as the host
44  * time out code will use it to check if a host's
45  * reputation info is outdated. */
46 SC_ATOMIC_DECLARE(uint32_t, srep_eversion);
47 /** reputation version set to the host's reputation,
48  * this will be set to 1 before rep files are loaded,
49  * so hosts will always have a minimal value of 1 */
50 static uint32_t srep_version = 0;
51 
52 static uint32_t SRepIncrVersion(void)
53 {
54  return ++srep_version;
55 }
56 
57 static uint32_t SRepGetVersion(void)
58 {
59  return srep_version;
60 }
61 
62 void SRepResetVersion(void)
63 {
64  srep_version = 0;
65 }
66 
67 static uint32_t SRepGetEffectiveVersion(void)
68 {
69  return SC_ATOMIC_GET(srep_eversion);
70 }
71 
72 static void SRepCIDRFreeUserData(void *data)
73 {
74  if (data != NULL)
75  SCFree(data);
76 }
77 
78 static void SRepCIDRAddNetblock(SRepCIDRTree *cidr_ctx, char *ip, int cat, uint8_t value)
79 {
80  SReputation *user_data = NULL;
81  if ((user_data = SCCalloc(1, sizeof(SReputation))) == NULL) {
82  FatalError("Error allocating memory. Exiting");
83  }
84 
85  user_data->version = SRepGetVersion();
86  user_data->rep[cat] = value;
87 
88  if (strchr(ip, ':') != NULL) {
89  if (cidr_ctx->srepIPV6_tree[cat] == NULL) {
90  cidr_ctx->srepIPV6_tree[cat] = SCRadixCreateRadixTree(SRepCIDRFreeUserData, NULL);
91  if (cidr_ctx->srepIPV6_tree[cat] == NULL) {
92  SCLogDebug("Error initializing Reputation IPV6 with CIDR module for cat %d", cat);
93  exit(EXIT_FAILURE);
94  }
95  SCLogDebug("Reputation IPV6 with CIDR module for cat %d initialized", cat);
96  }
97 
98  SCLogDebug("adding ipv6 host %s", ip);
99  if (!SCRadixAddKeyIPV6String(ip, cidr_ctx->srepIPV6_tree[cat], (void *)user_data)) {
100  SCFree(user_data);
101  if (sc_errno != SC_EEXIST)
102  SCLogWarning("failed to add ipv6 host %s", ip);
103  }
104 
105  } else {
106  if (cidr_ctx->srepIPV4_tree[cat] == NULL) {
107  cidr_ctx->srepIPV4_tree[cat] = SCRadixCreateRadixTree(SRepCIDRFreeUserData, NULL);
108  if (cidr_ctx->srepIPV4_tree[cat] == NULL) {
109  SCLogDebug("Error initializing Reputation IPV4 with CIDR module for cat %d", cat);
110  exit(EXIT_FAILURE);
111  }
112  SCLogDebug("Reputation IPV4 with CIDR module for cat %d initialized", cat);
113  }
114 
115  SCLogDebug("adding ipv4 host %s", ip);
116  if (!SCRadixAddKeyIPV4String(ip, cidr_ctx->srepIPV4_tree[cat], (void *)user_data)) {
117  SCFree(user_data);
118  if (sc_errno != SC_EEXIST)
119  SCLogWarning("failed to add ipv4 host %s", ip);
120  }
121  }
122 }
123 
124 static int8_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 -1;
130 
131  SReputation *r = (SReputation *)user_data;
132  return r->rep[cat];
133 }
134 
135 static int8_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 -1;
141 
142  SReputation *r = (SReputation *)user_data;
143  return r->rep[cat];
144 }
145 
146 int8_t SRepCIDRGetIPRepSrc(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
147 {
148  int8_t rep = -3;
149 
150  if (PacketIsIPv4(p))
151  rep = SRepCIDRGetIPv4IPRep(cidr_ctx, (uint8_t *)GET_IPV4_SRC_ADDR_PTR(p), cat);
152  else if (PacketIsIPv6(p))
153  rep = SRepCIDRGetIPv6IPRep(cidr_ctx, (uint8_t *)GET_IPV6_SRC_ADDR(p), cat);
154 
155  return rep;
156 }
157 
158 int8_t SRepCIDRGetIPRepDst(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
159 {
160  int8_t rep = -3;
161 
162  if (PacketIsIPv4(p))
163  rep = SRepCIDRGetIPv4IPRep(cidr_ctx, (uint8_t *)GET_IPV4_DST_ADDR_PTR(p), cat);
164  else if (PacketIsIPv6(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/reputation reload is complete. */
173 {
174  (void) SC_ATOMIC_ADD(srep_eversion, 1);
175  SCLogDebug("effective Reputation version %u", SRepGetEffectiveVersion());
176 }
177 
179 {
180  SCFree(h->iprep);
181  h->iprep = NULL;
182  DEBUG_VALIDATE_BUG_ON(SC_ATOMIC_GET(h->use_cnt) != 1);
183  HostDecrUsecnt(h);
184 }
185 
186 /** \brief Set effective reputation version after
187  * reputation initialization is complete. */
188 static void SRepInitComplete(void)
189 {
190  (void) SC_ATOMIC_SET(srep_eversion, 1);
191  SCLogDebug("effective Reputation version %u", SRepGetEffectiveVersion());
192 }
193 
194 /** \brief Check if a Host is timed out wrt ip rep, meaning a new
195  * version is in place.
196  *
197  * We clean up the old version here.
198  *
199  * \param h host
200  *
201  * \retval 0 not timed out
202  * \retval 1 timed out
203  */
205 {
206  BUG_ON(h == NULL);
207 
208  if (h->iprep == NULL)
209  return 1;
210 
211  uint32_t eversion = SRepGetEffectiveVersion();
212  SReputation *r = h->iprep;
213  if (r->version < eversion) {
214  SCLogDebug("host %p has reputation version %u, "
215  "effective version is %u", h, r->version, eversion);
216  SRepFreeHostData(h);
217  return 1;
218  }
219 
220  return 0;
221 }
222 
223 static int SRepCatSplitLine(char *line, uint8_t *cat, char *shortname, size_t shortname_len)
224 {
225  size_t line_len = strlen(line);
226  char *ptrs[2] = {NULL,NULL};
227  int i = 0;
228  int idx = 0;
229  char *origline = line;
230 
231  while (i < (int)line_len) {
232  if (line[i] == ',' || line[i] == '\n' || line[i] == '\0' || i == (int)(line_len - 1)) {
233  line[i] = '\0';
234 
235  ptrs[idx] = line;
236  idx++;
237 
238  line += (i+1);
239  i = 0;
240 
241  if (line >= origline + line_len)
242  break;
243  if (strlen(line) == 0)
244  break;
245  if (idx == 2)
246  break;
247  } else {
248  i++;
249  }
250  }
251 
252  if (idx != 2) {
253  return -1;
254  }
255 
256  SCLogDebug("%s, %s", ptrs[0], ptrs[1]);
257 
258  int c;
259  if (StringParseI32RangeCheck(&c, 10, 0, (const char *)ptrs[0], 0, SREP_MAX_CATS - 1) < 0)
260  return -1;
261 
262  *cat = (uint8_t)c;
263  strlcpy(shortname, ptrs[1], shortname_len);
264  return 0;
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] == '\r' || line[i] == '\0' ||
282  i == (int)(line_len - 1)) {
283  line[i] = '\0';
284 
285  ptrs[idx] = line;
286  idx++;
287 
288  line += (i+1);
289  i = 0;
290 
291  if (line >= origline + line_len)
292  break;
293  if (strlen(line) == 0)
294  break;
295  if (idx == 3)
296  break;
297  } else {
298  i++;
299  }
300  }
301 
302  if (idx != 3) {
303  return -1;
304  }
305 
306  //SCLogInfo("%s, %s, %s", ptrs[0], ptrs[1], ptrs[2]);
307 
308  if (strcmp(ptrs[0], "ip") == 0)
309  return 1;
310 
311  uint8_t c, v;
312  if (StringParseU8RangeCheck(&c, 10, 0, (const char *)ptrs[1], 0, SREP_MAX_CATS - 1) < 0)
313  return -1;
314 
315  if (StringParseU8RangeCheck(&v, 10, 0, (const char *)ptrs[2], 0, SREP_MAX_VAL) < 0)
316  return -1;
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("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("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("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 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 = SCCalloc(1, sizeof(SReputation));
486  if (h->iprep != NULL) {
487  HostIncrUsecnt(h);
488  }
489  }
490  if (h->iprep != NULL) {
491  SReputation *rep = h->iprep;
492 
493  /* if version is outdated, it's an older entry that we'll
494  * now replace. */
495  if (rep->version != SRepGetVersion()) {
496  memset(rep, 0x00, sizeof(SReputation));
497  }
498 
499  rep->version = SRepGetVersion();
500  rep->rep[cat] = value;
501 
502  SCLogDebug("host %p iprep %p setting cat %u to value %u",
503  h, h->iprep, cat, value);
504 #ifdef DEBUG
505  if (SCLogDebugEnabled()) {
506  int i;
507  for (i = 0; i < SREP_MAX_CATS; i++) {
508  if (rep->rep[i] == 0)
509  continue;
510 
511  SCLogDebug("--> host %p iprep %p cat %d to value %u",
512  h, h->iprep, i, rep->rep[i]);
513  }
514  }
515 #endif
516  }
517 
518  HostRelease(h);
519  }
520  }
521  }
522 
523  return 0;
524 }
525 
526 /**
527  * \brief Create the path if default-rule-path was specified
528  * \param sig_file The name of the file
529  * \retval str Pointer to the string path + sig_file
530  */
531 static char *SRepCompleteFilePath(char *file)
532 {
533  const char *defaultpath = NULL;
534  char *path = NULL;
535 
536  /* Path not specified */
537  if (PathIsRelative(file)) {
538  if (ConfGet("default-reputation-path", &defaultpath) == 1) {
539  SCLogDebug("Default path: %s", defaultpath);
540  size_t path_len = sizeof(char) * (strlen(defaultpath) +
541  strlen(file) + 2);
542  path = SCMalloc(path_len);
543  if (unlikely(path == NULL))
544  return NULL;
545  strlcpy(path, defaultpath, path_len);
546 #if defined OS_WIN32 || defined __CYGWIN__
547  if (path[strlen(path) - 1] != '\\')
548  strlcat(path, "\\\\", path_len);
549 #else
550  if (path[strlen(path) - 1] != '/')
551  strlcat(path, "/", path_len);
552 #endif
553  strlcat(path, file, path_len);
554  } else {
555  path = SCStrdup(file);
556  if (unlikely(path == NULL))
557  return NULL;
558  }
559  } else {
560  path = SCStrdup(file);
561  if (unlikely(path == NULL))
562  return NULL;
563  }
564  return path;
565 }
566 
567 /** \brief init reputation
568  *
569  * \param de_ctx detection engine ctx for tracking iprep version
570  *
571  * \retval 0 ok
572  * \retval -1 error
573  *
574  * If this function is called more than once, the category file
575  * is not reloaded.
576  */
578 {
579  ConfNode *files;
580  ConfNode *file = NULL;
581  const char *filename = NULL;
582  int init = 0;
583 
585  if (de_ctx->srepCIDR_ctx == NULL)
586  exit(EXIT_FAILURE);
587  SRepCIDRTree *cidr_ctx = de_ctx->srepCIDR_ctx;
588 
589  if (SRepGetVersion() == 0) {
590  SC_ATOMIC_INIT(srep_eversion);
591  init = 1;
592  }
593 
594  /* if both settings are missing, we assume the user doesn't want ip rep */
595  (void)ConfGet("reputation-categories-file", &filename);
596  files = ConfGetNode("reputation-files");
597  if (filename == NULL && files == NULL) {
598  SCLogConfig("IP reputation disabled");
599  return 0;
600  }
601 
602  if (files == NULL) {
603  SCLogError("\"reputation-files\" not set");
604  return -1;
605  }
606 
607  if (init) {
608  if (filename == NULL) {
609  SCLogError("\"reputation-categories-file\" not set");
610  return -1;
611  }
612 
613  /* init even if we have reputation files, so that when we
614  * have a live reload, we have inited the cats */
615  if (SRepLoadCatFile(filename) < 0) {
616  SCLogError("failed to load reputation "
617  "categories file %s",
618  filename);
619  return -1;
620  }
621  }
622 
623  de_ctx->srep_version = SRepIncrVersion();
624  SCLogDebug("Reputation version %u", de_ctx->srep_version);
625 
626  /* ok, let's load reputation files from the general config */
627  if (files != NULL) {
628  TAILQ_FOREACH(file, &files->head, next) {
629  char *sfile = SRepCompleteFilePath(file->val);
630  if (sfile) {
631  SCLogInfo("Loading reputation file: %s", sfile);
632 
633  int r = SRepLoadFile(cidr_ctx, sfile);
634  if (r < 0){
635  if (de_ctx->failure_fatal) {
636  exit(EXIT_FAILURE);
637  }
638  }
639  SCFree(sfile);
640  }
641  }
642  }
643 
644  /* Set effective rep version.
645  * On live reload we will handle this after de_ctx has been swapped */
646  if (init) {
647  SRepInitComplete();
648  }
649 
650  HostPrintStats();
651  return 0;
652 }
653 
655  if (de_ctx->srepCIDR_ctx != NULL) {
656  int i;
657  for (i = 0; i < SREP_MAX_CATS; i++) {
658  if (de_ctx->srepCIDR_ctx->srepIPV4_tree[i] != NULL) {
660  de_ctx->srepCIDR_ctx->srepIPV4_tree[i] = NULL;
661  }
662 
663  if (de_ctx->srepCIDR_ctx->srepIPV6_tree[i] != NULL) {
665  de_ctx->srepCIDR_ctx->srepIPV6_tree[i] = NULL;
666  }
667  }
668 
670  de_ctx->srepCIDR_ctx = NULL;
671  }
672 }
673 
674 #ifdef UNITTESTS
675 #include "tests/reputation.c"
676 #endif
SREP_SHORTNAME_LEN
#define SREP_SHORTNAME_LEN
Definition: reputation.c:337
util-byte.h
SReputation_
Definition: reputation.h:40
len
uint8_t len
Definition: app-layer-dnp3.h:2
SREP_MAX_CATS
#define SREP_MAX_CATS
Definition: reputation.h:32
SCRadixAddKeyIPV6String
bool SCRadixAddKeyIPV6String(const char *str, SCRadixTree *tree, void *user)
Adds a new IPV6/netblock to the Radix tree from a string.
Definition: util-radix-tree.c:1063
SReputation_::rep
uint8_t rep[SREP_MAX_CATS]
Definition: reputation.h:42
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:314
SRepFreeHostData
void SRepFreeHostData(Host *h)
Definition: reputation.c:178
SRepCatGetByShortname
uint8_t SRepCatGetByShortname(char *shortname)
Definition: reputation.c:340
ConfNode_::val
char * val
Definition: conf.h:34
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:386
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
ConfGetNode
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:181
threads.h
Address_::address
union Address_::@26 address
HostRelease
void HostRelease(Host *h)
Definition: host.c:461
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:332
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:841
HostGetHostFromHash
Host * HostGetHostFromHash(Address *a)
Definition: host.c:486
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:853
Address_
Definition: decode.h:108
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:1565
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:1623
HostIncrUsecnt
#define HostIncrUsecnt(h)
Definition: host.h:112
GET_IPV6_DST_ADDR
#define GET_IPV6_DST_ADDR(p)
Definition: decode.h:200
SCRadixAddKeyIPV4String
bool SCRadixAddKeyIPV4String(const char *str, SCRadixTree *tree, void *user)
Adds a new IPV4/netblock to the Radix tree from a string.
Definition: util-radix-tree.c:988
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:195
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:440
DetectEngineCtx_::srepCIDR_ctx
SRepCIDRTree * srepCIDR_ctx
Definition: detect.h:856
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:368
DetectEngineCtx_::failure_fatal
bool failure_fatal
Definition: detect.h:842
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:230
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:405
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:300
Packet_
Definition: decode.h:473
conf.h
reputation.h
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
SRepReloadComplete
void SRepReloadComplete(void)
Increment effective reputation version after a rule/reputation reload is complete.
Definition: reputation.c:172
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:204
Host_::iprep
void * iprep
Definition: host.h:69
SRepCIDRGetIPRepSrc
int8_t SRepCIDRGetIPRepSrc(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
Definition: reputation.c:146
GET_IPV4_SRC_ADDR_PTR
#define GET_IPV4_SRC_ADDR_PTR(p)
Definition: decode.h:194
suricata-common.h
util-path.h
version
uint8_t version
Definition: decode-gre.h:1
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
FatalError
#define FatalError(...)
Definition: util-debug.h:502
SReputation_::version
uint32_t version
Definition: reputation.h:41
util-validate.h
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
SC_EEXIST
@ SC_EEXIST
Definition: util-error.h:32
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
GET_IPV6_SRC_ADDR
#define GET_IPV6_SRC_ADDR(p)
Definition: decode.h:199
SRepInit
int SRepInit(DetectEngineCtx *de_ctx)
init reputation
Definition: reputation.c:577
SCFree
#define SCFree(p)
Definition: util-mem.h:61
ConfNode_
Definition: conf.h:32
SRepCIDRGetIPRepDst
int8_t SRepCIDRGetIPRepDst(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
Definition: reputation.c:158
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:284
sc_errno
thread_local SCError sc_errno
Definition: util-error.c:31
reputation.c
SREP_MAX_VAL
#define SREP_MAX_VAL
Definition: reputation.h:33
SRepResetVersion
void SRepResetVersion(void)
Definition: reputation.c:62
SRepCIDRTree_::srepIPV4_tree
SCRadixTree * srepIPV4_tree[SREP_MAX_CATS]
Definition: reputation.h:36
Address_::family
char family
Definition: decode.h:109
SRepDestroy
void SRepDestroy(DetectEngineCtx *de_ctx)
Definition: reputation.c:654
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
Host_
Definition: host.h:58
SCLogDebugEnabled
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
Definition: util-debug.c:767
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
SRepCIDRTree_::srepIPV6_tree
SCRadixTree * srepIPV6_tree[SREP_MAX_CATS]
Definition: reputation.h:37