Go to the documentation of this file.
47 static Host *HostGetUsedHost(
void);
61 static uint16_t g_host_size =
sizeof(
Host);
152 if (h->
iprep != NULL) {
162 #define HOST_DEFAULT_HASHSIZE 4096
163 #define HOST_DEFAULT_MEMCAP 16777216
164 #define HOST_DEFAULT_PREALLOC 1000
191 const char *conf_val;
192 uint32_t configval = 0;
195 if ((
ConfGet(
"host.memcap", &conf_val)) == 1) {
196 uint64_t host_memcap = 0;
199 "from conf file - %s. Killing engine",
206 if ((
ConfGet(
"host.hash-size", &conf_val)) == 1) {
213 if ((
ConfGet(
"host.prealloc", &conf_val)) == 1) {
221 SCLogDebug(
"Host config from suricata.yaml: memcap: %"PRIu64
", hash-size: "
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.",
238 FatalError(
"Fatal error encountered in HostInitConfig. Exiting...");
249 SCLogConfig(
"allocated %"PRIu64
" bytes of memory for the host hash... "
250 "%" PRIu32
" buckets of size %" PRIuMAX
"",
252 (uintmax_t)
sizeof(HostHashRow));
259 "max host memcap reached. Memcap %" PRIu64
", "
260 "Memuse %" PRIu64
".",
268 SCLogError(
"preallocating host failed: %s", strerror(errno));
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,
286 #ifdef HOSTBITS_STATS
287 SCLogPerf(
"hostbits added: %" PRIu32
", removed: %" PRIu32
", max memory usage: %" PRIu32
"",
288 hostbits_added, hostbits_removed, hostbits_memuse_max);
347 if (h->
hprev != NULL)
349 if (h->
hnext != NULL)
373 static inline uint32_t HostGetKey(
Address *a)
377 if (a->
family == AF_INET) {
380 }
else if (a->
family == AF_INET6) {
394 return (h->
a.addr_data32[0] == a->addr_data32[0]);
429 h = HostGetUsedHost();
491 uint32_t key = HostGetKey(a);
497 if (hb->head == NULL) {
519 if (HostCompare(h, a) == 0) {
527 h = ph->
hnext = HostGetNew(a);
545 if (HostCompare(h, a) != 0) {
590 uint32_t key = HostGetKey(a);
596 if (hb->head == NULL) {
605 if (HostCompare(h, a) == 0) {
614 if (HostCompare(h, a) != 0) {
659 static Host *HostGetUsedHost(
void)
693 if (h->
hprev != NULL)
695 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.
#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)
#define SCMutexTrylock(mut)
HostQueue * HostQueueInit(HostQueue *q)
#define HOST_CHECK_MEMCAP(size)
check if a memory alloc would fit in the memcap