suricata
host.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2012 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 Victor Julien <victor@inliniac.net>
22  *
23  * Information about hosts.
24  */
25 
26 #include "suricata-common.h"
27 #include "conf.h"
28 
29 #include "util-debug.h"
30 #include "host.h"
31 #include "host-storage.h"
32 #include "host-bit.h"
33 
34 #include "util-random.h"
35 #include "util-misc.h"
36 #include "util-byte.h"
37 #include "util-validate.h"
38 
39 #include "host-queue.h"
40 
41 #include "detect-tag.h"
42 #include "detect-engine-tag.h"
44 
45 #include "util-hash-lookup3.h"
46 
47 static Host *HostGetUsedHost(void);
48 
49 /** host hash table */
50 HostHashRow *host_hash;
51 /** queue with spare hosts */
52 static HostQueue host_spare_q;
54 
55 SC_ATOMIC_DECLARE(uint64_t,host_memuse);
56 SC_ATOMIC_DECLARE(uint32_t,host_counter);
57 SC_ATOMIC_DECLARE(uint32_t,host_prune_idx);
58 
59 /** size of the host object. Maybe updated in HostInitConfig to include
60  * the storage APIs additions. */
61 static uint16_t g_host_size = sizeof(Host);
62 
63 /**
64  * \brief Update memcap value
65  *
66  * \param size new memcap value
67  */
68 int HostSetMemcap(uint64_t size)
69 {
70  if ((uint64_t)SC_ATOMIC_GET(host_memuse) < size) {
71  SC_ATOMIC_SET(host_config.memcap, size);
72  return 1;
73  }
74 
75  return 0;
76 }
77 
78 /**
79  * \brief Return memcap value
80  *
81  * \retval memcap value
82  */
83 uint64_t HostGetMemcap(void)
84 {
85  uint64_t memcapcopy = SC_ATOMIC_GET(host_config.memcap);
86  return memcapcopy;
87 }
88 
89 /**
90  * \brief Return memuse value
91  *
92  * \retval memuse value
93  */
94 uint64_t HostGetMemuse(void)
95 {
96  uint64_t memuse = SC_ATOMIC_GET(host_memuse);
97  return memuse;
98 }
99 
101 {
102  HostEnqueue(&host_spare_q, h);
103  (void) SC_ATOMIC_SUB(host_counter, 1);
104 }
105 
107 {
108  if (!(HOST_CHECK_MEMCAP(g_host_size))) {
109  return NULL;
110  }
111  (void) SC_ATOMIC_ADD(host_memuse, g_host_size);
112 
113  Host *h = SCCalloc(1, g_host_size);
114  if (unlikely(h == NULL))
115  goto error;
116 
117  SCMutexInit(&h->m, NULL);
118  SC_ATOMIC_INIT(h->use_cnt);
119  return h;
120 
121 error:
122  return NULL;
123 }
124 
125 void HostFree(Host *h)
126 {
127  if (h != NULL) {
128  HostClearMemory(h);
129  SCMutexDestroy(&h->m);
130  SCFree(h);
131  (void) SC_ATOMIC_SUB(host_memuse, g_host_size);
132  }
133 }
134 
135 static Host *HostNew(Address *a)
136 {
137  Host *h = HostAlloc();
138  if (h == NULL)
139  goto error;
140 
141  /* copy address */
142  COPY_ADDRESS(a, &h->a);
143 
144  return h;
145 
146 error:
147  return NULL;
148 }
149 
151 {
152  if (h->iprep != NULL) {
153  SRepFreeHostData(h);
154  }
155 
156  if (HostStorageSize() > 0)
157  HostFreeStorage(h);
158 
159  BUG_ON(SC_ATOMIC_GET(h->use_cnt) > 0);
160 }
161 
162 #define HOST_DEFAULT_HASHSIZE 4096
163 #define HOST_DEFAULT_MEMCAP 16777216
164 #define HOST_DEFAULT_PREALLOC 1000
165 
166 /** \brief initialize the configuration
167  * \warning Not thread safe */
168 void HostInitConfig(bool quiet)
169 {
170  SCLogDebug("initializing host engine...");
171  if (HostStorageSize() > 0) {
172  DEBUG_VALIDATE_BUG_ON(sizeof(Host) + HostStorageSize() > UINT16_MAX);
173  g_host_size = (uint16_t)(sizeof(Host) + HostStorageSize());
174  }
175 
176  memset(&host_config, 0, sizeof(host_config));
177  //SC_ATOMIC_INIT(flow_flags);
178  SC_ATOMIC_INIT(host_counter);
179  SC_ATOMIC_INIT(host_memuse);
180  SC_ATOMIC_INIT(host_prune_idx);
181  SC_ATOMIC_INIT(host_config.memcap);
182  HostQueueInit(&host_spare_q);
183 
184  /* set defaults */
185  host_config.hash_rand = (uint32_t)RandomGet();
189 
190  /* Check if we have memcap and hash_size defined at config */
191  const char *conf_val;
192  uint32_t configval = 0;
193 
194  /** set config values for memcap, prealloc and hash_size */
195  if ((ConfGet("host.memcap", &conf_val)) == 1) {
196  uint64_t host_memcap = 0;
197  if (ParseSizeStringU64(conf_val, &host_memcap) < 0) {
198  SCLogError("Error parsing host.memcap "
199  "from conf file - %s. Killing engine",
200  conf_val);
201  exit(EXIT_FAILURE);
202  } else {
203  SC_ATOMIC_SET(host_config.memcap, host_memcap);
204  }
205  }
206  if ((ConfGet("host.hash-size", &conf_val)) == 1) {
207  if (StringParseUint32(&configval, 10, strlen(conf_val),
208  conf_val) > 0) {
209  host_config.hash_size = configval;
210  }
211  }
212 
213  if ((ConfGet("host.prealloc", &conf_val)) == 1) {
214  if (StringParseUint32(&configval, 10, strlen(conf_val),
215  conf_val) > 0) {
216  host_config.prealloc = configval;
217  } else {
218  WarnInvalidConfEntry("host.prealloc", "%"PRIu32, host_config.prealloc);
219  }
220  }
221  SCLogDebug("Host config from suricata.yaml: memcap: %"PRIu64", hash-size: "
222  "%"PRIu32", prealloc: %"PRIu32, SC_ATOMIC_GET(host_config.memcap),
224 
225  /* alloc hash memory */
226  uint64_t hash_size = host_config.hash_size * sizeof(HostHashRow);
227  if (!(HOST_CHECK_MEMCAP(hash_size))) {
228  SCLogError("allocating host hash failed: "
229  "max host memcap is smaller than projected hash size. "
230  "Memcap: %" PRIu64 ", Hash table size %" PRIu64 ". Calculate "
231  "total hash size by multiplying \"host.hash-size\" with %" PRIuMAX ", "
232  "which is the hash bucket size.",
233  SC_ATOMIC_GET(host_config.memcap), hash_size, (uintmax_t)sizeof(HostHashRow));
234  exit(EXIT_FAILURE);
235  }
236  host_hash = SCMallocAligned(host_config.hash_size * sizeof(HostHashRow), CLS);
237  if (unlikely(host_hash == NULL)) {
238  FatalError("Fatal error encountered in HostInitConfig. Exiting...");
239  }
240  memset(host_hash, 0, host_config.hash_size * sizeof(HostHashRow));
241 
242  uint32_t i = 0;
243  for (i = 0; i < host_config.hash_size; i++) {
244  HRLOCK_INIT(&host_hash[i]);
245  }
246  (void) SC_ATOMIC_ADD(host_memuse, (host_config.hash_size * sizeof(HostHashRow)));
247 
248  if (!quiet) {
249  SCLogConfig("allocated %"PRIu64" bytes of memory for the host hash... "
250  "%" PRIu32 " buckets of size %" PRIuMAX "",
251  SC_ATOMIC_GET(host_memuse), host_config.hash_size,
252  (uintmax_t)sizeof(HostHashRow));
253  }
254 
255  /* pre allocate hosts */
256  for (i = 0; i < host_config.prealloc; i++) {
257  if (!(HOST_CHECK_MEMCAP(g_host_size))) {
258  SCLogError("preallocating hosts failed: "
259  "max host memcap reached. Memcap %" PRIu64 ", "
260  "Memuse %" PRIu64 ".",
261  SC_ATOMIC_GET(host_config.memcap),
262  ((uint64_t)SC_ATOMIC_GET(host_memuse) + g_host_size));
263  exit(EXIT_FAILURE);
264  }
265 
266  Host *h = HostAlloc();
267  if (h == NULL) {
268  SCLogError("preallocating host failed: %s", strerror(errno));
269  exit(EXIT_FAILURE);
270  }
271  HostEnqueue(&host_spare_q,h);
272  }
273 
274  if (!quiet) {
275  SCLogConfig("preallocated %" PRIu32 " hosts of size %" PRIu16 "",
276  host_spare_q.len, g_host_size);
277  SCLogConfig("host memory usage: %"PRIu64" bytes, maximum: %"PRIu64,
278  SC_ATOMIC_GET(host_memuse), SC_ATOMIC_GET(host_config.memcap));
279  }
280 
281  return;
282 }
283 
284 /** \brief print some host stats
285  * \warning Not thread safe */
286 void HostPrintStats (void)
287 {
288 #ifdef HOSTBITS_STATS
289  SCLogPerf("hostbits added: %" PRIu32 ", removed: %" PRIu32 ", max memory usage: %" PRIu32 "",
290  hostbits_added, hostbits_removed, hostbits_memuse_max);
291 #endif /* HOSTBITS_STATS */
292  SCLogPerf("host memory usage: %"PRIu64" bytes, maximum: %"PRIu64,
293  SC_ATOMIC_GET(host_memuse), SC_ATOMIC_GET(host_config.memcap));
294  return;
295 }
296 
297 /** \brief shutdown the flow engine
298  * \warning Not thread safe */
299 void HostShutdown(void)
300 {
301  Host *h;
302  uint32_t u;
303 
304  HostPrintStats();
305 
306  /* free spare queue */
307  while((h = HostDequeue(&host_spare_q))) {
308  HostFree(h);
309  }
310 
311  /* clear and free the hash */
312  if (host_hash != NULL) {
313  for (u = 0; u < host_config.hash_size; u++) {
314  h = host_hash[u].head;
315  while (h) {
316  Host *n = h->hnext;
317  HostFree(h);
318  h = n;
319  }
320 
322  }
324  host_hash = NULL;
325  }
326  (void) SC_ATOMIC_SUB(host_memuse, host_config.hash_size * sizeof(HostHashRow));
327  HostQueueDestroy(&host_spare_q);
328  return;
329 }
330 
331 /** \brief Cleanup the host engine
332  *
333  * Cleanup the host engine from tag and threshold.
334  *
335  */
336 void HostCleanup(void)
337 {
338  if (host_hash != NULL) {
339  for (uint32_t u = 0; u < host_config.hash_size; u++) {
340  HostHashRow *hb = &host_hash[u];
341  HRLOCK_LOCK(hb);
342  Host *h = host_hash[u].head;
343  while (h) {
344  if ((SC_ATOMIC_GET(h->use_cnt) > 0) && (h->iprep != NULL)) {
345  /* iprep is attached to host only clear local storage */
346  HostFreeStorage(h);
347  h = h->hnext;
348  } else {
349  Host *n = h->hnext;
350  /* remove from the hash */
351  if (h->hprev != NULL)
352  h->hprev->hnext = h->hnext;
353  if (h->hnext != NULL)
354  h->hnext->hprev = h->hprev;
355  if (hb->head == h)
356  hb->head = h->hnext;
357  if (hb->tail == h)
358  hb->tail = h->hprev;
359  h->hnext = NULL;
360  h->hprev = NULL;
361  HostClearMemory(h);
362  HostMoveToSpare(h);
363  h = n;
364  }
365  }
366  HRLOCK_UNLOCK(hb);
367  }
368  }
369 
370  return;
371 }
372 
373 /* calculate the hash key for this packet
374  *
375  * we're using:
376  * hash_rand -- set at init time
377  * source address
378  */
379 static inline uint32_t HostGetKey(Address *a)
380 {
381  uint32_t key;
382 
383  if (a->family == AF_INET) {
384  uint32_t hash = hashword(&a->addr_data32[0], 1, host_config.hash_rand);
385  key = hash % host_config.hash_size;
386  } else if (a->family == AF_INET6) {
387  uint32_t hash = hashword(a->addr_data32, 4, host_config.hash_rand);
388  key = hash % host_config.hash_size;
389  } else
390  key = 0;
391 
392  return key;
393 }
394 
395 static inline int HostCompare(Host *h, Address *a)
396 {
397  if (h->a.family == a->family) {
398  switch (a->family) {
399  case AF_INET:
400  return (h->a.addr_data32[0] == a->addr_data32[0]);
401  case AF_INET6:
402  return CMP_ADDR(&h->a, a);
403  }
404  }
405  return 0;
406 }
407 
408 /**
409  * \brief Get a new host
410  *
411  * Get a new host. We're checking memcap first and will try to make room
412  * if the memcap is reached.
413  *
414  * \retval h *LOCKED* host on succes, NULL on error.
415  */
416 static Host *HostGetNew(Address *a)
417 {
418  Host *h = NULL;
419 
420  /* get a host from the spare queue */
421  h = HostDequeue(&host_spare_q);
422  if (h == NULL) {
423  /* If we reached the max memcap, we get a used host */
424  if (!(HOST_CHECK_MEMCAP(g_host_size))) {
425  /* declare state of emergency */
426  //if (!(SC_ATOMIC_GET(host_flags) & HOST_EMERGENCY)) {
427  // SC_ATOMIC_OR(host_flags, HOST_EMERGENCY);
428 
429  /* under high load, waking up the flow mgr each time leads
430  * to high cpu usage. Flows are not timed out much faster if
431  * we check a 1000 times a second. */
432  // FlowWakeupFlowManagerThread();
433  //}
434 
435  h = HostGetUsedHost();
436  if (h == NULL) {
437  return NULL;
438  }
439 
440  /* freed a host, but it's unlocked */
441  } else {
442  /* now see if we can alloc a new host */
443  h = HostNew(a);
444  if (h == NULL) {
445  return NULL;
446  }
447 
448  /* host is initialized but *unlocked* */
449  }
450  } else {
451  /* host has been recycled before it went into the spare queue */
452 
453  /* host is initialized (recycled) but *unlocked* */
454  }
455 
456  (void) SC_ATOMIC_ADD(host_counter, 1);
457  SCMutexLock(&h->m);
458  return h;
459 }
460 
461 static void HostInit(Host *h, Address *a)
462 {
463  COPY_ADDRESS(a, &h->a);
464  (void) HostIncrUsecnt(h);
465 }
466 
468 {
469  (void) HostDecrUsecnt(h);
470  SCMutexUnlock(&h->m);
471 }
472 
473 void HostLock(Host *h)
474 {
475  SCMutexLock(&h->m);
476 }
477 
478 void HostUnlock(Host *h)
479 {
480  SCMutexUnlock(&h->m);
481 }
482 
483 
484 /* HostGetHostFromHash
485  *
486  * Hash retrieval function for hosts. Looks up the hash bucket containing the
487  * host pointer. Then compares the packet with the found host to see if it is
488  * the host we need. If it isn't, walk the list until the right host is found.
489  *
490  * returns a *LOCKED* host or NULL
491  */
493 {
494  Host *h = NULL;
495 
496  /* get the key to our bucket */
497  uint32_t key = HostGetKey(a);
498  /* get our hash bucket and lock it */
499  HostHashRow *hb = &host_hash[key];
500  HRLOCK_LOCK(hb);
501 
502  /* see if the bucket already has a host */
503  if (hb->head == NULL) {
504  h = HostGetNew(a);
505  if (h == NULL) {
506  HRLOCK_UNLOCK(hb);
507  return NULL;
508  }
509 
510  /* host is locked */
511  hb->head = h;
512  hb->tail = h;
513 
514  /* got one, now lock, initialize and return */
515  HostInit(h,a);
516 
517  HRLOCK_UNLOCK(hb);
518  return h;
519  }
520 
521  /* ok, we have a host in the bucket. Let's find out if it is our host */
522  h = hb->head;
523 
524  /* see if this is the host we are looking for */
525  if (HostCompare(h, a) == 0) {
526  Host *ph = NULL; /* previous host */
527 
528  while (h) {
529  ph = h;
530  h = h->hnext;
531 
532  if (h == NULL) {
533  h = ph->hnext = HostGetNew(a);
534  if (h == NULL) {
535  HRLOCK_UNLOCK(hb);
536  return NULL;
537  }
538  hb->tail = h;
539 
540  /* host is locked */
541 
542  h->hprev = ph;
543 
544  /* initialize and return */
545  HostInit(h,a);
546 
547  HRLOCK_UNLOCK(hb);
548  return h;
549  }
550 
551  if (HostCompare(h, a) != 0) {
552  /* we found our host, lets put it on top of the
553  * hash list -- this rewards active hosts */
554  if (h->hnext) {
555  h->hnext->hprev = h->hprev;
556  }
557  if (h->hprev) {
558  h->hprev->hnext = h->hnext;
559  }
560  if (h == hb->tail) {
561  hb->tail = h->hprev;
562  }
563 
564  h->hnext = hb->head;
565  h->hprev = NULL;
566  hb->head->hprev = h;
567  hb->head = h;
568 
569  /* found our host, lock & return */
570  SCMutexLock(&h->m);
571  (void) HostIncrUsecnt(h);
572  HRLOCK_UNLOCK(hb);
573  return h;
574  }
575  }
576  }
577 
578  /* lock & return */
579  SCMutexLock(&h->m);
580  (void) HostIncrUsecnt(h);
581  HRLOCK_UNLOCK(hb);
582  return h;
583 }
584 
585 /** \brief look up a host in the hash
586  *
587  * \param a address to look up
588  *
589  * \retval h *LOCKED* host or NULL
590  */
592 {
593  Host *h = NULL;
594 
595  /* get the key to our bucket */
596  uint32_t key = HostGetKey(a);
597  /* get our hash bucket and lock it */
598  HostHashRow *hb = &host_hash[key];
599  HRLOCK_LOCK(hb);
600 
601  /* see if the bucket already has a host */
602  if (hb->head == NULL) {
603  HRLOCK_UNLOCK(hb);
604  return h;
605  }
606 
607  /* ok, we have a host in the bucket. Let's find out if it is our host */
608  h = hb->head;
609 
610  /* see if this is the host we are looking for */
611  if (HostCompare(h, a) == 0) {
612  while (h) {
613  h = h->hnext;
614 
615  if (h == NULL) {
616  HRLOCK_UNLOCK(hb);
617  return h;
618  }
619 
620  if (HostCompare(h, a) != 0) {
621  /* we found our host, lets put it on top of the
622  * hash list -- this rewards active hosts */
623  if (h->hnext) {
624  h->hnext->hprev = h->hprev;
625  }
626  if (h->hprev) {
627  h->hprev->hnext = h->hnext;
628  }
629  if (h == hb->tail) {
630  hb->tail = h->hprev;
631  }
632 
633  h->hnext = hb->head;
634  h->hprev = NULL;
635  hb->head->hprev = h;
636  hb->head = h;
637 
638  /* found our host, lock & return */
639  SCMutexLock(&h->m);
640  (void) HostIncrUsecnt(h);
641  HRLOCK_UNLOCK(hb);
642  return h;
643  }
644  }
645  }
646 
647  /* lock & return */
648  SCMutexLock(&h->m);
649  (void) HostIncrUsecnt(h);
650  HRLOCK_UNLOCK(hb);
651  return h;
652 }
653 
654 /** \internal
655  * \brief Get a host from the hash directly.
656  *
657  * Called in conditions where the spare queue is empty and memcap is reached.
658  *
659  * Walks the hash until a host can be freed. "host_prune_idx" atomic int makes
660  * sure we don't start at the top each time since that would clear the top of
661  * the hash leading to longer and longer search times under high pressure (observed).
662  *
663  * \retval h host or NULL
664  */
665 static Host *HostGetUsedHost(void)
666 {
667  uint32_t idx = SC_ATOMIC_GET(host_prune_idx) % host_config.hash_size;
668  uint32_t cnt = host_config.hash_size;
669 
670  while (cnt--) {
671  if (++idx >= host_config.hash_size)
672  idx = 0;
673 
674  HostHashRow *hb = &host_hash[idx];
675 
676  if (HRLOCK_TRYLOCK(hb) != 0)
677  continue;
678 
679  Host *h = hb->tail;
680  if (h == NULL) {
681  HRLOCK_UNLOCK(hb);
682  continue;
683  }
684 
685  if (SCMutexTrylock(&h->m) != 0) {
686  HRLOCK_UNLOCK(hb);
687  continue;
688  }
689 
690  /** never prune a host that is used by a packets
691  * we are currently processing in one of the threads */
692  if (SC_ATOMIC_GET(h->use_cnt) > 0) {
693  HRLOCK_UNLOCK(hb);
694  SCMutexUnlock(&h->m);
695  continue;
696  }
697 
698  /* remove from the hash */
699  if (h->hprev != NULL)
700  h->hprev->hnext = h->hnext;
701  if (h->hnext != NULL)
702  h->hnext->hprev = h->hprev;
703  if (hb->head == h)
704  hb->head = h->hnext;
705  if (hb->tail == h)
706  hb->tail = h->hprev;
707 
708  h->hnext = NULL;
709  h->hprev = NULL;
710  HRLOCK_UNLOCK(hb);
711 
712  HostClearMemory (h);
713 
714  SCMutexUnlock(&h->m);
715 
716  (void) SC_ATOMIC_ADD(host_prune_idx, (host_config.hash_size - cnt));
717  return h;
718  }
719 
720  return NULL;
721 }
722 
724 {
726 }
727 
HRLOCK_DESTROY
#define HRLOCK_DESTROY(fb)
Definition: host.h:50
util-byte.h
host.h
HostUnlock
void HostUnlock(Host *h)
Definition: host.c:478
host-storage.h
HostAlloc
Host * HostAlloc(void)
Definition: host.c:106
hashword
uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval)
Definition: util-hash-lookup3.c:174
Host_::hnext
struct Host_ * hnext
Definition: host.h:72
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:180
CLS
#define CLS
Definition: suricata-common.h:56
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
HOST_DEFAULT_HASHSIZE
#define HOST_DEFAULT_HASHSIZE
Definition: host.c:162
HostQueue_
Definition: host-queue.h:42
HostConfig_::prealloc
uint32_t prealloc
Definition: host.h:99
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
ParseSizeStringU64
int ParseSizeStringU64(const char *size, uint64_t *res)
Definition: util-misc.c:198
HostConfig_
Definition: host.h:95
HostQueueDestroy
void HostQueueDestroy(HostQueue *q)
Destroy a host queue.
Definition: host-queue.c:58
HostRelease
void HostRelease(Host *h)
Definition: host.c:467
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:332
HostGetHostFromHash
Host * HostGetHostFromHash(Address *a)
Definition: host.c:492
HostSetMemcap
int HostSetMemcap(uint64_t size)
Update memcap value.
Definition: host.c:68
Host_::m
SCMutex m
Definition: host.h:60
Host_::a
Address a
Definition: host.h:63
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
HostDecrUsecnt
#define HostDecrUsecnt(h)
Definition: host.h:114
Address_
Definition: decode.h:116
RandomGet
long int RandomGet(void)
Definition: util-random.c:130
HostClearMemory
void HostClearMemory(Host *h)
Definition: host.c:150
detect-tag.h
Host
struct Host_ Host
HostIncrUsecnt
#define HostIncrUsecnt(h)
Definition: host.h:112
HRLOCK_LOCK
#define HRLOCK_LOCK(fb)
Definition: host.h:51
HostGetMemcap
uint64_t HostGetMemcap(void)
Return memcap value.
Definition: host.c:83
ConfGet
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:335
HRLOCK_UNLOCK
#define HRLOCK_UNLOCK(fb)
Definition: host.h:53
host_hash
HostHashRow * host_hash
Definition: host.c:50
Host_::hprev
struct Host_ * hprev
Definition: host.h:73
util-debug.h
RegisterHostStorageTests
void RegisterHostStorageTests(void)
Definition: host-storage.c:330
HostFreeStorage
void HostFreeStorage(Host *h)
Definition: host-storage.c:104
host_config
HostConfig host_config
Definition: host.c:53
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:119
HostCleanup
void HostCleanup(void)
Cleanup the host engine.
Definition: host.c:336
HostStorageSize
unsigned int HostStorageSize(void)
Definition: host-storage.c:30
StringParseUint32
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:313
HostGetMemuse
uint64_t HostGetMemuse(void)
Return memuse value.
Definition: host.c:94
host-queue.h
HostLock
void HostLock(Host *h)
Definition: host.c:473
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:300
detect-engine-tag.h
SC_ATOMIC_SUB
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
Definition: util-atomic.h:341
SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint64_t, host_memuse)
SCFreeAligned
#define SCFreeAligned(p)
Definition: util-mem.h:77
conf.h
HRLOCK_INIT
#define HRLOCK_INIT(fb)
Definition: host.h:49
SCMutexInit
#define SCMutexInit(mut, mutattrs)
Definition: threads-debug.h:116
WarnInvalidConfEntry
#define WarnInvalidConfEntry(param_name, format, value)
Generic API that can be used by all to log an invalid conf entry.
Definition: util-misc.h:35
Host_::iprep
void * iprep
Definition: host.h:69
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
CMP_ADDR
#define CMP_ADDR(a1, a2)
Definition: decode.h:234
suricata-common.h
HostQueue_::len
uint32_t len
Definition: host-queue.h:45
SCMallocAligned
#define SCMallocAligned(size, align)
Definition: util-mem.h:68
SCLogPerf
#define SCLogPerf(...)
Definition: util-debug.h:230
HostShutdown
void HostShutdown(void)
shutdown the flow engine
Definition: host.c:299
FatalError
#define FatalError(...)
Definition: util-debug.h:502
util-hash-lookup3.h
HostMoveToSpare
void HostMoveToSpare(Host *h)
Definition: host.c:100
util-validate.h
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
HostConfig_::hash_rand
uint32_t hash_rand
Definition: host.h:97
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SCFree
#define SCFree(p)
Definition: util-mem.h:61
HostConfig_::hash_size
uint32_t hash_size
Definition: host.h:98
HostPrintStats
void HostPrintStats(void)
print some host stats
Definition: host.c:286
HOST_DEFAULT_PREALLOC
#define HOST_DEFAULT_PREALLOC
Definition: host.c:164
HostFree
void HostFree(Host *h)
Definition: host.c:125
util-random.h
HRLOCK_TRYLOCK
#define HRLOCK_TRYLOCK(fb)
Definition: host.h:52
HostRegisterUnittests
void HostRegisterUnittests(void)
Definition: host.c:723
HostDequeue
Host * HostDequeue(HostQueue *q)
remove a host from the queue
Definition: host-queue.c:102
HOST_DEFAULT_MEMCAP
#define HOST_DEFAULT_MEMCAP
Definition: host.c:163
HostLookupHostFromHash
Host * HostLookupHostFromHash(Address *a)
look up a host in the hash
Definition: host.c:591
Address_::family
char family
Definition: decode.h:117
HostInitConfig
void HostInitConfig(bool quiet)
initialize the configuration
Definition: host.c:168
HostEnqueue
void HostEnqueue(HostQueue *q, Host *h)
add a host to a queue
Definition: host-queue.c:69
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375
util-misc.h
COPY_ADDRESS
#define COPY_ADDRESS(a, b)
Definition: decode.h:131
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
Host_
Definition: host.h:58
SCMutexDestroy
#define SCMutexDestroy
Definition: threads-debug.h:120
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:103
SCMutexTrylock
#define SCMutexTrylock(mut)
Definition: threads-debug.h:118
HostQueueInit
HostQueue * HostQueueInit(HostQueue *q)
Definition: host-queue.c:33
host-bit.h
detect-engine-threshold.h
HOST_CHECK_MEMCAP
#define HOST_CHECK_MEMCAP(size)
check if a memory alloc would fit in the memcap
Definition: host.h:109