fix(dhcp): remove unused IP range check and simplify DnsConfig

Remove the commented-out IP range validation in `DhcpConfig` and simplify the `DnsConfig` constructor by removing an unnecessary parameter, addressing several compiler warnings.
This commit is contained in:
2025-01-12 15:32:14 -05:00
parent cad63ecf20
commit f241bf793e
25 changed files with 38 additions and 84 deletions

View File

@@ -18,7 +18,7 @@ opnsense-config-xml = { path = "../opnsense-config-xml" }
chrono = "0.4.38"
russh-sftp = "2.0.6"
serde_json = "1.0.133"
tokio-util = "0.7.13"
tokio-util = { version = "0.7.13", features = [ "codec" ] }
tokio-stream = "0.1.17"
[dev-dependencies]

View File

@@ -35,7 +35,7 @@ impl Config {
}
pub fn dns(&mut self) -> DnsConfig {
DnsConfig::new(&mut self.opnsense, self.shell.clone())
DnsConfig::new(&mut self.opnsense)
}
pub fn tftp(&mut self) -> TftpConfig {

View File

@@ -86,13 +86,7 @@ impl<'a> DhcpConfig<'a> {
return Err(DhcpError::InvalidMacAddress(mac));
}
// TODO verify if address is in subnet range
// This check here does not do what we want to do, as we want to assign static leases
// outside of the dynamic DHCP pool
// let range = &lan_dhcpd.range;
// if !Self::is_ip_in_range(&ipaddr, range) {
// return Err(DhcpError::IpAddressOutOfRange(ipaddr.to_string()));
// }
// TODO validate that address is in subnet range
if existing_mappings.iter().any(|m| {
m.ipaddr
@@ -147,25 +141,6 @@ impl<'a> DhcpConfig<'a> {
.all(|part| part.len() <= 2 && part.chars().all(|c| c.is_ascii_hexdigit()))
}
fn is_ip_in_range(ip: &Ipv4Addr, range: &Range) -> bool {
let range_start = range
.from
.parse::<Ipv4Addr>()
.expect("Invalid DHCP range start");
let range_end = range.to.parse::<Ipv4Addr>().expect("Invalid DHCP range to");
let start_compare = range_start.cmp(ip);
let end_compare = range_end.cmp(ip);
if (Ordering::Less == start_compare || Ordering::Equal == start_compare)
&& (Ordering::Greater == end_compare || Ordering::Equal == end_compare)
{
return true;
} else {
return false;
}
}
pub async fn get_static_mappings(&self) -> Result<Vec<StaticMap>, Error> {
let list_static_output = self
.opnsense_shell

View File

@@ -1,20 +1,14 @@
use std::sync::Arc;
use opnsense_config_xml::{Host, OPNsense};
use crate::config::OPNsenseShell;
pub struct DnsConfig<'a> {
opnsense: &'a mut OPNsense,
opnsense_shell: Arc<dyn OPNsenseShell>,
}
impl<'a> DnsConfig<'a> {
pub fn new(opnsense: &'a mut OPNsense, opnsense_shell: Arc<dyn OPNsenseShell>) -> Self {
Self {
opnsense,
opnsense_shell,
}
pub fn new(opnsense: &'a mut OPNsense) -> Self {
Self { opnsense }
}
pub fn register_hosts(&mut self, mut hosts: Vec<Host>) {