#include "framework/data_bus.h"
#include "helpers/bitop.h"
#include "ips_options/ips_flowbits.h"
+#include "memory/memory_cap.h"
#include "protocols/packet.h"
#include "sfip/sf_ip.h"
#include "utils/stats.h"
Flow::Flow()
{
+ memory::MemoryCap::update_allocations(sizeof(*this) + sizeof(FlowStash));
memset(this, 0, sizeof(*this));
}
Flow::~Flow()
{
+ memory::MemoryCap::update_deallocations(sizeof(*this) + sizeof(FlowStash));
term();
}
#include "flow/flow_cache.h"
+#include "hash/hash_defs.h"
#include "hash/zhash.h"
#include "helpers/flag_context.h"
#include "ips_options/ips_flowbits.h"
}
FlowCache::~FlowCache()
+{
+ delete hash_table;
+ delete_uni();
+}
+
+void FlowCache::delete_uni()
{
delete uni_flows;
delete uni_ip_flows;
- delete hash_table;
+
+ uni_flows = nullptr;
+ uni_ip_flows = nullptr;
}
void FlowCache::push(Flow* flow)
{
Flow* new_flow = new Flow();
push(new_flow);
+ memory::MemoryCap::update_allocations(sizeof(HashNode) + sizeof(FlowKey));
}
else if ( !prune_stale(timestamp, nullptr) )
{
delete_stats.update(FlowDeleteState::ALLOWED);
delete flow;
+ memory::MemoryCap::update_deallocations(sizeof(HashNode) + sizeof(FlowKey));
--flows_allocated;
++deleted;
--num_to_delete;
delete flow;
delete_stats.update(FlowDeleteState::FREELIST);
+ memory::MemoryCap::update_deallocations(sizeof(HashNode) + sizeof(FlowKey));
+
--flows_allocated;
++deleted;
--num_to_delete;
while ( Flow* flow = (Flow*)hash_table->pop() )
{
delete flow;
+ memory::MemoryCap::update_deallocations(sizeof(HashNode) + sizeof(FlowKey));
--flows_allocated;
}
+ // Remove these here so alloc/dealloc counts are right when Memory::get_pegs is called
+ delete_uni();
+
return retired;
}
unsigned prune_excess(const snort::Flow* save_me);
bool prune_one(PruneReason, bool do_cleanup);
unsigned timeout(unsigned num_flows, time_t cur_time);
-
unsigned delete_flows(unsigned num_to_delete);
unsigned purge();
{ return flows_allocated; }
private:
+ void delete_uni();
void push(snort::Flow*);
void link_uni(snort::Flow*);
void remove(snort::Flow*);
}
static size_t fudge_it(size_t n)
-{ return ((n >> 7) + 1) << 7; }
+{
+ return ((n >> 7) + 1) << 7;
+}
void MemoryCap::update_allocations(size_t n)
{
+ if (n == 0)
+ return;
+
size_t k = n;
n = fudge_it(n);
mem_stats.total_fudge += (n - k);
void MemoryCap::update_deallocations(size_t n)
{
+ if (n == 0)
+ return;
+
n = fudge_it(n);
s_tracker.deallocate(n);
mp_active_context.update_deallocs(n);
{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr } \
}
-FLOW_TYPE_PARAMS(ip_params, "180", "64");
-FLOW_TYPE_PARAMS(icmp_params, "180", "8");
-FLOW_TYPE_PARAMS(tcp_params, "3600", "11500");
-FLOW_TYPE_PARAMS(udp_params, "180", "128");
-FLOW_TYPE_PARAMS(user_params,"180", "256");
+FLOW_TYPE_PARAMS(ip_params, "180", "0");
+FLOW_TYPE_PARAMS(icmp_params, "180", "0");
+FLOW_TYPE_PARAMS(tcp_params, "3600", "11000");
+FLOW_TYPE_PARAMS(udp_params, "180", "0");
+FLOW_TYPE_PARAMS(user_params,"180", "0");
FLOW_TYPE_PARAMS(file_params, "180", "32");
#define FLOW_TYPE_TABLE(flow_type, proto, params) \