#include "app_forecast.h"
#include "app_info_table.h"
#include "appid_discovery.h"
+#include "appid_http_session.h"
#include "appid_session.h"
#ifdef USE_RNA_CONFIG
#include "appid_utils/network_set.h"
#include "detector_plugins/detector_dns.h"
#include "target_based/snort_protocols.h"
#ifdef ENABLE_APPID_THIRD_PARTY
+#include "tp_appid_utils.h"
#include "tp_lib_handler.h"
#endif
PatternClientDetector::finalize_client_port_patterns();
AppIdDiscovery::finalize_plugins();
http_matchers->finalize_patterns();
- ssl_detector_process_patterns();
+ ssl_detector_process_patterns();
dns_host_detector_process_patterns();
read_port_detectors(ODP_PORT_DETECTORS);
read_port_detectors(CUSTOM_PORT_DETECTORS);
+ appid_http_profiler_init();
+#ifdef ENABLE_APPID_THIRD_PARTY
+ tp_appid_profiler_init();
+#endif
once = true;
}
#ifdef USE_RNA_CONFIG
"body",
};
-snort::ProfileStats httpPerfStats;
+#ifdef APPID_DEEP_PERF_PROFILING
+static THREAD_LOCAL snort::ProfileStats process_http_perf_stats;
+static ProfileStats* get_profile(const char*)
+{
+ return &process_http_perf_stats;
+}
+void appid_http_profiler_init()
+{
+ Profiler::register_module("http_process", "appid", get_profile);
+}
+#else
+void appid_http_profiler_init() { return; }
+#endif
AppIdHttpSession::AppIdHttpSession(AppIdSession& asd)
: asd(asd)
int AppIdHttpSession::process_http_packet(AppidSessionDirection direction,
AppidChangeBits& change_bits)
{
- snort::Profile http_profile_context(httpPerfStats);
+#ifdef APPID_DEEP_PERF_PROFILING
+ snort::Profile profile(process_http_perf_stats);
+#endif
AppId service_id = APP_ID_NONE;
AppId client_id = APP_ID_NONE;
AppId payload_id = APP_ID_NONE;
#endif
};
+void appid_http_profiler_init();
+
#endif
void AppIdInspector::eval(Packet* p)
{
- Profile profile(appidPerfStats);
+ Profile profile(appid_perf_stats);
appid_stats.packets++;
if (p->flow)
// appid module
//-------------------------------------------------------------------------
-THREAD_LOCAL ProfileStats appidPerfStats;
+THREAD_LOCAL ProfileStats appid_perf_stats;
THREAD_LOCAL AppIdStats appid_stats;
static const Parameter s_params[] =
ProfileStats* AppIdModule::get_profile() const
{
- return &appidPerfStats;
+ return &appid_perf_stats;
}
const AppIdModuleConfig* AppIdModule::get_data()
#include "appid_config.h"
#include "framework/module.h"
-extern THREAD_LOCAL snort::ProfileStats appidPerfStats;
+extern THREAD_LOCAL snort::ProfileStats appid_perf_stats;
extern Trace TRACE_NAME(appid_module);
#define MAX_CANDIDATE_CLIENTS 10
+#ifdef APPID_DEEP_PERF_PROFILING
+static THREAD_LOCAL ProfileStats client_disco_perf_stats;
+static ProfileStats* get_profile(const char*)
+{
+ return &client_disco_perf_stats;
+}
+#endif
+
ClientDiscovery* ClientDiscovery::discovery_manager = nullptr;
-ProfileStats clientMatchPerfStats;
THREAD_LOCAL ClientAppMatch* match_free_list = nullptr;
ClientDiscovery::ClientDiscovery(AppIdInspector& ins)
for ( auto kv : udp_detectors )
kv.second->initialize();
+
+#ifdef APPID_DEEP_PERF_PROFILING
+ Profiler::register_module("client_discovery", "appid", get_profile);
+#endif
}
void ClientDiscovery::finalize_client_plugins()
bool ClientDiscovery::do_client_discovery(AppIdSession& asd, Packet* p,
AppidSessionDirection direction, AppidChangeBits& change_bits)
{
+#ifdef APPID_DEEP_PERF_PROFILING
+ Profile profile(client_disco_perf_stats);
+#endif
bool isTpAppidDiscoveryDone = false;
AppInfoTableEntry* entry;
-
- Profile clientMatchPerfStats_profile_context(clientMatchPerfStats);
uint32_t prevRnaClientState = asd.client_disco_state;
bool was_http2 = asd.is_http2;
bool was_service = asd.is_service_detected();
#define SP_SERVICE 2
#define NUM_ID_TYPES 4
-static THREAD_LOCAL ProfileStats appidRuleOptionPerfStats;
+static THREAD_LOCAL ProfileStats ips_appid_perf_stats;
class AppIdIpsOption : public IpsOption
{
// first match wins...
IpsOption::EvalStatus AppIdIpsOption::eval(Cursor&, Packet* p)
{
- AppId app_ids[NUM_ID_TYPES];
-
if ( !p->flow )
return NO_MATCH;
- Profile profile(appidRuleOptionPerfStats);
+#ifdef APPID_DEEP_PERF_PROFILING
+ Profile profile(ips_appid_perf_stats);
+#endif
AppIdSession* session = appid_api.get_appid_session(*(p->flow));
if ( !session )
return NO_MATCH;
+ AppId app_ids[NUM_ID_TYPES];
+
// id order on stream api call is: service, client, payload, misc
if ( (p->packet_flags & PKT_FROM_CLIENT) )
session->get_application_ids(app_ids[CP_SERVICE], app_ids[CP_CLIENT],
bool end(const char*, int, SnortConfig*) override;
ProfileStats* get_profile() const override
- { return &appidRuleOptionPerfStats; }
+ { return &ips_appid_perf_stats; }
Usage get_usage() const override
{ return DETECT; }
LUA_LOG_TRACE = 5,
};
-ProfileStats luaDetectorsPerfStats;
-ProfileStats luaCiscoPerfStats;
-ProfileStats luaCustomPerfStats;
+#ifdef APPID_DEEP_PERF_PROFILING
+// FIXIT-L: Bring snort2's luaCiscoPerfStats and luaCustomPerfStats if more granularity is desired
+static THREAD_LOCAL ProfileStats lua_validate_perf_stats;
+static ProfileStats* get_profile(const char*)
+{
+ return &lua_validate_perf_stats;
+}
+void lua_detector_profiler_init()
+{
+ Profiler::register_module("lua_validate", "appid", get_profile);
+}
+#else
+void lua_detector_profiler_init() { return; }
+#endif
static std::unordered_map<AppId, CHPApp*>* CHP_glossary = nullptr; // tracks http multipatterns
int LuaStateDescriptor::lua_validate(AppIdDiscoveryArgs& args)
{
- Profile lua_detector_context(luaCustomPerfStats);
-
auto my_lua_state = lua_detector_mgr? lua_detector_mgr->L : nullptr;
if (!my_lua_state)
{
int LuaServiceDetector::validate(AppIdDiscoveryArgs& args)
{
+#ifdef APPID_DEEP_PERF_PROFILING
+ Profile profile(lua_validate_perf_stats);
+#endif
//FIXIT-M: RELOAD - use lua references to get user data object from stack
auto my_lua_state = lua_detector_mgr? lua_detector_mgr->L : nullptr;
lua_settop(my_lua_state,0);
int LuaClientDetector::validate(AppIdDiscoveryArgs& args)
{
+#ifdef APPID_DEEP_PERF_PROFILING
+ Profile profile(lua_validate_perf_stats);
+#endif
//FIXIT-M: RELOAD - use lua references to get user data object from stack
auto my_lua_state = lua_detector_mgr? lua_detector_mgr->L : nullptr;
std::string name = this->name + "_";
{ return cd; }
};
+void lua_detector_profiler_init();
int register_detector(lua_State*);
void init_chp_glossary();
int init(lua_State*, int result=0);
void LuaDetectorManager::initialize(AppIdConfig& config, int is_control)
{
+ if (is_control)
+ lua_detector_profiler_init();
+
// FIXIT-M: RELOAD - When reload is supported, remove this line which prevents re-initialize
if (lua_detector_mgr)
return;
using namespace snort;
-ProfileStats serviceMatchPerfStats;
+#ifdef APPID_DEEP_PERF_PROFILING
+static THREAD_LOCAL ProfileStats service_disco_perf_stats;
+static ProfileStats* get_profile(const char*)
+{
+ return &service_disco_perf_stats;
+}
+#endif
+
static ServiceDetector* ftp_service;
ServiceDiscovery* ServiceDiscovery::discovery_manager = nullptr;
kv.second->initialize();
service_detector_list.push_back(kv.second);
}
+
+#ifdef APPID_DEEP_PERF_PROFILING
+ Profiler::register_module("service_discovery", "appid", get_profile);
+#endif
}
void ServiceDiscovery::finalize_service_patterns()
bool ServiceDiscovery::do_service_discovery(AppIdSession& asd, Packet* p,
AppidSessionDirection direction, AppidChangeBits& change_bits)
{
+#ifdef APPID_DEEP_PERF_PROFILING
+ Profile profile(service_disco_perf_stats);
+#endif
bool isTpAppidDiscoveryDone = false;
-
- Profile serviceMatchPerfStats_profile_context(serviceMatchPerfStats);
uint32_t prevRnaServiceState = asd.service_disco_state;
AppId tp_app_id = asd.get_tp_app_id();
typedef AppIdHttpSession::pair_t pair_t;
-THREAD_LOCAL ProfileStats tpLibPerfStats;
-THREAD_LOCAL ProfileStats tpPerfStats;
+static THREAD_LOCAL ProfileStats tp_lib_perf_stats;
+#ifdef APPID_DEEP_PERF_PROFILING
+static THREAD_LOCAL ProfileStats tp_disco_perf_stats;
+static ProfileStats* get_profile(const char* key)
+{
+ if ( !strcmp(key, "tp_discovery") )
+ return &tp_disco_perf_stats;
+ if ( !strcmp(key, "tp_library") )
+ return &tp_lib_perf_stats;
+ return nullptr;
+}
+void tp_appid_profiler_init()
+{
+ Profiler::register_module("tp_discovery", "appid", get_profile);
+ Profiler::register_module("tp_library", "tp_discovery", get_profile);
+}
+#else
+static ProfileStats* get_profile(const char*)
+{
+ return &tp_lib_perf_stats;
+}
+void tp_appid_profiler_init()
+{
+ Profiler::register_module("tp_library", "appid", get_profile);
+}
+#endif
// std::vector does not have a convenient find() function.
// There is a generic std::find() in <algorithm>, but this might be faster.
bool do_tp_discovery(AppIdSession& asd, IpProtocol protocol,
Packet* p, AppidSessionDirection& direction, AppidChangeBits& change_bits)
{
- if ( !TPLibHandler::have_tp() )
- return true;
+#ifdef APPID_DEEP_PERF_PROFILING
+ Profile tp_disco_profile(tp_disco_perf_stats);
+#endif
AppId tp_app_id = asd.get_tp_app_id();
if (p->dsize || asd.config->mod_config->tp_allow_probes)
{
- Profile tpPerfStats_profile_context(tpPerfStats);
-
//restart inspection by 3rd party
if (!asd.tp_reinspect_by_initiator && (direction == APP_ID_FROM_INITIATOR) &&
check_reinspect(p, asd))
if (protocol != IpProtocol::TCP || (p->packet_flags & PKT_STREAM_ORDER_OK)
|| asd.config->mod_config->tp_allow_probes)
{
- Profile tpLibPerfStats_profile_context(tpLibPerfStats);
+ Profile tp_lib_profile(tp_lib_perf_stats);
int tp_confidence;
ThirdPartyAppIDAttributeData tp_attribute_data;
vector<AppId> tp_proto_list;
class AppIdSession;
+void tp_appid_profiler_init();
bool do_tp_discovery(AppIdSession&, IpProtocol, snort::Packet*, AppidSessionDirection&,
AppidChangeBits&);