]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2165 in SNORT/snort3 from ~SVLASIUK/snort3:trace_module to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Fri, 8 May 2020 17:31:11 +0000 (17:31 +0000)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Fri, 8 May 2020 17:31:11 +0000 (17:31 +0000)
Squashed commit of the following:

commit 64ec8e2b940ab8815d8061f9a50ee6e82de3c435
Author: Serhii Vlasiuk <svlasiuk@cisco.com>
Date:   Thu Apr 2 13:10:17 2020 +0300

    trace: move module trace configuration into the trace module.

    Instead of trace configuration being distributed amongst the individual module configurations,
    all module trace topic and level configuration is now centralized within the trace module.

118 files changed:
src/codecs/codec_module.cc
src/codecs/codec_module.h
src/codecs/ip/cd_auth.cc
src/codecs/ip/cd_esp.cc
src/codecs/ip/cd_gre.cc
src/codecs/ip/cd_icmp4.cc
src/codecs/ip/cd_icmp6.cc
src/codecs/ip/cd_igmp.cc
src/codecs/ip/cd_ipv4.cc
src/codecs/ip/cd_ipv6.cc
src/codecs/ip/cd_pgm.cc
src/codecs/ip/cd_tcp.cc
src/codecs/ip/cd_udp.cc
src/codecs/link/cd_arp.cc
src/codecs/link/cd_ciscometadata.cc
src/codecs/link/cd_erspan2.cc
src/codecs/link/cd_erspan3.cc
src/codecs/link/cd_fabricpath.cc
src/codecs/link/cd_mpls.cc
src/codecs/link/cd_pppoe.cc
src/codecs/link/cd_vlan.cc
src/codecs/misc/cd_gtp.cc
src/codecs/misc/cd_llc.cc
src/codecs/root/cd_eth.cc
src/connectors/file_connector/test/file_connector_module_test.cc
src/connectors/file_connector/test/file_connector_test.cc
src/connectors/tcp_connector/test/tcp_connector_module_test.cc
src/connectors/tcp_connector/test/tcp_connector_test.cc
src/detection/context_switcher.cc
src/detection/detect_trace.cc
src/detection/detect_trace.h
src/detection/detection_module.cc
src/detection/detection_module.h
src/detection/detection_options.cc
src/detection/tag.cc
src/detection/tag.h
src/file_api/file_mempool.h
src/flow/test/flow_test.cc
src/framework/module.cc
src/framework/module.h
src/framework/parameter.cc
src/framework/parameter.h
src/host_tracker/test/host_cache_module_test.cc
src/host_tracker/test/host_tracker_module_test.cc
src/ips_options/test/ips_regex_test.cc
src/latency/latency_config.h
src/latency/latency_module.cc
src/latency/latency_module.h
src/latency/packet_latency.cc
src/main.cc
src/main/CMakeLists.txt
src/main/analyzer.cc
src/main/modules.cc
src/main/modules.h
src/main/snort.cc
src/main/snort_config.cc
src/main/snort_config.h
src/main/snort_debug.cc
src/main/snort_debug.h
src/main/snort_module.cc
src/main/snort_module.h
src/main/trace.cc [deleted file]
src/managers/module_manager.cc
src/network_inspectors/appid/appid_module.cc
src/network_inspectors/appid/appid_module.h
src/network_inspectors/appid/client_plugins/test/client_plugin_mock.h
src/network_inspectors/appid/detector_plugins/detector_pattern.cc
src/network_inspectors/appid/detector_plugins/detector_pattern.h
src/network_inspectors/appid/detector_plugins/test/detector_plugins_mock.h
src/network_inspectors/appid/detector_plugins/test/http_url_patterns_test.cc
src/network_inspectors/appid/lua_detector_api.cc
src/network_inspectors/appid/lua_detector_api.h
src/network_inspectors/appid/service_plugins/service_netbios.cc
src/network_inspectors/appid/service_plugins/test/service_plugin_mock.h
src/network_inspectors/appid/test/appid_discovery_test.cc
src/network_inspectors/appid/test/appid_mock_inspector.h
src/network_inspectors/appid/test/tp_lib_handler_test.cc
src/protocols/packet_manager.cc
src/search_engines/test/hyperscan_test.cc
src/service_inspectors/dce_rpc/dce_smb2.cc
src/service_inspectors/dce_rpc/dce_smb_module.cc
src/service_inspectors/dce_rpc/dce_smb_module.h
src/service_inspectors/dce_rpc/dce_smb_transaction.cc
src/service_inspectors/dce_rpc/dce_smb_utils.cc
src/service_inspectors/dce_rpc/dce_udp_module.cc
src/service_inspectors/dce_rpc/dce_udp_module.h
src/service_inspectors/dce_rpc/smb_message.cc
src/service_inspectors/gtp/gtp_module.cc
src/service_inspectors/gtp/gtp_module.h
src/service_inspectors/gtp/gtp_parser.cc
src/service_inspectors/http_inspect/test/http_module_test.cc
src/service_inspectors/http_inspect/test/http_uri_norm_test.cc
src/service_inspectors/wizard/wiz_module.cc
src/service_inspectors/wizard/wiz_module.h
src/service_inspectors/wizard/wizard.cc
src/side_channel/test/side_channel_module_test.cc
src/side_channel/test/side_channel_test.cc
src/stream/base/stream_module.cc
src/stream/base/stream_module.h
src/stream/ip/ip_defrag.cc
src/stream/ip/ip_module.cc
src/stream/ip/ip_module.h
src/stream/stream.cc
src/stream/tcp/tcp_segment_node.h
src/stream/user/user_module.cc
src/stream/user/user_module.h
src/stream/user/user_session.cc
src/target_based/test/proto_ref_test.cc
src/trace/CMakeLists.txt
src/trace/dev_notes.txt
src/trace/trace.cc [new file with mode: 0644]
src/trace/trace.h [moved from src/main/trace.h with 54% similarity]
src/trace/trace_api.cc [moved from src/trace/trace_log_api.cc with 75% similarity]
src/trace/trace_api.h [moved from src/trace/trace_log_api.h with 87% similarity]
src/trace/trace_config.cc
src/trace/trace_config.h
src/trace/trace_module.cc
src/trace/trace_module.h

index f619e3870587eac7b929163ec0e529c64f374145..bd188fdc7a420666529254360d45386d43c9cf16 100644 (file)
 
 #include "codecs/codec_module.h"
 
-#include "main/snort_debug.h"
+#include "trace/trace.h"
 
 using namespace snort;
 
 #define codec_module_help \
     "general decoder rules"
 
-static const char s_module_name[] = "decode";
+#define s_name "decode"
 
-Trace decode_trace(s_module_name);
+THREAD_LOCAL const Trace* decode_trace = nullptr;
 
 static const Parameter s_params[] = {{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }};
 
-CodecModule::CodecModule() : Module(s_module_name, codec_module_help, s_params, false, &decode_trace)
+CodecModule::CodecModule() : BaseCodecModule(s_name, codec_module_help, s_params)
 { }
 
-bool CodecModule::set(const char* fqn, Value& v, SnortConfig* sc)
+void CodecModule::set_trace(const Trace* trace) const
+{ decode_trace = trace; }
+
+const TraceOption* CodecModule::get_trace_options() const
 {
-    return Module::set(fqn, v, sc);
+    static const TraceOption codec_trace_options(nullptr, 0, nullptr);
+    return &codec_trace_options;
 }
 
 static const RuleMap general_decode_rules[] =
index a180c0984869408eb6c397f0979ead2daaa5f55e..1c39e9d2e6e08a9a96e13bc1f7490673fad99b35 100644 (file)
 #include <cstdint>
 
 #include "framework/module.h"
-#include "main/snort_debug.h"
 #include "main/snort_types.h"
 
+namespace snort
+{
+class Trace;
+}
+
+extern THREAD_LOCAL const snort::Trace* decode_trace;
+
 namespace snort
 {
 constexpr int GID_DECODE = 116;
@@ -221,29 +227,33 @@ enum CodecSid : uint32_t
 // module
 //-------------------------------------------------------------------------
 
-class SO_PUBLIC CodecModule : public Module
+class BaseCodecModule : public Module
 {
 public:
-    CodecModule();
-    CodecModule(const char* s, const char* h) : Module(s, h)
+    BaseCodecModule(const char* s, const char* h) : Module(s, h)
     { }
 
-    CodecModule(const char* s, const char* h, const Parameter* p, bool is_list = false)
+    BaseCodecModule(const char* s, const char* h, const Parameter* p, bool is_list = false)
         : Module(s, h, p, is_list) { }
 
     unsigned get_gid() const override
     { return GID_DECODE; }
 
-    const RuleMap* get_rules() const override;
-
     Usage get_usage() const override
     { return CONTEXT; }
+};
+
+class SO_PUBLIC CodecModule : public BaseCodecModule
+{
+public:
+    CodecModule();
+
+    const RuleMap* get_rules() const override;
 
-    bool set(const char*, snort::Value&, snort::SnortConfig*) override;
+    void set_trace(const Trace*) const override;
+    const TraceOption* get_trace_options() const override;
 };
 }
 
-extern snort::Trace decode_trace;
-
 #endif
 
index 7f8662842afab909c2f654920f0fc1b3ee3a02f2..ce449d9ecb5626d176d89181dcb6139831b23c04 100644 (file)
@@ -39,10 +39,10 @@ static const RuleMap auth_rules[] =
     { 0, nullptr }
 };
 
-class AuthModule : public CodecModule
+class AuthModule : public BaseCodecModule
 {
 public:
-    AuthModule() : CodecModule(CD_AUTH_NAME, CD_AUTH_HELP) { }
+    AuthModule() : BaseCodecModule(CD_AUTH_NAME, CD_AUTH_HELP) { }
 
     const RuleMap* get_rules() const override
     { return auth_rules; }
index 843cebba9e78259b9bc06068359eb345a46856c9..d2e1add93ae2a2f41dc49e1cd71b697f0338ca3a 100644 (file)
@@ -47,10 +47,10 @@ static const Parameter esp_params[] =
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-class EspModule : public CodecModule
+class EspModule : public BaseCodecModule
 {
 public:
-    EspModule() : CodecModule(CD_ESP_NAME, CD_ESP_HELP, esp_params) { }
+    EspModule() : BaseCodecModule(CD_ESP_NAME, CD_ESP_HELP, esp_params) { }
 
     const RuleMap* get_rules() const override
     { return esp_rules; }
index 41f0e4da9676c8d5899949ddaf0d65452f0233f0..407b6bd0aef5e5c1af48f694d69f980990aac78d 100644 (file)
@@ -53,10 +53,10 @@ static const RuleMap gre_rules[] =
     { 0, nullptr }
 };
 
-class GreModule : public CodecModule
+class GreModule : public BaseCodecModule
 {
 public:
-    GreModule() : CodecModule(CD_GRE_NAME, CD_GRE_HELP) { }
+    GreModule() : BaseCodecModule(CD_GRE_NAME, CD_GRE_HELP) { }
 
     const RuleMap* get_rules() const override
     { return gre_rules; }
index 57ae178d0e8f4497c8b2bcc31c087f09f90e7255..5c3e73eb6298cb6185500c986c6fafb12080e434 100644 (file)
@@ -90,10 +90,10 @@ static const RuleMap icmp4_rules[] =
     { 0, nullptr }
 };
 
-class Icmp4Module : public CodecModule
+class Icmp4Module : public BaseCodecModule
 {
 public:
-    Icmp4Module() : CodecModule(CD_ICMP4_NAME, CD_ICMP4_HELP) { }
+    Icmp4Module() : BaseCodecModule(CD_ICMP4_NAME, CD_ICMP4_HELP) { }
 
     const RuleMap* get_rules() const override
     { return icmp4_rules; }
index 515f4fd7d6bf598f84258f432fb9be0a9b55a559..20dbd9a5b93785018317680de8dfaa5a79484bb1 100644 (file)
@@ -81,10 +81,10 @@ static const RuleMap icmp6_rules[] =
     { 0, nullptr }
 };
 
-class Icmp6Module : public CodecModule
+class Icmp6Module : public BaseCodecModule
 {
 public:
-    Icmp6Module() : CodecModule(CD_ICMP6_NAME, CD_ICMP6_HELP) { }
+    Icmp6Module() : BaseCodecModule(CD_ICMP6_NAME, CD_ICMP6_HELP) { }
 
     const RuleMap* get_rules() const override
     { return icmp6_rules; }
index cd98736d159b52f7fd4d1a62bf60ba9e1020ada3..5dad1ee7bdda4e591e933020c466b697307244d3 100644 (file)
@@ -37,10 +37,10 @@ static const RuleMap igmp_rules[] =
     { 0, nullptr }
 };
 
-class IgmpModule : public CodecModule
+class IgmpModule : public BaseCodecModule
 {
 public:
-    IgmpModule() : CodecModule(CD_IGMP_NAME, CD_IGMP_HELP) { }
+    IgmpModule() : BaseCodecModule(CD_IGMP_NAME, CD_IGMP_HELP) { }
 
     const RuleMap* get_rules() const override
     { return igmp_rules; }
index bc96a6e09a02119bb2bf44329ae4e4d1b06f038e..525f1cf0d9f36c3a9883b7c1cdac1ef0b393b32b 100644 (file)
@@ -91,10 +91,10 @@ static const RuleMap ipv4_rules[] =
     { 0, nullptr }
 };
 
-class Ipv4Module : public CodecModule
+class Ipv4Module : public BaseCodecModule
 {
 public:
-    Ipv4Module() : CodecModule(CD_IPV4_NAME, CD_IPV4_HELP) { }
+    Ipv4Module() : BaseCodecModule(CD_IPV4_NAME, CD_IPV4_HELP) { }
 
     const RuleMap* get_rules() const override
     { return ipv4_rules; }
index 4aac146c5acf00afd91e7f09738a303bdf29e9cb..f1f8432d4b01ec4378265fb13ba820cd06137fa8 100644 (file)
@@ -75,10 +75,10 @@ static const RuleMap ipv6_rules[] =
     { 0, nullptr }
 };
 
-class Ipv6Module : public CodecModule
+class Ipv6Module : public BaseCodecModule
 {
 public:
-    Ipv6Module() : CodecModule(CD_IPV6_NAME, CD_IPV6_HELP) { }
+    Ipv6Module() : BaseCodecModule(CD_IPV6_NAME, CD_IPV6_HELP) { }
 
     const RuleMap* get_rules() const override
     { return ipv6_rules; }
index c71a8a7cefa93bff7fb6e814e9c897227d8c37f6..a4e495596d9bc8968c4cafebf788a8ded8853379 100644 (file)
@@ -40,10 +40,10 @@ static const RuleMap pgm_rules[] =
     { 0, nullptr }
 };
 
-class PgmModule : public CodecModule
+class PgmModule : public BaseCodecModule
 {
 public:
-    PgmModule() : CodecModule(CD_PGM_NAME, CD_PGM_HELP) { }
+    PgmModule() : BaseCodecModule(CD_PGM_NAME, CD_PGM_HELP) { }
 
     const RuleMap* get_rules() const override
     { return pgm_rules; }
index 6e43611c9a9d3fe004c5bb0cb26f42f3332dd923..4bdcde16737564c88ff0c338453e02052f318a02 100644 (file)
@@ -96,10 +96,10 @@ static const RuleMap tcp_rules[] =
     { 0, nullptr }
 };
 
-class TcpModule : public CodecModule
+class TcpModule : public BaseCodecModule
 {
 public:
-    TcpModule() : CodecModule(CD_TCP_NAME, CD_TCP_HELP) { }
+    TcpModule() : BaseCodecModule(CD_TCP_NAME, CD_TCP_HELP) { }
 
     const RuleMap* get_rules() const override
     { return tcp_rules; }
index 333051de3dd3251d640252850feec060d3353604..8443a82adcd73fa3df77cecf31db84cb61c99b36 100644 (file)
@@ -137,10 +137,10 @@ private:
     bool vxlan_decode = true;
 };
 
-class UdpModule : public CodecModule
+class UdpModule : public BaseCodecModule
 {
 public:
-    UdpModule() : CodecModule(CD_UDP_NAME, CD_UDP_HELP, udp_params)
+    UdpModule() : BaseCodecModule(CD_UDP_NAME, CD_UDP_HELP, udp_params)
     {
         config = nullptr;
     }
@@ -172,6 +172,7 @@ public:
         config = nullptr;
         return tmp;
     }
+    
 private:
     UdpCodecConfig* config;
 };
index 3cedb38238eb1f0cac9f6d987ee5c0be7a3c7cf2..d387ea58738ec95ee9686a45fb2fdf7ef3d50c10 100644 (file)
@@ -39,10 +39,10 @@ static const RuleMap arp_rules[] =
     { 0, nullptr }
 };
 
-class ArpModule : public CodecModule
+class ArpModule : public BaseCodecModule
 {
 public:
-    ArpModule() : CodecModule(CD_ARP_NAME, CD_ARP_HELP) { }
+    ArpModule() : BaseCodecModule(CD_ARP_NAME, CD_ARP_HELP) { }
 
     const RuleMap* get_rules() const override
     { return arp_rules; }
index 55e46d1ea281d9f7643615f9f553972ad418237e..f7d8f9c878d3f53db051f09bf740bd182b17d847 100644 (file)
@@ -64,10 +64,10 @@ struct CiscoMetaDataStats
 };
 static THREAD_LOCAL CiscoMetaDataStats ciscometadata_stats;
 
-class CiscoMetaDataModule : public CodecModule
+class CiscoMetaDataModule : public BaseCodecModule
 {
 public:
-    CiscoMetaDataModule() : CodecModule(CD_CISCOMETADATA_NAME, CD_CISCOMETADATA_HELP) { }
+    CiscoMetaDataModule() : BaseCodecModule(CD_CISCOMETADATA_NAME, CD_CISCOMETADATA_HELP) { }
 
     const RuleMap* get_rules() const override
     { return ciscometadata_rules; }
index f746c583935a00ba95888097aa98dbbb6b834e58..54abe21c6d3eeb47dc65249a392c316cc7372be2 100644 (file)
@@ -38,10 +38,10 @@ static const RuleMap erspan2_rules[] =
     { 0, nullptr }
 };
 
-class Erspan2Module : public CodecModule
+class Erspan2Module : public BaseCodecModule
 {
 public:
-    Erspan2Module() : CodecModule(CD_ERSPAN2_NAME, CD_ERSPAN2_HELP) { }
+    Erspan2Module() : BaseCodecModule(CD_ERSPAN2_NAME, CD_ERSPAN2_HELP) { }
 
     const RuleMap* get_rules() const override
     { return erspan2_rules; }
index a7bc44c8f9eae9902d5bb50d8c4488bd31915a07..e10d03ab3c1acc518969fbb9bc1fb5f729cde064 100644 (file)
@@ -37,10 +37,10 @@ static const RuleMap erspan3_rules[] =
     { 0, nullptr }
 };
 
-class Erspan3Module : public CodecModule
+class Erspan3Module : public BaseCodecModule
 {
 public:
-    Erspan3Module() : CodecModule(CD_ERSPAN3_NAME, CD_ERSPAN3_HELP) { }
+    Erspan3Module() : BaseCodecModule(CD_ERSPAN3_NAME, CD_ERSPAN3_HELP) { }
 
     const RuleMap* get_rules() const override
     { return erspan3_rules; }
index 1b351f750318471dfabecb30697b478cd6e7c3a5..423e748b986e7ed00d03ee7085c22a506ef161c9 100644 (file)
@@ -37,10 +37,10 @@ static const RuleMap fabricpath_rules[] =
     { 0, nullptr }
 };
 
-class FabricPathModule : public CodecModule
+class FabricPathModule : public BaseCodecModule
 {
 public:
-    FabricPathModule() : CodecModule(CD_FABRICPATH_NAME, CD_FABRICPATH_HELP) { }
+    FabricPathModule() : BaseCodecModule(CD_FABRICPATH_NAME, CD_FABRICPATH_HELP) { }
 
     const RuleMap* get_rules() const override
     { return fabricpath_rules; }
index 1655555cb36ff475e115445c71ba82d17c6880de..8acf8b171a99a3ba34f6b85590547ffba0c4e202 100644 (file)
@@ -78,10 +78,10 @@ struct MplsStats
 };
 static THREAD_LOCAL MplsStats mpls_stats;
 
-class MplsModule : public CodecModule
+class MplsModule : public BaseCodecModule
 {
 public:
-    MplsModule() : CodecModule(CD_MPLS_NAME, CD_MPLS_HELP, mpls_params) { }
+    MplsModule() : BaseCodecModule(CD_MPLS_NAME, CD_MPLS_HELP, mpls_params) { }
 
     const RuleMap* get_rules() const override
     { return mpls_rules; }
index 8205546f88b2a90e6c2c1c3a0882a1224c739b96..e2dc212c12f50e0456ae6b5aa79d5d1adca45648 100644 (file)
@@ -63,10 +63,10 @@ static const RuleMap pppoe_rules[] =
 #define pppoe_help \
     "support for point-to-point protocol over ethernet"
 
-class PPPoEModule : public CodecModule
+class PPPoEModule : public BaseCodecModule
 {
 public:
-    PPPoEModule() : CodecModule(CD_PPPOE_NAME, pppoe_help) { }
+    PPPoEModule() : BaseCodecModule(CD_PPPOE_NAME, pppoe_help) { }
 
     const RuleMap* get_rules() const override
     { return pppoe_rules; }
index c58bf3c4dc28826eb361d6de33574a309469cf1b..045a8c30c46a0858655a58961fd056ba7ff3c480 100644 (file)
@@ -41,10 +41,10 @@ static const RuleMap vlan_rules[] =
     { 0, nullptr }
 };
 
-class VlanModule : public CodecModule
+class VlanModule : public BaseCodecModule
 {
 public:
-    VlanModule() : CodecModule(CD_VLAN_NAME, CD_VLAN_HELP) { }
+    VlanModule() : BaseCodecModule(CD_VLAN_NAME, CD_VLAN_HELP) { }
 
     const RuleMap* get_rules() const override
     { return vlan_rules; }
index 50302aa2cc3edddfdcc8b7e92d059a57a3595dd2..ae9961c65db532f8c0115b746f051164d204d7c5 100644 (file)
@@ -40,10 +40,10 @@ static const RuleMap gtp_rules[] =
     { 0, nullptr }
 };
 
-class GtpModule : public CodecModule
+class GtpModule : public BaseCodecModule
 {
 public:
-    GtpModule() : CodecModule(CD_GTP_NAME, CD_GTP_HELP) { }
+    GtpModule() : BaseCodecModule(CD_GTP_NAME, CD_GTP_HELP) { }
 
     const RuleMap* get_rules() const override
     { return gtp_rules; }
index cbaaf2a240afb6a2594287d8eb7a443fbe96afca..c83c22b4c12802c9331b15d656146424cfb83cc0 100644 (file)
@@ -39,10 +39,10 @@ static const RuleMap llc_rules[] =
     { 0, nullptr }
 };
 
-class LlcModule : public CodecModule
+class LlcModule : public BaseCodecModule
 {
 public:
-    LlcModule() : CodecModule(LLC_NAME, LLC_HELP) {}
+    LlcModule() : BaseCodecModule(LLC_NAME, LLC_HELP) {}
 
     const RuleMap* get_rules() const override
     { return llc_rules; }
index 9f0e16ef7ebd93a3c60f86c7cf77470afccb8214..4a722dd4c8b2b4ddc990c464b3c2522ec64e0129 100644 (file)
@@ -45,10 +45,10 @@ static const RuleMap eth_rules[] =
     { 0, nullptr }
 };
 
-class EthModule : public CodecModule
+class EthModule : public BaseCodecModule
 {
 public:
-    EthModule() : CodecModule(CD_ETH_NAME, CD_ETH_HELP) { }
+    EthModule() : BaseCodecModule(CD_ETH_NAME, CD_ETH_HELP) { }
 
     const RuleMap* get_rules() const override
     { return eth_rules; }
index c69d0af4c973275b55849544da7ed37da434f204..caf39c67eda447a0c7b81a4f8428050d5e1145da 100644 (file)
@@ -26,8 +26,6 @@
 #include "connectors/file_connector/file_connector_module.h"
 #include "profiler/profiler.h"
 
-#include "main/snort_debug.h"
-
 #include <CppUTest/CommandLineTestRunner.h>
 #include <CppUTest/TestHarness.h>
 
@@ -45,12 +43,6 @@ char* snort_strdup(const char* s)
 { return strdup(s); }
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 TEST_GROUP(file_connector_module)
 {
 };
index 825d2c6486e4a0e704268095fc8e16d8a63f802a..313f5a3d68b49a12d050f269eb98178bd9d7b45f 100644 (file)
@@ -26,8 +26,6 @@
 #include "connectors/file_connector/file_connector.h"
 #include "connectors/file_connector/file_connector_module.h"
 
-#include "main/snort_debug.h"
-
 #include <CppUTest/CommandLineTestRunner.h>
 #include <CppUTest/TestHarness.h>
 
@@ -59,12 +57,6 @@ const char* get_instance_file(std::string& file, const char* name)
 { file += name; return nullptr; }
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 FileConnectorModule::FileConnectorModule() :
     Module("FC", "FC Help", nullptr)
 { }
index 45b384c91dbbbc5bba788810f4ab2c3a05c0fdfa..cb3653485cbd15d2e49aa746f95e5551290b7126 100644 (file)
@@ -26,8 +26,6 @@
 #include "connectors/tcp_connector/tcp_connector_module.h"
 #include "profiler/profiler.h"
 
-#include "main/snort_debug.h"
-
 #include <CppUTest/CommandLineTestRunner.h>
 #include <CppUTest/TestHarness.h>
 
@@ -45,12 +43,6 @@ char* snort_strdup(const char* s)
 { return strdup(s); }
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 TEST_GROUP(tcp_connector_module)
 {
 };
index b144f50d2b8331f9c61832f313e4f232199656bc..af9576284221e8c3d7fcad2fb992fda7a5efc487 100644 (file)
@@ -31,8 +31,6 @@
 #include <sys/socket.h>
 #include <unistd.h>
 
-#include "main/snort_debug.h"
-
 #include <CppUTest/CommandLineTestRunner.h>
 #include <CppUTest/TestHarness.h>
 
@@ -170,12 +168,6 @@ static void set_normal_status()
     s_rec_return_zero = false;
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 TcpConnectorModule::TcpConnectorModule() :
     Module("TCPC", "TCPC Help", nullptr)
 { }
index 686be66bfcb1b15e4590d57de90aa35be278a081..58e3b545914ce42541d7d16b060b7e7e677e7f55 100644 (file)
@@ -30,7 +30,6 @@
 #include "packet_io/active.h"
 #include "utils/stats.h"
 
-#include "detection_module.h"
 #include "detect_trace.h"
 #include "ips_context.h"
 #include "ips_context_data.h"
@@ -72,6 +71,7 @@ void ContextSwitcher::start()
     assert(!c->has_callbacks());
 
     c->context_num = ++global_context_num;
+
     debug_logf(detection_trace, TRACE_DETECTION_ENGINE,
         "(wire) %" PRIu64 " cs::start %" PRIu64 " (i=%zu, b=%zu)\n",
         get_packet_number(), c->context_num, idle.size(), busy.size());
index 3ddc3af781e96c43dc462cf3258910c888d6f9f1..e12c8ee7e216d1b35774265ab7b05a97c75e1481 100644 (file)
@@ -25,7 +25,6 @@
 #include "detect_trace.h"
 
 #include "log/log.h"
-#include "main/snort_debug.h"
 #include "main/thread.h"
 #include "protocols/packet.h"
 #include "utils/stats.h"
@@ -96,7 +95,7 @@ void print_pattern(const PatternMatchData* pmd)
 
 void dump_buffer(const uint8_t* buff, unsigned len, Packet* p)
 {
-    if ( !detection_trace.enabled(TRACE_BUFFER) )
+    if ( !trace_enabled(detection_trace, TRACE_BUFFER) )
         return;
 
     if (len == 0)
@@ -125,10 +124,10 @@ void node_eval_trace(const detection_option_tree_node_t* node, const Cursor& cur
             "Reached leaf, cursor name %s, cursor position %u\n", name, pos);
     }
 
-    if ( !detection_trace.enabled(TRACE_BUFFER) )
+    if ( !trace_enabled(detection_trace, TRACE_BUFFER) )
         return;
 
-    if ( detection_trace.enabled(TRACE_BUFFER, 5) )
+    if ( trace_enabled(detection_trace, TRACE_BUFFER, 5) )
                dump_buffer(cursor.buffer() + pos, cursor.length(), p);
     else if ((pos != cursor_pos) || strcmp(cursor_name, name))
     {
index af4b09097c219d537f4accb65aab9a394b30ba0b..1f3527d76c4c48a5a582987ef88ddab7234e30db 100644 (file)
 
 #include "framework/cursor.h"
 #include "main/snort_types.h"
+#include "main/thread.h"
 
 namespace snort
 {
 struct Packet;
-struct Trace;
+class Trace;
 }
 
-extern snort::Trace detection_trace;
+extern THREAD_LOCAL const snort::Trace* detection_trace;
 
 struct detection_option_tree_node_t;
 struct PatternMatchData;
index e97ba5847292aa98ce5dac4df7e72c8be319bb48..bb561e614da67fbe285f45954d160fc223b76a77 100644 (file)
 #include "log/messages.h"
 #include "main/snort_config.h"
 #include "main/thread_config.h"
+#include "trace/trace.h"
 
 #include "detect_trace.h"
 
 using namespace snort;
 
-static const char s_module_name[] = "detection";
+THREAD_LOCAL const Trace* detection_trace = nullptr;
 
-/* *INDENT-OFF* */   //  Uncrustify handles this section incorrectly.
-static const Parameter detection_module_trace_values[] =
+static const TraceOption detection_trace_options[] =
 {
-    { "all", Parameter::PT_INT, "0:255", "0", "enable detection module trace logging options" },
-
-    { "detect_engine", Parameter::PT_INT, "0:255", "0", "enable detection engine trace logging" },
-
-    { "rule_eval", Parameter::PT_INT, "0:255", "0", "enable rule evaluation trace logging" },
-
-    { "buffer", Parameter::PT_INT, "0:255", "0", "enable buffer trace logging" },
-
-    { "rule_vars", Parameter::PT_INT, "0:255", "0", "enable rule variables trace logging" },
-
-    { "fp_search", Parameter::PT_INT, "0:255", "0", "enable fast pattern search trace logging" },
-
-    { "pkt_detect", Parameter::PT_INT, "0:255", "0", "enable packet detection trace logging" },
-
-    { "opt_tree", Parameter::PT_INT, "0:255", "0", "enable tree option trace logging" },
-
-    { "tag", Parameter::PT_INT, "0:255", "0", "enable tag trace logging" },
-
-    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
-};
-
-static const Parameter detection_module_trace[] =
-{
-    { "trace", Parameter::PT_TABLE, detection_module_trace_values, nullptr, "trace config for detection module" },
-
-    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
+    { "detect_engine", TRACE_DETECTION_ENGINE,  "enable detection engine trace logging" },
+    { "rule_eval",     TRACE_RULE_EVAL,         "enable rule evaluation trace logging" },
+    { "buffer",        TRACE_BUFFER,            "enable buffer trace logging" },
+    { "rule_vars",     TRACE_RULE_VARS,         "enable rule variables trace logging" },
+    { "fp_search",     TRACE_FP_SEARCH,         "enable fast pattern search trace logging" },
+    { "pkt_detect",    TRACE_PKT_DETECTION,     "enable packet detection trace logging" },
+    { "opt_tree",      TRACE_OPTION_TREE,       "enable tree option trace logging" },
+    { "tag",           TRACE_TAG,               "enable tag trace logging" },
+
+    { nullptr, 0, nullptr }
 };
 
-static const TraceOptionString detection_trace_options[] =
-{
-    { "detect_engine", TRACE_DETECTION_ENGINE },
-    { "rule_eval",     TRACE_RULE_EVAL },
-    { "buffer",        TRACE_BUFFER },
-    { "rule_vars",     TRACE_RULE_VARS },
-    { "fp_search",     TRACE_FP_SEARCH },
-    { "pkt_detect",    TRACE_PKT_DETECTION },
-    { "opt_tree",      TRACE_OPTION_TREE },
-    { "tag",           TRACE_TAG }
-};
-
-Trace detection_trace(s_module_name, detection_trace_options,
-    (sizeof(detection_trace_options) / sizeof(TraceOptionString)));
-
 static const Parameter detection_params[] =
 {
     { "asn1", Parameter::PT_INT, "0:65535", "0",
@@ -132,10 +101,17 @@ static const Parameter detection_params[] =
 #define detection_help \
     "configure general IPS rule processing parameters"
 
-DetectionModule::DetectionModule() : Module(s_module_name, detection_help,
-    detection_params, false, &detection_trace, detection_module_trace)
+#define s_name "detection"
+
+DetectionModule::DetectionModule() : Module(s_name, detection_help, detection_params)
 { }
 
+void DetectionModule::set_trace(const Trace* trace) const
+{ detection_trace = trace; }
+
+const TraceOption* DetectionModule::get_trace_options() const
+{ return detection_trace_options; }
+
 bool DetectionModule::end(const char*, int, SnortConfig* sc)
 {
     if ( sc->offload_threads and ThreadConfig::get_instance_max() != 1 )
@@ -144,7 +120,7 @@ bool DetectionModule::end(const char*, int, SnortConfig* sc)
     return true;
 }
 
-bool DetectionModule::set(const char* fqn, Value& v, SnortConfig* sc)
+bool DetectionModule::set(const char*, Value& v, SnortConfig* sc)
 {
     if ( v.is("asn1") )
         sc->asn1_mem = v.get_uint16();
@@ -216,8 +192,6 @@ bool DetectionModule::set(const char* fqn, Value& v, SnortConfig* sc)
 
     else if ( v.is("enable_address_anomaly_checks") )
         sc->address_anomaly_check_enabled = v.get_bool();
-    else
-        return Module::set(fqn, v, sc);
 
     return true;
 }
index 996b3caa46dda6c873f2764822535176f5b6cbf2..0bd782ca59b7bb61d6ce9a9ae9165ee373bb161c 100644 (file)
@@ -42,6 +42,9 @@ public:
 
     Usage get_usage() const override
     { return GLOBAL; }
+
+    void set_trace(const Trace*) const override;
+    const TraceOption* get_trace_options() const override;
 };
 }
 
index 5c8dd15d157fa72a1454bc6c7d4a55820ac6d042..3a04febb61265d6423267cbbde8c07ea317170d0 100644 (file)
@@ -46,7 +46,6 @@
 #include "latency/rule_latency_state.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
-#include "main/snort_debug.h"
 #include "main/thread_config.h"
 #include "managers/ips_manager.h"
 #include "parser/parser.h"
@@ -562,7 +561,7 @@ int detection_option_node_evaluate(
             GetVarValueByIndex(&(tmp_byte_extract_vars[i]), (int8_t)i);
         }
 #ifdef DEBUG_MSGS
-        if ( detection_trace.enabled(TRACE_RULE_VARS) )
+        if ( trace_enabled(detection_trace, TRACE_RULE_VARS) )
         {
             char var_buf[100];
             std::string rule_vars;
index dc6d1f2ee850a8231cef6d182222f23d4e87cc86..caa3c07581321b010a9045968d02992a150ce334 100644 (file)
@@ -30,6 +30,7 @@
 #include "hash/xhash.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
+#include "main/snort_debug.h"
 #include "parser/parser.h"
 #include "protocols/packet.h"
 #include "sfip/sf_ip.h"
index 0edf6609eb9a963bfca28edcf5f367fbc563e4e5..204f40d3b51da84cdf64c42541eb989e339a8402 100644 (file)
@@ -29,8 +29,6 @@
 
 #include <cstdint>
 
-#include "main/snort_debug.h"
-
 namespace snort
 {
 struct Packet;
index 39cbae14f6a1735ef392bd66202dabb22be89fcb..9a2f04c3902de829bca2a6f561f7befea4b4b2a8 100644 (file)
@@ -30,8 +30,6 @@
 
 #include <mutex>
 
-#include "main/snort_debug.h"
-
 #include "circular_buffer.h"
 
 #define FILE_MEM_SUCCESS    0  // FIXIT-RC use bool
index 75998729377a2f9b81d8d522b7b607ff93b4495e..4be31f0670229f99945af5420dd062eed39bde26 100644 (file)
@@ -30,7 +30,6 @@
 #include "framework/inspector.h"
 #include "framework/data_bus.h"
 #include "main/snort_config.h"
-#include "main/snort_debug.h"
 #include "memory/memory_cap.h"
 #include "protocols/ip.h"
 #include "protocols/layer.h"
index ec5b390e8f05fa1bd7e560de7ae6e164af204812..582abfcad561ae3e92d405d4b75fd2bd171940b2 100644 (file)
 
 #include "module.h"
 
-using namespace snort;
-
-static const Parameter default_trace[] =
-{
-    { "all", Parameter::PT_INT, "0:255", "0", "enable traces in module" },
+#include "trace/trace.h"
 
-    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
-};
+using namespace snort;
 
-static const Parameter default_trace_params[] =
+static const Parameter null_params[] =
 {
-    { "trace", Parameter::PT_TABLE, default_trace, nullptr, "trace config" },
-
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
@@ -55,53 +48,23 @@ std::string Command::get_arg_list() const
     return args;
 }
 
-void Module::reset_trace()
-{
-    if ( trace )
-        trace->reset();
-}
-
 void Module::init(const char* s, const char* h)
 {
     name = s;
     help = h;
-    params = &default_trace_params[(sizeof(default_trace_params) / sizeof(Parameter)) - 1];
-    default_params = params;
     list = false;
     num_counts = -1;
+    params = null_params;
 }
 
 Module::Module(const char* s, const char* h)
 { init(s, h); }
 
-Module::Module(const char* s, const char* h, const Parameter* p, bool is_list, Trace* t,
-    const Parameter* module_trace_param)
+Module::Module(const char* s, const char* h, const Parameter* p, bool is_list)
 {
     init(s, h);
     list = is_list;
-    trace = t;
     params = p;
-
-    // FIXIT-L: This will not be valid after adding more default options
-    if ( t )
-    {
-        if ( module_trace_param )
-        {
-            default_params = module_trace_param;
-        }
-        else
-        {
-            default_params = default_trace_params;
-        }
-    }
-}
-
-bool Module::set(const char* fqn, Value& v, SnortConfig*)
-{
-    if ( strstr(fqn, ".trace.") )
-        return trace and trace->set(v);
-
-    return false;
 }
 
 void Module::sum_stats(bool accumulate_now_stats)
@@ -214,12 +177,6 @@ bool Module::verified_end(const char* fqn, int idx, SnortConfig* c)
     return end(fqn, idx, c);
 }
 
-void Module::enable_trace()
-{
-    if ( trace )
-        trace->enable();
-}
-
 namespace snort
 {
 const PegInfo simple_pegs[] =
index fcf64a4156e4edaee496a8e322aa3b85c33ab562..4908b4415f70b8c0e8341ce2bc1d908841170b00 100644 (file)
@@ -45,7 +45,6 @@
 #include "framework/counts.h"
 #include "framework/parameter.h"
 #include "framework/value.h"
-#include "main/snort_debug.h"
 #include "main/snort_types.h"
 #include "utils/stats.h"
 
@@ -54,8 +53,10 @@ struct lua_State;
 namespace snort
 {
 class ModuleManager;
+class Trace;
 struct ProfileStats;
 struct SnortConfig;
+struct TraceOption;
 
 using LuaCFunction = int(*)(lua_State*);
 
@@ -90,7 +91,13 @@ public:
     virtual bool end(const char*, int, SnortConfig*)
     { return true; }
 
-    virtual bool set(const char*, Value&, SnortConfig*);
+    virtual bool set(const char*, Value&, SnortConfig*)
+    { return true; }
+
+    virtual void set_trace(const Trace*) const { }
+
+    virtual const TraceOption* get_trace_options() const
+    { return nullptr; }
 
     // used to match parameters with $var names like <gid:sid> for rule_state
     virtual bool matches(const char* /*param_name*/, std::string& /*lua_name*/)
@@ -125,9 +132,6 @@ public:
     const Parameter* get_parameters() const
     { return params; }
 
-    const Parameter* get_default_parameters() const
-    { return default_params; }
-
     virtual const Command* get_commands() const
     { return nullptr; }
 
@@ -187,13 +191,12 @@ public:
     virtual Usage get_usage() const
     { return CONTEXT; }
 
-    void enable_trace();
-    void reset_trace();
-
 protected:
     Module(const char* name, const char* help);
-    Module(const char* name, const char* help, const Parameter*,
-        bool is_list = false, Trace* = nullptr, const Parameter* = nullptr);
+    Module(const char* name, const char* help, const Parameter*, bool is_list = false);
+
+    void set_params(const Parameter* p)
+    { params = p; }
 
 private:
     friend ModuleManager;
@@ -206,10 +209,8 @@ private:
     const char* help;
 
     const Parameter* params;
-    const Parameter* default_params = nullptr;
     bool list;
     int table_level = 0;
-    Trace* trace = nullptr;
 
     void set_peg_count(int index, PegCount value)
     {
index e266be180ac5c314539d0b1bf8f946f064bbba6a..2471b7f1ab590544f77b43995d06943aeeb7d392 100644 (file)
@@ -510,16 +510,6 @@ const char* Parameter::get_string() const
     return deflt ? deflt : "";
 }
 
-const Parameter* Parameter::find(const Parameter* p, const Parameter* d, const char* s)
-{
-    auto ret = find(p, s);
-
-    if ( !ret )
-        ret = find(d, s);
-
-    return ret;
-}
-
 const Parameter* Parameter::find(const Parameter* p, const char* s)
 {
     if ( !p )
index 493c8a4b0865d607efc8d67d93cdad64b685d9f7..bfe8a5f81341dc7fa90657b4af89eeeca136768a 100644 (file)
@@ -92,7 +92,6 @@ struct SO_PUBLIC Parameter
     double get_number() const;
     const char* get_string() const;
 
-    static const Parameter* find(const Parameter*, const Parameter*, const char*);
     static const Parameter* find(const Parameter*, const char*);
 
     // 0-based; -1 if not found; list is | delimited
index e048064c075328374c903607e1a09c6eb94824e7..4f1a5a94ab45970d050492e4a55225e5252cad42 100644 (file)
@@ -67,12 +67,6 @@ extern "C"
 const char* luaL_optlstring(lua_State*, int, const char*, size_t*) { return nullptr; }
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
 void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
 
index c69cc8435d5d2129f23e4731160f2371d2a2f31d..ad74160c989b03071e50a516f14e7320f51407f9 100644 (file)
@@ -42,12 +42,6 @@ char* snort_strdup(const char* s)
 time_t packet_time() { return 0; }
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 //  Fake show_stats to avoid bringing in a ton of dependencies.
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
 void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
index 6962a362d66d79386a296c716fabb3c0d88fecc8..b3d5e45da5443ac3e8b65259604c99645c8dccdb 100644 (file)
@@ -98,12 +98,6 @@ extern const BaseApi* ips_regex;
 Cursor::Cursor(Packet* p)
 { set("pkt_data", p->data, p->dsize); }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
 void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
 
index c580c4495d474e78bb0ac2a139e13057dab8652a..3607cff74fa4f306eec811e37ccc4ca02f5c7001 100644 (file)
 #ifndef LATENCY_CONFIG_H
 #define LATENCY_CONFIG_H
 
-#include "main/snort_debug.h"
-
 #include "packet_latency_config.h"
 #include "rule_latency_config.h"
 
+namespace snort
+{
+class Trace;
+}
+
+extern THREAD_LOCAL const snort::Trace* latency_trace;
+
 struct LatencyConfig
 {
     PacketLatencyConfig packet_latency;
     RuleLatencyConfig rule_latency;
 };
 
-extern snort::Trace latency_trace;
-
 #endif
index e0ea9c7898c46136c7b6fe49dbcc9d299cfe705c..0007dccf60d98db911e53b1eeb9540de9db43e7a 100644 (file)
@@ -27,6 +27,7 @@
 #include <chrono>
 
 #include "main/snort_config.h"
+#include "trace/trace.h"
 
 #include "latency_config.h"
 #include "latency_rules.h"
@@ -34,6 +35,8 @@
 
 using namespace snort;
 
+THREAD_LOCAL const Trace* latency_trace = nullptr;
+
 // -----------------------------------------------------------------------------
 // latency attributes
 // -----------------------------------------------------------------------------
@@ -42,8 +45,6 @@ using namespace snort;
 #define s_help \
     "packet and rule latency monitoring and control"
 
-Trace latency_trace(s_name);
-
 static const Parameter s_packet_params[] =
 {
     { "max_time", Parameter::PT_INT, "0:max53", "500",
@@ -170,10 +171,18 @@ static inline bool latency_set(Value& v, RuleLatencyConfig& config)
     return true;
 }
 
-LatencyModule::LatencyModule() :
-    Module(s_name, s_help, s_params, false, &latency_trace)
+LatencyModule::LatencyModule() : Module(s_name, s_help, s_params)
 { }
 
+void LatencyModule::set_trace(const Trace* trace) const
+{ latency_trace = trace; }
+
+const TraceOption* LatencyModule::get_trace_options() const
+{
+    static const TraceOption latency_trace_options(nullptr, 0, nullptr);
+    return &latency_trace_options;
+}
+
 bool LatencyModule::set(const char* fqn, Value& v, SnortConfig* sc)
 {
     const char* slp = "latency.packet";
@@ -185,7 +194,7 @@ bool LatencyModule::set(const char* fqn, Value& v, SnortConfig* sc)
     else if ( !strncmp(fqn, slr, strlen(slr)) )
         return latency_set(v, sc->latency->rule_latency);
 
-    return Module::set(fqn, v, sc);
+    return true;
 }
 
 const RuleMap* LatencyModule::get_rules() const
index 26589eb717ade2e661eea3e81a7ed814fb6eb88d..8e16390e9a8c1e26dd6e95b7ac52f13c94507876 100644 (file)
@@ -38,6 +38,9 @@ public:
 
     Usage get_usage() const override
     { return CONTEXT; }
+
+    void set_trace(const snort::Trace*) const override;
+    const snort::TraceOption* get_trace_options() const override;
 };
 
 #endif
index 93611f81fe049d4c93f09686a9dd39f3637a34bf..4c5e6617054953a4c9f344c0ec5ea784d8b0471c 100644 (file)
@@ -27,6 +27,7 @@
 #include "detection/detection_engine.h"
 #include "log/messages.h"
 #include "main/snort_config.h"
+#include "main/snort_debug.h"
 #include "protocols/packet.h"
 #include "utils/stats.h"
 
index 566f32314fc179ef165a353584508f08840262f1..4b81d2f44b53a61cd8efbc5e4a18108ba1ff432e 100644 (file)
@@ -51,6 +51,7 @@
 #include "packet_io/trough.h"
 #include "target_based/host_attributes.h"
 #include "time/periodic.h"
+#include "trace/trace_api.h"
 #include "utils/util.h"
 #include "utils/safec.h"
 
@@ -373,6 +374,7 @@ int main_reload_config(lua_State* L)
 
     PluginManager::reload_so_plugins_cleanup(sc);
     SnortConfig::set_conf(sc);
+    TraceApi::thread_reinit(sc);
     proc_stats.conf_reloads++;
 
     bool from_shell = ( L != nullptr );
index 1ae5531e9548be699d73b3e7be4b7fb7ca8ec8e0..d1d61cd96f9517c73f64e6bad6f5b181f77ecc57 100644 (file)
@@ -6,7 +6,6 @@ set (INCLUDES
     snort_debug.h
     snort_types.h
     thread.h
-    trace.h
 )
 
 if ( ENABLE_SHELL )
@@ -42,7 +41,6 @@ add_library (main OBJECT
     thread.cc
     thread_config.h
     thread_config.cc
-    trace.cc
     ${INCLUDES}
     ${SHELL_SOURCES}
 )
index 80ba6d6cfa0f3264626151d815a24a13ce4f2f5f..5c4a7b66c7dea2a40f9c726c5a27fd738ede37d1 100644 (file)
@@ -63,7 +63,7 @@
 #include "side_channel/side_channel.h"
 #include "stream/stream.h"
 #include "time/packet_time.h"
-#include "trace/trace_log_api.h"
+#include "trace/trace_api.h"
 #include "utils/stats.h"
 
 #include "analyzer_command.h"
@@ -594,7 +594,8 @@ void Analyzer::init_unprivileged()
 
     // This should be called as soon as possible
     // to handle all trace log messages
-    TraceLogApi::thread_init(sc);
+    TraceApi::thread_init(sc);
+
     CodecManager::thread_init(sc);
 
     // this depends on instantiated daq capabilities
@@ -627,6 +628,7 @@ void Analyzer::reinit(SnortConfig* sc)
 {
     InspectorManager::thread_reinit(sc);
     ActionManager::thread_reinit(sc);
+    TraceApi::thread_reinit(sc);
 }
 
 void Analyzer::term()
@@ -682,7 +684,7 @@ void Analyzer::term()
     sfthreshold_free();
     RateFilter_Cleanup();
 
-    TraceLogApi::thread_term();
+    TraceApi::thread_term();
 }
 
 Analyzer::Analyzer(SFDAQInstance* instance, unsigned i, const char* s, uint64_t msg_cnt)
index bae2a1b5c22f58d55dbb413765fb797fac698132..8ecf11bd392fca0e2a68a93b2da159708e1a4c9f 100644 (file)
@@ -1964,7 +1964,6 @@ void module_init()
     ModuleManager::add_module(new RuleStateModule);
     ModuleManager::add_module(new SearchEngineModule);
     ModuleManager::add_module(new SFDAQModule);
-    ModuleManager::add_module(new TraceModule);
 
     // these could but prolly shouldn't be policy specific
     // or should be broken into policy and non-policy parts
@@ -1995,4 +1994,6 @@ void module_init()
     ModuleManager::add_module(new HostsModule);
     ModuleManager::add_module(new HostTrackerModule);
     ModuleManager::add_module(new HostCacheModule);
+    // The TraceModule must be added last so that it can properly generate its Parameter table
+    ModuleManager::add_module(new TraceModule);
 }
index 4f4f0e019c7dc9f8962597e7ebfa43babfa9ef4b..d3aa388edbb44b08508f09834d1373f33a25533b 100644 (file)
@@ -25,7 +25,6 @@
 // ideally, modules.cc would be refactored into several files.
 
 #include "framework/counts.h"
-#include "main/snort_debug.h"
 #include "main/thread.h"
 
 
index b26265a45c638b1acb1ee94d134e0519eae53538..02e6da721cb8e2f0e10f0dbf4bf1f9d092714010 100644 (file)
@@ -67,7 +67,7 @@
 #include "stream/stream_inspectors.h"
 #include "target_based/host_attributes.h"
 #include "time/periodic.h"
-#include "trace/trace_log_api.h"
+#include "trace/trace_api.h"
 #include "utils/util.h"
 
 #ifdef PIGLET
@@ -134,9 +134,12 @@ void Snort::init(int argc, char** argv)
 
     SideChannelManager::pre_config_init();
 
-    ModuleManager::init();
     ScriptManager::load_scripts(snort_cmd_line_conf->script_paths);
     PluginManager::load_plugins(snort_cmd_line_conf->plugin_path);
+
+    /* load_plugins() must be called before init() so that
+    TraceModule can properly generate its Parameter table */
+    ModuleManager::init();
     ModuleManager::load_params();
 
     FileService::init();
@@ -152,7 +155,7 @@ void Snort::init(int argc, char** argv)
 
     // This call must be immediately after "SnortConfig::set_conf(sc)"
     // since the first trace call may happen somewhere after this point
-    TraceLogApi::thread_init(sc);
+    TraceApi::thread_init(sc);
 
     PluginManager::load_so_plugins(sc);
 
@@ -340,8 +343,8 @@ void Snort::term()
     LogMessage("%s  Snort exiting\n", get_prompt());
 
     // This call must be before SnortConfig cleanup
-    // since the "TraceLogApi::thread_term()" uses SnortConfig
-    TraceLogApi::thread_term();
+    // since the "TraceApi::thread_term()" uses SnortConfig
+    TraceApi::thread_term();
 
     /* free allocated memory */
     if (SnortConfig::get_conf() == snort_cmd_line_conf)
@@ -460,7 +463,6 @@ SnortConfig* Snort::get_reload_config(const char* fname, const char* plugin_path
     }
 
     PluginManager::reload_so_plugins(plugin_path, sc);
-
     sc->setup();
 
 #ifdef SHELL
index 7e3bb90fd448fc60857dd82360556d2e8ac28e9b..fb86664e6c67f2fb578e937d97cfb03925e47a3e 100644 (file)
@@ -177,6 +177,7 @@ void SnortConfig::init(const SnortConfig* const other_conf, ProtocolReference* p
         memset(evalOrder, 0, sizeof(evalOrder));
         proto_ref = new ProtocolReference(protocol_reference);
         so_rules = new SoRules;
+        trace_config = new TraceConfig;
     }
     else
     {
@@ -262,11 +263,10 @@ SnortConfig::~SnortConfig()
 
     delete[] state;
     delete thread_config;
+    delete trace_config;
     delete ha_config;
     delete global_dbus;
 
-    delete trace_config;
-
     delete profiler;
     delete latency;
     delete memory;
@@ -461,6 +461,7 @@ void SnortConfig::merge(SnortConfig* cmd_line)
     assert(!state);
     num_slots = offload_threads + ThreadConfig::get_instance_max();
     state = new std::vector<void*>[num_slots];
+    trace_config->merge_cmd_line(cmd_line->trace_config);
 }
 
 bool SnortConfig::verify()
index a6abd4dc8e0ea165fe0ab80dc0a67a2755abe9e5..f58c5d72ab9093db6e657b3947a0f817a36529e0 100644 (file)
@@ -412,9 +412,6 @@ public:
 
     ThreadConfig* thread_config;
     HighAvailabilityConfig* ha_config = nullptr;
-
-    //------------------------------------------------------
-
     TraceConfig* trace_config = nullptr;
 
     //------------------------------------------------------
index d48ec727a33d2026c2ec7826d5474e3f84676f46..3327e59cded9ebfb00df424c3fd8009afc7d9f1f 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <cstring>
 
-#include "trace/trace_log_api.h"
+#include "trace/trace_api.h"
 #include "utils/safec.h"
 
 #define STD_BUF_SIZE 1024
@@ -46,7 +46,7 @@ void trace_vprintf(const char* name, TraceLevel log_level,
 void trace_vprintf(const char* name, TraceLevel log_level,
     const char* trace_option, const char* fmt, va_list ap)
 {
-    trace_vprintf<TraceLogApi::log>(name, log_level, trace_option, fmt, ap);
+    trace_vprintf<TraceApi::log>(name, log_level, trace_option, fmt, ap);
 }
 }
 
@@ -55,6 +55,8 @@ void trace_vprintf(const char* name, TraceLevel log_level,
 
 #ifdef DEBUG_MSGS
 
+#include "framework/module.h"
+
 using namespace snort;
 
 //stringify the expansion of the macro
@@ -83,20 +85,20 @@ TEST_CASE("macros", "[trace]")
     TestCase cases[] =
     {
         {
-            sx(debug_log(1, testing, "my message")),
-            "trace_print<snort::trace_vprintf>(1, testing, \"my message\")"
+            sx(debug_log(1, test_trace, "my message")),
+            "trace_print<snort::trace_vprintf>(1, test_trace, \"my message\")"
         },
         {
-            sx(debug_log(testing, my_flags, "my message")),
-            "trace_print<snort::trace_vprintf>(testing, my_flags, \"my message\")"
+            sx(debug_log(test_trace, my_flags, "my message")),
+            "trace_print<snort::trace_vprintf>(test_trace, my_flags, \"my message\")"
         },
         {
-            sx(debug_logf(1, testing, "%s %s", "my", "message")),
-            "trace_printf<snort::trace_vprintf>(1, testing, \"%s %s\", \"my\", \"message\")"
+            sx(debug_logf(1, test_trace, "%s %s", "my", "message")),
+            "trace_printf<snort::trace_vprintf>(1, test_trace, \"%s %s\", \"my\", \"message\")"
         },
         {
-            sx(debug_logf(testing, my_flags, "%s %s", "my", "message")),
-            "trace_printf<snort::trace_vprintf>(testing, my_flags, \"%s %s\", \"my\", \"message\")"
+            sx(debug_logf(test_trace, my_flags, "%s %s", "my", "message")),
+            "trace_printf<snort::trace_vprintf>(test_trace, my_flags, \"%s %s\", \"my\", \"message\")"
         }
     };
 
@@ -110,214 +112,138 @@ TEST_CASE("macros", "[trace]")
 #undef trace_printf
 
 //These templates expand to replace the default expansion of trace_vprintf.
-//This custom expansion replaces log_func (expands to TraceLogApi::log())
+//This custom expansion replaces log_func (expands to TraceApi::log())
 //with test_log for capturing what would be passed to the console.
 #define trace_print trace_print<trace_vprintf<test_log>>
 #define trace_printf trace_printf<trace_vprintf<test_log>>
 
-enum
+class TraceTestModule : public Module
 {
-    TEST_TRACE_OPTION1 = 0,
-    TEST_TRACE_OPTION2,
-    TEST_TRACE_OPTION3,
-    TEST_TRACE_OPTION4,
-    TEST_TRACE_OPTION5,
-};
+public:
+    TraceTestModule(const char* name, const TraceOption* trace_options) :
+        Module(name, "trace_test_help"), test_trace_options(trace_options)
+    { }
 
-const TraceOptionString test_trace_values[] =
-{
-    { "option1", TEST_TRACE_OPTION1 },
-    { "option2", TEST_TRACE_OPTION2 },
-    { "option3", TEST_TRACE_OPTION3 },
-    { "option4", TEST_TRACE_OPTION4 },
-    { "option5", TEST_TRACE_OPTION5 },
+    virtual const TraceOption* get_trace_options() const
+    { return test_trace_options; }
+
+private:
+    const TraceOption* test_trace_options;
 };
 
-TEST_CASE("Trace logging", "[trace]")
+TEST_CASE("debug_log, debug_logf", "[trace]")
 {
-    SECTION("trace all=0")
+    enum
     {
-        Trace test("test");
-
-        Parameter p("all", Parameter::PT_INT, "0:255", "0", "enable traces in module");
-        Value trace_val((double)0);
-        trace_val.set(&p);
-
-        test.set(trace_val);
+        TEST_TRACE_OPTION1 = 0,
+        TEST_TRACE_OPTION2,
+        TEST_TRACE_OPTION3,
+        TEST_TRACE_OPTION4,
+        TEST_TRACE_OPTION5,
+    };
 
-        testing_dump[0] = '\0';
-        debug_log(test, "my message");
-        CHECK( testing_dump[0] == '\0' );
-    }
-    SECTION("debug_log")
-    {
-        Trace test("test");
-
-        Parameter p("all", Parameter::PT_INT, "0:255", "0", "enable traces in module");
-        Value trace_val((double)1);
-        trace_val.set(&p);
-
-        test.set(trace_val);
-
-        testing_dump[0] = '\0';
-        debug_log(test, "my message");
-        CHECK( !strcmp(testing_dump, "test:all:1: my message") );
-
-        Parameter p_all("all", Parameter::PT_INT, "0:255", "0", "p_all");
-        Parameter p1("option1", Parameter::PT_INT, "0:255", "0", "p1");
-        Parameter p2("option3", Parameter::PT_INT, "0:255", "0", "p2");
-        Value trace_val1("trace");
-
-        Trace testing_opt("testing_opt", test_trace_values,
-            (sizeof(test_trace_values) / sizeof(TraceOptionString)));
-
-        // set log_level = 1 for TEST_TRACE_OPTION1
-        trace_val1.set(&p1);
-        trace_val1.set_enum(1);
-        testing_opt.set(trace_val1);
-
-        // set log_level = 5 for TEST_TRACE_OPTION3
-        trace_val1.set(&p2);
-        trace_val1.set_enum(5);
-        testing_opt.set(trace_val1);
-
-        // set log_level = 2 for TEST_TRACE_OPTION2, TEST_TRACE_OPTION4, TEST_TRACE_OPTION5
-        trace_val1.set(&p_all);
-        trace_val1.set_enum(2);
-        testing_opt.set(trace_val1);
-
-        testing_dump[0] = '\0';
-        debug_log(testing_opt, TEST_TRACE_OPTION1, "my other masked message");
-        CHECK( !strcmp(testing_dump, "testing_opt:option1:1: my other masked message") );
-
-        testing_dump[0] = '\0';
-        debug_log(3, testing_opt, TEST_TRACE_OPTION2, "log option2 message");
-        CHECK( testing_dump[0] == '\0' );
-
-        testing_dump[0] = '\0';
-        debug_log(testing_opt, TEST_TRACE_OPTION2, "log option2 message");
-        CHECK( !strcmp(testing_dump, "testing_opt:option2:1: log option2 message") );
-
-        testing_dump[0] = '\0';
-        debug_log(6, testing_opt, TEST_TRACE_OPTION3, "log option3 message");
-        CHECK( testing_dump[0] == '\0' );
-
-        testing_dump[0] = '\0';
-        debug_log(3, testing_opt, TEST_TRACE_OPTION3, "log option3 message");
-        CHECK( !strcmp(testing_dump, "testing_opt:option3:3: log option3 message") );
-
-        testing_dump[0] = '\0';
-        debug_log(2, testing_opt, TEST_TRACE_OPTION4, "log option4 message");
-        CHECK( !strcmp(testing_dump, "testing_opt:option4:2: log option4 message") );
-
-        testing_dump[0] = '\0';
-        debug_log(4, testing_opt, TEST_TRACE_OPTION5, "log option5 message");
-        CHECK( testing_dump[0] == '\0' );
-    }
-    SECTION("debug_logf")
-    {
-        Trace test("test");
-
-        Parameter p("all", Parameter::PT_INT, "0:255", "0", "enable traces in module");
-        Value trace_val((double)1);
-        trace_val.set(&p);
-        test.set(trace_val);
-
-        testing_dump[0] = '\0';
-        debug_logf(test, "%s %s", "my", "message");
-        CHECK( !strcmp(testing_dump, "test:all:1: my message") );
-
-        Parameter p_all("all", Parameter::PT_INT, "0:255", "0", "p_all");
-        Parameter p1("option1", Parameter::PT_INT, "0:255", "0", "p1");
-        Parameter p2("option3", Parameter::PT_INT, "0:255", "0", "p2");
-        Value trace_val1("trace");
-
-        Trace testing_opt("testing_opt", test_trace_values,
-            (sizeof(test_trace_values) / sizeof(TraceOptionString)));
-
-        // set log_level = 1 for TEST_TRACE_OPTION1
-        trace_val1.set(&p1);
-        trace_val1.set_enum(1);
-        testing_opt.set(trace_val1);
-
-        // set log_level = 5 for TEST_TRACE_OPTION3
-        trace_val1.set(&p2);
-        trace_val1.set_enum(5);
-        testing_opt.set(trace_val1);
-
-        // set log_level = 3 for TEST_TRACE_OPTION2, TEST_TRACE_OPTION4, TEST_TRACE_OPTION5
-        trace_val1.set(&p_all);
-        trace_val1.set_enum(3);
-        testing_opt.set(trace_val1);
-
-        testing_dump[0] = '\0';
-        debug_logf(testing_opt, TEST_TRACE_OPTION1, "%s %s %s", "log", "option1", "message");
-        CHECK( !strcmp(testing_dump, "testing_opt:option1:1: log option1 message") );
-
-        testing_dump[0] = '\0';
-        debug_logf(testing_opt, TEST_TRACE_OPTION2, "%s %s %s", "log", "option2", "message");
-        CHECK( !strcmp(testing_dump, "testing_opt:option2:1: log option2 message") );
-
-        testing_dump[0] = '\0';
-        debug_logf(4, testing_opt, TEST_TRACE_OPTION2, "%s %s %s", "log", "option2", "message");
-        CHECK( testing_dump[0] == '\0' );
-
-        testing_dump[0] = '\0';
-        debug_logf(3, testing_opt, TEST_TRACE_OPTION3, "%s %s %s", "log", "option3", "message");
-        CHECK( !strcmp(testing_dump, "testing_opt:option3:3: log option3 message") );
-
-        testing_dump[0] = '\0';
-        debug_logf(6, testing_opt, TEST_TRACE_OPTION3, "%s %s %s", "log", "option3", "message");
-        CHECK( testing_dump[0] == '\0' );
-
-        testing_dump[0] = '\0';
-        debug_logf(2, testing_opt, TEST_TRACE_OPTION4, "%s %s %s", "log", "option4", "message");
-        CHECK( !strcmp(testing_dump, "testing_opt:option4:2: log option4 message") );
-
-        testing_dump[0] = '\0';
-        debug_logf(4, testing_opt, TEST_TRACE_OPTION5, "%s %s %s", "log", "option5", "message");
-        CHECK( testing_dump[0] == '\0' );
-    }
-    SECTION("safety")
+    const TraceOption test_trace_values[] =
     {
-        Trace test("test");
+        { "option1", TEST_TRACE_OPTION1, "help_option1" },
+        { "option2", TEST_TRACE_OPTION2, "help_option2" },
+        { "option3", TEST_TRACE_OPTION3, "help_option3" },
+        { "option4", TEST_TRACE_OPTION4, "help_option4" },
+        { "option5", TEST_TRACE_OPTION5, "help_option5" },
 
-        Parameter p("all", Parameter::PT_INT, "0:255", "0", "enable traces in module");
-        Value trace_val((double)1);
-        trace_val.set(&p);
-
-        test.set(trace_val);
-
-        char message[STD_BUF_SIZE + 1];
-
-        for( int i = 0; i < STD_BUF_SIZE; i++ )
-            message[i] = 'A';
-        message[STD_BUF_SIZE] = '\0';
-
-        testing_dump[0] = '\0';
-        debug_log(test, message);
-        CHECK( (strlen(testing_dump) == STD_BUF_SIZE - 1) );
-
-        Trace testing_opt("testing_opt", test_trace_values,
-            (sizeof(test_trace_values) / sizeof(TraceOptionString)));
-
-        Parameter p1("option3", Parameter::PT_INT, "0:255", "0", "p1");
-        Value trace_val1("trace");
-        trace_val1.set(&p1);
-        trace_val1.set_enum(5);
-        testing_opt.set(trace_val1);
-
-        testing_dump[0] = '\0';
-        debug_log(3, testing_opt, TEST_TRACE_OPTION3, message);
-        CHECK( (strlen(testing_dump) == STD_BUF_SIZE - 1) );
+        { nullptr, 0, nullptr },
+    };
 
-        testing_dump[0] = '\0';
-        debug_log(6, testing_opt, TEST_TRACE_OPTION3, message);
-        CHECK( (strlen(testing_dump) == 0) );
-    }
+    TraceOption test_trace_options(nullptr, 0, nullptr);
+    TraceTestModule trace_test_module("test_module", &test_trace_options);
+    Trace test_trace(trace_test_module);
+
+    TraceTestModule trace_test_module_opt("test_opt_module", test_trace_values);
+    Trace test_opt_trace(trace_test_module_opt);
+
+    test_trace.set("all", 0);
+
+    testing_dump[0] = '\0';
+    debug_log(&test_trace, "my message");
+    CHECK( testing_dump[0] == '\0' );
+
+    test_trace.set("all", 1);
+    test_opt_trace.set("option1", 1);
+    test_opt_trace.set("option2", 2);
+    test_opt_trace.set("option3", 3);
+    test_opt_trace.set("option4", 2);
+    test_opt_trace.set("option5", 2);
+
+    char message[STD_BUF_SIZE + 1];
+    for( int i = 0; i < STD_BUF_SIZE; i++ )
+        message[i] = 'A';
+    message[STD_BUF_SIZE] = '\0';
+
+    testing_dump[0] = '\0';
+    debug_log(&test_trace, message);
+    CHECK( (strlen(testing_dump) == STD_BUF_SIZE - 1) );
+
+    testing_dump[0] = '\0';
+    debug_log(3, &test_opt_trace, TEST_TRACE_OPTION3, message);
+    CHECK( (strlen(testing_dump) == STD_BUF_SIZE - 1) );
+
+    testing_dump[0] = '\0';
+    debug_log(6, &test_opt_trace, TEST_TRACE_OPTION3, message);
+    CHECK( (strlen(testing_dump) == 0) );
+
+    testing_dump[0] = '\0';
+    debug_log(&test_trace, "my message"); 
+    CHECK( !strcmp(testing_dump, "test_module:all:1: my message") );
+
+    testing_dump[0] = '\0';
+    debug_logf(&test_trace, "%s %s", "my", "message");
+    CHECK( !strcmp(testing_dump, "test_module:all:1: my message") );
+
+    testing_dump[0] = '\0';
+    debug_log(&test_opt_trace, TEST_TRACE_OPTION1, "log option1 message");
+    CHECK( !strcmp(testing_dump, "test_opt_module:option1:1: log option1 message") );
+
+    testing_dump[0] = '\0';
+    debug_logf(&test_opt_trace, TEST_TRACE_OPTION1, "%s %s %s", "log", "option1", "message");
+    CHECK( !strcmp(testing_dump, "test_opt_module:option1:1: log option1 message") );
+
+    testing_dump[0] = '\0';
+    debug_log(3, &test_opt_trace, TEST_TRACE_OPTION2, "log option2 message");
+    CHECK( testing_dump[0] == '\0' );
+
+    testing_dump[0] = '\0';
+    debug_log(&test_opt_trace, TEST_TRACE_OPTION2, "log option2 message");
+    CHECK( !strcmp(testing_dump, "test_opt_module:option2:1: log option2 message") );
+
+    testing_dump[0] = '\0';
+    debug_logf(&test_opt_trace, TEST_TRACE_OPTION2, "%s %s %s", "log", "option2", "message");
+    CHECK( !strcmp(testing_dump, "test_opt_module:option2:1: log option2 message") );
+
+    testing_dump[0] = '\0';
+    debug_log(6, &test_opt_trace, TEST_TRACE_OPTION3, "log option3 message");
+    CHECK( testing_dump[0] == '\0' );
+
+    testing_dump[0] = '\0';
+    debug_log(3, &test_opt_trace, TEST_TRACE_OPTION3, "log option3 message");
+    CHECK( !strcmp(testing_dump, "test_opt_module:option3:3: log option3 message") );
+
+    testing_dump[0] = '\0';
+    debug_logf(3, &test_opt_trace, TEST_TRACE_OPTION3, "%s %s %s", "log", "option3", "message");
+    CHECK( !strcmp(testing_dump, "test_opt_module:option3:3: log option3 message") );
+    
+    testing_dump[0] = '\0';
+    debug_log(2, &test_opt_trace, TEST_TRACE_OPTION4, "log option4 message");
+    CHECK( !strcmp(testing_dump, "test_opt_module:option4:2: log option4 message") );
+
+    testing_dump[0] = '\0';
+    debug_logf(2, &test_opt_trace, TEST_TRACE_OPTION4, "%s %s %s", "log", "option4", "message");
+    CHECK( !strcmp(testing_dump, "test_opt_module:option4:2: log option4 message") );
+
+    testing_dump[0] = '\0';
+    debug_log(4, &test_opt_trace, TEST_TRACE_OPTION5, "log option5 message");
+    CHECK( testing_dump[0] == '\0' );
 }
 
-#endif  // DEBUG_MSGS
+#endif // DEBUG_MSGS
 
-#endif  // UNIT_TEST
+#endif // UNIT_TEST
 
index 8069b3d22c7821a92e02bb33b0bb9526bad9426d..af74577311800ff173228604ee322b598b2709af 100644 (file)
 
 #include <cstdarg>
 
-#include "main/snort_types.h"
-#include "main/trace.h"
+#include "trace/trace.h"
+
+static inline bool trace_enabled(const snort::Trace* trace,
+    TraceOptionID trace_option_id, TraceLevel log_level = DEFAULT_TRACE_LOG_LEVEL)
+{
+    return trace && trace->enabled(trace_option_id, log_level);
+}
 
 namespace snort
 {
@@ -39,106 +44,107 @@ SO_PUBLIC void trace_vprintf(const char* name, TraceLevel log_level,
 using trace_func = void(const char*, TraceLevel, const char*, const char*, va_list);
 
 template <trace_func>
-static inline void trace_printf(TraceLevel log_level, const snort::Trace& trace,
-    TraceOption trace_option, const char* fmt, ...) __attribute__((format (printf, 4, 5)));
+static inline void trace_printf(TraceLevel log_level, const snort::Trace* trace,
+    TraceOptionID trace_option_id, const char* fmt, ...) __attribute__((format (printf, 4, 5)));
 
 template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_printf(TraceLevel log_level, const snort::Trace& trace,
-    TraceOption trace_option, const char* fmt, ...)
+static inline void trace_printf(TraceLevel log_level, const snort::Trace* trace,
+    TraceOptionID trace_option_id, const char* fmt, ...)
 {
-    if ( !trace.enabled(trace_option, log_level) )
+    if ( !trace_enabled(trace, trace_option_id, log_level) )
         return;
 
     va_list ap;
     va_start(ap, fmt);
 
-    const char* trace_option_name = trace.option_name(trace_option);
-    trace_vprintf(trace.module_name(), log_level, trace_option_name, fmt, ap);
+    const char* trace_option_name = trace->option_name(trace_option_id);
+    trace_vprintf(trace->module_name(), log_level, trace_option_name, fmt, ap);
 
     va_end(ap);
 }
 
 template <trace_func>
-static inline void trace_printf(TraceLevel log_level, const snort::Trace& trace,
+static inline void trace_printf(TraceLevel log_level, const snort::Trace* trace,
     const char* fmt, ...) __attribute__((format (printf, 3, 4)));
 
 template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_printf(TraceLevel log_level, const snort::Trace& trace,
+static inline void trace_printf(TraceLevel log_level, const snort::Trace* trace,
     const char* fmt, ...)
 {
-    if ( !trace.enabled(DEFAULT_TRACE_OPTION, log_level) )
+    if ( !trace_enabled(trace, DEFAULT_TRACE_OPTION_ID, log_level) )
         return;
 
     va_list ap;
     va_start(ap, fmt);
 
-    const char* trace_option_name = trace.option_name(DEFAULT_TRACE_OPTION);
-    trace_vprintf(trace.module_name(), log_level, trace_option_name, fmt, ap);
+    const char* trace_option_name = trace->option_name(DEFAULT_TRACE_OPTION_ID);
+    trace_vprintf(trace->module_name(), log_level, trace_option_name, fmt, ap);
 
     va_end(ap);
 }
 
 template <trace_func>
-static inline void trace_printf(const snort::Trace& trace,
-    TraceOption trace_option, const char* fmt, ...) __attribute__((format (printf, 3, 4)));
+static inline void trace_printf(const snort::Trace* trace,
+    TraceOptionID trace_option_id, const char* fmt, ...) __attribute__((format (printf, 3, 4)));
 
 template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_printf(const snort::Trace& trace,
-    TraceOption trace_option, const char* fmt, ...)
+static inline void trace_printf(const snort::Trace* trace,
+    TraceOptionID trace_option_id, const char* fmt, ...)
 {
-    if ( !trace.enabled(trace_option) )
+    if ( !trace_enabled(trace, trace_option_id) )
         return;
 
     va_list ap;
     va_start(ap, fmt);
 
-    const char* trace_option_name = trace.option_name(trace_option);
-    trace_vprintf(trace.module_name(), DEFAULT_LOG_LEVEL, trace_option_name, fmt, ap);
+    const char* trace_option_name = trace->option_name(trace_option_id);
+    trace_vprintf(trace->module_name(), DEFAULT_TRACE_LOG_LEVEL, trace_option_name, fmt, ap);
 
     va_end(ap);
 }
 
 template <trace_func>
-static inline void trace_printf(const snort::Trace& trace,
+static inline void trace_printf(const snort::Trace* trace,
     const char* fmt, ...) __attribute__((format (printf, 2, 3)));
 
 template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_printf(const snort::Trace& trace, const char* fmt, ...)
+static inline void trace_printf(const snort::Trace* trace, const char* fmt, ...)
 {
-    if ( !trace.enabled(DEFAULT_TRACE_OPTION) )
+    if ( !trace_enabled(trace, DEFAULT_TRACE_OPTION_ID) )
         return;
 
     va_list ap;
     va_start(ap, fmt);
 
-    const char* trace_option_name = trace.option_name(DEFAULT_TRACE_OPTION);
-    trace_vprintf(trace.module_name(), DEFAULT_LOG_LEVEL, trace_option_name, fmt, ap);
+    const char* trace_option_name = trace->option_name(DEFAULT_TRACE_OPTION_ID);
+    trace_vprintf(trace->module_name(), DEFAULT_TRACE_LOG_LEVEL, trace_option_name, fmt, ap);
 
     va_end(ap);
 }
 
 template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_print(TraceLevel log_level, const snort::Trace& trace,
-    TraceOption trace_option, const char* msg)
+static inline void trace_print(TraceLevel log_level, const snort::Trace* trace,
+    TraceOptionID trace_option_id, const char* msg)
 {
-    trace_printf<trace_vprintf>(log_level, trace, trace_option, "%s", msg);
+    trace_printf<trace_vprintf>(log_level, trace, trace_option_id, "%s", msg);
 }
 
 template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_print(const snort::Trace& trace, TraceOption trace_option, const char* msg)
+static inline void trace_print(const snort::Trace* trace,
+    TraceOptionID trace_option_id, const char* msg)
 {
-    trace_printf<trace_vprintf>(trace, trace_option, "%s", msg);
+    trace_printf<trace_vprintf>(trace, trace_option_id, "%s", msg);
 }
 
 template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_print(TraceLevel log_level, const snort::Trace& trace,
+static inline void trace_print(TraceLevel log_level, const snort::Trace* trace,
     const char* msg)
 {
     trace_printf<trace_vprintf>(log_level, trace, "%s", msg);
 }
 
 template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_print(const snort::Trace& trace, const char* msg)
+static inline void trace_print(const snort::Trace* trace, const char* msg)
 {
     trace_printf<trace_vprintf>(trace, "%s", msg);
 }
index 9163fc6f4b6a094d1b742484566bf322e3c018ee..a7c9a08900bc8a162cdb887d46a0d4f6d5016156 100644 (file)
@@ -38,6 +38,7 @@
 #include "parser/parser.h"
 #include "parser/parse_utils.h"
 #include "parser/vars.h"
+#include "trace/trace_config.h"
 
 #ifdef UNIT_TEST
 #include "catch/unit_test.h"
@@ -606,12 +607,12 @@ static const Parameter s_params[] =
     "command line configuration"
 #endif
 
-Trace snort_trace(s_name);
+THREAD_LOCAL const Trace* snort_trace = nullptr;
 
 class SnortModule : public Module
 {
 public:
-    SnortModule() : Module(s_name, s_help, s_params, false, &snort_trace)
+    SnortModule() : Module(s_name, s_help, s_params)
     { }
 
 #ifdef SHELL
@@ -640,10 +641,22 @@ public:
     Usage get_usage() const override
     { return GLOBAL; }
 
+    void set_trace(const Trace*) const override;
+    const TraceOption* get_trace_options() const override;
+
 private:
     SFDAQModuleConfig* module_config;
 };
 
+void SnortModule::set_trace(const Trace* trace) const
+{ snort_trace = trace; }
+
+const TraceOption* SnortModule::get_trace_options() const
+{
+    static const TraceOption snort_trace_options(nullptr, 0, nullptr);
+    return &snort_trace_options;
+}
+
 bool SnortModule::begin(const char* fqn, int, SnortConfig*)
 {
     if (!strcmp(fqn, "snort"))
@@ -1084,7 +1097,7 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc)
         x2s(v.get_string());
 
     else if (v.is("--trace"))
-        Module::enable_trace();
+        sc->trace_config->enable_trace_snort();
 
     return true;
 }
index b1781c83371f3081957375a0de567a282a7ea937..11e12a545c14de6bc9332e5b29e584a86e90aff8 100644 (file)
 // the snort module is for handling command line args,
 // shell commands, and basic application stats
 
-#include "main/snort_debug.h"
+#include "main/thread.h"
 
 namespace snort
 {
 class Module;
+class Trace;
 }
 
-extern snort::Trace snort_trace;
+extern THREAD_LOCAL const snort::Trace* snort_trace;
+
 snort::Module* get_snort_module();
 
 #endif
diff --git a/src/main/trace.cc b/src/main/trace.cc
deleted file mode 100644 (file)
index 8bd5e2f..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-//--------------------------------------------------------------------------
-// Copyright (C) 2020-2020 Cisco and/or its affiliates. All rights reserved.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License Version 2 as published
-// by the Free Software Foundation.  You may not use, modify or distribute
-// this program under any other version of the GNU General Public License.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-//--------------------------------------------------------------------------
-// trace.cc author Serhii Vlasiuk <svlasiuk@cisco.com>
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "trace.h"
-
-using namespace snort;
-
-static const TraceOptionString default_trace_option[] =
-{
-    { "all", DEFAULT_TRACE_OPTION }
-};
-static const size_t default_trace_size = (sizeof(default_trace_option) / sizeof(TraceOptionString));
-
-Trace::Trace(const char* name, const TraceOptionString* trace_options, size_t size)
-{
-    assert(trace_options);
-    mod_name = name;
-    options = trace_options;
-    option_levels.resize(size, 0);
-    config_options.resize(size, false);
-}
-
-Trace::Trace(const char* name)
-{
-    mod_name = name;
-    options = default_trace_option;
-    option_levels.resize(default_trace_size, 0);
-    config_options.resize(default_trace_size, false);
-}
-
-bool Trace::set(const snort::Value& v)
-{
-    size_t size = option_levels.size();
-    if ( v.is("all") )
-    {
-        for ( size_t index = 0; index < size; ++index )
-            if ( !config_options[index] )
-                option_levels[index] = v.get_uint8();
-        return true;
-    }
-
-    for ( size_t index = 0; index < size; ++index )
-    {
-        if ( v.is(option_name(index)) )
-        {
-            TraceOption trace_option = options[index].option;
-
-            option_levels[trace_option] = v.get_uint8();
-            config_options[trace_option] = true;
-            return true;
-        }
-    }
-    return false;
-}
-
-void Trace::reset()
-{
-    std::fill(option_levels.begin(), option_levels.end(), 0);
-    std::fill(config_options.begin(), config_options.end(), false);
-}
-
-void Trace::enable()
-{
-    option_levels[DEFAULT_TRACE_OPTION] = DEFAULT_LOG_LEVEL;
-}
-
-#ifdef UNIT_TEST
-
-#include <catch/snort_catch.h>
-
-//-------------------------------------------------------------------------
-// Set trace option tests
-//-------------------------------------------------------------------------
-
-
-#define LOG_LEVEL_TEST 1
-
-TEST_CASE("Trace - single trace value", "[trace]")
-{
-    Trace test_trace("test");
-
-    Parameter p("all", Parameter::PT_INT, "0:255", "0", "enabling traces in module");
-    Value trace_val((double)1);
-    trace_val.set(&p);
-
-    bool result = test_trace.set(trace_val);
-    CHECK( result == true );
-    CHECK( test_trace.option_levels[DEFAULT_TRACE_OPTION] == LOG_LEVEL_TEST );
-}
-
-TEST_CASE("Trace - multiple trace values", "[trace]")
-{
-    enum
-    {
-        TEST_TRACE_DETECTION_ENGINE = 0,
-        TEST_TRACE_RULE_VARS,
-        TEST_TRACE_OPTION_TREE,
-        TEST_TRACE_TAG,
-    };
-    const TraceOptionString test_trace_values[] =
-    {
-        { "detect_engine", TEST_TRACE_DETECTION_ENGINE },
-        { "rule_vars",     TEST_TRACE_RULE_VARS },
-        { "opt_tree",      TEST_TRACE_OPTION_TREE },
-        { "tag",           TEST_TRACE_TAG }
-    };
-
-    Trace test_trace("test", test_trace_values,
-        (sizeof(test_trace_values) / sizeof(TraceOptionString)));
-
-    Parameter p1("detect_engine", Parameter::PT_INT, "0:255", "0", "p1");
-    Parameter p2("rule_vars", Parameter::PT_INT, "0:255", "0", "p2");
-    Parameter p3("opt_tree", Parameter::PT_INT, "0:255", "0", "p3");
-    Parameter p4("tag", Parameter::PT_INT, "0:255", "0", "p4");
-    Value trace_val("trace");
-    trace_val.set(&p1);
-    trace_val.set_enum(1);
-
-    bool result = test_trace.set(trace_val);
-    CHECK( result == true );
-    CHECK( test_trace.option_levels[TEST_TRACE_DETECTION_ENGINE] == LOG_LEVEL_TEST );
-
-    trace_val.set(&p2);
-    result = test_trace.set(trace_val);
-    CHECK( result == true );
-    CHECK( test_trace.option_levels[TEST_TRACE_DETECTION_ENGINE] == LOG_LEVEL_TEST );
-    CHECK( test_trace.option_levels[TEST_TRACE_RULE_VARS] == LOG_LEVEL_TEST );
-
-    trace_val.set(&p3);
-    result = test_trace.set(trace_val);
-    CHECK( result == true );
-    CHECK( test_trace.option_levels[TEST_TRACE_DETECTION_ENGINE] == LOG_LEVEL_TEST );
-    CHECK( test_trace.option_levels[TEST_TRACE_RULE_VARS] == LOG_LEVEL_TEST );
-    CHECK( test_trace.option_levels[TEST_TRACE_OPTION_TREE] == LOG_LEVEL_TEST );
-
-    trace_val.set(&p4);
-    result = test_trace.set(trace_val);
-    CHECK( result == true );
-    CHECK( test_trace.option_levels[TEST_TRACE_DETECTION_ENGINE] == LOG_LEVEL_TEST );
-    CHECK( test_trace.option_levels[TEST_TRACE_RULE_VARS] == LOG_LEVEL_TEST );
-    CHECK( test_trace.option_levels[TEST_TRACE_OPTION_TREE] == LOG_LEVEL_TEST );
-    CHECK( test_trace.option_levels[TEST_TRACE_TAG] == LOG_LEVEL_TEST );
-}
-
-TEST_CASE("Trace - incorrect trace value", "[trace]")
-{
-    Trace test_trace("test");
-    Parameter p("test", Parameter::PT_INT, "0:255", "0", "p");
-    Value trace_val("trace");
-    trace_val.set(&p);
-    trace_val.set_enum(1);
-
-    bool result = test_trace.set(trace_val);
-    CHECK( result == false );
-    CHECK( test_trace.option_levels[DEFAULT_TRACE_OPTION] == TraceLevel(0) );
-}
-
-#endif // UNIT_TEST
-
index 36b818fdecdb1f10354f2c1b22902c8143e289f1..85540579e8f965d74cdfb769092c01df23ecb0a2 100644 (file)
@@ -512,9 +512,6 @@ static bool set_value(const char* fqn, Value& v)
         // now we must traverse the mod params to get the leaf
         string s = fqn;
         p = get_params(s, mod, mod->get_parameters());
-
-        if ( !p )
-            p = get_params(s, mod, mod->get_default_parameters());
     }
 
     if ( !p )
@@ -567,7 +564,6 @@ static bool begin(Module* m, const Parameter* p, const char* s, int idx, int dep
     // Module::(verified_)begin() will be called for top-level tables, lists, and list items only
     if ( top_level(s) )
     {
-        m->reset_trace();
         if ( !m->verified_begin(s, idx, s_config) )
             return false;
         // don't set list defaults
@@ -758,9 +754,6 @@ SO_PUBLIC bool open_table(const char* s, int idx)
         std::string sfqn = s;
         p = get_params(sfqn, m, m->get_parameters(), idx);
 
-        if ( !p )
-            p = get_params(sfqn, m, m->get_default_parameters(), idx);
-
         if ( !p )
         {
             ParseError("can't find %s", s);
@@ -1062,10 +1055,7 @@ void ModuleManager::show_module(const char* name)
         cout << endl << "Usage: "  << mod_use(m->get_usage()) << endl;
 
         const Parameter* params = m->get_parameters();
-        const Parameter* def_params = m->get_default_parameters();
-
-        if ( ( params and params->type < Parameter::PT_MAX ) ||
-             ( def_params and def_params->type < Parameter::PT_MAX ) )
+        if ( params and params->type < Parameter::PT_MAX )
         {
             cout << endl << "Configuration: " << endl << endl;
             show_configs(name, true);
@@ -1165,11 +1155,6 @@ void ModuleManager::show_configs(const char* pfx, bool exact)
             dump_field(s, pfx, m->params);
         }
 
-        s = m->name;
-
-        if ( m->default_params )
-            dump_table(s, pfx, m->default_params);
-
         if ( !pfx )
             cout << endl;
 
@@ -1484,11 +1469,6 @@ void ModuleManager::load_params()
         {
             load_field(s, m->params);
         }
-
-        s = m->name;
-
-        if ( m->default_params )
-            load_table(s, m->default_params);
     }
 }
 
index e9cce524b4f1dbfdd7cef99bfa58bd06808779e6..0035a99eae16c0c85a4ec44c16bf013040c71f55 100644 (file)
@@ -35,6 +35,7 @@
 #include "main/thread_config.h"
 #include "managers/inspector_manager.h"
 #include "profiler/profiler.h"
+#include "trace/trace.h"
 #include "utils/util.h"
 
 #include "app_info_table.h"
@@ -46,7 +47,7 @@
 using namespace snort;
 using namespace std;
 
-Trace appid_module_trace(MOD_NAME);
+THREAD_LOCAL const Trace* appid_trace = nullptr;
 
 //-------------------------------------------------------------------------
 // appid module
@@ -250,8 +251,7 @@ static const PegInfo appid_pegs[] =
     { CountType::END, nullptr, nullptr },
 };
 
-AppIdModule::AppIdModule() :
-    Module(MOD_NAME, MOD_HELP, s_params, false, &appid_module_trace)
+AppIdModule::AppIdModule() : Module(MOD_NAME, MOD_HELP, s_params)
 {
     config = nullptr;
 }
@@ -261,6 +261,15 @@ AppIdModule::~AppIdModule()
     AppIdPegCounts::cleanup_peg_info();
 }
 
+void AppIdModule::set_trace(const Trace* trace) const
+{ appid_trace = trace; }
+
+const TraceOption* AppIdModule::get_trace_options() const
+{
+    static const TraceOption appid_trace_options(nullptr, 0, nullptr);
+    return &appid_trace_options;
+}
+
 ProfileStats* AppIdModule::get_profile() const
 {
     return &appid_perf_stats;
@@ -273,7 +282,7 @@ const AppIdConfig* AppIdModule::get_data()
     return temp;
 }
 
-bool AppIdModule::set(const char* fqn, Value& v, SnortConfig* c)
+bool AppIdModule::set(const char*, Value& v, SnortConfig*)
 {
     // FIXIT-L: DECRYPT_DEBUG - Move this to ssl-module
 #ifdef REG_TEST
@@ -303,8 +312,6 @@ bool AppIdModule::set(const char* fqn, Value& v, SnortConfig* c)
         config->list_odp_detectors = v.get_bool();
     else if ( v.is("log_all_sessions") )
         config->log_all_sessions = v.get_bool();
-    else
-        return Module::set(fqn, v, c);
 
     return true;
 }
index 323fec56cc989c47d3517f7f5e314eb415ce2d76..d2197f8ad9163d69b9309afcd8c0d10a282b6b5f 100644 (file)
 #include "appid_config.h"
 #include "appid_pegs.h"
 
-extern THREAD_LOCAL snort::ProfileStats appid_perf_stats;
+namespace snort
+{
+class Trace;
+}
 
-extern snort::Trace appid_module_trace;
+extern THREAD_LOCAL snort::ProfileStats appid_perf_stats;
+extern THREAD_LOCAL const snort::Trace* appid_trace;
 
 #define MOD_NAME "appid"
 #define MOD_HELP "application and service identification"
@@ -86,6 +90,9 @@ public:
     void sum_stats(bool) override;
     void show_dynamic_stats() override;
 
+    void set_trace(const snort::Trace*) const override;
+    const snort::TraceOption* get_trace_options() const override;
+
 private:
     AppIdConfig* config;
     AppIdReloadTuner appid_rrt;
index c5a4aff6025c3352adb96bbb81fc6c1056d91770..437195bbcaba00551538db52bbbd6a6bf4868f19 100644 (file)
@@ -65,7 +65,6 @@ PegCount Module::get_global_count(char const*) const { return 0; }
 void Module::show_interval_stats(std::vector<unsigned int, std::allocator<unsigned int> >&, FILE*) {}
 void Module::show_stats(){}
 void Module::sum_stats(bool ){}
-bool Module::set(const char*, Value&, SnortConfig*){ return false;}
 void Module::reset_stats() {}
 }
 
index 021657b48c8de0473138458f3e7f86b347e5b2ae..962a4a435051ed0c99884a1f8b2e0193dd9d5a8f 100644 (file)
@@ -26,6 +26,7 @@
 #include "detector_pattern.h"
 
 #include "log/messages.h"
+#include "main/snort_debug.h"
 #include "managers/inspector_manager.h"
 #include "protocols/packet.h"
 #include "search_engines/search_tool.h"
@@ -39,12 +40,12 @@ static void dump_patterns(const char* name, PatternService* pList)
 {
     UNUSED(name);
 
-    debug_logf(appid_module_trace, "Adding pattern for \"%s\"\n", name);
+    debug_logf(appid_trace, "Adding pattern for \"%s\"\n", name);
     for (PatternService* ps = pList; ps; ps = ps->next)
         for (Pattern* pattern = ps->pattern; pattern; pattern = pattern->next)
             if (pattern->data && pattern->length)
             {
-                debug_logf(appid_module_trace, "\t\t%s, %u\n",pattern->data, pattern->length);
+                debug_logf(appid_trace, "\t\t%s, %u\n",pattern->data, pattern->length);
             }
 }
 
index b4449713bd68d3b468d6d14278e5d63dfcbff9e0..696a2e2cf7eda4c2adb196a1aaddfc66c5ab985a 100644 (file)
@@ -26,8 +26,6 @@
 #include "client_plugins/client_detector.h"
 #include "service_plugins/service_detector.h"
 
-#include "main/snort_debug.h"
-
 namespace snort
 {
 class SearchTool;
index 1f594dfb264af0b2c46b9c54d13c0677424db296..ee874d50b04658e6a9b49f2f52489169341e61d5 100644 (file)
@@ -142,6 +142,9 @@ snort::ProfileStats* AppIdModule::get_profile() const
     return nullptr;
 }
 
+void AppIdModule::set_trace(const Trace*) const { }
+const TraceOption* AppIdModule::get_trace_options() const { return nullptr; }
+
 // Stubs for inspectors
 unsigned AppIdSession::inspector_id = 0;
 AppIdConfig stub_config;
index a57f43e4e7277d1778b7a3ef175addc274ea1ecf..1705c02d45522333e5b0468e788e66d228149467 100644 (file)
@@ -69,12 +69,6 @@ DnsPatternMatchers::~DnsPatternMatchers() { }
 SipPatternMatchers::~SipPatternMatchers() { }
 SslPatternMatchers::~SslPatternMatchers() { }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 TEST_GROUP(http_url_patterns_tests)
 {
     void setup() override
index d6c4eec874ad9f460edefb259dabf221257fbec7..aefacc26e67b313a63b87c50c7aeed8858119ae4 100644 (file)
@@ -29,6 +29,7 @@
 #include <unordered_map>
 
 #include "log/messages.h"
+#include "main/snort_debug.h"
 #include "main/snort_types.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
@@ -300,7 +301,7 @@ static int detector_log_message(lua_State* L)
         break;
 
     case LUA_LOG_TRACE:
-        debug_logf(appid_module_trace, "%s:%s\n", name.c_str(), message);
+        debug_logf(appid_trace, "%s:%s\n", name.c_str(), message);
         break;
 
     default:
index baa67f72fc019e6298f9ce1f2d6e351afbf6f078..d29e7ae01099c1c0c5627c66a4de39f4514565b7 100644 (file)
@@ -31,8 +31,6 @@
 #include "client_plugins/client_detector.h"
 #include "service_plugins/service_detector.h"
 
-#include "main/snort_debug.h"
-
 namespace snort
 {
 struct Packet;
index 812b8a77fe9859b39a52f0811c510eeb0ba4e51f..ffe1f16c4cf804a6dbe348c76ba13ba64b4e92a0 100644 (file)
@@ -77,8 +77,6 @@ enum NBSSState
 #define NBDGM_ERROR_CODE_MIN    0x82
 #define NBDGM_ERROR_CODE_MAX    0x84
 
-#define min(x,y) ((x)<(y) ? (x) : (y))
-
 #define FINGERPRINT_UDP_FLAGS_XENIX 0x00000800
 #define FINGERPRINT_UDP_FLAGS_NT    0x00001000
 #define FINGERPRINT_UDP_FLAGS_MASK  (FINGERPRINT_UDP_FLAGS_XENIX | FINGERPRINT_UDP_FLAGS_NT)
@@ -862,7 +860,7 @@ int NbssServiceDetector::validate(AppIdDiscoveryArgs& args)
                 }
                 else if (tmp >= 4 && nd->length >= 4 &&
                     !(*((const uint32_t*)data)) &&
-                    dcerpc_validate(data+4, ((int)min(tmp, nd->length)) - 4) > 0)
+                    dcerpc_validate(data+4, ((int)std::min(tmp, nd->length)) - 4) > 0)
                 {
                     nd->serviceAppId = APP_ID_DCE_RPC;
                     nd->miscAppId = APP_ID_NETBIOS_SSN;
@@ -924,7 +922,7 @@ int NbssServiceDetector::validate(AppIdDiscoveryArgs& args)
                 }
                 else if (tmp >= 4 && nd->length >= 4 &&
                     !(*((const uint32_t*)data)) &&
-                    !(dcerpc_validate(data+4, ((int)min(tmp, nd->length)) - 4) > 0))
+                    !(dcerpc_validate(data+4, ((int)std::min(tmp, nd->length)) - 4) > 0))
                 {
                     nd->serviceAppId = APP_ID_DCE_RPC;
                     nd->miscAppId = APP_ID_NETBIOS_SSN;
index 391a053c3dc6b58fbf45a1e81f04f8bce82c41e8..de9eb8c5d2ad03a39d6108feca02b0ed2fe968c4 100644 (file)
@@ -68,13 +68,12 @@ public:
 SO_PUBLIC static Inspector* get_inspector(const char*, bool, SnortConfig*) {return nullptr;}
 };
 Module::Module(const char*, const char*) {}
-Module::Module(const char*, const char*, const Parameter*, bool, Trace*, const Parameter*)
+Module::Module(const char*, const char*, const Parameter*, bool)
 {}
 PegCount Module::get_global_count(char const*) const { return 0; }
 void Module::show_interval_stats(std::vector<unsigned int, std::allocator<unsigned int> >&, FILE*) {}
 void Module::show_stats(){}
 void Module::sum_stats(bool ){}
-bool Module::set(const char*, Value&, SnortConfig*){ return false;}
 void Module::reset_stats() {}
 }
 
@@ -163,6 +162,9 @@ PegCount* AppIdModule::get_counts() const
     return nullptr;
 }
 
+void AppIdModule::set_trace(const Trace*) const { }
+const TraceOption* AppIdModule::get_trace_options() const { return nullptr; }
+
 // Stubs for inspectors
 unsigned AppIdSession::inspector_id = 0;
 AppIdConfig stub_config;
index d3c4fd6719d5bcdb4c4b3d351e9313e7ccddace5..c8e0dd1721ccb93427b39426821bdcb8deb6be60 100644 (file)
@@ -56,7 +56,6 @@ class StreamSplitter* Inspector::get_splitter(bool) { return nullptr; }
 
 // Stubs for module
 Module::Module(char const*, char const*) {}
-bool Module::set(const char*, Value&, SnortConfig*) { return true; }
 void Module::sum_stats(bool) {}
 void Module::show_interval_stats(std::vector<unsigned>&, FILE*) {}
 void Module::show_stats() {}
@@ -148,6 +147,8 @@ const Command* AppIdModule::get_commands() const { return nullptr; }
 const PegInfo* AppIdModule::get_pegs() const { return nullptr; }
 PegCount* AppIdModule::get_counts() const { return nullptr; }
 ProfileStats* AppIdModule::get_profile() const { return nullptr; }
+void AppIdModule::set_trace(const Trace*) const { }
+const TraceOption* AppIdModule::get_trace_options() const { return nullptr; }
 
 // Stubs for config
 static AppIdConfig app_config;
index 2452a89c1fae9dd4ac31584f4136e8d02713ed0e..9d30adce667ec51f1df2e1802462d246a8312c72 100644 (file)
@@ -38,7 +38,6 @@ bool Inspector::get_buf(const char*, Packet*, InspectionBuffer&) { return true;
 class StreamSplitter* Inspector::get_splitter(bool) { return nullptr; }
 
 Module::Module(char const*, char const*) {}
-bool Module::set(const char*, Value&, SnortConfig*) { return true; }
 void Module::sum_stats(bool) {}
 void Module::show_interval_stats(std::vector<unsigned int, std::allocator<unsigned int> >&, FILE*) {}
 void Module::show_stats() {}
@@ -58,6 +57,8 @@ const snort::Command* AppIdModule::get_commands() const { return nullptr; }
 const PegInfo* AppIdModule::get_pegs() const { return nullptr; }
 PegCount* AppIdModule::get_counts() const { return nullptr; }
 snort::ProfileStats* AppIdModule::get_profile() const { return nullptr; }
+void AppIdModule::set_trace(const Trace*) const { }
+const TraceOption* AppIdModule::get_trace_options() const { return nullptr; }
 
 AppIdInspector::AppIdInspector(AppIdModule& ) { }
 AppIdInspector::~AppIdInspector() { }
index 350b86bd38837621f41c8b7b243444210d559675..350a4b16b3db7bf2a26fb963f8f6fefe104bd268 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "tp_lib_handler.h"
 #include "appid_config.h"
-#include "main/snort_debug.h"
 #include "log_message_mock.h"
 
 #include <CppUTest/CommandLineTestRunner.h>
index 7d70d91336fcc7e004efd8dd0d4e42f50e1177c5..0d31e465deb468232b14894439f2d10914ebac7a 100644 (file)
@@ -30,6 +30,7 @@
 #include "detection/detection_engine.h"
 #include "log/text_log.h"
 #include "main/snort_config.h"
+#include "main/snort_debug.h"
 #include "packet_io/active.h"
 #include "packet_io/sfdaq.h"
 #include "profiler/profiler_defs.h"
index c27035d1ad787499f13b440343ef628a15f54983..3458e1b03d7faf2e7b778c1560bfffa40a829885 100644 (file)
@@ -29,7 +29,6 @@
 #include "framework/mpse.h"
 #include "framework/mpse_batch.h"
 #include "main/snort_config.h"
-#include "main/trace.h"
 #include "utils/stats.h"
 
 // must appear after snort_config.h to avoid broken c++ map include
@@ -134,12 +133,6 @@ unsigned get_instance_id()
 
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
 void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
 
index cbf463e8c1a10e735084c9ad7940d473911f1745..9b5075d3af3b597b149ac55cd5a925d87b277b0b 100644 (file)
@@ -28,6 +28,7 @@
 #include "detection/detection_util.h"
 #include "file_api/file_flows.h"
 #include "file_api/file_service.h"
+#include "main/snort_debug.h"
 #include "utils/util.h"
 
 #include "dce_smb_module.h"
index f07307c0996735d61d7e28bb4fac38c8d4cf01d5..f3f0cc25398c695bed016fc83ef0011f4f8967ed 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "log/messages.h"
 #include "main/snort_config.h"
+#include "trace/trace.h"
 #include "utils/util.h"
 
 #include "dce_smb.h"
@@ -33,7 +34,7 @@
 using namespace snort;
 using namespace std;
 
-Trace dce_smb_trace(DCE2_SMB_NAME);
+THREAD_LOCAL const Trace* dce_smb_trace = nullptr;
 
 static const PegInfo dce2_smb_pegs[] =
 {
@@ -213,7 +214,7 @@ static std::string get_shares(DCE2_List* shares)
     return cmds;
 }
 
-Dce2SmbModule::Dce2SmbModule() : Module(DCE2_SMB_NAME, DCE2_SMB_HELP, s_params, false, &dce_smb_trace)
+Dce2SmbModule::Dce2SmbModule() : Module(DCE2_SMB_NAME, DCE2_SMB_HELP, s_params)
 {
     memset(&config, 0, sizeof(config));
 }
@@ -226,6 +227,15 @@ Dce2SmbModule::~Dce2SmbModule()
     }
 }
 
+void Dce2SmbModule::set_trace(const Trace* trace) const
+{ dce_smb_trace = trace; }
+
+const TraceOption* Dce2SmbModule::get_trace_options() const
+{
+    static const TraceOption dce_smb_trace_options(nullptr, 0, nullptr);
+    return &dce_smb_trace_options;
+}
+
 const RuleMap* Dce2SmbModule::get_rules() const
 {
     return dce2_smb_rules;
@@ -376,7 +386,7 @@ static bool set_smb_invalid_shares(dce2SmbProtoConf& config, Value& v)
     return(true);
 }
 
-bool Dce2SmbModule::set(const char* fqn, Value& v, SnortConfig* c)
+bool Dce2SmbModule::set(const char*, Value& v, SnortConfig*)
 {
     if (dce2_set_co_config(v,config.common))
         return true;
@@ -405,9 +415,6 @@ bool Dce2SmbModule::set(const char* fqn, Value& v, SnortConfig* c)
     else if ( v.is("smb_legacy_mode"))
         config.legacy_mode = v.get_bool();
 
-    else
-        return Module::set(fqn, v, c);
-
     return true;
 }
 
index 1b91415284152db1374fbb2b8e094fbc00b370e6..86e0061eae872f96e4ee7290c8518f30803cb871 100644 (file)
 
 namespace snort
 {
+class Trace;
 struct SnortConfig;
 }
 
+extern THREAD_LOCAL const snort::Trace* dce_smb_trace;
+
 #define DCE2_VALID_SMB_VERSION_FLAG_V1 1
 #define DCE2_VALID_SMB_VERSION_FLAG_V2 2
 
@@ -61,8 +64,6 @@ struct dce2SmbProtoConf
     bool legacy_mode;
 };
 
-extern snort::Trace dce_smb_trace;
-
 class Dce2SmbModule : public snort::Module
 {
 public:
@@ -83,6 +84,9 @@ public:
     Usage get_usage() const override
     { return INSPECT; }
 
+    void set_trace(const snort::Trace*) const override;
+    const snort::TraceOption* get_trace_options() const override;
+
 private:
     dce2SmbProtoConf config;
 };
index a8ab1a13889d23b0609255e2502ee6976e30ccd9..33e0fffb65c10f8c09ac7b97e1dd99cb93058cdd 100644 (file)
@@ -30,6 +30,8 @@
 #include "dce_smb_module.h"
 #include "dce_smb_transaction_utils.h"
 
+#include "main/snort_debug.h"
+
 using namespace snort;
 
 #define DCE2_SMB_TRANS__NONE    0x00
index e370a2f70f028ac424d85a1daea909547f176f21..fab99ac0a1f67c42dd49184e63660a2d1233934b 100644 (file)
@@ -29,6 +29,7 @@
 #include "detection/detection_util.h"
 #include "file_api/file_api.h"
 #include "main/snort.h"
+#include "main/snort_debug.h"
 #include "packet_io/active.h"
 #include "utils/util.h"
 
index cd649f742a189931a960cf8791d45e377048ffcb..8f32459d632a819e05d356f8367c3735163af488 100644 (file)
 #include "dce_udp_module.h"
 
 #include "log/messages.h"
+#include "trace/trace.h"
 
 #include "dce_udp.h"
 
 using namespace snort;
 using namespace std;
 
-Trace dce_udp_trace(DCE2_UDP_NAME);
+THREAD_LOCAL const Trace* dce_udp_trace = nullptr;
 
 static const Parameter s_params[] =
 {
@@ -84,8 +85,16 @@ static const PegInfo dce2_udp_pegs[] =
     { CountType::END, nullptr, nullptr }
 };
 
-Dce2UdpModule::Dce2UdpModule() : Module(DCE2_UDP_NAME, DCE2_UDP_HELP, s_params, false, &dce_udp_trace)
+Dce2UdpModule::Dce2UdpModule() : Module(DCE2_UDP_NAME, DCE2_UDP_HELP, s_params)
+{ }
+
+void Dce2UdpModule::set_trace(const Trace* trace) const
+{ dce_udp_trace = trace; }
+
+const TraceOption* Dce2UdpModule::get_trace_options() const
 {
+    static const TraceOption dce_udp_trace_options(nullptr, 0, nullptr);
+    return &dce_udp_trace_options;
 }
 
 const RuleMap* Dce2UdpModule::get_rules() const
@@ -108,12 +117,9 @@ ProfileStats* Dce2UdpModule::get_profile() const
     return &dce2_udp_pstat_main;
 }
 
-bool Dce2UdpModule::set(const char* fqn, Value& v, SnortConfig* c)
+bool Dce2UdpModule::set(const char*, Value& v, SnortConfig*)
 {
-    if (dce2_set_common_config(v,config.common))
-        return true;
-    else
-        return Module::set(fqn, v, c);
+    return dce2_set_common_config(v,config.common);
 }
 
 void Dce2UdpModule::get_data(dce2UdpProtoConf& dce2_udp_config)
index d44a05bbedce301da87d083385d8dc97c8bd9db4..4c953ec46066bc58399c0ae25eb8b0d49503ad6f 100644 (file)
 #include "dce_common.h"
 #include "framework/module.h"
 
+namespace snort
+{
+class Trace;
+struct SnortConfig;
+}
+
+extern THREAD_LOCAL const snort::Trace* dce_udp_trace;
+
 #define DCE2_CL_BAD_MAJOR_VERSION 40
 #define DCE2_CL_BAD_PDU_TYPE      41
 #define DCE2_CL_DATA_LT_HDR       42
 #define DCE2_CL_DATA_LT_HDR_STR  "connection-less DCE/RPC - data length less than header size"
 #define DCE2_CL_BAD_SEQ_NUM_STR  "connection-less DCE/RPC - bad sequence number"
 
-namespace snort
-{
-struct SnortConfig;
-}
-
 struct dce2UdpProtoConf
 {
     dce2CommonProtoConf common;
 };
 
-extern snort::Trace dce_udp_trace;
-
 class Dce2UdpModule : public snort::Module
 {
 public:
@@ -65,6 +66,9 @@ public:
     Usage get_usage() const override
     { return INSPECT; }
 
+    void set_trace(const snort::Trace*) const override;
+    const snort::TraceOption* get_trace_options() const override;
+
 private:
     dce2UdpProtoConf config;
 };
index 25e09d839f6eb141a3474514b7fb177e28a5fc2f..27bc1a36027095c0e77484b2b3257f7d30d1a504 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "detection/detect.h"
 #include "file_api/file_service.h"
+#include "main/snort_debug.h"
 #include "protocols/packet.h"
 #include "utils/util.h"
 #include "packet_io/active.h"
index 79fd0478331480592ea52245ceba398a74381ceb..664ef61f96e866381e5a9f4da9fdfd195f96b170 100644 (file)
 #include <cassert>
 
 #include "profiler/profiler.h"
+#include "trace/trace.h"
 
 #include "gtp.h"
 
 using namespace snort;
 
-Trace gtp_inspect_trace(GTP_NAME);
+THREAD_LOCAL const Trace* gtp_inspect_trace = nullptr;
 
 THREAD_LOCAL ProfileStats gtp_inspect_prof;
 
@@ -124,11 +125,19 @@ static const Parameter gtp_params[] =
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-GtpInspectModule::GtpInspectModule() :
-    Module(GTP_NAME, GTP_HELP, gtp_params, true, &gtp_inspect_trace)
+GtpInspectModule::GtpInspectModule() : Module(GTP_NAME, GTP_HELP, gtp_params, true)
 { }
 
-bool GtpInspectModule::set(const char* fqn, Value& v, SnortConfig* c)
+void GtpInspectModule::set_trace(const Trace* trace) const
+{ gtp_inspect_trace = trace; }
+
+const TraceOption* GtpInspectModule::get_trace_options() const
+{
+    static const TraceOption gtp_inspect_trace_options(nullptr, 0, nullptr);
+    return &gtp_inspect_trace_options;
+}
+
+bool GtpInspectModule::set(const char*, Value& v, SnortConfig*)
 {
     if ( v.is("version") )
         stuff.version = v.get_uint8();
@@ -142,9 +151,6 @@ bool GtpInspectModule::set(const char* fqn, Value& v, SnortConfig* c)
     else if ( v.is("name") )
         stuff.name = v.get_string();
 
-    else
-        return Module::set(fqn, v, c);
-
     return true;
 }
 
index 3152b2d46c5df0f0d88c01b6e9795a48912df10a..5a568fda31644d5862acd76f287db9ed25265a59 100644 (file)
@@ -22,7 +22,6 @@
 #define GTP_MODULE_H
 
 #include "framework/module.h"
-#include "main/snort_debug.h"
 
 #define GID_GTP 143
 
 #define GTP_NAME "gtp_inspect"
 #define GTP_HELP "gtp control channel inspection"
 
+namespace snort
+{
+class Trace;
+}
+
 extern THREAD_LOCAL snort::ProfileStats gtp_inspect_prof;
-extern snort::Trace gtp_inspect_trace;
+extern THREAD_LOCAL const snort::Trace* gtp_inspect_trace;
 
 struct GtpStuff
 {
@@ -68,6 +72,9 @@ public:
     Usage get_usage() const override
     { return INSPECT; }
 
+    void set_trace(const snort::Trace*) const override;
+    const snort::TraceOption* get_trace_options() const override;
+
 public:
     GtpStuff stuff;
     std::vector<GtpStuff> temp;
index c576e4005bf1163b52a86f5b75e6c2b968cf21f6..4d50137c1136961ad0a2e311bbf7c21063484002 100644 (file)
@@ -31,6 +31,7 @@
 #include "detection/detection_engine.h"
 #include "events/event_queue.h"
 #include "log/messages.h"
+#include "main/snort_debug.h"
 #include "utils/util_cstring.h"
 
 #include "gtp.h"
index 1c47d0cf9e75aa8c8ad1cce5ad1b6b5a7ab770d4..f5f1e86ce2edfbd7accdc432e992e67933b5a3c3 100644 (file)
@@ -47,12 +47,6 @@ void Value::get_bits(std::bitset<256ul>&) const {}
 int DetectionEngine::queue_event(unsigned int, unsigned int, Actions::Type) { return 0; }
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
 void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
 
index 69e20f6e4d10d59f188e7a0917e06bf19cde4c8c..5d095a146d3fe14689877b99081c01cae39e598b 100644 (file)
@@ -42,12 +42,6 @@ void Value::get_bits(std::bitset<256ul>&) const {}
 int DetectionEngine::queue_event(unsigned int, unsigned int, Actions::Type) { return 0; }
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
 void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
 
index 2106c384e814a8c1e00fa17a1dce7bdde8a89e2b..da4828a1bac92678996a22b74b3d5b99ec984eb3 100644 (file)
 
 #include "wiz_module.h"
 
+#include "trace/trace.h"
+
 #include "curses.h"
 #include "magic.h"
 
 using namespace snort;
 using namespace std;
 
-Trace wizard_trace(WIZ_NAME);
+THREAD_LOCAL const Trace* wizard_trace = nullptr;
 
 //-------------------------------------------------------------------------
 // wizard module
@@ -106,7 +108,7 @@ static const Parameter s_params[] =
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-WizardModule::WizardModule() : Module(WIZ_NAME, WIZ_HELP, s_params, false, &wizard_trace)
+WizardModule::WizardModule() : Module(WIZ_NAME, WIZ_HELP, s_params)
 {
     c2s_hexes = nullptr;
     s2c_hexes = nullptr;
@@ -126,10 +128,19 @@ WizardModule::~WizardModule()
     delete curses;
 }
 
+void WizardModule::set_trace(const Trace* trace) const
+{ wizard_trace = trace; }
+
+const TraceOption* WizardModule::get_trace_options() const
+{
+    static const TraceOption wizard_trace_options(nullptr, 0, nullptr);
+    return &wizard_trace_options;
+}
+
 ProfileStats* WizardModule::get_profile() const
 { return &wizPerfStats; }
 
-bool WizardModule::set(const char* fqn, Value& v, SnortConfig* sc)
+bool WizardModule::set(const char*, Value& v, SnortConfig*)
 {
     if ( v.is("service") )
         service = v.get_string();
@@ -150,9 +161,6 @@ bool WizardModule::set(const char* fqn, Value& v, SnortConfig* sc)
     else if ( v.is("curses") )
         curses->add_curse(v.get_string());
 
-    else
-        return Module::set(fqn, v, sc);
-
     return true;
 }
 
index f3c7d68ab34f1ae4c76be0255fa08e0283c4e2c5..26ca6ba6f244766ea248853f434a555b1e041a6d 100644 (file)
 #define WIZ_NAME "wizard"
 #define WIZ_HELP "inspector that implements port-independent protocol identification"
 
+namespace snort
+{
+class Trace;
+}
+
 extern const PegInfo wiz_pegs[];
 extern THREAD_LOCAL struct WizStats tstats;
 extern THREAD_LOCAL snort::ProfileStats wizPerfStats;
+extern THREAD_LOCAL const snort::Trace* wizard_trace;
 
 class MagicBook;
 class CurseBook;
@@ -55,6 +61,9 @@ public:
     Usage get_usage() const override
     { return INSPECT; }
 
+    void set_trace(const snort::Trace*) const override;
+    const snort::TraceOption* get_trace_options() const override;
+
 private:
     void add_spells(MagicBook*, std::string&);
 
@@ -73,7 +82,5 @@ private:
     CurseBook* curses;
 };
 
-extern snort::Trace wizard_trace;
-
 #endif
 
index 72a37823021d890c77d62b27e06a8db7870ee772..7c35cedcc7b6ed316076d86b5bc7a26d2be692c1 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "flow/flow.h"
 #include "log/messages.h"
+#include "main/snort_debug.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
 #include "stream/stream_splitter.h"
index e12dfe54c7b88d79de67c9a2e388818450363490..76e2a71f9cfdb134a0f504a4fb65a0f67fc7c5b1 100644 (file)
@@ -27,7 +27,6 @@
 #include "side_channel/side_channel_module.h"
 
 #include "log/messages.h"
-#include "main/snort_debug.h"
 #include "profiler/profiler.h"
 
 #include <CppUTest/CommandLineTestRunner.h>
@@ -56,12 +55,6 @@ void SideChannelManager::instantiate(const SCConnectors*, const PortBitSet* port
     port_1_set = ports->test(1);
 }
 
-Trace::Trace(const char*, const TraceOptionString*, size_t) {}
-Trace::Trace(const char*) {}
-bool Trace::set(const snort::Value&) { return true; }
-void Trace::reset() {}
-void Trace::enable() {}
-
 void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { }
 void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { }
 
index 5ddbbe9fe777364bc3253e8c32c623dc40fce82b..acefe8d74bc57c6df3aaff9ba0f5a9466a15ec54 100644 (file)
@@ -26,7 +26,6 @@
 #include "side_channel/side_channel.h"
 
 #include "log/messages.h"
-#include "main/snort_debug.h"
 #include "managers/connector_manager.h"
 
 #include <CppUTest/CommandLineTestRunner.h>
index ecd7850b81b96b973b6eb1fec3473f49591d1c36..0a7df8a8ebd9118a5bf8622d3cdd8ed5966bb542 100644 (file)
 #include "log/messages.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
-#include "main/snort_debug.h"
 #include "stream/flush_bucket.h"
+#include "trace/trace.h"
 
 using namespace snort;
 using namespace std;
 
+THREAD_LOCAL const Trace* stream_trace = nullptr;
+
 //-------------------------------------------------------------------------
 // stream module
 //-------------------------------------------------------------------------
-Trace stream_trace(MOD_NAME);
 
 #define FLOW_TYPE_PARAMS(name, idle, weight) \
 static const Parameter name[] = \
@@ -101,10 +102,18 @@ static const RuleMap stream_rules[] =
 static const char* const flow_type_names[] =
 { "none", "ip_cache", "tcp_cache", "udp_cache", "icmp_cache", "user_cache", "file_cache", "max"};
 
-StreamModule::StreamModule() :
-    Module(MOD_NAME, MOD_HELP, s_params, false, &stream_trace)
+StreamModule::StreamModule() : Module(MOD_NAME, MOD_HELP, s_params)
 { }
 
+void StreamModule::set_trace(const Trace* trace) const
+{ stream_trace = trace; }
+
+const TraceOption* StreamModule::get_trace_options() const
+{
+    static const TraceOption stream_trace_options(nullptr, 0, nullptr);
+    return &stream_trace_options;
+}
+
 const PegInfo* StreamModule::get_pegs() const
 { return base_pegs; }
 
@@ -172,14 +181,12 @@ bool StreamModule::set(const char* fqn, Value& v, SnortConfig* c)
     else if ( strstr(fqn, "file_cache") )
         type = PktType::FILE;
     else
-        return Module::set(fqn, v, c);
+        return false;
 
     if ( v.is("idle_timeout") )
         config.flow_cache_cfg.proto[to_utype(type)].nominal_timeout = v.get_uint32();
     else if ( v.is("cap_weight") )
         config.flow_cache_cfg.proto[to_utype(type)].cap_weight = v.get_uint16();
-    else
-        return false;
 
     return true;
 }
index 016d37d00750bc4b70367abfbd019be8c4e3e956..671103f314978eeabf3317d84c31d47c71340b49 100644 (file)
 #include "flow/flow_control.h"
 #include "framework/module.h"
 
-extern THREAD_LOCAL snort::ProfileStats s5PerfStats;
-extern THREAD_LOCAL class FlowControl* flow_con;
-
 namespace snort
 {
+class Trace;
 struct SnortConfig;
 }
 
+extern THREAD_LOCAL snort::ProfileStats s5PerfStats;
+extern THREAD_LOCAL class FlowControl* flow_con;
+extern THREAD_LOCAL const snort::Trace* stream_trace;
+
 //-------------------------------------------------------------------------
 // stream module
 //-------------------------------------------------------------------------
-extern snort::Trace stream_trace;
 
 #define MOD_NAME "stream"
 #define MOD_HELP "common flow tracking"
@@ -128,6 +129,9 @@ public:
     Usage get_usage() const override
     { return GLOBAL; }
 
+    void set_trace(const snort::Trace*) const override;
+    const snort::TraceOption* get_trace_options() const override;
+
 private:
     StreamModuleConfig config;
     StreamReloadResourceManager reload_resource_manager;
index 24ac736cef5d3438911e6dc1a3397cf7ca77c4d2..38b235e7938726dc0f9b1bf04c6e611cd8765bd4 100644 (file)
@@ -75,6 +75,7 @@
 #include "log/messages.h"
 #include "main/analyzer.h"
 #include "main/snort_config.h"
+#include "main/snort_debug.h"
 #include "memory/memory_cap.h"
 #include "packet_io/active.h"
 #include "packet_io/sfdaq_config.h"
index 662c29849782df50f92199c735bef372ecff2307..895a5d8354e95af1a80eacdb163ea7ce6aafb791 100644 (file)
 
 #include "ip_session.h"
 #include "stream_ip.h"
+#include "trace/trace.h"
 
 using namespace snort;
 using namespace std;
 
+THREAD_LOCAL const Trace* stream_ip_trace = nullptr;
+
 #define DEFRAG_IPOPTIONS_STR \
     "inconsistent IP options on fragmented packets"
 
@@ -81,8 +84,6 @@ FragEngine::FragEngine()
 // stream_ip module
 //-------------------------------------------------------------------------
 
-Trace stream_ip_trace(MOD_NAME);
-
 static const RuleMap stream_ip_rules[] =
 {
     { DEFRAG_IPOPTIONS, DEFRAG_IPOPTIONS_STR },
@@ -123,9 +124,10 @@ static const Parameter s_params[] =
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-StreamIpModule::StreamIpModule() :
-    Module(MOD_NAME, MOD_HELP, s_params, false, &stream_ip_trace)
-{ config = nullptr; }
+StreamIpModule::StreamIpModule() : Module(MOD_NAME, MOD_HELP, s_params)
+{
+    config = nullptr;
+}
 
 StreamIpModule::~StreamIpModule()
 {
@@ -133,6 +135,15 @@ StreamIpModule::~StreamIpModule()
         delete config;
 }
 
+void StreamIpModule::set_trace(const Trace* trace) const
+{ stream_ip_trace = trace; }
+
+const TraceOption* StreamIpModule::get_trace_options() const
+{
+    static const TraceOption stream_ip_trace_options(nullptr, 0, nullptr);
+    return &stream_ip_trace_options;
+}
+
 const RuleMap* StreamIpModule::get_rules() const
 { return stream_ip_rules; }
 
@@ -146,7 +157,7 @@ StreamIpConfig* StreamIpModule::get_data()
     return temp;
 }
 
-bool StreamIpModule::set(const char* f, Value& v, SnortConfig* c)
+bool StreamIpModule::set(const char*, Value& v, SnortConfig*)
 {
     if ( v.is("max_frags") )
         config->frag_engine.max_frags = v.get_uint32();
@@ -169,8 +180,6 @@ bool StreamIpModule::set(const char* f, Value& v, SnortConfig* c)
         config->session_timeout = v.get_uint32();
         config->frag_engine.frag_timeout = v.get_uint32();
     }
-    else
-        return Module::set(f, v, c);
 
     return true;
 }
index bebf45abeaf422eada55ef783d0c749888a1d89e..b1f26214fc6f72975d4d337edbbc4af778813803 100644 (file)
 
 #include "flow/session.h"
 #include "framework/module.h"
-#include "main/snort_debug.h"
 
 namespace snort
 {
+class Trace;
 struct SnortConfig;
 }
 
+extern THREAD_LOCAL const snort::Trace* stream_ip_trace;
+
 #define GLOBAL_KEYWORD "defrag"
 #define ENGINE_KEYWORD "defrag_engine"
 
@@ -83,7 +85,6 @@ struct IpStats
 
 extern const PegInfo ip_pegs[];
 extern THREAD_LOCAL snort::ProfileStats ip_perf_stats;
-extern snort::Trace stream_ip_trace;
 
 //-------------------------------------------------------------------------
 // stream_ip module
@@ -115,6 +116,9 @@ public:
     Usage get_usage() const override
     { return INSPECT; }
 
+    void set_trace(const snort::Trace*) const override;
+    const snort::TraceOption* get_trace_options() const override;
+
 private:
     StreamIpConfig* config;
 };
index 15df7c81cdd04b31ffd00b210db0a365942ba2a2..2f96dd37df53163a1dd9f85a66137f78fbd094a1 100644 (file)
@@ -32,6 +32,7 @@
 #include "flow/prune_stats.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
+#include "main/snort_debug.h"
 #include "packet_io/active.h"
 #include "protocols/vlan.h"
 #include "stream/base/stream_module.h"
index 14602f5bc37229c5b105daadf2ccac123ed71bf4..92aa3f6115972a9d1997cef7ea45c697a1e49d1c 100644 (file)
@@ -22,8 +22,6 @@
 #ifndef TCP_SEGMENT_H
 #define TCP_SEGMENT_H
 
-#include "main/snort_debug.h"
-
 #include "tcp_segment_descriptor.h"
 #include "tcp_defs.h"
 
index 1d54be68899dbc0f1994206a14f28bcf4dc48b8c..e5f1099204a4968439d900f86ca91776670f9dad 100644 (file)
 #include "user_module.h"
 
 #include "stream_user.h"
+#include "trace/trace.h"
 
 using namespace snort;
 using namespace std;
 
-Trace stream_user_trace(MOD_NAME);
+THREAD_LOCAL const Trace* stream_user_trace = nullptr;
 
 //-------------------------------------------------------------------------
 // stream_user module
@@ -42,8 +43,7 @@ static const Parameter s_params[] =
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-StreamUserModule::StreamUserModule() :
-    Module(MOD_NAME, MOD_HELP, s_params, false, &stream_user_trace)
+StreamUserModule::StreamUserModule() : Module(MOD_NAME, MOD_HELP, s_params)
 {
     config = nullptr;
 }
@@ -61,14 +61,20 @@ StreamUserConfig* StreamUserModule::get_data()
     return temp;
 }
 
-bool StreamUserModule::set(const char* fqn, Value& v, SnortConfig* sc)
+void StreamUserModule::set_trace(const Trace* trace) const
+{ stream_user_trace = trace; }
+
+const TraceOption* StreamUserModule::get_trace_options() const
+{
+    static const TraceOption stream_user_trace_options(nullptr, 0, nullptr);
+    return &stream_user_trace_options;
+}
+
+bool StreamUserModule::set(const char*, Value& v, SnortConfig*)
 {
     if ( v.is("session_timeout") )
         config->session_timeout = v.get_uint32();
 
-    else
-        return Module::set(fqn, v, sc);
-
     return true;
 }
 
index cc4c4629689304b044e3bfac4cf5dcb997269eae..f42f235b02568f44e0d20a2add5a2c55a93bd24c 100644 (file)
 
 namespace snort
 {
+class Trace;
 struct SnortConfig;
 }
 
+extern THREAD_LOCAL const snort::Trace* stream_user_trace;
 extern THREAD_LOCAL snort::ProfileStats user_perf_stats;
 
-extern snort::Trace stream_user_trace;
-
 //-------------------------------------------------------------------------
 // stream_user module
 //-------------------------------------------------------------------------
@@ -54,6 +54,9 @@ public:
 
     StreamUserConfig* get_data();
 
+    void set_trace(const snort::Trace*) const override;
+    const snort::TraceOption* get_trace_options() const override;
+
 private:
     StreamUserConfig* config;
 };
index 73094beb3e7f7450f3ac043ddee3aaae73a4de72..961f0892706463723da50f91575f2fe2363401d5 100644 (file)
@@ -26,6 +26,7 @@
 #include "detection/detection_engine.h"
 #include "detection/rules.h"
 #include "main/analyzer.h"
+#include "main/snort_debug.h"
 #include "memory/memory_cap.h"
 #include "profiler/profiler_defs.h"
 #include "protocols/packet.h"
index 251ceed8ed281d2a3f273729279f9f54d78c7ecb..f6a421728f40c243a2affc651538e795a33163e3 100644 (file)
@@ -25,7 +25,6 @@
 #include <iostream>
 
 #include "main/snort_config.h"
-#include "main/snort_debug.h"
 #include "target_based/snort_protocols.h"
 
 #include <CppUTest/CommandLineTestRunner.h>
index adbb81c21b4ce6fcf6e2c4599c8600eca408c113..da956f98a66df7500aa5e104a032e351dcb7edbe 100644 (file)
@@ -1,16 +1,32 @@
+set ( INCLUDES
+    trace.h
+    trace_api.h
+)
 
 set ( TRACE_SOURCES
+    trace.cc
+    trace_api.cc
     trace_config.cc
     trace_config.h
     trace_log.cc
     trace_log.h
-    trace_log_api.cc
-    trace_log_api.h
     trace_log_base.h
     trace_module.cc
     trace_module.h
+    ${INCLUDES}
 )
 
 add_library ( trace OBJECT
     ${TRACE_SOURCES}
 )
+
+install ( FILES ${INCLUDES}
+    DESTINATION "${INCLUDE_INSTALL_PATH}/trace"
+)
+
+add_catch_test( trace_test
+    NO_TEST_SOURCE
+    SOURCES
+        trace.cc
+)
+
index 962fdfa574011dc691e2783c01bd63604f3a3400..5e866f632149c5c921f88d1e8cdcaba85e486176 100644 (file)
@@ -20,46 +20,50 @@ This directory contains the trace logger framework.
 
 * TraceConfig
 
-    This is a class that handles a pointer to TraceLoggerFactory and used by TraceLogApi as
-    a global access point. Pointer to TraceConfig is placed into SnortConfig. It will be
-    overwritten during reloading and new TraceLoggerFactory pointer will be used by TraceLogApi
-    since that point.
+    This is a class that contains pointer on TraceLoggerFactory object and Trace list.
+    By default all Traces are off. TraceModule fills Traces from configuration.
 
     TraceConfig placed into "trace_config.h".
 
 * TraceModule
 
-    This module provides configuration for trace logs. The main goal of TraceModule
-    is to create a concrete logger factory based on the configuration, init/reload TraceConfig
-    pointer and move it into SnortConfig.
+    This module provides configuration for trace logs:
+        output - create a concrete logger factory based on the output value (stdout/syslog).
+        modules - set modules trace level verbosity.
 
     This is a built-in module (from coreinit.lua)
 
     The module placed into "trace_module.h/trace_module.cc".
 
-* TraceLogApi
+    TraceModule ctor should be called after all existed modules due to TraceModule
+        dynamic params restriction. 
 
-    TraceLogApi is a facade API class used to init/term trace logger framework and make logs
-    per each thread. TraceLogger is encapsulated in TraceLogApi. This, in a couple with
-    the TraceConfig, is a single common entry point to trace logger framework.
+* TraceApi
 
-    TraceLogApi placed into "trace_log_api.h/trace_log_api.cc"
+    TraceApi is a facade API class used to init/reinit/term thread-local trace logger and module's
+    trace pointers.
+
+    TraceApi placed into "trace_api.h/trace_api.cc"
+
+* Trace
+
+    This class encapsulates trace verbosity functionality.
 
 * Configuration override
 
     By default, the factory will be initialized based on Snort run mode (stdout or syslog).
-    But this can be explicitly overwritten in TraceModule's configuration to specify which
-    kind of logger to use.
+    But this can be explicitly overwritten in TraceModule's configuration to specify
+    which kind of logger to use.
 
     Changes will be applied in case of reloading too.
 
 * External dependencies
 
-    Include TraceLogApi header somewhere in the code where it needs to make trace logs.
-    Make sure that TraceLogApi::thread_init()/thread_term() are provided for thread where
-    TraceLogApi::log() is going used.
+    Include TraceApi header somewhere in the code where it needs to make trace logs.
+    Make sure that TraceApi::thread_init()/thread_term() are provided for thread where
+    TraceApi::log() is going used.
 
-    TraceConfig should be configured and moved into SnortConfig before TraceLogApi init.
+    TraceConfig should be configured in SnortConfig before TraceApi init.
 
     To create specific TraceLogger/TraceLoggerFactory pair just inherit base classes placed
     into "trace_log_base.h" and init TraceConfig with a new factory during configuration.
diff --git a/src/trace/trace.cc b/src/trace/trace.cc
new file mode 100644 (file)
index 0000000..d6ddf07
--- /dev/null
@@ -0,0 +1,167 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2020-2020 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation.  You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//--------------------------------------------------------------------------
+// trace.cc author Serhii Vlasiuk <svlasiuk@cisco.com>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "trace.h"
+
+#include "framework/module.h"
+
+using namespace snort;
+
+static const TraceOption s_default_trace_options[] =
+{
+    { DEFAULT_TRACE_OPTION_NAME, DEFAULT_TRACE_OPTION_ID, "default trace options" },
+
+    { nullptr, 0, nullptr }
+};
+
+Trace::Trace(const Module& m) : module(m)
+{
+    mod_name = module.get_name();
+    const snort::TraceOption* trace_options = module.get_trace_options();
+    options = ( trace_options->name ) ? trace_options : s_default_trace_options;
+    
+    size_t options_size = 0;
+    trace_options = options;
+    while ( trace_options->name )
+    {
+        ++options_size;
+        ++trace_options;
+    }
+    option_levels.resize(options_size, 0);
+}
+
+bool Trace::set(const std::string& trace_option_name, uint8_t trace_level)
+{
+    size_t size = option_levels.size();
+    for ( size_t index = 0; index < size; ++index )
+    {
+        if ( trace_option_name == option_name(index) )
+        {
+            option_levels[options[index].id] = trace_level;
+            return true;
+        }
+    }
+    return false;
+}
+
+void Trace::set_module_trace() const
+{
+    module.set_trace(this);
+}
+
+#ifdef CATCH_TEST_BUILD
+
+#include "catch/catch.hpp"
+
+Module::Module(const char* s, const char* h) : name(s), help(h)
+{}
+Module::Module(const char*, const char*, const Parameter*, bool)
+{}
+PegCount Module::get_global_count(char const*) const { return 0; }
+void Module::show_interval_stats(std::vector<unsigned int, std::allocator<unsigned int> >&, FILE*) {}
+void Module::show_stats(){}
+void Module::sum_stats(bool ){}
+void Module::reset_stats() {}
+
+class TraceTestModule : public Module
+{
+public:
+    TraceTestModule(const char* name, const TraceOption* trace_options) :
+        Module(name, "trace_test_help"), test_trace_options(trace_options)
+    { }
+
+    virtual const TraceOption* get_trace_options() const
+    { return test_trace_options; }
+
+private:
+    const TraceOption* test_trace_options;
+};
+
+TEST_CASE("default option", "[Trace]")
+{
+    TraceOption test_trace_options(nullptr, 0, nullptr);
+    TraceTestModule trace_test_module("test_trace_module", &test_trace_options);
+    Trace trace(trace_test_module);
+
+    bool result = trace.set(DEFAULT_TRACE_OPTION_NAME, DEFAULT_TRACE_LOG_LEVEL);
+    CHECK(result == true);
+    CHECK(trace.enabled(DEFAULT_TRACE_OPTION_ID));
+}
+
+TEST_CASE("multiple options", "[Trace]")
+{
+    enum
+    {
+        TEST_TRACE_OPTION1 = 0,
+        TEST_TRACE_OPTION2,
+        TEST_TRACE_OPTION3,
+        TEST_TRACE_OPTION4,
+    };
+    const TraceOption trace_values[] =
+    {
+        { "option1", TEST_TRACE_OPTION1, "help_option1" },
+        { "option2", TEST_TRACE_OPTION2, "help_option2" },
+        { "option3", TEST_TRACE_OPTION3, "help_option3" },
+        { "option4", TEST_TRACE_OPTION4, "help_option4" },
+
+        { nullptr, 0, nullptr },
+    };
+
+    TraceTestModule trace_test_module("test_trace_module", trace_values);
+    Trace trace(trace_test_module);
+
+    bool result = trace.set("option1", DEFAULT_TRACE_LOG_LEVEL);
+    CHECK(result == true);
+    CHECK(trace.enabled(TEST_TRACE_OPTION1));
+
+    result = trace.set("option2", DEFAULT_TRACE_LOG_LEVEL);
+    CHECK(result == true);
+    CHECK(trace.enabled(TEST_TRACE_OPTION1));
+    CHECK(trace.enabled(TEST_TRACE_OPTION2));
+
+    result = trace.set("option3", DEFAULT_TRACE_LOG_LEVEL);
+    CHECK(result == true);
+    CHECK(trace.enabled(TEST_TRACE_OPTION1));
+    CHECK(trace.enabled(TEST_TRACE_OPTION2));
+    CHECK(trace.enabled(TEST_TRACE_OPTION3));
+
+    result = trace.set("option4", DEFAULT_TRACE_LOG_LEVEL);
+    CHECK(result == true);
+    CHECK(trace.enabled(TEST_TRACE_OPTION1));
+    CHECK(trace.enabled(TEST_TRACE_OPTION2));
+    CHECK(trace.enabled(TEST_TRACE_OPTION3));
+    CHECK(trace.enabled(TEST_TRACE_OPTION4));
+}
+
+TEST_CASE("invalid option", "[Trace]")
+{
+    TraceOption test_trace_options(nullptr, 0, nullptr);
+    TraceTestModule trace_test_module("test_trace_module", &test_trace_options);
+    Trace trace(trace_test_module);
+
+    bool result = trace.set("invalid_option", DEFAULT_TRACE_LOG_LEVEL);
+    CHECK(result == false);
+}
+
+#endif
+
similarity index 54%
rename from src/main/trace.h
rename to src/trace/trace.h
index b8e5e4359a4a1060385edc2a9ea0df45f29ea93e..454d01d112f8ed2e2a2f8a538a00d6b3868aee1d 100644 (file)
 #define TRACE_H
 
 #include <cassert>
+#include <map>
 #include <vector>
 
-#include "framework/value.h"
-#include "main/snort_types.h"
+#include "main/thread.h"
 
-#define DEFAULT_TRACE_OPTION 0
-#define DEFAULT_LOG_LEVEL 1
+#define DEFAULT_TRACE_LOG_LEVEL 1
+#define DEFAULT_TRACE_OPTION_ID 0
+#define DEFAULT_TRACE_OPTION_NAME "all"
 
-typedef uint8_t TraceOption;
-typedef uint8_t TraceLevel;
+namespace snort
+{
+class Trace;
+}
 
+using TraceOptionID = uint8_t;
+using TraceLevel = uint8_t;
+using Traces = std::vector<snort::Trace>;
+using ConfigTraceOptions = std::map<std::string, bool>;
+using ModulesConfigTraceOptions = std::map<std::string, ConfigTraceOptions>;
 
-struct TraceOptionString
+namespace snort
 {
-    const char* alias;
-    TraceOption option;
-};
+class Module;
 
-namespace snort
+struct TraceOption
 {
-struct SO_PUBLIC Trace
+    TraceOption(const char* n, TraceOptionID tid, const char* h) :
+        name(n), id(tid), help(h) {}
+
+    const char* name;
+    TraceOptionID id;
+    const char* help;
+};
+
+class Trace
 {
-    Trace(const char*, const TraceOptionString*, size_t);
-    Trace(const char*);
-    ~Trace() = default;
+public:
+    Trace(const Module& m);
 
-    bool set(const snort::Value&);
-    void reset();
-    void enable();
+    bool set(const std::string& option_name, uint8_t option_level);
+    void set_module_trace() const;
 
     const char* module_name() const
-    { return mod_name; }
+    { return mod_name.c_str(); }
 
     const char* option_name(size_t index) const
     {
         assert(index < option_levels.size());
-        return options[index].alias;
+        return options[index].name;
     }
 
-    bool enabled(TraceOption trace_option, TraceLevel log_level = DEFAULT_LOG_LEVEL) const
+    bool enabled(TraceOptionID trace_option_id, TraceLevel log_level = DEFAULT_TRACE_LOG_LEVEL) const
     {
-        assert(trace_option < option_levels.size());
-        return option_levels[trace_option] >= log_level;
+        assert(trace_option_id < option_levels.size());
+        return option_levels[trace_option_id] >= log_level;
     }
 
-    const TraceOptionString* options;
+private:
+    std::string mod_name;
+    const TraceOption* options;
+    const Module& module;
     std::vector<TraceLevel> option_levels;
-    std::vector<bool> config_options;
-    const char* mod_name;
 };
 }
 
 #endif
+
similarity index 75%
rename from src/trace/trace_log_api.cc
rename to src/trace/trace_api.cc
index b3023c4b53039c4da6a10773c080d4f23a8b144e..40b6abb5edfdbc8ab473e7d790987699c6b42eff 100644 (file)
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
-// trace_log_api.cc author Oleksandr Serhiienko <oserhiie@cisco.com>
+// trace_api.cc author Oleksandr Serhiienko <oserhiie@cisco.com>
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include "trace_log_api.h"
+#include "trace_api.h"
 
 #include "main/snort_config.h"
 #include "main/thread.h"
@@ -33,22 +33,28 @@ using namespace snort;
 
 static THREAD_LOCAL TraceLogger* g_trace_logger = nullptr;
 
-void TraceLogApi::thread_init(SnortConfig* sc)
+void TraceApi::thread_init(SnortConfig* sc)
 {
-    if ( sc->trace_config and sc->trace_config->logger_factory )
+    if ( sc->trace_config->logger_factory )
         g_trace_logger = sc->trace_config->logger_factory->instantiate();
+
+    sc->trace_config->setup_module_trace();
 }
 
-void TraceLogApi::thread_term()
+void TraceApi::thread_term()
 {
     delete g_trace_logger;
     g_trace_logger = nullptr;
 }
 
-void TraceLogApi::log(const char* log_msg, const char* name,
+void TraceApi::thread_reinit(SnortConfig* sc)
+{
+    sc->trace_config->setup_module_trace();
+}
+
+void TraceApi::log(const char* log_msg, const char* name,
     uint8_t log_level, const char* trace_option)
 {
-    if ( g_trace_logger )
-        g_trace_logger->log(log_msg, name, log_level, trace_option);
+    g_trace_logger->log(log_msg, name, log_level, trace_option);
 }
 
similarity index 87%
rename from src/trace/trace_log_api.h
rename to src/trace/trace_api.h
index afde50873a5d0e81098353c8bae8cb3797a471ff..06268b8cc94fad5bdc6d7053d6702d632af2a627 100644 (file)
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
-// trace_log_api.h author Oleksandr Serhiienko <oserhiie@cisco.com>
+// trace_api.h author Oleksandr Serhiienko <oserhiie@cisco.com>
 
-#ifndef TRACE_LOG_API_H
-#define TRACE_LOG_API_H
+#ifndef TRACE_API_H
+#define TRACE_API_H
 
 #include <cstdint>
 
@@ -26,10 +26,11 @@ namespace snort
 {
 struct SnortConfig;
 
-class TraceLogApi
+class TraceApi
 {
 public:
     static void thread_init(SnortConfig* sc);
+    static void thread_reinit(SnortConfig* sc);
     static void thread_term();
 
     static void log(const char* log_msg, const char* name,
@@ -37,5 +38,5 @@ public:
 };
 }
 
-#endif // TRACE_LOG_API_H
+#endif // TRACE_API_H
 
index f280607f36c380708a07ebbe96ab42f057d5727b..46b35f542242cad0019a411acade52b13759d5a5 100644 (file)
 
 #include "trace_config.h"
 
+#include <cstring>
+
+#include "framework/module.h"
+#include "managers/module_manager.h"
+
 #include "trace_log_base.h"
 
-using namespace snort;
+TraceConfig::TraceConfig()
+{
+    auto modules = snort::ModuleManager::get_all_modules();
+    for ( auto* module : modules )
+    {
+        if ( module->get_trace_options() )
+            traces.emplace_back(*module);
+    }
+}
 
 TraceConfig::~TraceConfig()
-{ delete logger_factory; }
+{
+    delete logger_factory;
+    logger_factory = nullptr;
+}
+
+bool TraceConfig::set_trace(const std::string& module_name, const std::string& trace_option_name,
+    uint8_t trace_level)
+{
+    for ( auto& trace : traces )
+    {
+        if ( strcmp(trace.module_name(), module_name.c_str()) == 0 )
+            return trace.set(trace_option_name, trace_level);
+    }
+    return false;
+}
+
+void TraceConfig::setup_module_trace() const
+{
+    for ( const auto& trace : traces )
+        trace.set_module_trace();
+}
+
+void TraceConfig::enable_trace_snort()
+{ trace_snort_enabled = true; }
+
+void TraceConfig::merge_cmd_line(TraceConfig* trace_config)
+{
+    trace_snort_enabled = trace_config->trace_snort_enabled;
+    
+    if ( trace_snort_enabled )
+        set_trace("snort", DEFAULT_TRACE_OPTION_NAME, DEFAULT_TRACE_LOG_LEVEL);
+}
 
index ea8be458f613d90d815cc76f285df3194e101281..8142dd40035bd4da2ce13cf0d969f899eba1af10 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef TRACE_CONFIG_H
 #define TRACE_CONFIG_H
 
+#include "trace.h"
+
 namespace snort
 {
 class TraceLoggerFactory;
@@ -28,10 +30,20 @@ class TraceLoggerFactory;
 class TraceConfig
 {
 public:
-    TraceConfig() = default;
+    TraceConfig();
     ~TraceConfig();
 
+    void enable_trace_snort();
+    void setup_module_trace() const;
+    void merge_cmd_line(TraceConfig*);
+    bool set_trace(const std::string& module_name,
+        const std::string& trace_option_name, uint8_t trace_level);
+
     snort::TraceLoggerFactory* logger_factory = nullptr;
+
+private:
+    bool trace_snort_enabled = false;
+    Traces traces;
 };
 
 #endif // TRACE_CONFIG_H
index ef7c23e1b7cdf73afad1ea1a6442a2a96fca1b1e..a496bf408e699e1abcdae1316a25dc2a1e99f840 100644 (file)
 #include <syslog.h>
 
 #include "main/snort_config.h"
+#include "managers/module_manager.h"
 
 #include "trace_config.h"
 #include "trace_log.h"
 
 using namespace snort;
 
-static const Parameter trace_params[] =
+#define trace_help "configure trace log messages"
+#define s_name "trace"
+
+TraceModule::TraceModule() : Module(s_name, trace_help)
 {
-    { "output", Parameter::PT_ENUM, "stdout | syslog", nullptr,
-      "output method for trace log messages" },
+    generate_params();
+}
+
+void TraceModule::generate_params()
+{
+    auto modules = snort::ModuleManager::get_all_modules();
+    for ( const auto* module : modules )
+    {
+        const TraceOption* trace_options = module->get_trace_options();
+        if ( trace_options && strcmp(module->get_name(), "snort") != 0 )
+        {
+            auto& module_trace_options = configured_trace_options[module->get_name()];
+            std::string module_trace_help(module->get_name());
+            module_trace_help += " module trace options";
+            modules_help.emplace_back(module_trace_help);
 
-    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
-};
+            module_ranges.emplace_back();
+            auto& module_range = module_ranges.back();
 
-#define trace_help \
-    "configure trace log messages"
+            module_range.emplace_back(DEFAULT_TRACE_OPTION_NAME, Parameter::PT_INT, "0:255", nullptr,
+                "enable all trace options");
 
-TraceModule::TraceModule() : Module("trace", trace_help, trace_params, false)
-{ }
+            if ( !trace_options->name )
+                module_trace_options[DEFAULT_TRACE_OPTION_NAME] = false;
 
-TraceModule::~TraceModule()
-{
-    delete t_config;
+            while ( trace_options->name )
+            {
+                module_range.emplace_back(trace_options->name,
+                    Parameter::PT_INT, "0:255", nullptr, trace_options->help);
+
+                module_trace_options[trace_options->name] = false;
+                ++trace_options;
+            }
+
+            module_range.emplace_back(nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr);
+
+            modules_params.emplace_back(module->get_name(), Parameter::PT_TABLE, module_range.data(),
+                nullptr, modules_help.back().c_str());
+        }
+    }
+
+    modules_params.emplace_back(nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr);
+
+    const static Parameter trace_params[] =
+    {
+        { "modules", Parameter::PT_TABLE, modules_params.data(), nullptr, "modules trace option" },
+
+        { "output", Parameter::PT_ENUM, "stdout | syslog", nullptr,
+            "output method for trace log messages" },
+
+        { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
+    };
+
+    set_params(trace_params);
 }
 
 bool TraceModule::begin(const char* fqn, int, SnortConfig* sc)
 {
     if ( !strcmp(fqn, "trace") )
     {
-        assert(!t_config);
-        t_config = new TraceConfig();
-
         // Init default output type based on Snort run-mode
         if ( sc->test_mode() )
             log_output_type = OUTPUT_TYPE_NO_INIT;
@@ -65,12 +105,21 @@ bool TraceModule::begin(const char* fqn, int, SnortConfig* sc)
             log_output_type = OUTPUT_TYPE_SYSLOG;
         else
             log_output_type = OUTPUT_TYPE_STDOUT;
+
+        reset_configured_trace_options();
     }
 
     return true;
 }
 
-bool TraceModule::set(const char*, Value& v, SnortConfig* sc)
+void TraceModule::reset_configured_trace_options()
+{
+    for ( auto& module_trace_options : configured_trace_options )
+        for ( auto& trace_options : module_trace_options.second )
+            trace_options.second = false;
+}
+
+bool TraceModule::set(const char* fqn, Value& v, SnortConfig* sc)
 {
     if ( v.is("output") )
     {
@@ -91,6 +140,25 @@ bool TraceModule::set(const char*, Value& v, SnortConfig* sc)
 
         return true;
     }
+    else if ( strstr(fqn, "trace.modules.") == fqn )
+    {
+        std::string module_name = find_module(fqn);
+        if ( strcmp(v.get_name(), DEFAULT_TRACE_OPTION_NAME) == 0 )
+        {
+            const auto& trace_options = configured_trace_options[module_name];
+            for ( const auto& trace_option : trace_options )
+                if ( !trace_option.second )
+                    sc->trace_config->set_trace(module_name, trace_option.first, v.get_uint8());
+
+            return true;
+        }
+        else
+        {
+            bool res = sc->trace_config->set_trace(module_name, v.get_name(), v.get_uint8());
+            configured_trace_options[module_name][v.get_name()] = res;
+            return res;
+        }
+    }
 
     return false;
 }
@@ -102,21 +170,17 @@ bool TraceModule::end(const char* fqn, int, SnortConfig* sc)
         switch ( log_output_type )
         {
             case OUTPUT_TYPE_STDOUT:
-                t_config->logger_factory = new StdoutLoggerFactory();
+                sc->trace_config->logger_factory = new StdoutLoggerFactory();
                 break;
             case OUTPUT_TYPE_SYSLOG:
-                t_config->logger_factory = new SyslogLoggerFactory();
+                sc->trace_config->logger_factory = new SyslogLoggerFactory();
                 break;
             case OUTPUT_TYPE_NO_INIT:
-                t_config->logger_factory = nullptr;
+                sc->trace_config->logger_factory = nullptr;
+            default:
                 break;
         }
 
-        delete sc->trace_config;
-
-        sc->trace_config = t_config;
-        t_config = nullptr;
-
         // "output=syslog" config override case
         // do not closelog() here since it will be closed in Snort::clean_exit()
         if ( !sc->log_syslog() and log_output_type == OUTPUT_TYPE_SYSLOG
@@ -130,3 +194,19 @@ bool TraceModule::end(const char* fqn, int, SnortConfig* sc)
     return true;
 }
 
+std::string TraceModule::find_module(const char* fqn) const
+{
+    std::string module_name;
+    const std::string config_name(fqn);
+    const std::string pattern = "trace.modules.";
+    size_t start_pos = config_name.find(pattern);
+    if ( start_pos != std::string::npos )
+    {
+        start_pos += pattern.size();
+        size_t end_pos = config_name.find(".", start_pos);
+        if ( end_pos != std::string::npos )
+            module_name = config_name.substr(start_pos, end_pos - start_pos);
+    }
+    return module_name;
+}
+
index 0dca7da9be6bc944d3e8a32c152b5ea9cadaf15c..d99f57c2dc9e4924485d976c270f4f345a400bb5 100644 (file)
@@ -20,9 +20,9 @@
 #ifndef TRACE_MODULE_H
 #define TRACE_MODULE_H
 
-#include "framework/module.h"
+#include <map>
 
-class TraceConfig;
+#include "framework/module.h"
 
 class TraceModule : public snort::Module
 {
@@ -36,7 +36,6 @@ private:
 
 public:
     TraceModule();
-    ~TraceModule() override;
 
     bool begin(const char*, int, snort::SnortConfig*) override;
     bool set(const char*, snort::Value&, snort::SnortConfig*) override;
@@ -45,10 +44,19 @@ public:
     Usage get_usage() const override
     { return GLOBAL; }
 
+private:
+    std::string find_module(const char* config_name) const;
+    void generate_params();
+    void reset_configured_trace_options();
+
 private:
     OutputType log_output_type = OUTPUT_TYPE_NO_INIT;
-    TraceConfig* t_config = nullptr;
     bool local_syslog = false;
+    std::vector<snort::Parameter> modules_params;
+    std::vector<std::vector<snort::Parameter>> module_ranges;
+    std::vector<std::string> modules_help;
+    std::map<std::string, std::map<std::string, bool>> configured_trace_options;
+    
 };
 
 #endif  // TRACE_MODULE_H