#include "framework/module.h"
#include "log/messages.h"
#include "main/snort_config.h"
-#include "main/snort_debug.h"
#include "packet_io/active.h"
#include "payload_injector/payload_injector.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "service_inspectors/http2_inspect/http2_flow_data.h"
+#include "trace/trace_api.h"
#include "utils/util.h"
#include "utils/util_cstring.h"
#include "detection/detection_engine.h"
#include "helpers/literal_search.h"
#include "ips_options/ips_vba_data.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
#include "utils/util.h"
#include "utils/util_utf.h"
#include <cassert>
-#include "main/snort_debug.h"
#include "packet_io/active.h"
+#include "trace/trace_api.h"
#include "utils/stats.h"
#include "detect_trace.h"
#include "latency/packet_latency.h"
#include "main/analyzer.h"
#include "main/snort_config.h"
-#include "main/snort_debug.h"
#include "main/thread.h"
#include "managers/inspector_manager.h"
#include "managers/mpse_manager.h"
#include "protocols/packet.h"
#include "stream/stream.h"
#include "time/packet_time.h"
+#include "trace/trace_api.h"
#include "utils/stats.h"
#include "context_switcher.h"
#include "detection/rule_option_types.h"
#include "time/clock_defs.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
namespace snort
{
#include "log/messages.h"
#include "main/snort.h"
#include "main/snort_config.h"
-#include "main/snort_debug.h"
#include "managers/action_manager.h"
#include "packet_io/active.h"
#include "packet_tracer/packet_tracer.h"
#include "protocols/udp.h"
#include "search_engines/pat_stats.h"
#include "stream/stream.h"
+#include "trace/trace_api.h"
#include "utils/stats.h"
#include "utils/util.h"
#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"
+#include "trace/trace_api.h"
#include "utils/cpp_macros.h"
#include "utils/util.h"
#include "managers/inspector_manager.h"
#include "packet_tracer/packet_tracer.h"
#include "protocols/packet.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
#include "file_cache.h"
#include "file_config.h"
#include "file_config.h"
#include "file_identifier.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
#include "utils/util.h"
//-------------------------------------------------------------------------
// file_id module
#include "hash/hash_defs.h"
#include "hash/zhash.h"
#include "helpers/flag_context.h"
-#include "main/snort_debug.h"
#include "memory/memory_cap.h"
#include "packet_io/active.h"
#include "packet_tracer/packet_tracer.h"
#include "stream/base/stream_module.h"
#include "time/packet_time.h"
+#include "trace/trace_api.h"
#include "utils/stats.h"
#include "flow.h"
#include "detection/detection_engine.h"
#include "main/policy.h"
#include "main/snort_config.h"
-#include "main/snort_debug.h"
#include "managers/inspector_manager.h"
#include "packet_io/active.h"
#include "packet_tracer/packet_tracer.h"
#include "flow/flow_cache.h"
#include "flow/ha.h"
#include "flow/session.h"
+#include "trace/trace_api.h"
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/TestHarness.h>
#include "detection/detection_engine.h"
#include "log/messages.h"
#include "main/snort_config.h"
-#include "main/snort_debug.h"
#include "protocols/packet.h"
+#include "trace/trace_api.h"
#include "utils/stats.h"
#include "latency_config.h"
#include "main/shell.h"
#include "main/snort.h"
#include "main/snort_config.h"
-#include "main/snort_debug.h"
#include "main/snort_module.h"
#include "main/swapper.h"
#include "main/thread_config.h"
reload_tuner.h
snort.h
snort_config.h
- snort_debug.h
snort_types.h
swapper.h
thread.h
snort.cc
snort.h
snort_config.cc
- snort_debug.cc
snort_module.h
snort_module.cc
swapper.cc
+++ /dev/null
-//--------------------------------------------------------------------------
-// Copyright (C) 2014-2022 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2002-2013 Sourcefire, Inc.
-// Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
-//
-// 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.
-//--------------------------------------------------------------------------
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "snort_debug.h"
-
-#include <cstring>
-
-#include "trace/trace_api.h"
-#include "utils/safec.h"
-
-#define BUF_SIZE_MIN (1 << 10) // guaranteed size, this one will be allocated on stack
-#define BUF_SIZE_MAX (1 << 20) // this prevents unlimited memory allocation
-
-namespace snort
-{
-template <void (log_func)(const char*, const char*, uint8_t, const char*, const Packet*)>
-void trace_vprintf(const char* name, TraceLevel log_level,
- const char* trace_option, const Packet* p, const char* fmt, va_list ap)
-{
- char buf[BUF_SIZE_MIN];
- int n;
-
- va_list dup_ap;
- va_copy(dup_ap, ap);
-
- n = vsnprintf(buf, sizeof(buf), fmt, ap);
-
- if (n < 0)
- {
- std::string err_msg = "trace_vprintf: printf error: ";
- err_msg += strerror(errno);
- err_msg += "\n";
- log_func(err_msg.c_str(), name, log_level, trace_option, p);
- }
- else if (n < (int)sizeof(buf))
- {
- log_func(buf, name, log_level, trace_option, p);
- }
- else if (n < BUF_SIZE_MAX)
- {
- char* d_buf = new char[n + 1];
-
- if (d_buf)
- {
- vsnprintf(d_buf, n + 1, fmt, dup_ap);
- log_func(d_buf, name, log_level, trace_option, p);
- }
- else
- log_func("trace_vprintf: out of memory\n", name, log_level, trace_option, p);
-
- delete[] d_buf;
- }
- else
- {
- n = BUF_SIZE_MAX;
- char* d_buf = new char[n];
-
- if (d_buf)
- {
- log_func("trace_vprintf: next message will be truncated\n", name, log_level, trace_option, p);
-
- vsnprintf(d_buf, n, fmt, dup_ap);
- d_buf[n - 2] = '\n';
- d_buf[n - 1] = '\0';
- log_func(d_buf, name, log_level, trace_option, p);
- }
- else
- log_func("trace_vprintf: out of memory\n", name, log_level, trace_option, p);
-
- delete[] d_buf;
- }
-
- va_end(dup_ap);
-}
-
-void trace_vprintf(const char* name, TraceLevel log_level,
- const char* trace_option, const Packet* p, const char* fmt, va_list ap)
-{
- trace_vprintf<TraceApi::log>(name, log_level, trace_option, p, fmt, ap);
-}
-}
-
-#ifdef UNIT_TEST
-#include <catch/snort_catch.h>
-
-#ifdef DEBUG_MSGS
-
-#include "framework/module.h"
-
-using namespace snort;
-
-//stringify the expansion of the macro
-#define sx(code) sm(code)
-
-//stringify the macro
-#define sm(code) #code
-
-struct TestCase
-{
- const char* test;
- const char* expected;
-};
-
-static char testing_dump[BUF_SIZE_MAX * 2];
-
-static void test_log(const char* log_msg, const char* name,
- uint8_t log_level, const char* trace_option, const snort::Packet*)
-{
- snprintf(testing_dump, sizeof(testing_dump), "%s:%s:%d: %s",
- name, trace_option, log_level, log_msg);
-}
-
-TEST_CASE("macros", "[trace]")
-{
- TestCase cases[] =
- {
- {
- sx(debug_log(1, test_trace, "my message")),
- "trace_print<snort::trace_vprintf>(1, test_trace, \"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, test_trace, "%s %s", "my", "message")),
- "trace_printf<snort::trace_vprintf>(1, test_trace, \"%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\")"
- }
- };
-
- CHECK( !strcmp(cases[0].expected, cases[0].test) );
- CHECK( !strcmp(cases[1].expected, cases[1].test) );
- CHECK( !strcmp(cases[2].expected, cases[2].test) );
- CHECK( !strcmp(cases[3].expected, cases[3].test) );
-}
-
-#undef trace_print
-#undef trace_printf
-
-//These templates expand to replace the default expansion of trace_vprintf.
-//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>>
-
-class TraceTestModule : public Module
-{
-public:
- TraceTestModule(const char* name, const TraceOption* trace_options) :
- Module(name, "trace_test_help"), test_trace_options(trace_options)
- { }
-
- const TraceOption* get_trace_options() const override
- { return test_trace_options; }
-
-private:
- const TraceOption* test_trace_options;
-};
-
-TEST_CASE("debug_log, debug_logf", "[trace]")
-{
- enum
- {
- TEST_TRACE_OPTION1 = 0,
- TEST_TRACE_OPTION2,
- TEST_TRACE_OPTION3,
- TEST_TRACE_OPTION4,
- TEST_TRACE_OPTION5,
- };
-
- const TraceOption test_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" },
- { "option5", TEST_TRACE_OPTION5, "help_option5" },
-
- { nullptr, 0, nullptr },
- };
-
- 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, nullptr, "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[BUF_SIZE_MIN + 1];
- for( int i = 0; i < BUF_SIZE_MIN; i++ )
- message[i] = 'A';
- message[BUF_SIZE_MIN] = '\0';
-
- testing_dump[0] = '\0';
- debug_log(6, &test_opt_trace, TEST_TRACE_OPTION3, nullptr, message);
- CHECK( (strlen(testing_dump) == 0) );
-
- testing_dump[0] = '\0';
- debug_log(&test_trace, nullptr, "my message");
- CHECK( !strcmp(testing_dump, "test_module:all:1: my message") );
-
- testing_dump[0] = '\0';
- debug_logf(&test_trace, nullptr, "%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, nullptr, "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, nullptr, "%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, nullptr, "log option2 message");
- CHECK( testing_dump[0] == '\0' );
-
- testing_dump[0] = '\0';
- debug_log(&test_opt_trace, TEST_TRACE_OPTION2, nullptr, "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, nullptr, "%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, nullptr, "log option3 message");
- CHECK( testing_dump[0] == '\0' );
-
- testing_dump[0] = '\0';
- debug_log(3, &test_opt_trace, TEST_TRACE_OPTION3, nullptr, "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, nullptr, "%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, nullptr, "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, nullptr, "%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, nullptr, "log option5 message");
- CHECK( testing_dump[0] == '\0' );
-}
-
-TEST_CASE("trace big message", "[trace]")
-{
- TraceOption test_trace_options(nullptr, 0, nullptr);
- TraceTestModule trace_test_module("test_module", &test_trace_options);
- Trace test_trace(trace_test_module);
-
- const int hdr_size = strlen("test_module:all:1: ");
- const char exp_1[] = "test_module:all:1: 1111111111111111111111111111";
- const char exp_2[] = "test_module:all:1: 2222222222222222222222222222";
- const char exp_3[] = "test_module:all:1: 3333333333333333333333333333";
- const char exp_4[] = "test_module:all:1: 4444444444444444444444444444";
-
-
- char msg_1[BUF_SIZE_MIN * 1];
- char msg_2[BUF_SIZE_MIN * 2];
- char msg_3[BUF_SIZE_MAX * 1];
- char msg_4[BUF_SIZE_MAX * 2];
-
- test_trace.set("all", 1);
-
- memset(msg_1, '1', sizeof(msg_1));
- memset(msg_2, '2', sizeof(msg_2));
- memset(msg_3, '3', sizeof(msg_3));
- memset(msg_4, '4', sizeof(msg_4));
-
- msg_1[sizeof(msg_1) - 1] = '\0';
- msg_2[sizeof(msg_2) - 1] = '\0';
- msg_3[sizeof(msg_3) - 1] = '\0';
- msg_4[sizeof(msg_4) - 1] = '\0';
-
- memset(testing_dump, '\0', sizeof(testing_dump));
- debug_log(&test_trace, nullptr, msg_1);
- CHECK( strlen(testing_dump) == hdr_size + strlen(msg_1) );
- CHECK( !strncmp(testing_dump, exp_1, strlen(exp_1)) );
-
- memset(testing_dump, '\0', sizeof(testing_dump));
- debug_log(&test_trace, nullptr, msg_2);
- CHECK( strlen(testing_dump) == hdr_size + strlen(msg_2) );
- CHECK( !strncmp(testing_dump, exp_2, strlen(exp_2)) );
-
- memset(testing_dump, '\0', sizeof(testing_dump));
- debug_log(&test_trace, nullptr, msg_3);
- CHECK( strlen(testing_dump) == hdr_size + strlen(msg_3) );
- CHECK( !strncmp(testing_dump, exp_3, strlen(exp_3)) );
-
- memset(testing_dump, '\0', sizeof(testing_dump));
- debug_log(&test_trace, nullptr, msg_4);
- CHECK( strlen(testing_dump) == hdr_size + BUF_SIZE_MAX - 1 );
- CHECK( !strncmp(testing_dump, exp_4, strlen(exp_4)) );
-}
-
-#endif // DEBUG_MSGS
-
-#endif // UNIT_TEST
+++ /dev/null
-//--------------------------------------------------------------------------
-// Copyright (C) 2014-2022 Cisco and/or its affiliates. All rights reserved.
-// Copyright (C) 2002-2013 Sourcefire, Inc.
-// Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
-//
-// 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.
-//--------------------------------------------------------------------------
-
-#ifndef SNORT_DEBUG_H
-#define SNORT_DEBUG_H
-
-// this provides a module trace capability that can be set by config to
-// turn on the output of specific debug messages.
-//
-
-#include <cstdarg>
-
-#include "protocols/packet.h"
-#include "trace/trace.h"
-#include "trace/trace_api.h"
-
-static inline bool trace_enabled(const snort::Trace* trace,
- TraceOptionID trace_option_id,
- TraceLevel log_level = DEFAULT_TRACE_LOG_LEVEL,
- const snort::Packet* p = nullptr)
-{
- if ( !trace or !trace->enabled(trace_option_id, log_level) )
- return false;
-
- if ( !p )
- return true;
-
- const auto gid = snort::TraceApi::get_constraints_generation();
- if ( !p->filtering_state.was_checked(gid) )
- snort::TraceApi::filter(*p);
-
- return p->filtering_state.matched;
-}
-
-namespace snort
-{
-SO_PUBLIC void trace_vprintf(const char* name, TraceLevel log_level,
- const char* trace_option, const snort::Packet* p, const char* fmt, va_list);
-}
-
-using trace_func = void(const char*, TraceLevel, const char*, const snort::Packet*, const char*, va_list);
-
-template <trace_func>
-static inline void trace_uprintf(const snort::Trace* trace,
- TraceOptionID trace_option_id, const snort::Packet* p, const char* fmt, ...) __attribute__((format (printf, 4, 5)));
-
-template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_uprintf(const snort::Trace* trace,
- TraceOptionID trace_option_id, const snort::Packet* p, const char* fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
-
- const char* trace_option_name = trace->option_name(trace_option_id);
- trace_vprintf(trace->module_name(), DEFAULT_TRACE_LOG_LEVEL, trace_option_name, p, fmt, ap);
-
- va_end(ap);
-}
-
-template <trace_func>
-static inline void trace_printf(TraceLevel log_level,
- const snort::Trace* trace, TraceOptionID trace_option_id,
- const snort::Packet* p, const char* fmt, ...)
- __attribute__((format (printf, 5, 6)));
-
-template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_printf(TraceLevel log_level,
- const snort::Trace* trace, TraceOptionID trace_option_id,
- const snort::Packet* p, const char* fmt, ...)
-{
- if ( !trace_enabled(trace, trace_option_id, log_level, p) )
- return;
-
- va_list ap;
- va_start(ap, fmt);
-
- const char* trace_option_name = trace->option_name(trace_option_id);
- trace_vprintf(trace->module_name(), log_level, trace_option_name, p,
- fmt, ap);
-
- va_end(ap);
-}
-
-template <trace_func>
-static inline void trace_printf(TraceLevel log_level,
- const snort::Trace* trace, const snort::Packet* p,
- 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, const snort::Packet* p,
- const char* fmt, ...)
-{
- if ( !trace_enabled(trace, DEFAULT_TRACE_OPTION_ID, log_level, p) )
- return;
-
- va_list ap;
- va_start(ap, fmt);
-
- const char* trace_option_name = trace->option_name(DEFAULT_TRACE_OPTION_ID);
- trace_vprintf(trace->module_name(), log_level, trace_option_name, p,
- fmt, ap);
-
- va_end(ap);
-}
-
-template <trace_func>
-static inline void trace_printf(const snort::Trace* trace,
- TraceOptionID trace_option_id, const snort::Packet* p,
- const char* fmt, ...) __attribute__((format (printf, 4, 5)));
-
-template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_printf(const snort::Trace* trace,
- TraceOptionID trace_option_id, const snort::Packet* p, const char* fmt, ...)
-{
- if ( !trace_enabled(trace, trace_option_id, DEFAULT_TRACE_LOG_LEVEL, p) )
- return;
-
- va_list ap;
- va_start(ap, fmt);
-
- const char* trace_option_name = trace->option_name(trace_option_id);
- trace_vprintf(trace->module_name(), DEFAULT_TRACE_LOG_LEVEL,
- trace_option_name, p, fmt, ap);
-
- va_end(ap);
-}
-
-template <trace_func>
-static inline void trace_printf(const snort::Trace* trace,
- const snort::Packet* p, 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,
- const snort::Packet* p, const char* fmt, ...)
-{
- if ( !trace_enabled(trace, DEFAULT_TRACE_OPTION_ID, DEFAULT_TRACE_LOG_LEVEL, p) )
- return;
-
- va_list ap;
- va_start(ap, fmt);
-
- const char* trace_option_name = trace->option_name(DEFAULT_TRACE_OPTION_ID);
- trace_vprintf(trace->module_name(), DEFAULT_TRACE_LOG_LEVEL,
- trace_option_name, p, 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, TraceOptionID trace_option_id,
- const snort::Packet* p, const char* msg)
-{
- trace_printf<trace_vprintf>(log_level, trace, trace_option_id, p,
- "%s", msg);
-}
-
-template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_print(const snort::Trace* trace,
- TraceOptionID trace_option_id, const snort::Packet* p, const char* msg)
-{
- trace_printf<trace_vprintf>(trace, trace_option_id, p, "%s", msg);
-}
-
-template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_print(TraceLevel log_level,
- const snort::Trace* trace, const snort::Packet* p, const char* msg)
-{
- trace_printf<trace_vprintf>(log_level, trace, p, "%s", msg);
-}
-
-template <trace_func trace_vprintf = snort::trace_vprintf>
-static inline void trace_print(const snort::Trace* trace, const snort::Packet* p,
- const char* msg)
-{
- trace_printf<trace_vprintf>(trace, p, "%s", msg);
-}
-
-#define trace_print trace_print<snort::trace_vprintf>
-#define trace_printf trace_printf<snort::trace_vprintf>
-#define trace_uprintf trace_uprintf<snort::trace_vprintf>
-
-#define trace_log(...) trace_print(__VA_ARGS__)
-#define trace_logf(...) trace_printf(__VA_ARGS__)
-#define trace_ulogf(...) trace_uprintf(__VA_ARGS__)
-
-#ifdef DEBUG_MSGS
-#define debug_log trace_log
-#define debug_logf trace_logf
-#else
-#define debug_log(...)
-#define debug_logf(...)
-#endif
-
-#endif
#include "framework/parameter.h"
#include "log/messages.h"
#include "main.h"
-#include "main/snort_debug.h"
#include "managers/codec_manager.h"
#include "packet_io/sfdaq_config.h"
#include "packet_io/trough.h"
#include "parser/parser.h"
#include "parser/parse_utils.h"
#include "parser/vars.h"
+#include "trace/trace_api.h"
#include "trace/trace_config.h"
#if defined(UNIT_TEST) || defined(BENCHMARK_TEST)
#include "main/shell.h"
#include "main/snort.h"
#include "main/snort_config.h"
-#include "main/snort_debug.h"
#include "main/snort_module.h"
#include "main/thread_config.h"
#include "protocols/packet.h"
#include "target_based/snort_protocols.h"
#include "time/clock_defs.h"
#include "time/stopwatch.h"
+#include "trace/trace_api.h"
#include "module_manager.h"
#include <cctype>
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
using namespace snort;
#include "detector_pattern.h"
#include "log/messages.h"
-#include "main/snort_debug.h"
#include "protocols/packet.h"
#include "search_engines/search_tool.h"
+#include "trace/trace_api.h"
#include "app_info_table.h"
#include "appid_inspector.h"
#include "host_tracker/cache_allocator.cc"
#include "host_tracker/host_cache.h"
#include "log/messages.h"
-#include "main/snort_debug.h"
#include "main/snort_types.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
+#include "trace/trace_api.h"
#include "app_info_table.h"
#include "appid_debug.h"
#include <dlfcn.h>
#include "log/messages.h"
-#include "main/snort_debug.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "stream/stream.h"
+#include "trace/trace_api.h"
#include "app_info_table.h"
#include "appid_config.h"
#include "appid_config.h"
-#include "main/snort_debug.h"
#include "log/messages.h"
+#include "trace/trace_api.h"
#include "tp_lib_handler.h"
#include "framework/module.h"
#include "main/reload_tuner.h"
-#include "main/snort_debug.h"
#include "profiler/profiler.h"
+#include "trace/trace_api.h"
#include "rna_config.h"
#include "rna_fingerprint.h"
#include "hash/hash_defs.h"
#include "hash/hash_key_operations.h"
#include "log/messages.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
#include "utils/util.h"
#include "utils/util_cstring.h"
#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"
#include "stream/stream.h"
+#include "trace/trace_api.h"
#include "eth.h"
#include "icmp4.h"
// Also provides common functions used by both versions
#include "file_api/file_api.h"
-#include "main/snort_debug.h"
#include "protocols/packet.h"
#include "profiler/profiler_defs.h"
+#include "trace/trace_api.h"
#include "dce_common.h"
#include "dce_smb_module.h"
#include "dce_smb_module.h"
#include "dce_smb_transaction_utils.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
using namespace snort;
#include "file_api/file_api.h"
#include "hash/hash_key_operations.h"
#include "main/snort.h"
-#include "main/snort_debug.h"
#include "network_inspectors/packet_tracer/packet_tracer.h"
#include "packet_io/active.h"
+#include "trace/trace_api.h"
#include "utils/util.h"
#include "dce_smb_module.h"
#include "dce_udp.h"
#include "flow/session.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
#include "utils/safec.h"
#include "utils/util.h"
#include "dce_smb_transaction.h"
#include "detection/detect.h"
#include "file_api/file_service.h"
-#include "main/snort_debug.h"
#include "memory/memory_cap.h"
#include "packet_io/active.h"
#include "protocols/packet.h"
+#include "trace/trace_api.h"
#include "utils/util.h"
using namespace snort;
#include "gtp.h"
-#include "main/snort_debug.h"
#include "protocols/packet.h"
+#include "trace/trace_api.h"
#include "gtp_inspect.h"
#include "gtp_module.h"
#include "detection/detection_engine.h"
#include "events/event_queue.h"
#include "log/messages.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
#include "utils/util_cstring.h"
#include "gtp.h"
#include "http_flow_data.h"
#include "decompress/file_decomp.h"
-#include "main/snort_debug.h"
#include "mime/file_mime_process.h"
#include "service_inspectors/http2_inspect/http2_flow_data.h"
+#include "trace/trace_api.h"
#include "utils/js_identifier_ctx.h"
#include "utils/js_normalizer.h"
#include "http_js_norm.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
#include "utils/js_normalizer.h"
#include "utils/safec.h"
#include "utils/util_jsnorm.h"
#include "detection/detection_engine.h"
#include "events/event_queue.h"
#include "log/messages.h"
-#include "main/snort_debug.h"
#include "protocols/packet.h"
+#include "trace/trace_api.h"
#include "iec104.h"
#include "iec104_module.h"
#include "detection/detection_engine.h"
#include "events/event_queue.h"
#include "log/messages.h"
-#include "main/snort_debug.h"
#include "managers/plugin_manager.h"
#include "protocols/packet.h"
+#include "trace/trace_api.h"
#include "utils/util_ber.h"
#include "mms.h"
#include <cassert>
#include "log/messages.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
#include "utils/util.h"
using namespace snort;
#include "detection/detection_engine.h"
#include "events/event_queue.h"
#include "log/messages.h"
-#include "main/snort_debug.h"
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/ssl.h"
#include "pub_sub/opportunistic_tls_event.h"
#include "stream/stream.h"
#include "stream/stream_splitter.h"
+#include "trace/trace_api.h"
#include "ssl_module.h"
#include "ssl_splitter.h"
#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"
+#include "trace/trace_api.h"
#include "curses.h"
#include "magic.h"
#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"
#include "profiler/profiler_defs.h"
#include "protocols/ipv4_options.h"
#include "time/timersub.h"
+#include "trace/trace_api.h"
#include "utils/safec.h"
#include "utils/stats.h"
#include "utils/util.h"
#include "flow/prune_stats.h"
#include "main/snort.h"
#include "main/snort_config.h"
-#include "main/snort_debug.h"
#include "network_inspectors/packet_tracer/packet_tracer.h"
#include "packet_io/active.h"
#include "protocols/vlan.h"
#include "stream/base/stream_module.h"
#include "target_based/host_attributes.h"
#include "target_based/snort_protocols.h"
+#include "trace/trace_api.h"
#include "utils/util.h"
#include "tcp/tcp_session.h"
#include "tcp_trace.h"
-#include "main/snort_debug.h"
+#include "trace/trace_api.h"
#include "utils/stats.h"
#include "tcp_module.h"
#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"
+#include "trace/trace_api.h"
#include "utils/util.h"
#include "stream_user.h"
#include "trace_api.h"
+#include <cstring>
+
#include "framework/packet_constraints.h"
#include "main/snort.h"
#include "main/snort_config.h"
#include "main/thread.h"
#include "protocols/packet.h"
+#include "utils/safec.h"
#include "trace_config.h"
#include "trace_logger.h"
return g_constraints_generation;
}
+#define BUF_SIZE_MIN (1 << 10) // guaranteed size, this one will be allocated on stack
+#define BUF_SIZE_MAX (1 << 20) // this prevents unlimited memory allocation
+
+namespace snort
+{
+template <void (log_func)(const char*, const char*, uint8_t, const char*, const Packet*)>
+void trace_vprintf(const char* name, TraceLevel log_level,
+ const char* trace_option, const Packet* p, const char* fmt, va_list ap)
+{
+ char buf[BUF_SIZE_MIN];
+ int n;
+
+ va_list dup_ap;
+ va_copy(dup_ap, ap);
+
+ n = vsnprintf(buf, sizeof(buf), fmt, ap);
+
+ if (n < 0)
+ {
+ std::string err_msg = "trace_vprintf: printf error: ";
+ err_msg += strerror(errno);
+ err_msg += "\n";
+ log_func(err_msg.c_str(), name, log_level, trace_option, p);
+ }
+ else if (n < (int)sizeof(buf))
+ {
+ log_func(buf, name, log_level, trace_option, p);
+ }
+ else if (n < BUF_SIZE_MAX)
+ {
+ char* d_buf = new char[n + 1];
+
+ if (d_buf)
+ {
+ vsnprintf(d_buf, n + 1, fmt, dup_ap);
+ log_func(d_buf, name, log_level, trace_option, p);
+ }
+ else
+ log_func("trace_vprintf: out of memory\n", name, log_level, trace_option, p);
+
+ delete[] d_buf;
+ }
+ else
+ {
+ n = BUF_SIZE_MAX;
+ char* d_buf = new char[n];
+
+ if (d_buf)
+ {
+ log_func("trace_vprintf: next message will be truncated\n", name, log_level, trace_option, p);
+
+ vsnprintf(d_buf, n, fmt, dup_ap);
+ d_buf[n - 2] = '\n';
+ d_buf[n - 1] = '\0';
+ log_func(d_buf, name, log_level, trace_option, p);
+ }
+ else
+ log_func("trace_vprintf: out of memory\n", name, log_level, trace_option, p);
+
+ delete[] d_buf;
+ }
+
+ va_end(dup_ap);
+}
+
+void trace_vprintf(const char* name, TraceLevel log_level,
+ const char* trace_option, const Packet* p, const char* fmt, va_list ap)
+{
+ trace_vprintf<TraceApi::log>(name, log_level, trace_option, p, fmt, ap);
+}
+}
+
+#ifdef UNIT_TEST
+#include <catch/snort_catch.h>
+
+#ifdef DEBUG_MSGS
+
+#include "framework/module.h"
+
+using namespace snort;
+
+//stringify the expansion of the macro
+#define sx(code) sm(code)
+
+//stringify the macro
+#define sm(code) #code
+
+struct TestCase
+{
+ const char* test;
+ const char* expected;
+};
+
+static char testing_dump[BUF_SIZE_MAX * 2];
+
+static void test_log(const char* log_msg, const char* name,
+ uint8_t log_level, const char* trace_option, const snort::Packet*)
+{
+ snprintf(testing_dump, sizeof(testing_dump), "%s:%s:%d: %s",
+ name, trace_option, log_level, log_msg);
+}
+
+TEST_CASE("macros", "[trace]")
+{
+ TestCase cases[] =
+ {
+ {
+ sx(debug_log(1, test_trace, "my message")),
+ "trace_print<snort::trace_vprintf>(1, test_trace, \"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, test_trace, "%s %s", "my", "message")),
+ "trace_printf<snort::trace_vprintf>(1, test_trace, \"%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\")"
+ }
+ };
+
+ CHECK( !strcmp(cases[0].expected, cases[0].test) );
+ CHECK( !strcmp(cases[1].expected, cases[1].test) );
+ CHECK( !strcmp(cases[2].expected, cases[2].test) );
+ CHECK( !strcmp(cases[3].expected, cases[3].test) );
+}
+
+#undef trace_print
+#undef trace_printf
+
+//These templates expand to replace the default expansion of trace_vprintf.
+//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>>
+
+class TraceTestModule : public Module
+{
+public:
+ TraceTestModule(const char* name, const TraceOption* trace_options) :
+ Module(name, "trace_test_help"), test_trace_options(trace_options)
+ { }
+
+ const TraceOption* get_trace_options() const override
+ { return test_trace_options; }
+
+private:
+ const TraceOption* test_trace_options;
+};
+
+TEST_CASE("debug_log, debug_logf", "[trace]")
+{
+ enum
+ {
+ TEST_TRACE_OPTION1 = 0,
+ TEST_TRACE_OPTION2,
+ TEST_TRACE_OPTION3,
+ TEST_TRACE_OPTION4,
+ TEST_TRACE_OPTION5,
+ };
+
+ const TraceOption test_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" },
+ { "option5", TEST_TRACE_OPTION5, "help_option5" },
+
+ { nullptr, 0, nullptr },
+ };
+
+ 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, nullptr, "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[BUF_SIZE_MIN + 1];
+ for( int i = 0; i < BUF_SIZE_MIN; i++ )
+ message[i] = 'A';
+ message[BUF_SIZE_MIN] = '\0';
+
+ testing_dump[0] = '\0';
+ debug_log(6, &test_opt_trace, TEST_TRACE_OPTION3, nullptr, message);
+ CHECK( (strlen(testing_dump) == 0) );
+
+ testing_dump[0] = '\0';
+ debug_log(&test_trace, nullptr, "my message");
+ CHECK( !strcmp(testing_dump, "test_module:all:1: my message") );
+
+ testing_dump[0] = '\0';
+ debug_logf(&test_trace, nullptr, "%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, nullptr, "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, nullptr, "%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, nullptr, "log option2 message");
+ CHECK( testing_dump[0] == '\0' );
+
+ testing_dump[0] = '\0';
+ debug_log(&test_opt_trace, TEST_TRACE_OPTION2, nullptr, "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, nullptr, "%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, nullptr, "log option3 message");
+ CHECK( testing_dump[0] == '\0' );
+
+ testing_dump[0] = '\0';
+ debug_log(3, &test_opt_trace, TEST_TRACE_OPTION3, nullptr, "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, nullptr, "%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, nullptr, "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, nullptr, "%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, nullptr, "log option5 message");
+ CHECK( testing_dump[0] == '\0' );
+}
+
+TEST_CASE("trace big message", "[trace]")
+{
+ TraceOption test_trace_options(nullptr, 0, nullptr);
+ TraceTestModule trace_test_module("test_module", &test_trace_options);
+ Trace test_trace(trace_test_module);
+
+ const int hdr_size = strlen("test_module:all:1: ");
+ const char exp_1[] = "test_module:all:1: 1111111111111111111111111111";
+ const char exp_2[] = "test_module:all:1: 2222222222222222222222222222";
+ const char exp_3[] = "test_module:all:1: 3333333333333333333333333333";
+ const char exp_4[] = "test_module:all:1: 4444444444444444444444444444";
+
+
+ char msg_1[BUF_SIZE_MIN * 1];
+ char msg_2[BUF_SIZE_MIN * 2];
+ char msg_3[BUF_SIZE_MAX * 1];
+ char msg_4[BUF_SIZE_MAX * 2];
+
+ test_trace.set("all", 1);
+
+ memset(msg_1, '1', sizeof(msg_1));
+ memset(msg_2, '2', sizeof(msg_2));
+ memset(msg_3, '3', sizeof(msg_3));
+ memset(msg_4, '4', sizeof(msg_4));
+
+ msg_1[sizeof(msg_1) - 1] = '\0';
+ msg_2[sizeof(msg_2) - 1] = '\0';
+ msg_3[sizeof(msg_3) - 1] = '\0';
+ msg_4[sizeof(msg_4) - 1] = '\0';
+
+ memset(testing_dump, '\0', sizeof(testing_dump));
+ debug_log(&test_trace, nullptr, msg_1);
+ CHECK( strlen(testing_dump) == hdr_size + strlen(msg_1) );
+ CHECK( !strncmp(testing_dump, exp_1, strlen(exp_1)) );
+
+ memset(testing_dump, '\0', sizeof(testing_dump));
+ debug_log(&test_trace, nullptr, msg_2);
+ CHECK( strlen(testing_dump) == hdr_size + strlen(msg_2) );
+ CHECK( !strncmp(testing_dump, exp_2, strlen(exp_2)) );
+
+ memset(testing_dump, '\0', sizeof(testing_dump));
+ debug_log(&test_trace, nullptr, msg_3);
+ CHECK( strlen(testing_dump) == hdr_size + strlen(msg_3) );
+ CHECK( !strncmp(testing_dump, exp_3, strlen(exp_3)) );
+
+ memset(testing_dump, '\0', sizeof(testing_dump));
+ debug_log(&test_trace, nullptr, msg_4);
+ CHECK( strlen(testing_dump) == hdr_size + BUF_SIZE_MAX - 1 );
+ CHECK( !strncmp(testing_dump, exp_4, strlen(exp_4)) );
+}
+
+#endif // DEBUG_MSGS
+
+#endif // UNIT_TEST
#ifndef TRACE_API_H
#define TRACE_API_H
+#include <cstdarg>
#include <cstdint>
#include "main/snort_types.h"
+#include "protocols/packet.h"
+#include "trace.h"
class TraceConfig;
};
}
+static inline bool trace_enabled(const snort::Trace* trace,
+ TraceOptionID trace_option_id,
+ TraceLevel log_level = DEFAULT_TRACE_LOG_LEVEL,
+ const snort::Packet* p = nullptr)
+{
+ if ( !trace or !trace->enabled(trace_option_id, log_level) )
+ return false;
+
+ if ( !p )
+ return true;
+
+ const auto gid = snort::TraceApi::get_constraints_generation();
+ if ( !p->filtering_state.was_checked(gid) )
+ snort::TraceApi::filter(*p);
+
+ return p->filtering_state.matched;
+}
+
+namespace snort
+{
+SO_PUBLIC void trace_vprintf(const char* name, TraceLevel log_level,
+ const char* trace_option, const snort::Packet* p, const char* fmt, va_list);
+}
+
+using trace_func = void(const char*, TraceLevel, const char*, const snort::Packet*, const char*, va_list);
+
+template <trace_func>
+static inline void trace_uprintf(const snort::Trace* trace,
+ TraceOptionID trace_option_id, const snort::Packet* p, const char* fmt, ...) __attribute__((format (printf, 4, 5)));
+
+template <trace_func trace_vprintf = snort::trace_vprintf>
+static inline void trace_uprintf(const snort::Trace* trace,
+ TraceOptionID trace_option_id, const snort::Packet* p, const char* fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+
+ const char* trace_option_name = trace->option_name(trace_option_id);
+ trace_vprintf(trace->module_name(), DEFAULT_TRACE_LOG_LEVEL, trace_option_name, p, fmt, ap);
+
+ va_end(ap);
+}
+
+template <trace_func>
+static inline void trace_printf(TraceLevel log_level,
+ const snort::Trace* trace, TraceOptionID trace_option_id,
+ const snort::Packet* p, const char* fmt, ...)
+ __attribute__((format (printf, 5, 6)));
+
+template <trace_func trace_vprintf = snort::trace_vprintf>
+static inline void trace_printf(TraceLevel log_level,
+ const snort::Trace* trace, TraceOptionID trace_option_id,
+ const snort::Packet* p, const char* fmt, ...)
+{
+ if ( !trace_enabled(trace, trace_option_id, log_level, p) )
+ return;
+
+ va_list ap;
+ va_start(ap, fmt);
+
+ const char* trace_option_name = trace->option_name(trace_option_id);
+ trace_vprintf(trace->module_name(), log_level, trace_option_name, p,
+ fmt, ap);
+
+ va_end(ap);
+}
+
+template <trace_func>
+static inline void trace_printf(TraceLevel log_level,
+ const snort::Trace* trace, const snort::Packet* p,
+ 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, const snort::Packet* p,
+ const char* fmt, ...)
+{
+ if ( !trace_enabled(trace, DEFAULT_TRACE_OPTION_ID, log_level, p) )
+ return;
+
+ va_list ap;
+ va_start(ap, fmt);
+
+ const char* trace_option_name = trace->option_name(DEFAULT_TRACE_OPTION_ID);
+ trace_vprintf(trace->module_name(), log_level, trace_option_name, p,
+ fmt, ap);
+
+ va_end(ap);
+}
+
+template <trace_func>
+static inline void trace_printf(const snort::Trace* trace,
+ TraceOptionID trace_option_id, const snort::Packet* p,
+ const char* fmt, ...) __attribute__((format (printf, 4, 5)));
+
+template <trace_func trace_vprintf = snort::trace_vprintf>
+static inline void trace_printf(const snort::Trace* trace,
+ TraceOptionID trace_option_id, const snort::Packet* p, const char* fmt, ...)
+{
+ if ( !trace_enabled(trace, trace_option_id, DEFAULT_TRACE_LOG_LEVEL, p) )
+ return;
+
+ va_list ap;
+ va_start(ap, fmt);
+
+ const char* trace_option_name = trace->option_name(trace_option_id);
+ trace_vprintf(trace->module_name(), DEFAULT_TRACE_LOG_LEVEL,
+ trace_option_name, p, fmt, ap);
+
+ va_end(ap);
+}
+
+template <trace_func>
+static inline void trace_printf(const snort::Trace* trace,
+ const snort::Packet* p, 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,
+ const snort::Packet* p, const char* fmt, ...)
+{
+ if ( !trace_enabled(trace, DEFAULT_TRACE_OPTION_ID, DEFAULT_TRACE_LOG_LEVEL, p) )
+ return;
+
+ va_list ap;
+ va_start(ap, fmt);
+
+ const char* trace_option_name = trace->option_name(DEFAULT_TRACE_OPTION_ID);
+ trace_vprintf(trace->module_name(), DEFAULT_TRACE_LOG_LEVEL,
+ trace_option_name, p, 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, TraceOptionID trace_option_id,
+ const snort::Packet* p, const char* msg)
+{
+ trace_printf<trace_vprintf>(log_level, trace, trace_option_id, p,
+ "%s", msg);
+}
+
+template <trace_func trace_vprintf = snort::trace_vprintf>
+static inline void trace_print(const snort::Trace* trace,
+ TraceOptionID trace_option_id, const snort::Packet* p, const char* msg)
+{
+ trace_printf<trace_vprintf>(trace, trace_option_id, p, "%s", msg);
+}
+
+template <trace_func trace_vprintf = snort::trace_vprintf>
+static inline void trace_print(TraceLevel log_level,
+ const snort::Trace* trace, const snort::Packet* p, const char* msg)
+{
+ trace_printf<trace_vprintf>(log_level, trace, p, "%s", msg);
+}
+
+template <trace_func trace_vprintf = snort::trace_vprintf>
+static inline void trace_print(const snort::Trace* trace, const snort::Packet* p,
+ const char* msg)
+{
+ trace_printf<trace_vprintf>(trace, p, "%s", msg);
+}
+
+#define trace_print trace_print<snort::trace_vprintf>
+#define trace_printf trace_printf<snort::trace_vprintf>
+#define trace_uprintf trace_uprintf<snort::trace_vprintf>
+
+#define trace_log(...) trace_print(__VA_ARGS__)
+#define trace_logf(...) trace_printf(__VA_ARGS__)
+#define trace_ulogf(...) trace_uprintf(__VA_ARGS__)
+
+#ifdef DEBUG_MSGS
+#define debug_log trace_log
+#define debug_logf trace_logf
+#else
+#define debug_log(...)
+#define debug_logf(...)
+#endif
+
#endif // TRACE_API_H
#include <vector>
#include "log/messages.h"
-#include "main/snort_debug.h"
#include "service_inspectors/http_inspect/http_enum.h"
+#include "trace/trace_api.h"
extern THREAD_LOCAL const snort::Trace* http_trace;