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,
283 #ifdef IPPAIRBITS_STATS
284 SCLogPerf(
"ippairbits added: %" PRIu32
", removed: %" PRIu32
", max memory usage: %" PRIu32
"",
285 ippairbits_added, ippairbits_removed, ippairbits_memuse_max);
287 SCLogPerf(
"ippair memory usage: %" PRIu64
" bytes, maximum: %" PRIu64,
345 if (h->
hprev != NULL)
347 if (h->
hnext != NULL)
376 static inline int IPPairHashRawAddressIPv6GtU32(
const uint32_t *a,
const uint32_t *b)
380 for (i = 0; i < 4; i++) {
400 if (a->
family == AF_INET) {
401 uint32_t addrs[2] = {
MIN(a->addr_data32[0], b->addr_data32[0]),
402 MAX(a->addr_data32[0], b->addr_data32[0]) };
405 }
else if (a->
family == AF_INET6) {
407 if (IPPairHashRawAddressIPv6GtU32(&a->addr_data32[0],&b->addr_data32[0])) {
408 addrs[0] = b->addr_data32[0];
409 addrs[1] = b->addr_data32[1];
410 addrs[2] = b->addr_data32[2];
411 addrs[3] = b->addr_data32[3];
412 addrs[4] = a->addr_data32[0];
413 addrs[5] = a->addr_data32[1];
414 addrs[6] = a->addr_data32[2];
415 addrs[7] = a->addr_data32[3];
417 addrs[0] = a->addr_data32[0];
418 addrs[1] = a->addr_data32[1];
419 addrs[2] = a->addr_data32[2];
420 addrs[3] = a->addr_data32[3];
421 addrs[4] = b->addr_data32[0];
422 addrs[5] = b->addr_data32[1];
423 addrs[6] = b->addr_data32[2];
424 addrs[7] = b->addr_data32[3];
472 h = IPPairGetUsedIPPair();
529 uint32_t key = IPPairGetKey(a, b);
535 if (hb->head == NULL) {
536 h = IPPairGetNew(a,b);
557 if (IPPairCompare(h, a, b) == 0) {
565 h = ph->
hnext = IPPairGetNew(a,b);
583 if (IPPairCompare(h, a, b) != 0) {
628 uint32_t key = IPPairGetKey(a, b);
634 if (hb->head == NULL) {
643 if (IPPairCompare(h, a, b) == 0) {
652 if (IPPairCompare(h, a, b) != 0) {
697 static IPPair *IPPairGetUsedIPPair(
void)
731 if (h->
hprev != NULL)
733 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)