* IT_PROBE - process all packets after all the above (e.g. perf_monitor,
port_scan)
+* IT_PASSIVE - for configuration only or data consuming
+
=== Codecs
determine verdict. (Conversely, builtin actions don't have an associated
plugin function.)
+
+=== Trace Loggers
+
+The Trace Loggers print trace messages. They can be implemented as inspector
+plugins.
+
+The first step is creating a custom logger by inheriting from the Snort
+TraceLogger class. The following is an example TraceLogger.
+
+ class FooLogger : public TraceLogger
+ {
+ public:
+ void log(const char*, const char*, uint8_t, const char*, const Packet*) override
+ { printf("%s%s\n", "Foo", "Bar"); }
+ };
+
+To instantiate logger objects it's needed to create a logger factory derived
+from the Snort TraceLoggerFactory class.
+
+ class FooFactory : public TraceLoggerFactory
+ {
+ public:
+ TraceLogger* instantiate() override
+ { return new FooLogger(); }
+ };
+
+Once the Factory is created, Inspector and appropriate Module are needed.
+*Inspector::configure()* must initialize the logger factory.
+
+ bool FooInspector::configure(SnortConfig* sc) override
+ {
+ return TraceApi::override_logger_factory(sc, new FooFactory());
+ }
+
+
=== Piglet Test Harness
In order to assist with plugin development, an experimental mode called "piglet" mode
set ( INCLUDES
trace.h
trace_api.h
+ trace_logger.h
)
set ( TRACE_SOURCES
trace_api.cc
trace_config.cc
trace_config.h
- trace_log.cc
- trace_log.h
- trace_log_base.h
+ trace_loggers.cc
+ trace_loggers.h
trace_module.cc
trace_module.h
trace_parser.cc
is created per each packet thread and one for the main thread. The logging configuration
happens in the module. The logger factory is used to init/cleanup loggers.
- Include "trace_log_base.h" to get TraceLogger base class.
- Derived loggers placed into "trace_log.h/trace_log.cc".
+ Include "trace_logger.h" to get TraceLogger base class.
+ Built-in loggers are defined in "trace_loggers.h/trace_loggers.cc".
* TraceLoggerFactory
thread. One factory instance exists which used to init/cleanup loggers and placed
into TraceConfig. The factory object instantiates in the module due to configuration.
- Include "trace_log_base.h" to get TraceLoggerFactory base class and template function
- to create particular objects. Derived factories placed into "trace_log.h/trace_log.cc".
+ Include "trace_logger.h" to get TraceLoggerFactory base class and template function
+ to create particular objects. Built-in factories are defined in "trace_loggers.h/trace_loggers.cc".
* TraceConfig
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.
+ into "trace_logger.h" and init TraceConfig with a new factory during configuration.
+
+* Extending the trace logger framework with TraceLogger plugins
+
+ It's possible to create a trace logger as an inspector plugin to handle a custom logic of trace
+ messages printing. The workflow here is to implement the custom logger and logger factory by
+ inheriting from the Snort TraceLogger and TraceLoggerFactory classes, put them into a separate
+ plugin, and call TraceApi::override_logger_factory() during the plugin configuration to
+ initialize the framework with the custom logger factory.
* Disabling packet constraints matching
#include "trace_api.h"
#include "framework/packet_constraints.h"
+#include "main/snort.h"
#include "main/snort_config.h"
#include "main/thread.h"
#include "protocols/packet.h"
#include "trace_config.h"
-#include "trace_log_base.h"
+#include "trace_logger.h"
using namespace snort;
trace_config->setup_module_trace();
}
+bool TraceApi::override_logger_factory(SnortConfig* sc, TraceLoggerFactory* factory)
+{
+ if ( !sc or !sc->trace_config or !factory )
+ return false;
+
+ delete sc->trace_config->logger_factory;
+ sc->trace_config->logger_factory = factory;
+
+ if ( !Snort::is_reloading() )
+ {
+ delete g_trace_logger;
+ g_trace_logger = sc->trace_config->logger_factory->instantiate();
+ }
+
+ return true;
+}
+
void TraceApi::log(const char* log_msg, const char* name,
uint8_t log_level, const char* trace_option, const Packet* p)
{
namespace snort
{
struct Packet;
+struct SnortConfig;
+
+class TraceLoggerFactory;
class SO_PUBLIC TraceApi
{
static void thread_reinit(const TraceConfig* tc);
static void thread_term();
+ // This method will change an ownership of the passed TraceLoggerFactory
+ // from the caller to the passed SnortConfig
+ static bool override_logger_factory(SnortConfig*, TraceLoggerFactory*);
+
static void log(const char* log_msg, const char* name,
uint8_t log_level, const char* trace_option, const Packet* p);
static void filter(const Packet& p);
#include "framework/packet_constraints.h"
#include "managers/module_manager.h"
-#include "trace_log_base.h"
+#include "trace_logger.h"
using namespace snort;
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-// trace_log_base.h author Oleksandr Serhiienko <oserhiie@cisco.com>
+// trace_logger.h author Oleksandr Serhiienko <oserhiie@cisco.com>
-#ifndef TRACE_LOG_BASE_H
-#define TRACE_LOG_BASE_H
+#ifndef TRACE_LOGGER_H
+#define TRACE_LOGGER_H
#include <cstdint>
};
}
-#endif // TRACE_LOG_BASE_H
+#endif // TRACE_LOGGER_H
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-// trace_log.cc author Oleksandr Serhiienko <oserhiie@cisco.com>
+// trace_loggers.cc author Oleksandr Serhiienko <oserhiie@cisco.com>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include "trace_log.h"
+#include "trace_loggers.h"
#include <cstdio>
#include <syslog.h>
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//--------------------------------------------------------------------------
-// trace_log.h author Oleksandr Serhiienko <oserhiie@cisco.com>
+// trace_loggers.h author Oleksandr Serhiienko <oserhiie@cisco.com>
-#ifndef TRACE_LOG_H
-#define TRACE_LOG_H
+#ifndef TRACE_LOGGERS_H
+#define TRACE_LOGGERS_H
-#include "trace_log_base.h"
+#include "trace_logger.h"
//-----------------------------------------------
// Logger factories
snort::TraceLogger* instantiate() override;
};
-#endif // TRACE_LOG_H
+#endif // TRACE_LOGGERS_H
#include "managers/module_manager.h"
#include "trace_config.h"
-#include "trace_log.h"
+#include "trace_loggers.h"
#include "trace_parser.h"
#include "trace_swap.h"