appid_inspector.h
appid_module.cc
appid_module.h
- appid_pegs.h
appid_ssh_event_handler.cc
appid_ssh_event_handler.h
appid_stats.cc
void ApplicationDescriptor::set_id(AppId app_id)
{
if ( my_id != app_id )
- {
my_id = app_id;
- if ( app_id > APP_ID_NONE )
- update_stats(app_id);
- else if ( app_id == APP_ID_UNKNOWN )
- appid_stats.appid_unknown++;
- else
- return; // app_id == APP_ID_NONE
-
- if ( overwritten_id > APP_ID_NONE )
- {
- update_stats(overwritten_id, false);
- overwritten_id = APP_ID_NONE;
- }
- }
}
void ApplicationDescriptor::set_id(const Packet& p, AppIdSession& asd,
}
}
-void ServiceAppDescriptor::update_stats(AppId id, bool increment)
-{
- AppIdPegCounts::update_service_count(id, increment);
-}
-
void ServiceAppDescriptor::set_port_service_id(AppId id)
{
if ( id != port_service_id )
- {
port_service_id = id;
- if ( id > APP_ID_NONE )
- AppIdPegCounts::update_service_count(id, true);
- }
}
void ServiceAppDescriptor::set_id(AppId app_id, OdpContext& odp_ctxt)
}
}
}
-
-void ClientAppDescriptor::update_stats(AppId id, bool increment)
-{
- AppIdPegCounts::update_client_count(id, increment);
-}
-
-void PayloadAppDescriptor::update_stats(AppId id, bool increment)
-{
- AppIdPegCounts::update_payload_count(id, increment);
-}
set_version(version);
}
- virtual void update_stats(AppId id, bool increment = true) = 0;
-
AppId get_id() const
{
return my_id;
virtual void set_id(const snort::Packet& p, AppIdSession& asd, AppidSessionDirection dir, AppId app_id, AppidChangeBits& change_bits);
- void set_overwritten_id(AppId app_id)
- {
- overwritten_id = app_id;
- }
-
const char* get_version() const
{
return my_version.empty() ? nullptr : my_version.c_str();
private:
AppId my_id = APP_ID_NONE;
- AppId overwritten_id = APP_ID_NONE;
std::string my_version;
};
service_group = DAQ_PKTHDR_UNKNOWN;
}
- void update_stats(AppId id, bool increment = true) override;
-
AppId get_port_service_id() const
{
return port_service_id;
return my_username.empty() ? nullptr : my_username.c_str();
}
- void update_stats(AppId id, bool increment = true) override;
-
void set_efp_client_app_id(AppId id)
{
efp_client_app_id = id;
{
ApplicationDescriptor::reset();
}
-
- void update_stats(AppId id, bool increment = true) override;
};
#endif
assert(asd.flow);
if (asd.flow->ha_state)
asd.flow->ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
+ if (asd.get_service_id() == APP_ID_HTTP2)
+ AppIdPegCounts::inc_client_count(app_id);
+
if (version)
{
client.set_version(version);
assert(asd.flow);
if (asd.flow->ha_state)
asd.flow->ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
+ if (asd.get_service_id() == APP_ID_HTTP2)
+ AppIdPegCounts::inc_payload_count(app_id);
payload.set_version(version);
if (appidDebug->is_active())
return;
referred_payload_app_id = app_id;
+ if (asd.get_service_id() == APP_ID_HTTP2)
+ AppIdPegCounts::inc_referred_count(app_id);
change_bits.set(APPID_REFERRED_BIT);
if (appidDebug->is_active())
{ CountType::SUM, "processed_packets", "count of packets processed" },
{ CountType::SUM, "ignored_packets", "count of packets ignored" },
{ CountType::SUM, "total_sessions", "count of sessions created" },
- { CountType::SUM, "appid_unknown", "count of sessions where appid could not be determined" },
{ CountType::SUM, "service_cache_prunes", "number of times the service cache was pruned" },
{ CountType::SUM, "service_cache_adds", "number of times an entry was added to the service cache" },
{ CountType::SUM, "service_cache_removes", "number of times an item was removed from the service cache" },
#include "main/snort_config.h"
#include "appid_config.h"
-#include "appid_pegs.h"
+#include "appid_peg_counts.h"
namespace snort
{
memset((*appid_peg_counts)[app_num].stats, 0, sizeof(PegCount) *
DetectorPegs::NUM_APPID_DETECTOR_PEGS);
}
+
+ // reset unknown_app stats
+ memset(appid_dynamic_sum[SF_APPID_MAX].stats, 0, sizeof(PegCount) *
+ DetectorPegs::NUM_APPID_DETECTOR_PEGS);
+ memset((*appid_peg_counts)[appid_peg_counts->size() - 1].stats, 0, sizeof(PegCount) *
+ DetectorPegs::NUM_APPID_DETECTOR_PEGS);
}
void AppIdPegCounts::add_app_peg_info(std::string app_name, AppId app_id)
appid_dynamic_sum[SF_APPID_MAX].stats[j] += ptr[peg_num].stats[j];
}
-void AppIdPegCounts::update_service_count(AppId id, bool increment)
+void AppIdPegCounts::inc_service_count(AppId id)
{
- if (increment)
- (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::SERVICE_DETECTS]++;
- else if ((*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::SERVICE_DETECTS])
- (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::SERVICE_DETECTS]--;
+ (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::SERVICE_DETECTS]++;
}
-void AppIdPegCounts::update_client_count(AppId id, bool increment)
+void AppIdPegCounts::inc_client_count(AppId id)
{
- if (increment)
- (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::CLIENT_DETECTS]++;
- else if ((*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::CLIENT_DETECTS])
- (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::CLIENT_DETECTS]--;
+ (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::CLIENT_DETECTS]++;
}
-void AppIdPegCounts::update_payload_count(AppId id, bool increment)
+void AppIdPegCounts::inc_payload_count(AppId id)
{
- if (increment)
- (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::PAYLOAD_DETECTS]++;
- else if ((*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::PAYLOAD_DETECTS])
- (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::PAYLOAD_DETECTS]--;
+ (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::PAYLOAD_DETECTS]++;
}
void AppIdPegCounts::inc_user_count(AppId id)
(*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::MISC_DETECTS]++;
}
+void AppIdPegCounts::inc_referred_count(AppId id)
+{
+ (*appid_peg_counts)[get_stats_index(id)].stats[DetectorPegs::REFERRED_DETECTS]++;
+}
+
uint32_t AppIdPegCounts::get_stats_index(AppId id)
{
std::unordered_map<AppId, uint32_t>::iterator stats_idx_it = appid_detector_pegs_idx.find(id);
LogLabel("detected apps and services");
char buff[120];
- snprintf(buff, sizeof(buff), "%25.25s: %-10s %-10s %-10s %-10s %-10s %-10s %-10s",
- "Application", "Flows", "Clients", "Users", "Payloads", "Misc", "Incompat.", "Failed");
+ snprintf(buff, sizeof(buff), "%25.25s: %-10s %-10s %-10s %-10s %-10s %-10s",
+ "Application", "Services", "Clients", "Users", "Payloads", "Misc", "Referred");
LogText(buff);
for (unsigned i = 0; i < app_num; i++)
#include "main/thread.h"
#include "utils/util.h"
+struct AppIdStats
+{
+ PegCount packets;
+ PegCount processed_packets;
+ PegCount ignored_packets;
+ PegCount total_sessions;
+ PegCount service_cache_prunes;
+ PegCount service_cache_adds;
+ PegCount service_cache_removes;
+ PegCount odp_reload_ignored_pkts;
+ PegCount tp_reload_ignored_pkts;
+};
+
class AppIdPegCounts
{
public:
USER_DETECTS,
PAYLOAD_DETECTS,
MISC_DETECTS,
- INCOMPATIBLE,
- FAILED,
+ REFERRED_DETECTS,
NUM_APPID_DETECTOR_PEGS
};
void print(const char* app, char* buf, int buf_size)
{
- snprintf(buf, buf_size, "%25.25s: " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10")
+ snprintf(buf, buf_size, "%25.25s: " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10")
" " FMTu64("-10") " " FMTu64("-10") " " FMTu64("-10"), app,
- stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6]);
+ stats[SERVICE_DETECTS], stats[CLIENT_DETECTS], stats[USER_DETECTS],
+ stats[PAYLOAD_DETECTS], stats[MISC_DETECTS], stats[REFERRED_DETECTS]);
}
};
static void cleanup_peg_info();
static void cleanup_dynamic_sum();
- static void update_service_count(AppId id, bool increment);
- static void update_client_count(AppId id, bool increment);
- static void update_payload_count(AppId id, bool increment);
-
+ static void inc_service_count(AppId id);
+ static void inc_client_count(AppId id);
+ static void inc_payload_count(AppId id);
static void inc_user_count(AppId id);
static void inc_misc_count(AppId id);
-
- static void inc_incompatible_count(AppId id)
- {
- if ( appid_detector_pegs_idx[id] != appid_detectors_info.size() )
- (*appid_peg_counts)[appid_detector_pegs_idx[id]].stats[DetectorPegs::INCOMPATIBLE]++;
- }
-
- static void inc_failed_count(AppId id)
- {
- if ( appid_detector_pegs_idx[id] != appid_detectors_info.size() )
- (*appid_peg_counts)[appid_detector_pegs_idx[id]].stats[DetectorPegs::FAILED]++;
- }
+ static void inc_referred_count(AppId id);
static void sum_stats();
static void print();
+++ /dev/null
-//--------------------------------------------------------------------------
-// Copyright (C) 2019-2021 Cisco and/or its affiliates. All rights reserved.
-//
-// 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.
-//--------------------------------------------------------------------------
-
-// appid_pegs.h author Silviu Minut <sminut@cisco.com>
-
-#ifndef APPID_PEGS_H
-#define APPID_PEGS_H
-
-#include "framework/counts.h"
-
-struct AppIdStats
-{
- PegCount packets;
- PegCount processed_packets;
- PegCount ignored_packets;
- PegCount total_sessions;
- PegCount appid_unknown;
- PegCount service_cache_prunes;
- PegCount service_cache_adds;
- PegCount service_cache_removes;
- PegCount odp_reload_ignored_pkts;
- PegCount tp_reload_ignored_pkts;
-};
-
-#endif
encrypted.misc_id = pick_ss_misc_app_id();
encrypted.referred_id = pick_ss_referred_payload_app_id();
- // After decryption, new application ids might be detected
- // overriding existing ones from the encrypted flow. Set overwritten id
- // to update app statistics when new AppId is detected.
- if (encrypted.service_id > APP_ID_NONE and client_inferred_service_id == APP_ID_NONE)
- api.service.set_overwritten_id(encrypted.service_id);
-
- if (encrypted.client_id > APP_ID_NONE)
- api.client.set_overwritten_id(encrypted.client_id);
-
- if (encrypted.payload_id > APP_ID_NONE)
- api.payload.set_overwritten_id(encrypted.payload_id);
-
reinit_session_data(change_bits, curr_tp_appid_ctxt);
if (appidDebug->is_active())
LogMessage("AppIdDbg %s SSL decryption is available, restarting app detection\n",
#include "flow/ha.h"
#include "managers/inspector_manager.h"
#include "appid_inspector.h"
+#include "appid_peg_counts.h"
#include "appid_session.h"
#include "appid_types.h"
#include "service_plugins/service_bootp.h"
void AppIdSessionApi::set_ss_application_ids(AppId service_id, AppId client_id,
AppId payload_id, AppId misc_id, AppId referred_id, AppidChangeBits& change_bits, Flow& flow)
{
- if (application_ids[APP_PROTOID_SERVICE] != service_id)
- {
- application_ids[APP_PROTOID_SERVICE] = service_id;
- change_bits.set(APPID_SERVICE_BIT);
- if (flow.ha_state)
- flow.ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
- }
- if (application_ids[APP_PROTOID_CLIENT] != client_id)
- {
- application_ids[APP_PROTOID_CLIENT] = client_id;
- change_bits.set(APPID_CLIENT_BIT);
- if (flow.ha_state)
- flow.ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
- }
- if (application_ids[APP_PROTOID_PAYLOAD] != payload_id)
- {
- application_ids[APP_PROTOID_PAYLOAD] = payload_id;
- change_bits.set(APPID_PAYLOAD_BIT);
- if (flow.ha_state)
- flow.ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
- }
+ set_application_ids_service(service_id, change_bits, flow);
+ set_ss_application_ids(client_id, payload_id, change_bits, flow);
+
if (application_ids[APP_PROTOID_MISC] != misc_id)
{
application_ids[APP_PROTOID_MISC] = misc_id;
+ AppIdPegCounts::inc_misc_count(misc_id);
change_bits.set(APPID_MISC_BIT);
if (flow.ha_state)
flow.ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
if (application_ids[APP_PROTOID_REFERRED] != referred_id)
{
application_ids[APP_PROTOID_REFERRED] = referred_id;
+ AppIdPegCounts::inc_referred_count(referred_id);
change_bits.set(APPID_REFERRED_BIT);
}
}
if (application_ids[APP_PROTOID_PAYLOAD] != payload_id)
{
application_ids[APP_PROTOID_PAYLOAD] = payload_id;
+ AppIdPegCounts::inc_payload_count(payload_id);
change_bits.set(APPID_PAYLOAD_BIT);
if (flow.ha_state)
flow.ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
if (application_ids[APP_PROTOID_CLIENT] != client_id)
{
application_ids[APP_PROTOID_CLIENT] = client_id;
+ AppIdPegCounts::inc_client_count(client_id);
change_bits.set(APPID_CLIENT_BIT);
if (flow.ha_state)
flow.ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
}
- if (application_ids[APP_PROTOID_PAYLOAD] != payload_id)
- {
- application_ids[APP_PROTOID_PAYLOAD] = payload_id;
- change_bits.set(APPID_PAYLOAD_BIT);
- if (flow.ha_state)
- flow.ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
- }
+ set_ss_application_ids_payload(payload_id, change_bits, flow);
}
void AppIdSessionApi::set_application_ids_service(AppId service_id, AppidChangeBits& change_bits,
if (application_ids[APP_PROTOID_SERVICE] != service_id)
{
application_ids[APP_PROTOID_SERVICE] = service_id;
+ AppIdPegCounts::inc_service_count(service_id);
change_bits.set(APPID_SERVICE_BIT);
if (flow.ha_state)
flow.ha_state->add(FlowHAState::MODIFIED | FlowHAState::MAJOR);
// Stubs for AppIdPegCounts
// LCOV_EXCL_START
-void AppIdPegCounts::update_service_count(AppId, bool) { }
-void AppIdPegCounts::update_client_count(AppId, bool) { }
+void AppIdPegCounts::inc_service_count(AppId) { }
+void AppIdPegCounts::inc_client_count(AppId) { }
void AppIdPegCounts::inc_user_count(AppId) { }
-void AppIdPegCounts::update_payload_count(AppId, bool) { }
+void AppIdPegCounts::inc_payload_count(AppId) { }
THREAD_LOCAL AppIdStats appid_stats;
void AppIdModule::sum_stats(bool) { }
}
void ApplicationDescriptor::set_id(AppId){}
void ServiceAppDescriptor::set_id(AppId, OdpContext&){}
-void ServiceAppDescriptor::update_stats(AppId, bool){}
-void ClientAppDescriptor::update_user(AppId, const char*, AppidChangeBits&){}
-void ClientAppDescriptor::update_stats(AppId, bool) {}
-void PayloadAppDescriptor::update_stats(AppId, bool) {}
void ServiceDiscovery::initialize(AppIdInspector&) {}
void ServiceDiscovery::reload() {}
void AppIdDetector::add_app(const snort::Packet&, AppIdSession&, AppidSessionDirection, AppId, AppId, const char*, AppidChangeBits&){}
void ApplicationDescriptor::set_id(AppId){}
void ServiceAppDescriptor::set_id(AppId, OdpContext&){}
-void ServiceAppDescriptor::update_stats(AppId, bool){}
void ClientAppDescriptor::update_user(AppId, const char*, AppidChangeBits&){}
-void ClientAppDescriptor::update_stats(AppId, bool) {}
-void PayloadAppDescriptor::update_stats(AppId, bool) {}
void AppIdDiscovery::add_pattern_data(AppIdDetector*, snort::SearchTool&, int,
const uint8_t* const, unsigned, unsigned){}
void AppIdDiscovery::register_detector(const std::string&, AppIdDetector*, IpProtocol){}
void* AppIdSession::get_flow_data(unsigned) const { return smb_data;}
// Stubs for AppIdPegCounts
-void AppIdPegCounts::update_service_count(AppId, bool) { }
-void AppIdPegCounts::update_client_count(AppId, bool) { }
-void AppIdPegCounts::update_payload_count(AppId, bool) { }
+void AppIdPegCounts::inc_service_count(AppId, bool) { }
+void AppIdPegCounts::inc_client_count(AppId, bool) { }
+void AppIdPegCounts::inc_payload_count(AppId, bool) { }
THREAD_LOCAL AppIdStats appid_stats;
void AppIdModule::show_dynamic_stats() { }
#include "utils/cpp_macros.h"
#include "utils/util.h"
-#include "appid_pegs.h"
+#include "appid_peg_counts.h"
#include "service_plugins/service_discovery.h"
class ServiceDetector;
set_id(app_id);
deferred = odp_ctxt.get_app_info_mgr().get_app_info_flags(app_id, APPINFO_FLAG_DEFER);
}
-void ServiceAppDescriptor::update_stats(AppId, bool){}
void ServiceAppDescriptor::set_port_service_id(AppId){}
void ClientAppDescriptor::update_user(AppId, const char*, AppidChangeBits&){}
-void ClientAppDescriptor::update_stats(AppId, bool) {}
-void PayloadAppDescriptor::update_stats(AppId, bool) {}
// Stubs for AppIdModule
AppIdModule::AppIdModule(): Module("appid_mock", "appid_mock_help") {}
session->flow = &flow;
mock_hsession = new AppIdHttpSession(*session, 0);
appidDebug = new AppIdDebug();
+ AppIdPegCounts::init_pegs();
}
void teardown() override
delete appidDebug;
delete mock_hsession;
delete session;
+ AppIdPegCounts::cleanup_pegs();
}
};
DiscoveryFilter::~DiscoveryFilter(){}
void ApplicationDescriptor::set_id(AppId app_id){ my_id = app_id;}
void ServiceAppDescriptor::set_id(AppId app_id, OdpContext&){ set_id(app_id); }
-void ServiceAppDescriptor::update_stats(AppId, bool){}
void ServiceAppDescriptor::set_port_service_id(AppId app_id){ port_service_id = app_id;}
void ClientAppDescriptor::update_user(AppId app_id, const char* username, AppidChangeBits& change_bits)
{
my_user_id = app_id;
change_bits.set(APPID_USER_INFO_BIT);
}
-void ClientAppDescriptor::update_stats(AppId, bool) {}
-void PayloadAppDescriptor::update_stats(AppId, bool) {}
AppIdDiscovery::~AppIdDiscovery() = default;
void ClientDiscovery::initialize(AppIdInspector&) { }
void ApplicationDescriptor::set_id(const Packet&, AppIdSession&, AppidSessionDirection, AppId, AppidChangeBits&) { }
void ApplicationDescriptor::set_id(AppId){}
void ServiceAppDescriptor::set_id(AppId, OdpContext&){}
-void ServiceAppDescriptor::update_stats(AppId, bool){}
void ServiceAppDescriptor::set_port_service_id(AppId){}
void ClientAppDescriptor::update_user(AppId, const char*, AppidChangeBits&){}
-void ClientAppDescriptor::update_stats(AppId, bool) {}
-void PayloadAppDescriptor::update_stats(AppId, bool) {}
AppIdConfig::~AppIdConfig() = default;
OdpContext::OdpContext(const AppIdConfig&, snort::SnortConfig*) { }
AppIdConfig stub_config;