From: Otto Moerbeek Date: Tue, 28 Oct 2025 15:40:05 +0000 (+0100) Subject: Clippy and store event trace values in yaml struct X-Git-Tag: rec-5.4.0-alpha1~108^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d66c6f9ed5f7cdbd14d005807a65ae9478a480a0;p=thirdparty%2Fpdns.git Clippy and store event trace values in yaml struct There are more cases Signed-off-by: Otto Moerbeek --- diff --git a/pdns/recursordist/rec-rust-lib/rust-bridge-in.rs b/pdns/recursordist/rec-rust-lib/rust-bridge-in.rs index 1e75d07b15..5851c748a7 100644 --- a/pdns/recursordist/rec-rust-lib/rust-bridge-in.rs +++ b/pdns/recursordist/rec-rust-lib/rust-bridge-in.rs @@ -403,7 +403,7 @@ extern "Rust" { // Prdoduce a YAML formatted string given a data structure known to Serde fn to_yaml_string(self: &Recursorsettings) -> Result; - fn get_value(self: &Recursorsettings, field: &Vec, defaults: &str) -> Result; + fn get_value(self: &Recursorsettings, field: &[String], defaults: &str) -> Result; // When doing a conversion of old-style to YAML style we use a vector of OldStyle structs fn map_to_yaml_string(map: &Vec) -> Result; fn forward_zones_to_yaml_string(vec: &Vec) -> Result; diff --git a/pdns/recursordist/rec-rust-lib/rust/src/bridge.rs b/pdns/recursordist/rec-rust-lib/rust/src/bridge.rs index 0000a8c5c2..0fc9f959b6 100644 --- a/pdns/recursordist/rec-rust-lib/rust/src/bridge.rs +++ b/pdns/recursordist/rec-rust-lib/rust/src/bridge.rs @@ -216,7 +216,12 @@ fn validate_address_family( for addr_str in vec { let mut wrong = false; let sa = SocketAddr::from_str(addr_str); - if sa.is_err() { + if let Ok(address) = sa { + if local.is_ipv4() != address.is_ipv4() || local.is_ipv6() != address.is_ipv6() { + wrong = true; + } + } + else { let ip = IpAddr::from_str(addr_str); if ip.is_err() { // It is likely a name @@ -226,11 +231,6 @@ fn validate_address_family( if local.is_ipv4() != ip.is_ipv4() || local.is_ipv6() != ip.is_ipv6() { wrong = true; } - } else { - let sa = sa.unwrap(); - if local.is_ipv4() != sa.is_ipv4() || local.is_ipv6() != sa.is_ipv6() { - wrong = true; - } } if wrong { let msg = format!( @@ -964,20 +964,20 @@ impl Recursorsettings { Err(std::io::Error::other(field[0].to_owned() + ": not a map")) } - pub fn get_value(&self, field: &Vec, defaults: &str) -> Result { + pub fn get_value(&self, field: &[String], defaults: &str) -> Result { let value = serde_yaml::to_value(self); let value = match value { Ok(value) => value, Err(error) => return Err(std::io::Error::other(error.to_string())) }; match Self::get_value1(&value, field) { - Ok(result) => Ok(result), + Ok(yaml) => Ok(yaml), Err(_) => { let defaults_value: serde_yaml::Value = serde_yaml::from_str(defaults).unwrap(); let yaml = Self::get_value1(&defaults_value, field); match yaml { - Ok(yaml) => Ok("# Not explicitly set, default value is:\n".to_owned() + &yaml), - Err(x) => Err(x) + Ok(yaml) => Ok("# Not explicitly set, default value(s) listed below:\n".to_owned() + &yaml), + x => x } } } @@ -1186,7 +1186,7 @@ fn api_read_zones_locked( let data: Result = serde_yaml::from_reader(BufReader::new(file)); match data { - Err(error) => return Err(std::io::Error::new(ErrorKind::Other, error.to_string())), + Err(error) => return Err(std::io::Error::other(error.to_string())), Ok(yaml) => yaml, } } @@ -1220,7 +1220,7 @@ fn api_write_zones(path: &str, zones: &ApiZones) -> Result<(), std::io::Error> { let file = File::create(tmpfile.as_str())?; let mut buffered_writer = BufWriter::new(&file); if let Err(error) = serde_yaml::to_writer(&mut buffered_writer, &zones) { - return Err(std::io::Error::new(ErrorKind::Other, error.to_string())); + return Err(std::io::Error::other(error.to_string())); } buffered_writer.flush()?; file.sync_all()?; diff --git a/pdns/recursordist/rec-rust-lib/rust/src/web.rs b/pdns/recursordist/rec-rust-lib/rust/src/web.rs index e84946c86a..b75c1ba12f 100644 --- a/pdns/recursordist/rec-rust-lib/rust/src/web.rs +++ b/pdns/recursordist/rec-rust-lib/rust/src/web.rs @@ -39,7 +39,6 @@ use hyper::server::conn::http1; use hyper::service::service_fn; use hyper::{body::Incoming as IncomingBody, header, Method, Request, Response, StatusCode}; use hyper_util::rt::TokioIo; -use std::io::ErrorKind; use std::str::FromStr; use std::sync::Arc; use tokio::net::TcpListener; @@ -719,7 +718,7 @@ async fn serveweb_async( let mut server_config = rustls::ServerConfig::builder() .with_no_client_auth() .with_single_cert(certs, key) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + .map_err(|e| std::io::Error::other(e.to_string()))?; server_config.alpn_protocols = vec![b"http/1.1".to_vec(), b"http/1.0".to_vec()]; // b"h2".to_vec() let tls_acceptor = tokio_rustls::TlsAcceptor::from(Arc::new(server_config)); // We start a loop to continuously accept incoming connections @@ -891,7 +890,7 @@ pub fn serveweb( Ok(val) => val, Err(err) => { let msg = format!("`{}' is not a IP:port combination: {}", addr_str, err); - return Err(std::io::Error::new(ErrorKind::Other, msg)); + return Err(std::io::Error::other(msg)); } }; @@ -937,7 +936,7 @@ pub fn serveweb( }], ); let msg = format!("Unable to bind web socket: {}", err); - return Err(std::io::Error::new(ErrorKind::Other, msg)); + return Err(std::io::Error::other(msg)); } } } @@ -968,8 +967,7 @@ pub fn serveweb( fn load_certs(filename: &str) -> std::io::Result>> { // Open certificate file. let certfile = std::fs::File::open(filename).map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("Failed to open {}: {}", filename, e), ) })?; @@ -983,8 +981,7 @@ fn load_certs(filename: &str) -> std::io::Result std::io::Result> { // Open keyfile. let keyfile = std::fs::File::open(filename).map_err(|e| { - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("Failed to open {}: {}", filename, e), ) })?; @@ -994,8 +991,7 @@ fn load_private_key(filename: &str) -> std::io::Result Ok(pkey), Ok(None) => Err( - std::io::Error::new( - std::io::ErrorKind::Other, + std::io::Error::other( format!("Failed to parse private key from {}", filename), )), Err(e) => Err(e) diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index 9b0f3a0411..f8d5787603 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -314,8 +314,9 @@ static Answer doGetParameter(ArgIterator begin, ArgIterator end) auto settings = g_yamlStruct.lock(); rust::Vec<::rust::String> field; stringtok(field, *begin, "."); + rust::Slice slice{field}; try { - auto yaml = settings->get_value(field, pdns::settings::rec::defaultsToYaml(false)); + auto yaml = settings->get_value(slice, pdns::settings::rec::defaultsToYaml(false)); return {0, std::string(yaml)}; } catch (const std::exception& stdex) { @@ -1860,6 +1861,9 @@ static Answer setEventTracing(ArgIterator begin, ArgIterator end) } try { pdns::checked_stoi_into(SyncRes::s_event_trace_enabled, *begin); + if (g_yamlSettings) { + g_yamlStruct.lock()->recursor.event_trace_enabled = SyncRes::s_event_trace_enabled; + } return {0, "New event trace enabled value: " + std::to_string(SyncRes::s_event_trace_enabled) + "\n"}; } catch (const std::exception& e) {