From 088f608614cb8c6032602040735f8ef6dac9599c Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Tue, 14 Feb 2023 22:06:57 +0000 Subject: [PATCH] #229 - Run cargo fmt to format everything. --- src/rust/lqos_bus/benches/socket.rs | 6 ++-- src/rust/lqos_bus/build.rs | 4 +-- .../lqos_bus/src/bus/persistent_client.rs | 6 ++-- .../lqos_bus/src/bus/unix_socket_server.rs | 4 ++- src/rust/lqos_config/src/authentication.rs | 4 +-- src/rust/lqos_config/src/program_control.rs | 5 ++- .../lqos_config/src/shaped_devices/mod.rs | 14 ++++---- .../lqos_node_manager/src/shaped_devices.rs | 7 ++-- .../lqos_node_manager/src/static_pages.rs | 4 +-- .../src/tracker/cache/cpu_ram.rs | 17 ++++----- .../src/tracker/cache_manager.rs | 13 ++++--- src/rust/lqos_node_manager/src/tracker/mod.rs | 15 ++++---- src/rust/lqos_python/src/blocking.rs | 9 +++-- src/rust/lqos_python/src/lib.rs | 22 ++++++------ src/rust/lqos_queue_tracker/benches/json.rs | 2 +- .../src/queue_structure/queue_node.rs | 6 +--- .../src/queue_types/tc_cake.rs | 12 ++----- .../src/queue_types/tc_fq_codel.rs | 4 +-- .../src/queue_types/tc_htb.rs | 4 +-- .../src/queue_types/tc_mq.rs | 4 +-- .../lqos_queue_tracker/src/tracking/mod.rs | 12 ++++--- .../src/tracking/watched_queues.rs | 4 +-- src/rust/lqos_sys/src/cpu_map.rs | 4 +-- src/rust/lqos_sys/src/ip_mapping/ip_to_map.rs | 9 ++--- src/rust/lqos_sys/src/lqos_kernel.rs | 3 +- src/rust/lqos_sys/src/xdp_ip_address.rs | 4 +-- src/rust/lqos_utils/src/unix_time.rs | 19 +++++----- src/rust/lqosd/src/lqos_daht_test.rs | 6 +--- src/rust/lqosd/src/main.rs | 10 +++--- src/rust/lqosd/src/throughput_tracker/mod.rs | 4 +-- .../src/throughput_tracker/tracking_data.rs | 35 ++++++++++++------- src/rust/lqosd/src/tuning/offloads.rs | 3 +- src/rust/lqtop/src/main.rs | 9 +++-- src/rust/rustfmt.toml | 4 +-- 34 files changed, 136 insertions(+), 152 deletions(-) diff --git a/src/rust/lqos_bus/benches/socket.rs b/src/rust/lqos_bus/benches/socket.rs index 010f4ea7..7c98248d 100644 --- a/src/rust/lqos_bus/benches/socket.rs +++ b/src/rust/lqos_bus/benches/socket.rs @@ -44,10 +44,8 @@ pub fn criterion_benchmark(c: &mut Criterion) { }); // Enable the Tokio runtime to test round-trip - let tokio_rt = tokio::runtime::Builder::new_current_thread() - .enable_io() - .build() - .unwrap(); + let tokio_rt = + tokio::runtime::Builder::new_current_thread().enable_io().build().unwrap(); c.bench_function("bus_ping_round_trip", |b| { b.iter(|| { diff --git a/src/rust/lqos_bus/build.rs b/src/rust/lqos_bus/build.rs index 4494d056..5e414178 100644 --- a/src/rust/lqos_bus/build.rs +++ b/src/rust/lqos_bus/build.rs @@ -1,5 +1,3 @@ fn main() { - cc::Build::new() - .file("src/tc_handle_parser.c") - .compile("tc_handle_parse.o"); + cc::Build::new().file("src/tc_handle_parser.c").compile("tc_handle_parse.o"); } diff --git a/src/rust/lqos_bus/src/bus/persistent_client.rs b/src/rust/lqos_bus/src/bus/persistent_client.rs index b5d84f2e..3ecbd7ff 100644 --- a/src/rust/lqos_bus/src/bus/persistent_client.rs +++ b/src/rust/lqos_bus/src/bus/persistent_client.rs @@ -70,10 +70,8 @@ impl BusClient { // Send with a timeout. If the timeout fails, then the stream went wrong if self.stream.is_some() { - let timer = timeout( - self.timeout, - Self::send(self.stream.as_mut().unwrap(), &msg), - ); + let timer = + timeout(self.timeout, Self::send(self.stream.as_mut().unwrap(), &msg)); let failed = if let Ok(inner) = timer.await { inner.is_err() } else { false }; if failed { diff --git a/src/rust/lqos_bus/src/bus/unix_socket_server.rs b/src/rust/lqos_bus/src/bus/unix_socket_server.rs index 20a00407..798ea6d3 100644 --- a/src/rust/lqos_bus/src/bus/unix_socket_server.rs +++ b/src/rust/lqos_bus/src/bus/unix_socket_server.rs @@ -51,7 +51,9 @@ impl UnixSocketServer { fn path_permissions() -> Result<(), UnixSocketServerError> { let unix_path = CString::new(BUS_SOCKET_DIRECTORY); if unix_path.is_err() { - error!("Unable to create C-compatible path string. This should never happen."); + error!( + "Unable to create C-compatible path string. This should never happen." + ); return Err(UnixSocketServerError::CString); } let unix_path = unix_path.unwrap(); diff --git a/src/rust/lqos_config/src/authentication.rs b/src/rust/lqos_config/src/authentication.rs index 6963af93..e6c3effe 100644 --- a/src/rust/lqos_config/src/authentication.rs +++ b/src/rust/lqos_config/src/authentication.rs @@ -113,9 +113,7 @@ impl WebUsers { if let Ok(users) = parse_result { Ok(users) } else { - error!( - "Unable to deserialize lqusers.toml. Error in next message." - ); + error!("Unable to deserialize lqusers.toml. Error in next message."); error!("{:?}", parse_result); Err(AuthenticationError::UnableToParse) } diff --git a/src/rust/lqos_config/src/program_control.rs b/src/rust/lqos_config/src/program_control.rs index 7f97fe35..e975834a 100644 --- a/src/rust/lqos_config/src/program_control.rs +++ b/src/rust/lqos_config/src/program_control.rs @@ -28,7 +28,10 @@ fn working_directory() -> Result { pub fn load_libreqos() -> Result { let path = path_to_libreqos()?; if !path.exists() { - error!("Unable to locate LibreQoS.py. ({}) Check your configuration directory.", path.display()); + error!( + "Unable to locate LibreQoS.py. ({}) Check your configuration directory.", + path.display() + ); return Err(ProgramControlError::LibreQosPyNotFound); } if !Path::new(PYTHON_PATH).exists() { diff --git a/src/rust/lqos_config/src/shaped_devices/mod.rs b/src/rust/lqos_config/src/shaped_devices/mod.rs index 6626a8fc..dc041046 100644 --- a/src/rust/lqos_config/src/shaped_devices/mod.rs +++ b/src/rust/lqos_config/src/shaped_devices/mod.rs @@ -33,8 +33,8 @@ impl ConfigShapedDevices { /// by acquiring the prefix from the `/etc/lqos.conf` configuration /// file. pub fn path() -> Result { - let cfg = etc::EtcLqos::load() - .map_err(|_| ShapedDevicesError::ConfigLoadError)?; + let cfg = + etc::EtcLqos::load().map_err(|_| ShapedDevicesError::ConfigLoadError)?; let base_path = Path::new(&cfg.lqos_directory); Ok(base_path.join("ShapedDevices.csv")) } @@ -52,8 +52,10 @@ impl ConfigShapedDevices { /// object containing the resulting data. pub fn load() -> Result { let final_path = ConfigShapedDevices::path()?; - let reader = - ReaderBuilder::new().comment(Some(b'#')).trim(csv::Trim::All).from_path(final_path); + let reader = ReaderBuilder::new() + .comment(Some(b'#')) + .trim(csv::Trim::All) + .from_path(final_path); if reader.is_err() { error!("Unable to read ShapedDevices.csv"); return Err(ShapedDevicesError::OpenFail); @@ -143,8 +145,8 @@ impl ConfigShapedDevices { /// Saves the current shaped devices list to `ShapedDevices.csv` pub fn write_csv(&self, filename: &str) -> Result<(), ShapedDevicesError> { - let cfg = etc::EtcLqos::load() - .map_err(|_| ShapedDevicesError::ConfigLoadError)?; + let cfg = + etc::EtcLqos::load().map_err(|_| ShapedDevicesError::ConfigLoadError)?; let base_path = Path::new(&cfg.lqos_directory); let path = base_path.join(filename); let csv = self.to_csv_string()?; diff --git a/src/rust/lqos_node_manager/src/shaped_devices.rs b/src/rust/lqos_node_manager/src/shaped_devices.rs index e96d8419..0200ee73 100644 --- a/src/rust/lqos_node_manager/src/shaped_devices.rs +++ b/src/rust/lqos_node_manager/src/shaped_devices.rs @@ -54,7 +54,9 @@ pub fn shaped_devices_search( #[get("/api/reload_required")] pub fn reload_required() -> NoCache> { - NoCache::new(Json(RELOAD_REQUIRED.load(std::sync::atomic::Ordering::Relaxed))) + NoCache::new(Json( + RELOAD_REQUIRED.load(std::sync::atomic::Ordering::Relaxed), + )) } #[get("/api/reload_libreqos")] @@ -63,8 +65,7 @@ pub async fn reload_libreqos(auth: AuthGuard) -> NoCache> { return NoCache::new(Json("Not authorized".to_string())); } // Send request to lqosd - let responses = - bus_request(vec![BusRequest::ReloadLibreQoS]).await.unwrap(); + let responses = bus_request(vec![BusRequest::ReloadLibreQoS]).await.unwrap(); let result = match &responses[0] { BusResponse::ReloadLibreQoS(msg) => msg.clone(), _ => "Unable to reload LibreQoS".to_string(), diff --git a/src/rust/lqos_node_manager/src/static_pages.rs b/src/rust/lqos_node_manager/src/static_pages.rs index bacf8bf8..5626863e 100644 --- a/src/rust/lqos_node_manager/src/static_pages.rs +++ b/src/rust/lqos_node_manager/src/static_pages.rs @@ -68,9 +68,7 @@ pub async fn shaped_devices_add_page<'a>( #[get("/vendor/bootstrap.min.css")] pub async fn bootsrap_css<'a>() -> LongCache> { - LongCache::new( - NamedFile::open("static/vendor/bootstrap.min.css").await.ok(), - ) + LongCache::new(NamedFile::open("static/vendor/bootstrap.min.css").await.ok()) } // Note that NoCache can be replaced with a cache option diff --git a/src/rust/lqos_node_manager/src/tracker/cache/cpu_ram.rs b/src/rust/lqos_node_manager/src/tracker/cache/cpu_ram.rs index cc9c8112..f791d241 100644 --- a/src/rust/lqos_node_manager/src/tracker/cache/cpu_ram.rs +++ b/src/rust/lqos_node_manager/src/tracker/cache/cpu_ram.rs @@ -1,10 +1,11 @@ -use std::sync::atomic::{AtomicU64, AtomicU32, AtomicUsize}; use once_cell::sync::Lazy; +use std::sync::atomic::{AtomicU32, AtomicU64, AtomicUsize}; const MAX_CPUS_COUNTED: usize = 128; /// Stores overall CPU usage -pub static CPU_USAGE: Lazy<[AtomicU32; MAX_CPUS_COUNTED]> = Lazy::new(build_empty_cpu_list); +pub static CPU_USAGE: Lazy<[AtomicU32; MAX_CPUS_COUNTED]> = + Lazy::new(build_empty_cpu_list); /// Total number of CPUs detected pub static NUM_CPUS: AtomicUsize = AtomicUsize::new(0); @@ -16,9 +17,9 @@ pub static RAM_USED: AtomicU64 = AtomicU64::new(0); pub static TOTAL_RAM: AtomicU64 = AtomicU64::new(0); fn build_empty_cpu_list() -> [AtomicU32; MAX_CPUS_COUNTED] { - let mut temp = Vec::with_capacity(MAX_CPUS_COUNTED); - for _ in 0..MAX_CPUS_COUNTED { - temp.push(AtomicU32::new(0)); - } - temp.try_into().expect("This should never happen, sizes are constant.") -} \ No newline at end of file + let mut temp = Vec::with_capacity(MAX_CPUS_COUNTED); + for _ in 0..MAX_CPUS_COUNTED { + temp.push(AtomicU32::new(0)); + } + temp.try_into().expect("This should never happen, sizes are constant.") +} diff --git a/src/rust/lqos_node_manager/src/tracker/cache_manager.rs b/src/rust/lqos_node_manager/src/tracker/cache_manager.rs index 5b0d65b6..fbde2066 100644 --- a/src/rust/lqos_node_manager/src/tracker/cache_manager.rs +++ b/src/rust/lqos_node_manager/src/tracker/cache_manager.rs @@ -59,11 +59,16 @@ pub async fn update_tracking() { .iter() .enumerate() .map(|(i, cpu)| (i, cpu.cpu_usage() as u32)) // Always rounds down - .for_each(|(i, cpu)| CPU_USAGE[i].store(cpu, std::sync::atomic::Ordering::Relaxed)); + .for_each(|(i, cpu)| { + CPU_USAGE[i].store(cpu, std::sync::atomic::Ordering::Relaxed) + }); - NUM_CPUS.store(sys.cpus().len(), std::sync::atomic::Ordering::Relaxed); - RAM_USED.store(sys.used_memory(), std::sync::atomic::Ordering::Relaxed); - TOTAL_RAM.store(sys.total_memory(), std::sync::atomic::Ordering::Relaxed); + NUM_CPUS + .store(sys.cpus().len(), std::sync::atomic::Ordering::Relaxed); + RAM_USED + .store(sys.used_memory(), std::sync::atomic::Ordering::Relaxed); + TOTAL_RAM + .store(sys.total_memory(), std::sync::atomic::Ordering::Relaxed); let error = get_data_from_server().await; // Ignoring errors to keep running if let Err(error) = error { error!("Error in usage update loop: {:?}", error); diff --git a/src/rust/lqos_node_manager/src/tracker/mod.rs b/src/rust/lqos_node_manager/src/tracker/mod.rs index 4e47c9eb..0f5aa5ef 100644 --- a/src/rust/lqos_node_manager/src/tracker/mod.rs +++ b/src/rust/lqos_node_manager/src/tracker/mod.rs @@ -1,8 +1,9 @@ mod cache; mod cache_manager; use self::cache::{ - CPU_USAGE, CURRENT_THROUGHPUT, HOST_COUNTS, RAM_USED, TOTAL_RAM, RTT_HISTOGRAM, - THROUGHPUT_BUFFER, TOP_10_DOWNLOADERS, WORST_10_RTT, NUM_CPUS, + CPU_USAGE, CURRENT_THROUGHPUT, HOST_COUNTS, NUM_CPUS, RAM_USED, + RTT_HISTOGRAM, THROUGHPUT_BUFFER, TOP_10_DOWNLOADERS, TOTAL_RAM, + WORST_10_RTT, }; use crate::{auth_guard::AuthGuard, tracker::cache::ThroughputPerSecond}; pub use cache::{SHAPED_DEVICES, UNKNOWN_DEVICES}; @@ -44,10 +45,8 @@ impl From<&IpStats> for IpStatsWithPlan { }; let cfg = SHAPED_DEVICES.read(); if let Some((_, id)) = cfg.trie.longest_match(lookup) { - result.ip_address = format!( - "{} ({})", - cfg.devices[*id].circuit_name, result.ip_address - ); + result.ip_address = + format!("{} ({})", cfg.devices[*id].circuit_name, result.ip_address); result.plan.0 = cfg.devices[*id].download_max_mbps; result.plan.1 = cfg.devices[*id].upload_max_mbps; result.circuit_id = cfg.devices[*id].circuit_id.clone(); @@ -136,8 +135,8 @@ pub fn busy_quantile(_auth: AuthGuard) -> Json> { let (down, up) = (down * 8, up * 8); //println!("{down_capacity}, {up_capacity}, {down}, {up}"); let (down, up) = ( - if down_capacity > 0.0 { down as f64 / down_capacity } else { 0.0 }, - if up_capacity > 0.0 { up as f64 / up_capacity } else { 0.0}, + if down_capacity > 0.0 { down as f64 / down_capacity } else { 0.0 }, + if up_capacity > 0.0 { up as f64 / up_capacity } else { 0.0 }, ); let (down, up) = ((down * 10.0) as usize, (up * 10.0) as usize); result[usize::min(9, down)].0 += 1; diff --git a/src/rust/lqos_python/src/blocking.rs b/src/rust/lqos_python/src/blocking.rs index 34b35d7f..c70d7ed4 100644 --- a/src/rust/lqos_python/src/blocking.rs +++ b/src/rust/lqos_python/src/blocking.rs @@ -3,11 +3,10 @@ use lqos_bus::{bus_request, BusRequest, BusResponse}; pub fn run_query(requests: Vec) -> Result> { let mut replies = Vec::with_capacity(8); - tokio::runtime::Builder::new_current_thread() - .enable_all() - .build()? - .block_on(async { + tokio::runtime::Builder::new_current_thread().enable_all().build()?.block_on( + async { replies.extend_from_slice(&bus_request(requests).await?); Ok(replies) - }) + }, + ) } diff --git a/src/rust/lqos_python/src/lib.rs b/src/rust/lqos_python/src/lib.rs index be6d059c..4a574dc4 100644 --- a/src/rust/lqos_python/src/lib.rs +++ b/src/rust/lqos_python/src/lib.rs @@ -1,10 +1,14 @@ -use std::{path::Path, fs::{File, remove_file}, io::Write}; use lqos_bus::{BusRequest, BusResponse, TcHandle}; use nix::libc::getpid; use pyo3::{ exceptions::PyOSError, pyclass, pyfunction, pymodule, types::PyModule, wrap_pyfunction, PyResult, Python, }; +use std::{ + fs::{remove_file, File}, + io::Write, + path::Path, +}; mod blocking; use anyhow::{Error, Result}; use blocking::run_query; @@ -147,9 +151,7 @@ fn validate_shaped_devices() -> PyResult { for response in result.iter() { match response { BusResponse::Ack => return Ok("OK".to_string()), - BusResponse::ShapedDevicesValidation(error) => { - return Ok(error.clone()) - } + BusResponse::ShapedDevicesValidation(error) => return Ok(error.clone()), _ => {} } } @@ -185,12 +187,12 @@ fn is_libre_already_running() -> PyResult { #[pyfunction] fn create_lock_file() -> PyResult<()> { let pid = unsafe { getpid() }; - let pid_format = format!("{pid}"); - { - if let Ok(mut f) = File::create(LOCK_FILE) { - f.write_all(pid_format.as_bytes())?; - } + let pid_format = format!("{pid}"); + { + if let Ok(mut f) = File::create(LOCK_FILE) { + f.write_all(pid_format.as_bytes())?; } + } Ok(()) } @@ -198,4 +200,4 @@ fn create_lock_file() -> PyResult<()> { fn free_lock_file() -> PyResult<()> { let _ = remove_file(LOCK_FILE); // Ignore result Ok(()) -} \ No newline at end of file +} diff --git a/src/rust/lqos_queue_tracker/benches/json.rs b/src/rust/lqos_queue_tracker/benches/json.rs index 2e605ffc..5aa0c511 100644 --- a/src/rust/lqos_queue_tracker/benches/json.rs +++ b/src/rust/lqos_queue_tracker/benches/json.rs @@ -66,7 +66,7 @@ fn setup_parent_htb(interface: &str) { .output() .unwrap(); - #[rustfmt::skip] + #[rustfmt::skip] Command::new(SUDO) .args([ TC, "qdisc", "add", "dev", interface, "parent", "0x1:1", "cake", diff --git a/src/rust/lqos_queue_tracker/src/queue_structure/queue_node.rs b/src/rust/lqos_queue_tracker/src/queue_structure/queue_node.rs index 80bfbe2b..6dbbb8d6 100644 --- a/src/rust/lqos_queue_tracker/src/queue_structure/queue_node.rs +++ b/src/rust/lqos_queue_tracker/src/queue_structure/queue_node.rs @@ -122,11 +122,7 @@ impl QueueNode { grab_u64!(result.upload_bandwidth_mbps, key.as_str(), value); } "downloadBandwidthMbpsMin" | "minDownload" => { - grab_u64!( - result.download_bandwidth_mbps_min, - key.as_str(), - value - ); + grab_u64!(result.download_bandwidth_mbps_min, key.as_str(), value); } "uploadBandwidthMbpsMin" | "minUpload" => { grab_u64!(result.upload_bandwidth_mbps_min, key.as_str(), value); diff --git a/src/rust/lqos_queue_tracker/src/queue_types/tc_cake.rs b/src/rust/lqos_queue_tracker/src/queue_types/tc_cake.rs index 4a9956b6..9ee9e710 100644 --- a/src/rust/lqos_queue_tracker/src/queue_types/tc_cake.rs +++ b/src/rust/lqos_queue_tracker/src/queue_types/tc_cake.rs @@ -101,9 +101,7 @@ impl TcCake { } "bytes" => result.bytes = value.as_u64().unwrap_or(0), "packets" => result.packets = value.as_u64().unwrap_or(0) as u32, - "overlimits" => { - result.overlimits = value.as_u64().unwrap_or(0) as u32 - } + "overlimits" => result.overlimits = value.as_u64().unwrap_or(0) as u32, "requeues" => result.requeues = value.as_u64().unwrap_or(0) as u32, "backlog" => result.backlog = value.as_u64().unwrap_or(0) as u32, "qlen" => result.qlen = value.as_u64().unwrap_or(0) as u32, @@ -176,14 +174,10 @@ impl TcCakeOptions { result.ack_filter = AckFilter::from_str(value.as_str().unwrap_or("")) } - "split_gso" => { - result.split_gso = value.as_bool().unwrap_or(false) - } + "split_gso" => result.split_gso = value.as_bool().unwrap_or(false), "rtt" => result.rtt = value.as_u64().unwrap_or(0), "raw" => result.raw = value.as_bool().unwrap_or(false), - "overhead" => { - result.overhead = value.as_u64().unwrap_or(0) as u16 - } + "overhead" => result.overhead = value.as_u64().unwrap_or(0) as u16, "fwmark" => { result.fwmark = value.as_str().unwrap_or("").to_string() } diff --git a/src/rust/lqos_queue_tracker/src/queue_types/tc_fq_codel.rs b/src/rust/lqos_queue_tracker/src/queue_types/tc_fq_codel.rs index fb3ce3ec..7011abd9 100644 --- a/src/rust/lqos_queue_tracker/src/queue_types/tc_fq_codel.rs +++ b/src/rust/lqos_queue_tracker/src/queue_types/tc_fq_codel.rs @@ -60,9 +60,7 @@ impl TcFqCodel { "bytes" => result.bytes = value.as_u64().unwrap_or(0), "packets" => result.packets = value.as_u64().unwrap_or(0) as u32, "drops" => result.drops = value.as_u64().unwrap_or(0) as u32, - "overlimits" => { - result.overlimits = value.as_u64().unwrap_or(0) as u32 - } + "overlimits" => result.overlimits = value.as_u64().unwrap_or(0) as u32, "requeues" => result.requeues = value.as_u64().unwrap_or(0) as u32, "backlog" => result.backlog = value.as_u64().unwrap_or(0) as u32, "qlen" => result.qlen = value.as_u64().unwrap_or(0) as u32, diff --git a/src/rust/lqos_queue_tracker/src/queue_types/tc_htb.rs b/src/rust/lqos_queue_tracker/src/queue_types/tc_htb.rs index 813d2ceb..92c7b937 100644 --- a/src/rust/lqos_queue_tracker/src/queue_types/tc_htb.rs +++ b/src/rust/lqos_queue_tracker/src/queue_types/tc_htb.rs @@ -48,9 +48,7 @@ impl TcHtb { "bytes" => result.bytes = value.as_u64().unwrap_or(0), "packets" => result.packets = value.as_u64().unwrap_or(0) as u32, "drops" => result.drops = value.as_u64().unwrap_or(0) as u32, - "overlimits" => { - result.overlimits = value.as_u64().unwrap_or(0) as u32 - } + "overlimits" => result.overlimits = value.as_u64().unwrap_or(0) as u32, "requeues" => result.requeues = value.as_u64().unwrap_or(0) as u32, "backlog" => result.backlog = value.as_u64().unwrap_or(0) as u32, "qlen" => result.qlen = value.as_u64().unwrap_or(0) as u32, diff --git a/src/rust/lqos_queue_tracker/src/queue_types/tc_mq.rs b/src/rust/lqos_queue_tracker/src/queue_types/tc_mq.rs index b81c1057..32830888 100644 --- a/src/rust/lqos_queue_tracker/src/queue_types/tc_mq.rs +++ b/src/rust/lqos_queue_tracker/src/queue_types/tc_mq.rs @@ -36,9 +36,7 @@ impl TcMultiQueue { "bytes" => result.bytes = value.as_u64().unwrap_or(0), "packets" => result.packets = value.as_u64().unwrap_or(0) as u32, "drops" => result.drops = value.as_u64().unwrap_or(0) as u32, - "overlimits" => { - result.overlimits = value.as_u64().unwrap_or(0) as u32 - } + "overlimits" => result.overlimits = value.as_u64().unwrap_or(0) as u32, "requeues" => result.requeues = value.as_u64().unwrap_or(0) as u32, "backlog" => result.backlog = value.as_u64().unwrap_or(0) as u32, "qlen" => result.qlen = value.as_u64().unwrap_or(0) as u32, diff --git a/src/rust/lqos_queue_tracker/src/tracking/mod.rs b/src/rust/lqos_queue_tracker/src/tracking/mod.rs index 6e1306da..97139dc8 100644 --- a/src/rust/lqos_queue_tracker/src/tracking/mod.rs +++ b/src/rust/lqos_queue_tracker/src/tracking/mod.rs @@ -40,10 +40,7 @@ fn track_queues() { ) } else { ( - read_named_queue_from_interface( - &config.isp_interface, - download_class, - ), + read_named_queue_from_interface(&config.isp_interface, download_class), read_named_queue_from_interface( &config.internet_interface, download_class, @@ -64,7 +61,12 @@ fn track_queues() { QueueStore::new(download[0].clone(), upload[0].clone()), ); } else { - info!("No queue data returned for {}, {}/{} found.", circuit_id.to_string(), download.len(), upload.len()); + info!( + "No queue data returned for {}, {}/{} found.", + circuit_id.to_string(), + download.len(), + upload.len() + ); info!("You probably want to run LibreQoS.py"); } } diff --git a/src/rust/lqos_queue_tracker/src/tracking/watched_queues.rs b/src/rust/lqos_queue_tracker/src/tracking/watched_queues.rs index c98f6ea6..4bf38d52 100644 --- a/src/rust/lqos_queue_tracker/src/tracking/watched_queues.rs +++ b/src/rust/lqos_queue_tracker/src/tracking/watched_queues.rs @@ -37,9 +37,7 @@ pub fn add_watched_queue(circuit_id: &str) { { let read_lock = WATCHED_QUEUES.read(); if read_lock.iter().any(|q| q.circuit_id == circuit_id) { - warn!( - "Queue {circuit_id} is already being watched. Duplicate ignored." - ); + warn!("Queue {circuit_id} is already being watched. Duplicate ignored."); return; // No duplicates, please } diff --git a/src/rust/lqos_sys/src/cpu_map.rs b/src/rust/lqos_sys/src/cpu_map.rs index 3f0a2392..6b75813d 100644 --- a/src/rust/lqos_sys/src/cpu_map.rs +++ b/src/rust/lqos_sys/src/cpu_map.rs @@ -1,7 +1,5 @@ use anyhow::{Error, Result}; -use libbpf_sys::{ - bpf_map_update_elem, bpf_obj_get, libbpf_num_possible_cpus, -}; +use libbpf_sys::{bpf_map_update_elem, bpf_obj_get, libbpf_num_possible_cpus}; use log::info; use std::{ffi::CString, os::raw::c_void}; diff --git a/src/rust/lqos_sys/src/ip_mapping/ip_to_map.rs b/src/rust/lqos_sys/src/ip_mapping/ip_to_map.rs index f8a887e2..728ffa12 100644 --- a/src/rust/lqos_sys/src/ip_mapping/ip_to_map.rs +++ b/src/rust/lqos_sys/src/ip_mapping/ip_to_map.rs @@ -120,12 +120,9 @@ mod test { #[test] fn parse_ipv6_subnet() { - let map = IpToMap::new( - "dead:beef::/64", - TcHandle::from_string("1:2").unwrap(), - 1, - ) - .unwrap(); + let map = + IpToMap::new("dead:beef::/64", TcHandle::from_string("1:2").unwrap(), 1) + .unwrap(); let rust_ip: IpAddr = "dead:beef::".parse().unwrap(); assert_eq!(rust_ip, map.subnet); assert_eq!(map.prefix, 64); diff --git a/src/rust/lqos_sys/src/lqos_kernel.rs b/src/rust/lqos_sys/src/lqos_kernel.rs index 4fcf2734..5dcb27a2 100644 --- a/src/rust/lqos_sys/src/lqos_kernel.rs +++ b/src/rust/lqos_sys/src/lqos_kernel.rs @@ -48,8 +48,7 @@ pub fn interface_name_to_index(interface_name: &str) -> Result { pub fn unload_xdp_from_interface(interface_name: &str) -> Result<()> { info!("Unloading XDP/TC"); check_root()?; - let interface_index = - interface_name_to_index(interface_name)?.try_into()?; + let interface_index = interface_name_to_index(interface_name)?.try_into()?; unsafe { let err = bpf_xdp_attach(interface_index, -1, 1 << 0, std::ptr::null()); if err != 0 { diff --git a/src/rust/lqos_sys/src/xdp_ip_address.rs b/src/rust/lqos_sys/src/xdp_ip_address.rs index ec5af027..7da8acb5 100644 --- a/src/rust/lqos_sys/src/xdp_ip_address.rs +++ b/src/rust/lqos_sys/src/xdp_ip_address.rs @@ -57,9 +57,7 @@ impl XdpIpAddress { && self.0[11] == 0xFF { // It's an IPv4 Address - IpAddr::V4(Ipv4Addr::new( - self.0[12], self.0[13], self.0[14], self.0[15], - )) + IpAddr::V4(Ipv4Addr::new(self.0[12], self.0[13], self.0[14], self.0[15])) } else { // It's an IPv6 address IpAddr::V6(Ipv6Addr::new( diff --git a/src/rust/lqos_utils/src/unix_time.rs b/src/rust/lqos_utils/src/unix_time.rs index 1add47cf..a60e714e 100644 --- a/src/rust/lqos_utils/src/unix_time.rs +++ b/src/rust/lqos_utils/src/unix_time.rs @@ -1,11 +1,14 @@ use log::{error, warn}; -use nix::{sys::time::TimeSpec, time::{clock_gettime, ClockId}}; +use nix::{ + sys::time::TimeSpec, + time::{clock_gettime, ClockId}, +}; use std::time::{SystemTime, UNIX_EPOCH}; use thiserror::Error; /// Retrieves the current time, in seconds since the UNIX epoch. /// Otherwise known as "unix time". -/// +/// /// It can fail if the clock isn't ready. pub fn unix_now() -> Result { match SystemTime::now().duration_since(UNIX_EPOCH) { @@ -20,13 +23,13 @@ pub fn unix_now() -> Result { /// Return the time since boot, from the Linux kernel. /// Can fail if the clock isn't ready yet. pub fn time_since_boot() -> Result { - match clock_gettime(ClockId::CLOCK_BOOTTIME) { - Ok(t) => Ok(t), - Err(e) => { - warn!("Clock not ready: {:?}", e); - Err(TimeError::ClockNotReady) - } + match clock_gettime(ClockId::CLOCK_BOOTTIME) { + Ok(t) => Ok(t), + Err(e) => { + warn!("Clock not ready: {:?}", e); + Err(TimeError::ClockNotReady) } + } } #[derive(Error, Debug)] diff --git a/src/rust/lqosd/src/lqos_daht_test.rs b/src/rust/lqosd/src/lqos_daht_test.rs index 3723933e..e20b6961 100644 --- a/src/rust/lqosd/src/lqos_daht_test.rs +++ b/src/rust/lqosd/src/lqos_daht_test.rs @@ -14,11 +14,7 @@ pub fn lqos_daht_test() -> BusResponse { ) == Ok(true) { let result = Command::new("/bin/ssh") - .args([ - "-t", - "lqtest@lqos.taht.net", - "\"/home/lqtest/bin/v6vsv4.sh\"", - ]) + .args(["-t", "lqtest@lqos.taht.net", "\"/home/lqtest/bin/v6vsv4.sh\""]) .output(); if result.is_err() { log::warn!("Unable to call dtaht test: {:?}", result); diff --git a/src/rust/lqosd/src/main.rs b/src/rust/lqosd/src/main.rs index 4a9050c4..c992f4aa 100644 --- a/src/rust/lqosd/src/main.rs +++ b/src/rust/lqosd/src/main.rs @@ -8,9 +8,7 @@ mod tuning; mod validation; use crate::{ file_lock::FileLock, - ip_mapping::{ - clear_ip_flows, del_ip_flow, list_mapped_ips, map_ip_to_flow, - }, + ip_mapping::{clear_ip_flows, del_ip_flow, list_mapped_ips, map_ip_to_flow}, }; use anyhow::Result; use log::{info, warn}; @@ -78,9 +76,9 @@ async fn main() -> Result<()> { match sig { SIGINT => warn!("Terminating on SIGINT"), SIGTERM => warn!("Terminating on SIGTERM"), - _ => warn!( - "This should never happen - terminating on unknown signal" - ), + _ => { + warn!("This should never happen - terminating on unknown signal") + } } std::mem::drop(kernels); UnixSocketServer::signal_cleanup(); diff --git a/src/rust/lqosd/src/throughput_tracker/mod.rs b/src/rust/lqosd/src/throughput_tracker/mod.rs index 2f284ce5..b1a22708 100644 --- a/src/rust/lqosd/src/throughput_tracker/mod.rs +++ b/src/rust/lqosd/src/throughput_tracker/mod.rs @@ -272,7 +272,6 @@ pub fn host_counts() -> BusResponse { type FullList = (XdpIpAddress, (u64, u64), (u64, u64), f32, TcHandle, u64); pub fn all_unknown_ips() -> BusResponse { - let boot_time = time_since_boot(); if boot_time.is_err() { warn!("The Linux system clock isn't available to provide time since boot, yet."); @@ -281,7 +280,8 @@ pub fn all_unknown_ips() -> BusResponse { } let boot_time = boot_time.unwrap(); let time_since_boot = Duration::from(boot_time); - let five_minutes_ago = time_since_boot.saturating_sub(Duration::from_secs(300)); + let five_minutes_ago = + time_since_boot.saturating_sub(Duration::from_secs(300)); let five_minutes_ago_nanoseconds = five_minutes_ago.as_nanos(); let mut full_list: Vec = { diff --git a/src/rust/lqosd/src/throughput_tracker/tracking_data.rs b/src/rust/lqosd/src/throughput_tracker/tracking_data.rs index d4013ffd..9ea150f2 100644 --- a/src/rust/lqosd/src/throughput_tracker/tracking_data.rs +++ b/src/rust/lqosd/src/throughput_tracker/tracking_data.rs @@ -120,7 +120,9 @@ impl ThroughputTracker { self.packets_per_second = (0, 0); self.shaped_bytes_per_second = (0, 0); self - .raw_data.values().map(|v| { + .raw_data + .values() + .map(|v| { ( v.bytes.0.saturating_sub(v.prev_bytes.0), v.bytes.1.saturating_sub(v.prev_bytes.1), @@ -129,18 +131,25 @@ impl ThroughputTracker { v.tc_handle.as_u32() > 0, ) }) - .for_each( - |(bytes_down, bytes_up, packets_down, packets_up, shaped)| { - self.bytes_per_second.0 = self.bytes_per_second.0.checked_add(bytes_down).unwrap_or(0); - self.bytes_per_second.1 = self.bytes_per_second.1.checked_add(bytes_up).unwrap_or(0); - self.packets_per_second.0 = self.packets_per_second.0.checked_add(packets_down).unwrap_or(0); - self.packets_per_second.1 = self.packets_per_second.1.checked_add(packets_up).unwrap_or(0); - if shaped { - self.shaped_bytes_per_second.0 = self.shaped_bytes_per_second.0.checked_add(bytes_down).unwrap_or(0); - self.shaped_bytes_per_second.1 = self.shaped_bytes_per_second.1.checked_add(bytes_up).unwrap_or(0); - } - }, - ); + .for_each(|(bytes_down, bytes_up, packets_down, packets_up, shaped)| { + self.bytes_per_second.0 = + self.bytes_per_second.0.checked_add(bytes_down).unwrap_or(0); + self.bytes_per_second.1 = + self.bytes_per_second.1.checked_add(bytes_up).unwrap_or(0); + self.packets_per_second.0 = + self.packets_per_second.0.checked_add(packets_down).unwrap_or(0); + self.packets_per_second.1 = + self.packets_per_second.1.checked_add(packets_up).unwrap_or(0); + if shaped { + self.shaped_bytes_per_second.0 = self + .shaped_bytes_per_second + .0 + .checked_add(bytes_down) + .unwrap_or(0); + self.shaped_bytes_per_second.1 = + self.shaped_bytes_per_second.1.checked_add(bytes_up).unwrap_or(0); + } + }); } pub(crate) fn next_cycle(&mut self) { diff --git a/src/rust/lqosd/src/tuning/offloads.rs b/src/rust/lqosd/src/tuning/offloads.rs index 9c77f857..d3aee238 100644 --- a/src/rust/lqosd/src/tuning/offloads.rs +++ b/src/rust/lqosd/src/tuning/offloads.rs @@ -7,8 +7,7 @@ pub fn bpf_sysctls() { } pub fn stop_irq_balance() { - let _ = - Command::new("/bin/systemctl").args(["stop", "irqbalance"]).output(); + let _ = Command::new("/bin/systemctl").args(["stop", "irqbalance"]).output(); } pub fn netdev_budget(usecs: u32, packets: u32) { diff --git a/src/rust/lqtop/src/main.rs b/src/rust/lqtop/src/main.rs index bc94ab10..b15b4802 100644 --- a/src/rust/lqtop/src/main.rs +++ b/src/rust/lqtop/src/main.rs @@ -62,10 +62,9 @@ fn draw_menu<'a>(is_connected: bool) -> Paragraph<'a> { .0 .push(Span::styled(" NOT CONNECTED ", Style::default().fg(Color::Red))) } else { - text.0.push(Span::styled( - " CONNECTED ", - Style::default().fg(Color::Green), - )) + text + .0 + .push(Span::styled(" CONNECTED ", Style::default().fg(Color::Green))) } let para = Paragraph::new(text) @@ -321,7 +320,7 @@ pub async fn main() -> Result<()> { code: KeyCode::Char('6'), modifiers: KeyModifiers::NONE, .. - }) => break, // FIXME Just look at ipv6 + }) => break, // FIXME Just look at ipv6 Event::Key(KeyEvent { code: KeyCode::Char('4'), modifiers: KeyModifiers::NONE, diff --git a/src/rust/rustfmt.toml b/src/rust/rustfmt.toml index 08e37267..3630e584 100644 --- a/src/rust/rustfmt.toml +++ b/src/rust/rustfmt.toml @@ -1,5 +1,5 @@ -max_width = 78 +max_width = 79 tab_spaces = 2 use_small_heuristics = "Max" -array_width = 78 +array_width = 77