fix: use only new config instead of old command line options

Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
This commit is contained in:
Andrea Terzolo 2023-11-17 13:04:46 +01:00 committed by poiana
parent f3f56db5ca
commit 1ee6569a5d
8 changed files with 27 additions and 13 deletions

View File

@ -30,7 +30,7 @@ TEST(ActionConfigureSyscallBufferNum, variable_number_of_CPUs)
// not modern ebpf engine, we do nothing // not modern ebpf engine, we do nothing
{ {
falco::app::state s; falco::app::state s;
s.options.modern_bpf = false; s.config->m_engine_mode = engine_kind_t::MODERN_EBPF;
EXPECT_ACTION_OK(action(s)); EXPECT_ACTION_OK(action(s));
} }
@ -38,7 +38,7 @@ TEST(ActionConfigureSyscallBufferNum, variable_number_of_CPUs)
// default `m_cpus_for_each_syscall_buffer` to online CPU number // default `m_cpus_for_each_syscall_buffer` to online CPU number
{ {
falco::app::state s; falco::app::state s;
s.options.modern_bpf = true; s.config->m_engine_mode = engine_kind_t::MODERN_EBPF;
s.config->m_modern_ebpf.m_cpus_for_each_syscall_buffer = online_cpus + 1; s.config->m_modern_ebpf.m_cpus_for_each_syscall_buffer = online_cpus + 1;
EXPECT_ACTION_OK(action(s)); EXPECT_ACTION_OK(action(s));
EXPECT_EQ(s.config->m_modern_ebpf.m_cpus_for_each_syscall_buffer, online_cpus); EXPECT_EQ(s.config->m_modern_ebpf.m_cpus_for_each_syscall_buffer, online_cpus);
@ -48,7 +48,7 @@ TEST(ActionConfigureSyscallBufferNum, variable_number_of_CPUs)
// we don't modify `m_cpus_for_each_syscall_buffer` // we don't modify `m_cpus_for_each_syscall_buffer`
{ {
falco::app::state s; falco::app::state s;
s.options.modern_bpf = true; s.config->m_engine_mode = engine_kind_t::MODERN_EBPF;
s.config->m_modern_ebpf.m_cpus_for_each_syscall_buffer = online_cpus - 1; s.config->m_modern_ebpf.m_cpus_for_each_syscall_buffer = online_cpus - 1;
EXPECT_ACTION_OK(action(s)); EXPECT_ACTION_OK(action(s));
EXPECT_EQ(s.config->m_modern_ebpf.m_cpus_for_each_syscall_buffer, online_cpus - 1); EXPECT_EQ(s.config->m_modern_ebpf.m_cpus_for_each_syscall_buffer, online_cpus - 1);

View File

@ -23,7 +23,7 @@ using namespace falco::app::actions;
falco::app::run_result falco::app::actions::configure_syscall_buffer_num(falco::app::state& s) falco::app::run_result falco::app::actions::configure_syscall_buffer_num(falco::app::state& s)
{ {
#ifdef __linux__ #ifdef __linux__
if(!s.options.modern_bpf) if(!s.is_modern_ebpf())
{ {
return run_result::ok(); return run_result::ok();
} }

View File

@ -39,10 +39,10 @@ falco::app::run_result falco::app::actions::create_requested_paths(falco::app::s
{ {
// This is bad: parsing gvisor config to get endpoint // This is bad: parsing gvisor config to get endpoint
// to be able to auto-create the path to the file for the user. // to be able to auto-create the path to the file for the user.
std::ifstream reader(s.options.gvisor_config); std::ifstream reader(s.config->m_gvisor.m_config);
if (reader.fail()) if (reader.fail())
{ {
return run_result::fatal(s.options.gvisor_config + ": cannot open file"); return run_result::fatal(s.config->m_gvisor.m_config + ": cannot open file");
} }
nlohmann::json parsed_json; nlohmann::json parsed_json;
@ -53,7 +53,7 @@ falco::app::run_result falco::app::actions::create_requested_paths(falco::app::s
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
return run_result::fatal(s.options.gvisor_config + ": cannot parse JSON: " + e.what()); return run_result::fatal(s.config->m_gvisor.m_config + ": cannot parse JSON: " + e.what());
} }
try try
@ -62,7 +62,7 @@ falco::app::run_result falco::app::actions::create_requested_paths(falco::app::s
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
return run_result::fatal(s.options.gvisor_config + ": failed to fetch config.endpoint: " + e.what()); return run_result::fatal(s.config->m_gvisor.m_config + ": failed to fetch config.endpoint: " + e.what());
} }
int ret = create_dir(gvisor_socket); int ret = create_dir(gvisor_socket);

View File

@ -75,7 +75,7 @@ void falco::app::actions::print_enabled_event_sources(falco::app::state& s)
} }
else else
{ {
if (src != falco_common::syscall_source || s.options.nodriver) if (src != falco_common::syscall_source || s.is_nodriver())
{ {
falco_logger::log(falco_logger::level::WARNING, "Enabled event source '" falco_logger::log(falco_logger::level::WARNING, "Enabled event source '"
+ src + "' can be opened with multiple loaded plugins, will use only '" + src + "' can be opened with multiple loaded plugins, will use only '"
@ -84,7 +84,7 @@ void falco::app::actions::print_enabled_event_sources(falco::app::state& s)
} }
} }
} }
if (!first_plugin && s.options.nodriver) if (!first_plugin && s.is_nodriver())
{ {
falco_logger::log(falco_logger::level::WARNING, "Enabled event source '" falco_logger::log(falco_logger::level::WARNING, "Enabled event source '"
+ src + "' will be opened with no driver, no event will be produced"); + src + "' will be opened with no driver, no event will be produced");
@ -126,4 +126,3 @@ void falco::app::actions::format_plugin_info(std::shared_ptr<sinsp_plugin> p, st
os << " - Async Events" << std::endl; os << " - Async Events" << std::endl;
} }
} }

View File

@ -27,6 +27,10 @@ using namespace falco::app::actions;
// applies legacy/in-deprecation options to the current state // applies legacy/in-deprecation options to the current state
static falco::app::run_result apply_deprecated_options(falco::app::state& s) static falco::app::run_result apply_deprecated_options(falco::app::state& s)
{ {
// Please note: is not possible to mix command line options and configs to obtain a configuration
// we need to use only one method. For example, is not possible to set the gvisor-config through
// the command line and the gvisor-root through the config file.
//
// If overridden from CLI options (soon to be removed), // If overridden from CLI options (soon to be removed),
// use the requested driver. // use the requested driver.
if (getenv(FALCO_BPF_ENV_VARIABLE)) if (getenv(FALCO_BPF_ENV_VARIABLE))

View File

@ -39,7 +39,8 @@ options::options()
markdown(false), markdown(false),
modern_bpf(false), modern_bpf(false),
dry_run(false), dry_run(false),
nodriver(false) nodriver(false),
trace_filename("")
{ {
} }

View File

@ -155,6 +155,16 @@ struct state
return config->m_engine_mode == engine_kind_t::GVISOR; return config->m_engine_mode == engine_kind_t::GVISOR;
} }
inline bool is_modern_ebpf() const
{
return config->m_engine_mode == engine_kind_t::MODERN_EBPF;
}
inline bool is_nodriver() const
{
return config->m_engine_mode == engine_kind_t::NONE;
}
inline bool is_source_enabled(const std::string& src) const inline bool is_source_enabled(const std::string& src) const
{ {
return enabled_sources.find(falco_common::syscall_source) != enabled_sources.end(); return enabled_sources.find(falco_common::syscall_source) != enabled_sources.end();

View File

@ -122,7 +122,7 @@ void falco_configuration::load_engine_config(const std::string& config_name, con
} }
else else
{ {
throw std::logic_error("Error reading config file (" + config_name + "): wrong engine.kind specified."); throw std::logic_error("Error reading config file (" + config_name + "): engine.kind '"+ driver_mode_str + "' is not a valid kind.");
} }
switch (m_engine_mode) switch (m_engine_mode)