Go to the documentation of this file.
47 static Host *HostGetUsedHost(
void);
61 static uint16_t g_host_size =
sizeof(
Host);
122 memset(h, 0x00, g_host_size);
159 if (h->
iprep != NULL) {
169 #define HOST_DEFAULT_HASHSIZE 4096
170 #define HOST_DEFAULT_MEMCAP 16777216
171 #define HOST_DEFAULT_PREALLOC 1000
198 const char *conf_val;
199 uint32_t configval = 0;
202 if ((
ConfGet(
"host.memcap", &conf_val)) == 1) {
203 uint64_t host_memcap = 0;
206 "from conf file - %s. Killing engine",
213 if ((
ConfGet(
"host.hash-size", &conf_val)) == 1) {
220 if ((
ConfGet(
"host.prealloc", &conf_val)) == 1) {
228 SCLogDebug(
"Host config from suricata.yaml: memcap: %"PRIu64
", hash-size: "
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.",
245 FatalError(
"Fatal error encountered in HostInitConfig. Exiting...");
256 SCLogConfig(
"allocated %"PRIu64
" bytes of memory for the host hash... "
257 "%" PRIu32
" buckets of size %" PRIuMAX
"",
259 (uintmax_t)
sizeof(HostHashRow));
266 "max host memcap reached. Memcap %" PRIu64
", "
267 "Memuse %" PRIu64
".",
275 SCLogError(
"preallocating host failed: %s", strerror(errno));
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,
295 #ifdef HOSTBITS_STATS
296 SCLogPerf(
"hostbits added: %" PRIu32
", removed: %" PRIu32
", max memory usage: %" PRIu32
"",
297 hostbits_added, hostbits_removed, hostbits_memuse_max);
299 SCLogPerf(
"host memory usage: %"PRIu64
" bytes, maximum: %"PRIu64,
361 if (h->
hprev != NULL)
363 if (h->
hnext != NULL)
389 static inline uint32_t HostGetKey(
Address *a)
393 if (a->
family == AF_INET) {
396 }
else if (a->
family == AF_INET6) {
410 return (h->
a.addr_data32[0] == a->addr_data32[0]);
445 h = HostGetUsedHost();
507 uint32_t key = HostGetKey(a);
513 if (hb->head == NULL) {
535 if (HostCompare(h, a) == 0) {
543 h = ph->
hnext = HostGetNew(a);
561 if (HostCompare(h, a) != 0) {
606 uint32_t key = HostGetKey(a);
612 if (hb->head == NULL) {
621 if (HostCompare(h, a) == 0) {
630 if (HostCompare(h, a) != 0) {
675 static Host *HostGetUsedHost(
void)
709 if (h->
hprev != NULL)
711 if (h->
hnext != NULL)
#define HRLOCK_DESTROY(fb)
uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval)
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
void SRepFreeHostData(Host *h)
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
#define HOST_DEFAULT_HASHSIZE
int ParseSizeStringU64(const char *size, uint64_t *res)
void HostQueueDestroy(HostQueue *q)
Destroy a host queue.
void HostRelease(Host *h)
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Host * HostGetHostFromHash(Address *a)
int HostSetMemcap(uint64_t size)
Update memcap value.
#define HostDecrUsecnt(h)
void HostClearMemory(Host *h)
#define HostIncrUsecnt(h)
uint64_t HostGetMemcap(void)
Return memcap value.
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
#define HRLOCK_UNLOCK(fb)
void RegisterHostStorageTests(void)
void HostFreeStorage(Host *h)
#define SCMutexUnlock(mut)
void HostCleanup(void)
Cleanup the host engine.
unsigned int HostStorageSize(void)
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
uint64_t HostGetMemuse(void)
Return memuse value.
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
SC_ATOMIC_DECLARE(uint64_t, host_memuse)
#define SCMutexInit(mut, mutattrs)
#define WarnInvalidConfEntry(param_name, format, value)
Generic API that can be used by all to log an invalid conf entry.
uint32_t HostQueueLen(HostQueue *q)
#define SCMallocAligned(size, align)
void HostShutdown(void)
shutdown the flow engine
void HostMoveToSpare(Host *h)
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
#define SCLogError(...)
Macro used to log ERROR messages.
void HostPrintStats(void)
print some host stats
#define HOST_DEFAULT_PREALLOC
#define HRLOCK_TRYLOCK(fb)
void HostRegisterUnittests(void)
Host * HostDequeue(HostQueue *q)
remove a host from the queue
#define HOST_DEFAULT_MEMCAP
Host * HostLookupHostFromHash(Address *a)
look up a host in the hash
void HostInitConfig(bool quiet)
initialize the configuration
void HostEnqueue(HostQueue *q, Host *h)
add a host to a queue
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
#define COPY_ADDRESS(a, b)
#define DEBUG_VALIDATE_BUG_ON(exp)
uint32_t HostSpareQueueGetSize(void)
#define SCMutexTrylock(mut)
HostQueue * HostQueueInit(HostQueue *q)
#define HOST_CHECK_MEMCAP(size)
check if a memory alloc would fit in the memcap