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 ((
SCConfGet(
"ippair.memcap", &conf_val)) == 1) {
193 "from conf file - %s. Killing engine",
200 if ((
SCConfGet(
"ippair.hash-size", &conf_val)) == 1) {
207 if ((
SCConfGet(
"ippair.prealloc", &conf_val)) == 1) {
215 SCLogDebug(
"IPPair config from suricata.yaml: memcap: %"PRIu64
", hash-size: "
223 "max ippair memcap is smaller than projected hash size. "
224 "Memcap: %" PRIu64
", Hash table size %" PRIu64
". Calculate "
225 "total hash size by multiplying \"ippair.hash-size\" with %" PRIuMAX
", "
226 "which is the hash bucket size.",
232 FatalError(
"Fatal error encountered in IPPairInitConfig. Exiting...");
243 SCLogConfig(
"allocated %"PRIu64
" bytes of memory for the ippair hash... "
244 "%" PRIu32
" buckets of size %" PRIuMAX
"",
246 (uintmax_t)
sizeof(IPPairHashRow));
253 "max ippair memcap reached. Memcap %" PRIu64
", "
254 "Memuse %" PRIu64
".",
262 SCLogError(
"preallocating ippair failed: %s", strerror(errno));
269 SCLogConfig(
"preallocated %" PRIu32
" ippairs of size %" PRIu16
"",
270 ippair_spare_q.
len, g_ippair_size);
271 SCLogConfig(
"ippair memory usage: %"PRIu64
" bytes, maximum: %"PRIu64,
280 #ifdef IPPAIRBITS_STATS
281 SCLogPerf(
"ippairbits added: %" PRIu32
", removed: %" PRIu32
", max memory usage: %" PRIu32
"",
282 ippairbits_added, ippairbits_removed, ippairbits_memuse_max);
284 SCLogPerf(
"ippair memory usage: %" PRIu64
" bytes, maximum: %" PRIu64,
342 if (h->
hprev != NULL)
344 if (h->
hnext != NULL)
373 static inline int IPPairHashRawAddressIPv6GtU32(
const uint32_t *a,
const uint32_t *b)
377 for (i = 0; i < 4; i++) {
397 if (a->
family == AF_INET) {
398 uint32_t addrs[2] = {
MIN(a->addr_data32[0], b->addr_data32[0]),
399 MAX(a->addr_data32[0], b->addr_data32[0]) };
402 }
else if (a->
family == AF_INET6) {
404 if (IPPairHashRawAddressIPv6GtU32(&a->addr_data32[0],&b->addr_data32[0])) {
405 addrs[0] = b->addr_data32[0];
406 addrs[1] = b->addr_data32[1];
407 addrs[2] = b->addr_data32[2];
408 addrs[3] = b->addr_data32[3];
409 addrs[4] = a->addr_data32[0];
410 addrs[5] = a->addr_data32[1];
411 addrs[6] = a->addr_data32[2];
412 addrs[7] = a->addr_data32[3];
414 addrs[0] = a->addr_data32[0];
415 addrs[1] = a->addr_data32[1];
416 addrs[2] = a->addr_data32[2];
417 addrs[3] = a->addr_data32[3];
418 addrs[4] = b->addr_data32[0];
419 addrs[5] = b->addr_data32[1];
420 addrs[6] = b->addr_data32[2];
421 addrs[7] = b->addr_data32[3];
469 h = IPPairGetUsedIPPair();
526 uint32_t key = IPPairGetKey(a, b);
532 if (hb->head == NULL) {
533 h = IPPairGetNew(a,b);
554 if (IPPairCompare(h, a, b) == 0) {
562 h = ph->
hnext = IPPairGetNew(a,b);
580 if (IPPairCompare(h, a, b) != 0) {
625 uint32_t key = IPPairGetKey(a, b);
631 if (hb->head == NULL) {
640 if (IPPairCompare(h, a, b) == 0) {
649 if (IPPairCompare(h, a, b) != 0) {
694 static IPPair *IPPairGetUsedIPPair(
void)
728 if (h->
hprev != NULL)
730 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
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
#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
#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)