116
-- fixed valgrind leak
--- observed memory corruption on Linux when loading dynamic plugins (not
-fixed)
+-- observed memory corruption on Linux when loading dynamic plugins
+ (not fixed)
-- fixed action leak
-- testing visibility=hidden
-- more FIXITs
-- fp related FIXITs
+-- deleted profile.rules.file and profile.modules.file
+-- deleted alerts.alert_file
+-- changed --help to just cmd line options and added --help!
115
-- remove share.h
#include "framework/parameter.h"
static const char* snort_help =
+"\n"
"Snort has several options to get more help:\n"
"\n"
-"--help this overview of help\n"
+"--help list command line options\n"
+"--help! this overview of help\n"
"--help-builtin [<module prefix>] output matching builtin rules\n"
"--help-buffers output available inspection buffers\n"
"--help-commands [<module prefix>] output matching commands\n"
"\n"
"--help* and --list* options preempt other processing so should be last on the\n"
"command line since any following options are ignored. To ensure options like\n"
-"--plugin-path take effect, place them ahead of the help or list options.\n"
+"--markup and --plugin-path take effect, place them ahead of the help or list\n"
+"options.\n"
"\n"
"Options that filter output based on a matching prefix, such as --help-config\n"
"won't output anything if there is no match. If no prefix is given, everything\n"
" The name does not appear in the rule.\n"
"+ IPS rules may also have a wild card parameter, which is indicated by a *.\n"
" Only used for metadata that Snort ignores.\n"
+"+ The snort module has command line options starting with a -.\n"
;
//-------------------------------------------------------------------------
void help_basic(SnortConfig*, const char*)
{
- fprintf(stdout, "Snort help: %s", snort_help);
+ fprintf(stdout, "%s\n", snort_help);
exit(0);
}
void help_usage(SnortConfig*, const char* val)
{
- fprintf(stdout, "USAGE: %s [-options] <filter options>\n", "snort");
+ fprintf(stdout, "USAGE: %s [-options]\n", "snort");
help_args(val);
exit(1);
}
//-------------------------------------------------------------------------
#ifdef PERF_PROFILING
-static const Parameter profile_file_params[] =
-{
- { "name", Parameter::PT_STRING, "128", nullptr,
- "output to file instead of log" },
-
- { "append", Parameter::PT_BOOL, nullptr, "false",
- "append or overwrite" },
-
- { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
-};
-
static const Parameter profile_rule_params[] =
{
{ "count", Parameter::PT_INT, "-1:", "-1",
"avg_ticks_per_match | avg_ticks_per_no_match",
"avg_ticks", "sort by given field" },
- { "file", Parameter::PT_TABLE, profile_file_params, nullptr,
- "file config" },
-
{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
};
"checks | avg_ticks | total_ticks", "avg_ticks",
"sort by given field" },
- { "file", Parameter::PT_TABLE, profile_file_params, nullptr,
- "file config" },
-
{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
};
else if ( v.is("sort") )
p->sort = v.get_long() + 1;
- else if ( v.is("append") )
- p->append = v.get_long() + 1;
-
- else if ( v.is("name") )
- p->filename = SnortStrdup(v.get_string()); // FIXIT-L use c++ string
- // FIXIT-M do this after log dir is set
- //p->filename = ProcessFileOption(sc, v.get_string());
-
else
return false;
static const Parameter alerts_params[] =
{
- { "alert_file", Parameter::PT_STRING, nullptr, nullptr,
- "set the alert output file name" }, // FIXIT-H delete if not used
-
// FIXIT-L move to fast, full, syslog and delete from here
{ "alert_with_interface_name", Parameter::PT_BOOL, nullptr, "false",
"include interface in alert info (fast, full, or syslog only)" },
bool AlertsModule::set(const char*, Value& v, SnortConfig* sc)
{
- if ( v.is("alert_file") )
- sc->alert_file = SnortStrdup(v.get_string());
-
- else if ( v.is("alert_with_interface_name") )
+ if ( v.is("alert_with_interface_name") )
sc->output_flags |= OUTPUT_FLAG__ALERT_IFACE;
else if ( v.is("default_rule_state") )
else
asn1_init_mem(256);
- if (snort_conf->alert_file != NULL)
- {
- char *tmp = snort_conf->alert_file;
- snort_conf->alert_file = ProcessFileOption(snort_conf, snort_conf->alert_file);
- free(tmp);
- }
-
-#ifdef PERF_PROFILING
- /* Parse profiling here because of file option and potential
- * dependence on log directory */
- ConfigProfiling(snort_conf);
-#endif
-
if (ScAlertBeforePass())
{
OrderRuleLists(snort_conf, "activation dynamic drop sdrop reject alert pass log");
sc = MergeSnortConfs(snort_cmd_line_conf, sc);
init_policy(sc);
-#ifdef PERF_PROFILING
- /* Parse profiling here because of file option and potential
- * dependence on log directory */
- ConfigProfiling(sc);
-#endif
-
if (VerifyReload(sc) == -1)
{
SnortConfFree(sc);
if (sc->chroot_dir != NULL)
free(sc->chroot_dir);
- if (sc->alert_file != NULL)
- free(sc->alert_file);
-
if (sc->bpf_filter != NULL)
free(sc->bpf_filter);
if (sc->event_trace_file != NULL)
free(sc->event_trace_file);
-#ifdef PERF_PROFILING
- if (sc->profile_rules.filename != NULL)
- free(sc->profile_rules.filename);
-
- if (sc->profile_preprocs.filename != NULL)
- free(sc->profile_preprocs.filename);
-#endif
-
FreeRuleStateList(sc->rule_state_list);
FreeClassifications(sc->classifications);
FreeReferences(sc->references);
free(sc);
}
-SnortConfig * MergeSnortConfs(SnortConfig *cmd_line, SnortConfig *config_file)
+SnortConfig* MergeSnortConfs(SnortConfig *cmd_line, SnortConfig *config_file)
{
/* Move everything from the command line config over to the
* config_file config */
if (config_file == NULL)
return cmd_line;
+ config_file->run_prefix = cmd_line->run_prefix;
+ cmd_line->run_prefix = nullptr;
+
+ config_file->id_subdir = cmd_line->id_subdir;
+ config_file->id_zero = cmd_line->id_zero;
+
/* Used because of a potential chroot */
config_file->orig_log_dir = SnortStrdup(config_file->log_dir);
if (sc == NULL)
return -1;
- if ((snort_conf->alert_file != NULL) && (sc->alert_file != NULL))
- {
- if (strcasecmp(snort_conf->alert_file, sc->alert_file) != 0)
- {
- ErrorMessage("Snort Reload: Changing the alert file "
- "configuration requires a restart.\n");
- return -1;
- }
- }
- else if (snort_conf->alert_file != sc->alert_file)
- {
- ErrorMessage("Snort Reload: Changing the alert file "
- "configuration requires a restart.\n");
- return -1;
- }
-
if (snort_conf->asn1_mem != sc->asn1_mem)
{
ErrorMessage("Snort Reload: Changing the asn1 memory configuration "
}
#endif
-#ifdef PERF_PROFILING
- if ((snort_conf->profile_rules.num != sc->profile_rules.num) ||
- (snort_conf->profile_rules.sort != sc->profile_rules.sort) ||
- (snort_conf->profile_rules.append != sc->profile_rules.append))
- {
- ErrorMessage("Snort Reload: Changing rule profiling number, sort "
- "or append configuration requires a restart.\n");
- return -1;
- }
-
- if ((snort_conf->profile_rules.filename != NULL) &&
- (sc->profile_rules.filename != NULL))
- {
- if (strcasecmp(snort_conf->profile_rules.filename,
- sc->profile_rules.filename) != 0)
- {
- ErrorMessage("Snort Reload: Changing the rule profiling filename "
- "configuration requires a restart.\n");
- return -1;
- }
- }
- else if (snort_conf->profile_rules.filename !=
- sc->profile_rules.filename)
- {
- ErrorMessage("Snort Reload: Changing the rule profiling filename "
- "configuration requires a restart.\n");
- return -1;
- }
-
- if ((snort_conf->profile_preprocs.num != sc->profile_preprocs.num) ||
- (snort_conf->profile_preprocs.sort != sc->profile_preprocs.sort) ||
- (snort_conf->profile_preprocs.append != sc->profile_preprocs.append))
- {
- ErrorMessage("Snort Reload: Changing preprocessor profiling number, "
- "sort or append configuration requires a restart.\n");
- return -1;
- }
-
- if ((snort_conf->profile_preprocs.filename != NULL) &&
- (sc->profile_preprocs.filename != NULL))
- {
- if (strcasecmp(snort_conf->profile_preprocs.filename,
- sc->profile_preprocs.filename) != 0)
- {
- ErrorMessage("Snort Reload: Changing the preprocessor profiling "
- "filename configuration requires a restart.\n");
- return -1;
- }
- }
- else if (snort_conf->profile_preprocs.filename !=
- sc->profile_preprocs.filename)
- {
- ErrorMessage("Snort Reload: Changing the preprocessor profiling "
- "filename configuration requires a restart.\n");
- return -1;
- }
-#endif
-
if (snort_conf->group_id != sc->group_id)
{
ErrorMessage("Snort Reload: Changing the group id "
#include "hash/sfghash.h"
#include "main/policy.h"
-#define MAX_PIDFILE_SUFFIX 11 /* uniqueness extension to PID file, see '-R' */
-
#define DEFAULT_LOG_DIR "."
#ifdef INTEL_SOFT_CPM
{
//------------------------------------------------------
// alert module stuff
- char *alert_file;
int default_rule_state;
uint16_t flowbit_size;
//------------------------------------------------------
// FIXIT-L non-module stuff - separate config from derived state?
+ char* run_prefix;
+ bool id_subdir;
+ bool id_zero;
char pid_filename[STD_BUF];
char *orig_log_dir; /* set in case of chroot */
static const Parameter snort_params[] =
{
{ "-?", Parameter::PT_IMPLIED, nullptr, nullptr,
- "show usage" },
+ "list command line options (same as --help)" },
{ "-A", Parameter::PT_STRING, nullptr, nullptr,
"<mode> set alert mode: none, cmg, or alert_*" },
"<mode> checksum mode (all,noip,notcp,noudp,noicmp,none)" },
{ "-l", Parameter::PT_STRING, nullptr, nullptr,
- "<ld> log to directory <ld>" },
+ "<logdir> log to this directory instead of current director" },
{ "-M", Parameter::PT_IMPLIED, nullptr, nullptr,
"log messages to syslog (not alerts)" },
"enable Inline-Test Mode Operation" },
{ "--help", Parameter::PT_IMPLIED, nullptr, nullptr,
+ "list command line options (same as -?)" },
+
+ { "--help!", Parameter::PT_IMPLIED, nullptr, nullptr,
"overview of help" },
{ "--help-builtin", Parameter::PT_STRING, "(optional)", nullptr,
{ "--help-signals", Parameter::PT_IMPLIED, nullptr, nullptr,
"dump available control signals" },
+ { "--id-subdir", Parameter::PT_IMPLIED, nullptr, nullptr,
+ "create/use instance subdirectories in logdir instead of instance filename prefix" },
+
+ { "--id-zero", Parameter::PT_IMPLIED, nullptr, nullptr,
+ "use id prefix / subdirectory even with one packet thread" },
+
{ "--list-modules", Parameter::PT_IMPLIED, nullptr, nullptr,
"list all known modules" },
{ "--rule", Parameter::PT_STRING, nullptr, nullptr,
"<rules> to be added to configuration; may be repeated" },
+ { "--run-prefix", Parameter::PT_STRING, nullptr, nullptr,
+ "<pfx> prepend this to each output file" },
+
{ "--script-path", Parameter::PT_STRING, nullptr, nullptr,
"<path> where to find luajit scripts" },
sc->run_flags |= RUN_FLAG__INLINE_TEST;
else if ( v.is("--help") )
+ help_usage(sc, v.get_string());
+
+ else if ( v.is("--help!") )
help_basic(sc, v.get_string());
else if ( v.is("--help-builtin") )
else if ( v.is("--help-signals") )
help_signals(sc, v.get_string());
+ else if ( v.is("--id-subdir") )
+ sc->id_subdir = true;
+
+ else if ( v.is("--id-zero") )
+ sc->id_zero = true;
+
else if ( v.is("--list-modules") )
list_modules(sc, v.get_string());
else if ( v.is("--rule") )
parser_append_rules(v.get_string());
+ else if ( v.is("--run-prefix") )
+ sc->run_prefix = SnortStrdup(v.get_string());
+
else if ( v.is("--script-path") )
ConfigScriptPath(sc, v.get_string());
return snort_conf->max_threads;
}
+//-------------------------------------------------------------------------
+// format is:
+// <logdir>/[<run_prefix>][<id#>][<X>]<name>
+//
+// where:
+// -- <logdir> is ./ if not set
+// -- <run_prefix> is optional
+// -- <id#> is optionally omitted for instance 0
+// -- <X> is either _ or / or nothing
+//-------------------------------------------------------------------------
+
const char* get_instance_file(std::string& file, const char* name)
{
- char id[8];
- snprintf(id, sizeof(id), "/%u/", get_instance_id());
-
+ bool sep = false;
file = snort_conf->log_dir ? snort_conf->log_dir : "./";
- file += id;
- struct stat s;
+ if ( file.back() != '/' )
+ file += '/';
+
+ if ( snort_conf->run_prefix )
+ {
+ file += snort_conf->run_prefix;
+ sep = true;
+ }
+
+ if ( get_instance_id() || snort_conf->id_zero )
+ {
+ char id[8];
+ snprintf(id, sizeof(id), "%u", get_instance_id());
+ file += id;
+ sep = true;
+ }
+
+ if ( sep )
+ file += '_';
+
+ if ( snort_conf->id_subdir )
+ {
+ file += '/';
+ struct stat s;
- if ( stat(file.c_str(), &s) )
- // FIXIT-H getting random 0750 or 0700 (umask not thread local)?
- mkdir(file.c_str(), 0770);
+ if ( stat(file.c_str(), &s) )
+ // FIXIT-H getting random 0750 or 0700 (umask not thread local)?
+ mkdir(file.c_str(), 0770);
+ }
file += name;
static THREAD_LOCAL rand_t* s_rand = NULL;
static THREAD_LOCAL Packet *encode_pkt;
static THREAD_LOCAL PegCount total_rebuilt_pkts = 0;
-static THREAD_LOCAL uint8_t* dst_mac = NULL;
static THREAD_LOCAL std::array<uint16_t, IP_ID_COUNT> s_id_pool{{0}};
static THREAD_LOCAL std::array<uint8_t, Codec::PKT_MAX> s_pkt{{0}};
-
+// FIXIT-L this shouldn't have to be thread lcoal
+static THREAD_LOCAL uint8_t* dst_mac = NULL;
//-------------------------------------------------------------------------
// Private helper functions
//-------------------------------------------------------------------------
-
static inline void push_layer(Packet *p,
uint16_t prot_id,
const uint8_t *hdr_start,
static THREAD_LOCAL ip_t* s_ipnet = NULL;
static THREAD_LOCAL send_t s_send = DAQ_Inject;
+// FIXIT-L these should not have to be thread local
+static THREAD_LOCAL uint8_t s_attempts = 0;
+static THREAD_LOCAL int s_enabled = 0;
+
static int Active_Open(const char*);
static int Active_Close(void);
static int Active_SendEth(const DAQ_PktHdr_t*, int, const uint8_t*, uint32_t);
static int Active_SendIp(const DAQ_PktHdr_t*, int, const uint8_t*, uint32_t);
-static uint8_t s_attempts = 0;
-static int s_enabled = 0;
-
static inline PROTO_ID GetInnerProto (const Packet* p)
{
if ( !p->num_layers ) return PROTO_MAX;
return mode;
}
-#ifdef PERF_PROFILING
-void ConfigProfiling(SnortConfig* sc)
-{
- if ( sc->profile_rules.filename )
- {
- char* fn = ProcessFileOption(sc, sc->profile_rules.filename);
- free(sc->profile_rules.filename);
- sc->profile_rules.filename = fn;
- }
- if ( sc->profile_preprocs.filename )
- {
- char* fn = ProcessFileOption(sc, sc->profile_preprocs.filename);
- free(sc->profile_preprocs.filename);
- sc->profile_preprocs.filename = fn;
- }
-
-}
-#endif
-
void ConfigQuiet(SnortConfig *sc, const char*)
{
sc->logging_flags |= LOGGING_FLAG__QUIET;
void ConfigSetUid(SnortConfig*, const char*);
void ConfigUmask(SnortConfig*, const char*);
void ConfigTunnelVerdicts(SnortConfig*, const char*);
-void ConfigProfiling(SnortConfig*);
PolicyMode GetPolicyMode(PolicyMode);
void config_syslog(SnortConfig* sc, const char*);
void config_daemon(SnortConfig* sc, const char*);
#include "treenodes.h"
#include "treenodes.h"
#include "snort_types.h"
-#include "log/text_log.h"
#include "detection_options.h"
#include "fpdetect.h"
#include "framework/module.h"
OptTreeNode *otn;
OTN_WorstPerformer *node, *tmp;
int num = 0;
- TextLog *log = NULL;
- time_t cur_time;
- char fullname[STD_BUF];
- int ret;
SnortConfig *sc = snort_conf;
if (sc == NULL)
getTicksPerMicrosec();
- cur_time = time(NULL);
-
- if (sc->profile_rules.filename != NULL)
- {
- if (sc->profile_rules.append)
- {
- log = TextLog_Init(sc->profile_rules.filename, 512*1024, 512*1024);
-
- if (log != NULL)
- TextLog_Print(log, "\ntimestamp: %u\n", cur_time);
- }
- else
- {
- ret = SnortSnprintf(fullname, STD_BUF, "%s.%u", sc->profile_rules.filename, (uint32_t)cur_time);
- if(ret != SNORT_SNPRINTF_SUCCESS)
- FatalError("profiler: file path+name too long\n");
- log = TextLog_Init(fullname, 512*1024, 512*1024);
- }
- }
-
if ( !worstPerformers )
- {
- if ( log )
- TextLog_Term(log);
return;
- }
- if ( log )
- TextLog_Print(log, "--------------------------------------------------\n");
- else
- LogMessage("--------------------------------------------------\n");
+ LogMessage("--------------------------------------------------\n");
if (numToPrint != -1)
{
- // FIXIT-L this is fugly; should have a LogMessage() type "file" within
- // TextLog so this if (log) TextLog_Print() else LogMessage() isn't
- // necessary.
- if(log)
- {
- TextLog_Print(log, "Rule Profile Statistics (worst %d rules)\n", numToPrint);
- } else {
- LogMessage("Rule Profile Statistics (worst %d rules)\n", numToPrint);
- }
+ LogMessage("Rule Profile Statistics (worst %d rules)\n", numToPrint);
}
else
{
- if(log)
- {
- TextLog_Print(log, "Rule Profile Statistics (all rules)\n");
- } else {
- LogMessage("Rule Profile Statistics (all rules)\n");
- }
+ LogMessage("Rule Profile Statistics (all rules)\n");
}
- if(log)
- {
- TextLog_Print(log,
+ LogMessage(
#ifdef PPM_MGR
- "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
+ "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
#else
- "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
+ "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
#endif
- 6, "Num",
- 9, "SID", 4, "GID", 4, "Rev",
- 11, "Checks",
- 10, "Matches",
- 10, "Alerts",
- 20, "Microsecs",
- 11, "Avg/Check",
- 11, "Avg/Match",
- 13, "Avg/Nonmatch"
+ 6, "Num",
+ 9, "SID", 4, "GID", 4, "Rev",
+ 11, "Checks",
+ 10, "Matches",
+ 10, "Alerts",
+ 20, "Microsecs",
+ 11, "Avg/Check",
+ 11, "Avg/Match",
+ 13, "Avg/Nonmatch"
#ifdef PPM_MGR
- , 11, "Disabled"
+ , 11, "Disabled"
#endif
- );
- }
- else
- {
- LogMessage(
-#ifdef PPM_MGR
- "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
-#else
- "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
-#endif
- 6, "Num",
- 9, "SID", 4, "GID", 4, "Rev",
- 11, "Checks",
- 10, "Matches",
- 10, "Alerts",
- 20, "Microsecs",
- 11, "Avg/Check",
- 11, "Avg/Match",
- 13, "Avg/Nonmatch"
-#ifdef PPM_MGR
- , 11, "Disabled"
-#endif
- );
- }
+ );
- if(log)
- {
- TextLog_Print(log,
-#ifdef PPM_MGR
- "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
-#else
- "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
-#endif
- 6, "===",
- 9, "===", 4, "===", 4, "===",
- 11, "======",
- 10, "=======",
- 10, "======",
- 20, "=========",
- 11, "=========",
- 11, "=========",
- 13, "============"
-#ifdef PPM_MGR
- , 11, "========"
-#endif
- );
- }
- else
- {
- LogMessage(
+ LogMessage(
#ifdef PPM_MGR
- "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
+ "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
#else
- "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
+ "%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
#endif
- 6, "===",
- 9, "===", 4, "===", 4, "===",
- 11, "======",
- 10, "=======",
- 10, "======",
- 20, "=========",
- 11, "=========",
- 11, "=========",
- 13, "============"
+ 6, "===",
+ 9, "===", 4, "===", 4, "===",
+ 11, "======",
+ 10, "=======",
+ 10, "======",
+ 20, "=========",
+ 11, "=========",
+ 11, "=========",
+ 13, "============"
#ifdef PPM_MGR
- , 11, "========"
+ , 11, "========"
#endif
- );
- }
+ );
for (node = worstPerformers, num=1;
node && ((numToPrint < 0) ? 1 : (num <= numToPrint));
otn = node->otn;
OtnState* state = otn->state;
- if(log)
- {
- TextLog_Print(log,
-#ifdef PPM_MGR
- "%*d%*d%*d%*d" FMTu64("*") FMTu64("*") FMTu64("*") FMTu64("*") "%*.1f%*.1f%*.1f" FMTu64("*") "\n",
-#else
- "%*d%*d%*d%*d" FMTu64("*") FMTu64("*") FMTu64("*") FMTu64("*") "%*.1f%*.1f%*.1f" "\n",
-#endif
- 6, num, 9, otn->sigInfo.id, 4, otn->sigInfo.generator, 4, otn->sigInfo.rev,
- 11, state->checks,
- 10, state->matches,
- 10, state->alerts,
- 20, (uint64_t)(state->ticks/ticks_per_microsec),
- 11, node->ticks_per_check/ticks_per_microsec,
- 11, node->ticks_per_match/ticks_per_microsec,
- 13, node->ticks_per_nomatch/ticks_per_microsec
-#ifdef PPM_MGR
- , 11, state->ppm_disable_cnt
-#endif
- );
- }
- else
- {
- LogMessage(
+ LogMessage(
#ifdef PPM_MGR
- "%*d%*d%*d%*d" FMTu64("*") FMTu64("*") FMTu64("*") FMTu64("*") "%*.1f%*.1f%*.1f" FMTu64("*") "\n",
+ "%*d%*d%*d%*d" FMTu64("*") FMTu64("*") FMTu64("*") FMTu64("*") "%*.1f%*.1f%*.1f" FMTu64("*") "\n",
#else
- "%*d%*d%*d%*d" FMTu64("*") FMTu64("*") FMTu64("*") FMTu64("*") "%*.1f%*.1f%*.1f" "\n",
+ "%*d%*d%*d%*d" FMTu64("*") FMTu64("*") FMTu64("*") FMTu64("*") "%*.1f%*.1f%*.1f" "\n",
#endif
- 6, num, 9, otn->sigInfo.id, 4, otn->sigInfo.generator, 4, otn->sigInfo.rev,
- 11, state->checks,
- 10, state->matches,
- 10, state->alerts,
- 20, (uint64_t)(state->ticks/ticks_per_microsec),
- 11, node->ticks_per_check/ticks_per_microsec,
- 11, node->ticks_per_match/ticks_per_microsec,
- 13, node->ticks_per_nomatch/ticks_per_microsec
+ 6, num, 9, otn->sigInfo.id, 4, otn->sigInfo.generator, 4, otn->sigInfo.rev,
+ 11, state->checks,
+ 10, state->matches,
+ 10, state->alerts,
+ 20, (uint64_t)(state->ticks/ticks_per_microsec),
+ 11, node->ticks_per_check/ticks_per_microsec,
+ 11, node->ticks_per_match/ticks_per_microsec,
+ 13, node->ticks_per_nomatch/ticks_per_microsec
#ifdef PPM_MGR
- , 11, state->ppm_disable_cnt
+ , 11, state->ppm_disable_cnt
#endif
- );
- }
+ );
}
/* Do some cleanup */
node = tmp;
}
- if(log)
- TextLog_Term(log);
worstPerformers = NULL;
}
}
}
-void PrintPreprocPerformance(TextLog *log, int num, Preproc_WorstPerformer *idx)
+void PrintPreprocPerformance(int num, Preproc_WorstPerformer *idx)
{
Preproc_WorstPerformer *child;
int i;
if (num != 0)
{
indent += 2;
- if(log)
- {
- TextLog_Print(log, "%*d%*s%*d" FMTu64("*") FMTu64("*") FMTu64("*") "%*.2f%*.2f%*.2f\n",
- indent, num,
- 28 - indent, idx->node->name, 6, idx->node->layer,
- 11, idx->node->stats.checks,
- 11, idx->node->stats.exits,
- 20, (uint64_t)(idx->node->stats.ticks/ticks_per_microsec),
- 11, idx->ticks_per_check/ticks_per_microsec,
- 14, idx->pct_of_parent,
- 13, idx->pct_of_total);
- }
- else
- {
LogMessage("%*d%*s%*d" FMTu64("*") FMTu64("*") FMTu64("*") "%*.2f%*.2f%*.2f\n",
indent, num,
28 - indent, idx->node->name, 6, idx->node->layer,
11, idx->ticks_per_check/ticks_per_microsec,
14, idx->pct_of_parent,
13, idx->pct_of_total);
- }
}
else
{
/* The totals */
indent += strlen(idx->node->name);
- if(log)
- {
- TextLog_Print(log, "%*s%*s%*d" FMTu64("*") FMTu64("*") FMTu64("*") "%*.2f%*.2f%*.2f\n",
- indent, idx->node->name,
- 28 - indent, idx->node->name, 6, idx->node->layer,
- 11, idx->node->stats.checks,
- 11, idx->node->stats.exits,
- 20, (uint64_t)(idx->node->stats.ticks/ticks_per_microsec),
- 11, idx->ticks_per_check/ticks_per_microsec,
- 14, idx->pct_of_parent,
- 13, idx->pct_of_parent);
- }
- else
- {
LogMessage("%*s%*s%*d" FMTu64("*") FMTu64("*") FMTu64("*") "%*.2f%*.2f%*.2f\n",
indent, idx->node->name,
28 - indent, idx->node->name, 6, idx->node->layer,
11, idx->ticks_per_check/ticks_per_microsec,
14, idx->pct_of_parent,
13, idx->pct_of_parent);
- }
}
child = idx->children;
i = 1;
while (child)
{
- PrintPreprocPerformance(log, i++, child);
+ PrintPreprocPerformance(i++, child);
child = child->next;
}
}
Preproc_WorstPerformer *idx;
Preproc_WorstPerformer *total = NULL;
int num = 0;
- TextLog *log = NULL;
- time_t cur_time;
- char fullname[STD_BUF];
- int ret;
- SnortConfig *sc = snort_conf;
getTicksPerMicrosec();
- cur_time = time(NULL);
- if (sc->profile_preprocs.filename != NULL)
- {
- if (sc->profile_preprocs.append)
- {
- log = TextLog_Init(sc->profile_preprocs.filename, 512*1024, 512*1024);
-
- if (log != NULL)
- TextLog_Print(log, "\ntimestamp: %u\n", cur_time);
- }
- else
- {
- ret = SnortSnprintf(fullname, STD_BUF, "%s.%u", sc->profile_preprocs.filename, (uint32_t)cur_time);
- if(ret != SNORT_SNPRINTF_SUCCESS)
- FatalError("profiler: file path+name too long\n");
- log = TextLog_Init(fullname, 512*1024, 512*1024);
- }
- }
-
if ( !worstPreprocPerformers )
- {
- if ( log )
- TextLog_Term(log);
return;
- }
- if ( log )
- TextLog_Print(log, "--------------------------------------------------\n");
- else
- LogMessage("--------------------------------------------------\n");
+ LogMessage("--------------------------------------------------\n");
if (numToPrint != -1)
- {
- if(log)
- {
- TextLog_Print(log, "Module Profile Statistics (worst %d)\n", numToPrint);
- }
- else
- {
- LogMessage("Module Profile Statistics (worst %d)\n", numToPrint);
- }
- }
- else
- {
- if(log)
- {
- TextLog_Print(log, "Module Profile Statistics (all)\n");
- }
- else
- {
- LogMessage("Module Profile Statistics (all)\n");
- }
- }
-
- if(log)
- {
- TextLog_Print(log, "%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
- 4, "Num",
- 24, "Preprocessor",
- 6, "Layer",
- 11, "Checks",
- 11, "Exits",
- 20, "Microsecs",
- 11, "Avg/Check",
- 14, "Pct of Caller",
- 13, "Pct of Total");
- }
+ LogMessage("Module Profile Statistics (worst %d)\n", numToPrint);
else
- {
- LogMessage("%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
- 4, "Num",
- 24, "Preprocessor",
- 6, "Layer",
- 11, "Checks",
- 11, "Exits",
- 20, "Microsecs",
- 11, "Avg/Check",
- 14, "Pct of Caller",
- 13, "Pct of Total");
- }
-
- if(log)
- {
- TextLog_Print(log, "%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
- 4, "===",
- 24, "============",
- 6, "=====",
- 11, "======",
- 11, "=====",
- 20, "=========",
- 11, "=========",
- 14, "=============",
- 13, "============");
- }
- else
- {
- LogMessage("%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
- 4, "===",
- 24, "============",
- 6, "=====",
- 11, "======",
- 11, "=====",
- 20, "=========",
- 11, "=========",
- 14, "=============",
- 13, "============");
- }
+ LogMessage("Module Profile Statistics (all)\n");
+
+ LogMessage("%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
+ 4, "Num",
+ 24, "Preprocessor",
+ 6, "Layer",
+ 11, "Checks",
+ 11, "Exits",
+ 20, "Microsecs",
+ 11, "Avg/Check",
+ 14, "Pct of Caller",
+ 13, "Pct of Total");
+
+ LogMessage("%*s%*s%*s%*s%*s%*s%*s%*s%*s\n",
+ 4, "===",
+ 24, "============",
+ 6, "=====",
+ 11, "======",
+ 11, "=====",
+ 20, "=========",
+ 11, "=========",
+ 14, "=============",
+ 13, "============");
for (idx = worstPreprocPerformers, num=1;
idx && ((numToPrint < 0) ? 1 : (num <= numToPrint));
total = idx;
continue;
}
- //if (!idx)
- // break;
- PrintPreprocPerformance(log, num, idx);
- //LogMessage("%*d%*s%*d%*d" FMTu64("*") "%*.1f%*.1f\n",
- // 6, num, 20, idx->node->name, 6, idx->node->layer,
- // 11, idx->node->stats.checks,
- // 11, idx->node->stats.exits,
- // 20, idx->node->stats.ticks,
- // 11, idx->ticks_per_check,
- // 14, idx->pct_of_parent,
- // 14, idx->pct_of_total);
+ PrintPreprocPerformance(num, idx);
}
if (total)
- PrintPreprocPerformance(log, 0, total);
+ PrintPreprocPerformance(0, total);
- if(log)
- TextLog_Term(log);
CleanupPreprocPerformance(worstPreprocPerformers);
worstPreprocPerformers = NULL;
}
void ShowRuleProfiles(void);
void ResetRuleProfiling(void);
-typedef struct _ProfileConfig
+struct ProfileConfig
{
int num;
int sort;
- int append;
- char *filename;
-
-} ProfileConfig;
+};
// thread local access method
typedef ProfileStats* (*get_profile_func)(const char*);