45 static IPPair *IPPairGetUsedIPPair(
void);
52 static uint16_t g_ippair_size =
sizeof(
IPPair);
114 memset(h, 0x00, g_ippair_size);
158 #define IPPAIR_DEFAULT_HASHSIZE 4096 159 #define IPPAIR_DEFAULT_MEMCAP 16777216 160 #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
", " 230 (uintmax_t)
sizeof(IPPairHashRow));
246 if (quiet ==
FALSE) {
247 SCLogConfig(
"allocated %"PRIu64
" bytes of memory for the ippair hash... " 248 "%" PRIu32
" buckets of size %" PRIuMAX
"",
250 (uintmax_t)
sizeof(IPPairHashRow));
257 "max ippair memcap reached. Memcap %"PRIu64
", " 271 if (quiet ==
FALSE) {
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,
358 if (h->
hprev != NULL)
360 if (h->
hnext != NULL)
391 static inline int IPPairHashRawAddressIPv6GtU32(
const uint32_t *a,
const uint32_t *b)
395 for (i = 0; i < 4; i++) {
415 if (a->
family == AF_INET) {
416 uint32_t addrs[2] = {
MIN(a->addr_data32[0], b->addr_data32[0]),
417 MAX(a->addr_data32[0], b->addr_data32[0]) };
420 }
else if (a->
family == AF_INET6) {
422 if (IPPairHashRawAddressIPv6GtU32(&a->addr_data32[0],&b->addr_data32[0])) {
423 addrs[0] = b->addr_data32[0];
424 addrs[1] = b->addr_data32[1];
425 addrs[2] = b->addr_data32[2];
426 addrs[3] = b->addr_data32[3];
427 addrs[4] = a->addr_data32[0];
428 addrs[5] = a->addr_data32[1];
429 addrs[6] = a->addr_data32[2];
430 addrs[7] = a->addr_data32[3];
432 addrs[0] = a->addr_data32[0];
433 addrs[1] = a->addr_data32[1];
434 addrs[2] = a->addr_data32[2];
435 addrs[3] = a->addr_data32[3];
436 addrs[4] = b->addr_data32[0];
437 addrs[5] = b->addr_data32[1];
438 addrs[6] = b->addr_data32[2];
439 addrs[7] = b->addr_data32[3];
487 h = IPPairGetUsedIPPair();
549 uint32_t key = IPPairGetKey(a, b);
555 if (hb->head == NULL) {
556 h = IPPairGetNew(a,b);
577 if (IPPairCompare(h, a, b) == 0) {
585 h = ph->
hnext = IPPairGetNew(a,b);
603 if (IPPairCompare(h, a, b) != 0) {
648 uint32_t key = IPPairGetKey(a, b);
654 if (hb->head == NULL) {
663 if (IPPairCompare(h, a, b) == 0) {
672 if (IPPairCompare(h, a, b) != 0) {
717 static IPPair *IPPairGetUsedIPPair(
void)
751 if (h->
hprev != NULL)
753 if (h->
hnext != NULL)
#define HRLOCK_UNLOCK(fb)
void IPPairMoveToSpare(IPPair *h)
#define COPY_ADDRESS(a, b)
uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval)
#define IPPAIR_DEFAULT_MEMCAP
#define SCMutexDestroy(x)
#define SCMutexTrylock(mut)
void IPPairClearMemory(IPPair *h)
uint64_t IPPairGetMemcap(void)
Return memcap value.
#define HRLOCK_TRYLOCK(fb)
void IPPairEnqueue(IPPairQueue *q, IPPair *h)
add a ippair to a queue
#define HRLOCK_DESTROY(fb)
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
IPPair * IPPairGetIPPairFromHash(Address *a, Address *b)
#define IPPAIR_DEFAULT_HASHSIZE
int ByteExtractStringUint32(uint32_t *res, int base, uint16_t len, const char *str)
uint64_t IPPairGetMemuse(void)
Return memuse value.
void IPPairLock(IPPair *h)
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
#define IPPairIncrUsecnt(h)
int IPPairSetMemcap(uint64_t size)
Update memcap value.
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
#define SC_ATOMIC_DESTROY(name)
Destroy the lock used to protect this variable.
void RegisterIPPairStorageTests(void)
IPPair * IPPairLookupIPPairFromHash(Address *a, Address *b)
look up a ippair in the hash
int ParseSizeStringU64(const char *size, uint64_t *res)
IPPairConfig ippair_config
void IPPairInitConfig(char quiet)
initialize the configuration
#define SC_ATOMIC_INIT(name)
Initialize the previously declared atomic variable and it's lock.
uint32_t IPPairSpareQueueGetSize(void)
#define IPPairDecrUsecnt(h)
#define SCMutexUnlock(mut)
#define SCMutexInit(mut, mutattr)
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
void IPPairPrintStats(void)
print some ippair stats
void IPPairQueueDestroy(IPPairQueue *q)
Destroy a ippair queue.
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
#define SCMallocAligned(a, b)
wrapper for allocing aligned mem
uint32_t IPPairQueueLen(IPPairQueue *q)
IPPair * IPPairAlloc(void)
#define IPPAIR_CHECK_MEMCAP(size)
check if a memory alloc would fit in the memcap
#define IPPAIR_DEFAULT_PREALLOC
#define WarnInvalidConfEntry(param_name, format, value)
Generic API that can be used by all to log an invalid conf entry.
void IPPairRegisterUnittests(void)
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
void IPPairCleanup(void)
Cleanup the ippair engine.
IPPairQueue * IPPairQueueInit(IPPairQueue *q)
void IPPairUnlock(IPPair *h)
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
IPPair * IPPairDequeue(IPPairQueue *q)
remove a ippair from the queue
void IPPairFreeStorage(IPPair *h)
void IPPairRelease(IPPair *h)
unsigned int IPPairStorageSize(void)
void IPPairFree(IPPair *h)
#define SCFreeAligned(a)
Free aligned memory.
void IPPairShutdown(void)
shutdown the flow engine
IPPairHashRow * ippair_hash