Go to the documentation of this file.
47 static Host *HostGetUsedHost(
void);
61 static uint16_t g_host_size =
sizeof(
Host);
157 if (h->
iprep != NULL) {
167 #define HOST_DEFAULT_HASHSIZE 4096
168 #define HOST_DEFAULT_MEMCAP 16777216
169 #define HOST_DEFAULT_PREALLOC 1000
196 const char *conf_val;
197 uint32_t configval = 0;
200 if ((
ConfGet(
"host.memcap", &conf_val)) == 1) {
201 uint64_t host_memcap = 0;
204 "from conf file - %s. Killing engine",
211 if ((
ConfGet(
"host.hash-size", &conf_val)) == 1) {
218 if ((
ConfGet(
"host.prealloc", &conf_val)) == 1) {
226 SCLogDebug(
"Host config from suricata.yaml: memcap: %"PRIu64
", hash-size: "
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.",
243 FatalError(
"Fatal error encountered in HostInitConfig. Exiting...");
254 SCLogConfig(
"allocated %"PRIu64
" bytes of memory for the host hash... "
255 "%" PRIu32
" buckets of size %" PRIuMAX
"",
257 (uintmax_t)
sizeof(HostHashRow));
264 "max host memcap reached. Memcap %" PRIu64
", "
265 "Memuse %" PRIu64
".",
273 SCLogError(
"preallocating host failed: %s", strerror(errno));
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,
293 #ifdef HOSTBITS_STATS
294 SCLogPerf(
"hostbits added: %" PRIu32
", removed: %" PRIu32
", max memory usage: %" PRIu32
"",
295 hostbits_added, hostbits_removed, hostbits_memuse_max);
297 SCLogPerf(
"host memory usage: %"PRIu64
" bytes, maximum: %"PRIu64,
356 if (h->
hprev != NULL)
358 if (h->
hnext != NULL)
384 static inline uint32_t HostGetKey(
Address *a)
388 if (a->
family == AF_INET) {
391 }
else if (a->
family == AF_INET6) {
405 return (h->
a.addr_data32[0] == a->addr_data32[0]);
440 h = HostGetUsedHost();
502 uint32_t key = HostGetKey(a);
508 if (hb->head == NULL) {
530 if (HostCompare(h, a) == 0) {
538 h = ph->
hnext = HostGetNew(a);
556 if (HostCompare(h, a) != 0) {
601 uint32_t key = HostGetKey(a);
607 if (hb->head == NULL) {
616 if (HostCompare(h, a) == 0) {
625 if (HostCompare(h, a) != 0) {
670 static Host *HostGetUsedHost(
void)
704 if (h->
hprev != NULL)
706 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