suricata
host.h File Reference
#include "decode.h"
#include "util-storage.h"
Include dependency graph for host.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Host_
 
struct  HostHashRow_
 
struct  HostConfig_
 

Macros

#define HRLOCK_MUTEX
 
#define HRLOCK_TYPE   SCMutex
 
#define HRLOCK_INIT(fb)   SCMutexInit(&(fb)->lock, NULL)
 
#define HRLOCK_DESTROY(fb)   SCMutexDestroy(&(fb)->lock)
 
#define HRLOCK_LOCK(fb)   SCMutexLock(&(fb)->lock)
 
#define HRLOCK_TRYLOCK(fb)   SCMutexTrylock(&(fb)->lock)
 
#define HRLOCK_UNLOCK(fb)   SCMutexUnlock(&(fb)->lock)
 
#define HOST_VERBOSE   0
 
#define HOST_QUIET   1
 
#define HOST_CHECK_MEMCAP(size)   ((((uint64_t)SC_ATOMIC_GET(host_memuse) + (uint64_t)(size)) <= SC_ATOMIC_GET(host_config.memcap)))
 check if a memory alloc would fit in the memcap More...
 
#define HostIncrUsecnt(h)   (void)SC_ATOMIC_ADD((h)->use_cnt, 1)
 
#define HostDecrUsecnt(h)   (void)SC_ATOMIC_SUB((h)->use_cnt, 1)
 
#define HostReference(dst_h_ptr, h)
 
#define HostDeReference(src_h_ptr)
 

Typedefs

typedef struct Host_ Host
 
typedef struct HostConfig_ HostConfig
 

Functions

struct HostHashRow_ __attribute__ ((aligned(CLS))) HostHashRow
 
 SC_ATOMIC_DECLARE (uint64_t, host_memuse)
 
 SC_ATOMIC_DECLARE (uint32_t, host_counter)
 
 SC_ATOMIC_DECLARE (uint32_t, host_prune_idx)
 
void HostInitConfig (char quiet)
 initialize the configuration More...
 
void HostShutdown (void)
 shutdown the flow engine More...
 
void HostCleanup (void)
 Cleanup the host engine. More...
 
HostHostLookupHostFromHash (Address *)
 look up a host in the hash More...
 
HostHostGetHostFromHash (Address *)
 
void HostRelease (Host *)
 
void HostLock (Host *)
 
void HostClearMemory (Host *)
 
void HostMoveToSpare (Host *)
 
uint32_t HostSpareQueueGetSize (void)
 
void HostPrintStats (void)
 print some host stats More...
 
void HostRegisterUnittests (void)
 
HostHostAlloc (void)
 
void HostFree (Host *)
 
void HostUnlock (Host *h)
 
int HostSetMemcap (uint64_t)
 Update memcap value. More...
 
uint64_t HostGetMemcap (void)
 Return memcap value. More...
 
uint64_t HostGetMemuse (void)
 Return memuse value. More...
 

Variables

HRLOCK_TYPE lock
 
Hosthead
 
Hosttail
 
HostHashRow * host_hash
 
HostConfig host_config
 

Detailed Description

Author
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t

Definition in file host.h.

Macro Definition Documentation

#define HOST_CHECK_MEMCAP (   size)    ((((uint64_t)SC_ATOMIC_GET(host_memuse) + (uint64_t)(size)) <= SC_ATOMIC_GET(host_config.memcap)))

check if a memory alloc would fit in the memcap

Parameters
sizememory allocation size to check
Return values
1it fits
0no fit

Definition at line 109 of file host.h.

Referenced by HostAlloc(), and HostInitConfig().

#define HOST_QUIET   1
#define HOST_VERBOSE   0

Definition at line 92 of file host.h.

Referenced by PostRunDeinit().

#define HostDecrUsecnt (   h)    (void)SC_ATOMIC_SUB((h)->use_cnt, 1)

Definition at line 114 of file host.h.

Referenced by HostRelease(), and SRepHostTimedOut().

#define HostDeReference (   src_h_ptr)
Value:
do { \
if (*(src_h_ptr) != NULL) { \
HostDecrUsecnt(*(src_h_ptr)); \
*(src_h_ptr) = NULL; \
} \
} while (0)
#define HostDecrUsecnt(h)
Definition: host.h:114

Definition at line 124 of file host.h.

#define HostIncrUsecnt (   h)    (void)SC_ATOMIC_ADD((h)->use_cnt, 1)

Definition at line 112 of file host.h.

Referenced by HostGetHostFromHash(), HostLookupHostFromHash(), and SRepLoadFileFromFD().

#define HostReference (   dst_h_ptr,
 
)
Value:
do { \
if ((h) != NULL) { \
*(dst_h_ptr) = h; \
} \
} while (0)
#define HostIncrUsecnt(h)
Definition: host.h:112

Definition at line 117 of file host.h.

Referenced by DetectIPRepRegister().

#define HRLOCK_DESTROY (   fb)    SCMutexDestroy(&(fb)->lock)

Definition at line 50 of file host.h.

Referenced by HostShutdown(), and IPPairShutdown().

#define HRLOCK_INIT (   fb)    SCMutexInit(&(fb)->lock, NULL)

Definition at line 49 of file host.h.

Referenced by HostInitConfig(), and IPPairInitConfig().

#define HRLOCK_LOCK (   fb)    SCMutexLock(&(fb)->lock)
#define HRLOCK_MUTEX

Spinlocks or Mutex for the flow buckets.

Definition at line 32 of file host.h.

#define HRLOCK_TRYLOCK (   fb)    SCMutexTrylock(&(fb)->lock)
#define HRLOCK_TYPE   SCMutex

Definition at line 48 of file host.h.

Typedef Documentation

typedef struct Host_ Host
typedef struct HostConfig_ HostConfig

Function Documentation

struct HostHashRow_ __attribute__ ( (aligned(CLS))  )
Host* HostAlloc ( void  )

Definition at line 103 of file host.c.

References HOST_CHECK_MEMCAP, Host_::m, SC_ATOMIC_ADD, SC_ATOMIC_INIT, SCMalloc, SCMutexInit, and unlikely.

Referenced by HostBitList(), HostFree(), and HostInitConfig().

Here is the caller graph for this function:

void HostCleanup ( void  )

Cleanup the host engine.

Cleanup the host engine from tag and threshold.

Definition at line 344 of file host.c.

References Address_::family, HostConfig_::hash_rand, HostConfig_::hash_size, hashword(), Host_::hnext, host_config, host_hash, HostClearMemory(), HostFreeStorage(), HostMoveToSpare(), Host_::hprev, HRLOCK_LOCK, HRLOCK_UNLOCK, Host_::iprep, and SC_ATOMIC_GET.

Referenced by DetectHostbitFree(), DetectXbitFree(), HostBitList(), and PostRunDeinit().

Here is the call graph for this function:

Here is the caller graph for this function:

void HostClearMemory ( Host )

Definition at line 151 of file host.c.

References HostFreeStorage(), HostStorageSize(), Host_::iprep, and SCFree.

Referenced by HostCleanup(), HostFree(), HostGetActiveCount(), and HostLookupHostFromHash().

Here is the call graph for this function:

Here is the caller graph for this function:

void HostFree ( Host )

Definition at line 124 of file host.c.

References Host_::a, COPY_ADDRESS, HostAlloc(), HostClearMemory(), Host_::m, SC_ATOMIC_DESTROY, SC_ATOMIC_SUB, SCFree, and SCMutexDestroy.

Referenced by HostBitList(), and HostShutdown().

Here is the call graph for this function:

Here is the caller graph for this function:

Host* HostGetHostFromHash ( Address )
uint64_t HostGetMemcap ( void  )

Return memcap value.

Return values
memcapvalue

Definition at line 75 of file host.c.

References host_config, and SC_ATOMIC_GET.

Referenced by RunModeUnixSocketGetDefaultMode().

Here is the caller graph for this function:

uint64_t HostGetMemuse ( void  )

Return memuse value.

Return values
memusevalue

Definition at line 86 of file host.c.

References SC_ATOMIC_GET.

Referenced by RunModeUnixSocketGetDefaultMode().

Here is the caller graph for this function:

void HostLock ( Host )

Definition at line 481 of file host.c.

References Host_::m, and SCMutexLock.

Referenced by DetectHostbitsRegister(), and DetectIPRepRegister().

Here is the caller graph for this function:

Host* HostLookupHostFromHash ( Address a)

look up a host in the hash

Parameters
aaddress to look up
Return values
hLOCKED host or NULL

Definition at line 599 of file host.c.

References HostConfig_::hash_size, Host_::hnext, host_config, host_hash, HostClearMemory(), HostIncrUsecnt, Host_::hprev, HRLOCK_LOCK, HRLOCK_TRYLOCK, HRLOCK_UNLOCK, Host_::m, SC_ATOMIC_ADD, SC_ATOMIC_GET, SCMutexLock, SCMutexTrylock, and SCMutexUnlock.

Referenced by DetectHostbitsRegister(), DetectIPRepRegister(), DetectThresholdRegister(), TagHandlePacket(), TagTimeoutCheck(), and UnixSocketPcapFile().

Here is the call graph for this function:

Here is the caller graph for this function:

void HostMoveToSpare ( Host )

Definition at line 97 of file host.c.

References HostEnqueue(), and SC_ATOMIC_SUB.

Referenced by HostCleanup(), and HostGetActiveCount().

Here is the call graph for this function:

Here is the caller graph for this function:

void HostPrintStats ( void  )

print some host stats

Warning
Not thread safe

Definition at line 287 of file host.c.

References host_config, SC_ATOMIC_GET, and SCLogPerf.

Referenced by HostShutdown(), and SRepInit().

Here is the caller graph for this function:

void HostRegisterUnittests ( void  )

Definition at line 731 of file host.c.

References RegisterHostStorageTests().

Here is the call graph for this function:

void HostRelease ( Host )
int HostSetMemcap ( uint64_t  size)

Update memcap value.

Parameters
sizenew memcap value

Definition at line 60 of file host.c.

References host_config, SC_ATOMIC_GET, and SC_ATOMIC_SET.

Referenced by RunModeUnixSocketGetDefaultMode().

Here is the caller graph for this function:

void HostShutdown ( void  )

shutdown the flow engine

Warning
Not thread safe

Definition at line 300 of file host.c.

References BUG_ON, HostConfig_::hash_size, Host_::hnext, host_config, host_hash, HostDequeue(), HostFree(), HostPrintStats(), HostQueueDestroy(), HRLOCK_DESTROY, SC_ATOMIC_DESTROY, SC_ATOMIC_GET, SC_ATOMIC_SUB, and SCFreeAligned.

Referenced by DetectDetectionFilterRegister(), DetectIPRepFree(), DetectThresholdRegister(), GlobalsInitPreConfig(), HostFreeStorage(), SCThresholdConfParseFile(), and TagTimeoutCheck().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t HostSpareQueueGetSize ( void  )

Definition at line 92 of file host.c.

References HostQueueLen().

Referenced by HostGetSpareCount().

Here is the call graph for this function:

Here is the caller graph for this function:

void HostUnlock ( Host h)

Definition at line 486 of file host.c.

References Host_::m, and SCMutexUnlock.

Referenced by DetectHostbitsRegister(), and UnixSocketPcapFile().

Here is the caller graph for this function:

SC_ATOMIC_DECLARE ( uint64_t  ,
host_memuse   
)
SC_ATOMIC_DECLARE ( uint32_t  ,
host_counter   
)
SC_ATOMIC_DECLARE ( uint32_t  ,
host_prune_idx   
)

Variable Documentation

Host* head

Definition at line 733 of file host.h.

HostHashRow* host_hash

host hash table

Definition at line 90 of file host.h.

Referenced by HostCleanup(), HostGetHostFromHash(), HostInitConfig(), HostLookupHostFromHash(), HostShutdown(), and HostTimeoutHash().

Definition at line 732 of file host.h.

Host* tail

Definition at line 734 of file host.h.