detect.h
detection_defines.h
detection_util.h
+ ips_context.h
rule_option_types.h
rules.h
signature.h
add_library (detection STATIC
${DETECTION_INCLUDES}
+ context_switcher.cc
+ context_switcher.h
detect.cc
detection_options.cc
detection_options.h
fp_detect.h
fp_utils.cc
fp_utils.h
+ ips_context.cc
pattern_match_data.h
pcrm.cc
pcrm.h
detect.h \
detection_defines.h \
detection_util.h \
+ips_context.h \
rule_option_types.h \
rules.h \
signature.h \
treenodes.h
libdetection_a_SOURCES = \
+context_switcher.cc \
+context_switcher.h \
detect.cc \
detection_options.cc \
detection_options.h \
fp_detect.h \
fp_utils.cc \
fp_utils.h \
+ips_context.cc \
pattern_match_data.h \
pcrm.cc \
pcrm.h \
#include "context_switcher.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <assert.h>
#include "ips_context.h"
-#define UNIT_TEST
-
#ifdef UNIT_TEST
-#include "catch.hpp"
+#include "catch/catch.hpp"
#endif
//--------------------------------------------------------------------------
ContextData(int) { }
};
-TEST_CASE("normal", "[ContextSwitcher]")
+TEST_CASE("ContextSwitcher normal", "[ContextSwitcher]")
{
const unsigned max = 3;
auto mgr = ContextSwitcher(max);
CHECK(!mgr.pop());
}
-TEST_CASE("abort", "[ContextSwitcher]")
+TEST_CASE("ContextSwitcher abort", "[ContextSwitcher]")
{
const unsigned max = 3;
auto mgr = ContextSwitcher(max);
#include "ips_context.h"
-#include <assert.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
-#define UNIT_TEST
+#include <assert.h>
#ifdef UNIT_TEST
-#include "catch.hpp"
+#include "catch/catch.hpp"
#endif
-unsigned IpsContextData::ips_id = 0;
+//--------------------------------------------------------------------------
+// context data
+//--------------------------------------------------------------------------
+
+// ips_id is not a member of context data so that
+// tests (and only tests) can reset the id
+static unsigned ips_id = 0;
+
+unsigned IpsContextData::get_ips_id()
+{ return ++ips_id; }
+
+unsigned IpsContextData::get_max_id()
+{ return ips_id; }
//--------------------------------------------------------------------------
// context methods
class ContextData : public IpsContextData
{
public:
- ContextData(int i)
+ ContextData(int)
{ ++count; }
~ContextData()
int ContextData::count = 0;
-TEST_CASE("ips_ids", "[IpsContextData]")
+TEST_CASE("IpsContextData id", "[IpsContextData]")
{
+ ips_id = 0;
CHECK(IpsContextData::get_max_id() == 0);
unsigned id1 = IpsContextData::get_ips_id();
CHECK(IpsContextData::get_max_id() == id2);
}
-TEST_CASE("basic", "[IpsContext]")
+TEST_CASE("IpsContext basic", "[IpsContext]")
{
+ ips_id = 0;
+
SECTION("one context")
{
auto id = IpsContextData::get_ips_id();
public:
virtual ~IpsContextData() { };
- static unsigned get_ips_id()
- { return ++ips_id; }
-
- static unsigned get_max_id()
- { return ips_id; }
+ static unsigned get_ips_id();
+ static unsigned get_max_id();
protected:
IpsContextData() { }
-
-private:
- static unsigned ips_id;
};
class IpsContext
#include "codecs/codec_api.h"
#include "connectors/connectors.h"
#include "decompress/file_decomp.h"
+#include "detection/context_switcher.h"
#include "detection/detect.h"
#include "detection/detection_util.h"
#include "detection/fp_config.h"
#include "detection/fp_detect.h"
+#include "detection/ips_context.h"
#include "detection/tag.h"
#include "file_api/file_service.h"
#include "filters/detection_filter.h"
static THREAD_LOCAL DAQ_PktHdr_t s_pkth;
static THREAD_LOCAL uint8_t s_data[65536];
static THREAD_LOCAL Packet* s_packet = nullptr;
+static THREAD_LOCAL ContextSwitcher* s_switcher = nullptr;
//-------------------------------------------------------------------------
// perf stats
*/
void Snort::thread_init_unprivileged()
{
+ // using dummy values until further integration
+ const unsigned max_contexts = 5;
+ const unsigned max_data = 1;
+
+ s_switcher = new ContextSwitcher(max_contexts);
+
+ for ( unsigned i = 0; i < max_contexts; ++i )
+ s_switcher->push(new IpsContext(max_data));
+
s_packet = new Packet(false);
CodecManager::thread_init(snort_conf);
SnortEventqFree();
Active::term();
+ delete s_switcher;
}
void Snort::detect_rebuilt_packet(Packet* p)
if ( snort_conf->pkt_skip && pc.total_from_daq <= snort_conf->pkt_skip )
return DAQ_VERDICT_PASS;
+ s_switcher->start();
+
{
Profile eventq_profile(eventqPerfStats);
SnortEventqReset();
else if ( break_time() )
SFDAQ::break_loop(0);
+ s_switcher->stop();
+
return verdict;
}