From f03555b98fa6b9d83cb4e45fbe8f4f42a0e7bfd4 Mon Sep 17 00:00:00 2001 From: Eliska Cervinkova Date: Tue, 22 Sep 2026 14:11:50 +0200 Subject: [PATCH] refactor: replace deprecated ifconfig tool --- README.md | 1 - src/argument.rs | 4 ---- src/cpu_affinity.rs | 13 ++++++++----- src/main.rs | 7 ------- src/query/suriconf.json | 3 --- src/structures.rs | 2 -- src/suriconf.yaml | 1 - src/yaml.rs | 30 +++++------------------------- 8 files changed, 13 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index f51825a..8849493 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,6 @@ The following tools must be installed, and their paths must be accessible and sp |------|---------| | Suricata | 9.0.0-dev (d030a9c4e 2026-04-01) | | ethtool | 5.13 | -| ifconfig | net-tools 2.10-alpha | | ip | iproute2-6.8.0, libbpf 0.5.0 | ## Configuration diff --git a/src/argument.rs b/src/argument.rs index d3caebe..c8c2427 100644 --- a/src/argument.rs +++ b/src/argument.rs @@ -56,10 +56,6 @@ pub enum Commands { #[clap(short='e', long)] ethtool_bin: Option, - /// Ifconfig path to bin - #[clap(short='i', long)] - ifconfig_bin: Option, - /// IP path to bin #[clap(short='p', long)] ip_bin: Option, diff --git a/src/cpu_affinity.rs b/src/cpu_affinity.rs index 04476d9..f01b549 100644 --- a/src/cpu_affinity.rs +++ b/src/cpu_affinity.rs @@ -35,7 +35,6 @@ impl Module for CpuAffinityModule { Keys::interface, Keys::capture_mode, Keys::ethtool, - Keys::ifconfig, Keys::capture_kernel_drops, Keys::capture_kernel_packets, Keys::capture_errors, @@ -44,9 +43,9 @@ impl Module for CpuAffinityModule { Keys::ethtool_stat, Keys::flow_managers, Keys::flow_recyclers, - Keys::ifconfig, Keys::af_packet_interface_threads, - Keys::datetime + Keys::datetime, + Keys::ip ]; let questions: HashMap = @@ -350,6 +349,10 @@ impl CpuAffinityModule { answers.iter().find(|h| h.key == &Keys::ethtool).and_then(|h| h.value.as_str()).expect("Ethtool cannot be found.") } + fn get_ip_stat<'a>(&self, answers: &Vec>) -> &'a str { + answers.iter().find(|h| h.key == &Keys::ip).and_then(|h| h.value.as_str()).expect("Ip cannot be found.") + } + fn get_datetime_stat(&self, answers: &Vec>) -> DateTime { answers.iter().find(|h| h.key == &Keys::datetime) .and_then(|h| h.value.as_str()).and_then(|v| DateTime::parse_from_rfc3339(v).ok()) @@ -532,9 +535,9 @@ impl CpuAffinityModule { fn module_af_packet_tuning(&self, answers: &Vec>, nic_file: &mut File) { let interface = self.get_interface_stat(answers); let ethtool = self.get_ethtool_stat(answers); - let ifconfig = answers.iter().find(|h| h.key == &Keys::ifconfig).and_then(|h| h.value.as_str()).expect("Ifconfig cannot be found."); + let ip = self.get_ip_stat(answers); let wrk_cpu_set_len = self.get_wrk_cpu_set().len() as u64; - yaml::af_packet_tuning(interface, wrk_cpu_set_len, ethtool, ifconfig, nic_file); + yaml::af_packet_tuning(interface, wrk_cpu_set_len, ethtool, ip, nic_file); } fn module_set_rss(&self, answers: &Vec>, nic_file: &mut File) { diff --git a/src/main.rs b/src/main.rs index aa876fc..d5a129a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,13 +69,6 @@ fn main() { Ok(()) => {} } - match suriconf.find_ifconfig_executable_file() { - Err(e) => { - panic!("{}", e); - } - Ok(()) => {} - } - match suriconf.find_ip_executable_file() { Err(e) => { panic!("{}", e); diff --git a/src/query/suriconf.json b/src/query/suriconf.json index b0adf2f..64e76e6 100644 --- a/src/query/suriconf.json +++ b/src/query/suriconf.json @@ -15,9 +15,6 @@ "ethtool" : { "path_to_value": "/ethtool-bin" }, - "ifconfig" : { - "path_to_value": "/ifconfig-bin" - }, "ip" :{ "path_to_value": "/ip-bin" diff --git a/src/structures.rs b/src/structures.rs index 12cce3c..ed9086b 100644 --- a/src/structures.rs +++ b/src/structures.rs @@ -262,7 +262,6 @@ pub enum Keys { // JUST FOR FLOW decoder_pkts, decoder_invalid, ethtool, - ifconfig, ip, ethtool_stat, af_packet_interface_threads @@ -367,7 +366,6 @@ impl Keys { "decoder_pkts" => Keys::decoder_pkts, "decoder_invalid" => Keys::decoder_invalid, "ethtool" => Keys::ethtool, - "ifconfig" => Keys::ifconfig, "ip" => Keys::ip, "ethtool_stat" => Keys::ethtool_stat, "af_packet_interface_threads" => Keys::af_packet_interface_threads, diff --git a/src/suriconf.yaml b/src/suriconf.yaml index 07131d2..43793c0 100644 --- a/src/suriconf.yaml +++ b/src/suriconf.yaml @@ -6,7 +6,6 @@ suriconf-version: 1.0-dev suri-configuration: suricata.yaml suricata-bin: /usr/bin/suricata ethtool-bin: /usr/bin/ethtool -ifconfig-bin: /usr/sbin/ifconfig ip-bin: /usr/sbin/ip log-dir: /var/log/suricata/ socket: /var/run/suricata/suricata-command.socket diff --git a/src/yaml.rs b/src/yaml.rs index cd63077..3b10e53 100644 --- a/src/yaml.rs +++ b/src/yaml.rs @@ -365,7 +365,7 @@ fn run_command_and_write_it_down(cmd: &str, args: &[&str], nic_file: &mut File) output } -pub fn af_packet_tuning(interface: &str, threads: u64, ethtool: &str, ifconfig: &str, nic_file: &mut File) { +pub fn af_packet_tuning(interface: &str, threads: u64, ethtool: &str, ip: &str, nic_file: &mut File) { run_command_and_write_it_down("sudo", &["sysctl", "-w", "net.core.rmem_max=268435456"], nic_file); run_command_and_write_it_down("sudo", &["sysctl", "-w", "net.core.netdev_max_backlog=16384"], nic_file); @@ -393,7 +393,7 @@ pub fn af_packet_tuning(interface: &str, threads: u64, ethtool: &str, ifconfig: None => { panic!("Unable to get driver.")} }; - run_command_and_write_it_down("sudo", &[format!("{ifconfig}").as_str(), format!("{interface}").as_str(), "down"], nic_file); + run_command_and_write_it_down("sudo", &[format!("{ip}").as_str(), "link", "set", format!("{interface}").as_str(), "down"], nic_file); run_command_and_write_it_down("sudo", &[format!("{ethtool}").as_str(), "-X", format!("{interface}").as_str(), "default"], nic_file); run_command_and_write_it_down("sudo", &[format!("{ethtool}").as_str(), "-L", interface, "combined", &threads.to_string()], nic_file); run_command_and_write_it_down("sudo", &[format!("{ethtool}").as_str(), "-K", interface, "rxhash", "on"], nic_file); @@ -403,7 +403,7 @@ pub fn af_packet_tuning(interface: &str, threads: u64, ethtool: &str, ifconfig: } - run_command_and_write_it_down("sudo", &[format!("{ifconfig}").as_str(), format!("{interface}").as_str(), "up"], nic_file); + run_command_and_write_it_down("sudo", &[format!("{ip}").as_str(), "link", "set", format!("{interface}").as_str(), "up"], nic_file); output = run_command_and_write_it_down("sudo", &[format!("{ethtool}").as_str(), "-x" ,format!("{interface}").as_str()], nic_file); @@ -565,8 +565,8 @@ pub fn set_interface_with_threads(suricata_string: &mut Value, suriconf: &Surico if shrink != 0 { // remove cpus to match RSS queues cpus.drain(0..shrink as usize); }; - let ifconfig = suriconf.ifconfig_bin.to_str().expect("Unable to transform path to Ifconfig to str."); - af_packet_tuning(&suriconf.interface, cpus.len() as u64, ethtool, ifconfig, &mut nic_file); + let ip = suriconf.ip_bin.to_str().expect("Unable to transform path to Ip to str."); + af_packet_tuning(&suriconf.interface, cpus.len() as u64, ethtool, ip, &mut nic_file); set_hard_irq(&suriconf.interface, &cpus, &mut nic_file); } @@ -723,7 +723,6 @@ pub struct Suriconf { pub suri_configuration: PathBuf, pub suricata_bin: PathBuf, pub ethtool_bin: PathBuf, - pub ifconfig_bin: PathBuf, pub ip_bin: PathBuf, pub log_dir: PathBuf, pub socket: PathBuf, @@ -754,14 +753,6 @@ impl Suriconf { } } - pub fn find_ifconfig_executable_file(&self) -> Result<(), String> { - if self.ifconfig_bin.is_executable() { - Ok(()) - } else { - Err(String::from("Unable to parse path to Ifconfig or Ifconfig is not executable.")) - } - } - pub fn find_ip_executable_file(&self) -> Result<(), String> { if self.ip_bin.is_executable() { Ok(()) @@ -824,13 +815,6 @@ impl Suriconf { self.find_ethtool_bin(suriconf_string).expect("Unable to parse path to Ethtool binary file.") }; - self.ifconfig_bin = if let Some(Commands::Suricata {ifconfig_bin: Some(p), ..}) = &args.cmd { - p.clone() - } - else { - self.find_ifconfig_bin(suriconf_string).expect("Unable to parse path to Ifconfig binary file.") - }; - self.ip_bin = if let Some(Commands::Suricata {ip_bin: Some(p), ..}) = &args.cmd { p.clone() } @@ -948,10 +932,6 @@ impl Suriconf { text.get("ethtool-bin").and_then(|c| c.as_str()).map(|c| PathBuf::from(c)) } - pub fn find_ifconfig_bin(&self, text: &Value) -> Option { - text.get("ifconfig-bin").and_then(|c| c.as_str()).map(|c| PathBuf::from(c)) - } - pub fn find_ip_bin(&self, text: &Value) -> Option { text.get("ip-bin").and_then(|c| c.as_str()).map(|c| PathBuf::from(c)) }