#include "hash/zhash.h"
#include "helpers/flag_context.h"
#include "ips_options/ips_flowbits.h"
+#include "main/snort_debug.h"
#include "memory/memory_cap.h"
#include "packet_io/active.h"
#include "packet_tracer/packet_tracer.h"
+#include "stream/base/stream_module.h"
#include "time/packet_time.h"
#include "utils/stats.h"
//-------------------------------------------------------------------------
THREAD_LOCAL bool FlowCache::pruning_in_progress = false;
+extern THREAD_LOCAL const snort::Trace* stream_trace;
FlowCache::FlowCache(const FlowCacheConfig& cfg) : config(cfg)
{
// always prepend
void FlowCache::link_uni(Flow* flow)
{
- if ( flow->pkt_type == PktType::IP )
+ if ( flow->key->pkt_type == PktType::IP )
+ {
+ debug_logf(stream_trace, TRACE_FLOW, nullptr,
+ "linking unidirectional flow (IP) to list of size: %u\n",
+ uni_ip_flows->get_count());
uni_ip_flows->link_uni(flow);
+ }
else
+ {
+ debug_logf(stream_trace, TRACE_FLOW, nullptr,
+ "linking unidirectional flow (non-IP) to list of size: %u\n",
+ uni_flows->get_count());
uni_flows->link_uni(flow);
+ }
}
// but remove from any point
void FlowCache::unlink_uni(Flow* flow)
{
- if ( flow->pkt_type == PktType::IP )
- uni_ip_flows->unlink_uni(flow);
+ if ( flow->key->pkt_type == PktType::IP )
+ {
+ if ( uni_ip_flows->unlink_uni(flow) )
+ debug_logf(stream_trace, TRACE_FLOW, nullptr,
+ "unlinked unidirectional flow (IP) from list, size: %u\n",
+ uni_ip_flows->get_count());
+ }
else
- uni_flows->unlink_uni(flow);
+ {
+ if ( uni_flows->unlink_uni(flow) )
+ debug_logf(stream_trace, TRACE_FLOW, nullptr,
+ "unlinked unidirectional flow (non-IP) from list, size: %u\n",
+ uni_flows->get_count());
+ }
}
Flow* FlowCache::allocate(const FlowKey* key)
void FlowCache::remove(Flow* flow)
{
- if ( flow->next )
- unlink_uni(flow);
+ unlink_uni(flow);
// FIXIT-M This check is added for offload case where both Flow::reset
// and Flow::retire try remove the flow from hash. Flow::reset should
}
// we have a winner...
- if ( flow->next )
- unlink_uni(flow);
+ unlink_uni(flow);
if ( flow->was_blocked() )
delete_stats.update(FlowDeleteState::BLOCKED);
// FIXIT-M refactor to unlink_uni immediately after session
// is processed by inspector manager (all flows)
- if ( flow->next && is_bidirectional(flow) )
+ if ( is_bidirectional(flow) )
cache->unlink_uni(flow);
return true;
++count;
}
- void unlink_uni(snort::Flow* flow)
+ bool unlink_uni(snort::Flow* flow)
{
if ( !flow->next )
- return;
+ return false;
flow->next->prev = flow->prev;
flow->prev->next = flow->next;
flow->next = flow->prev = nullptr;
--count;
+ return true;
}
snort::Flow* get_oldest_uni()
#include "detection/detection_engine.h"
#include "main/snort_config.h"
+#include "main/snort_debug.h"
#include "managers/inspector_manager.h"
#include "memory/memory_cap.h"
#include "packet_io/active.h"
THREAD_LOCAL Active::ActiveSuspendReason Active::s_suspend_reason = Active::ASP_NONE;
THREAD_LOCAL PacketTracer* snort::s_pkt_trace = nullptr;
+THREAD_LOCAL const Trace* stream_trace = nullptr;
void Active::drop_packet(snort::Packet const*, bool) { }
PacketTracer::~PacketTracer() = default;
Flow* HighAvailabilityManager::import(Packet&, FlowKey&) { return nullptr; }
bool HighAvailabilityManager::in_standby(Flow*) { return true; }
SfIpRet SfIp::set(void const*, int) { return SFIP_SUCCESS; }
+void snort::trace_vprintf(const char*, TraceLevel, const char*, const Packet*, const char*, va_list) {}
+uint8_t snort::TraceApi::get_constraints_generation() { return 0; }
+void snort::TraceApi::filter(const Packet&) {}
namespace memory
{
void MemoryCap::update_allocations(size_t) { }
using namespace snort;
using namespace std;
+#ifdef DEBUG_MSGS
+static const TraceOption stream_trace_options[] =
+{
+ { "base", TRACE_BASE, "enable base stream trace logging" },
+ { "flow", TRACE_FLOW, "enable flow trace logging" },
+ { nullptr, 0, nullptr }
+};
+#endif
+
THREAD_LOCAL const Trace* stream_trace = nullptr;
static THREAD_LOCAL timeval reload_time { };
#ifndef DEBUG_MSGS
return nullptr;
#else
- static const TraceOption stream_trace_options(nullptr, 0, nullptr);
- return &stream_trace_options;
+ return stream_trace_options;
#endif
}
extern THREAD_LOCAL class FlowControl* flow_con;
extern THREAD_LOCAL const snort::Trace* stream_trace;
+#ifdef DEBUG_MSGS
+enum
+{
+ TRACE_BASE = 0,
+ TRACE_FLOW
+};
+#endif
+
//-------------------------------------------------------------------------
// stream module
//-------------------------------------------------------------------------
{
assert(flow && flow->session);
- debug_logf(stream_trace, p, "stop inspection on flow, dir %s \n",
+ debug_logf(stream_trace, TRACE_BASE, p, "stop inspection on flow, dir %s \n",
dir == SSN_DIR_BOTH ? "BOTH" :
((dir == SSN_DIR_FROM_CLIENT) ? "FROM_CLIENT" : "FROM_SERVER"));