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