]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
move offload_limit to detection; use trace feature
authorRuss Combs <rucombs@cisco.com>
Fri, 28 Oct 2016 11:34:52 +0000 (07:34 -0400)
committerRuss Combs <rucombs@cisco.com>
Wed, 18 Jan 2017 15:44:45 +0000 (10:44 -0500)
src/detection/context_switcher.cc
src/detection/detection_engine.cc
src/detection/fp_config.cc
src/detection/fp_config.h
src/main/modules.cc
src/main/modules.h
src/main/snort_config.h

index 71b0743d0943c1e45e9ff615245be2d4093d56f2..ce95832ac3e85ef19acdf6de8d73e5bb88466101 100644 (file)
 
 #include <assert.h>
 
+#include "main/modules.h"
+#include "main/snort_debug.h"
 #include "utils/stats.h"
+
 #include "ips_context.h"
 
 #ifdef UNIT_TEST
@@ -70,8 +73,8 @@ void ContextSwitcher::start()
 {
     assert(busy.empty());
     assert(idle.size() > 0);
-//printf("%ld cs::start %u (i=%lu, b=%lu)\n",
-//    pc.total_from_daq, idle.back()->get_slot(), idle.size(), busy.size());
+    trace_logf(detection, "%ld cs::start %u (i=%lu, b=%lu)\n",
+        pc.total_from_daq, idle.back()->get_slot(), idle.size(), busy.size());
     busy.push_back(idle.back());
     idle.pop_back();
 }
@@ -79,16 +82,16 @@ void ContextSwitcher::start()
 void ContextSwitcher::stop()
 {
     assert(busy.size() == 1);
-//printf("%ld cs::stop %u (i=%lu, b=%lu)\n",
-//    pc.total_from_daq, busy.back()->get_slot(), idle.size(), busy.size());
+    trace_logf(detection, "%ld cs::stop %u (i=%lu, b=%lu)\n",
+        pc.total_from_daq, busy.back()->get_slot(), idle.size(), busy.size());
     idle.push_back(busy.back());
     busy.pop_back();
 }
 
 void ContextSwitcher::abort()
 {
-//printf("%ld cs::abort (i=%lu, b=%lu)\n",
-//    pc.total_from_daq, idle.size(), busy.size());
+    trace_logf(detection, "%ld cs::abort (i=%lu, b=%lu)\n",
+        pc.total_from_daq, idle.size(), busy.size());
     for ( unsigned i = 0; i < hold.capacity(); ++i )
     {
         if ( hold[i] )
@@ -107,8 +110,8 @@ void ContextSwitcher::abort()
 IpsContext* ContextSwitcher::interrupt()
 {
     assert(!idle.empty());
-//printf("%ld cs::interrupt %u (i=%lu, b=%lu)\n",
-//    pc.total_from_daq, idle.back()->get_slot(), idle.size(), busy.size());
+    trace_logf(detection, "%ld cs::interrupt %u (i=%lu, b=%lu)\n",
+        pc.total_from_daq, idle.back()->get_slot(), idle.size(), busy.size());
     busy.push_back(idle.back());
     idle.pop_back();
     return busy.back();
@@ -117,8 +120,8 @@ IpsContext* ContextSwitcher::interrupt()
 IpsContext* ContextSwitcher::complete()
 {
     assert(!busy.empty());
-//printf("%ld cs::complete %u (i=%lu, b=%lu)\n",
-//    pc.total_from_daq, busy.back()->get_slot(), idle.size(), busy.size());
+    trace_logf(detection, "%ld cs::complete %u (i=%lu, b=%lu)\n",
+        pc.total_from_daq, busy.back()->get_slot(), idle.size(), busy.size());
     idle.push_back(busy.back());
     busy.pop_back();
     return busy.empty() ? nullptr : busy.back();
@@ -127,8 +130,8 @@ IpsContext* ContextSwitcher::complete()
 unsigned ContextSwitcher::suspend()
 {
     assert(!busy.empty());
-//printf("%ld cs::suspend %u (i=%lu, b=%lu)\n",
-//    pc.total_from_daq, busy.back()->get_slot(), idle.size(), busy.size());
+    trace_logf(detection, "%ld cs::suspend %u (i=%lu, b=%lu)\n",
+        pc.total_from_daq, busy.back()->get_slot(), idle.size(), busy.size());
     IpsContext* c = busy.back();
     busy.pop_back();
     unsigned slot = c->get_slot();
@@ -140,8 +143,8 @@ unsigned ContextSwitcher::suspend()
 void ContextSwitcher::resume(unsigned slot)
 {
     assert(slot <= hold.capacity());
-//printf("%ld cs::resume %u (i=%lu, b=%lu)\n",
-//    pc.total_from_daq, slot, idle.size(), busy.size());
+    trace_logf(detection, "%ld cs::resume %u (i=%lu, b=%lu)\n",
+        pc.total_from_daq, slot, idle.size(), busy.size());
     busy.push_back(hold[slot]);
     hold[slot] = nullptr;
 }
index 24c13e2487d1d9b5944dcaf62cd01b82077be8c2..6218595f4ef20d2e4be5b8e42060e4037665c70d 100644 (file)
 #include "framework/endianness.h"
 #include "helpers/ring.h"
 #include "latency/packet_latency.h"
+#include "main/modules.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
+#include "main/snort_debug.h"
 #include "main/thread.h"
 #include "managers/inspector_manager.h"
 #include "packet_io/active.h"
@@ -43,6 +45,8 @@
 #include "fp_detect.h"
 #include "ips_context.h"
 
+Trace TRACE_NAME(detection);
+
 THREAD_LOCAL DetectionEngine::ActiveRules active_rules = DetectionEngine::NONE;
 
 static THREAD_LOCAL unsigned s_events = 0;
@@ -183,11 +187,11 @@ void DetectionEngine::idle()
     while ( !offload_ids->empty() )
     {
         const struct timespec blip = { 0, 1 };
-//printf("%lu de::sleep\n", pc.total_from_daq);
+        trace_logf(detection, "%lu de::sleep\n", pc.total_from_daq);
         nanosleep(&blip, nullptr);
         onload();
     }
-//printf("%lu de::idle (r=%d)\n", pc.total_from_daq, offload_ids->count());
+    trace_logf(detection, "%lu de::idle (r=%d)\n", pc.total_from_daq, offload_ids->count());
 }
 
 void DetectionEngine::onload(Flow* flow)
@@ -195,7 +199,7 @@ void DetectionEngine::onload(Flow* flow)
     while ( flow->test_session_flags(SSNFLAG_OFFLOAD) )
     {
         const struct timespec blip = { 0, 1 };
-//printf("%lu de::sleep\n", pc.total_from_daq);
+        trace_logf(detection, "%lu de::sleep\n", pc.total_from_daq);
         nanosleep(&blip, nullptr);
         onload();
     }
@@ -212,7 +216,9 @@ void DetectionEngine::onload()
     if ( !c->onload )
         return;
 
-//printf("%lu de::onload %u (r=%d)\n", pc.total_from_daq, *id, offload_ids->count());
+    trace_logf(detection, "%lu de::onload %u (r=%d)\n",
+        pc.total_from_daq, *id, offload_ids->count());
+
     Packet* p = c->packet;
     p->flow->clear_session_flags(SSNFLAG_OFFLOAD);
 
@@ -233,9 +239,8 @@ void DetectionEngine::onload()
 bool DetectionEngine::offload(Packet* p)
 {
     ContextSwitcher* sw = Snort::get_switcher();
-    FastPatternConfig* fp = snort_conf->fast_pattern_config;
 
-    if ( p->type() != PktType::PDU or (p->dsize < fp->get_offload_limit()) or !sw->can_hold() )
+    if ( p->type() != PktType::PDU or (p->dsize < snort_conf->offload_limit) or !sw->can_hold() )
     {
         fp_local(p);
         return false;
@@ -248,7 +253,9 @@ bool DetectionEngine::offload(Packet* p)
 
     unsigned id = sw->suspend();
     offload_ids->put(id);
-//printf("%lu de::offload %u (r=%d)\n", pc.total_from_daq, id, offload_ids->count());
+
+    trace_logf(detection, "%lu de::offload %u (r=%d)\n",
+        pc.total_from_daq, id, offload_ids->count());
 
     p->context->onload = false;
     p->context->offload = new std::thread(fp_offload, p, snort_conf);
index 885c0c107fb280a11114695d2042f1e43f51f5d7..a343cb7f70f2965a1bab8f58e2a4270fd9d2c47a 100644 (file)
@@ -46,8 +46,6 @@ FastPatternConfig::FastPatternConfig()
     search_api = MpseManager::get_search_api("ac_bnfa");
     assert(search_api);
     trim = MpseManager::search_engine_trim(search_api);
-
-    offload_limit = 99999;  // FIXIT-H use common value
 }
 
 FastPatternConfig::~FastPatternConfig()
index e4e85f1f093a8a65ab7114661f04ac587e1850e7..e8152e2fddb08f44b8a348755f1b6fa727bec788 100644 (file)
@@ -64,12 +64,6 @@ public:
     int get_bleed_over_port_limit()
     { return bleedover_port_limit; }
 
-    void set_offload_limit(unsigned n)
-    { offload_limit = n; }
-
-    unsigned get_offload_limit()
-    { return offload_limit; }
-
     int get_single_rule_group()
     { return portlists_flags & PL_SINGLE_RULE_GROUP; }
 
@@ -158,7 +152,6 @@ private:
 
     unsigned max_queue_events;
     unsigned bleedover_port_limit;
-    unsigned offload_limit;
 
     int search_opt;
     int portlists_flags;
index fa4bccf731931491a8b71981292871acd47dfc97..3344d476dad71a58208686d7e84578927cb9f312 100644 (file)
@@ -69,6 +69,9 @@ static const Parameter detection_params[] =
     { "asn1", Parameter::PT_INT, "1:", "256",
       "maximum decode nodes" },
 
+    { "offload_limit", Parameter::PT_INT, "0:", "99999",
+      "minimum sizeof PDU to offload fast pattern search (defaults to disabled)" },
+
     { "pcre_enable", Parameter::PT_BOOL, nullptr, "true",
       "disable pcre pattern matching" },
 
@@ -88,7 +91,8 @@ static const Parameter detection_params[] =
 class DetectionModule : public Module
 {
 public:
-    DetectionModule() : Module("detection", detection_help, detection_params) {}
+    DetectionModule() :
+        Module("detection", detection_help, detection_params, false, &TRACE_NAME(detection)) {}
     bool set(const char*, Value&, SnortConfig*) override;
 
     const PegInfo* get_pegs() const override
@@ -98,11 +102,14 @@ public:
     { return (PegCount*) &pc; }
 };
 
-bool DetectionModule::set(const char*, Value& v, SnortConfig* sc)
+bool DetectionModule::set(const char* fqn, Value& v, SnortConfig* sc)
 {
     if ( v.is("asn1") )
         sc->asn1_mem = v.get_long();
 
+    else if ( v.is("offload_limit") )
+        sc->offload_limit = v.get_long();
+
     else if ( v.is("pcre_enable") )
         v.update_mask(sc->run_flags, RUN_FLAG__NO_PCRE, true);
 
@@ -113,7 +120,7 @@ bool DetectionModule::set(const char*, Value& v, SnortConfig* sc)
         sc->pcre_match_limit_recursion = v.get_long();
 
     else
-        return false;
+        return Module::set(fqn, v, sc);
 
     return true;
 }
@@ -221,9 +228,6 @@ static const Parameter search_engine_params[] =
     { "inspect_stream_inserts", Parameter::PT_BOOL, nullptr, "false",
       "inspect reassembled payload - disabling is good for performance, bad for detection" },
 
-    { "offload_limit", Parameter::PT_INT, "0:", "99999",
-      "minimum sizeof PDU to offload fast pattern search (defaults to disabled)" },
-
     { "search_method", Parameter::PT_DYNAMIC, (void*)&get_search_methods, "ac_bnfa",
       "set fast pattern algorithm - choose available search engine" },
 
@@ -319,9 +323,6 @@ bool SearchEngineModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( v.is("inspect_stream_inserts") )
         fp->set_stream_insert(v.get_bool());
 
-    else if ( v.is("offload_limit") )
-        fp->set_offload_limit(v.get_long());
-
     else if ( v.is("search_method") )
     {
         if ( !fp->set_detect_search_method(v.get_string()) )
index ffc85e1523f9b0e9c4eb3e10c2c2eed072d9abec..639b21f206fcc5a5e3eeda2ec39a4b4b8f9fa0b7 100644 (file)
 // this is for builtin module initialization.
 // ideally, modules.cc would be refactored and several files.
 
+#include "main/snort_debug.h"
+
 void module_init();
 
+extern Trace TRACE_NAME(detection);  // FIXIT-L refactor detection module out
+
 #endif
 
index e01df2cd9a47e4f90255e48d25b7459e613f8e52..2c397a7847ef256c190532fbe33c24b6d785e182 100644 (file)
@@ -183,6 +183,8 @@ public:
     int asn1_mem = 0;
     uint32_t run_flags = 0;
 
+    unsigned offload_limit = 99999;
+
     //------------------------------------------------------
     // process stuff