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