Go to the documentation of this file.
46 static IPPair *IPPairGetUsedIPPair(
void);
59 static uint16_t g_ippair_size =
sizeof(
IPPair);
156 #define IPPAIR_DEFAULT_HASHSIZE 4096
157 #define IPPAIR_DEFAULT_MEMCAP 16777216
158 #define IPPAIR_DEFAULT_PREALLOC 1000
185 const char *conf_val;
186 uint32_t configval = 0;
189 uint64_t ippair_memcap;
190 if ((
ConfGet(
"ippair.memcap", &conf_val)) == 1)
194 "from conf file - %s. Killing engine",
201 if ((
ConfGet(
"ippair.hash-size", &conf_val)) == 1)
209 if ((
ConfGet(
"ippair.prealloc", &conf_val)) == 1)
218 SCLogDebug(
"IPPair config from suricata.yaml: memcap: %"PRIu64
", hash-size: "
226 "max ippair memcap is smaller than projected hash size. "
227 "Memcap: %" PRIu64
", Hash table size %" PRIu64
". Calculate "
228 "total hash size by multiplying \"ippair.hash-size\" with %" PRIuMAX
", "
229 "which is the hash bucket size.",
235 FatalError(
"Fatal error encountered in IPPairInitConfig. Exiting...");
246 SCLogConfig(
"allocated %"PRIu64
" bytes of memory for the ippair hash... "
247 "%" PRIu32
" buckets of size %" PRIuMAX
"",
249 (uintmax_t)
sizeof(IPPairHashRow));
256 "max ippair memcap reached. Memcap %" PRIu64
", "
257 "Memuse %" PRIu64
".",
265 SCLogError(
"preallocating ippair failed: %s", strerror(errno));
272 SCLogConfig(
"preallocated %" PRIu32
" ippairs of size %" PRIu16
"",
273 ippair_spare_q.
len, g_ippair_size);
274 SCLogConfig(
"ippair memory usage: %"PRIu64
" bytes, maximum: %"PRIu64,
285 #ifdef IPPAIRBITS_STATS
286 SCLogPerf(
"ippairbits added: %" PRIu32
", removed: %" PRIu32
", max memory usage: %" PRIu32
"",
287 ippairbits_added, ippairbits_removed, ippairbits_memuse_max);
289 SCLogPerf(
"ippair memory usage: %"PRIu64
" bytes, maximum: %"PRIu64,
349 if (h->
hprev != NULL)
351 if (h->
hnext != NULL)
382 static inline int IPPairHashRawAddressIPv6GtU32(
const uint32_t *a,
const uint32_t *b)
386 for (i = 0; i < 4; i++) {
406 if (a->
family == AF_INET) {
407 uint32_t addrs[2] = {
MIN(a->addr_data32[0], b->addr_data32[0]),
408 MAX(a->addr_data32[0], b->addr_data32[0]) };
411 }
else if (a->
family == AF_INET6) {
413 if (IPPairHashRawAddressIPv6GtU32(&a->addr_data32[0],&b->addr_data32[0])) {
414 addrs[0] = b->addr_data32[0];
415 addrs[1] = b->addr_data32[1];
416 addrs[2] = b->addr_data32[2];
417 addrs[3] = b->addr_data32[3];
418 addrs[4] = a->addr_data32[0];
419 addrs[5] = a->addr_data32[1];
420 addrs[6] = a->addr_data32[2];
421 addrs[7] = a->addr_data32[3];
423 addrs[0] = a->addr_data32[0];
424 addrs[1] = a->addr_data32[1];
425 addrs[2] = a->addr_data32[2];
426 addrs[3] = a->addr_data32[3];
427 addrs[4] = b->addr_data32[0];
428 addrs[5] = b->addr_data32[1];
429 addrs[6] = b->addr_data32[2];
430 addrs[7] = b->addr_data32[3];
478 h = IPPairGetUsedIPPair();
535 uint32_t key = IPPairGetKey(a, b);
541 if (hb->head == NULL) {
542 h = IPPairGetNew(a,b);
563 if (IPPairCompare(h, a, b) == 0) {
571 h = ph->
hnext = IPPairGetNew(a,b);
589 if (IPPairCompare(h, a, b) != 0) {
634 uint32_t key = IPPairGetKey(a, b);
640 if (hb->head == NULL) {
649 if (IPPairCompare(h, a, b) == 0) {
658 if (IPPairCompare(h, a, b) != 0) {
703 static IPPair *IPPairGetUsedIPPair(
void)
737 if (h->
hprev != NULL)
739 if (h->
hnext != NULL)
#define HRLOCK_DESTROY(fb)
void IPPairInitConfig(bool quiet)
initialize the configuration
uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval)
#define IPPAIR_DEFAULT_HASHSIZE
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
SC_ATOMIC_DECLARE(uint64_t, ippair_memuse)
void IPPairRelease(IPPair *h)
#define IPPAIR_DEFAULT_PREALLOC
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
#define IPPairIncrUsecnt(h)
int ParseSizeStringU64(const char *size, uint64_t *res)
IPPairQueue * IPPairQueueInit(IPPairQueue *q)
void IPPairRegisterUnittests(void)
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
#define IPPAIR_CHECK_MEMCAP(size)
check if a memory alloc would fit in the memcap
#define IPPairDecrUsecnt(h)
IPPair * IPPairDequeue(IPPairQueue *q)
remove a ippair from the queue
IPPair * IPPairAlloc(void)
void IPPairMoveToSpare(IPPair *h)
unsigned int IPPairStorageSize(void)
void IPPairFree(IPPair *h)
void IPPairShutdown(void)
shutdown the flow engine
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
#define HRLOCK_UNLOCK(fb)
IPPairConfig ippair_config
void IPPairCleanup(void)
Cleanup the ippair engine.
#define SCMutexUnlock(mut)
uint64_t IPPairGetMemcap(void)
Return memcap value.
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
IPPair * IPPairGetIPPairFromHash(Address *a, Address *b)
void IPPairEnqueue(IPPairQueue *q, IPPair *h)
add a ippair to a queue
#define IPPAIR_DEFAULT_MEMCAP
void IPPairUnlock(IPPair *h)
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
#define SCMutexInit(mut, mutattrs)
#define WarnInvalidConfEntry(param_name, format, value)
Generic API that can be used by all to log an invalid conf entry.
void RegisterIPPairStorageTests(void)
#define SCMallocAligned(size, align)
uint64_t IPPairGetMemuse(void)
Return memuse value.
void IPPairClearMemory(IPPair *h)
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
#define SCLogError(...)
Macro used to log ERROR messages.
#define HRLOCK_TRYLOCK(fb)
void IPPairQueueDestroy(IPPairQueue *q)
Destroy a ippair queue.
int IPPairSetMemcap(uint64_t size)
Update memcap value.
IPPair * IPPairLookupIPPairFromHash(Address *a, Address *b)
look up a ippair in the hash
void IPPairFreeStorage(IPPair *h)
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
#define COPY_ADDRESS(a, b)
IPPairHashRow * ippair_hash
#define DEBUG_VALIDATE_BUG_ON(exp)
void IPPairPrintStats(void)
print some ippair stats
#define SCMutexTrylock(mut)