]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Clippy and store event trace values in yaml struct
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 28 Oct 2025 15:40:05 +0000 (16:40 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 4 Nov 2025 12:40:38 +0000 (13:40 +0100)
There are more cases

Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/rec-rust-lib/rust-bridge-in.rs
pdns/recursordist/rec-rust-lib/rust/src/bridge.rs
pdns/recursordist/rec-rust-lib/rust/src/web.rs
pdns/recursordist/rec_channel_rec.cc

index 1e75d07b15f9ae8a4bf936dc11b7311e78e66124..5851c748a7364f6929fc739d3f7fec08f35c1250 100644 (file)
@@ -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<String>;
-    fn get_value(self: &Recursorsettings, field: &Vec<String>, defaults: &str) -> Result<String>;
+    fn get_value(self: &Recursorsettings, field: &[String], defaults: &str) -> Result<String>;
     // When doing a conversion of old-style to YAML style we use a vector of OldStyle structs
     fn map_to_yaml_string(map: &Vec<OldStyle>) -> Result<String>;
     fn forward_zones_to_yaml_string(vec: &Vec<ForwardZone>) -> Result<String>;
index 0000a8c5c28ff98c8d86b981c07b53489b8e8d32..0fc9f959b6edac3d195c2d085f9212685cda89a0 100644 (file)
@@ -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<String>, defaults: &str) -> Result<String, std::io::Error> {
+    pub fn get_value(&self, field: &[String], defaults: &str) -> Result<String, std::io::Error> {
         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<ApiZones, serde_yaml::Error> =
                 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()?;
index e84946c86a75e2562ca05a82e0680665215b24af..b75c1ba12f319bbc70aa979e5b0b5c5db0cc5944 100644 (file)
@@ -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<Vec<pki_types::CertificateDer<'static>>> {
     // 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<Vec<pki_types::CertificateDer<'
 fn load_private_key(filename: &str) -> std::io::Result<pki_types::PrivateKeyDer<'static>> {
     // 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<pki_types::PrivateKeyDer<
     match rustls_pemfile::private_key(&mut reader) {
         Ok(Some(pkey)) => 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)
index 9b0f3a041136841f3a6bc8f9dcf77f4840f4d938..f8d578760336df94c452a213434993028f89b977 100644 (file)
@@ -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<const ::rust::String> 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) {