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