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