]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
cleanup
authorRuss Combs <rucombs@cisco.com>
Sat, 23 Aug 2014 20:13:48 +0000 (16:13 -0400)
committerRuss Combs <rucombs@cisco.com>
Sat, 23 Aug 2014 20:13:48 +0000 (16:13 -0400)
14 files changed:
ChangeLog
src/main/help.cc
src/main/modules.cc
src/main/snort.cc
src/main/snort_config.cc
src/main/snort_config.h
src/main/snort_module.cc
src/main/thread.cc
src/managers/packet_manager.cc
src/packet_io/active.cc
src/parser/config_file.cc
src/parser/config_file.h
src/time/profiler.cc
src/time/profiler.h

index bfecaa839ee4d80d96367384f5212198f97693dd..492762b01cc6d2efff662d92e44e094b5f98097e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,14 @@
 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
index 0fb7619005af97f6dca313a41b5a32f519fa9cc1..29aa83d1087bc84de3b808ad5f00959043be1132 100644 (file)
@@ -46,9 +46,11 @@ using namespace std;
 #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"
@@ -63,7 +65,8 @@ static const char* snort_help =
 "\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"
@@ -79,6 +82,7 @@ static const char* snort_help =
 "  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"
 ;
 
 //-------------------------------------------------------------------------
@@ -110,13 +114,13 @@ void help_args(const char* pfx)
 
 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);
 }
index fc57e3921f4c3d46f45955ec9e1837256d1cf954..7fcba6903f8125f2196d254c1c8f6da57ad144ef 100644 (file)
@@ -303,17 +303,6 @@ bool SearchEngineModule::set(const char*, Value& v, SnortConfig* sc)
 //-------------------------------------------------------------------------
 
 #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",
@@ -324,9 +313,6 @@ static const Parameter profile_rule_params[] =
       "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 }
 };
 
@@ -339,9 +325,6 @@ static const Parameter profile_module_params[] =
       "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 }
 };
 
@@ -396,14 +379,6 @@ bool ProfileModule::set(const char* fqn, Value& v, SnortConfig* sc)
     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;
 
@@ -545,9 +520,6 @@ bool ReferencesModule::set(const char*, Value& v, SnortConfig*)
 
 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)" },
@@ -593,10 +565,7 @@ public:
 
 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") )
index 3172101a13d13901269fe4bde54b34e52440ac6e..e45f6c042a6b6500436d814edd60e950e0230ab1 100644 (file)
@@ -353,19 +353,6 @@ static void SnortInit(int argc, char **argv)
     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");
@@ -621,12 +608,6 @@ static SnortConfig * get_reload_config(void)
     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);
index 59ae5f8f1ebf2092ffa80cb31ca219db2b81f466..81ba4bd6b7becb4166574654ab3dff5e151a65d3 100644 (file)
@@ -217,23 +217,12 @@ void SnortConfFree(SnortConfig *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);
@@ -304,7 +293,7 @@ void SnortConfFree(SnortConfig *sc)
     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 */
@@ -335,6 +324,12 @@ SnortConfig * MergeSnortConfs(SnortConfig *cmd_line, SnortConfig *config_file)
     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);
 
@@ -483,22 +478,6 @@ int VerifyReload(SnortConfig *sc)
     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 "
@@ -615,64 +594,6 @@ int VerifyReload(SnortConfig *sc)
     }
 #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 "
index c4dbc211ae566280e10aea3f5c6b5804a0152f46..a7963b0fb467d2a63a3ca4ddcee073c4f0df4f98 100644 (file)
@@ -46,8 +46,6 @@
 #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
@@ -74,7 +72,6 @@ struct SnortConfig
 {
     //------------------------------------------------------
     // alert module stuff
-    char *alert_file;
     int default_rule_state;
 
     uint16_t flowbit_size;
@@ -191,6 +188,9 @@ struct SnortConfig
 
     //------------------------------------------------------
     // 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 */
index bf8090dbf793b6dea4a1e725351bbbbd436ac040..81abda16f4644870906d9f566babfe086b4cd790 100644 (file)
@@ -75,7 +75,7 @@ static const Command snort_cmds[] =
 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_*" },
@@ -126,7 +126,7 @@ static const Parameter snort_params[] =
       "<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)" },
@@ -234,6 +234,9 @@ static const Parameter snort_params[] =
       "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,
@@ -260,6 +263,12 @@ static const Parameter snort_params[] =
     { "--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" },
 
@@ -323,6 +332,9 @@ static const Parameter snort_params[] =
     { "--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" },
 
@@ -533,6 +545,9 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc)
         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") )
@@ -559,6 +574,12 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc)
     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());
 
@@ -617,6 +638,9 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc)
     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());
 
index 673be538dc22a251206bf2eece0dec8743512999..d56496465a90ddd0f524d8346c658d9630961378 100644 (file)
@@ -46,19 +46,51 @@ unsigned get_instance_max()
     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;
 
index 9b3f7b806e8a92405a3d27eb4bb18d9378a3a2ea..803fad7e9265183977702ca01b6ea95050292859 100644 (file)
@@ -91,17 +91,16 @@ static std::array<PegCount, s_stats.size()> g_stats{{0}};
 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,
index bc2741db77657f42506cc70a01c3e274e8a9d2d3..4367a0d5704e56abe1feda90486698ba13923bb5 100644 (file)
@@ -67,15 +67,16 @@ static THREAD_LOCAL eth_t* s_link = NULL;
 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;
index e9e13ad9c2edf4db0e598c2503fb226aeb76c9a5..16d6cb0f5eccc01f09c20e3bc3f107093a034ebb 100644 (file)
@@ -430,25 +430,6 @@ PolicyMode GetPolicyMode(PolicyMode mode)
     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;
index 0a1ef408699ee2f26012a3f2aee4844c9dcf6f47..63f66d78f1106801a978eb7bf1159d0916eed0d0 100644 (file)
@@ -63,7 +63,6 @@ void ConfigSetGid(SnortConfig*, const char*);
 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*);
index db3c69a17050d448d58cb8e5b1b8dec61fffa2ef..e31cf9705ef712b2e3d685ae3990c1254f1eeba4 100644 (file)
@@ -47,7 +47,6 @@ using namespace std;
 #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"
@@ -210,10 +209,6 @@ void PrintWorstRules(int numToPrint)
     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)
@@ -221,149 +216,59 @@ void PrintWorstRules(int numToPrint)
 
     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));
@@ -374,48 +279,24 @@ void PrintWorstRules(int 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 */
@@ -426,8 +307,6 @@ void PrintWorstRules(int numToPrint)
         node = tmp;
     }
 
-    if(log)
-        TextLog_Term(log);
     worstPerformers = NULL;
 }
 
@@ -701,7 +580,7 @@ void FreePreprocPerformance(Preproc_WorstPerformer *idx)
     }
 }
 
-void PrintPreprocPerformance(TextLog *log, int num, Preproc_WorstPerformer *idx)
+void PrintPreprocPerformance(int num, Preproc_WorstPerformer *idx)
 {
     Preproc_WorstPerformer *child;
     int i;
@@ -711,20 +590,6 @@ void PrintPreprocPerformance(TextLog *log, int num, Preproc_WorstPerformer *idx)
     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,
@@ -734,27 +599,12 @@ void PrintPreprocPerformance(TextLog *log, int num, Preproc_WorstPerformer *idx)
                                   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,
@@ -764,7 +614,6 @@ void PrintPreprocPerformance(TextLog *log, int num, Preproc_WorstPerformer *idx)
                                   11, idx->ticks_per_check/ticks_per_microsec,
                                   14, idx->pct_of_parent,
                                   13, idx->pct_of_parent);
-        }
     }
 
     child = idx->children;
@@ -772,7 +621,7 @@ void PrintPreprocPerformance(TextLog *log, int num, Preproc_WorstPerformer *idx)
     i = 1;
     while (child)
     {
-        PrintPreprocPerformance(log, i++, child);
+        PrintPreprocPerformance(i++, child);
         child = child->next;
     }
 }
@@ -845,121 +694,40 @@ void PrintWorstPreprocs(int numToPrint)
     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));
@@ -972,23 +740,11 @@ void PrintWorstPreprocs(int 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;
 }
index d0dc5f1cc3678b0a5e7fa9b37139b195b71f67b8..cd63017d3a9937481193364b09ed8c9caaa59a15 100644 (file)
@@ -159,14 +159,11 @@ struct ProfileStats
 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*);