#include <DaemonService.hpp>
Classes | |
| struct | CachedVerdict |
Public Member Functions | |
| DaemonService (bsc::config::Config config) | |
| void | run () |
| void | stop () |
Private Member Functions | |
| void | scan_connections () |
| bool | desktop_allows_activity () const |
| void | set_desktop_active (bool active) |
| void | handle_proc_event (const bsc::netlink::ProcEvent &ev) |
| void | heartbeat () |
| void | reload_rules () |
| void | reload_firewall () |
| void | handle_notification (const bsc::ui::NotificationEvent &ev) |
| bsc::netfilter::Decision | decide_connection (bsc::model::Connection conn, bool realtime, bool allow_blocking_ask=true) |
| void | persist_learned_rule (const bsc::model::Connection &conn, const bsc::rule::Rule &decision) |
| void | remember_connection (const bsc::model::Connection &conn) |
| void | enrich_from_recent_flows (bsc::model::Connection &conn) |
| void | enrich_from_recent_processes (bsc::model::Connection &conn, std::chrono::milliseconds max_age=std::chrono::milliseconds(5000)) |
| bool | rules_changed () const |
| std::optional< CachedVerdict > | verdict_lookup (const bsc::model::Connection &c) const |
| void | verdict_store (const bsc::model::Connection &c, const bsc::rule::Rule &r) |
Static Private Member Functions | |
| static std::chrono::milliseconds | parse_interval (const std::string &v, std::chrono::milliseconds def=std::chrono::seconds(5)) |
| static std::string | verdict_key (const bsc::model::Connection &c) |
Private Attributes | |
| bsc::config::Config | config_ |
| bsc::fw::Firewall | firewall_ |
| bsc::net::DnsResolver | dns_ |
| bsc::netlink::ProcEventMonitor | proc_events_ |
| bsc::net::SocketSnapshot | net_ |
| bsc::netfilter::NFQueue | nfqueue_ |
| bsc::proc::ProcMon | proc_ |
| bsc::rule::Loader | rules_ |
| bsc::stats::Statistics | stats_ |
| bsc::ui::UIClient | ui_ |
| bsc::task::TaskRunner | tasks_ |
| std::atomic_bool | running_ {true} |
| std::mutex | seen_mutex_ |
| std::set< std::string > | seen_ |
| std::mutex | rules_reload_mutex_ |
| std::mutex | flow_mutex_ |
| std::unordered_map< std::string, std::pair< bsc::model::Connection, std::chrono::steady_clock::time_point > > | recent_flows_ |
| std::mutex | verdict_cache_mutex_ |
| std::unordered_map< std::string, CachedVerdict > | verdict_cache_ |
| std::atomic_bool | is_asking_ {false} |
| std::atomic_bool | desktop_active_ {false} |
| std::atomic_bool | inactive_notice_logged_ {false} |
| std::filesystem::file_time_type | rules_mtime_ {} |
| std::chrono::steady_clock::time_point | start_time_ {std::chrono::steady_clock::now()} |
Definition at line 23 of file DaemonService.hpp.
|
explicit |
Definition at line 77 of file DaemonService.cpp.
References config_, firewall_, bsc::rule::Loader::load_aliases(), bsc::rule::Loader::load_directory(), bsc::config::Config::RulesOptions::path, bsc::config::Config::rules, rules_, rules_changed(), stats_, and ui_.
Referenced by rules_changed().
|
private |
Definition at line 544 of file DaemonService.cpp.
References bsc::netfilter::Accept, config_, decide_connection(), desktop_allows_activity(), dns_, bsc::netfilter::Drop, bsc::model::Connection::dst_host, bsc::model::Connection::dst_ip, bsc::model::Connection::dst_port, enrich_from_recent_flows(), enrich_from_recent_processes(), bsc::logging::Logger::instance(), is_asking_, persist_learned_rule(), proc_, bsc::model::Connection::process_comm, bsc::model::Connection::process_id, bsc::model::Connection::process_path, bsc::model::Connection::protocol, remember_connection(), rules_, stats_, ui_, bsc::model::Connection::user_id, bsc::netfilter::Decision::verdict, verdict_lookup(), and verdict_store().
Referenced by decide_connection(), run(), and scan_connections().
|
private |
Definition at line 234 of file DaemonService.cpp.
References desktop_active_, desktop_allows_activity(), and ui_.
Referenced by decide_connection(), desktop_allows_activity(), and scan_connections().
|
private |
Definition at line 458 of file DaemonService.cpp.
References bsc::model::Connection::dst_ip, bsc::model::Connection::dst_port, enrich_from_recent_flows(), flow_mutex_, bsc::model::Connection::process_args, bsc::model::Connection::process_checksums, bsc::model::Connection::process_comm, bsc::model::Connection::process_cwd, bsc::model::Connection::process_env, bsc::model::Connection::process_id, bsc::model::Connection::process_path, bsc::model::Connection::process_tree, bsc::model::Connection::protocol, recent_flows_, bsc::model::Connection::src_ip, bsc::model::Connection::src_port, and bsc::model::Connection::user_id.
Referenced by decide_connection(), enrich_from_recent_flows(), and run().
|
private |
Definition at line 485 of file DaemonService.cpp.
References enrich_from_recent_processes(), proc_, bsc::model::Connection::process_comm, bsc::model::Connection::process_id, bsc::model::Connection::process_path, and bsc::model::Connection::user_id.
Referenced by decide_connection(), enrich_from_recent_processes(), and run().
|
private |
Definition at line 298 of file DaemonService.cpp.
References config_, bsc::ui::NotificationEvent::data, firewall_, handle_notification(), heartbeat(), bsc::logging::Logger::instance(), parse_interval(), reload_firewall(), reload_rules(), bsc::ui::NotificationEvent::rules, rules_, bsc::config::save_file(), scan_connections(), set_desktop_active(), bsc::logging::Logger::set_level(), bsc::logging::Logger::set_microseconds(), bsc::logging::Logger::set_utc(), stop(), tasks_, and bsc::ui::NotificationEvent::type.
Referenced by handle_notification(), and run().
|
private |
Definition at line 384 of file DaemonService.cpp.
References config_, bsc::netlink::ProcEvent::Exec, bsc::netlink::ProcEvent::Exit, bsc::netlink::ProcEvent::exit_code, bsc::netlink::ProcEvent::Fork, handle_proc_event(), bsc::logging::Logger::instance(), bsc::netlink::ProcEvent::parent_pid, bsc::netlink::ProcEvent::parent_tgid, bsc::netlink::ProcEvent::pid, proc_, bsc::netlink::ProcEvent::tgid, and bsc::netlink::ProcEvent::type.
Referenced by handle_proc_event().
|
private |
Definition at line 681 of file DaemonService.cpp.
References heartbeat(), stats_, and ui_.
Referenced by handle_notification(), heartbeat(), and run().
|
staticprivate |
Definition at line 67 of file DaemonService.cpp.
Referenced by handle_notification(), and run().
|
private |
Definition at line 401 of file DaemonService.cpp.
References bsc::rule::Rule::action, config_, bsc::rule::Rule::created, bsc::rule::Operator::data, bsc::rule::Rule::description, bsc::model::Connection::dst_host, bsc::model::Connection::dst_ip, bsc::model::Connection::dst_port, bsc::rule::Rule::duration, bsc::rule::Rule::enabled, bsc::rule::List, bsc::rule::Operator::list, bsc::rule::Rule::name, bsc::rule::Rule::nolog, bsc::rule::Rule::op, bsc::rule::Operator::operand, persist_learned_rule(), bsc::rule::Rule::precedence, bsc::model::Connection::process_comm, bsc::model::Connection::process_id, bsc::model::Connection::process_path, reload_rules(), rules_, bsc::rule::Simple, bsc::rule::Operator::type, and ui_.
Referenced by decide_connection(), and persist_learned_rule().
|
private |
Definition at line 283 of file DaemonService.cpp.
References _, config_, firewall_, bsc::logging::Logger::instance(), reload_firewall(), ui_, and bsc::logging::Logger::warning().
Referenced by handle_notification(), reload_firewall(), and run().
|
private |
Definition at line 274 of file DaemonService.cpp.
References config_, reload_rules(), rules_, rules_changed(), and rules_reload_mutex_.
Referenced by handle_notification(), persist_learned_rule(), reload_rules(), and run().
|
private |
Definition at line 445 of file DaemonService.cpp.
References flow_mutex_, bsc::model::Connection::key(), bsc::model::Connection::process_id, bsc::model::Connection::process_path, recent_flows_, remember_connection(), and bsc::model::Connection::user_id.
Referenced by decide_connection(), and remember_connection().
|
private |
Definition at line 261 of file DaemonService.cpp.
References config_, DaemonService(), rules_changed(), and rules_mtime_.
Referenced by DaemonService(), reload_rules(), and rules_changed().
| void bsc::service::DaemonService::run | ( | ) |
Definition at line 85 of file DaemonService.cpp.
References bsc::config::Config::ServerConfig::address, bsc::netfilter::available(), config_, bsc::config::Config::FwOptions::config_path, bsc::config::Config::TasksOptions::config_path, bsc::netfilter::PacketInfo::connection, decide_connection(), bsc::config::Config::ebpf_obj_path, bsc::net::SocketSnapshot::enrich_connection(), enrich_from_recent_flows(), enrich_from_recent_processes(), bsc::task::TaskRunner::every(), firewall_, bsc::config::Config::fw_options, handle_notification(), heartbeat(), bsc::fw::Firewall::install_nfqueue_rule(), bsc::logging::Logger::instance(), bsc::net::SocketSnapshot::invalidate_cache(), bsc::config::Config::FwOptions::monitor_interval, net_, nfqueue_, bsc::netfilter::NFQueue::open(), parse_interval(), bsc::ui::UIClient::post_alert(), proc_events_, bsc::config::Config::proc_monitor_method, bsc::config::Config::FwOptions::queue_bypass, bsc::config::Config::FwOptions::queue_num, bsc::fw::Firewall::reload(), reload_firewall(), reload_rules(), bsc::fw::Firewall::remove_nfqueue_rule(), scan_connections(), bsc::config::Config::server, bsc::ui::UIClient::set_notification_handler(), bsc::netlink::ProcEventMonitor::start(), bsc::ui::UIClient::start(), bsc::net::SocketSnapshot::start_ebpf(), bsc::config::Config::tasks, tasks_, ui_, bsc::netfilter::PacketInfo::uid, and bsc::model::Connection::user_id.
|
private |
Definition at line 657 of file DaemonService.cpp.
References config_, decide_connection(), desktop_allows_activity(), inactive_notice_logged_, bsc::logging::Logger::info(), bsc::logging::Logger::instance(), net_, scan_connections(), seen_, and seen_mutex_.
Referenced by handle_notification(), run(), and scan_connections().
|
private |
Definition at line 238 of file DaemonService.cpp.
References desktop_active_, inactive_notice_logged_, bsc::logging::Logger::instance(), net_, seen_, seen_mutex_, and set_desktop_active().
Referenced by handle_notification(), and set_desktop_active().
| void bsc::service::DaemonService::stop | ( | ) |
Definition at line 232 of file DaemonService.cpp.
References running_, and stop().
Referenced by handle_notification(), and stop().
|
staticprivate |
Definition at line 508 of file DaemonService.cpp.
References bsc::model::Connection::dst_host, bsc::model::Connection::dst_ip, bsc::model::Connection::dst_port, bsc::model::Connection::process_comm, bsc::model::Connection::process_id, bsc::model::Connection::process_path, and verdict_key().
Referenced by verdict_key(), verdict_lookup(), and verdict_store().
|
private |
Definition at line 516 of file DaemonService.cpp.
References verdict_cache_, verdict_cache_mutex_, verdict_key(), and verdict_lookup().
Referenced by decide_connection(), and verdict_lookup().
|
private |
Definition at line 529 of file DaemonService.cpp.
References verdict_cache_, verdict_cache_mutex_, verdict_key(), and verdict_store().
Referenced by decide_connection(), and verdict_store().
|
private |
Definition at line 48 of file DaemonService.hpp.
Referenced by DaemonService(), decide_connection(), handle_notification(), handle_proc_event(), persist_learned_rule(), reload_firewall(), reload_rules(), rules_changed(), run(), and scan_connections().
|
private |
Definition at line 92 of file DaemonService.hpp.
Referenced by desktop_allows_activity(), and set_desktop_active().
|
private |
Definition at line 50 of file DaemonService.hpp.
Referenced by decide_connection().
|
private |
Definition at line 49 of file DaemonService.hpp.
Referenced by DaemonService(), handle_notification(), reload_firewall(), and run().
|
mutableprivate |
Definition at line 63 of file DaemonService.hpp.
Referenced by enrich_from_recent_flows(), and remember_connection().
|
private |
Definition at line 93 of file DaemonService.hpp.
Referenced by scan_connections(), and set_desktop_active().
|
private |
Definition at line 87 of file DaemonService.hpp.
Referenced by decide_connection().
|
private |
Definition at line 52 of file DaemonService.hpp.
Referenced by run(), scan_connections(), and set_desktop_active().
|
private |
Definition at line 53 of file DaemonService.hpp.
Referenced by run().
|
private |
Definition at line 54 of file DaemonService.hpp.
Referenced by decide_connection(), enrich_from_recent_processes(), and handle_proc_event().
|
private |
Definition at line 51 of file DaemonService.hpp.
Referenced by run().
|
private |
Definition at line 64 of file DaemonService.hpp.
Referenced by enrich_from_recent_flows(), and remember_connection().
|
private |
Definition at line 55 of file DaemonService.hpp.
Referenced by DaemonService(), decide_connection(), handle_notification(), persist_learned_rule(), and reload_rules().
|
private |
Definition at line 95 of file DaemonService.hpp.
Referenced by rules_changed().
|
mutableprivate |
Definition at line 62 of file DaemonService.hpp.
Referenced by reload_rules().
|
private |
Definition at line 59 of file DaemonService.hpp.
Referenced by stop().
|
private |
Definition at line 61 of file DaemonService.hpp.
Referenced by scan_connections(), and set_desktop_active().
|
private |
Definition at line 60 of file DaemonService.hpp.
Referenced by scan_connections(), and set_desktop_active().
|
private |
Definition at line 96 of file DaemonService.hpp.
|
private |
Definition at line 56 of file DaemonService.hpp.
Referenced by DaemonService(), decide_connection(), and heartbeat().
|
private |
Definition at line 58 of file DaemonService.hpp.
Referenced by handle_notification(), and run().
|
private |
Definition at line 57 of file DaemonService.hpp.
Referenced by DaemonService(), decide_connection(), desktop_allows_activity(), heartbeat(), persist_learned_rule(), reload_firewall(), and run().
|
private |
Definition at line 77 of file DaemonService.hpp.
Referenced by verdict_lookup(), and verdict_store().
|
mutableprivate |
Definition at line 76 of file DaemonService.hpp.
Referenced by verdict_lookup(), and verdict_store().